From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEIIs-0000r1-GS for qemu-devel@nongnu.org; Tue, 27 Aug 2013 08:23:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEIIm-00030w-Gs for qemu-devel@nongnu.org; Tue, 27 Aug 2013 08:23:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8636) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEIIm-0002xr-49 for qemu-devel@nongnu.org; Tue, 27 Aug 2013 08:23:16 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7RCNEYH010600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 27 Aug 2013 08:23:14 -0400 Date: Tue, 27 Aug 2013 14:23:27 +0200 From: Kevin Wolf Message-ID: <20130827122327.GF648@dhcp-200-207.str.redhat.com> References: <1377522260-16676-1-git-send-email-mreitz@redhat.com> <1377522260-16676-5-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1377522260-16676-5-git-send-email-mreitz@redhat.com> Subject: Re: [Qemu-devel] [PATCH 4/5] qcow2: Check allocations in qcow2_check List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Am 26.08.2013 um 15:04 hat Max Reitz geschrieben: > Adds a new function checking for overlapping cluster allocations. > Furthermore, qcow2_check now marks the image as consistent if no > corruptions have been found. > > Signed-off-by: Max Reitz > --- > block/qcow2-cluster.c | 414 ++++++++++++++++++++++++++++++++++++++++++++++++++ > block/qcow2.c | 15 +- > block/qcow2.h | 2 + > 3 files changed, 429 insertions(+), 2 deletions(-) > > diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c > index be35983..ea7d334 100644 > --- a/block/qcow2-cluster.c > +++ b/block/qcow2-cluster.c > @@ -1499,3 +1499,417 @@ fail: > > return ret; > } > + > +static const char *const overlap_strings[8] = { > + "main header", > + "active L1 table", > + "active L2 table", > + "refcount table", > + "refcount block", > + "snapshot table", > + "inactive L1 table", > + "inactive L2 table" > +}; > + > +/* > + * Checks the table and cluster allocations for inconsistencies. > + */ > +int qcow2_check_allocations(BlockDriverState *bs, BdrvCheckResult *result, > + BdrvCheckMode fix) For the record: We have decided to leave this out as the required functionality is already provided by the refcount checks. > diff --git a/block/qcow2.c b/block/qcow2.c > index 95497c6..0b0f0ac 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -311,8 +311,19 @@ static int qcow2_check(BlockDriverState *bs, BdrvCheckResult *result, > return ret; > } > > - if (fix && result->check_errors == 0 && result->corruptions == 0) { > - return qcow2_mark_clean(bs); > + ret = qcow2_check_allocations(bs, result, fix); > + if (ret < 0) { > + return ret; > + } > + > + if (result->check_errors == 0 && result->corruptions == 0) { > + if (fix) { > + ret = qcow2_mark_clean(bs); > + if (ret < 0) { > + return ret; > + } > + } > + return qcow2_mark_consistent(bs); The qcow2_mark_consistent() call should probably be inside the if block, otherwise you'll be trying to update the header of read-only image. The reason why you didn't notice this is that qemu-img is broken since commit 8599ea4c and doesn't report errors on negative return values any more... Kevin