From patchwork Thu Dec 5 12:02:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 297088 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 201A22C009D for ; Thu, 5 Dec 2013 23:02:16 +1100 (EST) Received: from localhost ([::1]:53044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoXdF-0002PG-PG for incoming@patchwork.ozlabs.org; Thu, 05 Dec 2013 07:02:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoXca-0002L4-Q1 for qemu-devel@nongnu.org; Thu, 05 Dec 2013 07:01:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoXcR-0005CI-DY for qemu-devel@nongnu.org; Thu, 05 Dec 2013 07:01:32 -0500 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:43083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoXcQ-0005AY-Ks for qemu-devel@nongnu.org; Thu, 05 Dec 2013 07:01:23 -0500 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Dec 2013 17:31:18 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Dec 2013 17:31:16 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id B2F34394004E for ; Thu, 5 Dec 2013 17:31:15 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rB5C1CI633095710 for ; Thu, 5 Dec 2013 17:31:12 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rB5C1Dp9003040 for ; Thu, 5 Dec 2013 17:31:13 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rB5C19iZ002561; Thu, 5 Dec 2013 17:31:12 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 5 Dec 2013 20:02:48 +0800 Message-Id: <1386244972-528-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1386244972-528-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1386244972-528-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13120512-5564-0000-0000-00000AF985D1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.4 Cc: kwolf@redhat.com, jcody@redhat.com, Wenchao Xia , stefanha@redhat.com, mreitz@redhat.com Subject: [Qemu-devel] [PATCH V7 2/6] qcow2: add error message in qcow2_write_snapshots() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The function still returns int since qcow2_snapshot_delete() will return the number. Signed-off-by: Wenchao Xia Reviewed-by: Max Reitz --- block/qcow2-snapshot.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 files changed, 37 insertions(+), 6 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 670a58d..d7ab4ae 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -152,7 +152,7 @@ fail: } /* add at the end of the file a new list of snapshots */ -static int qcow2_write_snapshots(BlockDriverState *bs) +static int qcow2_write_snapshots(BlockDriverState *bs, Error **errp) { BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; @@ -183,10 +183,15 @@ static int qcow2_write_snapshots(BlockDriverState *bs) offset = snapshots_offset; if (offset < 0) { ret = offset; + error_setg_errno(errp, -ret, + "Failed in allocation of cluster for snapshot list"); goto fail; } ret = bdrv_flush(bs); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in flush after snapshot list cluster " + "allocation"); goto fail; } @@ -194,6 +199,10 @@ static int qcow2_write_snapshots(BlockDriverState *bs) * must indeed be completely free */ ret = qcow2_pre_write_overlap_check(bs, 0, offset, snapshots_size); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in overlap check for snapshot list cluster " + "at %" PRIi64 " with size %d", + offset, snapshots_size); goto fail; } @@ -227,24 +236,40 @@ static int qcow2_write_snapshots(BlockDriverState *bs) ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h)); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in write of snapshot header at %" + PRIi64 " with size %d", + offset, (int)sizeof(h)); goto fail; } offset += sizeof(h); ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra)); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in write of extra snapshot data at %" + PRIi64 " with size %d", + offset, (int)sizeof(extra)); goto fail; } offset += sizeof(extra); ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in write of snapshot id string at %" + PRIi64 " with size %d", + offset, id_str_size); goto fail; } offset += id_str_size; ret = bdrv_pwrite(bs->file, offset, sn->name, name_size); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in write of snapshot name string at %" + PRIi64 " with size %d", + offset, name_size); goto fail; } offset += name_size; @@ -256,6 +281,8 @@ static int qcow2_write_snapshots(BlockDriverState *bs) */ ret = bdrv_flush(bs); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in flush after snapshot list update"); goto fail; } @@ -268,6 +295,10 @@ static int qcow2_write_snapshots(BlockDriverState *bs) ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), &header_data, sizeof(header_data)); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed in update of image header at %d with size %d", + (int)offsetof(QCowHeader, nb_snapshots), + (int)sizeof(header_data)); goto fail; } @@ -283,6 +314,9 @@ fail: qcow2_free_clusters(bs, snapshots_offset, snapshots_size, QCOW2_DISCARD_ALWAYS); } + if (errp) { + g_assert(error_is_set(errp)); + } return ret; } @@ -447,10 +481,8 @@ void qcow2_snapshot_create(BlockDriverState *bs, s->snapshots = new_snapshot_list; s->snapshots[s->nb_snapshots++] = *sn; - ret = qcow2_write_snapshots(bs); + ret = qcow2_write_snapshots(bs, errp); if (ret < 0) { - /* Following line will be replaced with more detailed error later */ - error_setg(errp, "Failed in write of snapshot"); g_free(s->snapshots); s->snapshots = old_snapshot_list; s->nb_snapshots--; @@ -624,9 +656,8 @@ int qcow2_snapshot_delete(BlockDriverState *bs, s->snapshots + snapshot_index + 1, (s->nb_snapshots - snapshot_index - 1) * sizeof(sn)); s->nb_snapshots--; - ret = qcow2_write_snapshots(bs); + ret = qcow2_write_snapshots(bs, errp); if (ret < 0) { - error_setg(errp, "Failed to remove snapshot from snapshot list"); return ret; }