From nobody Sun Apr 28 14:00:14 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 1495657835511968.9822358704694; Wed, 24 May 2017 13:30:35 -0700 (PDT) Received: from localhost ([::1]:56709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDcvR-0004cO-Vn for importer@patchew.org; Wed, 24 May 2017 16:30:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDctp-0003Yg-Hr for qemu-devel@nongnu.org; Wed, 24 May 2017 16:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDcto-0005xg-JS for qemu-devel@nongnu.org; Wed, 24 May 2017 16:28:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55340) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDctm-0005wm-6L; Wed, 24 May 2017 16:28:50 -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 09E9E90C73; Wed, 24 May 2017 20:28:49 +0000 (UTC) Received: from red.redhat.com (ovpn-122-27.rdu2.redhat.com [10.10.122.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EC071710F; Wed, 24 May 2017 20:28:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 09E9E90C73 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 09E9E90C73 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 24 May 2017 15:28:38 -0500 Message-Id: <20170524202842.26724-2-eblake@redhat.com> In-Reply-To: <20170524202842.26724-1-eblake@redhat.com> References: <20170524202842.26724-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]); Wed, 24 May 2017 20:28:49 +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 v2 1/5] 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" Most callback commands in qemu-io return 0 to keep the interpreter loop running, or 1 to quit immediately. However, open_f() just passed through the return value of openfile(), which has different semantics of returning 0 if a file was opened, or 1 on any failure. As a result of mixing the return semantics, we are forcing the qemu-io interpreter to exit early on any failures, which is rather annoying when some of the failures are obviously trying to give the user a hint of how to proceed (if we didn't then kill qemu-io out from under the user's feet): $ qemu-io qemu-io> open foo qemu-io> open foo file open already, try 'help close' $ echo $? 0 Meanwhile, we WANT openfile() to report failures, as it is the way that 'qemu-io -c "$something" no_such_file' knows to exit early rather than attempting $something. So the solution is to fix open_f() to always return 0 (when we are in interactive mode, even failure to open should not end the session), and save the return value of openfile() for command line use in main(). This has been awkward since at least as far back as commit e3aff4f, in 2009. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng --- v2: fix open_f(), not openfile() --- qemu-io.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 34fa8a1..b3febc2 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -230,13 +230,14 @@ static int open_f(BlockBackend *blk, int argc, char *= *argv) qemu_opts_reset(&empty_opts); if (optind =3D=3D argc - 1) { - return openfile(argv[optind], flags, writethrough, force_share, op= ts); + openfile(argv[optind], flags, writethrough, force_share, opts); } else if (optind =3D=3D argc) { - return openfile(NULL, flags, writethrough, force_share, opts); + openfile(NULL, flags, writethrough, force_share, opts); } else { QDECREF(opts); - return qemuio_command_usage(&open_cmd); + qemuio_command_usage(&open_cmd); } + return 0; } static int quit_f(BlockBackend *blk, int argc, char **argv) --=20 2.9.4 From nobody Sun Apr 28 14:00:14 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 1495658020337572.6593580184627; Wed, 24 May 2017 13:33:40 -0700 (PDT) Received: from localhost ([::1]:56720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDcyP-0007KQ-Vy for importer@patchew.org; Wed, 24 May 2017 16:33:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDctx-0003gd-Tp for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDctw-00061U-Mb for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDctr-0005yI-VH; Wed, 24 May 2017 16:28:56 -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 EA45FC054C58; Wed, 24 May 2017 20:28:54 +0000 (UTC) Received: from red.redhat.com (ovpn-122-27.rdu2.redhat.com [10.10.122.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44BF41710F; Wed, 24 May 2017 20:28:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EA45FC054C58 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EA45FC054C58 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 24 May 2017 15:28:39 -0500 Message-Id: <20170524202842.26724-3-eblake@redhat.com> In-Reply-To: <20170524202842.26724-1-eblake@redhat.com> References: <20170524202842.26724-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.32]); Wed, 24 May 2017 20:28:55 +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 v2 2/5] 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 on all paths that return 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 broken caller that blindly dereferences file without checking for error is now more likely to get a reliable SEGV instead of randomly acting on garbage, making it easier to diagnose such buggy callers. Adding an assertion that file is set where expected doesn't hurt either. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Max Reitz --- v2: drop redundant assignment --- block/io.c | 5 +++-- tests/qemu-iotests/177 | 3 +++ tests/qemu-iotests/177.out | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index fdd7485..8e6c3fe 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,11 +1770,11 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(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; } - *file =3D NULL; bdrv_inc_in_flight(bs); ret =3D bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, = pnum, file); @@ -1783,7 +1784,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 Sun Apr 28 14:00:14 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 1495658094388320.2811021826453; Wed, 24 May 2017 13:34:54 -0700 (PDT) Received: from localhost ([::1]:56726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDczc-0007wX-UR for importer@patchew.org; Wed, 24 May 2017 16:34:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDcty-0003hC-F3 for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDctx-00061t-8M for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDctt-0005ys-Mn; Wed, 24 May 2017 16:28:57 -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 A9D3513A60; Wed, 24 May 2017 20:28:56 +0000 (UTC) Received: from red.redhat.com (ovpn-122-27.rdu2.redhat.com [10.10.122.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E6A71710F; Wed, 24 May 2017 20:28:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9D3513A60 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 A9D3513A60 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 24 May 2017 15:28:40 -0500 Message-Id: <20170524202842.26724-4-eblake@redhat.com> In-Reply-To: <20170524202842.26724-1-eblake@redhat.com> References: <20170524202842.26724-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]); Wed, 24 May 2017 20:28:56 +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 v2 3/5] block: Allow NULL file for 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, Jeff Cody , 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" Not all callers care about which BDS owns the mapping for a given range of the file. This patch merely simplifies the callers by consolidating the logic in the common call point, while guaranteeing a non-NULL file to all the driver callbacks, for no semantic change. However, this will also set the stage for a future cleanup: when a caller does not care about which BDS owns an offset, it would be nice to allow the driver to optimize things to not have to return BDRV_BLOCK_OFFSET_VALID in the first place. In the case of fragmented allocation (for example, it's fairly easy to create a qcow2 image where consecutive guest addresses are not at consecutive host addresses), the current contract requires bdrv_get_block_status() to clamp *pnum to the limit where host addresses are no longer consecutive, but allowing a NULL file means that *pnum could be set to the full length of known-allocated data. Signed-off-by: Eric Blake --- v2: new patch --- block/io.c | 15 +++++++++------ block/mirror.c | 3 +-- block/qcow2.c | 4 +--- qemu-img.c | 10 ++++------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/block/io.c b/block/io.c index 8e6c3fe..eea74cb 100644 --- a/block/io.c +++ b/block/io.c @@ -706,7 +706,6 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags f= lags) { int64_t target_sectors, ret, nb_sectors, sector_num =3D 0; BlockDriverState *bs =3D child->bs; - BlockDriverState *file; int n; target_sectors =3D bdrv_nb_sectors(bs); @@ -719,7 +718,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags f= lags) if (nb_sectors <=3D 0) { return 0; } - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &n, &fil= e); + ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &n, NULL= ); if (ret < 0) { error_report("error getting block status at sector %" PRId64 "= : %s", sector_num, strerror(-ret)); @@ -1737,8 +1736,9 @@ typedef struct BdrvCoGetBlockStatusData { * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors g= oes * beyond the end of the disk image it will be clamped. * - * If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, '= file' - * points to the BDS which the sector range is allocated in. + * If returned value is positive, BDRV_BLOCK_OFFSET_VALID bit is set, and + * 'file' is non-NULL, then '*file' points to the BDS which the sector ran= ge + * is allocated in. */ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, int64_t sector_num, @@ -1748,7 +1748,11 @@ static int64_t coroutine_fn bdrv_co_get_block_status= (BlockDriverState *bs, int64_t total_sectors; int64_t n; int64_t ret, ret2; + BlockDriverState *tmpfile; + if (!file) { + file =3D &tmpfile; + } *file =3D NULL; total_sectors =3D bdrv_nb_sectors(bs); if (total_sectors < 0) { @@ -1916,9 +1920,8 @@ int64_t bdrv_get_block_status(BlockDriverState *bs, int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_nu= m, int nb_sectors, int *pnum) { - BlockDriverState *file; int64_t ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, pnum, - &file); + NULL); if (ret < 0) { return ret; } diff --git a/block/mirror.c b/block/mirror.c index e86f8f8..4563ba7 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -392,7 +392,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) while (nb_chunks > 0 && sector_num < end) { int64_t ret; int io_sectors, io_sectors_acct; - BlockDriverState *file; enum MirrorMethod { MIRROR_METHOD_COPY, MIRROR_METHOD_ZERO, @@ -402,7 +401,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) assert(!(sector_num % sectors_per_chunk)); ret =3D bdrv_get_block_status_above(source, NULL, sector_num, nb_chunks * sectors_per_chunk, - &io_sectors, &file); + &io_sectors, NULL); if (ret < 0) { io_sectors =3D MIN(nb_chunks * sectors_per_chunk, max_io_secto= rs); } else if (ret & BDRV_BLOCK_DATA) { diff --git a/block/qcow2.c b/block/qcow2.c index b3ba5da..8e9e29b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2448,7 +2448,6 @@ static bool is_zero_sectors(BlockDriverState *bs, int= 64_t start, uint32_t count) { int nr; - BlockDriverState *file; int64_t res; if (start + count > bs->total_sectors) { @@ -2458,8 +2457,7 @@ static bool is_zero_sectors(BlockDriverState *bs, int= 64_t start, if (!count) { return true; } - res =3D bdrv_get_block_status_above(bs, NULL, start, count, - &nr, &file); + res =3D bdrv_get_block_status_above(bs, NULL, start, count, &nr, NULL); return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr =3D=3D count; } diff --git a/qemu-img.c b/qemu-img.c index 5aef8ef..cb78696 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1398,7 +1398,6 @@ static int img_compare(int argc, char **argv) for (;;) { int64_t status1, status2; - BlockDriverState *file; nb_sectors =3D sectors_to_process(total_sectors, sector_num); if (nb_sectors <=3D 0) { @@ -1406,7 +1405,7 @@ static int img_compare(int argc, char **argv) } status1 =3D bdrv_get_block_status_above(bs1, NULL, sector_num, total_sectors1 - sector_num, - &pnum1, &file); + &pnum1, NULL); if (status1 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename1= ); @@ -1416,7 +1415,7 @@ static int img_compare(int argc, char **argv) status2 =3D bdrv_get_block_status_above(bs2, NULL, sector_num, total_sectors2 - sector_num, - &pnum2, &file); + &pnum2, NULL); if (status2 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename2= ); @@ -1615,15 +1614,14 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) n =3D MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); if (s->sector_next_status <=3D sector_num) { - BlockDriverState *file; if (s->target_has_backing) { ret =3D bdrv_get_block_status(blk_bs(s->src[src_cur]), sector_num - src_cur_offset, - n, &n, &file); + n, &n, NULL); } else { ret =3D bdrv_get_block_status_above(blk_bs(s->src[src_cur]), N= ULL, sector_num - src_cur_offset, - n, &n, &file); + n, &n, NULL); } if (ret < 0) { return ret; --=20 2.9.4 From nobody Sun Apr 28 14:00:14 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 1495657848423204.70770451967928; Wed, 24 May 2017 13:30:48 -0700 (PDT) Received: from localhost ([::1]:56710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDcvf-0004lJ-4n for importer@patchew.org; Wed, 24 May 2017 16:30:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDcty-0003hM-KY for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDctx-000626-O5 for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53750) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDctu-00060Q-T0; Wed, 24 May 2017 16:28:59 -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 D742061D0F; Wed, 24 May 2017 20:28:57 +0000 (UTC) Received: from red.redhat.com (ovpn-122-27.rdu2.redhat.com [10.10.122.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id E57651710F; Wed, 24 May 2017 20:28:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D742061D0F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D742061D0F From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 24 May 2017 15:28:41 -0500 Message-Id: <20170524202842.26724-5-eblake@redhat.com> In-Reply-To: <20170524202842.26724-1-eblake@redhat.com> References: <20170524202842.26724-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.39]); Wed, 24 May 2017 20:28:58 +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 v2 4/5] 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 (namely, io.c:bdrv_co_get_block_status) completely replaces the return value, so there is no point in passing BDRV_BLOCK_DATA. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng --- v2: fix subject, tweak commit message --- 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 4563ba7..432d58d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1046,7 +1046,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 Sun Apr 28 14:00:14 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 1495657981735680.5939874154491; Wed, 24 May 2017 13:33:01 -0700 (PDT) Received: from localhost ([::1]:56719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDcxo-0006fU-9X for importer@patchew.org; Wed, 24 May 2017 16:33:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDctz-0003iG-Hs for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDcty-00062V-9E for qemu-devel@nongnu.org; Wed, 24 May 2017 16:29:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40858) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDctv-00060s-VT; Wed, 24 May 2017 16:29:00 -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 E9AE485545; Wed, 24 May 2017 20:28:58 +0000 (UTC) Received: from red.redhat.com (ovpn-122-27.rdu2.redhat.com [10.10.122.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B96F1710F; Wed, 24 May 2017 20:28:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E9AE485545 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E9AE485545 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 24 May 2017 15:28:42 -0500 Message-Id: <20170524202842.26724-6-eblake@redhat.com> In-Reply-To: <20170524202842.26724-1-eblake@redhat.com> References: <20170524202842.26724-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.28]); Wed, 24 May 2017 20:28:59 +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 v2 5/5] 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. Update iotest 177 for the new expected output. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Max Reitz --- v2: tweak commit message --- 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