From patchwork Fri Aug 10 16:47:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 176552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4CDBB2C0040 for ; Sat, 11 Aug 2012 03:20:52 +1000 (EST) Received: from localhost ([::1]:50076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzsNw-0007sH-5y for incoming@patchwork.ozlabs.org; Fri, 10 Aug 2012 12:48:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzsNO-00072I-1e for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:47:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzsNH-00087L-SK for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:47:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzsNH-00087B-Jz for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:47:47 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7AGlkde013574 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Aug 2012 12:47:46 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-5-75.ams2.redhat.com [10.36.5.75]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7AGlVXa030123; Fri, 10 Aug 2012 12:47:45 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 10 Aug 2012 18:47:28 +0200 Message-Id: <1344617249-6620-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1344617249-6620-1-git-send-email-kwolf@redhat.com> References: <1344617249-6620-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 10/11] block: add BLOCK_O_CHECK for qemu-img check 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 From: Stefan Hajnoczi Image formats with a dirty bit, like qed and qcow2, repair dirty image files upon open with BDRV_O_RDWR. Performing automatic repair when qemu-img check runs is not ideal because the bdrv_open() call repairs the image before the actual bdrv_check() call from qemu-img.c. Fix this "double repair" since it leads to confusing output from qemu-img check. Tell the block driver that this image is being opened just for bdrv_check(). This skips automatic repair and qemu-img.c can invoke it manually with bdrv_check(). Update the golden output for qemu-iotests 039 to reflect the new qemu-img check output. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.h | 1 + block/qcow2.c | 4 ++-- block/qed.c | 2 +- qemu-img.c | 2 +- tests/qemu-iotests/039.out | 6 ++++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/block.h b/block.h index 650d872..2e2be11 100644 --- a/block.h +++ b/block.h @@ -79,6 +79,7 @@ typedef struct BlockDevOps { #define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */ #define BDRV_O_COPY_ON_READ 0x0400 /* copy read backing sectors into image */ #define BDRV_O_INCOMING 0x0800 /* consistency hint for incoming migration */ +#define BDRV_O_CHECK 0x1000 /* open solely for consistency check */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH) diff --git a/block/qcow2.c b/block/qcow2.c index 5896fd6..8f183f1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -484,8 +484,8 @@ static int qcow2_open(BlockDriverState *bs, int flags) qemu_co_mutex_init(&s->lock); /* Repair image if dirty */ - if ((s->incompatible_features & QCOW2_INCOMPAT_DIRTY) && - !bs->read_only) { + if (!(flags & BDRV_O_CHECK) && !bs->read_only && + (s->incompatible_features & QCOW2_INCOMPAT_DIRTY)) { BdrvCheckResult result = {0}; ret = qcow2_check(bs, &result, BDRV_FIX_ERRORS); diff --git a/block/qed.c b/block/qed.c index 226545d..a02dbfd 100644 --- a/block/qed.c +++ b/block/qed.c @@ -477,7 +477,7 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags) } /* If image was not closed cleanly, check consistency */ - if (s->header.features & QED_F_NEED_CHECK) { + if (!(flags & BDRV_O_CHECK) && (s->header.features & QED_F_NEED_CHECK)) { /* Read-only images cannot be fixed. There is no risk of corruption * since write operations are not possible. Therefore, allow * potentially inconsistent images to be opened read-only. This can diff --git a/qemu-img.c b/qemu-img.c index 94a31ad..b41e670 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -379,7 +379,7 @@ static int img_check(int argc, char **argv) BlockDriverState *bs; BdrvCheckResult result; int fix = 0; - int flags = BDRV_O_FLAGS; + int flags = BDRV_O_FLAGS | BDRV_O_CHECK; fmt = NULL; for(;;) { diff --git a/tests/qemu-iotests/039.out b/tests/qemu-iotests/039.out index 155a05e..cb510d6 100644 --- a/tests/qemu-iotests/039.out +++ b/tests/qemu-iotests/039.out @@ -26,6 +26,12 @@ incompatible_features 0x1 == Repairing the image file must succeed == ERROR OFLAG_COPIED: offset=8000000000050000 refcount=0 Repairing cluster 5 refcount=0 reference=1 +The following inconsistencies were found and repaired: + + 0 leaked clusters + 1 corruptions + +Double checking the fixed image now... No errors were found on the image. incompatible_features 0x0