From patchwork Thu Feb 3 16:53:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunqiang Tang X-Patchwork-Id: 81682 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 3ACCDB70EC for ; Fri, 4 Feb 2011 04:00:29 +1100 (EST) Received: from localhost ([127.0.0.1]:56407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pl2Ws-0000wz-8y for incoming@patchwork.ozlabs.org; Thu, 03 Feb 2011 11:59:34 -0500 Received: from [140.186.70.92] (port=33747 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pl2Tq-0001p7-N4 for qemu-devel@nongnu.org; Thu, 03 Feb 2011 11:57:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pl2To-0000UG-Um for qemu-devel@nongnu.org; Thu, 03 Feb 2011 11:56:26 -0500 Received: from e36.co.us.ibm.com ([32.97.110.154]:42208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pl2To-0000Tw-OR for qemu-devel@nongnu.org; Thu, 03 Feb 2011 11:56:24 -0500 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e36.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p13GpNt5011793 for ; Thu, 3 Feb 2011 09:51:23 -0700 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id p13GuNYL241402 for ; Thu, 3 Feb 2011 09:56:23 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p13GuMsW015396 for ; Thu, 3 Feb 2011 09:56:23 -0700 Received: from localhost.localdomain ([9.59.229.24]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p13GuMYX015301; Thu, 3 Feb 2011 09:56:22 -0700 From: Chunqiang Tang To: qemu-devel@nongnu.org Date: Thu, 3 Feb 2011 11:53:54 -0500 Message-Id: <1296752034-28539-1-git-send-email-ctang@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.110.154 Cc: Kevin Wolf , Stefan Hajnoczi , Chunqiang Tang Subject: [Qemu-devel] [PATCH] QCOW2: fix bug - report read success on failure 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 This patch fixes bugs in QCOW2's error handling paths of read operations. When an I/O operation fails, the QCOW2 driver mistakenly reports it as success to the uper layer. This bug was found by Fast Virtual Disk (FVD)'s fully automated testing tool, when it injected failures. Specifically, the following test triggered the bug. /bin/rm -rf /var/ramdisk/truth.raw /var/ramdisk/test.qcow2 /var/ramdisk/zero-500M.raw dd if=/dev/zero of=/var/ramdisk/truth.raw count=0 bs=1 seek=1112250368 dd if=/dev/zero of=/var/ramdisk/zero-500M.raw count=0 bs=1 seek=575525376 ./qemu-img create -f qcow2 -ocluster_size=65536,backing_fmt=blksim -b /var/ramdisk/zero-500M.raw /var/ramdisk/test.qcow2 1112250368 ./qemu-io --auto --seed=184915369 --truth=/var/ramdisk/truth.raw --format=qcow2 --test=blksim:/var/ramdisk/test.qcow2 --verify_write=true --compare_before=false --compare_after=true --round=100000 --parallel=100 --io_size=1048576 --fail_prob=0.1 --cancel_prob=0 --instant_qemubh=true Signed-off-by: Chunqiang Tang --- block/qcow2.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 8c906d1..6f6d56f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -479,8 +479,10 @@ static void qcow2_aio_read_cb(void *opaque, int ret) BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); acb->hd_aiocb = bdrv_aio_readv(bs->backing_hd, acb->sector_num, &acb->hd_qiov, n1, qcow2_aio_read_cb, acb); - if (acb->hd_aiocb == NULL) + if (acb->hd_aiocb == NULL) { + ret = -EIO; goto done; + } } else { ret = qcow2_schedule_bh(qcow2_aio_read_bh, acb); if (ret < 0) @@ -495,8 +497,10 @@ static void qcow2_aio_read_cb(void *opaque, int ret) } } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ - if (qcow2_decompress_cluster(bs, acb->cluster_offset) < 0) + if (qcow2_decompress_cluster(bs, acb->cluster_offset) < 0) { + ret = -EIO; goto done; + } qemu_iovec_from_buffer(&acb->hd_qiov, s->cluster_cache + index_in_cluster * 512,