From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15200174542811016.7277385445545; Fri, 2 Mar 2018 11:04:14 -0800 (PST) Received: from localhost ([::1]:36906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpyX-0008Io-DT for importer@patchew.org; Fri, 02 Mar 2018 14:04:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erppz-000121-HQ for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppx-0002dM-5a for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:23 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47256 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppq-0002Vm-Tq; Fri, 02 Mar 2018 13:55:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29643EAEA6; Fri, 2 Mar 2018 18:55:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A21AAB588; Fri, 2 Mar 2018 18:55:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:12 +0100 Message-Id: <20180302185448.6314-2-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:09 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 01/37] block: Add .bdrv_co_block_status() callback 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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Now that the block layer exposes byte-based allocation, it's time to tackle the drivers. Add a new callback that operates on as small as byte boundaries. Subsequent patches will then update individual drivers, then finally remove .bdrv_co_get_block_status(). The new code also passes through the 'want_zero' hint, which will allow subsequent patches to further optimize callers that only care about how much of the image is allocated (want_zero is false), rather than full details about runs of zeroes and which offsets the allocation actually maps to (want_zero is true). As part of this effort, fix another part of the documentation: the claim in commit 4c41cb4 that BDRV_BLOCK_ALLOCATED is short for 'DATA || ZERO' is a lie at the block layer (see commit e88ae2264), even though it is how the bit is computed from the driver layer. After all, there are intentionally cases where we return ZERO but not ALLOCATED at the block layer, when we know that a read sees zero because the backing file is too short. Note that the driver interface is thus slightly different than the public interface with regards to which bits will be set, and what guarantees are provided on input. We also add an assertion that any driver using the new callback will make progress (the only time pnum will be 0 is if the block layer already handled an out-of-bounds request, or if there is an error); the old driver interface did not provide this guarantee, which could lead to some inf-loops in drastic corner-case failures. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 14 +++++++------- include/block/block_int.h | 20 +++++++++++++++----- block/io.c | 28 +++++++++++++++++++--------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 19b3ab9cb5..947e8876cd 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -115,19 +115,19 @@ typedef struct HDGeometry { * BDRV_BLOCK_ZERO: offset reads as zero * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw = data * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this - * layer (short for DATA || ZERO), set by block layer - * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this l= ayer + * layer rather than any backing, set by block layer + * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this + * layer, set by block layer * * Internal flag: * BDRV_BLOCK_RAW: for use by passthrough drivers, such as raw, to request * 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) 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: + * If BDRV_BLOCK_OFFSET_VALID is set, the map parameter represents the + * host offset within the returned BDS that is allocated for the + * corresponding raw guest 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 diff --git a/include/block/block_int.h b/include/block/block_int.h index 5ea63f8fa8..c93722b43a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -202,15 +202,25 @@ struct BlockDriver { /* * 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 input aligned to request_alignment, as well as - * non-NULL pnum and file. + * according to the current layer, and should only need to set + * BDRV_BLOCK_DATA, BDRV_BLOCK_ZERO, BDRV_BLOCK_OFFSET_VALID, + * and/or BDRV_BLOCK_RAW; if the current layer defers to a backing + * layer, the result should be 0 (and not BDRV_BLOCK_ZERO). See + * block.h for the overall meaning of the bits. As a hint, the + * flag want_zero is true if the caller cares more about precise + * mappings (favor accurate _OFFSET_VALID/_ZERO) or false for + * overall allocation (favor larger *pnum, perhaps by reporting + * _DATA instead of _ZERO). The block layer guarantees input + * clamped to bdrv_getlength() and aligned to request_alignment, + * as well as non-NULL pnum, map, and file; in turn, the driver + * must return an error or set pnum to an aligned non-zero value. */ int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file); + 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); =20 /* * Invalidate any cached meta-data. diff --git a/block/io.c b/block/io.c index 89d0745e95..b00c7e2e2c 100644 --- a/block/io.c +++ b/block/io.c @@ -1899,10 +1899,10 @@ int64_t coroutine_fn bdrv_co_get_block_status_from_= backing(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 'want_zero' is true, the caller is querying for mapping + * purposes, with a focus on valid BDRV_BLOCK_OFFSET_VALID, _DATA, and + * _ZERO where possible; otherwise, the result favors larger 'pnum', + * with a focus on accurate BDRV_BLOCK_ALLOCATED. * * If 'offset' is beyond the end of the disk image the return value is * BDRV_BLOCK_EOF and 'pnum' is set to 0. @@ -1959,7 +1959,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, =20 /* Must be non-NULL or bdrv_getlength() would have failed */ assert(bs->drv); - if (!bs->drv->bdrv_co_get_block_status) { + if (!bs->drv->bdrv_co_get_block_status && !bs->drv->bdrv_co_block_stat= us) { *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; if (offset + bytes =3D=3D total_size) { @@ -1976,13 +1976,14 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, bdrv_inc_in_flight(bs); =20 /* 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); + align =3D bs->bl.request_alignment; + if (bs->drv->bdrv_co_get_block_status && align < BDRV_SECTOR_SIZE) { + align =3D BDRV_SECTOR_SIZE; + } aligned_offset =3D QEMU_ALIGN_DOWN(offset, align); aligned_bytes =3D ROUND_UP(offset + bytes, align) - aligned_offset; =20 - { + if (bs->drv->bdrv_co_get_block_status) { int count; /* sectors */ int64_t longret; =20 @@ -2007,6 +2008,15 @@ static int coroutine_fn bdrv_co_block_status(BlockDr= iverState *bs, } ret =3D longret & ~BDRV_BLOCK_OFFSET_MASK; *pnum =3D count * BDRV_SECTOR_SIZE; + } else { + ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offse= t, + aligned_bytes, pnum, &local_ma= p, + &local_file); + if (ret < 0) { + *pnum =3D 0; + goto out; + } + assert(*pnum); /* The block driver must make progress */ } =20 /* --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017095716218.85326273880867; Fri, 2 Mar 2018 10:58:15 -0800 (PST) Received: from localhost ([::1]:36870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpsk-0003Dm-Sa for importer@patchew.org; Fri, 02 Mar 2018 13:58:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erppy-00010q-JK for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppw-0002cK-QI for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56442 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppq-0002Vl-Ti; Fri, 02 Mar 2018 13:55:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD15F404084B; Fri, 2 Mar 2018 18:55:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EDFC9C079; Fri, 2 Mar 2018 18:55:09 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:13 +0100 Message-Id: <20180302185448.6314-3-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:10 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 02/37] nvme: Drop pointless .bdrv_co_get_block_status() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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" From: Eric Blake Commit bdd6a90 has a bug: drivers should never directly set BDRV_BLOCK_ALLOCATED, but only io.c should do that (as needed). Instead, drivers should report BDRV_BLOCK_DATA if it knows that data comes from this BDS. But let's look at the bigger picture: semantically, the nvme driver is similar to the nbd, null, and raw drivers (no backing file, all data comes from this BDS). But while two of those other drivers have to supply the callback (null because it can special-case BDRV_BLOCK_ZERO, raw because it can special-case a different offset), in this case the block layer defaults are good enough without the callback at all (similar to nbd). So, fix the bug by deletion ;) Signed-off-by: Eric Blake Signed-off-by: Kevin Wolf --- block/nvme.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 75078022f6..8bca57aae6 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1072,18 +1072,6 @@ static int nvme_reopen_prepare(BDRVReopenState *reop= en_state, return 0; } =20 -static int64_t coroutine_fn nvme_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *= pnum, - BlockDriverState **fi= le) -{ - *pnum =3D nb_sectors; - *file =3D bs; - - return BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); -} - static void nvme_refresh_filename(BlockDriverState *bs, QDict *opts) { QINCREF(opts); @@ -1183,8 +1171,6 @@ static BlockDriver bdrv_nvme =3D { .bdrv_co_flush_to_disk =3D nvme_co_flush, .bdrv_reopen_prepare =3D nvme_reopen_prepare, =20 - .bdrv_co_get_block_status =3D nvme_co_get_block_status, - .bdrv_refresh_filename =3D nvme_refresh_filename, .bdrv_refresh_limits =3D nvme_refresh_limits, =20 --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017244928229.58105891048695; Fri, 2 Mar 2018 11:00:44 -0800 (PST) Received: from localhost ([::1]:36887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpv9-0005U1-02 for importer@patchew.org; Fri, 02 Mar 2018 14:00:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erppy-00011H-V2 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppw-0002cp-UK for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47994 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppq-0002Vk-Vt; Fri, 02 Mar 2018 13:55:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 417F08D744; Fri, 2 Mar 2018 18:55:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 200579C079; Fri, 2 Mar 2018 18:55:10 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:14 +0100 Message-Id: <20180302185448.6314-4-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:55:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:55:12 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/37] block: Switch passthrough drivers to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the generic helpers, and all passthrough clients (blkdebug, commit, mirror, throttle) accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block_int.h | 28 ++++++++++++++++------------ block/blkdebug.c | 20 +++++++++++--------- block/commit.c | 2 +- block/io.c | 36 ++++++++++++++++++++---------------- block/mirror.c | 2 +- block/throttle.c | 2 +- 6 files changed, 50 insertions(+), 40 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index c93722b43a..bf2598856c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1041,23 +1041,27 @@ void bdrv_format_default_perms(BlockDriverState *bs= , BdrvChild *c, uint64_t *nperm, uint64_t *nshared); =20 /* - * Default implementation for drivers to pass bdrv_co_get_block_status() to + * Default implementation for drivers to pass bdrv_co_block_status() to * their file. */ -int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *= bs, - int64_t sector_num, - int nb_sectors, - int *pnum, - BlockDriverState *= *file); +int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file); /* - * Default implementation for drivers to pass bdrv_co_get_block_status() to + * Default implementation for drivers to pass bdrv_co_block_status() to * their backing file. */ -int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverStat= e *bs, - int64_t sector_= num, - int nb_sectors, - int *pnum, - BlockDriverStat= e **file); +int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file= ); const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); diff --git a/block/blkdebug.c b/block/blkdebug.c index d83f23febd..589712475a 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -627,15 +627,17 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDri= verState *bs, return bdrv_co_pdiscard(bs->file->bs, offset, bytes); } =20 -static int64_t coroutine_fn blkdebug_co_get_block_status( - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, - BlockDriverState **file) +static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + 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); + assert(QEMU_IS_ALIGNED(offset | bytes, bs->bl.request_alignment)); + return bdrv_co_block_status_from_file(bs, want_zero, offset, bytes, + pnum, map, file); } =20 static void blkdebug_close(BlockDriverState *bs) @@ -907,7 +909,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_co_flush_to_disk =3D blkdebug_co_flush, .bdrv_co_pwrite_zeroes =3D blkdebug_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkdebug_co_pdiscard, - .bdrv_co_get_block_status =3D blkdebug_co_get_block_status, + .bdrv_co_block_status =3D blkdebug_co_block_status, =20 .bdrv_debug_event =3D blkdebug_debug_event, .bdrv_debug_breakpoint =3D blkdebug_debug_breakpoint, diff --git a/block/commit.c b/block/commit.c index bb6c904704..1943c9c3e1 100644 --- a/block/commit.c +++ b/block/commit.c @@ -265,7 +265,7 @@ static void bdrv_commit_top_child_perm(BlockDriverState= *bs, BdrvChild *c, static BlockDriver bdrv_commit_top =3D { .format_name =3D "commit_top", .bdrv_co_preadv =3D bdrv_commit_top_preadv, - .bdrv_co_get_block_status =3D bdrv_co_get_block_status_from_backing, + .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_commit_top_refresh_filename, .bdrv_close =3D bdrv_commit_top_close, .bdrv_child_perm =3D bdrv_commit_top_child_perm, diff --git a/block/io.c b/block/io.c index b00c7e2e2c..5bae79f282 100644 --- a/block/io.c +++ b/block/io.c @@ -1868,30 +1868,34 @@ typedef struct BdrvCoBlockStatusData { bool done; } BdrvCoBlockStatusData; =20 -int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *= bs, - int64_t sector_num, - int nb_sectors, - int *pnum, - BlockDriverState *= *file) +int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { assert(bs->file && bs->file->bs); - *pnum =3D nb_sectors; + *pnum =3D bytes; + *map =3D offset; *file =3D bs->file->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 -int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverStat= e *bs, - int64_t sector_= num, - int nb_sectors, - int *pnum, - BlockDriverStat= e **file) +int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { assert(bs->backing && bs->backing->bs); - *pnum =3D nb_sectors; + *pnum =3D bytes; + *map =3D offset; *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 /* diff --git a/block/mirror.c b/block/mirror.c index c9badc1203..f5bf620942 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1094,7 +1094,7 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_pwrite_zeroes =3D bdrv_mirror_top_pwrite_zeroes, .bdrv_co_pdiscard =3D bdrv_mirror_top_pdiscard, .bdrv_co_flush =3D bdrv_mirror_top_flush, - .bdrv_co_get_block_status =3D bdrv_co_get_block_status_from_backing, + .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_mirror_top_refresh_filename, .bdrv_close =3D bdrv_mirror_top_close, .bdrv_child_perm =3D bdrv_mirror_top_child_perm, diff --git a/block/throttle.c b/block/throttle.c index 495f88c752..5f4d43d0fc 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -240,7 +240,7 @@ static BlockDriver bdrv_throttle =3D { .bdrv_reopen_prepare =3D throttle_reopen_prepare, .bdrv_reopen_commit =3D throttle_reopen_commit, .bdrv_reopen_abort =3D throttle_reopen_abort, - .bdrv_co_get_block_status =3D bdrv_co_get_block_status_fro= m_file, + .bdrv_co_block_status =3D bdrv_co_block_status_from_fi= le, =20 .bdrv_co_drain_begin =3D throttle_co_drain_begin, .bdrv_co_drain_end =3D throttle_co_drain_end, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017056029392.79208089556823; Fri, 2 Mar 2018 10:57:36 -0800 (PST) Received: from localhost ([::1]:36868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erps6-0002e6-Uc for importer@patchew.org; Fri, 02 Mar 2018 13:57:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erppy-00010r-JL for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppw-0002cP-P4 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60088 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppq-0002Vy-Vs; Fri, 02 Mar 2018 13:55:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7059402291E; Fri, 2 Mar 2018 18:55:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6965AB583; Fri, 2 Mar 2018 18:55:12 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:15 +0100 Message-Id: <20180302185448.6314-5-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:13 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 04/37] file-posix: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the file protocol driver accordingly. In want_zero mode, we continue to report fine-grained hole information (the caller wants as much mapping detail as possible); but when not in that mode, the caller prefers larger *pnum and merely cares about what offsets are allocated at this layer, rather than where the holes live. Since holes still read as zeroes at this layer (rather than deferring to a backing layer), we can take the shortcut of skipping lseek(), and merely state that all bytes are allocated. We can also drop redundant bounds checks that are already guaranteed by the block layer. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/file-posix.c | 64 +++++++++++++++++++++++++-------------------------= ---- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index ca49c1a98a..f1591c3849 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2131,25 +2131,24 @@ static int find_allocation(BlockDriverState *bs, of= f_t start, } =20 /* - * Returns the allocation status of the specified sectors. + * Returns the allocation status of the specified offset. * - * If 'sector_num' is beyond the end of the disk image the return value is= 0 - * and 'pnum' is set to 0. + * The block layer guarantees 'offset' and 'bytes' are within bounds. * - * 'pnum' is set to the number of sectors (including and immediately follo= wing - * the specified sector) that are known to be in the same + * 'pnum' is set to the number of bytes (including and immediately followi= ng + * the specified offset) 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 - * beyond the end of the disk image it will be clamped. + * 'bytes' is the max value 'pnum' should be set to. */ -static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *p= num, - BlockDriverState **fil= e) -{ - off_t start, data =3D 0, hole =3D 0; - int64_t total_size; +static int coroutine_fn raw_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) +{ + off_t data =3D 0, hole =3D 0; int ret; =20 ret =3D fd_open(bs); @@ -2157,39 +2156,36 @@ static int64_t coroutine_fn raw_co_get_block_status= (BlockDriverState *bs, return ret; } =20 - start =3D sector_num * BDRV_SECTOR_SIZE; - total_size =3D bdrv_getlength(bs); - if (total_size < 0) { - return total_size; - } else if (start >=3D total_size) { - *pnum =3D 0; - return 0; - } else if (start + nb_sectors * BDRV_SECTOR_SIZE > total_size) { - nb_sectors =3D DIV_ROUND_UP(total_size - start, BDRV_SECTOR_SIZE); + if (!want_zero) { + *pnum =3D bytes; + *map =3D offset; + *file =3D bs; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 - ret =3D find_allocation(bs, start, &data, &hole); + ret =3D find_allocation(bs, offset, &data, &hole); if (ret =3D=3D -ENXIO) { /* Trailing hole */ - *pnum =3D nb_sectors; + *pnum =3D bytes; ret =3D BDRV_BLOCK_ZERO; } else if (ret < 0) { /* No info available, so pretend there are no holes */ - *pnum =3D nb_sectors; + *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA; - } else if (data =3D=3D start) { - /* On a data extent, compute sectors to the end of the extent, + } else if (data =3D=3D offset) { + /* On a data extent, compute bytes to the end of the extent, * possibly including a partial sector at EOF. */ - *pnum =3D MIN(nb_sectors, DIV_ROUND_UP(hole - start, BDRV_SECTOR_S= IZE)); + *pnum =3D MIN(bytes, hole - offset); ret =3D BDRV_BLOCK_DATA; } else { - /* On a hole, compute sectors to the beginning of the next extent.= */ - assert(hole =3D=3D start); - *pnum =3D MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE); + /* On a hole, compute bytes to the beginning of the next extent. = */ + assert(hole =3D=3D offset); + *pnum =3D MIN(bytes, data - offset); ret =3D BDRV_BLOCK_ZERO; } + *map =3D offset; *file =3D bs; - return ret | BDRV_BLOCK_OFFSET_VALID | start; + return ret | BDRV_BLOCK_OFFSET_VALID; } =20 static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs, @@ -2282,7 +2278,7 @@ BlockDriver bdrv_file =3D { .bdrv_close =3D raw_close, .bdrv_create =3D raw_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_co_get_block_status =3D raw_co_get_block_status, + .bdrv_co_block_status =3D raw_co_block_status, .bdrv_co_pwrite_zeroes =3D raw_co_pwrite_zeroes, =20 .bdrv_co_preadv =3D raw_co_preadv, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017108160306.0054060918268; Fri, 2 Mar 2018 10:58:28 -0800 (PST) Received: from localhost ([::1]:36871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpsx-0003PZ-Az for importer@patchew.org; Fri, 02 Mar 2018 13:58:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erppy-00011I-Vh for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppx-0002d9-3o for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45386 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpps-0002Wy-1D; Fri, 02 Mar 2018 13:55:16 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59B5140FB659; Fri, 2 Mar 2018 18:55:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A1EAAB589; Fri, 2 Mar 2018 18:55:14 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:16 +0100 Message-Id: <20180302185448.6314-6-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 02 Mar 2018 18:55:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 02 Mar 2018 18:55:15 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 05/37] gluster: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the gluster driver accordingly. In want_zero mode, we continue to report fine-grained hole information (the caller wants as much mapping detail as possible); but when not in that mode, the caller prefers larger *pnum and merely cares about what offsets are allocated at this layer, rather than where the holes live. Since holes still read as zeroes at this layer (rather than deferring to a backing layer), we can take the shortcut of skipping find_allocation(), and merely state that all bytes are allocated. We can also drop redundant bounds checks that are already guaranteed by the block layer. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/gluster.c | 70 ++++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 3f17b7819d..1a07d221d1 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1362,68 +1362,66 @@ exit: } =20 /* - * Returns the allocation status of the specified sectors. + * Returns the allocation status of the specified offset. * - * If 'sector_num' is beyond the end of the disk image the return value is= 0 - * and 'pnum' is set to 0. + * The block layer guarantees 'offset' and 'bytes' are within bounds. * - * 'pnum' is set to the number of sectors (including and immediately follo= wing - * the specified sector) that are known to be in the same + * 'pnum' is set to the number of bytes (including and immediately followi= ng + * the specified offset) 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 - * beyond the end of the disk image it will be clamped. + * 'bytes' is the max value 'pnum' should be set to. * - * (Based on raw_co_get_block_status() from file-posix.c.) + * (Based on raw_co_block_status() from file-posix.c.) */ -static int64_t coroutine_fn qemu_gluster_co_get_block_status( - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnu= m, - BlockDriverState **file) +static int coroutine_fn qemu_gluster_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **fi= le) { BDRVGlusterState *s =3D bs->opaque; - off_t start, data =3D 0, hole =3D 0; - int64_t total_size; + off_t data =3D 0, hole =3D 0; int ret =3D -EINVAL; =20 if (!s->fd) { return ret; } =20 - start =3D sector_num * BDRV_SECTOR_SIZE; - total_size =3D bdrv_getlength(bs); - if (total_size < 0) { - return total_size; - } else if (start >=3D total_size) { - *pnum =3D 0; - return 0; - } else if (start + nb_sectors * BDRV_SECTOR_SIZE > total_size) { - nb_sectors =3D DIV_ROUND_UP(total_size - start, BDRV_SECTOR_SIZE); + if (!want_zero) { + *pnum =3D bytes; + *map =3D offset; + *file =3D bs; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 - ret =3D find_allocation(bs, start, &data, &hole); + ret =3D find_allocation(bs, offset, &data, &hole); if (ret =3D=3D -ENXIO) { /* Trailing hole */ - *pnum =3D nb_sectors; + *pnum =3D bytes; ret =3D BDRV_BLOCK_ZERO; } else if (ret < 0) { /* No info available, so pretend there are no holes */ - *pnum =3D nb_sectors; + *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA; - } else if (data =3D=3D start) { - /* On a data extent, compute sectors to the end of the extent, + } else if (data =3D=3D offset) { + /* On a data extent, compute bytes to the end of the extent, * possibly including a partial sector at EOF. */ - *pnum =3D MIN(nb_sectors, DIV_ROUND_UP(hole - start, BDRV_SECTOR_S= IZE)); + *pnum =3D MIN(bytes, hole - offset); ret =3D BDRV_BLOCK_DATA; } else { - /* On a hole, compute sectors to the beginning of the next extent.= */ - assert(hole =3D=3D start); - *pnum =3D MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE); + /* On a hole, compute bytes to the beginning of the next extent. = */ + assert(hole =3D=3D offset); + *pnum =3D MIN(bytes, data - offset); ret =3D BDRV_BLOCK_ZERO; } =20 + *map =3D offset; *file =3D bs; =20 - return ret | BDRV_BLOCK_OFFSET_VALID | start; + return ret | BDRV_BLOCK_OFFSET_VALID; } =20 =20 @@ -1451,7 +1449,7 @@ static BlockDriver bdrv_gluster =3D { #ifdef CONFIG_GLUSTERFS_ZEROFILL .bdrv_co_pwrite_zeroes =3D qemu_gluster_co_pwrite_zeroes, #endif - .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, + .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, }; =20 @@ -1479,7 +1477,7 @@ static BlockDriver bdrv_gluster_tcp =3D { #ifdef CONFIG_GLUSTERFS_ZEROFILL .bdrv_co_pwrite_zeroes =3D qemu_gluster_co_pwrite_zeroes, #endif - .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, + .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, }; =20 @@ -1507,7 +1505,7 @@ static BlockDriver bdrv_gluster_unix =3D { #ifdef CONFIG_GLUSTERFS_ZEROFILL .bdrv_co_pwrite_zeroes =3D qemu_gluster_co_pwrite_zeroes, #endif - .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, + .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, }; =20 @@ -1541,7 +1539,7 @@ static BlockDriver bdrv_gluster_rdma =3D { #ifdef CONFIG_GLUSTERFS_ZEROFILL .bdrv_co_pwrite_zeroes =3D qemu_gluster_co_pwrite_zeroes, #endif - .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, + .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, }; =20 --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017267078580.4467418831646; Fri, 2 Mar 2018 11:01:07 -0800 (PST) Received: from localhost ([::1]:36891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpvW-0005nA-8p for importer@patchew.org; Fri, 02 Mar 2018 14:01:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erppy-00011D-UO for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppx-0002d2-1P for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60090 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppt-0002YG-Da; Fri, 02 Mar 2018 13:55:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDBCB402291E; Fri, 2 Mar 2018 18:55:16 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0037AB583; Fri, 2 Mar 2018 18:55:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:17 +0100 Message-Id: <20180302185448.6314-7-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:16 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 06/37] iscsi: Switch cluster_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert all uses of the cluster size in sectors, along with adding assertions that we are not dividing by zero. Improve some comment grammar while in the area. Signed-off-by: Eric Blake Acked-by: Paolo Bonzini Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 421983dd6f..3414c21c7f 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -86,7 +86,7 @@ typedef struct IscsiLun { unsigned long *allocmap; unsigned long *allocmap_valid; long allocmap_size; - int cluster_sectors; + int cluster_size; bool use_16_for_rw; bool write_protected; bool lbpme; @@ -430,9 +430,10 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, int= open_flags) { iscsi_allocmap_free(iscsilun); =20 + assert(iscsilun->cluster_size); iscsilun->allocmap_size =3D - DIV_ROUND_UP(sector_lun2qemu(iscsilun->num_blocks, iscsilun), - iscsilun->cluster_sectors); + DIV_ROUND_UP(iscsilun->num_blocks * iscsilun->block_size, + iscsilun->cluster_size); =20 iscsilun->allocmap =3D bitmap_try_new(iscsilun->allocmap_size); if (!iscsilun->allocmap) { @@ -440,7 +441,7 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, int = open_flags) } =20 if (open_flags & BDRV_O_NOCACHE) { - /* in case that cache.direct =3D on all allocmap entries are + /* when cache.direct =3D on all allocmap entries are * treated as invalid to force a relookup of the block * status on every read request */ return 0; @@ -461,17 +462,19 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sec= tor_num, int nb_sectors, bool allocated, bool valid) { int64_t cl_num_expanded, nb_cls_expanded, cl_num_shrunk, nb_cls_shrunk; + int cluster_sectors =3D iscsilun->cluster_size >> BDRV_SECTOR_BITS; =20 if (iscsilun->allocmap =3D=3D NULL) { return; } /* expand to entirely contain all affected clusters */ - cl_num_expanded =3D sector_num / iscsilun->cluster_sectors; + assert(cluster_sectors); + cl_num_expanded =3D sector_num / cluster_sectors; nb_cls_expanded =3D DIV_ROUND_UP(sector_num + nb_sectors, - iscsilun->cluster_sectors) - cl_num_exp= anded; + cluster_sectors) - cl_num_expanded; /* shrink to touch only completely contained clusters */ - cl_num_shrunk =3D DIV_ROUND_UP(sector_num, iscsilun->cluster_sectors); - nb_cls_shrunk =3D (sector_num + nb_sectors) / iscsilun->cluster_sectors + cl_num_shrunk =3D DIV_ROUND_UP(sector_num, cluster_sectors); + nb_cls_shrunk =3D (sector_num + nb_sectors) / cluster_sectors - cl_num_shrunk; if (allocated) { bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded); @@ -535,9 +538,12 @@ iscsi_allocmap_is_allocated(IscsiLun *iscsilun, int64_= t sector_num, if (iscsilun->allocmap =3D=3D NULL) { return true; } - size =3D DIV_ROUND_UP(sector_num + nb_sectors, iscsilun->cluster_secto= rs); + assert(iscsilun->cluster_size); + size =3D DIV_ROUND_UP(sector_num + nb_sectors, + iscsilun->cluster_size >> BDRV_SECTOR_BITS); return !(find_next_bit(iscsilun->allocmap, size, - sector_num / iscsilun->cluster_sectors) =3D=3D = size); + sector_num * BDRV_SECTOR_SIZE / + iscsilun->cluster_size) =3D=3D size); } =20 static inline bool iscsi_allocmap_is_valid(IscsiLun *iscsilun, @@ -547,9 +553,12 @@ static inline bool iscsi_allocmap_is_valid(IscsiLun *i= scsilun, if (iscsilun->allocmap_valid =3D=3D NULL) { return false; } - size =3D DIV_ROUND_UP(sector_num + nb_sectors, iscsilun->cluster_secto= rs); + assert(iscsilun->cluster_size); + size =3D DIV_ROUND_UP(sector_num + nb_sectors, + iscsilun->cluster_size >> BDRV_SECTOR_BITS); return (find_next_zero_bit(iscsilun->allocmap_valid, size, - sector_num / iscsilun->cluster_sectors) =3D= =3D size); + sector_num * BDRV_SECTOR_SIZE / + iscsilun->cluster_size) =3D=3D size); } =20 static int coroutine_fn @@ -793,16 +802,21 @@ static int coroutine_fn iscsi_co_readv(BlockDriverSta= te *bs, BlockDriverState *file; /* check the block status from the beginning of the cluster * containing the start sector */ - int64_t ret =3D iscsi_co_get_block_status(bs, - sector_num - sector_num % iscsilun->cluster_sect= ors, - BDRV_REQUEST_MAX_SECTORS, &pnum, &file); + int cluster_sectors =3D iscsilun->cluster_size >> BDRV_SECTOR_BITS; + int head; + int64_t ret; + + assert(cluster_sectors); + head =3D sector_num % cluster_sectors; + ret =3D iscsi_co_get_block_status(bs, sector_num - head, + BDRV_REQUEST_MAX_SECTORS, &pnum, + &file); if (ret < 0) { return ret; } /* if the whole request falls into an unallocated area we can avoid - * to read and directly return zeroes instead */ - if (ret & BDRV_BLOCK_ZERO && - pnum >=3D nb_sectors + sector_num % iscsilun->cluster_sectors)= { + * reading and directly return zeroes instead */ + if (ret & BDRV_BLOCK_ZERO && pnum >=3D nb_sectors + head) { qemu_iovec_memset(iov, 0, 0x00, iov->size); return 0; } @@ -1953,8 +1967,8 @@ static int iscsi_open(BlockDriverState *bs, QDict *op= tions, int flags, * reasonable size */ if (iscsilun->bl.opt_unmap_gran * iscsilun->block_size >=3D 4 * 1024 && iscsilun->bl.opt_unmap_gran * iscsilun->block_size <=3D 16 * 1024 = * 1024) { - iscsilun->cluster_sectors =3D (iscsilun->bl.opt_unmap_gran * - iscsilun->block_size) >> BDRV_SECTOR_= BITS; + iscsilun->cluster_size =3D iscsilun->bl.opt_unmap_gran * + iscsilun->block_size; if (iscsilun->lbprz) { ret =3D iscsi_allocmap_init(iscsilun, bs->open_flags); } @@ -2163,7 +2177,7 @@ static int iscsi_get_info(BlockDriverState *bs, Block= DriverInfo *bdi) { IscsiLun *iscsilun =3D bs->opaque; bdi->unallocated_blocks_are_zero =3D iscsilun->lbprz; - bdi->cluster_size =3D iscsilun->cluster_sectors * BDRV_SECTOR_SIZE; + bdi->cluster_size =3D iscsilun->cluster_size; return 0; } =20 --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017434570816.6413277772042; Fri, 2 Mar 2018 11:03:54 -0800 (PST) Received: from localhost ([::1]:36904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpyD-00082E-G5 for importer@patchew.org; Fri, 02 Mar 2018 14:03:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpq1-00015F-Ua for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erppz-0002gB-Hd for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:26 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47268 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppu-0002a0-Vq; Fri, 02 Mar 2018 13:55:19 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 714D3FA466; Fri, 2 Mar 2018 18:55:18 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 511A79C079; Fri, 2 Mar 2018 18:55:17 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:18 +0100 Message-Id: <20180302185448.6314-8-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:18 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/37] iscsi: Switch iscsi_allocmap_update() 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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert all uses of the allocmap (no semantic change). Callers that already had bytes available are simpler, and callers that now scale to bytes will be easier to switch to byte-based in the future. Signed-off-by: Eric Blake Acked-by: Paolo Bonzini Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/iscsi.c | 90 +++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 3414c21c7f..d2b0466775 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -458,24 +458,22 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, in= t open_flags) } =20 static void -iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors, bool allocated, bool valid) +iscsi_allocmap_update(IscsiLun *iscsilun, int64_t offset, + int64_t bytes, bool allocated, bool valid) { int64_t cl_num_expanded, nb_cls_expanded, cl_num_shrunk, nb_cls_shrunk; - int cluster_sectors =3D iscsilun->cluster_size >> BDRV_SECTOR_BITS; =20 if (iscsilun->allocmap =3D=3D NULL) { return; } /* expand to entirely contain all affected clusters */ - assert(cluster_sectors); - cl_num_expanded =3D sector_num / cluster_sectors; - nb_cls_expanded =3D DIV_ROUND_UP(sector_num + nb_sectors, - cluster_sectors) - cl_num_expanded; + assert(iscsilun->cluster_size); + cl_num_expanded =3D offset / iscsilun->cluster_size; + nb_cls_expanded =3D DIV_ROUND_UP(offset + bytes, + iscsilun->cluster_size) - cl_num_expand= ed; /* shrink to touch only completely contained clusters */ - cl_num_shrunk =3D DIV_ROUND_UP(sector_num, cluster_sectors); - nb_cls_shrunk =3D (sector_num + nb_sectors) / cluster_sectors - - cl_num_shrunk; + cl_num_shrunk =3D DIV_ROUND_UP(offset, iscsilun->cluster_size); + nb_cls_shrunk =3D (offset + bytes) / iscsilun->cluster_size - cl_num_s= hrunk; if (allocated) { bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded); } else { @@ -498,26 +496,26 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sec= tor_num, } =20 static void -iscsi_allocmap_set_allocated(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors) +iscsi_allocmap_set_allocated(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { - iscsi_allocmap_update(iscsilun, sector_num, nb_sectors, true, true); + iscsi_allocmap_update(iscsilun, offset, bytes, true, true); } =20 static void -iscsi_allocmap_set_unallocated(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors) +iscsi_allocmap_set_unallocated(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { /* Note: if cache.direct=3Don the fifth argument to iscsi_allocmap_upd= ate * is ignored, so this will in effect be an iscsi_allocmap_set_invalid. */ - iscsi_allocmap_update(iscsilun, sector_num, nb_sectors, false, true); + iscsi_allocmap_update(iscsilun, offset, bytes, false, true); } =20 -static void iscsi_allocmap_set_invalid(IscsiLun *iscsilun, int64_t sector_= num, - int nb_sectors) +static void iscsi_allocmap_set_invalid(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { - iscsi_allocmap_update(iscsilun, sector_num, nb_sectors, false, false); + iscsi_allocmap_update(iscsilun, offset, bytes, false, false); } =20 static void iscsi_allocmap_invalidate(IscsiLun *iscsilun) @@ -531,34 +529,30 @@ static void iscsi_allocmap_invalidate(IscsiLun *iscsi= lun) } =20 static inline bool -iscsi_allocmap_is_allocated(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors) +iscsi_allocmap_is_allocated(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { unsigned long size; if (iscsilun->allocmap =3D=3D NULL) { return true; } assert(iscsilun->cluster_size); - size =3D DIV_ROUND_UP(sector_num + nb_sectors, - iscsilun->cluster_size >> BDRV_SECTOR_BITS); + size =3D DIV_ROUND_UP(offset + bytes, iscsilun->cluster_size); return !(find_next_bit(iscsilun->allocmap, size, - sector_num * BDRV_SECTOR_SIZE / - iscsilun->cluster_size) =3D=3D size); + offset / iscsilun->cluster_size) =3D=3D size); } =20 static inline bool iscsi_allocmap_is_valid(IscsiLun *iscsilun, - int64_t sector_num, int nb_sect= ors) + int64_t offset, int64_t bytes) { unsigned long size; if (iscsilun->allocmap_valid =3D=3D NULL) { return false; } assert(iscsilun->cluster_size); - size =3D DIV_ROUND_UP(sector_num + nb_sectors, - iscsilun->cluster_size >> BDRV_SECTOR_BITS); + size =3D DIV_ROUND_UP(offset + bytes, iscsilun->cluster_size); return (find_next_zero_bit(iscsilun->allocmap_valid, size, - sector_num * BDRV_SECTOR_SIZE / - iscsilun->cluster_size) =3D=3D size); + offset / iscsilun->cluster_size) =3D=3D siz= e); } =20 static int coroutine_fn @@ -640,14 +634,16 @@ retry: } =20 if (iTask.status !=3D SCSI_STATUS_GOOD) { - iscsi_allocmap_set_invalid(iscsilun, sector_num, nb_sectors); + iscsi_allocmap_set_invalid(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); error_report("iSCSI WRITE10/16 failed at lba %" PRIu64 ": %s", lba, iTask.err_str); r =3D iTask.err_code; goto out_unlock; } =20 - iscsi_allocmap_set_allocated(iscsilun, sector_num, nb_sectors); + iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); =20 out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -747,9 +743,11 @@ retry: } =20 if (ret & BDRV_BLOCK_ZERO) { - iscsi_allocmap_set_unallocated(iscsilun, sector_num, *pnum); + iscsi_allocmap_set_unallocated(iscsilun, sector_num * BDRV_SECTOR_= SIZE, + *pnum * BDRV_SECTOR_SIZE); } else { - iscsi_allocmap_set_allocated(iscsilun, sector_num, *pnum); + iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, + *pnum * BDRV_SECTOR_SIZE); } =20 if (*pnum > nb_sectors) { @@ -789,15 +787,19 @@ static int coroutine_fn iscsi_co_readv(BlockDriverSta= te *bs, /* if cache.direct is off and we have a valid entry in our allocation = map * we can skip checking the block status and directly return zeroes if * the request falls within an unallocated area */ - if (iscsi_allocmap_is_valid(iscsilun, sector_num, nb_sectors) && - !iscsi_allocmap_is_allocated(iscsilun, sector_num, nb_sectors)) { + if (iscsi_allocmap_is_valid(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE) && + !iscsi_allocmap_is_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, + nb_sectors * BDRV_SECTOR_SIZE)) { qemu_iovec_memset(iov, 0, 0x00, iov->size); return 0; } =20 if (nb_sectors >=3D ISCSI_CHECKALLOC_THRES && - !iscsi_allocmap_is_valid(iscsilun, sector_num, nb_sectors) && - !iscsi_allocmap_is_allocated(iscsilun, sector_num, nb_sectors)) { + !iscsi_allocmap_is_valid(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE) && + !iscsi_allocmap_is_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, + nb_sectors * BDRV_SECTOR_SIZE)) { int pnum; BlockDriverState *file; /* check the block status from the beginning of the cluster @@ -1160,8 +1162,7 @@ retry: goto retry; } =20 - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); =20 if (iTask.status =3D=3D SCSI_STATUS_CHECK_CONDITION) { /* the target might fail with a check condition if it @@ -1274,8 +1275,7 @@ retry: } =20 if (iTask.status !=3D SCSI_STATUS_GOOD) { - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); error_report("iSCSI WRITESAME10/16 failed at lba %" PRIu64 ": %s", lba, iTask.err_str); r =3D iTask.err_code; @@ -1283,11 +1283,9 @@ retry: } =20 if (flags & BDRV_REQ_MAY_UNMAP) { - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); } else { - iscsi_allocmap_set_allocated(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_allocated(iscsilun, offset, bytes); } =20 out_unlock: --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017440432718.2681485392224; Fri, 2 Mar 2018 11:04:00 -0800 (PST) Received: from localhost ([::1]:36905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpyJ-00088n-Ix for importer@patchew.org; Fri, 02 Mar 2018 14:03:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpq4-00018Y-7e for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq0-0002gx-Sk for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:28 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38094 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppw-0002bv-OH; Fri, 02 Mar 2018 13:55:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0417481A43B6; Fri, 2 Mar 2018 18:55:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id D87389C079; Fri, 2 Mar 2018 18:55:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:19 +0100 Message-Id: <20180302185448.6314-9-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:20 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 08/37] iscsi: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the iscsi driver accordingly. In this case, it is handy to teach iscsi_co_block_status() to handle a NULL map and file parameter, even though the block layer passes non-NULL values, because we also call the function directly. For now, there are no optimizations done based on the want_zero flag. We can also make the simplification of asserting that the block layer passed in aligned values. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/iscsi.c | 69 ++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index d2b0466775..c228ca21c8 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -653,36 +653,36 @@ out_unlock: =20 =20 =20 -static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnu= m, - BlockDriverState **file) +static int coroutine_fn iscsi_co_block_status(BlockDriverState *bs, + bool want_zero, int64_t offs= et, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) { IscsiLun *iscsilun =3D bs->opaque; struct scsi_get_lba_status *lbas =3D NULL; struct scsi_lba_status_descriptor *lbasd =3D NULL; struct IscsiTask iTask; uint64_t lba; - int64_t ret; + int ret; =20 iscsi_co_init_iscsitask(iscsilun, &iTask); =20 - if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { - ret =3D -EINVAL; - goto out; - } + assert(QEMU_IS_ALIGNED(offset | bytes, iscsilun->block_size)); =20 /* default to all sectors allocated */ - ret =3D BDRV_BLOCK_DATA; - ret |=3D (sector_num << BDRV_SECTOR_BITS) | BDRV_BLOCK_OFFSET_VALID; - *pnum =3D nb_sectors; + ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + if (map) { + *map =3D offset; + } + *pnum =3D bytes; =20 /* LUN does not support logical block provisioning */ if (!iscsilun->lbpme) { goto out; } =20 - lba =3D sector_qemu2lun(sector_num, iscsilun); + lba =3D offset / iscsilun->block_size; =20 qemu_mutex_lock(&iscsilun->mutex); retry: @@ -727,12 +727,12 @@ retry: =20 lbasd =3D &lbas->descriptors[0]; =20 - if (sector_qemu2lun(sector_num, iscsilun) !=3D lbasd->lba) { + if (lba !=3D lbasd->lba) { ret =3D -EIO; goto out_unlock; } =20 - *pnum =3D sector_lun2qemu(lbasd->num_blocks, iscsilun); + *pnum =3D lbasd->num_blocks * iscsilun->block_size; =20 if (lbasd->provisioning =3D=3D SCSI_PROVISIONING_TYPE_DEALLOCATED || lbasd->provisioning =3D=3D SCSI_PROVISIONING_TYPE_ANCHORED) { @@ -743,15 +743,13 @@ retry: } =20 if (ret & BDRV_BLOCK_ZERO) { - iscsi_allocmap_set_unallocated(iscsilun, sector_num * BDRV_SECTOR_= SIZE, - *pnum * BDRV_SECTOR_SIZE); + iscsi_allocmap_set_unallocated(iscsilun, offset, *pnum); } else { - iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, - *pnum * BDRV_SECTOR_SIZE); + iscsi_allocmap_set_allocated(iscsilun, offset, *pnum); } =20 - if (*pnum > nb_sectors) { - *pnum =3D nb_sectors; + if (*pnum > bytes) { + *pnum =3D bytes; } out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -760,7 +758,7 @@ out: if (iTask.task !=3D NULL) { scsi_free_scsi_task(iTask.task); } - if (ret > 0 && ret & BDRV_BLOCK_OFFSET_VALID) { + if (ret > 0 && ret & BDRV_BLOCK_OFFSET_VALID && file) { *file =3D bs; } return ret; @@ -800,25 +798,24 @@ static int coroutine_fn iscsi_co_readv(BlockDriverSta= te *bs, nb_sectors * BDRV_SECTOR_SIZE) && !iscsi_allocmap_is_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, nb_sectors * BDRV_SECTOR_SIZE)) { - int pnum; - BlockDriverState *file; + int64_t pnum; /* check the block status from the beginning of the cluster * containing the start sector */ - int cluster_sectors =3D iscsilun->cluster_size >> BDRV_SECTOR_BITS; - int head; - int64_t ret; - - assert(cluster_sectors); - head =3D sector_num % cluster_sectors; - ret =3D iscsi_co_get_block_status(bs, sector_num - head, - BDRV_REQUEST_MAX_SECTORS, &pnum, - &file); + int64_t head; + int ret; + + assert(iscsilun->cluster_size); + head =3D (sector_num * BDRV_SECTOR_SIZE) % iscsilun->cluster_size; + ret =3D iscsi_co_block_status(bs, true, + sector_num * BDRV_SECTOR_SIZE - head, + BDRV_REQUEST_MAX_BYTES, &pnum, NULL, N= ULL); if (ret < 0) { return ret; } /* if the whole request falls into an unallocated area we can avoid * reading and directly return zeroes instead */ - if (ret & BDRV_BLOCK_ZERO && pnum >=3D nb_sectors + head) { + if (ret & BDRV_BLOCK_ZERO && + pnum >=3D nb_sectors * BDRV_SECTOR_SIZE + head) { qemu_iovec_memset(iov, 0, 0x00, iov->size); return 0; } @@ -2218,7 +2215,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_truncate =3D iscsi_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, =20 - .bdrv_co_get_block_status =3D iscsi_co_get_block_status, + .bdrv_co_block_status =3D iscsi_co_block_status, .bdrv_co_pdiscard =3D iscsi_co_pdiscard, .bdrv_co_pwrite_zeroes =3D iscsi_co_pwrite_zeroes, .bdrv_co_readv =3D iscsi_co_readv, @@ -2253,7 +2250,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_truncate =3D iscsi_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, =20 - .bdrv_co_get_block_status =3D iscsi_co_get_block_status, + .bdrv_co_block_status =3D iscsi_co_block_status, .bdrv_co_pdiscard =3D iscsi_co_pdiscard, .bdrv_co_pwrite_zeroes =3D iscsi_co_pwrite_zeroes, .bdrv_co_readv =3D iscsi_co_readv, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017624201398.86952588607176; Fri, 2 Mar 2018 11:07:04 -0800 (PST) Received: from localhost ([::1]:36927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq1C-0002iS-5J for importer@patchew.org; Fri, 02 Mar 2018 14:06:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpq5-0001AF-Iw for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq4-0002nR-DC for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:29 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60094 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erppy-0002e7-9I; Fri, 02 Mar 2018 13:55:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A4AD4022909; Fri, 2 Mar 2018 18:55:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C353AB583; Fri, 2 Mar 2018 18:55:20 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:20 +0100 Message-Id: <20180302185448.6314-10-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:21 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/37] null: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the null driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/null.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block/null.c b/block/null.c index 214d394fff..806a8631e4 100644 --- a/block/null.c +++ b/block/null.c @@ -223,22 +223,23 @@ static int null_reopen_prepare(BDRVReopenState *reope= n_state, return 0; } =20 -static int64_t coroutine_fn null_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *= pnum, - BlockDriverState **fi= le) +static int coroutine_fn null_co_block_status(BlockDriverState *bs, + bool want_zero, int64_t offse= t, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BDRVNullState *s =3D bs->opaque; - off_t start =3D sector_num * BDRV_SECTOR_SIZE; + int ret =3D BDRV_BLOCK_OFFSET_VALID; =20 - *pnum =3D nb_sectors; + *pnum =3D bytes; + *map =3D offset; *file =3D bs; =20 if (s->read_zeroes) { - return BDRV_BLOCK_OFFSET_VALID | start | BDRV_BLOCK_ZERO; - } else { - return BDRV_BLOCK_OFFSET_VALID | start; + ret |=3D BDRV_BLOCK_ZERO; } + return ret; } =20 static void null_refresh_filename(BlockDriverState *bs, QDict *opts) @@ -270,7 +271,7 @@ static BlockDriver bdrv_null_co =3D { .bdrv_co_flush_to_disk =3D null_co_flush, .bdrv_reopen_prepare =3D null_reopen_prepare, =20 - .bdrv_co_get_block_status =3D null_co_get_block_status, + .bdrv_co_block_status =3D null_co_block_status, =20 .bdrv_refresh_filename =3D null_refresh_filename, }; @@ -290,7 +291,7 @@ static BlockDriver bdrv_null_aio =3D { .bdrv_aio_flush =3D null_aio_flush, .bdrv_reopen_prepare =3D null_reopen_prepare, =20 - .bdrv_co_get_block_status =3D null_co_get_block_status, + .bdrv_co_block_status =3D null_co_block_status, =20 .bdrv_refresh_filename =3D null_refresh_filename, }; --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017791702140.18099124286698; Fri, 2 Mar 2018 11:09:51 -0800 (PST) Received: from localhost ([::1]:36944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq3u-00057k-GC for importer@patchew.org; Fri, 02 Mar 2018 14:09:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpq6-0001C2-ST for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq5-0002q2-Rw for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:30 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47270 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq0-0002ga-Lu; Fri, 02 Mar 2018 13:55:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DB50FA466; Fri, 2 Mar 2018 18:55:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1AA59C079; Fri, 2 Mar 2018 18:55:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:21 +0100 Message-Id: <20180302185448.6314-11-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:24 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 10/37] parallels: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the parallels driver accordingly. Note that the internal function block_status() is still sector-based, because it is still in use by other sector-based functions; but that's okay because request_alignment is 512 as a result of those functions. For now, no optimizations are added based on the mapping hint. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/parallels.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index e1e3d80c88..3e952a9c14 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -261,23 +261,31 @@ static coroutine_fn int parallels_co_flush_to_os(Bloc= kDriverState *bs) } =20 =20 -static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState= *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn parallels_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BDRVParallelsState *s =3D bs->opaque; - int64_t offset; + int count; =20 + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); qemu_co_mutex_lock(&s->lock); - offset =3D block_status(s, sector_num, nb_sectors, pnum); + offset =3D block_status(s, offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &count); qemu_co_mutex_unlock(&s->lock); =20 + *pnum =3D count * BDRV_SECTOR_SIZE; if (offset < 0) { return 0; } =20 + *map =3D offset * BDRV_SECTOR_SIZE; *file =3D bs->file->bs; - return (offset << BDRV_SECTOR_BITS) | - BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 static coroutine_fn int parallels_co_writev(BlockDriverState *bs, @@ -782,7 +790,7 @@ static BlockDriver bdrv_parallels =3D { .bdrv_open =3D parallels_open, .bdrv_close =3D parallels_close, .bdrv_child_perm =3D bdrv_format_default_perms, - .bdrv_co_get_block_status =3D parallels_co_get_block_status, + .bdrv_co_block_status =3D parallels_co_block_status, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_flush_to_os =3D parallels_co_flush_to_os, .bdrv_co_readv =3D parallels_co_readv, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017294142255.8901365039393; Fri, 2 Mar 2018 11:01:34 -0800 (PST) Received: from localhost ([::1]:36894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpvx-00066r-Ct for importer@patchew.org; Fri, 02 Mar 2018 14:01:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpq6-0001C9-UI for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq5-0002px-QG for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:30 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38098 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq2-0002i4-4l; Fri, 02 Mar 2018 13:55:26 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2A4B81A43B0; Fri, 2 Mar 2018 18:55:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8421BAB583; Fri, 2 Mar 2018 18:55:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:22 +0100 Message-Id: <20180302185448.6314-12-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 11/37] qcow: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the qcow driver accordingly. There is no intent to optimize based on the want_zero flag for this format. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/qcow.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 8631155ac8..dead5029c6 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -524,23 +524,28 @@ static int get_cluster_offset(BlockDriverState *bs, return 1; } =20 -static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn qcow_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVQcowState *s =3D bs->opaque; - int index_in_cluster, n, ret; + int index_in_cluster, ret; + int64_t n; uint64_t cluster_offset; =20 qemu_co_mutex_lock(&s->lock); - ret =3D get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0, &cluster_o= ffset); + ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { return ret; } - index_in_cluster =3D sector_num & (s->cluster_sectors - 1); - n =3D s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) - n =3D nb_sectors; + index_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - index_in_cluster; + if (n > bytes) { + n =3D bytes; + } *pnum =3D n; if (!cluster_offset) { return 0; @@ -548,9 +553,9 @@ static int64_t coroutine_fn qcow_co_get_block_status(Bl= ockDriverState *bs, if ((cluster_offset & QCOW_OFLAG_COMPRESSED) || s->crypto) { return BDRV_BLOCK_DATA; } - cluster_offset |=3D (index_in_cluster << BDRV_SECTOR_BITS); + *map =3D cluster_offset | index_in_cluster; *file =3D bs->file->bs; - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | cluster_offset; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 static int decompress_buffer(uint8_t *out_buf, int out_buf_size, @@ -1128,7 +1133,7 @@ static BlockDriver bdrv_qcow =3D { =20 .bdrv_co_readv =3D qcow_co_readv, .bdrv_co_writev =3D qcow_co_writev, - .bdrv_co_get_block_status =3D qcow_co_get_block_status, + .bdrv_co_block_status =3D qcow_co_block_status, =20 .bdrv_make_empty =3D qcow_make_empty, .bdrv_co_pwritev_compressed =3D qcow_co_pwritev_compressed, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017477003718.4849651544893; Fri, 2 Mar 2018 11:04:37 -0800 (PST) Received: from localhost ([::1]:36907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpyu-0000Im-6P for importer@patchew.org; Fri, 02 Mar 2018 14:04:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpq8-0001DU-00 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq6-0002rZ-MD for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:32 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38100 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq3-0002ll-Lj; Fri, 02 Mar 2018 13:55:27 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35D4E81A43B9; Fri, 2 Mar 2018 18:55:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 161F69C079; Fri, 2 Mar 2018 18:55:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:23 +0100 Message-Id: <20180302185448.6314-13-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:27 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/37] qcow2: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the qcow2 driver accordingly. For now, we are ignoring the 'want_zero' hint. However, it should be relatively straightforward to honor the hint as a way to return larger *pnum values when we have consecutive clusters with the same data/zero status but which differ only in having non-consecutive mappings. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/qcow2.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 57a517e2bd..288b5299d8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1670,32 +1670,34 @@ static void qcow2_join_options(QDict *options, QDic= t *old_options) } } =20 -static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t coun= t, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVQcow2State *s =3D bs->opaque; uint64_t cluster_offset; int index_in_cluster, ret; unsigned int bytes; - int64_t status =3D 0; + int status =3D 0; =20 - bytes =3D MIN(INT_MAX, nb_sectors * BDRV_SECTOR_SIZE); + bytes =3D MIN(INT_MAX, count); qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_get_cluster_offset(bs, sector_num << BDRV_SECTOR_BITS, &= bytes, - &cluster_offset); + ret =3D qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { return ret; } =20 - *pnum =3D bytes >> BDRV_SECTOR_BITS; + *pnum =3D bytes; =20 if (cluster_offset !=3D 0 && ret !=3D QCOW2_CLUSTER_COMPRESSED && !s->crypto) { - index_in_cluster =3D sector_num & (s->cluster_sectors - 1); - cluster_offset |=3D (index_in_cluster << BDRV_SECTOR_BITS); + index_in_cluster =3D offset & (s->cluster_size - 1); + *map =3D cluster_offset | index_in_cluster; *file =3D bs->file->bs; - status |=3D BDRV_BLOCK_OFFSET_VALID | cluster_offset; + status |=3D BDRV_BLOCK_OFFSET_VALID; } if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || ret =3D=3D QCOW2_CLUSTER_ZE= RO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; @@ -4352,7 +4354,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D qcow2_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_co_get_block_status =3D qcow2_co_get_block_status, + .bdrv_co_block_status =3D qcow2_co_block_status, =20 .bdrv_co_preadv =3D qcow2_co_preadv, .bdrv_co_pwritev =3D qcow2_co_pwritev, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017973039745.865066011664; Fri, 2 Mar 2018 11:12:53 -0800 (PST) Received: from localhost ([::1]:36967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq6u-0008Ds-4o for importer@patchew.org; Fri, 02 Mar 2018 14:12:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqA-0001Fz-3p for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq8-0002vC-Iu for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60096 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq5-0002oP-B1; Fri, 02 Mar 2018 13:55:29 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBED5402291E; Fri, 2 Mar 2018 18:55:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C9D7AB583; Fri, 2 Mar 2018 18:55:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:24 +0100 Message-Id: <20180302185448.6314-14-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:28 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 13/37] qed: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the qed driver accordingly, taking the opportunity to inline qed_is_allocated_cb() into its lone caller (the callback used to be important, until we switched qed to coroutines). There is no intent to optimize based on the want_zero flag for this format. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/qed.c | 76 +++++++++++++++++++--------------------------------------= ---- 1 file changed, 24 insertions(+), 52 deletions(-) diff --git a/block/qed.c b/block/qed.c index c6ff3ab015..a595220926 100644 --- a/block/qed.c +++ b/block/qed.c @@ -688,74 +688,46 @@ finish: return ret; } =20 -typedef struct { - BlockDriverState *bs; - Coroutine *co; - uint64_t pos; - int64_t status; - int *pnum; - BlockDriverState **file; -} QEDIsAllocatedCB; - -/* Called with table_lock held. */ -static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, si= ze_t len) +static int coroutine_fn bdrv_qed_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t pos, int64_t byte= s, + int64_t *pnum, int64_t *m= ap, + BlockDriverState **file) { - QEDIsAllocatedCB *cb =3D opaque; - BDRVQEDState *s =3D cb->bs->opaque; - *cb->pnum =3D len / BDRV_SECTOR_SIZE; + BDRVQEDState *s =3D bs->opaque; + size_t len =3D MIN(bytes, SIZE_MAX); + int status; + QEDRequest request =3D { .l2_table =3D NULL }; + uint64_t offset; + int ret; + + qemu_co_mutex_lock(&s->table_lock); + ret =3D qed_find_cluster(s, &request, pos, &len, &offset); + + *pnum =3D len; switch (ret) { case QED_CLUSTER_FOUND: - offset |=3D qed_offset_into_cluster(s, cb->pos); - cb->status =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; - *cb->file =3D cb->bs->file->bs; + *map =3D offset | qed_offset_into_cluster(s, pos); + status =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + *file =3D bs->file->bs; break; case QED_CLUSTER_ZERO: - cb->status =3D BDRV_BLOCK_ZERO; + status =3D BDRV_BLOCK_ZERO; break; case QED_CLUSTER_L2: case QED_CLUSTER_L1: - cb->status =3D 0; + status =3D 0; break; default: assert(ret < 0); - cb->status =3D ret; + status =3D ret; break; } =20 - if (cb->co) { - aio_co_wake(cb->co); - } -} - -static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState = *bs, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) -{ - BDRVQEDState *s =3D bs->opaque; - size_t len =3D (size_t)nb_sectors * BDRV_SECTOR_SIZE; - QEDIsAllocatedCB cb =3D { - .bs =3D bs, - .pos =3D (uint64_t)sector_num * BDRV_SECTOR_SIZE, - .status =3D BDRV_BLOCK_OFFSET_MASK, - .pnum =3D pnum, - .file =3D file, - }; - QEDRequest request =3D { .l2_table =3D NULL }; - uint64_t offset; - int ret; - - qemu_co_mutex_lock(&s->table_lock); - ret =3D qed_find_cluster(s, &request, cb.pos, &len, &offset); - qed_is_allocated_cb(&cb, ret, offset, len); - - /* The callback was invoked immediately */ - assert(cb.status !=3D BDRV_BLOCK_OFFSET_MASK); - qed_unref_l2_cache_entry(request.l2_table); qemu_co_mutex_unlock(&s->table_lock); =20 - return cb.status; + return status; } =20 static BDRVQEDState *acb_to_s(QEDAIOCB *acb) @@ -1594,7 +1566,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D bdrv_qed_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_co_get_block_status =3D bdrv_qed_co_get_block_status, + .bdrv_co_block_status =3D bdrv_qed_co_block_status, .bdrv_co_readv =3D bdrv_qed_co_readv, .bdrv_co_writev =3D bdrv_qed_co_writev, .bdrv_co_pwrite_zeroes =3D bdrv_qed_co_pwrite_zeroes, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017644249776.3973576827103; Fri, 2 Mar 2018 11:07:24 -0800 (PST) Received: from localhost ([::1]:36928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq1b-00033Q-E2 for importer@patchew.org; Fri, 02 Mar 2018 14:07:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqA-0001GV-Ir for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpq9-0002wm-KG for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:34 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48022 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq6-0002rA-Ps; Fri, 02 Mar 2018 13:55:30 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E9C88D76A; Fri, 2 Mar 2018 18:55:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F6059C079; Fri, 2 Mar 2018 18:55:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:25 +0100 Message-Id: <20180302185448.6314-15-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:55:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:55:30 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 14/37] raw: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the raw driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/raw-format.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/block/raw-format.c b/block/raw-format.c index ab552c0954..830243a8e4 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -250,17 +250,17 @@ fail: return ret; } =20 -static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum, +static int coroutine_fn raw_co_block_status(BlockDriverState *bs, + bool want_zero, int64_t offset, + int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file) { BDRVRawState *s =3D bs->opaque; - *pnum =3D nb_sectors; + *pnum =3D bytes; *file =3D bs->file->bs; - sector_num +=3D s->offset / BDRV_SECTOR_SIZE; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + *map =3D offset + s->offset; + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, @@ -496,7 +496,7 @@ BlockDriver bdrv_raw =3D { .bdrv_co_pwritev =3D &raw_co_pwritev, .bdrv_co_pwrite_zeroes =3D &raw_co_pwrite_zeroes, .bdrv_co_pdiscard =3D &raw_co_pdiscard, - .bdrv_co_get_block_status =3D &raw_co_get_block_status, + .bdrv_co_block_status =3D &raw_co_block_status, .bdrv_truncate =3D &raw_truncate, .bdrv_getlength =3D &raw_getlength, .has_variable_length =3D true, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017648895273.146183298187; Fri, 2 Mar 2018 11:07:28 -0800 (PST) Received: from localhost ([::1]:36929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq1f-00036Y-Gt for importer@patchew.org; Fri, 02 Mar 2018 14:07:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqE-0001L4-JN for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqD-0002z9-GN for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:38 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60098 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq8-0002u8-Eh; Fri, 02 Mar 2018 13:55:32 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6E99402291E; Fri, 2 Mar 2018 18:55:31 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id B69DB9C079; Fri, 2 Mar 2018 18:55:30 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:26 +0100 Message-Id: <20180302185448.6314-16-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:31 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 15/37] sheepdog: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the sheepdog driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/sheepdog.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index ac02b10fe0..3c3becf94d 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -3004,19 +3004,19 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverS= tate *bs, int64_t offset, return acb.ret; } =20 -static coroutine_fn int64_t -sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_se= ctors, - int *pnum, BlockDriverState **file) +static coroutine_fn int +sd_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, + int64_t bytes, int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVSheepdogState *s =3D bs->opaque; SheepdogInode *inode =3D &s->inode; uint32_t object_size =3D (UINT32_C(1) << inode->block_size_shift); - uint64_t offset =3D sector_num * BDRV_SECTOR_SIZE; unsigned long start =3D offset / object_size, - end =3D DIV_ROUND_UP((sector_num + nb_sectors) * - BDRV_SECTOR_SIZE, object_size); + end =3D DIV_ROUND_UP(offset + bytes, object_size); unsigned long idx; - int64_t ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; + *map =3D offset; + int ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; =20 for (idx =3D start; idx < end; idx++) { if (inode->data_vdi_id[idx] =3D=3D 0) { @@ -3033,9 +3033,9 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t = sector_num, int nb_sectors, } } =20 - *pnum =3D (idx - start) * object_size / BDRV_SECTOR_SIZE; - if (*pnum > nb_sectors) { - *pnum =3D nb_sectors; + *pnum =3D (idx - start) * object_size; + if (*pnum > bytes) { + *pnum =3D bytes; } if (ret > 0 && ret & BDRV_BLOCK_OFFSET_VALID) { *file =3D bs; @@ -3113,7 +3113,7 @@ static BlockDriver bdrv_sheepdog =3D { .bdrv_co_writev =3D sd_co_writev, .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, .bdrv_co_pdiscard =3D sd_co_pdiscard, - .bdrv_co_get_block_status =3D sd_co_get_block_status, + .bdrv_co_block_status =3D sd_co_block_status, =20 .bdrv_snapshot_create =3D sd_snapshot_create, .bdrv_snapshot_goto =3D sd_snapshot_goto, @@ -3149,7 +3149,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .bdrv_co_writev =3D sd_co_writev, .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, .bdrv_co_pdiscard =3D sd_co_pdiscard, - .bdrv_co_get_block_status =3D sd_co_get_block_status, + .bdrv_co_block_status =3D sd_co_block_status, =20 .bdrv_snapshot_create =3D sd_snapshot_create, .bdrv_snapshot_goto =3D sd_snapshot_goto, @@ -3185,7 +3185,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .bdrv_co_writev =3D sd_co_writev, .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, .bdrv_co_pdiscard =3D sd_co_pdiscard, - .bdrv_co_get_block_status =3D sd_co_get_block_status, + .bdrv_co_block_status =3D sd_co_block_status, =20 .bdrv_snapshot_create =3D sd_snapshot_create, .bdrv_snapshot_goto =3D sd_snapshot_goto, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018145101429.1415855232141; Fri, 2 Mar 2018 11:15:45 -0800 (PST) Received: from localhost ([::1]:36983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq9U-0002Xp-49 for importer@patchew.org; Fri, 02 Mar 2018 14:15:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqF-0001M1-CA for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqE-0002zi-JJ for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:39 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56448 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpq9-0002ws-TT; Fri, 02 Mar 2018 13:55:33 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 697454040852; Fri, 2 Mar 2018 18:55:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A60EAB583; Fri, 2 Mar 2018 18:55:32 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:27 +0100 Message-Id: <20180302185448.6314-17-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:33 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 16/37] vdi: Avoid bitrot of debugging code 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Eric Blake Rework the debug define so that we always get -Wformat checking, even when debugging is disabled. Signed-off-by: Eric Blake Reviewed-by: Stefan Weil Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/vdi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index fc1c614cb1..32b1763cde 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -87,12 +87,18 @@ #define DEFAULT_CLUSTER_SIZE (1 * MiB) =20 #if defined(CONFIG_VDI_DEBUG) -#define logout(fmt, ...) \ - fprintf(stderr, "vdi\t%-24s" fmt, __func__, ##__VA_ARGS__) +#define VDI_DEBUG 1 #else -#define logout(fmt, ...) ((void)0) +#define VDI_DEBUG 0 #endif =20 +#define logout(fmt, ...) \ + do { \ + if (VDI_DEBUG) { \ + fprintf(stderr, "vdi\t%-24s" fmt, __func__, ##__VA_ARGS__); \ + } \ + } while (0) + /* Image signature. */ #define VDI_SIGNATURE 0xbeda107f =20 --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017658738401.5411523416061; Fri, 2 Mar 2018 11:07:38 -0800 (PST) Received: from localhost ([::1]:36930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq1p-0003Fe-RE for importer@patchew.org; Fri, 02 Mar 2018 14:07:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqF-0001MI-FY for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqE-0002zd-G5 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:39 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56450 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqB-0002ya-Eq; Fri, 02 Mar 2018 13:55:35 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDE1C4040852; Fri, 2 Mar 2018 18:55:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF37D9C079; Fri, 2 Mar 2018 18:55:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:28 +0100 Message-Id: <20180302185448.6314-18-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/37] vdi: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the vdi driver accordingly. Note that the TODO is already covered (the block layer guarantees bounds of its requests), and that we can remove the now-unused s->block_sectors. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/vdi.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 32b1763cde..0780c82d82 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -172,8 +172,6 @@ typedef struct { uint32_t *bmap; /* Size of block (bytes). */ uint32_t block_size; - /* Size of block (sectors). */ - uint32_t block_sectors; /* First sector of block map. */ uint32_t bmap_sector; /* VDI header (converted to host endianness). */ @@ -463,7 +461,6 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, bs->total_sectors =3D header.disk_size / SECTOR_SIZE; =20 s->block_size =3D header.block_size; - s->block_sectors =3D header.block_size / SECTOR_SIZE; s->bmap_sector =3D header.offset_bmap / SECTOR_SIZE; s->header =3D header; =20 @@ -509,33 +506,29 @@ static int vdi_reopen_prepare(BDRVReopenState *state, return 0; } =20 -static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn vdi_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { - /* TODO: Check for too large sector_num (in bdrv_is_allocated or here)= . */ BDRVVdiState *s =3D (BDRVVdiState *)bs->opaque; - size_t bmap_index =3D sector_num / s->block_sectors; - size_t sector_in_block =3D sector_num % s->block_sectors; - int n_sectors =3D s->block_sectors - sector_in_block; + size_t bmap_index =3D offset / s->block_size; + size_t index_in_block =3D offset % s->block_size; uint32_t bmap_entry =3D le32_to_cpu(s->bmap[bmap_index]); - uint64_t offset; int result; =20 - logout("%p, %" PRId64 ", %d, %p\n", bs, sector_num, nb_sectors, pnum); - if (n_sectors > nb_sectors) { - n_sectors =3D nb_sectors; - } - *pnum =3D n_sectors; + logout("%p, %" PRId64 ", %" PRId64 ", %p\n", bs, offset, bytes, pnum); + *pnum =3D MIN(s->block_size - index_in_block, bytes); result =3D VDI_IS_ALLOCATED(bmap_entry); if (!result) { return 0; } =20 - offset =3D s->header.offset_data + - (uint64_t)bmap_entry * s->block_size + - sector_in_block * SECTOR_SIZE; + *map =3D s->header.offset_data + (uint64_t)bmap_entry * s->block_size + + index_in_block; *file =3D bs->file->bs; - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 static int coroutine_fn @@ -903,7 +896,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D vdi_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_co_get_block_status =3D vdi_co_get_block_status, + .bdrv_co_block_status =3D vdi_co_block_status, .bdrv_make_empty =3D vdi_make_empty, =20 .bdrv_co_preadv =3D vdi_co_preadv, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017896371248.95877084294875; Fri, 2 Mar 2018 11:11:36 -0800 (PST) Received: from localhost ([::1]:36957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq5f-000763-Iu for importer@patchew.org; Fri, 02 Mar 2018 14:11:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqH-0001Ob-Ir for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqG-00030e-Mv for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:41 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48024 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqD-0002zH-Vm; Fri, 02 Mar 2018 13:55:38 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DAB88A3DD; Fri, 2 Mar 2018 18:55:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 603C6AB583; Fri, 2 Mar 2018 18:55:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:29 +0100 Message-Id: <20180302185448.6314-19-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:55:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:55:37 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 18/37] vmdk: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the vmdk driver accordingly. Drop the now-unused vmdk_find_index_in_cluster(). Also, fix a pre-existing bug: if find_extent() fails (unlikely, since the block layer did a bounds check), then we must return a failure, rather than 0. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/vmdk.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index ef15ddbfd3..75f84213e6 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1304,33 +1304,27 @@ static inline uint64_t vmdk_find_offset_in_cluster(= VmdkExtent *extent, return extent_relative_offset % cluster_size; } =20 -static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent, - int64_t sector_num) -{ - uint64_t offset; - offset =3D vmdk_find_offset_in_cluster(extent, sector_num * BDRV_SECTO= R_SIZE); - return offset / BDRV_SECTOR_SIZE; -} - -static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn vmdk_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVVmdkState *s =3D bs->opaque; int64_t index_in_cluster, n, ret; - uint64_t offset; + uint64_t cluster_offset; VmdkExtent *extent; =20 - extent =3D find_extent(s, sector_num, NULL); + extent =3D find_extent(s, offset >> BDRV_SECTOR_BITS, NULL); if (!extent) { - return 0; + return -EIO; } qemu_co_mutex_lock(&s->lock); - ret =3D get_cluster_offset(bs, extent, NULL, - sector_num * 512, false, &offset, + ret =3D get_cluster_offset(bs, extent, NULL, offset, false, &cluster_o= ffset, 0, 0); qemu_co_mutex_unlock(&s->lock); =20 - index_in_cluster =3D vmdk_find_index_in_cluster(extent, sector_num); + index_in_cluster =3D vmdk_find_offset_in_cluster(extent, offset); switch (ret) { case VMDK_ERROR: ret =3D -EIO; @@ -1345,18 +1339,14 @@ static int64_t coroutine_fn vmdk_co_get_block_statu= s(BlockDriverState *bs, ret =3D BDRV_BLOCK_DATA; if (!extent->compressed) { ret |=3D BDRV_BLOCK_OFFSET_VALID; - ret |=3D (offset + (index_in_cluster << BDRV_SECTOR_BITS)) - & BDRV_BLOCK_OFFSET_MASK; + *map =3D cluster_offset + index_in_cluster; } *file =3D extent->file->bs; break; } =20 - n =3D extent->cluster_sectors - index_in_cluster; - if (n > nb_sectors) { - n =3D nb_sectors; - } - *pnum =3D n; + n =3D extent->cluster_sectors * BDRV_SECTOR_SIZE - index_in_cluster; + *pnum =3D MIN(n, bytes); return ret; } =20 @@ -2410,7 +2400,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_close =3D vmdk_close, .bdrv_create =3D vmdk_create, .bdrv_co_flush_to_disk =3D vmdk_co_flush, - .bdrv_co_get_block_status =3D vmdk_co_get_block_status, + .bdrv_co_block_status =3D vmdk_co_block_status, .bdrv_get_allocated_file_size =3D vmdk_get_allocated_file_size, .bdrv_has_zero_init =3D vmdk_has_zero_init, .bdrv_get_specific_info =3D vmdk_get_specific_info, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018057256983.5414731024678; Fri, 2 Mar 2018 11:14:17 -0800 (PST) Received: from localhost ([::1]:36976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq8G-0001LO-A4 for importer@patchew.org; Fri, 02 Mar 2018 14:14:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqJ-0001QG-3n for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqI-000314-2s for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:43 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60112 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqF-000302-Gw; Fri, 02 Mar 2018 13:55:39 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E1BB4022909; Fri, 2 Mar 2018 18:55:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4F7B9C079; Fri, 2 Mar 2018 18:55:37 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:30 +0100 Message-Id: <20180302185448.6314-20-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:39 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 19/37] vpc: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the vpc driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/vpc.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index cfa5144e86..fba4492fd7 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -706,53 +706,54 @@ fail: return ret; } =20 -static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn vpc_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVVPCState *s =3D bs->opaque; VHDFooter *footer =3D (VHDFooter*) s->footer_buf; - int64_t start, offset; + int64_t image_offset; bool allocated; - int64_t ret; - int n; + int ret; + int64_t n; =20 if (be32_to_cpu(footer->type) =3D=3D VHD_FIXED) { - *pnum =3D nb_sectors; + *pnum =3D bytes; + *map =3D offset; *file =3D bs->file->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 qemu_co_mutex_lock(&s->lock); =20 - offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false,= NULL); - start =3D offset; - allocated =3D (offset !=3D -1); + image_offset =3D get_image_offset(bs, offset, false, NULL); + allocated =3D (image_offset !=3D -1); *pnum =3D 0; ret =3D 0; =20 do { /* All sectors in a block are contiguous (without using the bitmap= ) */ - n =3D ROUND_UP(sector_num + 1, s->block_size / BDRV_SECTOR_SIZE) - - sector_num; - n =3D MIN(n, nb_sectors); + n =3D ROUND_UP(offset + 1, s->block_size) - offset; + n =3D MIN(n, bytes); =20 *pnum +=3D n; - sector_num +=3D n; - nb_sectors -=3D n; + offset +=3D n; + bytes -=3D n; /* *pnum can't be greater than one block for allocated * sectors since there is always a bitmap in between. */ if (allocated) { *file =3D bs->file->bs; - ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; + *map =3D image_offset; + ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; break; } - if (nb_sectors =3D=3D 0) { + if (bytes =3D=3D 0) { break; } - offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, fa= lse, - NULL); - } while (offset =3D=3D -1); + image_offset =3D get_image_offset(bs, offset, false, NULL); + } while (image_offset =3D=3D -1); =20 qemu_co_mutex_unlock(&s->lock); return ret; @@ -1098,7 +1099,7 @@ static BlockDriver bdrv_vpc =3D { =20 .bdrv_co_preadv =3D vpc_co_preadv, .bdrv_co_pwritev =3D vpc_co_pwritev, - .bdrv_co_get_block_status =3D vpc_co_get_block_status, + .bdrv_co_block_status =3D vpc_co_block_status, =20 .bdrv_get_info =3D vpc_get_info, =20 --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018242944839.3048212894721; Fri, 2 Mar 2018 11:17:22 -0800 (PST) Received: from localhost ([::1]:36999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqBG-00040p-6P for importer@patchew.org; Fri, 02 Mar 2018 14:17:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqN-0001U4-Gv for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqM-00033I-NL for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:47 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56452 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqI-00030x-2T; Fri, 02 Mar 2018 13:55:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93EC0404084B; Fri, 2 Mar 2018 18:55:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7603FAB583; Fri, 2 Mar 2018 18:55:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:31 +0100 Message-Id: <20180302185448.6314-21-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:55:41 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 20/37] vvfat: Switch to .bdrv_co_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, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Update the vvfat driver accordingly. Note that we can rely on the block driver having already clamped limits to our block size, and simplify accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/vvfat.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 7e06ebacf6..4a17a49e12 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3088,15 +3088,13 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t off= set, uint64_t bytes, return ret; } =20 -static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *n, BlockDriverState **fil= e) +static int coroutine_fn vvfat_co_block_status(BlockDriverState *bs, + bool want_zero, int64_t offs= et, + int64_t bytes, int64_t *n, + int64_t *map, + BlockDriverState **file) { - *n =3D bs->total_sectors - sector_num; - if (*n > nb_sectors) { - *n =3D nb_sectors; - } else if (*n < 0) { - return 0; - } + *n =3D bytes; return BDRV_BLOCK_DATA; } =20 @@ -3257,7 +3255,7 @@ static BlockDriver bdrv_vvfat =3D { =20 .bdrv_co_preadv =3D vvfat_co_preadv, .bdrv_co_pwritev =3D vvfat_co_pwritev, - .bdrv_co_get_block_status =3D vvfat_co_get_block_status, + .bdrv_co_block_status =3D vvfat_co_block_status, }; =20 static void bdrv_vvfat_init(void) --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018329068536.8144630397904; Fri, 2 Mar 2018 11:18:49 -0800 (PST) Received: from localhost ([::1]:37006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqCc-0005BD-9V for importer@patchew.org; Fri, 02 Mar 2018 14:18:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqP-0001W9-Ax for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqO-00033m-82 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:49 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60114 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqJ-00031g-Lw; Fri, 02 Mar 2018 13:55:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 242224022909; Fri, 2 Mar 2018 18:55:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D449C079; Fri, 2 Mar 2018 18:55:41 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:32 +0100 Message-Id: <20180302185448.6314-22-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:43 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 21/37] block: Drop unused .bdrv_co_get_block_status() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Now that all drivers have been updated to provide the byte-based .bdrv_co_block_status(), we can delete the sector-based interface. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block_int.h | 3 --- block/io.c | 50 ++++++++++---------------------------------= ---- 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index bf2598856c..5ae7738cf8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -215,9 +215,6 @@ struct BlockDriver { * as well as non-NULL pnum, map, and file; in turn, the driver * must return an error or set pnum to an aligned non-zero value. */ - int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, - BlockDriverState **file); 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); diff --git a/block/io.c b/block/io.c index 5bae79f282..4c3dba0973 100644 --- a/block/io.c +++ b/block/io.c @@ -1963,7 +1963,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, =20 /* Must be non-NULL or bdrv_getlength() would have failed */ assert(bs->drv); - if (!bs->drv->bdrv_co_get_block_status && !bs->drv->bdrv_co_block_stat= us) { + if (!bs->drv->bdrv_co_block_status) { *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; if (offset + bytes =3D=3D total_size) { @@ -1981,53 +1981,23 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, =20 /* Round out to request_alignment boundaries */ align =3D bs->bl.request_alignment; - if (bs->drv->bdrv_co_get_block_status && align < BDRV_SECTOR_SIZE) { - align =3D BDRV_SECTOR_SIZE; - } aligned_offset =3D QEMU_ALIGN_DOWN(offset, align); aligned_bytes =3D ROUND_UP(offset + bytes, align) - aligned_offset; =20 - if (bs->drv->bdrv_co_get_block_status) { - 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; - } else { - ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offse= t, - aligned_bytes, pnum, &local_ma= p, - &local_file); - if (ret < 0) { - *pnum =3D 0; - goto out; - } - assert(*pnum); /* The block driver must make progress */ + ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offset, + aligned_bytes, pnum, &local_map, + &local_file); + if (ret < 0) { + *pnum =3D 0; + goto out; } =20 /* - * The driver's result must be a multiple of request_alignment. + * The driver's result must be a non-zero multiple of request_alignmen= t. * Clamp pnum and adjust map to original request. */ - assert(QEMU_IS_ALIGNED(*pnum, align) && align > offset - aligned_offse= t); + assert(*pnum && QEMU_IS_ALIGNED(*pnum, align) && + align > offset - aligned_offset); *pnum -=3D offset - aligned_offset; if (*pnum > bytes) { *pnum =3D bytes; --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520017824030826.81304101298; Fri, 2 Mar 2018 11:10:24 -0800 (PST) Received: from localhost ([::1]:36946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq4V-0005tN-7O for importer@patchew.org; Fri, 02 Mar 2018 14:10:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqP-0001WE-DL for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqO-00033v-L1 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:49 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47290 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqM-00032u-5H; Fri, 02 Mar 2018 13:55:46 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8DC37B4AD; Fri, 2 Mar 2018 18:55:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A55C9C079; Fri, 2 Mar 2018 18:55:43 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:33 +0100 Message-Id: <20180302185448.6314-23-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:55:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 22/37] block: fix write with zero flag set and iovector provided 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, qemu-devel@nongnu.org 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" From: Anton Nefedov The normal bdrv_co_pwritev() use is either - BDRV_REQ_ZERO_WRITE clear and iovector provided - BDRV_REQ_ZERO_WRITE set and iovector =3D=3D NULL while - the flag clear and iovector =3D=3D NULL is an assertion failure in bdrv_co_do_zero_pwritev() - the flag set and iovector provided is in fact allowed (the flag prevails and zeroes are written) However the alignment logic does not support the latter case so the padding areas get overwritten with zeroes. Currently, general functions like bdrv_rw_co() do provide iovector regardless of flags. So, keep it supported and use bdrv_co_do_zero_pwritev() alignment for it which also makes the code a bit more obvious anyway. Signed-off-by: Anton Nefedov Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index 4c3dba0973..4d3d1f640a 100644 --- a/block/io.c +++ b/block/io.c @@ -1701,7 +1701,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, */ tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_WRITE); =20 - if (!qiov) { + if (flags & BDRV_REQ_ZERO_WRITE) { ret =3D bdrv_co_do_zero_pwritev(child, offset, bytes, flags, &req); goto out; } --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152001802632391.99499027608181; Fri, 2 Mar 2018 11:13:46 -0800 (PST) Received: from localhost ([::1]:36971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq7l-0000c7-Fl for importer@patchew.org; Fri, 02 Mar 2018 14:13:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqW-0001ec-Gt for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqV-00036U-IX for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:56 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60122 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqQ-00034c-Mz; Fri, 02 Mar 2018 13:55:50 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BB45402291E; Fri, 2 Mar 2018 18:55:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C66BAB583; Fri, 2 Mar 2018 18:55:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:34 +0100 Message-Id: <20180302185448.6314-24-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:50 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 23/37] iotest 033: add misaligned write-zeroes test via truncate 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, qemu-devel@nongnu.org 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" From: Anton Nefedov This new test case only makes sense for qcow2 while iotest 033 is generic; however it matches the test purpose perfectly and also 033 contains those do_test() tricks to pass the alignment, which won't look nice being duplicated in other tests or moved to the common code. Signed-off-by: Anton Nefedov Signed-off-by: Kevin Wolf --- tests/qemu-iotests/033 | 29 +++++++++++++++++++++++++++++ tests/qemu-iotests/033.out | 13 +++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 index 2cdfd1397a..a1d8357331 100755 --- a/tests/qemu-iotests/033 +++ b/tests/qemu-iotests/033 @@ -64,6 +64,9 @@ do_test() } | $QEMU_IO $IO_EXTRA_ARGS } =20 +echo +echo "=3D=3D=3D Test aligned and misaligned write zeroes operations =3D=3D= =3D" + for write_zero_cmd in "write -z" "aio_write -z"; do for align in 512 4k; do echo @@ -102,7 +105,33 @@ for align in 512 4k; do done done =20 + +# Trigger truncate that would shrink qcow2 L1 table, which is done by +# clearing one entry (8 bytes) with bdrv_co_pwrite_zeroes() + +echo +echo "=3D=3D=3D Test misaligned write zeroes via truncate =3D=3D=3D" +echo + +# any size will do, but the smaller the size the smaller the required image +CLUSTER_SIZE=3D$((4 * 1024)) +L2_COVERAGE=3D$(($CLUSTER_SIZE * $CLUSTER_SIZE / 8)) +_make_test_img $(($L2_COVERAGE * 2)) + +do_test 512 "write -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io +# next L2 table +do_test 512 "write -P 1 $L2_COVERAGE 0x200" "$TEST_IMG" | _filter_qemu_io + +# only interested in qcow2 here; also other formats might respond with +# "not supported" error message +if [ $IMGFMT =3D "qcow2" ]; then + do_test 512 "truncate $L2_COVERAGE" "$TEST_IMG" | _filter_qemu_io +fi + +do_test 512 "read -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io + # success, all done +echo echo "*** done" rm -f $seq.full status=3D0 diff --git a/tests/qemu-iotests/033.out b/tests/qemu-iotests/033.out index 95929eff70..9683f6b290 100644 --- a/tests/qemu-iotests/033.out +++ b/tests/qemu-iotests/033.out @@ -1,6 +1,8 @@ QA output created by 033 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 =20 +=3D=3D=3D Test aligned and misaligned write zeroes operations =3D=3D=3D + =3D=3D preparing image =3D=3D wrote 1024/1024 bytes at offset 512 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -164,4 +166,15 @@ read 512/512 bytes at offset 512 read 3072/3072 bytes at offset 1024 3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 + +=3D=3D=3D Test misaligned write zeroes via truncate =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D4194304 +wrote 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 512/512 bytes at offset 2097152 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + *** done --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018195776982.5393207330127; Fri, 2 Mar 2018 11:16:35 -0800 (PST) Received: from localhost ([::1]:36992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqAU-0003Sb-P8 for importer@patchew.org; Fri, 02 Mar 2018 14:16:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqY-0001gP-1N for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqW-00037M-SJ for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38104 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqS-000354-8w; Fri, 02 Mar 2018 13:55:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C111D813F6FF; Fri, 2 Mar 2018 18:55:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2B739C079; Fri, 2 Mar 2018 18:55:50 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:35 +0100 Message-Id: <20180302185448.6314-25-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 24/37] specs/qcow2: Fix documentation of the compressed cluster descriptor 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, qemu-devel@nongnu.org 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" From: Alberto Garcia This patch fixes several mistakes in the documentation of the compressed cluster descriptor: 1) the documentation claims that the cluster descriptor contains the number of sectors used to store the compressed data, but what it actually contains is the number of sectors *minus one* or, in other words, the number of additional sectors after the first one. 2) the width of the fields is incorrectly specified. The number of bits used by each field is x =3D 62 - (cluster_bits - 8) for the offset field y =3D (cluster_bits - 8) for the size field So the offset field's location is [0, x-1], not [0, x] as stated. 3) the size field does not contain the size of the compressed data, but rather the number of sectors where that data is stored. The compressed data starts at the exact point specified in the offset field and ends when there's enough data to produce a cluster of decompressed data. Both points can be in the middle of a sector, allowing several compressed clusters to be stored next to one another, sharing sectors if necessary. Cc: qemu-stable@nongnu.org Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- docs/interop/qcow2.txt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index d7fdb1fee3..feb711fb6a 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -426,10 +426,20 @@ Standard Cluster Descriptor: =20 Compressed Clusters Descriptor (x =3D 62 - (cluster_bits - 8)): =20 - Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + Bit 0 - x-1: Host cluster offset. This is usually _not_ aligned to a + cluster or sector boundary! =20 - x+1 - 61: Compressed size of the images in sectors of 512 bytes + x - 61: Number of additional 512-byte sectors used for the + compressed data, beyond the sector containing the offs= et + in the previous field. Some of these sectors may reside + in the next contiguous host cluster. + + Note that the compressed data does not necessarily occ= upy + all of the bytes in the final sector; rather, decompre= ssion + stops when it has produced a cluster of data. + + Another compressed cluster may map to the tail of the = final + sector used by this compressed cluster. =20 If a cluster is unallocated, read requests shall read the data from the ba= cking file (except if bit 0 in the Standard Cluster Descriptor is set). If there= is --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018495087942.5604568211434; Fri, 2 Mar 2018 11:21:35 -0800 (PST) Received: from localhost ([::1]:37031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqFK-0007iI-3x for importer@patchew.org; Fri, 02 Mar 2018 14:21:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqY-0001gv-Hf for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqX-00037R-0Q for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60124 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqT-00035Y-PY; Fri, 02 Mar 2018 13:55:53 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 515664022909; Fri, 2 Mar 2018 18:55:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34265AB583; Fri, 2 Mar 2018 18:55:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:36 +0100 Message-Id: <20180302185448.6314-26-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:55:53 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 25/37] docs: document how to use the l2-cache-entry-size parameter 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, qemu-devel@nongnu.org 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" From: Alberto Garcia This patch updates docs/qcow2-cache.txt explaining how to use the new l2-cache-entry-size parameter. Here's a more detailed technical description of this feature: https://lists.gnu.org/archive/html/qemu-block/2017-09/msg00635.html And here are some performance numbers: https://lists.gnu.org/archive/html/qemu-block/2017-12/msg00507.html Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- docs/qcow2-cache.txt | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index b0571de4b8..170191a242 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -1,6 +1,6 @@ qcow2 L2/refcount cache configuration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Copyright (C) 2015 Igalia, S.L. +Copyright (C) 2015, 2018 Igalia, S.L. Author: Alberto Garcia =20 This work is licensed under the terms of the GNU GPL, version 2 or @@ -118,8 +118,8 @@ There are three options available, and all of them take= bytes: =20 There are two things that need to be taken into account: =20 - - Both caches must have a size that is a multiple of the cluster - size. + - Both caches must have a size that is a multiple of the cluster size + (or the cache entry size: see "Using smaller cache sizes" below). =20 - If you only set one of the options above, QEMU will automatically adjust the others so that the L2 cache is 4 times bigger than the @@ -143,6 +143,46 @@ much less often than the L2 cache, so it's perfectly r= easonable to keep it small. =20 =20 +Using smaller cache entries +--------------------------- +The qcow2 L2 cache stores complete tables by default. This means that +if QEMU needs an entry from an L2 table then the whole table is read +from disk and is kept in the cache. If the cache is full then a +complete table needs to be evicted first. + +This can be inefficient with large cluster sizes since it results in +more disk I/O and wastes more cache memory. + +Since QEMU 2.12 you can change the size of the L2 cache entry and make +it smaller than the cluster size. This can be configured using the +"l2-cache-entry-size" parameter: + + -drive file=3Dhd.qcow2,l2-cache-size=3D2097152,l2-cache-entry-size=3D40= 96 + +Some things to take into account: + + - The L2 cache entry size has the same restrictions as the cluster + size (power of two, at least 512 bytes). + + - Smaller entry sizes generally improve the cache efficiency and make + disk I/O faster. This is particularly true with solid state drives + so it's a good idea to reduce the entry size in those cases. With + rotating hard drives the situation is a bit more complicated so you + should test it first and stay with the default size if unsure. + + - Try different entry sizes to see which one gives faster performance + in your case. The block size of the host filesystem is generally a + good default (usually 4096 bytes in the case of ext4). + + - Only the L2 cache can be configured this way. The refcount cache + always uses the cluster size as the entry size. + + - If the L2 cache is big enough to hold all of the image's L2 tables + (as explained in the "Choosing the right cache sizes" section + earlier in this document) then none of this is necessary and you + can omit the "l2-cache-entry-size" parameter altogether. + + Reducing the memory usage ------------------------- It is possible to clean unused cache entries in order to reduce the --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018647943589.6671238106394; Fri, 2 Mar 2018 11:24:07 -0800 (PST) Received: from localhost ([::1]:37047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqHn-0001dT-5s for importer@patchew.org; Fri, 02 Mar 2018 14:24:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqZ-0001hi-5W for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqX-000383-Ul for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:55:59 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38106 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqV-00036A-AY; Fri, 02 Mar 2018 13:55:55 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D56C7813F6FF; Fri, 2 Mar 2018 18:55:54 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id B658C9C079; Fri, 2 Mar 2018 18:55:53 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:37 +0100 Message-Id: <20180302185448.6314-27-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:54 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 26/37] aio: rename aio_context_in_iothread() to in_aio_context_home_thread() 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, qemu-devel@nongnu.org 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" From: Stefan Hajnoczi The name aio_context_in_iothread() is misleading because it also returns true when called on the main AioContext from the main loop thread, which is not an IOThread. This patch renames it to in_aio_context_home_thread() and expands the doc comment to make the semantics clearer. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/block/aio.h | 7 +++++-- include/block/block.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index e9aeeaec94..a1d6b9e249 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -534,11 +534,14 @@ void aio_co_enter(AioContext *ctx, struct Coroutine *= co); AioContext *qemu_get_current_aio_context(void); =20 /** + * in_aio_context_home_thread: * @ctx: the aio context * - * Return whether we are running in the I/O thread that manages @ctx. + * Return whether we are running in the thread that normally runs @ctx. N= ote + * that acquiring/releasing ctx does not affect the outcome, each AioConte= xt + * still only has one home thread that is responsible for running it. */ -static inline bool aio_context_in_iothread(AioContext *ctx) +static inline bool in_aio_context_home_thread(AioContext *ctx) { return ctx =3D=3D qemu_get_current_aio_context(); } diff --git a/include/block/block.h b/include/block/block.h index 947e8876cd..bc41ed253b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -372,7 +372,7 @@ void bdrv_drain_all(void); bool busy_ =3D true; \ BlockDriverState *bs_ =3D (bs); \ AioContext *ctx_ =3D bdrv_get_aio_context(bs_); \ - if (aio_context_in_iothread(ctx_)) { \ + if (in_aio_context_home_thread(ctx_)) { \ while ((cond) || busy_) { \ busy_ =3D aio_poll(ctx_, (cond)); \ waited_ |=3D !!(cond) | busy_; \ --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018382472193.19733106598233; Fri, 2 Mar 2018 11:19:42 -0800 (PST) Received: from localhost ([::1]:37013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqDV-0005xc-Fb for importer@patchew.org; Fri, 02 Mar 2018 14:19:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqe-0001om-Tr for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqb-0003DZ-Jk for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:04 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45392 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqW-00037G-Vm; Fri, 02 Mar 2018 13:55:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6929A40FB658; Fri, 2 Mar 2018 18:55:56 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 489D29C079; Fri, 2 Mar 2018 18:55:55 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:38 +0100 Message-Id: <20180302185448.6314-28-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 02 Mar 2018 18:55:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 02 Mar 2018 18:55:56 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 27/37] block: extract AIO_WAIT_WHILE() from BlockDriverState 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, qemu-devel@nongnu.org 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" From: Stefan Hajnoczi BlockDriverState has the BDRV_POLL_WHILE() macro to wait on event loop activity while a condition evaluates to true. This is used to implement synchronous operations where it acts as a condvar between the IOThread running the operation and the main loop waiting for the operation. It can also be called from the thread that owns the AioContext and in that case it's just a nested event loop. BlockBackend needs this behavior but doesn't always have a BlockDriverState it can use. This patch extracts BDRV_POLL_WHILE() into the AioWait abstraction, which can be used with AioContext and isn't tied to BlockDriverState anymore. This feature could be built directly into AioContext but then all users would kick the event loop even if they signal different conditions. Imagine an AioContext with many BlockDriverStates, each time a request completes any waiter would wake up and re-check their condition. It's nicer to keep a separate AioWait object for each condition instead. Please see "block/aio-wait.h" for details on the API. The name AIO_WAIT_WHILE() avoids the confusion between AIO_POLL_WHILE() and AioContext polling. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/block/aio-wait.h | 116 ++++++++++++++++++++++++++++++++++++++++++= ++++ include/block/block.h | 40 +++------------- include/block/block_int.h | 7 ++- block.c | 5 ++ block/io.c | 10 +--- util/aio-wait.c | 40 ++++++++++++++++ util/Makefile.objs | 2 +- 7 files changed, 174 insertions(+), 46 deletions(-) create mode 100644 include/block/aio-wait.h create mode 100644 util/aio-wait.c diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h new file mode 100644 index 0000000000..a48c744fa8 --- /dev/null +++ b/include/block/aio-wait.h @@ -0,0 +1,116 @@ +/* + * AioContext wait support + * + * Copyright (C) 2018 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef QEMU_AIO_WAIT_H +#define QEMU_AIO_WAIT_H + +#include "block/aio.h" + +/** + * AioWait: + * + * An object that facilitates synchronous waiting on a condition. The main + * loop can wait on an operation running in an IOThread as follows: + * + * AioWait *wait =3D ...; + * AioContext *ctx =3D ...; + * MyWork work =3D { .done =3D false }; + * schedule_my_work_in_iothread(ctx, &work); + * AIO_WAIT_WHILE(wait, ctx, !work.done); + * + * The IOThread must call aio_wait_kick() to notify the main loop when + * work.done changes: + * + * static void do_work(...) + * { + * ... + * work.done =3D true; + * aio_wait_kick(wait); + * } + */ +typedef struct { + /* Is the main loop waiting for a kick? Accessed with atomic ops. */ + bool need_kick; +} AioWait; + +/** + * AIO_WAIT_WHILE: + * @wait: the aio wait object + * @ctx: the aio context + * @cond: wait while this conditional expression is true + * + * Wait while a condition is true. Use this to implement synchronous + * operations that require event loop activity. + * + * The caller must be sure that something calls aio_wait_kick() when the v= alue + * of @cond might have changed. + * + * The caller's thread must be the IOThread that owns @ctx or the main loop + * thread (with @ctx acquired exactly once). This function cannot be used= to + * wait on conditions between two IOThreads since that could lead to deadl= ock, + * go via the main loop instead. + */ +#define AIO_WAIT_WHILE(wait, ctx, cond) ({ \ + bool waited_ =3D false; \ + bool busy_ =3D true; \ + AioWait *wait_ =3D (wait); \ + AioContext *ctx_ =3D (ctx); \ + if (in_aio_context_home_thread(ctx_)) { \ + while ((cond) || busy_) { \ + busy_ =3D aio_poll(ctx_, (cond)); \ + waited_ |=3D !!(cond) | busy_; \ + } \ + } else { \ + assert(qemu_get_current_aio_context() =3D=3D \ + qemu_get_aio_context()); \ + assert(!wait_->need_kick); \ + /* Set wait_->need_kick before evaluating cond. */ \ + atomic_mb_set(&wait_->need_kick, true); \ + while (busy_) { \ + if ((cond)) { \ + waited_ =3D busy_ =3D true; \ + aio_context_release(ctx_); \ + aio_poll(qemu_get_aio_context(), true); \ + aio_context_acquire(ctx_); \ + } else { \ + busy_ =3D aio_poll(ctx_, false); \ + waited_ |=3D busy_; \ + } \ + } \ + atomic_set(&wait_->need_kick, false); \ + } \ + waited_; }) + +/** + * aio_wait_kick: + * @wait: the aio wait object that should re-evaluate its condition + * + * Wake up the main thread if it is waiting on AIO_WAIT_WHILE(). During + * synchronous operations performed in an IOThread, the main thread lets t= he + * IOThread's event loop run, waiting for the operation to complete. A + * aio_wait_kick() call will wake up the main thread. + */ +void aio_wait_kick(AioWait *wait); + +#endif /* QEMU_AIO_WAIT */ diff --git a/include/block/block.h b/include/block/block.h index bc41ed253b..4a80a2acd4 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -2,6 +2,7 @@ #define BLOCK_H =20 #include "block/aio.h" +#include "block/aio-wait.h" #include "qapi-types.h" #include "qemu/iov.h" #include "qemu/coroutine.h" @@ -367,41 +368,14 @@ void bdrv_drain_all_begin(void); void bdrv_drain_all_end(void); void bdrv_drain_all(void); =20 +/* Returns NULL when bs =3D=3D NULL */ +AioWait *bdrv_get_aio_wait(BlockDriverState *bs); + #define BDRV_POLL_WHILE(bs, cond) ({ \ - bool waited_ =3D false; \ - bool busy_ =3D true; \ BlockDriverState *bs_ =3D (bs); \ - AioContext *ctx_ =3D bdrv_get_aio_context(bs_); \ - if (in_aio_context_home_thread(ctx_)) { \ - while ((cond) || busy_) { \ - busy_ =3D aio_poll(ctx_, (cond)); \ - waited_ |=3D !!(cond) | busy_; \ - } \ - } else { \ - assert(qemu_get_current_aio_context() =3D=3D \ - qemu_get_aio_context()); \ - /* Ask bdrv_dec_in_flight to wake up the main \ - * QEMU AioContext. Extra I/O threads never take \ - * other I/O threads' AioContexts (see for example \ - * block_job_defer_to_main_loop for how to do it). \ - */ \ - assert(!bs_->wakeup); \ - /* Set bs->wakeup before evaluating cond. */ \ - atomic_mb_set(&bs_->wakeup, true); \ - while (busy_) { \ - if ((cond)) { \ - waited_ =3D busy_ =3D true; \ - aio_context_release(ctx_); \ - aio_poll(qemu_get_aio_context(), true); \ - aio_context_acquire(ctx_); \ - } else { \ - busy_ =3D aio_poll(ctx_, false); \ - waited_ |=3D busy_; \ - } \ - } \ - atomic_set(&bs_->wakeup, false); \ - } \ - waited_; }) + AIO_WAIT_WHILE(bdrv_get_aio_wait(bs_), \ + bdrv_get_aio_context(bs_), \ + cond); }) =20 int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); diff --git a/include/block/block_int.h b/include/block/block_int.h index 5ae7738cf8..aef10296b0 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -26,6 +26,7 @@ =20 #include "block/accounting.h" #include "block/block.h" +#include "block/aio-wait.h" #include "qemu/queue.h" #include "qemu/coroutine.h" #include "qemu/stats64.h" @@ -716,10 +717,8 @@ struct BlockDriverState { unsigned int in_flight; unsigned int serialising_in_flight; =20 - /* Internal to BDRV_POLL_WHILE and bdrv_wakeup. Accessed with atomic - * ops. - */ - bool wakeup; + /* Kicked to signal main loop when a request completes. */ + AioWait wait; =20 /* counter for nested bdrv_io_plug. * Accessed with atomic ops. diff --git a/block.c b/block.c index 814e5a02da..9e4da81213 100644 --- a/block.c +++ b/block.c @@ -4716,6 +4716,11 @@ AioContext *bdrv_get_aio_context(BlockDriverState *b= s) return bs->aio_context; } =20 +AioWait *bdrv_get_aio_wait(BlockDriverState *bs) +{ + return bs ? &bs->wait : NULL; +} + void bdrv_coroutine_enter(BlockDriverState *bs, Coroutine *co) { aio_co_enter(bdrv_get_aio_context(bs), co); diff --git a/block/io.c b/block/io.c index 4d3d1f640a..2b09c656d0 100644 --- a/block/io.c +++ b/block/io.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "trace.h" #include "sysemu/block-backend.h" +#include "block/aio-wait.h" #include "block/blockjob.h" #include "block/blockjob_int.h" #include "block/block_int.h" @@ -587,16 +588,9 @@ void bdrv_inc_in_flight(BlockDriverState *bs) atomic_inc(&bs->in_flight); } =20 -static void dummy_bh_cb(void *opaque) -{ -} - void bdrv_wakeup(BlockDriverState *bs) { - /* The barrier (or an atomic op) is in the caller. */ - if (atomic_read(&bs->wakeup)) { - aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL); - } + aio_wait_kick(bdrv_get_aio_wait(bs)); } =20 void bdrv_dec_in_flight(BlockDriverState *bs) diff --git a/util/aio-wait.c b/util/aio-wait.c new file mode 100644 index 0000000000..a487cdb852 --- /dev/null +++ b/util/aio-wait.c @@ -0,0 +1,40 @@ +/* + * AioContext wait support + * + * Copyright (C) 2018 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "block/aio-wait.h" + +static void dummy_bh_cb(void *opaque) +{ + /* The point is to make AIO_WAIT_WHILE()'s aio_poll() return */ +} + +void aio_wait_kick(AioWait *wait) +{ + /* The barrier (or an atomic op) is in the caller. */ + if (atomic_read(&wait->need_kick)) { + aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL); + } +} diff --git a/util/Makefile.objs b/util/Makefile.objs index 3fb611631f..ae90b9963d 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -1,7 +1,7 @@ util-obj-y =3D osdep.o cutils.o unicode.o qemu-timer-common.o util-obj-y +=3D bufferiszero.o util-obj-y +=3D lockcnt.o -util-obj-y +=3D aiocb.o async.o thread-pool.o qemu-timer.o +util-obj-y +=3D aiocb.o async.o aio-wait.o thread-pool.o qemu-timer.o util-obj-y +=3D main-loop.o iohandler.o util-obj-$(CONFIG_POSIX) +=3D aio-posix.o util-obj-$(CONFIG_POSIX) +=3D compatfd.o --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018460627206.36567754421492; Fri, 2 Mar 2018 11:21:00 -0800 (PST) Received: from localhost ([::1]:37022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqEa-00071A-S2 for importer@patchew.org; Fri, 02 Mar 2018 14:20:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqe-0001oq-Uz for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqb-0003De-Kg for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:05 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38108 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqY-00038Q-EX; Fri, 02 Mar 2018 13:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE106813F6FF; Fri, 2 Mar 2018 18:55:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF689AB58B; Fri, 2 Mar 2018 18:55:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:39 +0100 Message-Id: <20180302185448.6314-29-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:55:57 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 28/37] block: add BlockBackend->in_flight counter 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, qemu-devel@nongnu.org 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" From: Stefan Hajnoczi BlockBackend currently relies on BlockDriverState->in_flight to track requests for blk_drain(). There is a corner case where BlockDriverState->in_flight cannot be used though: blk->root can be NULL when there is no medium. This results in a segfault when the NULL pointer is dereferenced. Introduce a BlockBackend->in_flight counter for aio requests so it works even when blk->root =3D=3D NULL. Based on a patch by Kevin Wolf . Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 2 +- block/block-backend.c | 60 +++++++++++++++++++++++++++++++++++++++++++++--= ---- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index 9e4da81213..a83037c2a5 100644 --- a/block.c +++ b/block.c @@ -4713,7 +4713,7 @@ out: =20 AioContext *bdrv_get_aio_context(BlockDriverState *bs) { - return bs->aio_context; + return bs ? bs->aio_context : qemu_get_aio_context(); } =20 AioWait *bdrv_get_aio_wait(BlockDriverState *bs) diff --git a/block/block-backend.c b/block/block-backend.c index 0266ac990b..a775a3dd2f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -73,6 +73,14 @@ struct BlockBackend { int quiesce_counter; VMChangeStateEntry *vmsh; bool force_allow_inactivate; + + /* Number of in-flight aio requests. BlockDriverState also counts + * in-flight requests but aio requests can exist even when blk->root is + * NULL, so we cannot rely on its counter for that case. + * Accessed with atomic ops. + */ + unsigned int in_flight; + AioWait wait; }; =20 typedef struct BlockBackendAIOCB { @@ -1225,11 +1233,22 @@ int blk_make_zero(BlockBackend *blk, BdrvRequestFla= gs flags) return bdrv_make_zero(blk->root, flags); } =20 +static void blk_inc_in_flight(BlockBackend *blk) +{ + atomic_inc(&blk->in_flight); +} + +static void blk_dec_in_flight(BlockBackend *blk) +{ + atomic_dec(&blk->in_flight); + aio_wait_kick(&blk->wait); +} + static void error_callback_bh(void *opaque) { struct BlockBackendAIOCB *acb =3D opaque; =20 - bdrv_dec_in_flight(acb->common.bs); + blk_dec_in_flight(acb->blk); acb->common.cb(acb->common.opaque, acb->ret); qemu_aio_unref(acb); } @@ -1240,7 +1259,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, { struct BlockBackendAIOCB *acb; =20 - bdrv_inc_in_flight(blk_bs(blk)); + blk_inc_in_flight(blk); acb =3D blk_aio_get(&block_backend_aiocb_info, blk, cb, opaque); acb->blk =3D blk; acb->ret =3D ret; @@ -1263,7 +1282,7 @@ static const AIOCBInfo blk_aio_em_aiocb_info =3D { static void blk_aio_complete(BlkAioEmAIOCB *acb) { if (acb->has_returned) { - bdrv_dec_in_flight(acb->common.bs); + blk_dec_in_flight(acb->rwco.blk); acb->common.cb(acb->common.opaque, acb->rwco.ret); qemu_aio_unref(acb); } @@ -1284,7 +1303,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, in= t64_t offset, int bytes, BlkAioEmAIOCB *acb; Coroutine *co; =20 - bdrv_inc_in_flight(blk_bs(blk)); + blk_inc_in_flight(blk); acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); acb->rwco =3D (BlkRwCo) { .blk =3D blk, @@ -1521,14 +1540,41 @@ int blk_flush(BlockBackend *blk) =20 void blk_drain(BlockBackend *blk) { - if (blk_bs(blk)) { - bdrv_drain(blk_bs(blk)); + BlockDriverState *bs =3D blk_bs(blk); + + if (bs) { + bdrv_drained_begin(bs); + } + + /* We may have -ENOMEDIUM completions in flight */ + AIO_WAIT_WHILE(&blk->wait, + blk_get_aio_context(blk), + atomic_mb_read(&blk->in_flight) > 0); + + if (bs) { + bdrv_drained_end(bs); } } =20 void blk_drain_all(void) { - bdrv_drain_all(); + BlockBackend *blk =3D NULL; + + bdrv_drain_all_begin(); + + while ((blk =3D blk_all_next(blk)) !=3D NULL) { + AioContext *ctx =3D blk_get_aio_context(blk); + + aio_context_acquire(ctx); + + /* We may have -ENOMEDIUM completions in flight */ + AIO_WAIT_WHILE(&blk->wait, ctx, + atomic_mb_read(&blk->in_flight) > 0); + + aio_context_release(ctx); + } + + bdrv_drain_all_end(); } =20 void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018700712709.4792548770265; Fri, 2 Mar 2018 11:25:00 -0800 (PST) Received: from localhost ([::1]:37050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqId-0002T8-SP for importer@patchew.org; Fri, 02 Mar 2018 14:24:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqh-0001rx-So for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqg-0003I1-T9 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:07 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60128 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqd-0003EK-0E; Fri, 02 Mar 2018 13:56:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8245D4022909; Fri, 2 Mar 2018 18:56:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 618F59C079; Fri, 2 Mar 2018 18:55:58 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:40 +0100 Message-Id: <20180302185448.6314-30-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:56:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:56:02 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 29/37] block: test blk_aio_flush() with blk->root == NULL 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, qemu-devel@nongnu.org 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" This patch adds test cases for the scenario where blk_aio_flush() is called on a BlockBackend with no root. Calling drain afterwards should complete the requests with -ENOMEDIUM. Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/test-block-backend.c | 82 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/Makefile.include | 2 ++ 2 files changed, 84 insertions(+) create mode 100644 tests/test-block-backend.c diff --git a/tests/test-block-backend.c b/tests/test-block-backend.c new file mode 100644 index 0000000000..fd59f02bd0 --- /dev/null +++ b/tests/test-block-backend.c @@ -0,0 +1,82 @@ +/* + * BlockBackend tests + * + * Copyright (c) 2017 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "block/block.h" +#include "sysemu/block-backend.h" +#include "qapi/error.h" + +static void test_drain_aio_error_flush_cb(void *opaque, int ret) +{ + bool *completed =3D opaque; + + g_assert(ret =3D=3D -ENOMEDIUM); + *completed =3D true; +} + +static void test_drain_aio_error(void) +{ + BlockBackend *blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + BlockAIOCB *acb; + bool completed =3D false; + + acb =3D blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed); + g_assert(acb !=3D NULL); + g_assert(completed =3D=3D false); + + blk_drain(blk); + g_assert(completed =3D=3D true); + + blk_unref(blk); +} + +static void test_drain_all_aio_error(void) +{ + BlockBackend *blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + BlockAIOCB *acb; + bool completed =3D false; + + acb =3D blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed); + g_assert(acb !=3D NULL); + g_assert(completed =3D=3D false); + + blk_drain_all(); + g_assert(completed =3D=3D true); + + blk_unref(blk); +} + +int main(int argc, char **argv) +{ + bdrv_init(); + qemu_init_main_loop(&error_abort); + + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/block-backend/drain_aio_error", test_drain_aio_error= ); + g_test_add_func("/block-backend/drain_all_aio_error", + test_drain_all_aio_error); + + return g_test_run(); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 937cbd874a..b5aab848b3 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -83,6 +83,7 @@ gcov-files-test-hbitmap-y =3D blockjob.c check-unit-y +=3D tests/test-bdrv-drain$(EXESUF) check-unit-y +=3D tests/test-blockjob$(EXESUF) check-unit-y +=3D tests/test-blockjob-txn$(EXESUF) +check-unit-y +=3D tests/test-block-backend$(EXESUF) check-unit-y +=3D tests/test-x86-cpuid$(EXESUF) # all code tested by test-x86-cpuid is inside topology.h gcov-files-test-x86-cpuid-y =3D @@ -613,6 +614,7 @@ tests/test-throttle$(EXESUF): tests/test-throttle.o $(t= est-block-obj-y) tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y= ) $(test-util-obj-y) tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(= test-util-obj-y) tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-o= bj-y) $(test-util-obj-y) +tests/test-block-backend$(EXESUF): tests/test-block-backend.o $(test-block= -obj-y) $(test-util-obj-y) tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj= -y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(tes= t-crypto-obj-y) --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018545979953.7741605609382; Fri, 2 Mar 2018 11:22:25 -0800 (PST) Received: from localhost ([::1]:37038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqG9-000050-6w for importer@patchew.org; Fri, 02 Mar 2018 14:22:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqh-0001re-Hz for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqg-0003Hp-ON for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:07 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56454 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqe-0003F1-J7; Fri, 02 Mar 2018 13:56:04 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14B37404084B; Fri, 2 Mar 2018 18:56:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E944AAB583; Fri, 2 Mar 2018 18:56:02 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:41 +0100 Message-Id: <20180302185448.6314-31-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:56:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 02 Mar 2018 18:56:04 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 30/37] Revert "IDE: Do not flush empty CDROM drives" 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, qemu-devel@nongnu.org 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" From: Stefan Hajnoczi This reverts commit 4da97120d51a4383aa96d741a2b837f8c4bbcd0b. blk_aio_flush() now handles the blk->root =3D=3D NULL case, so we no longer need this workaround. Cc: John Snow Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- hw/ide/core.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 257b429381..139c843514 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1087,15 +1087,7 @@ static void ide_flush_cache(IDEState *s) s->status |=3D BUSY_STAT; ide_set_retry(s); block_acct_start(blk_get_stats(s->blk), &s->acct, 0, BLOCK_ACCT_FLUSH); - - if (blk_bs(s->blk)) { - s->pio_aiocb =3D blk_aio_flush(s->blk, ide_flush_cb, s); - } else { - /* XXX blk_aio_flush() crashes when blk_bs(blk) is NULL, remove th= is - * temporary workaround when blk_aio_*() functions handle NULL blk= _bs. - */ - ide_flush_cb(s, 0); - } + s->pio_aiocb =3D blk_aio_flush(s->blk, ide_flush_cb, s); } =20 static void ide_cfata_metadata_inquiry(IDEState *s) --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018622010239.9609348507762; Fri, 2 Mar 2018 11:23:42 -0800 (PST) Received: from localhost ([::1]:37044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqHN-0001EA-45 for importer@patchew.org; Fri, 02 Mar 2018 14:23:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqp-0001zL-08 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqm-0003Mj-FM for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:15 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45394 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqg-0003GZ-AI; Fri, 02 Mar 2018 13:56:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D177940FB658; Fri, 2 Mar 2018 18:56:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A95A9C079; Fri, 2 Mar 2018 18:56:04 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:42 +0100 Message-Id: <20180302185448.6314-32-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 02 Mar 2018 18:56:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 02 Mar 2018 18:56:05 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 31/37] block: rename .bdrv_create() to .bdrv_co_create_opts() 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, qemu-devel@nongnu.org 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" From: Stefan Hajnoczi BlockDriver->bdrv_create() has been called from coroutine context since commit 5b7e1542cfa41a281af9629d31cef03704d976e6 ("block: make bdrv_create adopt coroutine"). Make this explicit by renaming to .bdrv_co_create_opts() and add the coroutine_fn annotation. This makes it obvious to block driver authors that they may yield, use CoMutex, or other coroutine_fn APIs. bdrv_co_create is reserved for the QAPI-based version that Kevin is working on. Signed-off-by: Stefan Hajnoczi Message-Id: <20170705102231.20711-2-stefanha@redhat.com> Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/block/block_int.h | 3 ++- block.c | 4 ++-- block/crypto.c | 8 ++++---- block/file-posix.c | 15 ++++++++------- block/file-win32.c | 5 +++-- block/gluster.c | 13 +++++++------ block/iscsi.c | 7 ++++--- block/nfs.c | 5 +++-- block/parallels.c | 6 ++++-- block/qcow.c | 5 +++-- block/qcow2.c | 5 +++-- block/qed.c | 6 ++++-- block/raw-format.c | 5 +++-- block/rbd.c | 6 ++++-- block/sheepdog.c | 10 +++++----- block/ssh.c | 5 +++-- block/vdi.c | 5 +++-- block/vhdx.c | 5 +++-- block/vmdk.c | 5 +++-- block/vpc.c | 5 +++-- 20 files changed, 74 insertions(+), 54 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index aef10296b0..64a5700f2b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -129,7 +129,8 @@ struct BlockDriver { int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, Error **errp); void (*bdrv_close)(BlockDriverState *bs); - int (*bdrv_create)(const char *filename, QemuOpts *opts, Error **errp); + int coroutine_fn (*bdrv_co_create_opts)(const char *filename, QemuOpts= *opts, + Error **errp); int (*bdrv_make_empty)(BlockDriverState *bs); =20 void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); diff --git a/block.c b/block.c index a83037c2a5..86dd809041 100644 --- a/block.c +++ b/block.c @@ -420,7 +420,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opa= que) CreateCo *cco =3D opaque; assert(cco->drv); =20 - ret =3D cco->drv->bdrv_create(cco->filename, cco->opts, &local_err); + ret =3D cco->drv->bdrv_co_create_opts(cco->filename, cco->opts, &local= _err); error_propagate(&cco->err, local_err); cco->ret =3D ret; } @@ -439,7 +439,7 @@ int bdrv_create(BlockDriver *drv, const char* filename, .err =3D NULL, }; =20 - if (!drv->bdrv_create) { + if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation", dr= v->format_name); ret =3D -ENOTSUP; goto out; diff --git a/block/crypto.c b/block/crypto.c index 3df66947c5..2ea116e6db 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -556,9 +556,9 @@ static int block_crypto_open_luks(BlockDriverState *bs, bs, options, flags, errp); } =20 -static int block_crypto_create_luks(const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn block_crypto_co_create_opts_luks(const char *filen= ame, + QemuOpts *opts, + Error **errp) { return block_crypto_create_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS, filename, opts, errp); @@ -617,7 +617,7 @@ BlockDriver bdrv_crypto_luks =3D { .bdrv_open =3D block_crypto_open_luks, .bdrv_close =3D block_crypto_close, .bdrv_child_perm =3D bdrv_format_default_perms, - .bdrv_create =3D block_crypto_create_luks, + .bdrv_co_create_opts =3D block_crypto_co_create_opts_luks, .bdrv_truncate =3D block_crypto_truncate, .create_opts =3D &block_crypto_create_opts_luks, =20 diff --git a/block/file-posix.c b/block/file-posix.c index f1591c3849..7f2cc63c60 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1982,7 +1982,8 @@ static int64_t raw_get_allocated_file_size(BlockDrive= rState *bs) return (int64_t)st.st_blocks * 512; } =20 -static int raw_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts = *opts, + Error **errp) { int fd; int result =3D 0; @@ -2276,7 +2277,7 @@ BlockDriver bdrv_file =3D { .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, .bdrv_close =3D raw_close, - .bdrv_create =3D raw_create, + .bdrv_co_create_opts =3D raw_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D raw_co_block_status, .bdrv_co_pwrite_zeroes =3D raw_co_pwrite_zeroes, @@ -2680,8 +2681,8 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDr= iverState *bs, return -ENOTSUP; } =20 -static int hdev_create(const char *filename, QemuOpts *opts, - Error **errp) +static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts= *opts, + Error **errp) { int fd; int ret =3D 0; @@ -2754,7 +2755,7 @@ static BlockDriver bdrv_host_device =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, - .bdrv_create =3D hdev_create, + .bdrv_co_create_opts =3D hdev_co_create_opts, .create_opts =3D &raw_create_opts, .bdrv_co_pwrite_zeroes =3D hdev_co_pwrite_zeroes, =20 @@ -2876,7 +2877,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, - .bdrv_create =3D hdev_create, + .bdrv_co_create_opts =3D hdev_co_create_opts, .create_opts =3D &raw_create_opts, =20 =20 @@ -3007,7 +3008,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, - .bdrv_create =3D hdev_create, + .bdrv_co_create_opts =3D hdev_co_create_opts, .create_opts =3D &raw_create_opts, =20 .bdrv_co_preadv =3D raw_co_preadv, diff --git a/block/file-win32.c b/block/file-win32.c index f24c7bb92c..4a430d45f1 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -553,7 +553,8 @@ static int64_t raw_get_allocated_file_size(BlockDriverS= tate *bs) return st.st_size; } =20 -static int raw_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts = *opts, + Error **errp) { int fd; int64_t total_size =3D 0; @@ -599,7 +600,7 @@ BlockDriver bdrv_file =3D { .bdrv_file_open =3D raw_open, .bdrv_refresh_limits =3D raw_probe_alignment, .bdrv_close =3D raw_close, - .bdrv_create =3D raw_create, + .bdrv_co_create_opts =3D raw_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, =20 .bdrv_aio_readv =3D raw_aio_readv, diff --git a/block/gluster.c b/block/gluster.c index 1a07d221d1..79b4cfdf74 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1021,8 +1021,9 @@ static int qemu_gluster_do_truncate(struct glfs_fd *f= d, int64_t offset, return 0; } =20 -static int qemu_gluster_create(const char *filename, - QemuOpts *opts, Error **errp) +static int coroutine_fn qemu_gluster_co_create_opts(const char *filename, + QemuOpts *opts, + Error **errp) { BlockdevOptionsGluster *gconf; struct glfs *glfs; @@ -1435,7 +1436,7 @@ static BlockDriver bdrv_gluster =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, - .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, @@ -1463,7 +1464,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, - .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, @@ -1491,7 +1492,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, - .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, @@ -1525,7 +1526,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, - .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, diff --git a/block/iscsi.c b/block/iscsi.c index c228ca21c8..07988ce761 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2117,7 +2117,8 @@ static int iscsi_truncate(BlockDriverState *bs, int64= _t offset, return 0; } =20 -static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn iscsi_co_create_opts(const char *filename, QemuOpt= s *opts, + Error **errp) { int ret =3D 0; int64_t total_size =3D 0; @@ -2204,7 +2205,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_parse_filename =3D iscsi_parse_filename, .bdrv_file_open =3D iscsi_open, .bdrv_close =3D iscsi_close, - .bdrv_create =3D iscsi_create, + .bdrv_co_create_opts =3D iscsi_co_create_opts, .create_opts =3D &iscsi_create_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, @@ -2239,7 +2240,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_parse_filename =3D iscsi_parse_filename, .bdrv_file_open =3D iscsi_open, .bdrv_close =3D iscsi_close, - .bdrv_create =3D iscsi_create, + .bdrv_co_create_opts =3D iscsi_co_create_opts, .create_opts =3D &iscsi_create_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, diff --git a/block/nfs.c b/block/nfs.c index 6576a73d6e..ce6e195a41 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -684,7 +684,8 @@ static QemuOptsList nfs_create_opts =3D { } }; =20 -static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp) +static int coroutine_fn nfs_file_co_create_opts(const char *url, QemuOpts = *opts, + Error **errp) { int64_t ret, total_size; NFSClient *client =3D g_new0(NFSClient, 1); @@ -897,7 +898,7 @@ static BlockDriver bdrv_nfs =3D { =20 .bdrv_file_open =3D nfs_file_open, .bdrv_close =3D nfs_file_close, - .bdrv_create =3D nfs_file_create, + .bdrv_co_create_opts =3D nfs_file_co_create_opts, .bdrv_reopen_prepare =3D nfs_reopen_prepare, =20 .bdrv_co_preadv =3D nfs_co_preadv, diff --git a/block/parallels.c b/block/parallels.c index 3e952a9c14..81085795c2 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -475,7 +475,9 @@ static int parallels_check(BlockDriverState *bs, BdrvCh= eckResult *res, } =20 =20 -static int parallels_create(const char *filename, QemuOpts *opts, Error **= errp) +static int coroutine_fn parallels_co_create_opts(const char *filename, + QemuOpts *opts, + Error **errp) { int64_t total_size, cl_size; uint8_t tmp[BDRV_SECTOR_SIZE]; @@ -796,7 +798,7 @@ static BlockDriver bdrv_parallels =3D { .bdrv_co_readv =3D parallels_co_readv, .bdrv_co_writev =3D parallels_co_writev, .supports_backing =3D true, - .bdrv_create =3D parallels_create, + .bdrv_co_create_opts =3D parallels_co_create_opts, .bdrv_check =3D parallels_check, .create_opts =3D ¶llels_create_opts, }; diff --git a/block/qcow.c b/block/qcow.c index dead5029c6..47a18d9a3a 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -810,7 +810,8 @@ static void qcow_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 -static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn qcow_co_create_opts(const char *filename, QemuOpts= *opts, + Error **errp) { int header_size, backing_filename_len, l1_size, shift, i; QCowHeader header; @@ -1127,7 +1128,7 @@ static BlockDriver bdrv_qcow =3D { .bdrv_close =3D qcow_close, .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_reopen_prepare =3D qcow_reopen_prepare, - .bdrv_create =3D qcow_create, + .bdrv_co_create_opts =3D qcow_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .supports_backing =3D true, =20 diff --git a/block/qcow2.c b/block/qcow2.c index 288b5299d8..93fb625dcb 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2916,7 +2916,8 @@ out: return ret; } =20 -static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpt= s *opts, + Error **errp) { char *backing_file =3D NULL; char *backing_fmt =3D NULL; @@ -4352,7 +4353,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_reopen_abort =3D qcow2_reopen_abort, .bdrv_join_options =3D qcow2_join_options, .bdrv_child_perm =3D bdrv_format_default_perms, - .bdrv_create =3D qcow2_create, + .bdrv_co_create_opts =3D qcow2_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D qcow2_co_block_status, =20 diff --git a/block/qed.c b/block/qed.c index a595220926..72cf2f58ab 100644 --- a/block/qed.c +++ b/block/qed.c @@ -638,7 +638,9 @@ out: return ret; } =20 -static int bdrv_qed_create(const char *filename, QemuOpts *opts, Error **e= rrp) +static int coroutine_fn bdrv_qed_co_create_opts(const char *filename, + QemuOpts *opts, + Error **errp) { uint64_t image_size =3D 0; uint32_t cluster_size =3D QED_DEFAULT_CLUSTER_SIZE; @@ -1564,7 +1566,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_close =3D bdrv_qed_close, .bdrv_reopen_prepare =3D bdrv_qed_reopen_prepare, .bdrv_child_perm =3D bdrv_format_default_perms, - .bdrv_create =3D bdrv_qed_create, + .bdrv_co_create_opts =3D bdrv_qed_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D bdrv_qed_co_block_status, .bdrv_co_readv =3D bdrv_qed_co_readv, diff --git a/block/raw-format.c b/block/raw-format.c index 830243a8e4..a378547c99 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -396,7 +396,8 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs->file->bs); } =20 -static int raw_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts = *opts, + Error **errp) { return bdrv_create_file(filename, opts, errp); } @@ -491,7 +492,7 @@ BlockDriver bdrv_raw =3D { .bdrv_open =3D &raw_open, .bdrv_close =3D &raw_close, .bdrv_child_perm =3D bdrv_filter_default_perms, - .bdrv_create =3D &raw_create, + .bdrv_co_create_opts =3D &raw_co_create_opts, .bdrv_co_preadv =3D &raw_co_preadv, .bdrv_co_pwritev =3D &raw_co_pwritev, .bdrv_co_pwrite_zeroes =3D &raw_co_pwrite_zeroes, diff --git a/block/rbd.c b/block/rbd.c index 8474b0ba11..c7dd32e213 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -351,7 +351,9 @@ static QemuOptsList runtime_opts =3D { }, }; =20 -static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **e= rrp) +static int coroutine_fn qemu_rbd_co_create_opts(const char *filename, + QemuOpts *opts, + Error **errp) { Error *local_err =3D NULL; int64_t bytes =3D 0; @@ -1132,7 +1134,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_file_open =3D qemu_rbd_open, .bdrv_close =3D qemu_rbd_close, .bdrv_reopen_prepare =3D qemu_rbd_reopen_prepare, - .bdrv_create =3D qemu_rbd_create, + .bdrv_co_create_opts =3D qemu_rbd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_get_info =3D qemu_rbd_getinfo, .create_opts =3D &qemu_rbd_create_opts, diff --git a/block/sheepdog.c b/block/sheepdog.c index 3c3becf94d..cef6faec4d 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1959,8 +1959,8 @@ static int parse_block_size_shift(BDRVSheepdogState *= s, QemuOpts *opt) return 0; } =20 -static int sd_create(const char *filename, QemuOpts *opts, - Error **errp) +static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *= opts, + Error **errp) { Error *err =3D NULL; int ret =3D 0; @@ -3103,7 +3103,7 @@ static BlockDriver bdrv_sheepdog =3D { .bdrv_reopen_commit =3D sd_reopen_commit, .bdrv_reopen_abort =3D sd_reopen_abort, .bdrv_close =3D sd_close, - .bdrv_create =3D sd_create, + .bdrv_co_create_opts =3D sd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, @@ -3139,7 +3139,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .bdrv_reopen_commit =3D sd_reopen_commit, .bdrv_reopen_abort =3D sd_reopen_abort, .bdrv_close =3D sd_close, - .bdrv_create =3D sd_create, + .bdrv_co_create_opts =3D sd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, @@ -3175,7 +3175,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .bdrv_reopen_commit =3D sd_reopen_commit, .bdrv_reopen_abort =3D sd_reopen_abort, .bdrv_close =3D sd_close, - .bdrv_create =3D sd_create, + .bdrv_co_create_opts =3D sd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, diff --git a/block/ssh.c b/block/ssh.c index b63addcf94..36d5d888d5 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -816,7 +816,8 @@ static QemuOptsList ssh_create_opts =3D { } }; =20 -static int ssh_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn ssh_co_create_opts(const char *filename, QemuOpts = *opts, + Error **errp) { int r, ret; int64_t total_size =3D 0; @@ -1204,7 +1205,7 @@ static BlockDriver bdrv_ssh =3D { .instance_size =3D sizeof(BDRVSSHState), .bdrv_parse_filename =3D ssh_parse_filename, .bdrv_file_open =3D ssh_file_open, - .bdrv_create =3D ssh_create, + .bdrv_co_create_opts =3D ssh_co_create_opts, .bdrv_close =3D ssh_close, .bdrv_has_zero_init =3D ssh_has_zero_init, .bdrv_co_readv =3D ssh_co_readv, diff --git a/block/vdi.c b/block/vdi.c index 0780c82d82..68592cc58d 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -716,7 +716,8 @@ nonallocating_write: return ret; } =20 -static int vdi_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts = *opts, + Error **errp) { int ret =3D 0; uint64_t bytes =3D 0; @@ -894,7 +895,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_close =3D vdi_close, .bdrv_reopen_prepare =3D vdi_reopen_prepare, .bdrv_child_perm =3D bdrv_format_default_perms, - .bdrv_create =3D vdi_create, + .bdrv_co_create_opts =3D vdi_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D vdi_co_block_status, .bdrv_make_empty =3D vdi_make_empty, diff --git a/block/vhdx.c b/block/vhdx.c index c449c5dcfd..3fbff5048b 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1792,7 +1792,8 @@ exit: * .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------. * 1MB */ -static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn vhdx_co_create_opts(const char *filename, QemuOpts= *opts, + Error **errp) { int ret =3D 0; uint64_t image_size =3D (uint64_t) 2 * GiB; @@ -2003,7 +2004,7 @@ static BlockDriver bdrv_vhdx =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_readv =3D vhdx_co_readv, .bdrv_co_writev =3D vhdx_co_writev, - .bdrv_create =3D vhdx_create, + .bdrv_co_create_opts =3D vhdx_co_create_opts, .bdrv_get_info =3D vhdx_get_info, .bdrv_check =3D vhdx_check, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, diff --git a/block/vmdk.c b/block/vmdk.c index 75f84213e6..67342ed69b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1882,7 +1882,8 @@ static int filename_decompose(const char *filename, c= har *path, char *prefix, return VMDK_OK; } =20 -static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn vmdk_co_create_opts(const char *filename, QemuOpts= *opts, + Error **errp) { int idx =3D 0; BlockBackend *new_blk =3D NULL; @@ -2398,7 +2399,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_co_pwritev_compressed =3D vmdk_co_pwritev_compressed, .bdrv_co_pwrite_zeroes =3D vmdk_co_pwrite_zeroes, .bdrv_close =3D vmdk_close, - .bdrv_create =3D vmdk_create, + .bdrv_co_create_opts =3D vmdk_co_create_opts, .bdrv_co_flush_to_disk =3D vmdk_co_flush, .bdrv_co_block_status =3D vmdk_co_block_status, .bdrv_get_allocated_file_size =3D vmdk_get_allocated_file_size, diff --git a/block/vpc.c b/block/vpc.c index fba4492fd7..b2e2b9ebd4 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -897,7 +897,8 @@ static int create_fixed_disk(BlockBackend *blk, uint8_t= *buf, return ret; } =20 -static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) +static int coroutine_fn vpc_co_create_opts(const char *filename, QemuOpts = *opts, + Error **errp) { uint8_t buf[1024]; VHDFooter *footer =3D (VHDFooter *) buf; @@ -1095,7 +1096,7 @@ static BlockDriver bdrv_vpc =3D { .bdrv_close =3D vpc_close, .bdrv_reopen_prepare =3D vpc_reopen_prepare, .bdrv_child_perm =3D bdrv_format_default_perms, - .bdrv_create =3D vpc_create, + .bdrv_co_create_opts =3D vpc_co_create_opts, =20 .bdrv_co_preadv =3D vpc_co_preadv, .bdrv_co_pwritev =3D vpc_co_pwritev, --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018017389919.1511344442299; Fri, 2 Mar 2018 11:13:37 -0800 (PST) Received: from localhost ([::1]:36970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erq7c-0000Tb-Hz for importer@patchew.org; Fri, 02 Mar 2018 14:13:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqn-0001xZ-9K for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqk-0003Kv-1G for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:13 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47296 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqh-0003Ib-T6; Fri, 02 Mar 2018 13:56:07 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 658F77B4AD; Fri, 2 Mar 2018 18:56:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44E43AB58B; Fri, 2 Mar 2018 18:56:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:43 +0100 Message-Id: <20180302185448.6314-33-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:56:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:56:07 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 32/37] qcow2: make qcow2_co_create2() a coroutine_fn 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi qcow2_create2() calls qemu_co_mutex_lock(). Only a coroutine_fn may call another coroutine_fn. In fact, qcow2_create2 is always called from coroutine context. Rename the function to add the "co" moniker and add coroutine_fn. Reported-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Stefan Hajnoczi Message-Id: <20170705102231.20711-3-stefanha@redhat.com> Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 93fb625dcb..7cf3c1518a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2725,11 +2725,12 @@ static uint64_t qcow2_opt_get_refcount_bits_del(Qem= uOpts *opts, int version, return refcount_bits; } =20 -static int qcow2_create2(const char *filename, int64_t total_size, - const char *backing_file, const char *backing_for= mat, - int flags, size_t cluster_size, PreallocMode prea= lloc, - QemuOpts *opts, int version, int refcount_order, - const char *encryptfmt, Error **errp) +static int coroutine_fn +qcow2_co_create2(const char *filename, int64_t total_size, + const char *backing_file, const char *backing_format, + int flags, size_t cluster_size, PreallocMode prealloc, + QemuOpts *opts, int version, int refcount_order, + const char *encryptfmt, Error **errp) { QDict *options; =20 @@ -2998,9 +2999,9 @@ static int coroutine_fn qcow2_co_create_opts(const ch= ar *filename, QemuOpts *opt =20 refcount_order =3D ctz32(refcount_bits); =20 - ret =3D qcow2_create2(filename, size, backing_file, backing_fmt, flags, - cluster_size, prealloc, opts, version, refcount_or= der, - encryptfmt, &local_err); + ret =3D qcow2_co_create2(filename, size, backing_file, backing_fmt, fl= ags, + cluster_size, prealloc, opts, version, refcount= _order, + encryptfmt, &local_err); error_propagate(errp, local_err); =20 finish: --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15200188689091000.3647840842738; Fri, 2 Mar 2018 11:27:48 -0800 (PST) Received: from localhost ([::1]:37076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqLM-0005Mh-5b for importer@patchew.org; Fri, 02 Mar 2018 14:27:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqp-0001za-83 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqo-0003Pd-Fx for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:15 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38114 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpql-0003LP-DX; Fri, 02 Mar 2018 13:56:11 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB75D813F6FF; Fri, 2 Mar 2018 18:56:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD3A6AB583; Fri, 2 Mar 2018 18:56:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:44 +0100 Message-Id: <20180302185448.6314-34-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:56:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:56:10 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 33/37] qemu-img: Make resize error message more general 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, qemu-devel@nongnu.org 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" From: Max Reitz The issue: $ qemu-img resize -f qcow2 foo.qcow2 qemu-img: Expecting one image file name Try 'qemu-img --help' for more information So we gave an image file name, but we omitted the length. qemu-img thinks the last argument is always the size and removes it immediately from argv (by decrementing argc), and tries to verify that it is a valid size only at a later point. So we do not actually know whether that last argument we called "size" is indeed a size or whether the user instead forgot to specify that size but did give a file name. Therefore, the error message should be more general. Bug: https://bugzilla.redhat.com/show_bug.cgi?id=3D1523458 Signed-off-by: Max Reitz Message-id: 20180205162745.23650-1-mreitz@redhat.com Reviewed-by: John Snow Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 56edc15218..aa99fd32e9 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3469,7 +3469,7 @@ static int img_resize(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit("Expecting image file name and size"); } filename =3D argv[optind++]; =20 --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018788663490.84864032374867; Fri, 2 Mar 2018 11:26:28 -0800 (PST) Received: from localhost ([::1]:37067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqJw-0003l7-N4 for importer@patchew.org; Fri, 02 Mar 2018 14:26:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqr-00022E-Bx for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqq-0003Rr-F0 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:17 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47306 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqo-0003Oj-5i; Fri, 02 Mar 2018 13:56:14 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A90F47B4AD; Fri, 2 Mar 2018 18:56:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DC7CAB588; Fri, 2 Mar 2018 18:56:11 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:45 +0100 Message-Id: <20180302185448.6314-35-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:56:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:56:13 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 34/37] block/ssh: Pull ssh_grow_file() from ssh_create() 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, qemu-devel@nongnu.org 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" From: Max Reitz If we ever want to offer even rudimentary truncation functionality for ssh, we should put the respective code into a reusable function. Signed-off-by: Max Reitz Message-id: 20180214204915.7980-2-mreitz@redhat.com Reviewed-by: Eric Blake Reviewed-by: Richard W.M. Jones Signed-off-by: Max Reitz --- block/ssh.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 36d5d888d5..d6a68cb880 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -803,6 +803,26 @@ static int ssh_file_open(BlockDriverState *bs, QDict *= options, int bdrv_flags, return ret; } =20 +static int ssh_grow_file(BDRVSSHState *s, int64_t offset, Error **errp) +{ + ssize_t ret; + char c[1] =3D { '\0' }; + + /* offset must be strictly greater than the current size so we do + * not overwrite anything */ + assert(offset > 0 && offset > s->attrs.filesize); + + libssh2_sftp_seek64(s->sftp_handle, offset - 1); + ret =3D libssh2_sftp_write(s->sftp_handle, c, 1); + if (ret < 0) { + sftp_error_setg(errp, s, "Failed to grow file"); + return -EIO; + } + + s->attrs.filesize =3D offset; + return 0; +} + static QemuOptsList ssh_create_opts =3D { .name =3D "ssh-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(ssh_create_opts.head), @@ -823,8 +843,6 @@ static int coroutine_fn ssh_co_create_opts(const char *= filename, QemuOpts *opts, int64_t total_size =3D 0; QDict *uri_options =3D NULL; BDRVSSHState s; - ssize_t r2; - char c[1] =3D { '\0' }; =20 ssh_state_init(&s); =20 @@ -850,14 +868,10 @@ static int coroutine_fn ssh_co_create_opts(const char= *filename, QemuOpts *opts, } =20 if (total_size > 0) { - libssh2_sftp_seek64(s.sftp_handle, total_size-1); - r2 =3D libssh2_sftp_write(s.sftp_handle, c, 1); - if (r2 < 0) { - sftp_error_setg(errp, &s, "truncate failed"); - ret =3D -EINVAL; + ret =3D ssh_grow_file(&s, total_size, errp); + if (ret < 0) { goto out; } - s.attrs.filesize =3D total_size; } =20 ret =3D 0; --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520019067788804.2375059497556; Fri, 2 Mar 2018 11:31:07 -0800 (PST) Received: from localhost ([::1]:37102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqOY-0000WD-Ob for importer@patchew.org; Fri, 02 Mar 2018 14:31:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqs-00023P-NI for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqr-0003SR-Sn for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:18 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48036 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqp-0003RI-Ms; Fri, 02 Mar 2018 13:56:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AE1C8A3DD; Fri, 2 Mar 2018 18:56:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B02EAB583; Fri, 2 Mar 2018 18:56:13 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:46 +0100 Message-Id: <20180302185448.6314-36-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:56:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 02 Mar 2018 18:56:15 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 35/37] block/ssh: Make ssh_grow_file() blocking 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, qemu-devel@nongnu.org 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" From: Max Reitz At runtime (that is, during a future ssh_truncate()), the SSH session is non-blocking. However, ssh_truncate() (or rather, bdrv_truncate() in general) is not a coroutine, so this resize operation needs to block. For ssh_create(), that is fine, too; the session is never set to non-blocking anyway. Signed-off-by: Max Reitz Message-id: 20180214204915.7980-3-mreitz@redhat.com Reviewed-by: Eric Blake Reviewed-by: Richard W.M. Jones Signed-off-by: Max Reitz --- block/ssh.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/ssh.c b/block/ssh.c index d6a68cb880..4bcf10334f 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -803,17 +803,24 @@ static int ssh_file_open(BlockDriverState *bs, QDict = *options, int bdrv_flags, return ret; } =20 +/* Note: This is a blocking operation */ static int ssh_grow_file(BDRVSSHState *s, int64_t offset, Error **errp) { ssize_t ret; char c[1] =3D { '\0' }; + int was_blocking =3D libssh2_session_get_blocking(s->session); =20 /* offset must be strictly greater than the current size so we do * not overwrite anything */ assert(offset > 0 && offset > s->attrs.filesize); =20 + libssh2_session_set_blocking(s->session, 1); + libssh2_sftp_seek64(s->sftp_handle, offset - 1); ret =3D libssh2_sftp_write(s->sftp_handle, c, 1); + + libssh2_session_set_blocking(s->session, was_blocking); + if (ret < 0) { sftp_error_setg(errp, s, "Failed to grow file"); return -EIO; --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018943748651.4660662167366; Fri, 2 Mar 2018 11:29:03 -0800 (PST) Received: from localhost ([::1]:37088 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqMY-0006tI-UT for importer@patchew.org; Fri, 02 Mar 2018 14:29:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqx-00027U-Ji for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqw-0003Wu-QE for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:23 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60130 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqs-0003SV-8a; Fri, 02 Mar 2018 13:56:18 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF0214022909; Fri, 2 Mar 2018 18:56:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1EDF9C079; Fri, 2 Mar 2018 18:56:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:47 +0100 Message-Id: <20180302185448.6314-37-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:56:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:56:17 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 36/37] block/ssh: Add basic .bdrv_truncate() 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, qemu-devel@nongnu.org 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" From: Max Reitz libssh2 does not seem to offer real truncation support, so we can only grow files -- but that is better than nothing. Signed-off-by: Max Reitz Message-id: 20180214204915.7980-4-mreitz@redhat.com Reviewed-by: Eric Blake Reviewed-by: Richard W.M. Jones Signed-off-by: Max Reitz --- block/ssh.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block/ssh.c b/block/ssh.c index 4bcf10334f..80a8b40dfa 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1220,6 +1220,29 @@ static int64_t ssh_getlength(BlockDriverState *bs) return length; } =20 +static int ssh_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) +{ + BDRVSSHState *s =3D bs->opaque; + + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_str(prealloc)); + return -ENOTSUP; + } + + if (offset < s->attrs.filesize) { + error_setg(errp, "ssh driver does not support shrinking files"); + return -ENOTSUP; + } + + if (offset =3D=3D s->attrs.filesize) { + return 0; + } + + return ssh_grow_file(s, offset, errp); +} + static BlockDriver bdrv_ssh =3D { .format_name =3D "ssh", .protocol_name =3D "ssh", @@ -1232,6 +1255,7 @@ static BlockDriver bdrv_ssh =3D { .bdrv_co_readv =3D ssh_co_readv, .bdrv_co_writev =3D ssh_co_writev, .bdrv_getlength =3D ssh_getlength, + .bdrv_truncate =3D ssh_truncate, .bdrv_co_flush_to_disk =3D ssh_co_flush, .create_opts =3D &ssh_create_opts, }; --=20 2.13.6 From nobody Thu Dec 18 13:34:35 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520019120196575.4760539074018; Fri, 2 Mar 2018 11:32:00 -0800 (PST) Received: from localhost ([::1]:37103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqOl-0000eV-3l for importer@patchew.org; Fri, 02 Mar 2018 14:31:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpr1-0002AV-8s for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqz-0003Xq-Ra for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:27 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47314 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqw-0003WF-1m; Fri, 02 Mar 2018 13:56:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8892C7B4AD; Fri, 2 Mar 2018 18:56:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33B409C079; Fri, 2 Mar 2018 18:56:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:48 +0100 Message-Id: <20180302185448.6314-38-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:56:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:56:21 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 37/37] qcow2: Replace align_offset() with ROUND_UP() 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Alberto Garcia The align_offset() function is equivalent to the ROUND_UP() macro so there's no need to use the former. The ROUND_UP() name is also a bit more explicit. This patch uses ROUND_UP() instead of the slower QEMU_ALIGN_UP() because align_offset() already requires that the second parameter is a power of two. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20180215131008.5153-1-berto@igalia.com Signed-off-by: Max Reitz --- block/qcow2.h | 6 ------ block/qcow2-bitmap.c | 4 ++-- block/qcow2-cluster.c | 4 ++-- block/qcow2-refcount.c | 4 ++-- block/qcow2-snapshot.c | 10 +++++----- block/qcow2.c | 14 +++++++------- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 883802241f..1a84cc77b0 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -480,12 +480,6 @@ static inline int offset_to_l2_slice_index(BDRVQcow2St= ate *s, int64_t offset) return (offset >> s->cluster_bits) & (s->l2_slice_size - 1); } =20 -static inline int64_t align_offset(int64_t offset, int n) -{ - offset =3D (offset + n - 1) & ~(n - 1); - return offset; -} - static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s) { return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 4f6fd863ea..5127276f90 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -413,8 +413,8 @@ static inline void bitmap_dir_entry_to_be(Qcow2BitmapDi= rEntry *entry) =20 static inline int calc_dir_entry_size(size_t name_size, size_t extra_data_= size) { - return align_offset(sizeof(Qcow2BitmapDirEntry) + - name_size + extra_data_size, 8); + int size =3D sizeof(Qcow2BitmapDirEntry) + name_size + extra_data_size; + return ROUND_UP(size, 8); } =20 static inline int dir_entry_size(Qcow2BitmapDirEntry *entry) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e406b0f3b9..98908c4264 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -126,11 +126,11 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_= t min_size, =20 new_l1_size2 =3D sizeof(uint64_t) * new_l1_size; new_l1_table =3D qemu_try_blockalign(bs->file->bs, - align_offset(new_l1_size2, 512)); + ROUND_UP(new_l1_size2, 512)); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } - memset(new_l1_table, 0, align_offset(new_l1_size2, 512)); + memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512)); =20 if (s->l1_size) { memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index d46b69d7f3..126cca3276 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1204,7 +1204,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, * l1_table_offset when it is the current s->l1_table_offset! Be caref= ul * when changing this! */ if (l1_table_offset !=3D s->l1_table_offset) { - l1_table =3D g_try_malloc0(align_offset(l1_size2, 512)); + l1_table =3D g_try_malloc0(ROUND_UP(l1_size2, 512)); if (l1_size2 && l1_table =3D=3D NULL) { ret =3D -ENOMEM; goto fail; @@ -2553,7 +2553,7 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs= , int ign, int64_t offset, } =20 /* align range to test to cluster boundaries */ - size =3D align_offset(offset_into_cluster(s, offset) + size, s->cluste= r_size); + size =3D ROUND_UP(offset_into_cluster(s, offset) + size, s->cluster_si= ze); offset =3D start_of_cluster(s, offset); =20 if ((chk & QCOW2_OL_ACTIVE_L1) && s->l1_size) { diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 44243e0e95..cee25f582b 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -66,7 +66,7 @@ int qcow2_read_snapshots(BlockDriverState *bs) =20 for(i =3D 0; i < s->nb_snapshots; i++) { /* Read statically sized part of the snapshot header */ - offset =3D align_offset(offset, 8); + offset =3D ROUND_UP(offset, 8); ret =3D bdrv_pread(bs->file, offset, &h, sizeof(h)); if (ret < 0) { goto fail; @@ -155,7 +155,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) offset =3D 0; for(i =3D 0; i < s->nb_snapshots; i++) { sn =3D s->snapshots + i; - offset =3D align_offset(offset, 8); + offset =3D ROUND_UP(offset, 8); offset +=3D sizeof(h); offset +=3D sizeof(extra); offset +=3D strlen(sn->id_str); @@ -215,7 +215,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) assert(id_str_size <=3D UINT16_MAX && name_size <=3D UINT16_MAX); h.id_str_size =3D cpu_to_be16(id_str_size); h.name_size =3D cpu_to_be16(name_size); - offset =3D align_offset(offset, 8); + offset =3D ROUND_UP(offset, 8); =20 ret =3D bdrv_pwrite(bs->file, offset, &h, sizeof(h)); if (ret < 0) { @@ -441,7 +441,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSna= pshotInfo *sn_info) /* The VM state isn't needed any more in the active L1 table; in fact,= it * hurts by causing expensive COW for the next snapshot. */ qcow2_cluster_discard(bs, qcow2_vm_state_offset(s), - align_offset(sn->vm_state_size, s->cluster_size), + ROUND_UP(sn->vm_state_size, s->cluster_size), QCOW2_DISCARD_NEVER, false); =20 #ifdef DEBUG_ALLOC @@ -710,7 +710,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, } new_l1_bytes =3D sn->l1_size * sizeof(uint64_t); new_l1_table =3D qemu_try_blockalign(bs->file->bs, - align_offset(new_l1_bytes, 512)); + ROUND_UP(new_l1_bytes, 512)); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } diff --git a/block/qcow2.c b/block/qcow2.c index 7cf3c1518a..0397506b39 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1379,7 +1379,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, =20 if (s->l1_size > 0) { s->l1_table =3D qemu_try_blockalign(bs->file->bs, - align_offset(s->l1_size * sizeof(uint64_t), 512)); + ROUND_UP(s->l1_size * sizeof(uint64_t), 512)); if (s->l1_table =3D=3D NULL) { error_setg(errp, "Could not allocate L1 table"); ret =3D -ENOMEM; @@ -2642,19 +2642,19 @@ static int64_t qcow2_calc_prealloc_size(int64_t tot= al_size, { int64_t meta_size =3D 0; uint64_t nl1e, nl2e; - int64_t aligned_total_size =3D align_offset(total_size, cluster_size); + int64_t aligned_total_size =3D ROUND_UP(total_size, cluster_size); =20 /* header: 1 cluster */ meta_size +=3D cluster_size; =20 /* total size of L2 tables */ nl2e =3D aligned_total_size / cluster_size; - nl2e =3D align_offset(nl2e, cluster_size / sizeof(uint64_t)); + nl2e =3D ROUND_UP(nl2e, cluster_size / sizeof(uint64_t)); meta_size +=3D nl2e * sizeof(uint64_t); =20 /* total size of L1 tables */ nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; - nl1e =3D align_offset(nl1e, cluster_size / sizeof(uint64_t)); + nl1e =3D ROUND_UP(nl1e, cluster_size / sizeof(uint64_t)); meta_size +=3D nl1e * sizeof(uint64_t); =20 /* total size of refcount table and blocks */ @@ -3710,8 +3710,8 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, has_backing_file =3D !!optstr; g_free(optstr); =20 - virtual_size =3D align_offset(qemu_opt_get_size_del(opts, BLOCK_OPT_SI= ZE, 0), - cluster_size); + virtual_size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + virtual_size =3D ROUND_UP(virtual_size, cluster_size); =20 /* Check that virtual disk size is valid */ l2_tables =3D DIV_ROUND_UP(virtual_size / cluster_size, @@ -3731,7 +3731,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, goto err; } =20 - virtual_size =3D align_offset(ssize, cluster_size); + virtual_size =3D ROUND_UP(ssize, cluster_size); =20 if (has_backing_file) { /* We don't how much of the backing chain is shared by the inp= ut --=20 2.13.6