From patchwork Thu Aug 9 12:05:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 176067 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 D99E12C008B for ; Thu, 9 Aug 2012 22:06:53 +1000 (EST) Received: from localhost ([::1]:44837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRVr-0006Lv-U0 for incoming@patchwork.ozlabs.org; Thu, 09 Aug 2012 08:06:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRVc-0005xT-2U for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:06:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzRVV-0003OX-KV for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:06:35 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:60931) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRVV-0003OH-Bt for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:06:29 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 9 Aug 2012 13:06:28 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 9 Aug 2012 13:06:05 +0100 Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q79C5w9J31064296 for ; Thu, 9 Aug 2012 12:05:58 GMT Received: from d06av10.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q79BcX5s017407 for ; Thu, 9 Aug 2012 07:38:34 -0400 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.145]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q79BcXCb017394; Thu, 9 Aug 2012 07:38:33 -0400 From: Stefan Hajnoczi To: Date: Thu, 9 Aug 2012 13:05:56 +0100 Message-Id: <1344513957-17906-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1344513957-17906-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1344513957-17906-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12080912-8372-0000-0000-0000036C3157 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.108 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 3/4] 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 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 --- 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