From nobody Sat May 4 14:26:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495161480920946.9504533347831; Thu, 18 May 2017 19:38:00 -0700 (PDT) Received: from localhost ([::1]:56245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXnj-0005W6-4T for importer@patchew.org; Thu, 18 May 2017 22:37:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXic-0001hW-FB for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBXib-0002Oi-O9 for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBXiY-0002Hp-Vp; Thu, 18 May 2017 22:32:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F30F98004D; Fri, 19 May 2017 02:32:37 +0000 (UTC) Received: from red.redhat.com (ovpn-117-13.phx2.redhat.com [10.3.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64A0D1839C; Fri, 19 May 2017 02:32:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F30F98004D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F30F98004D From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 21:32:30 -0500 Message-Id: <20170519023233.24461-2-eblake@redhat.com> In-Reply-To: <20170519023233.24461-1-eblake@redhat.com> References: <20170519023233.24461-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 19 May 2017 02:32:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] qemu-io: Don't die on second open X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , jsnow@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Failure to open a file in qemu-io should normally return 1 on failure to end the command loop, on the presumption that when batching commands all on the command line, failure to open means nothing further can be attempted. But when executing qemu-io interactively, there is a special case: if open is executed a second time, we print a hint that the user should try the interactive 'close' first. But the hint is useless if we don't actually LET them try 'close'. This has been awkward since at least as far back as commit 43642b3, in 2011 (probably earlier, but git blame has a harder time going past the file renames at that point). Signed-off-by: Eric Blake --- qemu-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-io.c b/qemu-io.c index 34fa8a1..0c82dac 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -63,7 +63,7 @@ static int openfile(char *name, int flags, bool writethro= ugh, bool force_share, if (qemuio_blk) { error_report("file open already, try 'help close'"); QDECREF(opts); - return 1; + return 0; } if (force_share) { --=20 2.9.4 From nobody Sat May 4 14:26:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495161648092224.4281958566711; Thu, 18 May 2017 19:40:48 -0700 (PDT) Received: from localhost ([::1]:56258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXqQ-0007CM-S6 for importer@patchew.org; Thu, 18 May 2017 22:40:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXig-0001mP-Q0 for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBXif-0002TH-SU for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBXid-0002Qa-En; Thu, 18 May 2017 22:32:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E30E7F3F5; Fri, 19 May 2017 02:32:42 +0000 (UTC) Received: from red.redhat.com (ovpn-117-13.phx2.redhat.com [10.3.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24D436292C; Fri, 19 May 2017 02:32:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E30E7F3F5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4E30E7F3F5 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 21:32:31 -0500 Message-Id: <20170519023233.24461-3-eblake@redhat.com> In-Reply-To: <20170519023233.24461-1-eblake@redhat.com> References: <20170519023233.24461-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 19 May 2017 02:32:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/4] block: Guarantee that *file is set on bdrv_get_block_status() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, qemu-stable@nongnu.org, mreitz@redhat.com, Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We document that *file is valid if the return is not an error and includes BDRV_BLOCK_OFFSET_VALID, but forgot to obey this contract when a driver (such as blkdebug) lacks a callback. Broken in commit 67a0fd2 (v2.6), when we added the file parameter. Enhance qemu-iotest 177 to cover this, using a sequence that would print garbage or even SEGV, because it was dererefencing through uninitialized memory. [The resulting test output shows that we have less-than-ideal block status from the blkdebug driver, but that's a separate fix coming up soon.] Setting *file only when setting BDRV_BLOCK_OFFSET_VALID is enough to fix the crash, but we can go one step further: always setting *file, even on error, means that a caller is no longer dereferencing uninitialized memory, so that we are more likely to get a reliable SEGV instead of randomly acting on garbage. Adding an assertion doesn't hurt either. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake --- block/io.c | 4 +++- tests/qemu-iotests/177 | 3 +++ tests/qemu-iotests/177.out | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index fdd7485..164a82b 100644 --- a/block/io.c +++ b/block/io.c @@ -1749,6 +1749,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, int64_t n; int64_t ret, ret2; + *file =3D NULL; total_sectors =3D bdrv_nb_sectors(bs); if (total_sectors < 0) { return total_sectors; @@ -1769,6 +1770,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; if (bs->drv->protocol_name) { ret |=3D BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_S= IZE); + *file =3D bs; } return ret; } @@ -1783,7 +1785,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, } if (ret & BDRV_BLOCK_RAW) { - assert(ret & BDRV_BLOCK_OFFSET_VALID); + assert(ret & BDRV_BLOCK_OFFSET_VALID && *file); ret =3D bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS, *pnum, pnum, file); goto out; diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177 index 2005c17..f8ed8fb 100755 --- a/tests/qemu-iotests/177 +++ b/tests/qemu-iotests/177 @@ -43,6 +43,7 @@ _supported_proto file CLUSTER_SIZE=3D1M size=3D128M options=3Ddriver=3Dblkdebug,image.driver=3Dqcow2 +nested_opts=3Dimage.file.driver=3Dfile,image.file.filename=3D$TEST_IMG echo echo "=3D=3D setting up files =3D=3D" @@ -106,6 +107,8 @@ function verify_io() } verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --image-opts "$options,$nested_opts,align=3D4k" \ + | _filter_qemu_img_map _check_test_img diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out index e887542..b754ed4 100644 --- a/tests/qemu-iotests/177.out +++ b/tests/qemu-iotests/177.out @@ -45,5 +45,7 @@ read 30408704/30408704 bytes at offset 80740352 29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 23068672/23068672 bytes at offset 111149056 22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length File +0 0x8000000 blkdebug::TEST_DIR/t.IMGFMT No errors were found on the image. *** done --=20 2.9.4 From nobody Sat May 4 14:26:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495161383170486.5841971604482; Thu, 18 May 2017 19:36:23 -0700 (PDT) Received: from localhost ([::1]:56240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXm9-0004FC-Uc for importer@patchew.org; Thu, 18 May 2017 22:36:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXij-0001oo-8n for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBXig-0002Ts-5u for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBXie-0002Ql-7g; Thu, 18 May 2017 22:32:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 375079090F; Fri, 19 May 2017 02:32:43 +0000 (UTC) Received: from red.redhat.com (ovpn-117-13.phx2.redhat.com [10.3.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7600C1838B; Fri, 19 May 2017 02:32:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 375079090F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 375079090F From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 21:32:32 -0500 Message-Id: <20170519023233.24461-4-eblake@redhat.com> In-Reply-To: <20170519023233.24461-1-eblake@redhat.com> References: <20170519023233.24461-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 19 May 2017 02:32:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/4] block: Simplify use of BDRV_BLOCK_RAW. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Jeff Cody , jsnow@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The lone caller that cares about a return of BDRV_BLOCK_RAW completely replaces the return value, so there is no point in passing BDRV_BLOCK_DATA. Signed-off-by: Eric Blake --- block/commit.c | 2 +- block/mirror.c | 2 +- block/raw-format.c | 2 +- block/vpc.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/commit.c b/block/commit.c index 76a0d98..cf662ba 100644 --- a/block/commit.c +++ b/block/commit.c @@ -239,7 +239,7 @@ static int64_t coroutine_fn bdrv_commit_top_get_block_s= tatus( { *pnum =3D nb_sectors; *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } diff --git a/block/mirror.c b/block/mirror.c index e86f8f8..970c9f2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1047,7 +1047,7 @@ static int64_t coroutine_fn bdrv_mirror_top_get_block= _status( { *pnum =3D nb_sectors; *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } diff --git a/block/raw-format.c b/block/raw-format.c index 36e6503..1136eba 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -259,7 +259,7 @@ static int64_t coroutine_fn raw_co_get_block_status(Blo= ckDriverState *bs, *pnum =3D nb_sectors; *file =3D bs->file->bs; sector_num +=3D s->offset / BDRV_SECTOR_SIZE; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } diff --git a/block/vpc.c b/block/vpc.c index ecfee77..048504b 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -701,7 +701,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(Blo= ckDriverState *bs, if (be32_to_cpu(footer->type) =3D=3D VHD_FIXED) { *pnum =3D nb_sectors; *file =3D bs->file->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } --=20 2.9.4 From nobody Sat May 4 14:26:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495161483547511.9149146278105; Thu, 18 May 2017 19:38:03 -0700 (PDT) Received: from localhost ([::1]:56246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXnl-0005Xr-SL for importer@patchew.org; Thu, 18 May 2017 22:38:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBXik-0001pl-6J for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBXij-0002Z9-E7 for qemu-devel@nongnu.org; Thu, 18 May 2017 22:32:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36450) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBXif-0002Qz-1S; Thu, 18 May 2017 22:32:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06D2480C0A; Fri, 19 May 2017 02:32:44 +0000 (UTC) Received: from red.redhat.com (ovpn-117-13.phx2.redhat.com [10.3.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C41B17D35; Fri, 19 May 2017 02:32:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06D2480C0A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 06D2480C0A From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 21:32:33 -0500 Message-Id: <20170519023233.24461-5-eblake@redhat.com> In-Reply-To: <20170519023233.24461-1-eblake@redhat.com> References: <20170519023233.24461-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 19 May 2017 02:32:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/4] blkdebug: Support .bdrv_co_get_block_status X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , jsnow@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Without a passthrough status of BDRV_BLOCK_RAW, anything wrapped by blkdebug appears 100% allocated as data. Better is treating it the same as the underlying file being wrapped. For a quick manual test, compare this sequence, pre- and post-patch: $ qemu-img create -f qcow2 file 10M $ qemu-io -f qcow2 -c 'w 1m' file $ qemu-img map -f qcow2 file $ qemu-img map --image-opts driver=3Dblkdebug,image.driver=3Dqcow2,\ image.file.driver=3Dfile,image.file.filename=3Dfile Update iotest 177 for the new expected output. Signed-off-by: Eric Blake --- block/blkdebug.c | 11 +++++++++++ tests/qemu-iotests/177.out | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index a5196e8..1ad8d65 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -642,6 +642,16 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriv= erState *bs, return bdrv_co_pdiscard(bs->file->bs, offset, count); } +static int64_t coroutine_fn blkdebug_co_get_block_status( + BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, + BlockDriverState **file) +{ + *pnum =3D nb_sectors; + *file =3D bs->file->bs; + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | + (sector_num << BDRV_SECTOR_BITS); +} + static void blkdebug_close(BlockDriverState *bs) { BDRVBlkdebugState *s =3D bs->opaque; @@ -912,6 +922,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_co_flush_to_disk =3D blkdebug_co_flush, .bdrv_co_pwrite_zeroes =3D blkdebug_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkdebug_co_pdiscard, + .bdrv_co_get_block_status =3D blkdebug_co_get_block_status, .bdrv_debug_event =3D blkdebug_debug_event, .bdrv_debug_breakpoint =3D blkdebug_debug_breakpoint, diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out index b754ed4..43a7778 100644 --- a/tests/qemu-iotests/177.out +++ b/tests/qemu-iotests/177.out @@ -46,6 +46,9 @@ read 30408704/30408704 bytes at offset 80740352 read 23068672/23068672 bytes at offset 111149056 22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) Offset Length File -0 0x8000000 blkdebug::TEST_DIR/t.IMGFMT +0 0x800000 TEST_DIR/t.IMGFMT +0x900000 0x2400000 TEST_DIR/t.IMGFMT +0x3c00000 0x1100000 TEST_DIR/t.IMGFMT +0x6a00000 0x1600000 TEST_DIR/t.IMGFMT No errors were found on the image. *** done --=20 2.9.4