From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 150783489887152.42123903624133; Thu, 12 Oct 2017 12:01:38 -0700 (PDT) Received: from localhost ([::1]:46838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ijZ-00042V-Uz for importer@patchew.org; Thu, 12 Oct 2017 15:01:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ii8-00034t-4A for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:00:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ii6-00061G-Rv for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:00:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ii1-0005vK-Pf; Thu, 12 Oct 2017 14:59:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8D752D0FB7; Thu, 12 Oct 2017 18:59:52 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 246C66063B; Thu, 12 Oct 2017 18:59:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8D752D0FB7 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:58:57 -0500 Message-Id: <20171012185916.22776-2-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 12 Oct 2017 18:59:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 01/20] 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, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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 old code now uses a goto in order to minimize churn at that later removal. Update documentation in this patch so that the later removal can be a straight delete. 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 (mapping is false), rather than full details about runs of zeroes and which offsets the allocation actually maps to (mapping is true). Note that most drivers give sector-aligned answers, except at end-of-file, even when request_alignment is smaller than a sector. However, bdrv_getlength() is sector-aligned (even though it gives a byte answer), often by exceeding the actual file size. If we were to give back strict results, at least file-posix.c would report a transition from DATA to HOLE at the end of a file even in the middle of a sector, which can throw off callers; so we intentionally lie and state that any partial sector at the end of a file has the same status for the entire sector. Maybe at some future day we can report actual file size instead of rounding up, but not for this series. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: rebase to master v3: no change v2: improve alignment handling, ensure all iotests still pass --- include/block/block.h | 9 ++++----- include/block/block_int.h | 12 +++++++++--- block/io.c | 30 +++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index fbc21daf62..c5d6b2c933 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -136,11 +136,10 @@ typedef struct HDGeometry { * that the block layer recompute the answer from the retu= rned * BDS; must be accompanied by just BDRV_BLOCK_OFFSET_VALI= D. * - * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK) 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 4b9b23a08d..4153cd646d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -206,13 +206,19 @@ struct BlockDriver { * 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. + * for the meaning of _DATA, _ZERO, and _OFFSET_VALID. As a hint, + * the flag want_zero is true if the caller cares more about + * precise mappings (favor _OFFSET_VALID/_ZERO) or false for + * overall allocation (favor larger *pnum). The block layer + * guarantees input aligned to request_alignment, as well as + * non-NULL pnum, map, and file. */ 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 *bd, + bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file); /* * Invalidate any cached meta-data. diff --git a/block/io.c b/block/io.c index e4caa4acf1..ef9ea44667 100644 --- a/block/io.c +++ b/block/io.c @@ -1843,7 +1843,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, bytes =3D n; } - 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) { @@ -1860,13 +1860,14 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, bdrv_inc_in_flight(bs); /* Round out to request_alignment boundaries */ - /* TODO: until we have a byte-based driver callback, we also have to - * round out to sectors, even if that is bigger than request_alignment= */ - align =3D MAX(bs->bl.request_alignment, BDRV_SECTOR_SIZE); + 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; - { + if (bs->drv->bdrv_co_get_block_status) { int count; /* sectors */ int64_t longret; @@ -1891,8 +1892,27 @@ static int coroutine_fn bdrv_co_block_status(BlockDr= iverState *bs, } ret =3D longret & ~BDRV_BLOCK_OFFSET_MASK; *pnum =3D count * BDRV_SECTOR_SIZE; + goto refine; } + 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; + } + + /* + * total_size is always sector-aligned, by sometimes exceeding actual + * file size. Expand pnum if it lands mid-sector due to end-of-file. + */ + if (QEMU_ALIGN_UP(*pnum + aligned_offset, + BDRV_SECTOR_SIZE) =3D=3D total_size) { + *pnum =3D total_size - aligned_offset; + } + +refine: /* * The driver's result must be a multiple of request_alignment. * Clamp pnum and adjust map to original request. --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150783498311348.173039526268326; Thu, 12 Oct 2017 12:03:03 -0700 (PDT) Received: from localhost ([::1]:46843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iky-00057o-CW for importer@patchew.org; Thu, 12 Oct 2017 15:02:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iiY-0003Uo-Kb for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:00:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2iiU-0006Vu-9I for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:00:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2iiM-0006N2-0n; Thu, 12 Oct 2017 15:00:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E923D3E2D4; Thu, 12 Oct 2017 19:00:12 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AA846063B; Thu, 12 Oct 2017 18:59:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E923D3E2D4 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:58:58 -0500 Message-Id: <20171012185916.22776-3-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 19:00:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 02/20] 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, famz@redhat.com, qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Update the generic helpers, and all passthrough clients (blkdebug, commit, mirror, throttle) accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: rebase to interface tweak v3: rebase to addition of throttle driver v2: rebase to master, retitle while merging blkdebug, commit, and mirror --- include/block/block_int.h | 28 ++++++++++++++++------------ block/io.c | 36 ++++++++++++++++++++---------------- block/blkdebug.c | 20 +++++++++++--------- block/commit.c | 2 +- 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 4153cd646d..7c8503f693 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1018,23 +1018,27 @@ void bdrv_format_default_perms(BlockDriverState *bs= , BdrvChild *c, uint64_t *nperm, uint64_t *nshared); /* - * 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/io.c b/block/io.c index ef9ea44667..6a2a2e1484 100644 --- a/block/io.c +++ b/block/io.c @@ -1754,30 +1754,34 @@ typedef struct BdrvCoBlockStatusData { bool done; } BdrvCoBlockStatusData; -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; } -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; } /* diff --git a/block/blkdebug.c b/block/blkdebug.c index e21669979d..82c30357f8 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); } -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); } 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, .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 5036eec434..ec0511bac7 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/mirror.c b/block/mirror.c index 307b6391a8..79739d063e 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 5bca76300f..76cd963a8c 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -224,7 +224,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, .is_filter =3D true, }; --=20 2.13.6 From nobody Sun Oct 5 17:18:03 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835154672218.59612717107382; Thu, 12 Oct 2017 12:05:54 -0700 (PDT) Received: from localhost ([::1]:46853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2inZ-0006yp-Kb for importer@patchew.org; Thu, 12 Oct 2017 15:05:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iit-0003jD-Of for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:00:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2iis-0006oA-MI for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:00:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2iin-0006kb-DJ; Thu, 12 Oct 2017 15:00:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51386C005F79; Thu, 12 Oct 2017 19:00:40 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52F1578378; Thu, 12 Oct 2017 19:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51386C005F79 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:58:59 -0500 Message-Id: <20171012185916.22776-4-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 12 Oct 2017 19:00:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 03/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: tweak commit message [Fam], rebase to interface tweak v3: no change v2: tweak comment, add mapping support --- block/file-posix.c | 59 +++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 36ee89e940..536cd1db03 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2128,24 +2128,26 @@ static int find_allocation(BlockDriverState *bs, of= f_t start, } /* - * 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 + * If 'offset' is beyond the end of the disk image the return value is 0 * and 'pnum' is set to 0. * - * 'pnum' is set to the number of sectors (including and immediately follo= wing - * the specified sector) that are known to be in the same + * '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 + * 'bytes' is the max value 'pnum' should be set to. If bytes goes * beyond the end of the disk image it will be clamped. */ -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) +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 start, data =3D 0, hole =3D 0; + off_t data =3D 0, hole =3D 0; int64_t total_size; int ret; @@ -2154,39 +2156,46 @@ static int64_t coroutine_fn raw_co_get_block_status= (BlockDriverState *bs, return ret; } - 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) { + } else if (offset >=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); + } else if (offset + bytes > total_size) { + bytes =3D total_size - offset; } - ret =3D find_allocation(bs, start, &data, &hole); + if (!want_zero) { + *pnum =3D bytes; + *map =3D offset; + *file =3D bs; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + } + + 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; } static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs, @@ -2280,7 +2289,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, .bdrv_co_preadv =3D raw_co_preadv, --=20 2.13.6 From nobody Sun Oct 5 17:18:03 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835022148825.3188029187129; Thu, 12 Oct 2017 12:03:42 -0700 (PDT) Received: from localhost ([::1]:46845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ilS-0005P0-7S for importer@patchew.org; Thu, 12 Oct 2017 15:03:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ik0-0004bE-J5 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ijy-0007jM-Uq for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:01:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ijq-0007eB-Qu; Thu, 12 Oct 2017 15:01:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C336F7EBD6; Thu, 12 Oct 2017 19:01:45 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B1977836F; Thu, 12 Oct 2017 19:00:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C336F7EBD6 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:00 -0500 Message-Id: <20171012185916.22776-5-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 19:01:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 04/20] 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, famz@redhat.com, qemu-block@nongnu.org, Jeff Cody , Max Reitz , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: tweak commit message [Fam], rebase to interface tweak v3: no change v2: tweak comments [Prasanna], add mapping, drop R-b --- block/gluster.c | 67 +++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 0f4265a3a4..518f1984de 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1349,26 +1349,30 @@ exit: } /* - * 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 + * If 'offset' is beyond the end of the disk image the return value is 0 * and 'pnum' is set to 0. * - * 'pnum' is set to the number of sectors (including and immediately follo= wing - * the specified sector) that are known to be in the same + * '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 + * 'bytes' is the max value 'pnum' should be set to. If bytes goes * beyond the end of the disk image it will be clamped. * - * (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; + off_t data =3D 0, hole =3D 0; int64_t total_size; int ret =3D -EINVAL; @@ -1376,41 +1380,48 @@ static int64_t coroutine_fn qemu_gluster_co_get_blo= ck_status( return ret; } - 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) { + } else if (offset >=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); + } else if (offset + bytes > total_size) { + bytes =3D total_size - offset; } - ret =3D find_allocation(bs, start, &data, &hole); + if (!want_zero) { + *pnum =3D bytes; + *map =3D offset; + *file =3D bs; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + } + + 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; } @@ -1438,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, }; @@ -1466,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, }; @@ -1494,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, }; @@ -1528,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 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835185698853.2304237457358; Thu, 12 Oct 2017 12:06:25 -0700 (PDT) Received: from localhost ([::1]:46859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2io8-0007XR-6t for importer@patchew.org; Thu, 12 Oct 2017 15:06:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ikM-0004w1-Er for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ikL-00086u-5q for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ikF-0007xr-S0; Thu, 12 Oct 2017 15:02:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC22A2D1EC0; Thu, 12 Oct 2017 19:02:10 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1123B60841; Thu, 12 Oct 2017 19:01:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC22A2D1EC0 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:01 -0500 Message-Id: <20171012185916.22776-6-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 12 Oct 2017 19:02:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 05/20] 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, famz@redhat.com, qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert all uses of the cluster size in sectors, along with adding assertions that we are not dividing by zero. Signed-off-by: Eric Blake Acked-by: Paolo Bonzini --- v2: no change --- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 4683f3b244..8f903d8370 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -84,7 +84,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; @@ -427,9 +427,10 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, int= open_flags) { iscsi_allocmap_free(iscsilun); + 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); iscsilun->allocmap =3D bitmap_try_new(iscsilun->allocmap_size); if (!iscsilun->allocmap) { @@ -437,7 +438,7 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, int = open_flags) } 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; @@ -458,17 +459,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; 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); @@ -532,9 +535,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); } static inline bool iscsi_allocmap_is_valid(IscsiLun *iscsilun, @@ -544,9 +550,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); } static int coroutine_fn @@ -781,16 +790,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; } @@ -1930,8 +1944,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); } @@ -2137,7 +2151,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->can_write_zeroes_with_unmap =3D iscsilun->lbprz && iscsilun->lbp.= lbpws; - bdi->cluster_size =3D iscsilun->cluster_sectors * BDRV_SECTOR_SIZE; + bdi->cluster_size =3D iscsilun->cluster_size; return 0; } --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835086196759.1193833064618; Thu, 12 Oct 2017 12:04:46 -0700 (PDT) Received: from localhost ([::1]:46849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ima-0006EV-2u for importer@patchew.org; Thu, 12 Oct 2017 15:04:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iku-0005H2-8b for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2iks-0000Y6-US for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ikn-0000Ri-OC; Thu, 12 Oct 2017 15:02:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0BB5780C1; Thu, 12 Oct 2017 19:02:44 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 158EB614E7; Thu, 12 Oct 2017 19:02:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B0BB5780C1 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:02 -0500 Message-Id: <20171012185916.22776-7-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 19:02:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 06/20] 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, famz@redhat.com, qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert 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 --- v2: rebase to count/bytes rename --- block/iscsi.c | 90 +++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 8f903d8370..4896d50d6e 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -455,24 +455,22 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, in= t open_flags) } 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; 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_siz= e) + - cl_num_expanded; /* 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 { @@ -495,26 +493,26 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sec= tor_num, } 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); } 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); } -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); } static void iscsi_allocmap_invalidate(IscsiLun *iscsilun) @@ -528,34 +526,30 @@ static void iscsi_allocmap_invalidate(IscsiLun *iscsi= lun) } 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); } 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); } static int coroutine_fn @@ -637,12 +631,14 @@ retry: } 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); r =3D iTask.err_code; goto out_unlock; } - iscsi_allocmap_set_allocated(iscsilun, sector_num, nb_sectors); + iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -737,9 +733,11 @@ retry: } 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); } if (*pnum > nb_sectors) { @@ -777,15 +775,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; } 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 @@ -1154,8 +1156,7 @@ retry: goto out_unlock; } - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -1253,18 +1254,15 @@ retry: } 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); r =3D iTask.err_code; goto out_unlock; } 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); } out_unlock: --=20 2.13.6 From nobody Sun Oct 5 17:18:03 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835299821643.8574995064195; Thu, 12 Oct 2017 12:08:19 -0700 (PDT) Received: from localhost ([::1]:46869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ipx-0000mz-2l for importer@patchew.org; Thu, 12 Oct 2017 15:08:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ilB-0005VI-Tc for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:03:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ilA-00015F-Jf for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:03:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2il2-0000iU-IK; Thu, 12 Oct 2017 15:03:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89B102D0FA7; Thu, 12 Oct 2017 19:02:59 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF34C53CF5; Thu, 12 Oct 2017 19:02:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89B102D0FA7 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:03 -0500 Message-Id: <20171012185916.22776-8-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 12 Oct 2017 19:02:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 07/20] 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, famz@redhat.com, qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Eric Blake Acked-by: Paolo Bonzini --- v4: rebase to interface tweaks v3: no change v2: rebase to mapping parameter --- block/iscsi.c | 64 +++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 4896d50d6e..cb30e9652c 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -647,28 +647,31 @@ out_unlock: -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; - int64_t ret; + int ret; iscsi_co_init_iscsitask(iscsilun, &iTask); - if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { + if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) { ret =3D -EINVAL; goto out; } /* 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; /* LUN does not support logical block provisioning */ if (!iscsilun->lbpme) { @@ -678,7 +681,7 @@ static int64_t coroutine_fn iscsi_co_get_block_status(B= lockDriverState *bs, qemu_mutex_lock(&iscsilun->mutex); retry: if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun, - sector_qemu2lun(sector_num, iscsilun), + offset / iscsilun->block_size, 8 + 16, iscsi_co_generic_cb, &iTask) =3D=3D NULL) { ret =3D -ENOMEM; @@ -717,12 +720,12 @@ retry: lbasd =3D &lbas->descriptors[0]; - if (sector_qemu2lun(sector_num, iscsilun) !=3D lbasd->lba) { + if (offset / iscsilun->block_size !=3D lbasd->lba) { ret =3D -EIO; goto out_unlock; } - *pnum =3D sector_lun2qemu(lbasd->num_blocks, iscsilun); + *pnum =3D lbasd->num_blocks * iscsilun->block_size; if (lbasd->provisioning =3D=3D SCSI_PROVISIONING_TYPE_DEALLOCATED || lbasd->provisioning =3D=3D SCSI_PROVISIONING_TYPE_ANCHORED) { @@ -733,15 +736,13 @@ retry: } 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); } - if (*pnum > nb_sectors) { - *pnum =3D nb_sectors; + if (*pnum > bytes) { + *pnum =3D bytes; } out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -749,7 +750,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; @@ -788,25 +789,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; + int64_t head; + int 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); + assert(iscsilun->cluster_size); + head =3D (sector_num * BDRV_SECTOR_SIZE) % iscsilun->cluster_size; + ret =3D iscsi_co_block_status(bs, false, + 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; } @@ -2192,7 +2192,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_truncate =3D iscsi_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, - .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, @@ -2227,7 +2227,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_truncate =3D iscsi_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, - .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 Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835327743325.95839647025105; Thu, 12 Oct 2017 12:08:47 -0700 (PDT) Received: from localhost ([::1]:46872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iqQ-0001Am-Ow for importer@patchew.org; Thu, 12 Oct 2017 15:08:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ilh-0005tS-DP for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:03:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ilg-0001i5-MB for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:03:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45326) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ila-0001ay-0l; Thu, 12 Oct 2017 15:03:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DC8E7EAA5; Thu, 12 Oct 2017 19:03:33 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5A1253CF5; Thu, 12 Oct 2017 19:02:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0DC8E7EAA5 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:04 -0500 Message-Id: <20171012185916.22776-9-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 12 Oct 2017 19:03:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 08/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Update the null driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: rebase to interface tweak v3: no change v2: rebase to mapping parameter --- block/null.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block/null.c b/block/null.c index dd9c13f9ba..20c7eb0ee2 100644 --- a/block/null.c +++ b/block/null.c @@ -223,22 +223,23 @@ static int null_reopen_prepare(BDRVReopenState *reope= n_state, return 0; } -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; + int64_t ret =3D BDRV_BLOCK_OFFSET_VALID; - *pnum =3D nb_sectors; + *pnum =3D bytes; + *map =3D offset; *file =3D bs; 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; } 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, - .bdrv_co_get_block_status =3D null_co_get_block_status, + .bdrv_co_block_status =3D null_co_block_status, .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, - .bdrv_co_get_block_status =3D null_co_get_block_status, + .bdrv_co_block_status =3D null_co_block_status, .bdrv_refresh_filename =3D null_refresh_filename, }; --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835449844377.34782968918967; Thu, 12 Oct 2017 12:10:49 -0700 (PDT) Received: from localhost ([::1]:46890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2isU-00030x-TY for importer@patchew.org; Thu, 12 Oct 2017 15:10:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2im3-0006CU-Va for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:04:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2im2-0001wC-Vs for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:04:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ily-0001sN-17; Thu, 12 Oct 2017 15:03:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0827BC047B99; Thu, 12 Oct 2017 19:03:57 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B8A260841; Thu, 12 Oct 2017 19:03:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0827BC047B99 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:05 -0500 Message-Id: <20171012185916.22776-10-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 12 Oct 2017 19:03:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 09/20] 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, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , "Denis V. Lunev" , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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 --- v4: rebase to interface tweak, R-b dropped v3: no change v2: rebase to mapping parameter; it is ignored, so R-b kept --- block/parallels.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 2b6c6e5709..4a086f29e9 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -278,23 +278,31 @@ static coroutine_fn int parallels_co_flush_to_os(Bloc= kDriverState *bs) } -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; + 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); if (offset < 0) { return 0; } + *pnum =3D count * BDRV_SECTOR_SIZE; + *map =3D offset; *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; } static coroutine_fn int parallels_co_writev(BlockDriverState *bs, @@ -781,7 +789,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 Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150783518569437.24961318469457; Thu, 12 Oct 2017 12:06:25 -0700 (PDT) Received: from localhost ([::1]:46860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2io8-0007Xn-5H for importer@patchew.org; Thu, 12 Oct 2017 15:06:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2imB-0006IL-KP for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:04:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2im8-0001xm-BI for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:04:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48346) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2im5-0001wY-Df; Thu, 12 Oct 2017 15:04:05 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70D87C059B8E; Thu, 12 Oct 2017 19:04:04 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 155627838F; Thu, 12 Oct 2017 19:03:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 70D87C059B8E Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:06 -0500 Message-Id: <20171012185916.22776-11-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 12 Oct 2017 19:04:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 10/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually 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 --- v4: rebase to interface tweak v3: rebase to master v2: rebase to mapping flag --- block/qcow.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 9569deeaf0..f09661dc0c 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -513,23 +513,28 @@ static int get_cluster_offset(BlockDriverState *bs, return 1; } -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; 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; @@ -537,9 +542,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; } static int decompress_buffer(uint8_t *out_buf, int out_buf_size, @@ -1111,7 +1116,7 @@ static BlockDriver bdrv_qcow =3D { .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, .bdrv_make_empty =3D qcow_make_empty, .bdrv_co_pwritev_compressed =3D qcow_co_pwritev_compressed, --=20 2.13.6 From nobody Sun Oct 5 17:18:03 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835499777465.0793460832557; Thu, 12 Oct 2017 12:11:39 -0700 (PDT) Received: from localhost ([::1]:46891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2it8-0003Zx-Ph for importer@patchew.org; Thu, 12 Oct 2017 15:11:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2imf-0006gW-6w for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:04:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ime-0002Dl-5w for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:04:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29553) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2imZ-0002Ac-ES; Thu, 12 Oct 2017 15:04:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78B52D7E79; Thu, 12 Oct 2017 19:04:34 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE8397835E; Thu, 12 Oct 2017 19:04:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 78B52D7E79 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:07 -0500 Message-Id: <20171012185916.22776-12-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 12 Oct 2017 19:04:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 11/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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 --- v4: update to interface tweak v3: no change v2: rebase to mapping flag --- block/qcow2.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 92cb9f9bfa..a84e50a6e6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1625,32 +1625,34 @@ static void qcow2_join_options(QDict *options, QDic= t *old_options) } } -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; - 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; } - *pnum =3D bytes >> BDRV_SECTOR_BITS; + *pnum =3D bytes; 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; @@ -4333,7 +4335,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, .bdrv_co_preadv =3D qcow2_co_preadv, .bdrv_co_pwritev =3D qcow2_co_pwritev, --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835345723568.2899042650537; Thu, 12 Oct 2017 12:09:05 -0700 (PDT) Received: from localhost ([::1]:46873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iqo-0001UQ-Uq for importer@patchew.org; Thu, 12 Oct 2017 15:08:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2imz-0006tZ-1A for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2imy-0002X3-4l for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2imt-0002MP-1K; Thu, 12 Oct 2017 15:04:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E0D9780E7; Thu, 12 Oct 2017 19:04:54 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id B74D378405; Thu, 12 Oct 2017 19:04:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1E0D9780E7 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:08 -0500 Message-Id: <20171012185916.22776-13-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 19:04:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 12/20] 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, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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 --- v4: rebase to interface change, inline pointless callback v3: no change v2: rebase to mapping flag, fix mask in qed_is_allocated_cb --- block/qed.c | 84 +++++++++++++++++++++------------------------------------= ---- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/block/qed.c b/block/qed.c index 28e2ec89e8..cbab5b6f83 100644 --- a/block/qed.c +++ b/block/qed.c @@ -688,74 +688,46 @@ finish: return ret; } -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) -{ - QEDIsAllocatedCB *cb =3D opaque; - BDRVQEDState *s =3D cb->bs->opaque; - *cb->pnum =3D len / BDRV_SECTOR_SIZE; - 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; - break; - case QED_CLUSTER_ZERO: - cb->status =3D BDRV_BLOCK_ZERO; - break; - case QED_CLUSTER_L2: - case QED_CLUSTER_L1: - cb->status =3D 0; - break; - default: - assert(ret < 0); - cb->status =3D ret; - break; - } - - 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, +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) { 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, - }; + size_t len; + 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, cb.pos, &len, &offset); - qed_is_allocated_cb(&cb, ret, offset, len); + ret =3D qed_find_cluster(s, &request, pos, &len, &offset); - /* The callback was invoked immediately */ - assert(cb.status !=3D BDRV_BLOCK_OFFSET_MASK); + *pnum =3D len; + switch (ret) { + case QED_CLUSTER_FOUND: + *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: + status =3D BDRV_BLOCK_ZERO; + break; + case QED_CLUSTER_L2: + case QED_CLUSTER_L1: + status =3D 0; + break; + default: + assert(ret < 0); + status =3D ret; + break; + } qed_unref_l2_cache_entry(request.l2_table); qemu_co_mutex_unlock(&s->table_lock); - return cb.status; + return status; } static BDRVQEDState *acb_to_s(QEDAIOCB *acb) @@ -1595,7 +1567,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 Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835644139327.00920251666287; Thu, 12 Oct 2017 12:14:04 -0700 (PDT) Received: from localhost ([::1]:46905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ivY-0005uw-Ck for importer@patchew.org; Thu, 12 Oct 2017 15:13:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2inP-0007MI-T9 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2inO-0002wX-PF for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2inK-0002sK-1g; Thu, 12 Oct 2017 15:05:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2397E7EBDB; Thu, 12 Oct 2017 19:05:21 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96A28614CC; Thu, 12 Oct 2017 19:04:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2397E7EBDB Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:09 -0500 Message-Id: <20171012185916.22776-14-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 19:05:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 13/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Update the raw driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: rebase to interface tweak v3: no change v2: rebase to mapping --- 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; } -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; } 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 Sun Oct 5 17:18:03 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835507825960.3875192812309; Thu, 12 Oct 2017 12:11:47 -0700 (PDT) Received: from localhost ([::1]:46894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2itU-0003vg-Nx for importer@patchew.org; Thu, 12 Oct 2017 15:11:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ini-0007a4-76 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2inh-0003Bb-65 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2inb-00035a-M9; Thu, 12 Oct 2017 15:05:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A2FD81DE0; Thu, 12 Oct 2017 19:05:38 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B4C260633; Thu, 12 Oct 2017 19:05:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4A2FD81DE0 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:10 -0500 Message-Id: <20171012185916.22776-15-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 12 Oct 2017 19:05:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 14/20] 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, famz@redhat.com, qemu-block@nongnu.org, Hitoshi Mitake , Jeff Cody , Max Reitz , "open list:Sheepdog" , Liu Yuan , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- v4: update to interface tweak v3: no change v2: rebase to mapping flag --- block/sheepdog.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 696a71442a..0af8b07892 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2988,19 +2988,19 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverS= tate *bs, int64_t offset, return acb.ret; } -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; for (idx =3D start; idx < end; idx++) { if (inode->data_vdi_id[idx] =3D=3D 0) { @@ -3017,9 +3017,9 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t = sector_num, int nb_sectors, } } - *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; @@ -3097,7 +3097,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, .bdrv_snapshot_create =3D sd_snapshot_create, .bdrv_snapshot_goto =3D sd_snapshot_goto, @@ -3133,7 +3133,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, .bdrv_snapshot_create =3D sd_snapshot_create, .bdrv_snapshot_goto =3D sd_snapshot_goto, @@ -3169,7 +3169,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, .bdrv_snapshot_create =3D sd_snapshot_create, .bdrv_snapshot_goto =3D sd_snapshot_goto, --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835611596591.9430030028266; Thu, 12 Oct 2017 12:13:31 -0700 (PDT) Received: from localhost ([::1]:46904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iv9-0005ZF-K2 for importer@patchew.org; Thu, 12 Oct 2017 15:13:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2inq-0007gn-2d for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2inp-0003PH-0E for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:05:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ink-0003Gy-HW; Thu, 12 Oct 2017 15:05:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D8D1C9D34; Thu, 12 Oct 2017 19:05:47 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 873F060841; Thu, 12 Oct 2017 19:05:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9D8D1C9D34 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:11 -0500 Message-Id: <20171012185916.22776-16-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 12 Oct 2017 19:05:47 +0000 (UTC) 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: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 15/20] 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, famz@redhat.com, qemu-block@nongnu.org, Stefan Weil , Max Reitz , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- v2: no change --- block/vdi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 8da5dfc897..6f83221ddc 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -86,12 +86,18 @@ #define DEFAULT_CLUSTER_SIZE (1 * MiB) #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 +#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 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835768479177.4903975222095; Thu, 12 Oct 2017 12:16:08 -0700 (PDT) Received: from localhost ([::1]:46927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ixb-0007tA-Nr for importer@patchew.org; Thu, 12 Oct 2017 15:15:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2io2-0007s3-Dg for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2io1-0003Yk-Cb for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52554) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2inv-0003Uz-Kk; Thu, 12 Oct 2017 15:05:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADF305F2981; Thu, 12 Oct 2017 19:05:58 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCD4460841; Thu, 12 Oct 2017 19:05:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ADF305F2981 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:12 -0500 Message-Id: <20171012185916.22776-17-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 12 Oct 2017 19:05:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 16/20] 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, famz@redhat.com, qemu-block@nongnu.org, Stefan Weil , Max Reitz , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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 --- v4: rebase to interface tweak v3: no change v2: rebase to mapping flag --- block/vdi.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 6f83221ddc..b30886823d 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -171,8 +171,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). */ @@ -462,7 +460,6 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, bs->total_sectors =3D header.disk_size / SECTOR_SIZE; 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; @@ -508,33 +505,29 @@ static int vdi_reopen_prepare(BDRVReopenState *state, return 0; } -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; - 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, bytes); result =3D VDI_IS_ALLOCATED(bmap_entry); if (!result) { return 0; } - 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; } static int coroutine_fn @@ -902,7 +895,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, .bdrv_co_preadv =3D vdi_co_preadv, --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835673969207.95198471701315; Thu, 12 Oct 2017 12:14:33 -0700 (PDT) Received: from localhost ([::1]:46907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iw8-0006NC-4S for importer@patchew.org; Thu, 12 Oct 2017 15:14:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ioC-00080Y-7y for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ioB-0003lj-9N for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2io6-0003a5-Hq; Thu, 12 Oct 2017 15:06:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AAC547F403; Thu, 12 Oct 2017 19:06:09 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6188614CB; Thu, 12 Oct 2017 19:05:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AAC547F403 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:13 -0500 Message-Id: <20171012185916.22776-18-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 12 Oct 2017 19:06:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 17/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Update the vmdk driver accordingly. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v4: rebase to interface tweak v3: no change v2: rebase to mapping flag --- block/vmdk.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index c665bcc977..624b5c296a 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1303,25 +1303,27 @@ static inline uint64_t vmdk_find_index_in_cluster(V= mdkExtent *extent, 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; - extent =3D find_extent(s, sector_num, NULL); + extent =3D find_extent(s, offset >> BDRV_SECTOR_BITS, NULL); if (!extent) { return 0; } 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); - 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; @@ -1336,18 +1338,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; } - 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; } @@ -2393,7 +2391,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 Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835863238838.5217678410789; Thu, 12 Oct 2017 12:17:43 -0700 (PDT) Received: from localhost ([::1]:46934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iz6-0000do-Pq for importer@patchew.org; Thu, 12 Oct 2017 15:17:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ioM-00087n-Ai for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ioL-0003rs-90 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ioG-0003qd-Cq; Thu, 12 Oct 2017 15:06:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75CFA806B3; Thu, 12 Oct 2017 19:06:19 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3A955C682; Thu, 12 Oct 2017 19:06:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 75CFA806B3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:14 -0500 Message-Id: <20171012185916.22776-19-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 12 Oct 2017 19:06:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 18/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Update the vpc driver accordingly. Drop the now-unused get_sector_offset(). Signed-off-by: Eric Blake --- v4: rebase to interface tweak v3: rebase to master v2: drop get_sector_offset() [Kevin], rebase to mapping flag --- block/vpc.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 1576d7b595..4100ce1ed3 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -705,52 +705,54 @@ fail: return ret; } -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 start, image_offset; bool allocated; - int64_t ret; + int ret; int n; 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; } qemu_co_mutex_lock(&s->lock); - 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); + start =3D image_offset & BDRV_BLOCK_OFFSET_MASK; + allocated =3D (image_offset !=3D -1); *pnum =3D 0; ret =3D 0; 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); *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 start; + 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); + image_offset =3D get_image_offset(bs, offset, false, NULL); } while (offset =3D=3D -1); qemu_co_mutex_unlock(&s->lock); @@ -1097,7 +1099,7 @@ static BlockDriver bdrv_vpc =3D { .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, .bdrv_get_info =3D vpc_get_info, --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507835506985284.75901870796713; Thu, 12 Oct 2017 12:11:46 -0700 (PDT) Received: from localhost ([::1]:46892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2itI-0003iE-17 for importer@patchew.org; Thu, 12 Oct 2017 15:11:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ioV-0008GA-7Y for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ioU-0003vI-D9 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ioQ-0003ta-CG; Thu, 12 Oct 2017 15:06:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58FFD7E38C; Thu, 12 Oct 2017 19:06:29 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE9DB53CE0; Thu, 12 Oct 2017 19:06:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 58FFD7E38C Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:15 -0500 Message-Id: <20171012185916.22776-20-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 12 Oct 2017 19:06:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 19/20] 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, jsnow@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually 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 --- v4: rebase to interface tweak v3: no change v2: rebase to earlier changes, simplify --- block/vvfat.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index a0f2335894..9142117fc6 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3082,15 +3082,13 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t off= set, uint64_t bytes, return ret; } -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; } @@ -3251,7 +3249,7 @@ static BlockDriver bdrv_vvfat =3D { .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, }; static void bdrv_vvfat_init(void) --=20 2.13.6 From nobody Sun Oct 5 17:18:03 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15078357802681022.6368552216442; Thu, 12 Oct 2017 12:16:20 -0700 (PDT) Received: from localhost ([::1]:46928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ixq-00086T-H4 for importer@patchew.org; Thu, 12 Oct 2017 15:16:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ioi-000094-Tx for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ioh-0003zd-S7 for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:06:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2iod-0003y3-2n; Thu, 12 Oct 2017 15:06:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B47AD77FE; Thu, 12 Oct 2017 19:06:42 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92EDD6063A; Thu, 12 Oct 2017 19:06:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B47AD77FE Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:16 -0500 Message-Id: <20171012185916.22776-21-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 12 Oct 2017 19:06:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 20/20] 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, famz@redhat.com, qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. 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 --- v4: rebase to interface tweak v3: no change v2: rebase to earlier changes --- include/block/block_int.h | 3 --- block/io.c | 34 +--------------------------------- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 7c8503f693..6e7ae5fc8d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -213,9 +213,6 @@ struct BlockDriver { * guarantees input aligned to request_alignment, as well as * non-NULL pnum, map, and file. */ - 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 *bd, 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 6a2a2e1484..7ae4cdadf5 100644 --- a/block/io.c +++ b/block/io.c @@ -1847,7 +1847,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, bytes =3D n; } - 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) { @@ -1865,40 +1865,9 @@ static int coroutine_fn bdrv_co_block_status(BlockDr= iverState *bs, /* 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; - 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; - goto refine; - } - ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offset, aligned_bytes, pnum, &local_map, &local_file); @@ -1916,7 +1885,6 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, *pnum =3D total_size - aligned_offset; } -refine: /* * The driver's result must be a multiple of request_alignment. * Clamp pnum and adjust map to original request. --=20 2.13.6