From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780354511166.37997562723092; Wed, 11 Oct 2017 20:52:34 -0700 (PDT) Received: from localhost ([::1]:43543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UXx-00066T-ID for importer@patchew.org; Wed, 11 Oct 2017 23:52:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTD-0002Rf-7z for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTB-0007CE-Eh for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36784) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UT7-00077J-AM; Wed, 11 Oct 2017 23:47:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 530113DBCE; Thu, 12 Oct 2017 03:47:32 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D08B675F0; Thu, 12 Oct 2017 03:47:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 530113DBCE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:46:57 -0500 Message-Id: <20171012034720.11947-2-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 03:47:32 +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 v6 01/24] 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Jeff Cody , Max Reitz , 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. The only caller that does not care about pnum is bdrv_is_allocated, as invoked by vvfat; we can likewise add assertions that the rest of the stack does not have to worry about a NULL pnum. Furthermore, 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 --- v6: drop local_pnum experiment, tweak label indent [Kevin] v5: use second label for cleaner exit logic [John], use local_pnum v4: only context changes v3: rebase to recent changes (qcow2_measure), dropped R-b v2: use local variable and final transfer, rather than assignment of parameter to local [previously in different series]: v2: new patch, https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg056= 45.html --- include/block/block_int.h | 10 ++++++---- block/io.c | 49 ++++++++++++++++++++++++++-----------------= ---- block/mirror.c | 3 +-- block/qcow2.c | 8 ++------ qemu-img.c | 10 ++++------ 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 7e8a206239..489b390fd6 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -202,10 +202,12 @@ struct BlockDriver { int64_t offset, int bytes); /* - * Building block for bdrv_block_status[_above]. The driver should - * answer only according to the current layer, and should not - * set BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h - * for the meaning of _DATA, _ZERO, and _OFFSET_VALID. + * Building block for bdrv_block_status[_above] and + * bdrv_is_allocated[_above]. The driver should answer only + * according to the current layer, and should not set + * BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h + * for the meaning of _DATA, _ZERO, and _OFFSET_VALID. The block + * layer guarantees non-NULL pnum and file. */ int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, diff --git a/block/io.c b/block/io.c index 8e419070b5..51d2b219b8 100644 --- a/block/io.c +++ b/block/io.c @@ -698,7 +698,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); @@ -711,7 +710,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)); @@ -1800,8 +1799,9 @@ int64_t coroutine_fn bdrv_co_get_block_status_from_ba= cking(BlockDriverState *bs, * beyond the end of the disk image it will be clamped; if 'pnum' is set to * the end of the image, then the returned value will include BDRV_BLOCK_E= OF. * - * 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, @@ -1811,20 +1811,23 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, int64_t total_sectors; int64_t n; int64_t ret, ret2; + BlockDriverState *local_file =3D NULL; - *file =3D NULL; + assert(pnum); + *pnum =3D 0; total_sectors =3D bdrv_nb_sectors(bs); if (total_sectors < 0) { - return total_sectors; + ret =3D total_sectors; + goto early_out; } if (sector_num >=3D total_sectors) { - *pnum =3D 0; - return BDRV_BLOCK_EOF; + ret =3D BDRV_BLOCK_EOF; + goto early_out; } if (!nb_sectors) { - *pnum =3D 0; - return 0; + ret =3D 0; + goto early_out; } n =3D total_sectors - sector_num; @@ -1840,23 +1843,23 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, } if (bs->drv->protocol_name) { ret |=3D BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_S= IZE); - *file =3D bs; + local_file =3D bs; } - return ret; + goto early_out; } bdrv_inc_in_flight(bs); ret =3D bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, = pnum, - file); + &local_file); if (ret < 0) { *pnum =3D 0; goto out; } if (ret & BDRV_BLOCK_RAW) { - assert(ret & BDRV_BLOCK_OFFSET_VALID && *file); - ret =3D bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS, - *pnum, pnum, file); + assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file); + ret =3D bdrv_co_get_block_status(local_file, ret >> BDRV_SECTOR_BI= TS, + *pnum, pnum, &local_file); goto out; } @@ -1874,14 +1877,13 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, } } - if (*file && *file !=3D bs && + if (local_file && local_file !=3D bs && (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID)) { - BlockDriverState *file2; int file_pnum; - ret2 =3D bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS, - *pnum, &file_pnum, &file2); + ret2 =3D bdrv_co_get_block_status(local_file, ret >> BDRV_SECTOR_B= ITS, + *pnum, &file_pnum, NULL); if (ret2 >=3D 0) { /* Ignore errors. This is just providing extra information, it * is useful but not necessary. @@ -1907,6 +1909,10 @@ out: if (ret >=3D 0 && sector_num + *pnum =3D=3D total_sectors) { ret |=3D BDRV_BLOCK_EOF; } +early_out: + if (file) { + *file =3D local_file; + } return ret; } @@ -2006,7 +2012,6 @@ int64_t bdrv_get_block_status(BlockDriverState *bs, int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum) { - BlockDriverState *file; int64_t sector_num =3D offset >> BDRV_SECTOR_BITS; int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; int64_t ret; @@ -2015,7 +2020,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE) && bytes < INT_MAX); ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &psectors, - &file); + NULL); if (ret < 0) { return ret; } diff --git a/block/mirror.c b/block/mirror.c index 153758ca9f..e76e754d26 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -390,7 +390,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) int io_sectors; unsigned int io_bytes; int64_t io_bytes_acct; - BlockDriverState *file; enum MirrorMethod { MIRROR_METHOD_COPY, MIRROR_METHOD_ZERO, @@ -401,7 +400,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) ret =3D bdrv_get_block_status_above(source, NULL, offset >> BDRV_SECTOR_BITS, nb_chunks * sectors_per_chunk, - &io_sectors, &file); + &io_sectors, NULL); io_bytes =3D io_sectors * BDRV_SECTOR_SIZE; if (ret < 0) { io_bytes =3D MIN(nb_chunks * s->granularity, max_io_bytes); diff --git a/block/qcow2.c b/block/qcow2.c index d742b146da..990917096f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3003,7 +3003,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) { @@ -3013,8 +3012,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; } @@ -3732,13 +3730,11 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *op= ts, BlockDriverState *in_bs, offset +=3D pnum * BDRV_SECTOR_SIZE) { int nb_sectors =3D MIN(ssize - offset, BDRV_REQUEST_MAX_BYTES) / BDRV_SECTOR= _SIZE; - BlockDriverState *file; int64_t ret; ret =3D bdrv_get_block_status_above(in_bs, NULL, offset >> BDRV_SECTOR_BI= TS, - nb_sectors, - &pnum, &file); + nb_sectors, &pnum, NULL); if (ret < 0) { error_setg_errno(&local_err, -ret, "Unable to get block status"); diff --git a/qemu-img.c b/qemu-img.c index d6007b2a6d..e9c7b30c91 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1375,7 +1375,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) { @@ -1383,7 +1382,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= ); @@ -1393,7 +1392,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= ); @@ -1599,15 +1598,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.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780585854394.1959184086551; Wed, 11 Oct 2017 20:56:25 -0700 (PDT) Received: from localhost ([::1]:43570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Ubc-0000md-3h for importer@patchew.org; Wed, 11 Oct 2017 23:56:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTF-0002U4-CN for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTC-0007Co-7a for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43110) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UT8-00078P-Rt; Wed, 11 Oct 2017 23:47:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D95F14A6F0; Thu, 12 Oct 2017 03:47:33 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 961F16954A; Thu, 12 Oct 2017 03:47:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D95F14A6F0 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:46:58 -0500 Message-Id: <20171012034720.11947-3-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 12 Oct 2017 03:47:34 +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 v6 02/24] block: Add flag to avoid wasted work in bdrv_is_allocated() 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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, or where the zeroes lie within that mapping. In particular, bdrv_is_allocated() cares more about finding the largest run of allocated data from the guest perspective, whether or not that data is consecutive from the host perspective, and whether or not the data reads as zero. Therefore, doing subsequent refinements such as checking how much of the format-layer allocation also satisfies BDRV_BLOCK_ZERO at the protocol layer is wasted work - in the best case, it just costs extra CPU cycles during a single bdrv_is_allocated(), but in the worst case, it results in a smaller *pnum, and forces callers to iterate through more status probes when visiting the entire file for even more extra CPU cycles. This patch only optimizes the block layer (no behavior change when want_zero is true, but skip unnecessary effort when it is false). Then when subsequent patches tweak the driver callback to be byte-based, we can also pass this hint through to the driver. Tweak BdrvCoGetBlockStatusData to declare arguments in parameter order, rather than mixing things up (minimizing padding is not necessary here). Signed-off-by: Eric Blake --- v6: rebase to previous changes, s/mapping/need_zero/, tweak struct layout, drop R-b v5: tweak commit message and one comment, rebase to previous changes, minor enough to still add R-b v4: only context changes v3: s/allocation/mapping/ and flip sense of bool v2: new patch --- block/io.c | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index 51d2b219b8..0c87e9d8b3 100644 --- a/block/io.c +++ b/block/io.c @@ -1749,10 +1749,11 @@ int bdrv_flush_all(void) typedef struct BdrvCoGetBlockStatusData { BlockDriverState *bs; BlockDriverState *base; - BlockDriverState **file; + bool want_zero; int64_t sector_num; int nb_sectors; int *pnum; + BlockDriverState **file; int64_t ret; bool done; } BdrvCoGetBlockStatusData; @@ -1788,6 +1789,11 @@ int64_t coroutine_fn bdrv_co_get_block_status_from_b= acking(BlockDriverState *bs, * Drivers not implementing the functionality are assumed to not support * backing files, hence all their sectors are reported as allocated. * + * If 'want_zero' is true, the caller is querying for mapping purposes, + * and the result should include BDRV_BLOCK_OFFSET_VALID and + * BDRV_BLOCK_ZERO where possible; otherwise, the result may omit those + * bits particularly if it allows for a larger value in 'pnum'. + * * If 'sector_num' is beyond the end of the disk image the return value is * BDRV_BLOCK_EOF and 'pnum' is set to 0. * @@ -1804,6 +1810,7 @@ int64_t coroutine_fn bdrv_co_get_block_status_from_ba= cking(BlockDriverState *bs, * is allocated in. */ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, + bool want_zero, int64_t sector_num, int nb_sectors, int *= pnum, BlockDriverState **fi= le) @@ -1858,31 +1865,34 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, if (ret & BDRV_BLOCK_RAW) { assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file); - ret =3D bdrv_co_get_block_status(local_file, ret >> BDRV_SECTOR_BI= TS, + ret =3D bdrv_co_get_block_status(local_file, want_zero, + ret >> BDRV_SECTOR_BITS, *pnum, pnum, &local_file); goto out; } if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) { ret |=3D BDRV_BLOCK_ALLOCATED; - } else { + } else if (want_zero) { if (bdrv_unallocated_blocks_are_zero(bs)) { ret |=3D BDRV_BLOCK_ZERO; } else if (bs->backing) { BlockDriverState *bs2 =3D bs->backing->bs; int64_t nb_sectors2 =3D bdrv_nb_sectors(bs2); + if (nb_sectors2 >=3D 0 && sector_num >=3D nb_sectors2) { ret |=3D BDRV_BLOCK_ZERO; } } } - if (local_file && local_file !=3D bs && + if (want_zero && local_file && local_file !=3D bs && (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID)) { int file_pnum; - ret2 =3D bdrv_co_get_block_status(local_file, ret >> BDRV_SECTOR_B= ITS, + ret2 =3D bdrv_co_get_block_status(local_file, want_zero, + ret >> BDRV_SECTOR_BITS, *pnum, &file_pnum, NULL); if (ret2 >=3D 0) { /* Ignore errors. This is just providing extra information, it @@ -1918,6 +1928,7 @@ early_out: static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverStat= e *bs, BlockDriverState *base, + bool want_zero, int64_t sector_num, int nb_sectors, int *pnum, @@ -1929,7 +1940,8 @@ static int64_t coroutine_fn bdrv_co_get_block_status_= above(BlockDriverState *bs, assert(bs !=3D base); for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { - ret =3D bdrv_co_get_block_status(p, sector_num, nb_sectors, pnum, = file); + ret =3D bdrv_co_get_block_status(p, want_zero, sector_num, nb_sect= ors, + pnum, file); if (ret < 0) { break; } @@ -1959,6 +1971,7 @@ static void coroutine_fn bdrv_get_block_status_above_= co_entry(void *opaque) BdrvCoGetBlockStatusData *data =3D opaque; data->ret =3D bdrv_co_get_block_status_above(data->bs, data->base, + data->want_zero, data->sector_num, data->nb_sectors, data->pnum, @@ -1971,20 +1984,22 @@ static void coroutine_fn bdrv_get_block_status_abov= e_co_entry(void *opaque) * * See bdrv_co_get_block_status_above() for details. */ -int64_t bdrv_get_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +static int64_t bdrv_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t sector_num, + int nb_sectors, int *pnum, + BlockDriverState **file) { Coroutine *co; BdrvCoGetBlockStatusData data =3D { .bs =3D bs, .base =3D base, - .file =3D file, + .want_zero =3D want_zero, .sector_num =3D sector_num, .nb_sectors =3D nb_sectors, .pnum =3D pnum, + .file =3D file, .done =3D false, }; @@ -2000,6 +2015,16 @@ int64_t bdrv_get_block_status_above(BlockDriverState= *bs, return data.ret; } +int64_t bdrv_get_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + int64_t sector_num, + int nb_sectors, int *pnum, + BlockDriverState **file) +{ + return bdrv_common_block_status_above(bs, base, true, sector_num, + nb_sectors, pnum, file); +} + int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, @@ -2012,15 +2037,15 @@ int64_t bdrv_get_block_status(BlockDriverState *bs, int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum) { - int64_t sector_num =3D offset >> BDRV_SECTOR_BITS; - int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; int64_t ret; int psectors; assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE) && bytes < INT_MAX); - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &psectors, - NULL); + ret =3D bdrv_common_block_status_above(bs, backing_bs(bs), false, + offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &psect= ors, + NULL); if (ret < 0) { return ret; } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507780215479258.1256458752016; Wed, 11 Oct 2017 20:50:15 -0700 (PDT) Received: from localhost ([::1]:43531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UVf-00045k-Lv for importer@patchew.org; Wed, 11 Oct 2017 23:50:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTG-0002VV-L1 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTF-0007GA-HY for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTA-0007BQ-TH; Wed, 11 Oct 2017 23:47:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3BD09093E; Thu, 12 Oct 2017 03:47:35 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BAED6954A; Thu, 12 Oct 2017 03:47:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E3BD09093E 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:46:59 -0500 Message-Id: <20171012034720.11947-4-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 12 Oct 2017 03:47:36 +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 v6 03/24] block: Make bdrv_round_to_clusters() signature more useful 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Jeff Cody , Max Reitz , 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" In the process of converting sector-based interfaces to bytes, I'm finding it easier to represent a byte count as a 64-bit integer at the block layer (even if we are internally capped by SIZE_MAX or even INT_MAX for individual transactions, it's still nicer to not have to worry about truncation/overflow issues on as many variables). Update the signature of bdrv_round_to_clusters() to uniformly use int64_t, matching the signature already chosen for bdrv_is_allocated and the fact that off_t is also a signed type, then adjust clients according to the required fallout (even where the result could now exceed 32 bits, no client is directly assigning the result into a 32-bit value without breaking things into a loop first). Signed-off-by: Eric Blake --- v5: depends on copy-on-read fixes [John], fix incorrect trace, update commit message to document rounding considerations, drop R-b v4: only context changes v3: no change v2: fix commit message [John], rebase to earlier changes, including mirror_clip_bytes() signature update --- include/block/block.h | 4 ++-- block/io.c | 6 +++--- block/mirror.c | 7 +++---- block/trace-events | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index d5c2731a03..440f3e9e39 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -474,9 +474,9 @@ int bdrv_get_flags(BlockDriverState *bs); int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs); void bdrv_round_to_clusters(BlockDriverState *bs, - int64_t offset, unsigned int bytes, + int64_t offset, int64_t bytes, int64_t *cluster_offset, - unsigned int *cluster_bytes); + int64_t *cluster_bytes); const char *bdrv_get_encrypted_filename(BlockDriverState *bs); void bdrv_get_backing_filename(BlockDriverState *bs, diff --git a/block/io.c b/block/io.c index 0c87e9d8b3..20b4cb456c 100644 --- a/block/io.c +++ b/block/io.c @@ -449,9 +449,9 @@ static void mark_request_serialising(BdrvTrackedRequest= *req, uint64_t align) * Round a region to cluster boundaries */ void bdrv_round_to_clusters(BlockDriverState *bs, - int64_t offset, unsigned int bytes, + int64_t offset, int64_t bytes, int64_t *cluster_offset, - unsigned int *cluster_bytes) + int64_t *cluster_bytes) { BlockDriverInfo bdi; @@ -949,7 +949,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvCh= ild *child, struct iovec iov; QEMUIOVector local_qiov; int64_t cluster_offset; - unsigned int cluster_bytes; + int64_t cluster_bytes; size_t skip_bytes; int ret; int max_transfer =3D MIN_NON_ZERO(bs->bl.max_transfer, diff --git a/block/mirror.c b/block/mirror.c index e76e754d26..d11706c566 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -190,10 +190,9 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t= *offset, bool need_cow; int ret =3D 0; int64_t align_offset =3D *offset; - unsigned int align_bytes =3D *bytes; + int64_t align_bytes =3D *bytes; int max_bytes =3D s->granularity * s->max_iov; - assert(*bytes < INT_MAX); need_cow =3D !test_bit(*offset / s->granularity, s->cow_bitmap); need_cow |=3D !test_bit((*offset + *bytes - 1) / s->granularity, s->cow_bitmap); @@ -388,7 +387,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) while (nb_chunks > 0 && offset < s->bdev_length) { int64_t ret; int io_sectors; - unsigned int io_bytes; + int64_t io_bytes; int64_t io_bytes_acct; enum MirrorMethod { MIRROR_METHOD_COPY, @@ -413,7 +412,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) io_bytes =3D s->granularity; } else if (ret >=3D 0 && !(ret & BDRV_BLOCK_DATA)) { int64_t target_offset; - unsigned int target_bytes; + int64_t target_bytes; bdrv_round_to_clusters(blk_bs(s->target), offset, io_bytes, &target_offset, &target_bytes); if (target_offset =3D=3D offset && diff --git a/block/trace-events b/block/trace-events index 25dd5a3026..11c8d5f590 100644 --- a/block/trace-events +++ b/block/trace-events @@ -12,7 +12,7 @@ blk_co_pwritev(void *blk, void *bs, int64_t offset, unsig= ned int bytes, int flag bdrv_co_preadv(void *bs, int64_t offset, int64_t nbytes, unsigned int flag= s) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwritev(void *bs, int64_t offset, int64_t nbytes, unsigned int fla= gs) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs = %p offset %"PRId64" count %d flags 0x%x" -bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int= 64_t cluster_offset, unsigned int cluster_bytes) "bs %p offset %"PRId64" by= tes %u cluster_offset %"PRId64" cluster_bytes %u" +bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int= 64_t cluster_offset, int64_t cluster_bytes) "bs %p offset %"PRId64" bytes %= u cluster_offset %"PRId64" cluster_bytes %"PRId64 # block/stream.c stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_alloc= ated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d" --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780374842444.53903416301307; Wed, 11 Oct 2017 20:52:54 -0700 (PDT) Received: from localhost ([::1]:43544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UYI-0006N1-37 for importer@patchew.org; Wed, 11 Oct 2017 23:52:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTH-0002Wl-J3 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTG-0007Ha-MT for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTC-0007D1-Un; Wed, 11 Oct 2017 23:47:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F02D325774; Thu, 12 Oct 2017 03:47:37 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C04A6954A; Thu, 12 Oct 2017 03:47:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F02D325774 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:00 -0500 Message-Id: <20171012034720.11947-5-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 12 Oct 2017 03:47: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 v6 04/24] qcow2: Switch is_zero_sectors() to byte-based 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change), and rename it to is_zero() in the process. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow --- v6: tweak comments to add TODO for later in series [Kevin], minor enough to keep R-b v3-v5: no change v2: rename function, rebase to upstream changes --- block/qcow2.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 990917096f..df53535455 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2999,21 +2999,29 @@ finish: } -static bool is_zero_sectors(BlockDriverState *bs, int64_t start, - uint32_t count) +static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) { int nr; int64_t res; + int64_t start; - if (start + count > bs->total_sectors) { - count =3D bs->total_sectors - start; + /* TODO: Widening to sector boundaries should only be needed as + * long as we can't query finer granularity. */ + start =3D QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); + bytes =3D QEMU_ALIGN_UP(offset + bytes, BDRV_SECTOR_SIZE) - start; + + /* Clamp to image length, before checking status of underlying sectors= */ + if (start + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { + bytes =3D bs->total_sectors * BDRV_SECTOR_SIZE - start; } - if (!count) { + if (!bytes) { return true; } - 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; + res =3D bdrv_get_block_status_above(bs, NULL, start >> BDRV_SECTOR_BIT= S, + bytes >> BDRV_SECTOR_BITS, &nr, NULL= ); + return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && + nr * BDRV_SECTOR_SIZE =3D=3D bytes; } static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, @@ -3031,24 +3039,21 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(Bloc= kDriverState *bs, } if (head || tail) { - int64_t cl_start =3D (offset - head) >> BDRV_SECTOR_BITS; uint64_t off; unsigned int nr; assert(head + bytes <=3D s->cluster_size); /* check whether remainder of cluster already reads as zero */ - if (!(is_zero_sectors(bs, cl_start, - DIV_ROUND_UP(head, BDRV_SECTOR_SIZE)) && - is_zero_sectors(bs, (offset + bytes) >> BDRV_SECTOR_BITS, - DIV_ROUND_UP(-tail & (s->cluster_size - 1), - BDRV_SECTOR_SIZE)))) { + if (!(is_zero(bs, offset - head, head) && + is_zero(bs, offset + bytes, + tail ? s->cluster_size - tail : 0))) { return -ENOTSUP; } qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ - offset =3D cl_start << BDRV_SECTOR_BITS; + offset =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); bytes =3D s->cluster_size; nr =3D s->cluster_size; ret =3D qcow2_get_cluster_offset(bs, offset, &nr, &off); --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507780221246460.724179413151; Wed, 11 Oct 2017 20:50:21 -0700 (PDT) Received: from localhost ([::1]:43530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UVY-000418-Mu for importer@patchew.org; Wed, 11 Oct 2017 23:50:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTI-0002Xp-Lf for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTH-0007IE-P2 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48762) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTF-0007Ew-4C; Wed, 11 Oct 2017 23:47:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2108882102; Thu, 12 Oct 2017 03:47:40 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5813C60C82; Thu, 12 Oct 2017 03:47:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2108882102 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:01 -0500 Message-Id: <20171012034720.11947-6-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 12 Oct 2017 03:47:40 +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 v6 05/24] block: Switch bdrv_make_zero() to byte-based 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of zeroing a device to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are sector-aligned). Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow --- v3-v5: no change v2: rebase to earlier changes --- block/io.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index 20b4cb456c..e9604f0d00 100644 --- a/block/io.c +++ b/block/io.c @@ -696,38 +696,38 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offs= et, */ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) { - int64_t target_sectors, ret, nb_sectors, sector_num =3D 0; + int64_t target_size, ret, bytes, offset =3D 0; BlockDriverState *bs =3D child->bs; - int n; + int n; /* sectors */ - target_sectors =3D bdrv_nb_sectors(bs); - if (target_sectors < 0) { - return target_sectors; + target_size =3D bdrv_getlength(bs); + if (target_size < 0) { + return target_size; } for (;;) { - nb_sectors =3D MIN(target_sectors - sector_num, BDRV_REQUEST_MAX_S= ECTORS); - if (nb_sectors <=3D 0) { + bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <=3D 0) { return 0; } - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &n, NULL= ); + ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &n, NULL); if (ret < 0) { - error_report("error getting block status at sector %" PRId64 "= : %s", - sector_num, strerror(-ret)); + error_report("error getting block status at offset %" PRId64 "= : %s", + offset, strerror(-ret)); return ret; } if (ret & BDRV_BLOCK_ZERO) { - sector_num +=3D n; + offset +=3D n * BDRV_SECTOR_BITS; continue; } - ret =3D bdrv_pwrite_zeroes(child, sector_num << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, flags); + ret =3D bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, fl= ags); if (ret < 0) { - error_report("error writing zeroes at sector %" PRId64 ": %s", - sector_num, strerror(-ret)); + error_report("error writing zeroes at offset %" PRId64 ": %s", + offset, strerror(-ret)); return ret; } - sector_num +=3D n; + offset +=3D n * BDRV_SECTOR_SIZE; } } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780390359171.37422142180378; Wed, 11 Oct 2017 20:53:10 -0700 (PDT) Received: from localhost ([::1]:43546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UYX-0006Yz-Ip for importer@patchew.org; Wed, 11 Oct 2017 23:53:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTQ-0002d2-J0 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTP-0007O4-N0 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55274) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTL-0007Jw-0w; Wed, 11 Oct 2017 23:47:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AF3F7E458; Thu, 12 Oct 2017 03:47:46 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C81F17BB1; Thu, 12 Oct 2017 03:47:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AF3F7E458 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:02 -0500 Message-Id: <20171012034720.11947-7-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 03:47:46 +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 v6 06/24] qemu-img: Switch get_block_status() to byte-based 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Continue by converting an internal function (no semantic change), and simplifying its caller accordingly. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow --- v2-v5: no change --- qemu-img.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e9c7b30c91..af3effdec5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2671,14 +2671,16 @@ static void dump_map_entry(OutputFormat output_form= at, MapEntry *e, } } -static int get_block_status(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, MapEntry *e) +static int get_block_status(BlockDriverState *bs, int64_t offset, + int64_t bytes, MapEntry *e) { int64_t ret; int depth; BlockDriverState *file; bool has_offset; + int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; + assert(bytes < INT_MAX); /* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same * range repeatedly. @@ -2686,8 +2688,8 @@ static int get_block_status(BlockDriverState *bs, int= 64_t sector_num, depth =3D 0; for (;;) { - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &nb_sect= ors, - &file); + ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_s= ectors, + &nb_sectors, &file); if (ret < 0) { return ret; } @@ -2707,7 +2709,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t sector_num, has_offset =3D !!(ret & BDRV_BLOCK_OFFSET_VALID); *e =3D (MapEntry) { - .start =3D sector_num * BDRV_SECTOR_SIZE, + .start =3D offset, .length =3D nb_sectors * BDRV_SECTOR_SIZE, .data =3D !!(ret & BDRV_BLOCK_DATA), .zero =3D !!(ret & BDRV_BLOCK_ZERO), @@ -2837,16 +2839,12 @@ static int img_map(int argc, char **argv) length =3D blk_getlength(blk); while (curr.start + curr.length < length) { - int64_t nsectors_left; - int64_t sector_num; - int n; - - sector_num =3D (curr.start + curr.length) >> BDRV_SECTOR_BITS; + int64_t offset =3D curr.start + curr.length; + int64_t n; /* Probe up to 1 GiB at a time. */ - nsectors_left =3D DIV_ROUND_UP(length, BDRV_SECTOR_SIZE) - sector_= num; - n =3D MIN(1 << (30 - BDRV_SECTOR_BITS), nsectors_left); - ret =3D get_block_status(bs, sector_num, n, &next); + n =3D QEMU_ALIGN_DOWN(MIN(1 << 30, length - offset), BDRV_SECTOR_S= IZE); + ret =3D get_block_status(bs, offset, n, &next); if (ret < 0) { error_report("Could not read file metadata: %s", strerror(-ret= )); --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507780216651649.934122192074; Wed, 11 Oct 2017 20:50:16 -0700 (PDT) Received: from localhost ([::1]:43532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UVg-00047K-R5 for importer@patchew.org; Wed, 11 Oct 2017 23:50:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTU-0002gd-64 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTS-0007QV-G1 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTP-0007N8-2F; Wed, 11 Oct 2017 23:47:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DD7B3D970; Thu, 12 Oct 2017 03:47:50 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74D71675F0; Thu, 12 Oct 2017 03:47:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1DD7B3D970 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:03 -0500 Message-Id: <20171012034720.11947-8-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 03:47:50 +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 v6 07/24] block: Convert bdrv_get_block_status() to bytes 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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 are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the name of the function from bdrv_get_block_status() to bdrv_block_status() ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned, but that can be relaxed when a later patch implements byte-based block status in the drivers. There was an inherent limitation in returning the offset via the return value: we only have room for BDRV_BLOCK_OFFSET_MASK bits, which means an offset can only be mapped for sector-aligned queries (or, if we declare that non-aligned input is at the same relative position modulo 512 of the answer), so the new interface also changes things to return the offset via output through a parameter by reference rather than mashed into the return value. We'll have some glue code that munges between the two styles until we finish converting all uses. For the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_block_status(), coupled with the tweak in calling convention. But some code, particularly bdrv_is_allocated(), gets a lot simpler because it no longer has to mess with sectors. For ease of review, bdrv_get_block_status_above() will be tackled separately. Signed-off-by: Eric Blake --- v6: redo interface to return byte-based offset by reference [Kevin] v5: drop pointless 'if (pnum)' [John], add comment v4: no change v3: clamp bytes to 32-bits, rather than asserting v2: rebase to earlier changes --- include/block/block.h | 17 +++++++++-------- block/io.c | 47 ++++++++++++++++++++++++++++++++++------------- block/qcow2-cluster.c | 2 +- qemu-img.c | 25 ++++++++++++++----------- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 440f3e9e39..7ac851f82f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -121,7 +121,7 @@ typedef struct HDGeometry { #define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BI= TS) /* - * Allocation status flags for bdrv_get_block_status() and friends. + * Allocation status flags for bdrv_block_status() and friends. * * Public flags: * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer @@ -136,10 +136,11 @@ typedef struct HDGeometry { * that the block layer recompute the answer from the retu= rned * BDS; must be accompanied by just BDRV_BLOCK_OFFSET_VALI= D. * - * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK) - * represent the offset in the returned BDS that is allocated for the - * corresponding raw data; however, whether that offset actually contains - * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows: + * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK) of + * the return value (old interface) or the entire map parameter (new + * interface) represent the offset in the returned BDS that is allocated f= or + * the corresponding raw data. However, whether that offset actually + * contains data also depends on BDRV_BLOCK_DATA, as follows: * * DATA ZERO OFFSET_VALID * t t t sectors read as zero, returned file is zero at o= ffset @@ -421,9 +422,9 @@ int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); -int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file); +int bdrv_block_status(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum, int64_t *map, + BlockDriverState **file); int64_t bdrv_get_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t sector_num, diff --git a/block/io.c b/block/io.c index e9604f0d00..d543e1038f 100644 --- a/block/io.c +++ b/block/io.c @@ -696,9 +696,9 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, */ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) { - int64_t target_size, ret, bytes, offset =3D 0; + int ret; + int64_t target_size, bytes, offset =3D 0; BlockDriverState *bs =3D child->bs; - int n; /* sectors */ target_size =3D bdrv_getlength(bs); if (target_size < 0) { @@ -710,24 +710,23 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) if (bytes <=3D 0) { return 0; } - ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, &n, NULL); + ret =3D bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); if (ret < 0) { error_report("error getting block status at offset %" PRId64 "= : %s", offset, strerror(-ret)); return ret; } if (ret & BDRV_BLOCK_ZERO) { - offset +=3D n * BDRV_SECTOR_BITS; + offset +=3D bytes; continue; } - ret =3D bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, fl= ags); + ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); if (ret < 0) { error_report("error writing zeroes at offset %" PRId64 ": %s", offset, strerror(-ret)); return ret; } - offset +=3D n * BDRV_SECTOR_SIZE; + offset +=3D bytes; } } @@ -2025,13 +2024,35 @@ int64_t bdrv_get_block_status_above(BlockDriverStat= e *bs, nb_sectors, pnum, file); } -int64_t bdrv_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, BlockDriverState **file) { - return bdrv_get_block_status_above(bs, backing_bs(bs), - sector_num, nb_sectors, pnum, file); + int64_t ret; + int n; + + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); + assert(pnum); + /* + * The contract allows us to return pnum smaller than bytes, even + * if the next query would see the same status; we truncate the + * request to avoid overflowing the driver's 32-bit interface. + */ + bytes =3D MIN(bytes, BDRV_REQUEST_MAX_BYTES); + ret =3D bdrv_get_block_status_above(bs, backing_bs(bs), + offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &n, file); + if (ret < 0) { + assert(INT_MIN <=3D ret); + *pnum =3D 0; + return ret; + } + *pnum =3D n * BDRV_SECTOR_SIZE; + if (map) { + *map =3D ret & BDRV_BLOCK_OFFSET_MASK; + } else { + ret &=3D ~BDRV_BLOCK_OFFSET_VALID; + } + return ret & ~BDRV_BLOCK_OFFSET_MASK; } int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 0e5aec81cb..fb10e26068 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1632,7 +1632,7 @@ static int discard_single_l2(BlockDriverState *bs, ui= nt64_t offset, * cluster is already marked as zero, or if it's unallocated and we * don't have a backing file. * - * TODO We might want to use bdrv_get_block_status(bs) here, but w= e're + * TODO We might want to use bdrv_block_status(bs) here, but we're * holding s->lock, so that doesn't work today. * * If full_discard is true, the sector should not read back as zer= oes, diff --git a/qemu-img.c b/qemu-img.c index af3effdec5..c81d6ce733 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1599,9 +1599,14 @@ static int convert_iteration_sectors(ImgConvertState= *s, int64_t sector_num) if (s->sector_next_status <=3D sector_num) { if (s->target_has_backing) { - ret =3D bdrv_get_block_status(blk_bs(s->src[src_cur]), - sector_num - src_cur_offset, - n, &n, NULL); + int64_t count =3D n * BDRV_SECTOR_SIZE; + + ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), + (sector_num - src_cur_offset) * + BDRV_SECTOR_SIZE, + count, &count, NULL, NULL); + assert(ret < 0 || QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; } else { ret =3D bdrv_get_block_status_above(blk_bs(s->src[src_cur]), N= ULL, sector_num - src_cur_offset, @@ -2674,13 +2679,12 @@ static void dump_map_entry(OutputFormat output_form= at, MapEntry *e, static int get_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, MapEntry *e) { - int64_t ret; + int ret; int depth; BlockDriverState *file; bool has_offset; - int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; + int64_t map; - assert(bytes < INT_MAX); /* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same * range repeatedly. @@ -2688,12 +2692,11 @@ static int get_block_status(BlockDriverState *bs, i= nt64_t offset, depth =3D 0; for (;;) { - ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_s= ectors, - &nb_sectors, &file); + ret =3D bdrv_block_status(bs, offset, bytes, &bytes, &map, &file); if (ret < 0) { return ret; } - assert(nb_sectors); + assert(bytes); if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) { break; } @@ -2710,10 +2713,10 @@ static int get_block_status(BlockDriverState *bs, i= nt64_t offset, *e =3D (MapEntry) { .start =3D offset, - .length =3D nb_sectors * BDRV_SECTOR_SIZE, + .length =3D bytes, .data =3D !!(ret & BDRV_BLOCK_DATA), .zero =3D !!(ret & BDRV_BLOCK_ZERO), - .offset =3D ret & BDRV_BLOCK_OFFSET_MASK, + .offset =3D map, .has_offset =3D has_offset, .depth =3D depth, .has_filename =3D file && has_offset, --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780570885697.9765732608904; Wed, 11 Oct 2017 20:56:10 -0700 (PDT) Received: from localhost ([::1]:43568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UbJ-0000Wg-RN for importer@patchew.org; Wed, 11 Oct 2017 23:56:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTX-0002jh-5O for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTU-0007TS-25 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTQ-0007OL-LB; Wed, 11 Oct 2017 23:47:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A212AC04B303; Thu, 12 Oct 2017 03:47:51 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 618316954A; Thu, 12 Oct 2017 03:47:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A212AC04B303 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:04 -0500 Message-Id: <20171012034720.11947-9-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 12 Oct 2017 03:47:51 +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 v6 08/24] block: Switch bdrv_co_get_block_status() to byte-based 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change); and as with its public counterpart, rename to bdrv_co_block_status() and split the offset return, to make the compiler enforce that we catch all uses. For now, we assert that callers and the return value still use aligned data, but ultimately, this will be the function where we hand off to a byte-based driver callback, and will eventually need to add logic to ensure we round calls according to the driver's request_alignment then touch up the result handed back to the caller, to start permitting a caller to pass unaligned offsets. Note that we are now prepared to accepts 'bytes' larger than INT_MAX; this is okay as long as we clamp things internally before violating any 32-bit limits, and makes no difference to how a client will use the information (clients looping over the entire file must already be prepared for consecutive calls to return the same status, as drivers are already free to return shorter-than-maximal status due to any other convenient split points, such as when the L2 table crosses cluster boundaries in qcow2). Signed-off-by: Eric Blake --- v6: rebase to return value interface change [Kevin] v5: rebase to earlier changes in 1/23, add comment v4: no change v3: rebase to allocation/mapping sense change, clamp bytes to 32-bits when needed, drop R-b v2: rebase to earlier changes --- block/io.c | 122 ++++++++++++++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 80 insertions(+), 42 deletions(-) diff --git a/block/io.c b/block/io.c index d543e1038f..5805929ef0 100644 --- a/block/io.c +++ b/block/io.c @@ -1793,80 +1793,102 @@ int64_t coroutine_fn bdrv_co_get_block_status_from= _backing(BlockDriverState *bs, * BDRV_BLOCK_ZERO where possible; otherwise, the result may omit those * bits particularly if it allows for a larger value in 'pnum'. * - * If 'sector_num' is beyond the end of the disk image the return value is + * If 'offset' is beyond the end of the disk image the return value is * BDRV_BLOCK_EOF and 'pnum' is set to 0. * - * 'pnum' is set to the number of sectors (including and immediately follo= wing - * the specified sector) that are known to be in the same - * allocated/unallocated state. - * - * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors g= oes + * 'bytes' is the max value 'pnum' should be set to. If bytes goes * beyond the end of the disk image it will be clamped; if 'pnum' is set to * the end of the image, then the returned value will include BDRV_BLOCK_E= OF. * - * 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. + * 'pnum' is set to the number of bytes (including and immediately + * following the specified offset) that are easily known to be in the + * same allocated/unallocated state. Note that a second call starting + * at the original offset plus returned pnum may have the same status. + * The returned value is non-zero on success except at end-of-file. + * + * Returns negative errno on failure. Otherwise, if the + * BDRV_BLOCK_OFFSET_VALID bit is set, 'map' and 'file' (if non-NULL) are + * set to the host mapping and BDS corresponding to the guest offset. */ -static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, - bool want_zero, - int64_t sector_num, - int nb_sectors, int *= pnum, - BlockDriverState **fi= le) +static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { - int64_t total_sectors; - int64_t n; - int64_t ret, ret2; + int64_t total_size; + int64_t n; /* bytes */ + int64_t ret; + int64_t local_map =3D 0; BlockDriverState *local_file =3D NULL; + int count; /* sectors */ assert(pnum); *pnum =3D 0; - total_sectors =3D bdrv_nb_sectors(bs); - if (total_sectors < 0) { - ret =3D total_sectors; + total_size =3D bdrv_getlength(bs); + if (total_size < 0) { + ret =3D total_size; goto early_out; } - if (sector_num >=3D total_sectors) { + if (offset >=3D total_size) { ret =3D BDRV_BLOCK_EOF; goto early_out; } - if (!nb_sectors) { + if (!bytes) { ret =3D 0; goto early_out; } - n =3D total_sectors - sector_num; - if (n < nb_sectors) { - nb_sectors =3D n; + n =3D total_size - offset; + if (n < bytes) { + bytes =3D n; } if (!bs->drv->bdrv_co_get_block_status) { - *pnum =3D nb_sectors; + *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; - if (sector_num + nb_sectors =3D=3D total_sectors) { + if (offset + bytes =3D=3D total_size) { ret |=3D BDRV_BLOCK_EOF; } if (bs->drv->protocol_name) { - ret |=3D BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_S= IZE); + ret |=3D BDRV_BLOCK_OFFSET_VALID; + local_map =3D offset; local_file =3D bs; } goto early_out; } bdrv_inc_in_flight(bs); - ret =3D bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, = pnum, + /* + * TODO: Rather than require aligned offsets, we could instead + * round to the driver's request_alignment here, then touch up + * count afterwards back to the caller's expectations. + */ + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); + /* + * The contract allows us to return pnum smaller than bytes, even + * if the next query would see the same status; we truncate the + * request to avoid overflowing the driver's 32-bit interface. + */ + bytes =3D MIN(bytes, BDRV_REQUEST_MAX_BYTES); + ret =3D bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTOR_BI= TS, + bytes >> BDRV_SECTOR_BITS, &co= unt, &local_file); if (ret < 0) { - *pnum =3D 0; goto out; } + if (ret & BDRV_BLOCK_OFFSET_VALID) { + local_map =3D ret & BDRV_BLOCK_OFFSET_MASK; + } + *pnum =3D count * BDRV_SECTOR_SIZE; if (ret & BDRV_BLOCK_RAW) { assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file); - ret =3D bdrv_co_get_block_status(local_file, want_zero, - ret >> BDRV_SECTOR_BITS, - *pnum, pnum, &local_file); + ret =3D bdrv_co_block_status(local_file, want_zero, local_map, + *pnum, pnum, &local_map, &local_file); + assert(ret < 0 || + QEMU_IS_ALIGNED(*pnum | local_map, BDRV_SECTOR_SIZE)); goto out; } @@ -1877,9 +1899,9 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, ret |=3D BDRV_BLOCK_ZERO; } else if (bs->backing) { BlockDriverState *bs2 =3D bs->backing->bs; - int64_t nb_sectors2 =3D bdrv_nb_sectors(bs2); + int64_t size2 =3D bdrv_getlength(bs2); - if (nb_sectors2 >=3D 0 && sector_num >=3D nb_sectors2) { + if (size2 >=3D 0 && offset >=3D size2) { ret |=3D BDRV_BLOCK_ZERO; } } @@ -1888,11 +1910,11 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, if (want_zero && local_file && local_file !=3D bs && (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID)) { - int file_pnum; + int64_t file_pnum; + int ret2; - ret2 =3D bdrv_co_get_block_status(local_file, want_zero, - ret >> BDRV_SECTOR_BITS, - *pnum, &file_pnum, NULL); + ret2 =3D bdrv_co_block_status(local_file, want_zero, local_map, + *pnum, &file_pnum, NULL, NULL); if (ret2 >=3D 0) { /* Ignore errors. This is just providing extra information, it * is useful but not necessary. @@ -1915,13 +1937,21 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, out: bdrv_dec_in_flight(bs); - if (ret >=3D 0 && sector_num + *pnum =3D=3D total_sectors) { + if (ret >=3D 0 && offset + *pnum =3D=3D total_size) { ret |=3D BDRV_BLOCK_EOF; } early_out: if (file) { *file =3D local_file; } + if (map) { + *map =3D local_map; + } + if (ret >=3D 0) { + ret &=3D ~BDRV_BLOCK_OFFSET_MASK; + } else { + assert(INT_MIN <=3D ret); + } return ret; } @@ -1936,14 +1966,22 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s_above(BlockDriverState *bs, BlockDriverState *p; int64_t ret =3D 0; bool first =3D true; + int64_t map =3D 0; assert(bs !=3D base); for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { - ret =3D bdrv_co_get_block_status(p, want_zero, sector_num, nb_sect= ors, - pnum, file); + int64_t count; + + ret =3D bdrv_co_block_status(p, want_zero, + sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, &count, + &map, file); if (ret < 0) { break; } + assert(QEMU_IS_ALIGNED(count | map, BDRV_SECTOR_SIZE)); + ret |=3D map; + *pnum =3D count >> BDRV_SECTOR_BITS; if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { /* * Reading beyond the end of the file continues to read --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780386249372.5650371317057; Wed, 11 Oct 2017 20:53:06 -0700 (PDT) Received: from localhost ([::1]:43545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UYQ-0006Sk-IX for importer@patchew.org; Wed, 11 Oct 2017 23:53:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTX-0002jf-5C for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTU-0007U1-Ko for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:47:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48948) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTS-0007PQ-6M; Wed, 11 Oct 2017 23:47:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3260D820F5; Thu, 12 Oct 2017 03:47:53 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3CA660C82; Thu, 12 Oct 2017 03:47:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3260D820F5 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:05 -0500 Message-Id: <20171012034720.11947-10-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 12 Oct 2017 03:47:53 +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 v6 09/24] block: Switch BdrvCoGetBlockStatusData to byte-based 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal type (no semantic change), and rename it to match the corresponding public function rename. Signed-off-by: Eric Blake --- v6: fix -O2 compilation [Jeff], rebase to split return interface change [Kevin], drop R-b v4-v5: no change v3: rebase to context conflicts, simple enough to keep R-b v2: rebase to earlier changes --- block/io.c | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/block/io.c b/block/io.c index 5805929ef0..da600a8dc3 100644 --- a/block/io.c +++ b/block/io.c @@ -1745,17 +1745,18 @@ int bdrv_flush_all(void) } -typedef struct BdrvCoGetBlockStatusData { +typedef struct BdrvCoBlockStatusData { BlockDriverState *bs; BlockDriverState *base; bool want_zero; - int64_t sector_num; - int nb_sectors; - int *pnum; + int64_t offset; + int64_t bytes; + int64_t *pnum; + int64_t *map; BlockDriverState **file; - int64_t ret; + int ret; bool done; -} BdrvCoGetBlockStatusData; +} BdrvCoBlockStatusData; int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *= bs, int64_t sector_num, @@ -2005,14 +2006,24 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s_above(BlockDriverState *bs, /* Coroutine wrapper for bdrv_get_block_status_above() */ static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque) { - BdrvCoGetBlockStatusData *data =3D opaque; + BdrvCoBlockStatusData *data =3D opaque; + int n =3D 0; + int64_t ret; - data->ret =3D bdrv_co_get_block_status_above(data->bs, data->base, - data->want_zero, - data->sector_num, - data->nb_sectors, - data->pnum, - data->file); + ret =3D bdrv_co_get_block_status_above(data->bs, data->base, + data->want_zero, + data->offset >> BDRV_SECTOR_BITS, + data->bytes >> BDRV_SECTOR_BITS, + &n, + data->file); + if (ret < 0) { + assert(INT_MIN <=3D ret); + data->ret =3D ret; + } else { + *data->pnum =3D n * BDRV_SECTOR_SIZE; + *data->map =3D ret & BDRV_BLOCK_OFFSET_MASK; + data->ret =3D ret & ~BDRV_BLOCK_OFFSET_MASK; + } data->done =3D true; } @@ -2029,13 +2040,16 @@ static int64_t bdrv_common_block_status_above(Block= DriverState *bs, BlockDriverState **file) { Coroutine *co; - BdrvCoGetBlockStatusData data =3D { + int64_t n; + int64_t map; + BdrvCoBlockStatusData data =3D { .bs =3D bs, .base =3D base, .want_zero =3D want_zero, - .sector_num =3D sector_num, - .nb_sectors =3D nb_sectors, - .pnum =3D pnum, + .offset =3D sector_num * BDRV_SECTOR_SIZE, + .bytes =3D nb_sectors * BDRV_SECTOR_SIZE, + .pnum =3D &n, + .map =3D &map, .file =3D file, .done =3D false, }; @@ -2049,7 +2063,13 @@ static int64_t bdrv_common_block_status_above(BlockD= riverState *bs, bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } - return data.ret; + if (data.ret < 0) { + *pnum =3D 0; + return data.ret; + } + assert(QEMU_IS_ALIGNED(n | map, BDRV_SECTOR_SIZE)); + *pnum =3D n >> BDRV_SECTOR_BITS; + return data.ret | map; } int64_t bdrv_get_block_status_above(BlockDriverState *bs, --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780712635341.7843355464644; Wed, 11 Oct 2017 20:58:32 -0700 (PDT) Received: from localhost ([::1]:43582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Udj-0002pB-RK for importer@patchew.org; Wed, 11 Oct 2017 23:58:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTY-0002kp-6C for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTX-0007WQ-BT for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTT-0007S7-MO; Wed, 11 Oct 2017 23:47:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8F998046F; Thu, 12 Oct 2017 03:47:54 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 730A56954A; Thu, 12 Oct 2017 03:47:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8F998046F 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:06 -0500 Message-Id: <20171012034720.11947-11-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 12 Oct 2017 03:47:54 +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 v6 10/24] block: Switch bdrv_common_block_status_above() to byte-based 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change). Signed-off-by: Eric Blake --- v6: rebase to split return interface change [Kevin], R-b dropped v4-v5: no change v3: rebase to allocation/mapping sense change, simple enough to keep R-b v2: new patch --- block/io.c | 61 ++++++++++++++++++++++++++++++----------------------------= --- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/block/io.c b/block/io.c index da600a8dc3..e8fda1a4b8 100644 --- a/block/io.c +++ b/block/io.c @@ -2032,24 +2032,22 @@ static void coroutine_fn bdrv_get_block_status_abov= e_co_entry(void *opaque) * * See bdrv_co_get_block_status_above() for details. */ -static int64_t bdrv_common_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +static int bdrv_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, int64_t offset, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) { Coroutine *co; - int64_t n; - int64_t map; BdrvCoBlockStatusData data =3D { .bs =3D bs, .base =3D base, .want_zero =3D want_zero, - .offset =3D sector_num * BDRV_SECTOR_SIZE, - .bytes =3D nb_sectors * BDRV_SECTOR_SIZE, - .pnum =3D &n, - .map =3D &map, + .offset =3D offset, + .bytes =3D bytes, + .pnum =3D pnum, + .map =3D map, .file =3D file, .done =3D false, }; @@ -2063,13 +2061,7 @@ static int64_t bdrv_common_block_status_above(BlockD= riverState *bs, bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } - if (data.ret < 0) { - *pnum =3D 0; - return data.ret; - } - assert(QEMU_IS_ALIGNED(n | map, BDRV_SECTOR_SIZE)); - *pnum =3D n >> BDRV_SECTOR_BITS; - return data.ret | map; + return data.ret; } int64_t bdrv_get_block_status_above(BlockDriverState *bs, @@ -2078,8 +2070,21 @@ int64_t bdrv_get_block_status_above(BlockDriverState= *bs, int nb_sectors, int *pnum, BlockDriverState **file) { - return bdrv_common_block_status_above(bs, base, true, sector_num, - nb_sectors, pnum, file); + int64_t ret; + int64_t n; + int64_t map; + + ret =3D bdrv_common_block_status_above(bs, base, true, + sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, + &n, &map, file); + if (ret < 0) { + *pnum =3D 0; + return ret; + } + assert(QEMU_IS_ALIGNED(n | map, BDRV_SECTOR_SIZE)); + *pnum =3D n >> BDRV_SECTOR_BITS; + return ret | map; } int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, @@ -2116,21 +2121,15 @@ int bdrv_block_status(BlockDriverState *bs, int64_t= offset, int64_t bytes, int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum) { - int64_t ret; - int psectors; + int ret; + int64_t dummy; - assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE) && bytes < INT_MAX); - ret =3D bdrv_common_block_status_above(bs, backing_bs(bs), false, - offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, &psect= ors, + ret =3D bdrv_common_block_status_above(bs, backing_bs(bs), false, offs= et, + bytes, pnum ? pnum : &dummy, NULL, NULL); if (ret < 0) { return ret; } - if (pnum) { - *pnum =3D psectors * BDRV_SECTOR_SIZE; - } return !!(ret & BDRV_BLOCK_ALLOCATED); } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780570833228.60075744306016; Wed, 11 Oct 2017 20:56:10 -0700 (PDT) Received: from localhost ([::1]:43569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UbN-0000Zi-JI for importer@patchew.org; Wed, 11 Oct 2017 23:56:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTb-0002nW-Rf for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTY-0007Xq-Jj for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTV-0007U5-AL; Wed, 11 Oct 2017 23:47:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B94FC0587DE; Thu, 12 Oct 2017 03:47:56 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0871F1883F; Thu, 12 Oct 2017 03:47:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4B94FC0587DE 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:07 -0500 Message-Id: <20171012034720.11947-12-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 12 Oct 2017 03:47: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 v6 11/24] block: Switch bdrv_co_get_block_status_above() to byte-based 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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 are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal type (no semantic change), and rename it to match the corresponding public function rename. Signed-off-by: Eric Blake --- v6: rebase to split return interface change [Kevin], R-b dropped v5: no change other than rebase to context v4: no change v3: rebase to allocation/mapping sense change, simple enough to keep R-b v2: rebase to earlier changes --- block/io.c | 68 ++++++++++++++++++++++------------------------------------= ---- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/block/io.c b/block/io.c index e8fda1a4b8..938325b756 100644 --- a/block/io.c +++ b/block/io.c @@ -1956,33 +1956,26 @@ early_out: return ret; } -static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverStat= e *bs, - BlockDriverState *base, - bool want_zero, - int64_t sector_num, - int nb_sectors, - int *pnum, - BlockDriverState **file) +static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BlockDriverState *p; - int64_t ret =3D 0; + int ret =3D 0; bool first =3D true; - int64_t map =3D 0; assert(bs !=3D base); for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { - int64_t count; - - ret =3D bdrv_co_block_status(p, want_zero, - sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, &count, - &map, file); + ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, + file); if (ret < 0) { break; } - assert(QEMU_IS_ALIGNED(count | map, BDRV_SECTOR_SIZE)); - ret |=3D map; - *pnum =3D count >> BDRV_SECTOR_BITS; if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { /* * Reading beyond the end of the file continues to read @@ -1990,47 +1983,35 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s_above(BlockDriverState *bs, * unallocated length we learned from an earlier * iteration. */ - *pnum =3D nb_sectors; + *pnum =3D bytes; } if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { break; } - /* [sector_num, pnum] unallocated on this layer, which could be on= ly - * the first part of [sector_num, nb_sectors]. */ - nb_sectors =3D MIN(nb_sectors, *pnum); + /* [offset, pnum] unallocated on this layer, which could be only + * the first part of [offset, bytes]. */ + bytes =3D MIN(bytes, *pnum); first =3D false; } return ret; } /* Coroutine wrapper for bdrv_get_block_status_above() */ -static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque) +static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; - int n =3D 0; - int64_t ret; - ret =3D bdrv_co_get_block_status_above(data->bs, data->base, - data->want_zero, - data->offset >> BDRV_SECTOR_BITS, - data->bytes >> BDRV_SECTOR_BITS, - &n, - data->file); - if (ret < 0) { - assert(INT_MIN <=3D ret); - data->ret =3D ret; - } else { - *data->pnum =3D n * BDRV_SECTOR_SIZE; - *data->map =3D ret & BDRV_BLOCK_OFFSET_MASK; - data->ret =3D ret & ~BDRV_BLOCK_OFFSET_MASK; - } + data->ret =3D bdrv_co_block_status_above(data->bs, data->base, + data->want_zero, + data->offset, data->bytes, + data->pnum, data->map, data->fi= le); data->done =3D true; } /* - * Synchronous wrapper around bdrv_co_get_block_status_above(). + * Synchronous wrapper around bdrv_co_block_status_above(). * - * See bdrv_co_get_block_status_above() for details. + * See bdrv_co_block_status_above() for details. */ static int bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, @@ -2054,10 +2035,9 @@ static int bdrv_common_block_status_above(BlockDrive= rState *bs, if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ - bdrv_get_block_status_above_co_entry(&data); + bdrv_block_status_above_co_entry(&data); } else { - co =3D qemu_coroutine_create(bdrv_get_block_status_above_co_entry, - &data); + co =3D qemu_coroutine_create(bdrv_block_status_above_co_entry, &da= ta); bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780744814144.00314539304964; Wed, 11 Oct 2017 20:59:04 -0700 (PDT) Received: from localhost ([::1]:43585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UeD-0003Eq-1n for importer@patchew.org; Wed, 11 Oct 2017 23:59:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTe-0002qg-F0 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTc-0007aM-Ev for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTX-0007Vg-7K; Wed, 11 Oct 2017 23:47:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 297F381E1F; Thu, 12 Oct 2017 03:47:58 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9425917BB1; Thu, 12 Oct 2017 03:47:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 297F381E1F 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:08 -0500 Message-Id: <20171012034720.11947-13-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 12 Oct 2017 03:47: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 v6 12/24] block: Convert bdrv_get_block_status_above() to bytes 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Jeff Cody , Max Reitz , 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 are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the name of the function from bdrv_get_block_status_above() to bdrv_block_status_above() ensures that the compiler enforces that all callers are updated. Likewise, since it a byte interface allows an offset mapping that might not be sector aligned, split the mapping out of the return value and into a pass-by-reference parameter. For now, the io.c layer still assert()s that all uses are sector-aligned, but that can be relaxed when a later patch implements byte-based block status in the drivers. For the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_block_status(), plus updates for the new split return interface. But some code, particularly bdrv_block_status(), gets a lot simpler because it no longer has to mess with sectors. Likewise, mirror code no longer computes s->granularity >> BDRV_SECTOR_BITS, and can therefore drop an assertion about alignment because the loop no longer depends on alignment (never mind that we don't really have a driver that reports sub-sector alignments, so it's not really possible to test the effect of sub-sector mirroring). Fix a neighboring assertion to use is_power_of_2 while there. For ease of review, bdrv_get_block_status() was tackled separately. Signed-off-by: Eric Blake --- v6: rebase to split return interface change [Kevin] v5: assert alignment rather than rounding up in img_compare [John], rebase to earlier changes v4: rebase to earlier changes v3: rebase to allocation/mapping sense change and qcow2-measure, tweak mirror assertions, drop R-b v2: rebase to earlier changes --- include/block/block.h | 8 +++----- block/io.c | 55 ++++++++---------------------------------------= ---- block/mirror.c | 18 ++++++----------- block/qcow2.c | 30 +++++++++++----------------- qemu-img.c | 49 +++++++++++++++++++++++++-------------------- 5 files changed, 57 insertions(+), 103 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 7ac851f82f..fbc21daf62 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -425,11 +425,9 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState= *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); -int64_t bdrv_get_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file); +int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file); int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, diff --git a/block/io.c b/block/io.c index 938325b756..f0bd6aa63e 100644 --- a/block/io.c +++ b/block/io.c @@ -1996,7 +1996,7 @@ static int coroutine_fn bdrv_co_block_status_above(Bl= ockDriverState *bs, return ret; } -/* Coroutine wrapper for bdrv_get_block_status_above() */ +/* Coroutine wrapper for bdrv_block_status_above() */ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; @@ -2044,58 +2044,19 @@ static int bdrv_common_block_status_above(BlockDriv= erState *bs, return data.ret; } -int64_t bdrv_get_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file) { - int64_t ret; - int64_t n; - int64_t map; - - ret =3D bdrv_common_block_status_above(bs, base, true, - sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, - &n, &map, file); - if (ret < 0) { - *pnum =3D 0; - return ret; - } - assert(QEMU_IS_ALIGNED(n | map, BDRV_SECTOR_SIZE)); - *pnum =3D n >> BDRV_SECTOR_BITS; - return ret | map; + return bdrv_common_block_status_above(bs, base, true, offset, bytes, + pnum, map, file); } int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) { - int64_t ret; - int n; - - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); - assert(pnum); - /* - * The contract allows us to return pnum smaller than bytes, even - * if the next query would see the same status; we truncate the - * request to avoid overflowing the driver's 32-bit interface. - */ - bytes =3D MIN(bytes, BDRV_REQUEST_MAX_BYTES); - ret =3D bdrv_get_block_status_above(bs, backing_bs(bs), - offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, &n, file); - if (ret < 0) { - assert(INT_MIN <=3D ret); - *pnum =3D 0; - return ret; - } - *pnum =3D n * BDRV_SECTOR_SIZE; - if (map) { - *map =3D ret & BDRV_BLOCK_OFFSET_MASK; - } else { - ret &=3D ~BDRV_BLOCK_OFFSET_VALID; - } - return ret & ~BDRV_BLOCK_OFFSET_MASK; + return bdrv_block_status_above(bs, backing_bs(bs), + offset, bytes, pnum, map, file); } int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, diff --git a/block/mirror.c b/block/mirror.c index d11706c566..307b6391a8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -328,7 +328,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) uint64_t delay_ns =3D 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks =3D 1; - int sectors_per_chunk =3D s->granularity >> BDRV_SECTOR_BITS; bool write_zeroes_ok =3D bdrv_can_write_zeroes_with_unmap(blk_bs(s->ta= rget)); int max_io_bytes =3D MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); @@ -376,7 +375,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) } /* Clear dirty bits before querying the block status, because - * calling bdrv_get_block_status_above could yield - if some blocks are + * calling bdrv_block_status_above could yield - if some blocks are * marked dirty in this window, we need to know. */ bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset, @@ -385,8 +384,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks); while (nb_chunks > 0 && offset < s->bdev_length) { - int64_t ret; - int io_sectors; + int ret; int64_t io_bytes; int64_t io_bytes_acct; enum MirrorMethod { @@ -396,11 +394,9 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) } mirror_method =3D MIRROR_METHOD_COPY; assert(!(offset % s->granularity)); - ret =3D bdrv_get_block_status_above(source, NULL, - offset >> BDRV_SECTOR_BITS, - nb_chunks * sectors_per_chunk, - &io_sectors, NULL); - io_bytes =3D io_sectors * BDRV_SECTOR_SIZE; + ret =3D bdrv_block_status_above(source, NULL, offset, + nb_chunks * s->granularity, + &io_bytes, NULL, NULL); if (ret < 0) { io_bytes =3D MIN(nb_chunks * s->granularity, max_io_bytes); } else if (ret & BDRV_BLOCK_DATA) { @@ -1131,9 +1127,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, granularity =3D bdrv_get_default_bitmap_granularity(target); } - assert ((granularity & (granularity - 1)) =3D=3D 0); - /* Granularity must be large enough for sector-based dirty bitmap */ - assert(granularity >=3D BDRV_SECTOR_SIZE); + assert(is_power_of_2(granularity)); if (buf_size < 0) { error_setg(errp, "Invalid parameter 'buf-size'"); diff --git a/block/qcow2.c b/block/qcow2.c index df53535455..092a3cabdb 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3001,8 +3001,8 @@ finish: static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) { - int nr; - int64_t res; + int64_t nr; + int res; int64_t start; /* TODO: Widening to sector boundaries should only be needed as @@ -3018,10 +3018,8 @@ static bool is_zero(BlockDriverState *bs, int64_t of= fset, int64_t bytes) if (!bytes) { return true; } - res =3D bdrv_get_block_status_above(bs, NULL, start >> BDRV_SECTOR_BIT= S, - bytes >> BDRV_SECTOR_BITS, &nr, NULL= ); - return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && - nr * BDRV_SECTOR_SIZE =3D=3D bytes; + res =3D bdrv_block_status_above(bs, NULL, start, bytes, &nr, NULL, NUL= L); + return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr =3D=3D bytes; } static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, @@ -3729,17 +3727,14 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *op= ts, BlockDriverState *in_bs, required =3D virtual_size; } else { int64_t offset; - int pnum =3D 0; + int64_t pnum =3D 0; - for (offset =3D 0; offset < ssize; - offset +=3D pnum * BDRV_SECTOR_SIZE) { - int nb_sectors =3D MIN(ssize - offset, - BDRV_REQUEST_MAX_BYTES) / BDRV_SECTOR= _SIZE; - int64_t ret; + for (offset =3D 0; offset < ssize; offset +=3D pnum) { + int ret; - ret =3D bdrv_get_block_status_above(in_bs, NULL, - offset >> BDRV_SECTOR_BI= TS, - nb_sectors, &pnum, NULL); + ret =3D bdrv_block_status_above(in_bs, NULL, offset, + ssize - offset, &pnum, NULL, + NULL); if (ret < 0) { error_setg_errno(&local_err, -ret, "Unable to get block status"); @@ -3751,11 +3746,10 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *op= ts, BlockDriverState *in_bs, } else if ((ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)= ) =3D=3D (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) { /* Extend pnum to end of cluster for next iteration */ - pnum =3D (ROUND_UP(offset + pnum * BDRV_SECTOR_SIZE, - cluster_size) - offset) >> BDRV_SECTOR_BI= TS; + pnum =3D ROUND_UP(offset + pnum, cluster_size) - offse= t; /* Count clusters we've seen */ - required +=3D offset % cluster_size + pnum * BDRV_SECT= OR_SIZE; + required +=3D offset % cluster_size + pnum; } } } diff --git a/qemu-img.c b/qemu-img.c index c81d6ce733..78c820e487 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1226,7 +1226,7 @@ static int img_compare(int argc, char **argv) BlockDriverState *bs1, *bs2; int64_t total_sectors1, total_sectors2; uint8_t *buf1 =3D NULL, *buf2 =3D NULL; - int pnum1, pnum2; + int64_t pnum1, pnum2; int allocated1, allocated2; int ret =3D 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress =3D false, quiet =3D false, strict =3D false; @@ -1374,15 +1374,17 @@ static int img_compare(int argc, char **argv) } for (;;) { - int64_t status1, status2; + int status1, status2; nb_sectors =3D sectors_to_process(total_sectors, sector_num); if (nb_sectors <=3D 0) { break; } - status1 =3D bdrv_get_block_status_above(bs1, NULL, sector_num, - total_sectors1 - sector_num, - &pnum1, NULL); + status1 =3D bdrv_block_status_above(bs1, NULL, + sector_num * BDRV_SECTOR_SIZE, + (total_sectors1 - sector_num) * + BDRV_SECTOR_SIZE, + &pnum1, NULL, NULL); if (status1 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename1= ); @@ -1390,25 +1392,29 @@ static int img_compare(int argc, char **argv) } allocated1 =3D status1 & BDRV_BLOCK_ALLOCATED; - status2 =3D bdrv_get_block_status_above(bs2, NULL, sector_num, - total_sectors2 - sector_num, - &pnum2, NULL); + status2 =3D bdrv_block_status_above(bs2, NULL, + sector_num * BDRV_SECTOR_SIZE, + (total_sectors2 - sector_num) * + BDRV_SECTOR_SIZE, + &pnum2, NULL, NULL); if (status2 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename2= ); goto out; } allocated2 =3D status2 & BDRV_BLOCK_ALLOCATED; + /* TODO: Relax this once comparison is byte-based, and we no longer + * have to worry about sector alignment */ + assert(QEMU_IS_ALIGNED(pnum1 | pnum2, BDRV_SECTOR_SIZE)); if (pnum1) { - nb_sectors =3D MIN(nb_sectors, pnum1); + nb_sectors =3D MIN(nb_sectors, pnum1 >> BDRV_SECTOR_BITS); } if (pnum2) { - nb_sectors =3D MIN(nb_sectors, pnum2); + nb_sectors =3D MIN(nb_sectors, pnum2 >> BDRV_SECTOR_BITS); } if (strict) { - if ((status1 & ~BDRV_BLOCK_OFFSET_MASK) !=3D - (status2 & ~BDRV_BLOCK_OFFSET_MASK)) { + if (status1 !=3D status2) { ret =3D 1; qprintf(quiet, "Strict mode: Offset %" PRId64 " block status mismatch!\n", @@ -1417,7 +1423,7 @@ static int img_compare(int argc, char **argv) } } if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) { - nb_sectors =3D MIN(pnum1, pnum2); + nb_sectors =3D DIV_ROUND_UP(MIN(pnum1, pnum2), BDRV_SECTOR_SIZ= E); } else if (allocated1 =3D=3D allocated2) { if (allocated1) { ret =3D blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, bu= f1, @@ -1589,8 +1595,8 @@ static void convert_select_part(ImgConvertState *s, i= nt64_t sector_num, static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_nu= m) { - int64_t ret, src_cur_offset; - int n, src_cur; + int64_t src_cur_offset; + int ret, n, src_cur; convert_select_part(s, sector_num, &src_cur, &src_cur_offset); @@ -1598,23 +1604,24 @@ 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) { + int64_t count =3D n * BDRV_SECTOR_SIZE; + if (s->target_has_backing) { - int64_t count =3D n * BDRV_SECTOR_SIZE; ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), (sector_num - src_cur_offset) * BDRV_SECTOR_SIZE, count, &count, NULL, NULL); - assert(ret < 0 || QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); - n =3D count >> BDRV_SECTOR_BITS; } else { - ret =3D bdrv_get_block_status_above(blk_bs(s->src[src_cur]), N= ULL, - sector_num - src_cur_offset, - n, &n, NULL); + ret =3D bdrv_block_status_above(blk_bs(s->src[src_cur]), NULL, + (sector_num - src_cur_offset) * + BDRV_SECTOR_SIZE, + count, &count, NULL, NULL); } if (ret < 0) { return ret; } + n =3D DIV_ROUND_UP(count, BDRV_SECTOR_SIZE); if (ret & BDRV_BLOCK_ZERO) { s->status =3D BLK_ZERO; --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15077805628031001.2644834860984; Wed, 11 Oct 2017 20:56:02 -0700 (PDT) Received: from localhost ([::1]:43567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UbB-0000PV-98 for importer@patchew.org; Wed, 11 Oct 2017 23:55:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTg-0002sz-Al for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTd-0007aa-8E for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTa-0007Yi-DY; Wed, 11 Oct 2017 23:48:02 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6493AC0587DE; Thu, 12 Oct 2017 03:48:01 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CBE06954A; Thu, 12 Oct 2017 03:47:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6493AC0587DE 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:09 -0500 Message-Id: <20171012034720.11947-14-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 12 Oct 2017 03:48:01 +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 v6 13/24] qemu-img: Simplify logic in img_compare() 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" As long as we are querying the status for a chunk smaller than the known image size, we are guaranteed that a successful return will have set pnum to a non-zero size (pnum is zero only for queries beyond the end of the file). Use that to slightly simplify the calculation of the current chunk size being compared. Likewise, we don't have to shrink the amount of data operated on until we know we have to read the file, and therefore have to fit in the bounds of our buffer. Also, note that 'total_sectors_over' is equivalent to 'progress_base'. With these changes in place, sectors_to_process() is now dead code, and can be removed. Signed-off-by: Eric Blake --- v6: rebase to context v5: rebase to alignment assertion [John] v4: no change v3: new patch --- qemu-img.c | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 78c820e487..cfa28d41d5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1172,11 +1172,6 @@ static int64_t sectors_to_bytes(int64_t sectors) return sectors << BDRV_SECTOR_BITS; } -static int64_t sectors_to_process(int64_t total, int64_t from) -{ - return MIN(total - from, IO_BUF_SIZE >> BDRV_SECTOR_BITS); -} - /* * Check if passed sectors are empty (not allocated or contain only 0 byte= s) * @@ -1373,13 +1368,9 @@ static int img_compare(int argc, char **argv) goto out; } - for (;;) { + while (sector_num < total_sectors) { int status1, status2; - nb_sectors =3D sectors_to_process(total_sectors, sector_num); - if (nb_sectors <=3D 0) { - break; - } status1 =3D bdrv_block_status_above(bs1, NULL, sector_num * BDRV_SECTOR_SIZE, (total_sectors1 - sector_num) * @@ -1406,12 +1397,9 @@ static int img_compare(int argc, char **argv) /* TODO: Relax this once comparison is byte-based, and we no longer * have to worry about sector alignment */ assert(QEMU_IS_ALIGNED(pnum1 | pnum2, BDRV_SECTOR_SIZE)); - if (pnum1) { - nb_sectors =3D MIN(nb_sectors, pnum1 >> BDRV_SECTOR_BITS); - } - if (pnum2) { - nb_sectors =3D MIN(nb_sectors, pnum2 >> BDRV_SECTOR_BITS); - } + + assert(pnum1 && pnum2); + nb_sectors =3D MIN(pnum1, pnum2) >> BDRV_SECTOR_BITS; if (strict) { if (status1 !=3D status2) { @@ -1423,9 +1411,10 @@ static int img_compare(int argc, char **argv) } } if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) { - nb_sectors =3D DIV_ROUND_UP(MIN(pnum1, pnum2), BDRV_SECTOR_SIZ= E); + /* nothing to do */ } else if (allocated1 =3D=3D allocated2) { if (allocated1) { + nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); ret =3D blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, bu= f1, nb_sectors << BDRV_SECTOR_BITS); if (ret < 0) { @@ -1454,7 +1443,7 @@ static int img_compare(int argc, char **argv) } } } else { - + nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_BITS= ); if (allocated1) { ret =3D check_empty_sectors(blk1, sector_num, nb_sectors, filename1, buf1, quiet); @@ -1477,30 +1466,24 @@ static int img_compare(int argc, char **argv) if (total_sectors1 !=3D total_sectors2) { BlockBackend *blk_over; - int64_t total_sectors_over; const char *filename_over; qprintf(quiet, "Warning: Image size mismatch!\n"); if (total_sectors1 > total_sectors2) { - total_sectors_over =3D total_sectors1; blk_over =3D blk1; filename_over =3D filename1; } else { - total_sectors_over =3D total_sectors2; blk_over =3D blk2; filename_over =3D filename2; } - for (;;) { + while (sector_num < progress_base) { int64_t count; - nb_sectors =3D sectors_to_process(total_sectors_over, sector_n= um); - if (nb_sectors <=3D 0) { - break; - } ret =3D bdrv_is_allocated_above(blk_bs(blk_over), NULL, sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, + (progress_base - sector_num) * + BDRV_SECTOR_SIZE, &count); if (ret < 0) { ret =3D 3; @@ -1514,6 +1497,7 @@ static int img_compare(int argc, char **argv) assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); nb_sectors =3D count >> BDRV_SECTOR_BITS; if (ret) { + nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); ret =3D check_empty_sectors(blk_over, sector_num, nb_secto= rs, filename_over, buf1, quiet); if (ret) { --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780898330634.9255512685532; Wed, 11 Oct 2017 21:01:38 -0700 (PDT) Received: from localhost ([::1]:43605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Ugj-0005Yv-Km for importer@patchew.org; Thu, 12 Oct 2017 00:01:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTi-0002vD-Fc for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTh-0007hm-OE for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTe-0007ap-00; Wed, 11 Oct 2017 23:48:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 093CBC0587ED; Thu, 12 Oct 2017 03:48:05 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8275675F0; Thu, 12 Oct 2017 03:48:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 093CBC0587ED 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:10 -0500 Message-Id: <20171012034720.11947-15-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 12 Oct 2017 03:48:05 +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 v6 14/24] qemu-img: Speed up compare on pre-allocated larger file 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" Compare the following images with all-zero contents: $ truncate --size 1M A $ qemu-img create -f qcow2 -o preallocation=3Doff B 1G $ qemu-img create -f qcow2 -o preallocation=3Dmetadata C 1G On my machine, the difference is noticeable for pre-patch speeds, with more than an order of magnitude in difference caused by the choice of preallocation in the qcow2 file: $ time ./qemu-img compare -f raw -F qcow2 A B Warning: Image size mismatch! Images are identical. real 0m0.014s user 0m0.007s sys 0m0.007s $ time ./qemu-img compare -f raw -F qcow2 A C Warning: Image size mismatch! Images are identical. real 0m0.341s user 0m0.144s sys 0m0.188s Why? Because bdrv_is_allocated() returns false for image B but true for image C, throwing away the fact that both images know via lseek(SEEK_HOLE) that the entire image still reads as zero. From there, qemu-img ends up calling bdrv_pread() for every byte of the tail, instead of quickly looking for the next allocation. The solution: use block_status instead of is_allocated, giving: $ time ./qemu-img compare -f raw -F qcow2 A C Warning: Image size mismatch! Images are identical. real 0m0.014s user 0m0.011s sys 0m0.003s which is on par with the speeds for no pre-allocation. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- v6: rebase to interface change [Kevin], minor enough to keep R-b v4-v5: no change v3: new patch --- qemu-img.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index cfa28d41d5..e4b84c4f56 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1480,11 +1480,11 @@ static int img_compare(int argc, char **argv) while (sector_num < progress_base) { int64_t count; - ret =3D bdrv_is_allocated_above(blk_bs(blk_over), NULL, + ret =3D bdrv_block_status_above(blk_bs(blk_over), NULL, sector_num * BDRV_SECTOR_SIZE, (progress_base - sector_num) * BDRV_SECTOR_SIZE, - &count); + &count, NULL, NULL); if (ret < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", @@ -1492,11 +1492,11 @@ static int img_compare(int argc, char **argv) goto out; } - /* TODO relax this once bdrv_is_allocated_above does not enfor= ce + /* TODO relax this once bdrv_block_status_above does not enfor= ce * sector alignment */ assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); nb_sectors =3D count >> BDRV_SECTOR_BITS; - if (ret) { + if (ret & BDRV_BLOCK_ALLOCATED && !(ret & BDRV_BLOCK_ZERO)) { nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); ret =3D check_empty_sectors(blk_over, sector_num, nb_secto= rs, filename_over, buf1, quiet); --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780725806538.3717771576036; Wed, 11 Oct 2017 20:58:45 -0700 (PDT) Received: from localhost ([::1]:43584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Udx-00031P-1e for importer@patchew.org; Wed, 11 Oct 2017 23:58:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTi-0002vG-On for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTh-0007ht-QY for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTf-0007cc-JQ; Wed, 11 Oct 2017 23:48:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BE9C5114F; Thu, 12 Oct 2017 03:48:06 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C7626955E; Thu, 12 Oct 2017 03:48:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8BE9C5114F 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:11 -0500 Message-Id: <20171012034720.11947-16-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 12 Oct 2017 03:48:06 +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 v6 15/24] qemu-img: Add find_nonzero() 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" During 'qemu-img compare', when we are checking that an allocated portion of one file is all zeros, we don't need to waste time computing how many additional sectors after the first non-zero byte are also non-zero. Create a new helper find_nonzero() to do the check for a first non-zero sector, and rebase check_empty_sectors() to use it. The new interface intentionally uses bytes in its interface, even though it still crawls the buffer a sector at a time; it is robust to a partial sector at the end of the buffer. Signed-off-by: Eric Blake Reviewed-by: John Snow --- v4-v5: no change v3: new patch --- qemu-img.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e4b84c4f56..89f1093d81 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1065,6 +1065,28 @@ done: } /* + * Returns -1 if 'buf' contains only zeroes, otherwise the byte index + * of the first sector boundary within buf where the sector contains a + * non-zero byte. This function is robust to a buffer that is not + * sector-aligned. + */ +static int64_t find_nonzero(const uint8_t *buf, int64_t n) +{ + int64_t i; + int64_t end =3D QEMU_ALIGN_DOWN(n, BDRV_SECTOR_SIZE); + + for (i =3D 0; i < end; i +=3D BDRV_SECTOR_SIZE) { + if (!buffer_is_zero(buf + i, BDRV_SECTOR_SIZE)) { + return i; + } + } + if (i < n && !buffer_is_zero(buf + i, n - end)) { + return i; + } + return -1; +} + +/* * Returns true iff the first sector pointed to by 'buf' contains at least * a non-NUL byte. * @@ -1189,7 +1211,9 @@ static int check_empty_sectors(BlockBackend *blk, int= 64_t sect_num, int sect_count, const char *filename, uint8_t *buffer, bool quiet) { - int pnum, ret =3D 0; + int ret =3D 0; + int64_t idx; + ret =3D blk_pread(blk, sect_num << BDRV_SECTOR_BITS, buffer, sect_count << BDRV_SECTOR_BITS); if (ret < 0) { @@ -1197,10 +1221,10 @@ static int check_empty_sectors(BlockBackend *blk, i= nt64_t sect_num, sectors_to_bytes(sect_num), filename, strerror(-ret)); return ret; } - ret =3D is_allocated_sectors(buffer, sect_count, &pnum); - if (ret || pnum !=3D sect_count) { + idx =3D find_nonzero(buffer, sect_count * BDRV_SECTOR_SIZE); + if (idx >=3D 0) { qprintf(quiet, "Content mismatch at offset %" PRId64 "!\n", - sectors_to_bytes(ret ? sect_num : sect_num + pnum)); + sectors_to_bytes(sect_num) + idx); return 1; } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780892191266.74453976331563; Wed, 11 Oct 2017 21:01:32 -0700 (PDT) Received: from localhost ([::1]:43601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UgO-0005Dw-Nj for importer@patchew.org; Thu, 12 Oct 2017 00:01:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTp-0002zy-9z for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTm-0007mm-Bs for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTg-0007fD-Tf; Wed, 11 Oct 2017 23:48:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED653C04B303; Thu, 12 Oct 2017 03:48:07 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id D041D675F0; Thu, 12 Oct 2017 03:48:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ED653C04B303 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:12 -0500 Message-Id: <20171012034720.11947-17-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 12 Oct 2017 03:48:08 +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 v6 16/24] qemu-img: Drop redundant error message in compare 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" If a read error is encountered during 'qemu-img compare', we were printing the "Error while reading offset ..." message twice; this was because our helper function was awkward, printing output on some but not all paths. Fix it to consistently report errors on all paths, so that the callers do not risk a redundant message, and update the testsuite for the improved output. Further simplify the code by hoisting the conversion from an error message to an exit code into the helper function, rather than repeating that logic at all callers (yes, the helper function is now less generic, but it's a net win in lines of code). Signed-off-by: Eric Blake Reviewed-by: John Snow --- v5: tweak commit message, but no code change v4: no change v3: new patch --- qemu-img.c | 19 +++++-------------- tests/qemu-iotests/074.out | 2 -- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 89f1093d81..53cae6bb66 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1197,8 +1197,10 @@ static int64_t sectors_to_bytes(int64_t sectors) /* * Check if passed sectors are empty (not allocated or contain only 0 byte= s) * - * Returns 0 in case sectors are filled with 0, 1 if sectors contain non-z= ero - * data and negative value on error. + * Intended for use by 'qemu-img compare': Returns 0 in case sectors are + * filled with 0, 1 if sectors contain non-zero data (this is a comparison + * failure), and 4 on error (the exit status for read errors), after emitt= ing + * an error message. * * @param blk: BlockBackend for the image * @param sect_num: Number of first sector to check @@ -1219,7 +1221,7 @@ static int check_empty_sectors(BlockBackend *blk, int= 64_t sect_num, if (ret < 0) { error_report("Error while reading offset %" PRId64 " of %s: %s", sectors_to_bytes(sect_num), filename, strerror(-ret)); - return ret; + return 4; } idx =3D find_nonzero(buffer, sect_count * BDRV_SECTOR_SIZE); if (idx >=3D 0) { @@ -1476,11 +1478,6 @@ static int img_compare(int argc, char **argv) filename2, buf1, quiet); } if (ret) { - if (ret < 0) { - error_report("Error while reading offset %" PRId64 ": = %s", - sectors_to_bytes(sector_num), strerror(-r= et)); - ret =3D 4; - } goto out; } } @@ -1525,12 +1522,6 @@ static int img_compare(int argc, char **argv) ret =3D check_empty_sectors(blk_over, sector_num, nb_secto= rs, filename_over, buf1, quiet); if (ret) { - if (ret < 0) { - error_report("Error while reading offset %" PRId64 - " of %s: %s", sectors_to_bytes(sector= _num), - filename_over, strerror(-ret)); - ret =3D 4; - } goto out; } } diff --git a/tests/qemu-iotests/074.out b/tests/qemu-iotests/074.out index 8fba5aea9c..ede66c3f81 100644 --- a/tests/qemu-iotests/074.out +++ b/tests/qemu-iotests/074.out @@ -4,7 +4,6 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741= 824 wrote 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Error while reading offset 0 of blkdebug:TEST_DIR/blkdebug.conf:= TEST_DIR/t.IMGFMT: Input/output error -qemu-img: Error while reading offset 0: Input/output error 4 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 Formatting 'TEST_DIR/t.IMGFMT.2', fmt=3DIMGFMT size=3D0 @@ -12,7 +11,6 @@ Formatting 'TEST_DIR/t.IMGFMT.2', fmt=3DIMGFMT size=3D0 wrote 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Error while reading offset 0 of blkdebug:TEST_DIR/blkdebug.conf:= TEST_DIR/t.IMGFMT: Input/output error -qemu-img: Error while reading offset 0 of blkdebug:TEST_DIR/blkdebug.conf:= TEST_DIR/t.IMGFMT: Input/output error Warning: Image size mismatch! 4 Cleanup --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507780729772125.2143857147928; Wed, 11 Oct 2017 20:58:49 -0700 (PDT) Received: from localhost ([::1]:43583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Udw-0002zV-32 for importer@patchew.org; Wed, 11 Oct 2017 23:58:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTp-0002zz-AK for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTm-0007md-89 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTi-0007hr-CN; Wed, 11 Oct 2017 23:48:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 693E93DBCE; Thu, 12 Oct 2017 03:48:09 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EA7060C82; Thu, 12 Oct 2017 03:48:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 693E93DBCE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:13 -0500 Message-Id: <20171012034720.11947-18-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 03:48:09 +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 v6 17/24] qemu-img: Change check_empty_sectors() to byte-based 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" Continue on the quest to make more things byte-based instead of sector-based. Signed-off-by: Eric Blake Reviewed-by: John Snow --- v4-v5: no change v3: new patch --- qemu-img.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 53cae6bb66..66d595be3d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1203,30 +1203,29 @@ static int64_t sectors_to_bytes(int64_t sectors) * an error message. * * @param blk: BlockBackend for the image - * @param sect_num: Number of first sector to check - * @param sect_count: Number of sectors to check + * @param offset: Starting offset to check + * @param bytes: Number of bytes to check * @param filename: Name of disk file we are checking (logging purpose) * @param buffer: Allocated buffer for storing read data * @param quiet: Flag for quiet mode */ -static int check_empty_sectors(BlockBackend *blk, int64_t sect_num, - int sect_count, const char *filename, +static int check_empty_sectors(BlockBackend *blk, int64_t offset, + int64_t bytes, const char *filename, uint8_t *buffer, bool quiet) { int ret =3D 0; int64_t idx; - ret =3D blk_pread(blk, sect_num << BDRV_SECTOR_BITS, buffer, - sect_count << BDRV_SECTOR_BITS); + ret =3D blk_pread(blk, offset, buffer, bytes); if (ret < 0) { error_report("Error while reading offset %" PRId64 " of %s: %s", - sectors_to_bytes(sect_num), filename, strerror(-ret)); + offset, filename, strerror(-ret)); return 4; } - idx =3D find_nonzero(buffer, sect_count * BDRV_SECTOR_SIZE); + idx =3D find_nonzero(buffer, bytes); if (idx >=3D 0) { qprintf(quiet, "Content mismatch at offset %" PRId64 "!\n", - sectors_to_bytes(sect_num) + idx); + offset + idx); return 1; } @@ -1471,10 +1470,12 @@ static int img_compare(int argc, char **argv) } else { nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_BITS= ); if (allocated1) { - ret =3D check_empty_sectors(blk1, sector_num, nb_sectors, + ret =3D check_empty_sectors(blk1, sector_num * BDRV_SECTOR= _SIZE, + nb_sectors * BDRV_SECTOR_SIZE, filename1, buf1, quiet); } else { - ret =3D check_empty_sectors(blk2, sector_num, nb_sectors, + ret =3D check_empty_sectors(blk2, sector_num * BDRV_SECTOR= _SIZE, + nb_sectors * BDRV_SECTOR_SIZE, filename2, buf1, quiet); } if (ret) { @@ -1519,7 +1520,9 @@ static int img_compare(int argc, char **argv) nb_sectors =3D count >> BDRV_SECTOR_BITS; if (ret & BDRV_BLOCK_ALLOCATED && !(ret & BDRV_BLOCK_ZERO)) { nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); - ret =3D check_empty_sectors(blk_over, sector_num, nb_secto= rs, + ret =3D check_empty_sectors(blk_over, + sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, filename_over, buf1, quiet); if (ret) { goto out; --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507780905321585.9117378518487; Wed, 11 Oct 2017 21:01:45 -0700 (PDT) Received: from localhost ([::1]:43603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Ugb-0005OE-HM for importer@patchew.org; Thu, 12 Oct 2017 00:01:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTp-0002zv-9r for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTn-0007nN-3t for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37224) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTk-0007l2-BR; Wed, 11 Oct 2017 23:48:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58A513DBC0; Thu, 12 Oct 2017 03:48:11 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB16360C82; Thu, 12 Oct 2017 03:48:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 58A513DBC0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:14 -0500 Message-Id: <20171012034720.11947-19-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 03:48:11 +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 v6 18/24] qemu-img: Change compare_sectors() to be byte-based 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" In the continuing quest to make more things byte-based, change compare_sectors(), renaming it to compare_buffers() in the process. Note that one caller (qemu-img compare) only cares about the first difference, while the other (qemu-img rebase) cares about how many consecutive sectors have the same equal/different status; however, this patch does not bother to micro-optimize the compare case to avoid the comparisons of sectors beyond the first mismatch. Both callers are always passing valid buffers in, so the initial check for buffer size can be turned into an assertion. Signed-off-by: Eric Blake Reviewed-by: John Snow --- v4-v5: no change v3: new patch --- qemu-img.c | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 66d595be3d..c6b6263853 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1156,31 +1156,28 @@ static int is_allocated_sectors_min(const uint8_t *= buf, int n, int *pnum, } /* - * Compares two buffers sector by sector. Returns 0 if the first sector of= both - * buffers matches, non-zero otherwise. + * Compares two buffers sector by sector. Returns 0 if the first + * sector of each buffer matches, non-zero otherwise. * - * pnum is set to the number of sectors (including and immediately followi= ng - * the first one) that are known to have the same comparison result + * pnum is set to the sector-aligned size of the buffer prefix that + * has the same matching status as the first sector. */ -static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n, - int *pnum) +static int compare_buffers(const uint8_t *buf1, const uint8_t *buf2, + int64_t bytes, int64_t *pnum) { bool res; - int i; + int64_t i =3D MIN(bytes, BDRV_SECTOR_SIZE); - if (n <=3D 0) { - *pnum =3D 0; - return 0; - } + assert(bytes > 0); - res =3D !!memcmp(buf1, buf2, 512); - for(i =3D 1; i < n; i++) { - buf1 +=3D 512; - buf2 +=3D 512; + res =3D !!memcmp(buf1, buf2, i); + while (i < bytes) { + int64_t len =3D MIN(bytes - i, BDRV_SECTOR_SIZE); - if (!!memcmp(buf1, buf2, 512) !=3D res) { + if (!!memcmp(buf1 + i, buf2 + i, len) !=3D res) { break; } + i +=3D len; } *pnum =3D i; @@ -1255,7 +1252,7 @@ static int img_compare(int argc, char **argv) int64_t total_sectors; int64_t sector_num =3D 0; int64_t nb_sectors; - int c, pnum; + int c; uint64_t progress_base; bool image_opts =3D false; bool force_share =3D false; @@ -1439,6 +1436,8 @@ static int img_compare(int argc, char **argv) /* nothing to do */ } else if (allocated1 =3D=3D allocated2) { if (allocated1) { + int64_t pnum; + nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); ret =3D blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, bu= f1, nb_sectors << BDRV_SECTOR_BITS); @@ -1458,11 +1457,11 @@ static int img_compare(int argc, char **argv) ret =3D 4; goto out; } - ret =3D compare_sectors(buf1, buf2, nb_sectors, &pnum); - if (ret || pnum !=3D nb_sectors) { + ret =3D compare_buffers(buf1, buf2, + nb_sectors * BDRV_SECTOR_SIZE, &pnum= ); + if (ret || pnum !=3D nb_sectors * BDRV_SECTOR_SIZE) { qprintf(quiet, "Content mismatch at offset %" PRId64 "= !\n", - sectors_to_bytes( - ret ? sector_num : sector_num + pnum)); + sectors_to_bytes(sector_num) + (ret ? 0 : pnum= )); ret =3D 1; goto out; } @@ -3354,16 +3353,16 @@ static int img_rebase(int argc, char **argv) /* If they differ, we need to write to the COW file */ uint64_t written =3D 0; - while (written < n) { - int pnum; + while (written < n * BDRV_SECTOR_SIZE) { + int64_t pnum; - if (compare_sectors(buf_old + written * 512, - buf_new + written * 512, n - written, &pnum)) + if (compare_buffers(buf_old + written, + buf_new + written, + n * BDRV_SECTOR_SIZE - written, &pnum)) { ret =3D blk_pwrite(blk, - (sector + written) << BDRV_SECTOR_BIT= S, - buf_old + written * 512, - pnum << BDRV_SECTOR_BITS, 0); + (sector << BDRV_SECTOR_BITS) + writte= n, + buf_old + written, pnum, 0); if (ret < 0) { error_report("Error while writing to COW image: %s= ", strerror(-ret)); --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507781065367823.3232322361482; Wed, 11 Oct 2017 21:04:25 -0700 (PDT) Received: from localhost ([::1]:43617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UjE-0007ZO-Id for importer@patchew.org; Thu, 12 Oct 2017 00:04:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTs-000330-8e for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTr-0007qS-5c for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTm-0007mM-Er; Wed, 11 Oct 2017 23:48:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68550820F7; Thu, 12 Oct 2017 03:48:13 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id B63DD6954A; Thu, 12 Oct 2017 03:48:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 68550820F7 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:15 -0500 Message-Id: <20171012034720.11947-20-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 12 Oct 2017 03:48:13 +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 v6 19/24] qemu-img: Change img_rebase() to be byte-based 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" In the continuing quest to make more things byte-based, change the internal iteration of img_rebase(). We can finally drop the TODO assertion added earlier, now that the entire algorithm is byte-based and no longer has to shift from bytes to sectors. Most of the change is mechanical ('num_sectors' becomes 'size', 'sector' becomes 'offset', 'n' goes from sectors to bytes); some of it is also a cleanup (use of MIN() instead of open-coding, loss of variable 'count' added earlier in commit d6a644bb). Signed-off-by: Eric Blake Reviewed-by: John Snow --- v4-v5: no change v3: new patch --- qemu-img.c | 84 +++++++++++++++++++++++++---------------------------------= ---- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c6b6263853..994365c6a4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3248,70 +3248,58 @@ static int img_rebase(int argc, char **argv) * the image is the same as the original one at any time. */ if (!unsafe) { - int64_t num_sectors; - int64_t old_backing_num_sectors; - int64_t new_backing_num_sectors =3D 0; - uint64_t sector; - int n; - int64_t count; + int64_t size; + int64_t old_backing_size; + int64_t new_backing_size =3D 0; + uint64_t offset; + int64_t n; float local_progress =3D 0; buf_old =3D blk_blockalign(blk, IO_BUF_SIZE); buf_new =3D blk_blockalign(blk, IO_BUF_SIZE); - num_sectors =3D blk_nb_sectors(blk); - if (num_sectors < 0) { + size =3D blk_getlength(blk); + if (size < 0) { error_report("Could not get size of '%s': %s", - filename, strerror(-num_sectors)); + filename, strerror(-size)); ret =3D -1; goto out; } - old_backing_num_sectors =3D blk_nb_sectors(blk_old_backing); - if (old_backing_num_sectors < 0) { + old_backing_size =3D blk_getlength(blk_old_backing); + if (old_backing_size < 0) { char backing_name[PATH_MAX]; bdrv_get_backing_filename(bs, backing_name, sizeof(backing_nam= e)); error_report("Could not get size of '%s': %s", - backing_name, strerror(-old_backing_num_sectors)); + backing_name, strerror(-old_backing_size)); ret =3D -1; goto out; } if (blk_new_backing) { - new_backing_num_sectors =3D blk_nb_sectors(blk_new_backing); - if (new_backing_num_sectors < 0) { + new_backing_size =3D blk_getlength(blk_new_backing); + if (new_backing_size < 0) { error_report("Could not get size of '%s': %s", - out_baseimg, strerror(-new_backing_num_sector= s)); + out_baseimg, strerror(-new_backing_size)); ret =3D -1; goto out; } } - if (num_sectors !=3D 0) { - local_progress =3D (float)100 / - (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512)); + if (size !=3D 0) { + local_progress =3D (float)100 / (size / MIN(size, IO_BUF_SIZE)= ); } - for (sector =3D 0; sector < num_sectors; sector +=3D n) { - - /* How many sectors can we handle with the next read? */ - if (sector + (IO_BUF_SIZE / 512) <=3D num_sectors) { - n =3D (IO_BUF_SIZE / 512); - } else { - n =3D num_sectors - sector; - } + for (offset =3D 0; offset < size; offset +=3D n) { + /* How many bytes can we handle with the next read? */ + n =3D MIN(IO_BUF_SIZE, size - offset); /* If the cluster is allocated, we don't need to take action */ - ret =3D bdrv_is_allocated(bs, sector << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, &count); + ret =3D bdrv_is_allocated(bs, offset, n, &n); if (ret < 0) { error_report("error while reading image metadata: %s", strerror(-ret)); goto out; } - /* TODO relax this once bdrv_is_allocated does not enforce - * sector alignment */ - assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); - n =3D count >> BDRV_SECTOR_BITS; if (ret) { continue; } @@ -3320,30 +3308,28 @@ static int img_rebase(int argc, char **argv) * Read old and new backing file and take into consideration t= hat * backing files may be smaller than the COW image. */ - if (sector >=3D old_backing_num_sectors) { - memset(buf_old, 0, n * BDRV_SECTOR_SIZE); + if (offset >=3D old_backing_size) { + memset(buf_old, 0, n); } else { - if (sector + n > old_backing_num_sectors) { - n =3D old_backing_num_sectors - sector; + if (offset + n > old_backing_size) { + n =3D old_backing_size - offset; } - ret =3D blk_pread(blk_old_backing, sector << BDRV_SECTOR_B= ITS, - buf_old, n << BDRV_SECTOR_BITS); + ret =3D blk_pread(blk_old_backing, offset, buf_old, n); if (ret < 0) { error_report("error while reading from old backing fil= e"); goto out; } } - if (sector >=3D new_backing_num_sectors || !blk_new_backing) { - memset(buf_new, 0, n * BDRV_SECTOR_SIZE); + if (offset >=3D new_backing_size || !blk_new_backing) { + memset(buf_new, 0, n); } else { - if (sector + n > new_backing_num_sectors) { - n =3D new_backing_num_sectors - sector; + if (offset + n > new_backing_size) { + n =3D new_backing_size - offset; } - ret =3D blk_pread(blk_new_backing, sector << BDRV_SECTOR_B= ITS, - buf_new, n << BDRV_SECTOR_BITS); + ret =3D blk_pread(blk_new_backing, offset, buf_new, n); if (ret < 0) { error_report("error while reading from new backing fil= e"); goto out; @@ -3353,15 +3339,13 @@ static int img_rebase(int argc, char **argv) /* If they differ, we need to write to the COW file */ uint64_t written =3D 0; - while (written < n * BDRV_SECTOR_SIZE) { + while (written < n) { int64_t pnum; - if (compare_buffers(buf_old + written, - buf_new + written, - n * BDRV_SECTOR_SIZE - written, &pnum)) + if (compare_buffers(buf_old + written, buf_new + written, + n - written, &pnum)) { - ret =3D blk_pwrite(blk, - (sector << BDRV_SECTOR_BITS) + writte= n, + ret =3D blk_pwrite(blk, offset + written, buf_old + written, pnum, 0); if (ret < 0) { error_report("Error while writing to COW image: %s= ", --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507780905017393.93325358652817; Wed, 11 Oct 2017 21:01:45 -0700 (PDT) Received: from localhost ([::1]:43606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Ugl-0005aX-4t for importer@patchew.org; Thu, 12 Oct 2017 00:01:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UTt-00034v-M4 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UTs-0007qy-0S for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTo-0007np-Bt; Wed, 11 Oct 2017 23:48:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 585367E44B; Thu, 12 Oct 2017 03:48:15 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id C154560C82; Thu, 12 Oct 2017 03:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 585367E44B 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:16 -0500 Message-Id: <20171012034720.11947-21-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 03:48:15 +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 v6 20/24] qemu-img: Change img_compare() to be byte-based 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" In the continuing quest to make more things byte-based, change the internal iteration of img_compare(). We can finally drop the TODO assertions added earlier, now that the entire algorithm is byte-based and no longer has to shift from bytes to sectors. Most of the change is mechanical ('total_sectors' becomes 'total_size', 'sector_num' becomes 'offset', 'nb_sectors' becomes 'chunk', 'progress_base' goes from sectors to bytes); some of it is also a cleanup (sectors_to_bytes() is now unused, loss of variable 'count' added earlier in commit 51b0a488). Signed-off-by: Eric Blake Reviewed-by: John Snow --- v6: rebase to split return interface change [Kevin], minor enough to keep R= -b v5: rebase to earlier change, minor enough to keep R-b v4: no change v3: new patch --- qemu-img.c | 124 ++++++++++++++++++++++++---------------------------------= ---- 1 file changed, 48 insertions(+), 76 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 994365c6a4..02a6e27beb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1186,11 +1186,6 @@ static int compare_buffers(const uint8_t *buf1, cons= t uint8_t *buf2, #define IO_BUF_SIZE (2 * 1024 * 1024) -static int64_t sectors_to_bytes(int64_t sectors) -{ - return sectors << BDRV_SECTOR_BITS; -} - /* * Check if passed sectors are empty (not allocated or contain only 0 byte= s) * @@ -1241,7 +1236,7 @@ static int img_compare(int argc, char **argv) const char *fmt1 =3D NULL, *fmt2 =3D NULL, *cache, *filename1, *filena= me2; BlockBackend *blk1, *blk2; BlockDriverState *bs1, *bs2; - int64_t total_sectors1, total_sectors2; + int64_t total_size1, total_size2; uint8_t *buf1 =3D NULL, *buf2 =3D NULL; int64_t pnum1, pnum2; int allocated1, allocated2; @@ -1249,9 +1244,9 @@ static int img_compare(int argc, char **argv) bool progress =3D false, quiet =3D false, strict =3D false; int flags; bool writethrough; - int64_t total_sectors; - int64_t sector_num =3D 0; - int64_t nb_sectors; + int64_t total_size; + int64_t offset =3D 0; + int64_t chunk; int c; uint64_t progress_base; bool image_opts =3D false; @@ -1365,39 +1360,37 @@ static int img_compare(int argc, char **argv) buf1 =3D blk_blockalign(blk1, IO_BUF_SIZE); buf2 =3D blk_blockalign(blk2, IO_BUF_SIZE); - total_sectors1 =3D blk_nb_sectors(blk1); - if (total_sectors1 < 0) { + total_size1 =3D blk_getlength(blk1); + if (total_size1 < 0) { error_report("Can't get size of %s: %s", - filename1, strerror(-total_sectors1)); + filename1, strerror(-total_size1)); ret =3D 4; goto out; } - total_sectors2 =3D blk_nb_sectors(blk2); - if (total_sectors2 < 0) { + total_size2 =3D blk_getlength(blk2); + if (total_size2 < 0) { error_report("Can't get size of %s: %s", - filename2, strerror(-total_sectors2)); + filename2, strerror(-total_size2)); ret =3D 4; goto out; } - total_sectors =3D MIN(total_sectors1, total_sectors2); - progress_base =3D MAX(total_sectors1, total_sectors2); + total_size =3D MIN(total_size1, total_size2); + progress_base =3D MAX(total_size1, total_size2); qemu_progress_print(0, 100); - if (strict && total_sectors1 !=3D total_sectors2) { + if (strict && total_size1 !=3D total_size2) { ret =3D 1; qprintf(quiet, "Strict mode: Image size mismatch!\n"); goto out; } - while (sector_num < total_sectors) { + while (offset < total_size) { int status1, status2; - status1 =3D bdrv_block_status_above(bs1, NULL, - sector_num * BDRV_SECTOR_SIZE, - (total_sectors1 - sector_num) * - BDRV_SECTOR_SIZE, - &pnum1, NULL, NULL); + status1 =3D bdrv_block_status_above(bs1, NULL, offset, + total_size1 - offset, &pnum1, NU= LL, + NULL); if (status1 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename1= ); @@ -1405,30 +1398,24 @@ static int img_compare(int argc, char **argv) } allocated1 =3D status1 & BDRV_BLOCK_ALLOCATED; - status2 =3D bdrv_block_status_above(bs2, NULL, - sector_num * BDRV_SECTOR_SIZE, - (total_sectors2 - sector_num) * - BDRV_SECTOR_SIZE, - &pnum2, NULL, NULL); + status2 =3D bdrv_block_status_above(bs2, NULL, offset, + total_size2 - offset, &pnum2, NU= LL, + NULL); if (status2 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename2= ); goto out; } allocated2 =3D status2 & BDRV_BLOCK_ALLOCATED; - /* TODO: Relax this once comparison is byte-based, and we no longer - * have to worry about sector alignment */ - assert(QEMU_IS_ALIGNED(pnum1 | pnum2, BDRV_SECTOR_SIZE)); assert(pnum1 && pnum2); - nb_sectors =3D MIN(pnum1, pnum2) >> BDRV_SECTOR_BITS; + chunk =3D MIN(pnum1, pnum2); if (strict) { if (status1 !=3D status2) { ret =3D 1; qprintf(quiet, "Strict mode: Offset %" PRId64 - " block status mismatch!\n", - sectors_to_bytes(sector_num)); + " block status mismatch!\n", offset); goto out; } } @@ -1438,59 +1425,54 @@ static int img_compare(int argc, char **argv) if (allocated1) { int64_t pnum; - nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); - ret =3D blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, bu= f1, - nb_sectors << BDRV_SECTOR_BITS); + chunk =3D MIN(chunk, IO_BUF_SIZE); + ret =3D blk_pread(blk1, offset, buf1, chunk); if (ret < 0) { - error_report("Error while reading offset %" PRId64 " o= f %s:" - " %s", sectors_to_bytes(sector_num), file= name1, - strerror(-ret)); + error_report("Error while reading offset %" PRId64 + " of %s: %s", + offset, filename1, strerror(-ret)); ret =3D 4; goto out; } - ret =3D blk_pread(blk2, sector_num << BDRV_SECTOR_BITS, bu= f2, - nb_sectors << BDRV_SECTOR_BITS); + ret =3D blk_pread(blk2, offset, buf2, chunk); if (ret < 0) { error_report("Error while reading offset %" PRId64 - " of %s: %s", sectors_to_bytes(sector_num= ), - filename2, strerror(-ret)); + " of %s: %s", + offset, filename2, strerror(-ret)); ret =3D 4; goto out; } - ret =3D compare_buffers(buf1, buf2, - nb_sectors * BDRV_SECTOR_SIZE, &pnum= ); - if (ret || pnum !=3D nb_sectors * BDRV_SECTOR_SIZE) { + ret =3D compare_buffers(buf1, buf2, chunk, &pnum); + if (ret || pnum !=3D chunk) { qprintf(quiet, "Content mismatch at offset %" PRId64 "= !\n", - sectors_to_bytes(sector_num) + (ret ? 0 : pnum= )); + offset + (ret ? 0 : pnum)); ret =3D 1; goto out; } } } else { - nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_BITS= ); + chunk =3D MIN(chunk, IO_BUF_SIZE); if (allocated1) { - ret =3D check_empty_sectors(blk1, sector_num * BDRV_SECTOR= _SIZE, - nb_sectors * BDRV_SECTOR_SIZE, + ret =3D check_empty_sectors(blk1, offset, chunk, filename1, buf1, quiet); } else { - ret =3D check_empty_sectors(blk2, sector_num * BDRV_SECTOR= _SIZE, - nb_sectors * BDRV_SECTOR_SIZE, + ret =3D check_empty_sectors(blk2, offset, chunk, filename2, buf1, quiet); } if (ret) { goto out; } } - sector_num +=3D nb_sectors; - qemu_progress_print(((float) nb_sectors / progress_base)*100, 100); + offset +=3D chunk; + qemu_progress_print(((float) chunk / progress_base) * 100, 100); } - if (total_sectors1 !=3D total_sectors2) { + if (total_size1 !=3D total_size2) { BlockBackend *blk_over; const char *filename_over; qprintf(quiet, "Warning: Image size mismatch!\n"); - if (total_sectors1 > total_sectors2) { + if (total_size1 > total_size2) { blk_over =3D blk1; filename_over =3D filename1; } else { @@ -1498,14 +1480,10 @@ static int img_compare(int argc, char **argv) filename_over =3D filename2; } - while (sector_num < progress_base) { - int64_t count; - - ret =3D bdrv_block_status_above(blk_bs(blk_over), NULL, - sector_num * BDRV_SECTOR_SIZE, - (progress_base - sector_num) * - BDRV_SECTOR_SIZE, - &count, NULL, NULL); + while (offset < progress_base) { + ret =3D bdrv_block_status_above(blk_bs(blk_over), NULL, offset, + progress_base - offset, &chunk, + NULL, NULL); if (ret < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", @@ -1513,22 +1491,16 @@ static int img_compare(int argc, char **argv) goto out; } - /* TODO relax this once bdrv_block_status_above does not enfor= ce - * sector alignment */ - assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); - nb_sectors =3D count >> BDRV_SECTOR_BITS; if (ret & BDRV_BLOCK_ALLOCATED && !(ret & BDRV_BLOCK_ZERO)) { - nb_sectors =3D MIN(nb_sectors, IO_BUF_SIZE >> BDRV_SECTOR_= BITS); - ret =3D check_empty_sectors(blk_over, - sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, + chunk =3D MIN(chunk, IO_BUF_SIZE); + ret =3D check_empty_sectors(blk_over, offset, chunk, filename_over, buf1, quiet); if (ret) { goto out; } } - sector_num +=3D nb_sectors; - qemu_progress_print(((float) nb_sectors / progress_base)*100, = 100); + offset +=3D chunk; + qemu_progress_print(((float) chunk / progress_base) * 100, 100= ); } } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1507781232346197.78901256993367; Wed, 11 Oct 2017 21:07:12 -0700 (PDT) Received: from localhost ([::1]:43636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Ulw-0001hB-1Q for importer@patchew.org; Thu, 12 Oct 2017 00:07:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UU2-0003Bu-OR for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UU1-0007xu-Fz for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTu-0007sY-Pu; Wed, 11 Oct 2017 23:48:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6E2561468; Thu, 12 Oct 2017 03:48:21 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id B47BA6954A; Thu, 12 Oct 2017 03:48:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6E2561468 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:17 -0500 Message-Id: <20171012034720.11947-22-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 12 Oct 2017 03:48:21 +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 v6 21/24] block: Align block status requests 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Any device that has request_alignment greater than 512 should be unable to report status at a finer granularity; it may also be simpler for such devices to be guaranteed that the block layer has rounded things out to the granularity boundary (the way the block layer already rounds all other I/O out). Besides, getting the code correct for super-sector alignment also benefits us for the fact that our public interface now has byte granularity, even though none of our drivers have byte-level callbacks. Add an assertion in blkdebug that proves that the block layer never requests status of unaligned sections, similar to what it does on other requests (while still keeping the generic helper in place for when future patches add a throttle driver). Note that iotest 177 already covers this (it would fail if you use just the blkdebug.c hunk without the io.c changes). Meanwhile, we can drop assertions in callers that no longer have to pass in sector-aligned addresses. There is a mid-function scope added for 'count' and 'longret', for a couple of reasons: first, an upcoming patch will add an 'if' statement that checks whether a driver has an old- or new-style callback, and can conveniently use the same scope for less indentation churn at that time. Second, since we are trying to get rid of sector-based computations, wrapping things in a scope makes it easier to group and see what will be deleted in a final cleanup patch once all drivers have been converted to the new-style callback. Signed-off-by: Eric Blake --- v6: rebase to split return interface change [Kevin] v5: rebase to earlier changes, add more comments v4: no change v3: tweak commit message [Fam], rebase to context conflicts, ensure we don't exceed 32-bit limit, drop R-b v2: new patch --- include/block/block_int.h | 3 +- block/io.c | 71 ++++++++++++++++++++++++++++++-------------= ---- block/blkdebug.c | 13 ++++++++- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 489b390fd6..4b9b23a08d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -207,7 +207,8 @@ struct BlockDriver { * according to the current layer, and should not set * BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h * for the meaning of _DATA, _ZERO, and _OFFSET_VALID. The block - * layer guarantees non-NULL pnum and file. + * layer guarantees input aligned to request_alignment, as well as + * non-NULL pnum and file. */ int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, diff --git a/block/io.c b/block/io.c index f0bd6aa63e..35431dc9dd 100644 --- a/block/io.c +++ b/block/io.c @@ -1819,10 +1819,11 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, { int64_t total_size; int64_t n; /* bytes */ - int64_t ret; + int ret; int64_t local_map =3D 0; BlockDriverState *local_file =3D NULL; - int count; /* sectors */ + int64_t aligned_offset, aligned_bytes; + uint32_t align; assert(pnum); *pnum =3D 0; @@ -1861,35 +1862,58 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, } bdrv_inc_in_flight(bs); + + /* Round out to request_alignment boundaries */ + /* TODO: until we have a byte-based driver callback, we also have to + * round out to sectors, even if that is bigger than request_alignment= */ + align =3D MAX(bs->bl.request_alignment, BDRV_SECTOR_SIZE); + aligned_offset =3D QEMU_ALIGN_DOWN(offset, align); + aligned_bytes =3D ROUND_UP(offset + bytes, align) - aligned_offset; + + { + int count; /* sectors */ + int64_t longret; + + assert(QEMU_IS_ALIGNED(aligned_offset | aligned_bytes, + BDRV_SECTOR_SIZE)); + /* + * The contract allows us to return pnum smaller than bytes, even + * if the next query would see the same status; we truncate the + * request to avoid overflowing the driver's 32-bit interface. + */ + longret =3D bs->drv->bdrv_co_get_block_status( + bs, aligned_offset >> BDRV_SECTOR_BITS, + MIN(INT_MAX, aligned_bytes) >> BDRV_SECTOR_BITS, &count, + &local_file); + if (longret < 0) { + assert(INT_MIN <=3D longret); + ret =3D longret; + goto out; + } + if (longret & BDRV_BLOCK_OFFSET_VALID) { + local_map =3D longret & BDRV_BLOCK_OFFSET_MASK; + } + ret =3D longret & ~BDRV_BLOCK_OFFSET_MASK; + *pnum =3D count * BDRV_SECTOR_SIZE; + } + /* - * TODO: Rather than require aligned offsets, we could instead - * round to the driver's request_alignment here, then touch up - * count afterwards back to the caller's expectations. + * The driver's result must be a multiple of request_alignment. + * Clamp pnum and adjust map to original request. */ - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); - /* - * The contract allows us to return pnum smaller than bytes, even - * if the next query would see the same status; we truncate the - * request to avoid overflowing the driver's 32-bit interface. - */ - bytes =3D MIN(bytes, BDRV_REQUEST_MAX_BYTES); - ret =3D bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTOR_BI= TS, - bytes >> BDRV_SECTOR_BITS, &co= unt, - &local_file); - if (ret < 0) { - goto out; + assert(QEMU_IS_ALIGNED(*pnum, align) && align > offset - aligned_offse= t); + *pnum -=3D offset - aligned_offset; + if (*pnum > bytes) { + *pnum =3D bytes; } if (ret & BDRV_BLOCK_OFFSET_VALID) { - local_map =3D ret & BDRV_BLOCK_OFFSET_MASK; + local_map +=3D offset - aligned_offset; } - *pnum =3D count * BDRV_SECTOR_SIZE; if (ret & BDRV_BLOCK_RAW) { assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file); ret =3D bdrv_co_block_status(local_file, want_zero, local_map, *pnum, pnum, &local_map, &local_file); - assert(ret < 0 || - QEMU_IS_ALIGNED(*pnum | local_map, BDRV_SECTOR_SIZE)); goto out; } @@ -1948,11 +1972,6 @@ early_out: if (map) { *map =3D local_map; } - if (ret >=3D 0) { - ret &=3D ~BDRV_BLOCK_OFFSET_MASK; - } else { - assert(INT_MIN <=3D ret); - } return ret; } diff --git a/block/blkdebug.c b/block/blkdebug.c index dfdf9b91aa..e21669979d 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -627,6 +627,17 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriv= erState *bs, return bdrv_co_pdiscard(bs->file->bs, offset, bytes); } +static int64_t coroutine_fn blkdebug_co_get_block_status( + BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, + BlockDriverState **file) +{ + assert(QEMU_IS_ALIGNED(sector_num | nb_sectors, + DIV_ROUND_UP(bs->bl.request_alignment, + BDRV_SECTOR_SIZE))); + return bdrv_co_get_block_status_from_file(bs, sector_num, nb_sectors, + pnum, file); +} + static void blkdebug_close(BlockDriverState *bs) { BDRVBlkdebugState *s =3D bs->opaque; @@ -896,7 +907,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 bdrv_co_get_block_status_from_file, + .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, --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507781076264974.5338563008711; Wed, 11 Oct 2017 21:04:36 -0700 (PDT) Received: from localhost ([::1]:43619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UjS-0007jm-EO for importer@patchew.org; Thu, 12 Oct 2017 00:04:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UU2-0003BB-BN for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UU1-0007y0-G0 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18283) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UTz-0007vb-D5; Wed, 11 Oct 2017 23:48:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 672D9820F5; Thu, 12 Oct 2017 03:48:26 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E1F96955E; Thu, 12 Oct 2017 03:48:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 672D9820F5 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:18 -0500 Message-Id: <20171012034720.11947-23-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 12 Oct 2017 03:48:26 +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 v6 22/24] block: Relax bdrv_aligned_preadv() assertion 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , 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" Now that bdrv_is_allocated accepts non-aligned inputs, we can remove the TODO added in commit d6a644bb. Signed-off-by: Eric Blake Reviewed-by: John Snow --- v4-v5: no change v3: new patch [Kevin] --- block/io.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/block/io.c b/block/io.c index 35431dc9dd..e4caa4acf1 100644 --- a/block/io.c +++ b/block/io.c @@ -1104,18 +1104,14 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChi= ld *child, } if (flags & BDRV_REQ_COPY_ON_READ) { - /* TODO: Simplify further once bdrv_is_allocated no longer - * requires sector alignment */ - int64_t start =3D QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); - int64_t end =3D QEMU_ALIGN_UP(offset + bytes, BDRV_SECTOR_SIZE); int64_t pnum; - ret =3D bdrv_is_allocated(bs, start, end - start, &pnum); + ret =3D bdrv_is_allocated(bs, offset, bytes, &pnum); if (ret < 0) { goto out; } - if (!ret || pnum !=3D end - start) { + if (!ret || pnum !=3D bytes) { ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov); goto out; } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507781095201387.89987804488555; Wed, 11 Oct 2017 21:04:55 -0700 (PDT) Received: from localhost ([::1]:43620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Uju-0008EF-Dy for importer@patchew.org; Thu, 12 Oct 2017 00:04:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UU3-0003Cd-Ij for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UU2-0007yx-ON for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UU0-0007wn-NY; Wed, 11 Oct 2017 23:48:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5F2151153; Thu, 12 Oct 2017 03:48:27 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAF346954A; Thu, 12 Oct 2017 03:48:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5F2151153 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=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:19 -0500 Message-Id: <20171012034720.11947-24-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 12 Oct 2017 03:48:27 +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 v6 23/24] qcow2: Relax is_zero() assertion 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" Now that bdrv_is_allocated accepts non-aligned inputs, we can remove the TODO added in earlier refactoring. Signed-off-by: Eric Blake --- v6: new patch [Kevin] --- block/qcow2.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 092a3cabdb..92cb9f9bfa 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3003,22 +3003,16 @@ static bool is_zero(BlockDriverState *bs, int64_t o= ffset, int64_t bytes) { int64_t nr; int res; - int64_t start; - - /* TODO: Widening to sector boundaries should only be needed as - * long as we can't query finer granularity. */ - start =3D QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); - bytes =3D QEMU_ALIGN_UP(offset + bytes, BDRV_SECTOR_SIZE) - start; /* Clamp to image length, before checking status of underlying sectors= */ - if (start + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { - bytes =3D bs->total_sectors * BDRV_SECTOR_SIZE - start; + if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { + bytes =3D bs->total_sectors * BDRV_SECTOR_SIZE - offset; } if (!bytes) { return true; } - res =3D bdrv_block_status_above(bs, NULL, start, bytes, &nr, NULL, NUL= L); + res =3D bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NU= LL); return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr =3D=3D bytes; } --=20 2.13.6 From nobody Thu Apr 25 09:16:03 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.zohomail.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 1507781234352876.1403186194789; Wed, 11 Oct 2017 21:07:14 -0700 (PDT) Received: from localhost ([::1]:43632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2Ulm-0001SH-79 for importer@patchew.org; Thu, 12 Oct 2017 00:06:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2UU8-0003IU-QH for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2UU7-00083w-IY for qemu-devel@nongnu.org; Wed, 11 Oct 2017 23:48:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37508) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2UU2-0007yS-Of; Wed, 11 Oct 2017 23:48:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDBDD3E2A1; Thu, 12 Oct 2017 03:48:29 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1769D60C82; Thu, 12 Oct 2017 03:48:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BDBDD3E2A1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 11 Oct 2017 22:47:20 -0500 Message-Id: <20171012034720.11947-25-eblake@redhat.com> In-Reply-To: <20171012034720.11947-1-eblake@redhat.com> References: <20171012034720.11947-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 03:48:29 +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 v6 24/24] qemu-io: Relax 'alloc' now that block-status doesn't assert 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: kwolf@redhat.com, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz 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" Previously, the alloc command required that input parameters be sector-aligned and clamped to 32 bits, because the underlying bdrv_is_allocated used a 32-bit parameter and asserted aligned inputs. But now that we have fixed block status to report a 64-bit bytes value, and to properly round requests on behalf of guests, we can pass any values, and can use qemu-io to add coverage that our rounding is correct regardless of the guest alignment constraints. Update iotest 177 to intentionally probe block status at unaligned boundaries as well as with a bytes value that does not map to 32-bit sectors, which also required tweaking the image prep to leave an unallocated portion to the image under test. Signed-off-by: Eric Blake --- v3: also test huge bytes value, R-b dropped v2: new patch --- qemu-io-cmds.c | 13 ------------- tests/qemu-iotests/177 | 12 ++++++++++-- tests/qemu-iotests/177.out | 19 ++++++++++++++----- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 3727fb43f3..de8e3de726 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1769,10 +1769,6 @@ static int alloc_f(BlockBackend *blk, int argc, char= **argv) if (offset < 0) { print_cvtnum_err(offset, argv[1]); return 0; - } else if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { - printf("%" PRId64 " is not a sector-aligned value for 'offset'\n", - offset); - return 0; } if (argc =3D=3D 3) { @@ -1780,19 +1776,10 @@ static int alloc_f(BlockBackend *blk, int argc, cha= r **argv) if (count < 0) { print_cvtnum_err(count, argv[2]); return 0; - } else if (count > INT_MAX * BDRV_SECTOR_SIZE) { - printf("length argument cannot exceed %llu, given %s\n", - INT_MAX * BDRV_SECTOR_SIZE, argv[2]); - return 0; } } else { count =3D BDRV_SECTOR_SIZE; } - if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { - printf("%" PRId64 " is not a sector-aligned value for 'count'\n", - count); - return 0; - } remaining =3D count; sum_alloc =3D 0; diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177 index f8ed8fb86b..28990977f1 100755 --- a/tests/qemu-iotests/177 +++ b/tests/qemu-iotests/177 @@ -51,7 +51,7 @@ echo "=3D=3D setting up files =3D=3D" TEST_IMG=3D"$TEST_IMG.base" _make_test_img $size $QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io _make_test_img -b "$TEST_IMG.base" -$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -P 22 0 110M" "$TEST_IMG" | _filter_qemu_io # Limited to 64k max-transfer echo @@ -82,6 +82,13 @@ $QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IM= G" \ -c "discard 80000001 30M" | _filter_qemu_io echo +echo "=3D=3D block status smaller than alignment =3D=3D" +limits=3Dalign=3D4k +$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \ + -c "alloc 1 1" -c "alloc 0x6dffff0 1000" -c "alloc 127m 5P" \ + -c map | _filter_qemu_io + +echo echo "=3D=3D verify image content =3D=3D" function verify_io() @@ -103,7 +110,8 @@ function verify_io() echo read -P 0 32M 32M echo read -P 22 64M 13M echo read -P $discarded 77M 29M - echo read -P 22 106M 22M + echo read -P 22 106M 4M + echo read -P 11 110M 18M } verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out index 43a777836c..f788b55e20 100644 --- a/tests/qemu-iotests/177.out +++ b/tests/qemu-iotests/177.out @@ -5,8 +5,8 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D13= 4217728 wrote 134217728/134217728 bytes at offset 0 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 backing_file= =3DTEST_DIR/t.IMGFMT.base -wrote 134217728/134217728 bytes at offset 0 -128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 115343360/115343360 bytes at offset 0 +110 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =3D=3D constrained alignment and max-transfer =3D=3D wrote 131072/131072 bytes at offset 1000 @@ -26,6 +26,13 @@ wrote 33554432/33554432 bytes at offset 33554432 discard 31457280/31457280 bytes at offset 80000001 30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +=3D=3D block status smaller than alignment =3D=3D +1/1 bytes allocated at offset 1 bytes +16/1000 bytes allocated at offset 110 MiB +0/1048576 bytes allocated at offset 127 MiB +110 MiB (0x6e00000) bytes allocated at offset 0 bytes (0x0) +18 MiB (0x1200000) bytes not allocated at offset 110 MiB (0x6e00000) + =3D=3D verify image content =3D=3D read 1000/1000 bytes at offset 0 1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -43,12 +50,14 @@ read 13631488/13631488 bytes at offset 67108864 13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 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) +read 4194304/4194304 bytes at offset 111149056 +4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 18874368/18874368 bytes at offset 115343360 +18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) Offset Length File 0 0x800000 TEST_DIR/t.IMGFMT 0x900000 0x2400000 TEST_DIR/t.IMGFMT 0x3c00000 0x1100000 TEST_DIR/t.IMGFMT -0x6a00000 0x1600000 TEST_DIR/t.IMGFMT +0x6a00000 0x400000 TEST_DIR/t.IMGFMT No errors were found on the image. *** done --=20 2.13.6