From patchwork Tue Jul 6 10:51:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MORITA Kazutaka X-Patchwork-Id: 57994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A572EB6EFF for ; Tue, 6 Jul 2010 20:53:49 +1000 (EST) Received: from localhost ([127.0.0.1]:46829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OW5mb-0001Xs-Hq for incoming@patchwork.ozlabs.org; Tue, 06 Jul 2010 06:53:45 -0400 Received: from [140.186.70.92] (port=59084 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OW5lR-0001Vk-Am for qemu-devel@nongnu.org; Tue, 06 Jul 2010 06:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OW5lP-0006TA-To for qemu-devel@nongnu.org; Tue, 06 Jul 2010 06:52:33 -0400 Received: from sh.osrg.net ([192.16.179.4]:37314) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OW5lP-0006S4-Ct for qemu-devel@nongnu.org; Tue, 06 Jul 2010 06:52:31 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o66AqMGC018153; Tue, 6 Jul 2010 19:52:23 +0900 Received: from dfs-seven.osrg.net.osrg.net (unknown [10.32.32.68]) by fs.osrg.net (Postfix) with ESMTP id 678F13E0032; Tue, 6 Jul 2010 19:52:22 +0900 (JST) Date: Tue, 06 Jul 2010 19:51:24 +0900 Message-ID: <87vd8shoib.wl%morita.kazutaka@lab.ntt.co.jp> From: MORITA Kazutaka To: Kevin Wolf Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-img check: Distinguish different kinds of errors In-Reply-To: <1278090900-12832-2-git-send-email-kwolf@redhat.com> References: <1278090900-12832-1-git-send-email-kwolf@redhat.com> <1278090900-12832-2-git-send-email-kwolf@redhat.com> User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.7 Emacs/22.3 (x86_64-pc-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Tue, 06 Jul 2010 19:52:23 +0900 (JST) X-Virus-Scanned: clamav-milter 0.96.1 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org At Fri, 2 Jul 2010 19:14:59 +0200, Kevin Wolf wrote: > > People think that their images are corrupted when in fact there are just some > leaked clusters. Differentiating several error cases should make the messages > more comprehensible. > > Signed-off-by: Kevin Wolf > --- > block.c | 10 ++++++-- > block.h | 10 ++++++++- > qemu-img.c | 62 +++++++++++++++++++++++++++++++++++++++++++++-------------- > 3 files changed, 63 insertions(+), 19 deletions(-) > > diff --git a/block.c b/block.c > index dd6dd76..b0ceef0 100644 > --- a/block.c > +++ b/block.c > @@ -710,15 +710,19 @@ DeviceState *bdrv_get_attached(BlockDriverState *bs) > /* > * Run consistency checks on an image > * > - * Returns the number of errors or -errno when an internal error occurs > + * Returns 0 if the check could be completed (it doesn't mean that the image is > + * free of errors) or -errno when an internal error occured. The results of the > + * check are stored in res. > */ > -int bdrv_check(BlockDriverState *bs) > +int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res) > { > if (bs->drv->bdrv_check == NULL) { > return -ENOTSUP; > } > > - return bs->drv->bdrv_check(bs); > + memset(res, 0, sizeof(*res)); > + res->corruptions = bs->drv->bdrv_check(bs); > + return res->corruptions < 0 ? res->corruptions : 0; > } > > /* commit COW file into the raw image */ > diff --git a/block.h b/block.h > index 3d03b3e..c2a7e4c 100644 > --- a/block.h > +++ b/block.h > @@ -74,7 +74,6 @@ void bdrv_close(BlockDriverState *bs); > int bdrv_attach(BlockDriverState *bs, DeviceState *qdev); > void bdrv_detach(BlockDriverState *bs, DeviceState *qdev); > DeviceState *bdrv_get_attached(BlockDriverState *bs); > -int bdrv_check(BlockDriverState *bs); > int bdrv_read(BlockDriverState *bs, int64_t sector_num, > uint8_t *buf, int nb_sectors); > int bdrv_write(BlockDriverState *bs, int64_t sector_num, > @@ -97,6 +96,15 @@ int bdrv_change_backing_file(BlockDriverState *bs, > const char *backing_file, const char *backing_fmt); > void bdrv_register(BlockDriver *bdrv); > > + > +typedef struct BdrvCheckResult { > + int corruptions; > + int leaks; > + int check_errors; > +} BdrvCheckResult; > + > +int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res); > + > /* async block I/O */ > typedef struct BlockDriverAIOCB BlockDriverAIOCB; > typedef void BlockDriverCompletionFunc(void *opaque, int ret); > diff --git a/qemu-img.c b/qemu-img.c > index 700af21..1782ac9 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -425,11 +425,20 @@ out: > return 0; > } > > +/* > + * Checks an image for consistency. Exit codes: > + * > + * 0 - Check completed, image is good > + * 1 - Check not completed because of internal errors > + * 2 - Check completed, image is corrupted > + * 3 - Check completed, image has leaked clusters, but is good otherwise > + */ > static int img_check(int argc, char **argv) > { > int c, ret; > const char *filename, *fmt; > BlockDriverState *bs; > + BdrvCheckResult result; > > fmt = NULL; > for(;;) { > @@ -453,28 +462,51 @@ static int img_check(int argc, char **argv) > if (!bs) { > return 1; > } > - ret = bdrv_check(bs); > - switch(ret) { > - case 0: > - printf("No errors were found on the image.\n"); > - break; > - case -ENOTSUP: > + ret = bdrv_check(bs, &result); > + > + if (ret == -ENOTSUP) { > error("This image format does not support checks"); > - break; > - default: > - if (ret < 0) { > - error("An error occurred during the check"); > - } else { > - printf("%d errors were found on the image.\n", ret); > + return 1; Is it okay to call bdrv_delete(bs) before return? It is necessary for the sheepdog driver to pass qemu-iotests. Kazutaka --- a/qemu-img.c +++ b/qemu-img.c @@ -466,6 +466,7 @@ static int img_check(int argc, char **argv) if (ret == -ENOTSUP) { error("This image format does not support checks"); + bdrv_delete(bs); return 1; }