From patchwork Sun Jan 5 19:43:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 307089 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3CD3F2C00BD for ; Mon, 6 Jan 2014 14:46:17 +1100 (EST) Received: from localhost ([::1]:60470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W018p-0004Fz-4q for incoming@patchwork.ozlabs.org; Sun, 05 Jan 2014 22:46:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W016H-0001jN-6C for qemu-devel@nongnu.org; Sun, 05 Jan 2014 22:43:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0167-0001Dm-JM for qemu-devel@nongnu.org; Sun, 05 Jan 2014 22:43:37 -0500 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:52919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0167-0001DU-1E for qemu-devel@nongnu.org; Sun, 05 Jan 2014 22:43:27 -0500 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Jan 2014 09:13:25 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Jan 2014 09:13:23 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 010AA394004E for ; Mon, 6 Jan 2014 09:13:23 +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 s063hLqa5701956 for ; Mon, 6 Jan 2014 09:13:21 +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 s063hMRN022594 for ; Mon, 6 Jan 2014 09:13:22 +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 s063hHUc022368; Mon, 6 Jan 2014 09:13:21 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 6 Jan 2014 03:43:05 +0800 Message-Id: <1388950991-30105-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1388950991-30105-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1388950991-30105-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010603-2674-0000-0000-00000C28EAA6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.9 Cc: kwolf@redhat.com, peter.crosthwaite@xilinx.com, jcody@redhat.com, mreitz@redhat.com, stefanha@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V9 2/8] 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 8cac42d..5619fc3 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 %zu", + offset, 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 %zu", + offset, 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 %zu with size %zu", + offsetof(QCowHeader, nb_snapshots), + 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; }