From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500034645801566.9701418098709; Fri, 14 Jul 2017 05:17:25 -0700 (PDT) Received: from localhost ([::1]:37678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzX6-0005Lx-Ch for importer@patchew.org; Fri, 14 Jul 2017 08:17:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzV9-0003S2-KZ for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzV8-0003fM-AP for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37913) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzV5-0003d8-81; Fri, 14 Jul 2017 08:15:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46AD765871; Fri, 14 Jul 2017 12:15:14 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 151386E911; Fri, 14 Jul 2017 12:15:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 46AD765871 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=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 46AD765871 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:38 -0500 Message-Id: <20170714121457.10322-2-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 14 Jul 2017 12:15:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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. The new code also passes through the 'mapping' hint, which will allow subsequent patches to further optimize callers that only care about how much of the image is allocated, rather than which offsets the allocation actually maps to. 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. Signed-off-by: Eric Blake --- v2: improve alignment handling, ensure all iotests still pass --- include/block/block_int.h | 11 ++++++++--- block/io.c | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index f2c1da7..aeb2bf8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -176,13 +176,18 @@ 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 mapping is true if the caller cares more about precise + * mappings (favor _OFFSET_VALID) or false for overall allocation + * (favor larger *pnum). The block layer guarantees input aligned + * to request_alignment, as well as non-NULL pnum and file. */ int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file); + int64_t coroutine_fn (*bdrv_co_block_status)(BlockDriverState *bd, + bool mapping, int64_t offset, int64_t bytes, int64_t *pnum, + BlockDriverState **file); /* * Invalidate any cached meta-data. diff --git a/block/io.c b/block/io.c index 0e4a3e6..899a7b3 100644 --- a/block/io.c +++ b/block/io.c @@ -1770,7 +1770,7 @@ static int64_t coroutine_fn bdrv_co_block_status(Bloc= kDriverState *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) { @@ -1790,11 +1790,14 @@ static int64_t coroutine_fn bdrv_co_block_status(Bl= ockDriverState *bs, bdrv_inc_in_flight(bs); /* Round out to request_alignment boundaries */ - 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 */ assert(QEMU_IS_ALIGNED(aligned_offset | aligned_bytes, @@ -1808,8 +1811,26 @@ static int64_t coroutine_fn bdrv_co_block_status(Blo= ckDriverState *bs, goto out; } *pnum =3D count * BDRV_SECTOR_SIZE; + goto refine; } + ret =3D bs->drv->bdrv_co_block_status(bs, mapping, aligned_offset, + aligned_bytes, pnum, &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: /* Clamp pnum and ret to original request */ assert(QEMU_IS_ALIGNED(*pnum, align)); *pnum -=3D offset - aligned_offset; --=20 2.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500034797794288.8090030088896; Fri, 14 Jul 2017 05:19:57 -0700 (PDT) Received: from localhost ([::1]:37693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzZc-0000Be-9Y for importer@patchew.org; Fri, 14 Jul 2017 08:19:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVE-0003Zc-FB for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVD-0003i5-6F for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzV7-0003ec-D5; Fri, 14 Jul 2017 08:15:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FBEBC045751; Fri, 14 Jul 2017 12:15:16 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89CF677650; Fri, 14 Jul 2017 12:15:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6FBEBC045751 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6FBEBC045751 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:39 -0500 Message-Id: <20170714121457.10322-3-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Jul 2017 12:15:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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) accordingly. Signed-off-by: Eric Blake --- v2: rebase to master, retitle while merging blkdebug, commit, and mirror --- include/block/block_int.h | 26 ++++++++++++++------------ block/io.c | 30 ++++++++++++++++-------------- block/blkdebug.c | 19 ++++++++++--------- block/commit.c | 2 +- block/mirror.c | 2 +- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index aeb2bf8..72b8b81 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -973,23 +973,25 @@ 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); +int64_t coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, + int64_t *pnum, + BlockDriverState **fil= e); /* - * 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); +int64_t coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *b= s, + bool mapping, + int64_t offset, + int64_t bytes, + int64_t *pnum, + 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 899a7b3..2e8ddd7 100644 --- a/block/io.c +++ b/block/io.c @@ -1684,30 +1684,32 @@ 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) +int64_t coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, + int64_t *pnum, + BlockDriverState **fil= e) { assert(bs->file && bs->file->bs); - *pnum =3D nb_sectors; + *pnum =3D bytes; *file =3D bs->file->bs; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } -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) +int64_t coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *b= s, + bool mapping, + int64_t offset, + int64_t bytes, + int64_t *pnum, + BlockDriverState **= file) { assert(bs->backing && bs->backing->bs); - *pnum =3D nb_sectors; + *pnum =3D bytes; *file =3D bs->backing->bs; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } /* diff --git a/block/blkdebug.c b/block/blkdebug.c index 6b40a85..234c8fb9 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -641,15 +641,16 @@ 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 int64_t coroutine_fn blkdebug_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, + int64_t *pnum, + BlockDriverState **fi= le) { - 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, mapping, offset, bytes, + pnum, file); } static void blkdebug_close(BlockDriverState *bs) @@ -921,7 +922,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_co_flush_to_disk =3D blkdebug_co_flush, .bdrv_co_pwrite_zeroes =3D blkdebug_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkdebug_co_pdiscard, - .bdrv_co_get_block_status =3D blkdebug_co_get_block_status, + .bdrv_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 f646c13..be90611 100644 --- a/block/commit.c +++ b/block/commit.c @@ -267,7 +267,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 15b809e..d46dace 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1085,7 +1085,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, --=20 2.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150003496765882.61400644625144; Fri, 14 Jul 2017 05:22:47 -0700 (PDT) Received: from localhost ([::1]:37725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzcH-0002Og-3i for importer@patchew.org; Fri, 14 Jul 2017 08:22:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVF-0003ah-HM for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVE-0003j7-C4 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzV9-0003fS-4V; Fri, 14 Jul 2017 08:15:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D679C0587E8; Fri, 14 Jul 2017 12:15:18 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5BCB6FE4C; Fri, 14 Jul 2017 12:15:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2D679C0587E8 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2D679C0587E8 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:40 -0500 Message-Id: <20170714121457.10322-4-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Jul 2017 12:15:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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_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 file protocol driver accordingly. In mapping mode, note that the entire file is reported as allocated, so we can take a shortcut and skip lseek(). Signed-off-by: Eric Blake --- v2: tweak comment, add mapping support --- block/file-posix.c | 57 ++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index cfbb236..765a440 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2104,24 +2104,25 @@ 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 int64_t coroutine_fn raw_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, int64_t *pn= um, + 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; @@ -2130,39 +2131,45 @@ 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 (!mapping) { + *pnum =3D bytes; + *file =3D bs; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | + (offset & BDRV_BLOCK_OFFSET_MASK); + } + + 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; } *file =3D bs; - return ret | BDRV_BLOCK_OFFSET_VALID | start; + return ret | BDRV_BLOCK_OFFSET_VALID | (offset & BDRV_BLOCK_OFFSET_MAS= K); } static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs, @@ -2256,7 +2263,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035118347931.0269588215632; Fri, 14 Jul 2017 05:25:18 -0700 (PDT) Received: from localhost ([::1]:37735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzel-0005aX-0M for importer@patchew.org; Fri, 14 Jul 2017 08:25:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVG-0003bp-Op for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVF-0003k0-Ga for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42312) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVC-0003hS-HS; Fri, 14 Jul 2017 08:15:22 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F762303138; Fri, 14 Jul 2017 12:15:21 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 636C86E911; Fri, 14 Jul 2017 12:15:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8F762303138 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8F762303138 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:41 -0500 Message-Id: <20170714121457.10322-5-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 14 Jul 2017 12:15: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 v2 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_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 gluster driver accordingly. In mapping mode, note that the entire file is reported as allocated, so we can take a shortcut and skip find_allocation(). Signed-off-by: Eric Blake --- v2: tweak comments [Prasanna], add mapping, drop R-b --- block/gluster.c | 62 +++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index bfa4df1..6223ebd 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1353,26 +1353,26 @@ 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 int64_t coroutine_fn qemu_gluster_co_block_status( + BlockDriverState *bs, bool mapping, int64_t offset, int64_t bytes, + int64_t *pnum, BlockDriverState **file) { 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; @@ -1380,41 +1380,47 @@ 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 (!mapping) { + *pnum =3D bytes; + *file =3D bs; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | + (offset & BDRV_BLOCK_OFFSET_MASK); + } + + 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; } *file =3D bs; - return ret | BDRV_BLOCK_OFFSET_VALID | start; + return ret | BDRV_BLOCK_OFFSET_VALID | (offset & BDRV_BLOCK_OFFSET_MAS= K); } @@ -1442,7 +1448,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, }; @@ -1470,7 +1476,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, }; @@ -1498,7 +1504,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, }; @@ -1532,7 +1538,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500034987294129.3363995990013; Fri, 14 Jul 2017 05:23:07 -0700 (PDT) Received: from localhost ([::1]:37726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzcf-0002kL-0j for importer@patchew.org; Fri, 14 Jul 2017 08:23:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVI-0003dn-J8 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVH-0003kh-7P for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVE-0003iK-5s; Fri, 14 Jul 2017 08:15:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 237537EBD2; Fri, 14 Jul 2017 12:15:23 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C613B6E911; Fri, 14 Jul 2017 12:15:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 237537EBD2 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 237537EBD2 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:42 -0500 Message-Id: <20170714121457.10322-6-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Jul 2017 12:15:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- 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 904ef20..9c96b46 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -79,7 +79,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; @@ -460,9 +460,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) { @@ -470,7 +471,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; @@ -491,17 +492,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); @@ -565,9 +568,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, @@ -577,9 +583,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 @@ -814,16 +823,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; } @@ -1963,8 +1977,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); } @@ -2170,7 +2184,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035270313674.0904795020498; Fri, 14 Jul 2017 05:27:50 -0700 (PDT) Received: from localhost ([::1]:37750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzhD-0007jX-MA for importer@patchew.org; Fri, 14 Jul 2017 08:27:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVP-0003kb-N0 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVO-0003p5-GT for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVI-0003lI-Pe; Fri, 14 Jul 2017 08:15:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C412AC0587DD; Fri, 14 Jul 2017 12:15:27 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58C3C6E914; Fri, 14 Jul 2017 12:15:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C412AC0587DD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C412AC0587DD From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:43 -0500 Message-Id: <20170714121457.10322-7-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Jul 2017 12:15:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- 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 9c96b46..682a316 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -488,24 +488,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 { @@ -528,26 +526,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) @@ -561,34 +559,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 @@ -670,12 +664,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); @@ -770,9 +766,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) { @@ -810,15 +808,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 @@ -1187,8 +1189,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); @@ -1286,18 +1287,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035150599172.95402717962952; Fri, 14 Jul 2017 05:25:50 -0700 (PDT) Received: from localhost ([::1]:37741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzfJ-00066j-74 for importer@patchew.org; Fri, 14 Jul 2017 08:25:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVP-0003kE-Ac for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVO-0003ou-48 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVK-0003mA-AS; Fri, 14 Jul 2017 08:15:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BFCC9023C; Fri, 14 Jul 2017 12:15:29 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3EA46E911; Fri, 14 Jul 2017 12:15:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4BFCC9023C Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4BFCC9023C From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:44 -0500 Message-Id: <20170714121457.10322-8-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 14 Jul 2017 12:15: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 v2 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_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 iscsi driver accordingly. In this case, it is handy to teach iscsi_co_block_status() to handle a NULL file parameter, even though the block layer passes a non-NULL value, because we also call the function directly. For now, there are no optimizations done based on the mapping flag. Signed-off-by: Eric Blake --- v2: rebase to mapping parameter --- block/iscsi.c | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 682a316..a848817 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -680,9 +680,10 @@ out_unlock: -static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnu= m, +static int64_t coroutine_fn iscsi_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, int64_t *= pnum, BlockDriverState **file) { IscsiLun *iscsilun =3D bs->opaque; @@ -693,15 +694,15 @@ static int64_t coroutine_fn iscsi_co_get_block_status= (BlockDriverState *bs, 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 (offset & BDRV_BLOCK_OFFSET_MASK) | BDRV_BLOCK_OFFSET_VALID; + *pnum =3D bytes; /* LUN does not support logical block provisioning */ if (!iscsilun->lbpme) { @@ -711,7 +712,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; @@ -750,12 +751,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) { @@ -766,15 +767,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); @@ -782,7 +781,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; @@ -821,25 +820,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 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); + 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); 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; } @@ -2225,7 +2223,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, @@ -2260,7 +2258,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500034864800835.372785458758; Fri, 14 Jul 2017 05:21:04 -0700 (PDT) Received: from localhost ([::1]:37711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzad-00014z-3F for importer@patchew.org; Fri, 14 Jul 2017 08:20:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVO-0003jr-RN for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVN-0003on-U6 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36467) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVL-0003n6-KI; Fri, 14 Jul 2017 08:15:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A69C57F3F6; Fri, 14 Jul 2017 12:15:30 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 818CF6E911; Fri, 14 Jul 2017 12:15:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A69C57F3F6 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A69C57F3F6 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:45 -0500 Message-Id: <20170714121457.10322-9-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 12:15:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- v2: rebase to mapping parameter --- block/null.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/block/null.c b/block/null.c index 876f909..ef61fc0 100644 --- a/block/null.c +++ b/block/null.c @@ -204,22 +204,22 @@ 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 int64_t coroutine_fn null_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, int64_t *p= num, + BlockDriverState **file) { BDRVNullState *s =3D bs->opaque; - off_t start =3D sector_num * BDRV_SECTOR_SIZE; + int64_t ret =3D BDRV_BLOCK_OFFSET_VALID | (offset & BDRV_BLOCK_OFFSET_= MASK); - *pnum =3D nb_sectors; + *pnum =3D bytes; *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) @@ -250,7 +250,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, }; @@ -269,7 +269,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150003530695556.709351838402654; Fri, 14 Jul 2017 05:28:26 -0700 (PDT) Received: from localhost ([::1]:37751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzhl-0008Bk-MI for importer@patchew.org; Fri, 14 Jul 2017 08:28:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVW-0003tu-Sc for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVT-0003ue-0K for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56640) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVQ-0003ph-0L; Fri, 14 Jul 2017 08:15:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AD7B65874; Fri, 14 Jul 2017 12:15:35 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCAF56E911; Fri, 14 Jul 2017 12:15:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AD7B65874 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=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0AD7B65874 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:46 -0500 Message-Id: <20170714121457.10322-10-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 14 Jul 2017 12:15:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 Reviewed-by: Denis V. Lunev --- v2: rebase to mapping parameter; it is ignored, so R-b kept --- block/parallels.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 5bbdfab..8aaacea 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -274,22 +274,29 @@ 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 int64_t coroutine_fn parallels_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, + int64_t *pnum, + BlockDriverState **f= ile) { 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; *file =3D bs->file->bs; - return (offset << BDRV_SECTOR_BITS) | + return (offset & BDRV_BLOCK_OFFSET_MASK) | BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } @@ -778,7 +785,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500034703165224.77024887147832; Fri, 14 Jul 2017 05:18:23 -0700 (PDT) Received: from localhost ([::1]:37681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzY1-0006Lb-Ka for importer@patchew.org; Fri, 14 Jul 2017 08:18:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVX-0003up-QS for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVW-00040X-TR for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVR-0003ru-76; Fri, 14 Jul 2017 08:15:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 427F77F3F8; Fri, 14 Jul 2017 12:15:36 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C40E6E911; Fri, 14 Jul 2017 12:15:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 427F77F3F8 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 427F77F3F8 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:47 -0500 Message-Id: <20170714121457.10322-11-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 12:15:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 mapping flag for this format. Signed-off-by: Eric Blake --- v2: rebase to mapping flag --- block/qcow.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 66827d6..38dd191 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -486,20 +486,25 @@ static uint64_t get_cluster_offset(BlockDriverState *= bs, return cluster_offset; } -static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int64_t coroutine_fn qcow_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, int64_t b= ytes, + int64_t *pnum, + BlockDriverState **file) { BDRVQcowState *s =3D bs->opaque; - int index_in_cluster, n; + int index_in_cluster; + int64_t n; uint64_t cluster_offset; qemu_co_mutex_lock(&s->lock); - cluster_offset =3D get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); + cluster_offset =3D get_cluster_offset(bs, offset, 0, 0, 0, 0); qemu_co_mutex_unlock(&s->lock); - 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; @@ -507,7 +512,7 @@ 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); + cluster_offset |=3D (index_in_cluster & BDRV_BLOCK_OFFSET_MASK); *file =3D bs->file->bs; return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | cluster_offset; } @@ -1076,7 +1081,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035026853232.10388557893054; Fri, 14 Jul 2017 05:23:46 -0700 (PDT) Received: from localhost ([::1]:37728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzdI-0003Hm-Aj for importer@patchew.org; Fri, 14 Jul 2017 08:23:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVZ-0003wZ-3X for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVY-000431-5p for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36766) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVV-0003wa-3f; Fri, 14 Jul 2017 08:15:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 217917F405; Fri, 14 Jul 2017 12:15:40 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C43146E914; Fri, 14 Jul 2017 12:15:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 217917F405 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 217917F405 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:48 -0500 Message-Id: <20170714121457.10322-12-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 12:15: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 v2 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_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 qcow2 driver accordingly. For now, we are ignoring the 'mapping' 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 --- v2: rebase to mapping flag --- block/qcow2.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index c30becf..bcdd212 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1637,8 +1637,12 @@ static void qcow2_join_options(QDict *options, QDict= *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 int64_t coroutine_fn qcow2_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t count, + int64_t *pnum, + BlockDriverState **file) { BDRVQcow2State *s =3D bs->opaque; uint64_t cluster_offset; @@ -1646,21 +1650,20 @@ static int64_t coroutine_fn qcow2_co_get_block_stat= us(BlockDriverState *bs, unsigned int bytes; int64_t 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 << 9, &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); + cluster_offset |=3D (index_in_cluster & BDRV_BLOCK_OFFSET_MASK); *file =3D bs->file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID | cluster_offset; } @@ -4295,7 +4298,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035418631934.363333676193; Fri, 14 Jul 2017 05:30:18 -0700 (PDT) Received: from localhost ([::1]:37769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzjc-0002Hd-Em for importer@patchew.org; Fri, 14 Jul 2017 08:30:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVa-0003y8-FX for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVZ-00044I-C9 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVW-0003z9-Jx; Fri, 14 Jul 2017 08:15:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B4F680F6D; Fri, 14 Jul 2017 12:15:41 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 552FE6E911; Fri, 14 Jul 2017 12:15:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9B4F680F6D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9B4F680F6D From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:49 -0500 Message-Id: <20170714121457.10322-13-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Jul 2017 12:15:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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. There is no intent to optimize based on the mapping flag for this format. Signed-off-by: Eric Blake --- v2: rebase to mapping flag, fix mask in qed_is_allocated_cb --- block/qed.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/block/qed.c b/block/qed.c index 86cad21..a80195c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -677,7 +677,7 @@ typedef struct { Coroutine *co; uint64_t pos; int64_t status; - int *pnum; + int64_t *pnum; BlockDriverState **file; } QEDIsAllocatedCB; @@ -685,10 +685,10 @@ static void qed_is_allocated_cb(void *opaque, int ret= , uint64_t offset, size_t l { QEDIsAllocatedCB *cb =3D opaque; BDRVQEDState *s =3D cb->bs->opaque; - *cb->pnum =3D len / BDRV_SECTOR_SIZE; + *cb->pnum =3D len; switch (ret) { case QED_CLUSTER_FOUND: - offset |=3D qed_offset_into_cluster(s, cb->pos); + offset |=3D qed_offset_into_cluster(s, cb->pos) & BDRV_BLOCK_OFFSE= T_MASK; cb->status =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; *cb->file =3D cb->bs->file->bs; break; @@ -710,16 +710,18 @@ static void qed_is_allocated_cb(void *opaque, int ret= , uint64_t offset, size_t l } } -static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState = *bs, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +static int64_t coroutine_fn bdrv_qed_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t pos, + int64_t bytes, + int64_t *pnum, + BlockDriverState **fi= le) { BDRVQEDState *s =3D bs->opaque; - size_t len =3D (size_t)nb_sectors * BDRV_SECTOR_SIZE; + size_t len; QEDIsAllocatedCB cb =3D { .bs =3D bs, - .pos =3D (uint64_t)sector_num * BDRV_SECTOR_SIZE, + .pos =3D pos, .status =3D BDRV_BLOCK_OFFSET_MASK, .pnum =3D pnum, .file =3D file, @@ -1541,7 +1543,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500034873340420.3873204313402; Fri, 14 Jul 2017 05:21:13 -0700 (PDT) Received: from localhost ([::1]:37712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzam-0001EQ-3j for importer@patchew.org; Fri, 14 Jul 2017 08:21:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVg-00043t-KR for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVc-00046a-Kq for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVa-00044O-2R; Fri, 14 Jul 2017 08:15:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1EF48C04F4D8; Fri, 14 Jul 2017 12:15:45 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id D00A66E911; Fri, 14 Jul 2017 12:15:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1EF48C04F4D8 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=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1EF48C04F4D8 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:50 -0500 Message-Id: <20170714121457.10322-14-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 14 Jul 2017 12:15: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 v2 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 --- v2: rebase to mapping --- block/raw-format.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/block/raw-format.c b/block/raw-format.c index ab552c0..22c7e98 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -250,17 +250,18 @@ fail: return ret; } -static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +static int64_t coroutine_fn raw_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, int64_t *pn= um, + 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; + offset +=3D s->offset; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, @@ -496,7 +497,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035030142679.1665382784917; Fri, 14 Jul 2017 05:23:50 -0700 (PDT) Received: from localhost ([::1]:37729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzdL-0003JH-OC for importer@patchew.org; Fri, 14 Jul 2017 08:23:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVi-000485-SY for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVh-0004Ce-QR for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVc-00045q-S8; Fri, 14 Jul 2017 08:15:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B80A580478; Fri, 14 Jul 2017 12:15:47 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 554926E911; Fri, 14 Jul 2017 12:15:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B80A580478 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B80A580478 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:51 -0500 Message-Id: <20170714121457.10322-15-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Jul 2017 12:15:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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_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 sheepdog driver accordingly. Signed-off-by: Eric Blake --- v2: rebase to mapping flag --- block/sheepdog.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index b7b7e6b..8a83210 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2972,18 +2972,17 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverS= tate *bs, int64_t offset, } static coroutine_fn int64_t -sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_se= ctors, - int *pnum, BlockDriverState **file) +sd_co_block_status(BlockDriverState *bs, bool mapping, int64_t offset, + int64_t bytes, int64_t *pnum, 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; + int64_t ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | + (offset & BDRV_BLOCK_OFFSET_MASK); for (idx =3D start; idx < end; idx++) { if (inode->data_vdi_id[idx] =3D=3D 0) { @@ -3000,9 +2999,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; @@ -3080,7 +3079,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, @@ -3116,7 +3115,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, @@ -3152,7 +3151,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035188904783.6476060163255; Fri, 14 Jul 2017 05:26:28 -0700 (PDT) Received: from localhost ([::1]:37745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzfp-0006Y7-5w for importer@patchew.org; Fri, 14 Jul 2017 08:26:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVj-00048h-4I for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVi-0004Da-BB for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVf-0004AL-Va; Fri, 14 Jul 2017 08:15:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04E7EC0587D4; Fri, 14 Jul 2017 12:15:51 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED0686E91F; Fri, 14 Jul 2017 12:15:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 04E7EC0587D4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 04E7EC0587D4 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:52 -0500 Message-Id: <20170714121457.10322-16-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Jul 2017 12:15:51 +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 v2 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 --- 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 2b6e8fa..dc36685 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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035388286749.7253630514475; Fri, 14 Jul 2017 05:29:48 -0700 (PDT) Received: from localhost ([::1]:37760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzj8-0001TS-PL for importer@patchew.org; Fri, 14 Jul 2017 08:29:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVq-0004NA-Nv for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVk-0004Ft-Uf for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57600) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVi-0004CS-CE; Fri, 14 Jul 2017 08:15:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 641AB65878; Fri, 14 Jul 2017 12:15:53 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 394216FE42; Fri, 14 Jul 2017 12:15:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 641AB65878 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=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 641AB65878 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:53 -0500 Message-Id: <20170714121457.10322-17-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 14 Jul 2017 12:15:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- v2: rebase to mapping flag --- block/vdi.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index dc36685..7a438a3 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,23 +505,20 @@ 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 int64_t coroutine_fn vdi_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, int64_t by= tes, + int64_t *pnum, + 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; @@ -532,7 +526,7 @@ static int64_t coroutine_fn vdi_co_get_block_status(Blo= ckDriverState *bs, offset =3D s->header.offset_data + (uint64_t)bmap_entry * s->block_size + - sector_in_block * SECTOR_SIZE; + (index_in_block & BDRV_BLOCK_OFFSET_MASK); *file =3D bs->file->bs; return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; } @@ -902,7 +896,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D vdi_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_co_get_block_status =3D vdi_co_get_block_status, + .bdrv_co_block_status =3D vdi_co_block_status, .bdrv_make_empty =3D vdi_make_empty, .bdrv_co_preadv =3D vdi_co_preadv, --=20 2.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035489773555.9226634153127; Fri, 14 Jul 2017 05:31:29 -0700 (PDT) Received: from localhost ([::1]:37783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzkl-0003Ey-3b for importer@patchew.org; Fri, 14 Jul 2017 08:31:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVs-0004P3-TE for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVr-0004QY-Ky for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVm-0004GH-6N; Fri, 14 Jul 2017 08:15:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3731085540; Fri, 14 Jul 2017 12:15:57 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A7706FE42; Fri, 14 Jul 2017 12:15:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3731085540 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3731085540 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:54 -0500 Message-Id: <20170714121457.10322-18-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Jul 2017 12:15: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 v2 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 --- v2: rebase to mapping flag --- block/vmdk.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 24d71b5..f134d21 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1286,25 +1286,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 int64_t coroutine_fn vmdk_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, int64_t b= ytes, + int64_t *pnum, + 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; @@ -1319,18 +1321,15 @@ 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)) + ret |=3D (cluster_offset + index_in_cluster) & BDRV_BLOCK_OFFSET_MASK; } *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; } @@ -2363,7 +2362,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15000352423891021.596471781728; Fri, 14 Jul 2017 05:27:22 -0700 (PDT) Received: from localhost ([::1]:37748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzgl-0007Lb-2C for importer@patchew.org; Fri, 14 Jul 2017 08:27:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVs-0004P4-U1 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVs-0004RG-0O for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51702) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVn-0004HV-Bq; Fri, 14 Jul 2017 08:15:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 623837C845; Fri, 14 Jul 2017 12:15:58 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69ECA6E911; Fri, 14 Jul 2017 12:15:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 623837C845 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 623837C845 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:55 -0500 Message-Id: <20170714121457.10322-19-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Jul 2017 12:15:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- v2: drop get_sector_offset() [Kevin], rebase to mapping flag --- block/vpc.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 9a6f817..913f25d 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -496,12 +496,6 @@ static inline int64_t get_image_offset(BlockDriverStat= e *bs, uint64_t offset, return block_offset; } -static inline int64_t get_sector_offset(BlockDriverState *bs, - int64_t sector_num, bool write) -{ - return get_image_offset(bs, sector_num * BDRV_SECTOR_SIZE, write); -} - /* * Writes the footer to the end of the image file. This is needed when the * file grows as it overwrites the old footer @@ -689,46 +683,48 @@ 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 int64_t coroutine_fn vpc_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, int64_t by= tes, + int64_t *pnum, + 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; int n; if (be32_to_cpu(footer->type) =3D=3D VHD_FIXED) { - *pnum =3D nb_sectors; + *pnum =3D bytes; *file =3D bs->file->bs; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } - offset =3D get_sector_offset(bs, sector_num, 0); - start =3D offset; - allocated =3D (offset !=3D -1); + image_offset =3D get_image_offset(bs, offset, 0); + start =3D image_offset & BDRV_BLOCK_OFFSET_MASK; + allocated =3D (image_offset !=3D -1); *pnum =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; return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start; } - if (nb_sectors =3D=3D 0) { + if (bytes =3D=3D 0) { break; } - offset =3D get_sector_offset(bs, sector_num, 0); + image_offset =3D get_image_offset(bs, offset, 0); } while (offset =3D=3D -1); return 0; @@ -1074,7 +1070,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035335409530.1175799751525; Fri, 14 Jul 2017 05:28:55 -0700 (PDT) Received: from localhost ([::1]:37753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVziG-0000Am-AN for importer@patchew.org; Fri, 14 Jul 2017 08:28:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzW0-0004bk-DM for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVw-0004V4-IA for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVo-0004Js-Gc; Fri, 14 Jul 2017 08:16:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D35AC04B31E; Fri, 14 Jul 2017 12:15:59 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9773C6E911; Fri, 14 Jul 2017 12:15:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8D35AC04B31E 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=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8D35AC04B31E From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:56 -0500 Message-Id: <20170714121457.10322-20-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 14 Jul 2017 12:15:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- 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 4fd28e1..844aa26 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3062,15 +3062,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 int64_t coroutine_fn vvfat_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, + int64_t bytes, int64_t *= n, + 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; } @@ -3224,7 +3222,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.9.4 From nobody Mon Apr 29 14:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500035661815786.1501763826977; Fri, 14 Jul 2017 05:34:21 -0700 (PDT) Received: from localhost ([::1]:37793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVznW-0005Zf-9w for importer@patchew.org; Fri, 14 Jul 2017 08:34:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzW1-0004dQ-J8 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzW0-0004Ws-Gc for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:16:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52132) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVzVv-0004Ts-53; Fri, 14 Jul 2017 08:16:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 076587DCF0; Fri, 14 Jul 2017 12:16:06 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C949F6E911; Fri, 14 Jul 2017 12:15:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 076587DCF0 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 076587DCF0 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 07:14:57 -0500 Message-Id: <20170714121457.10322-21-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Jul 2017 12:16:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 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 --- v2: rebase to earlier changes --- include/block/block_int.h | 3 --- block/io.c | 23 +---------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 72b8b81..9b94b32 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -182,9 +182,6 @@ struct BlockDriver { * (favor larger *pnum). The block layer guarantees input aligned * to request_alignment, as well as non-NULL pnum and file. */ - int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, - BlockDriverState **file); int64_t coroutine_fn (*bdrv_co_block_status)(BlockDriverState *bd, bool mapping, int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **file); diff --git a/block/io.c b/block/io.c index 2e8ddd7..375fc66 100644 --- a/block/io.c +++ b/block/io.c @@ -1772,7 +1772,7 @@ static int64_t coroutine_fn bdrv_co_block_status(Bloc= kDriverState *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) { @@ -1793,29 +1793,9 @@ static int64_t coroutine_fn bdrv_co_block_status(Blo= ckDriverState *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 */ - - assert(QEMU_IS_ALIGNED(aligned_offset | aligned_bytes, - BDRV_SECTOR_SIZE)); - ret =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 (ret < 0) { - *pnum =3D 0; - goto out; - } - *pnum =3D count * BDRV_SECTOR_SIZE; - goto refine; - } - ret =3D bs->drv->bdrv_co_block_status(bs, mapping, aligned_offset, aligned_bytes, pnum, &local_file); if (ret < 0) { @@ -1832,7 +1812,6 @@ static int64_t coroutine_fn bdrv_co_block_status(Bloc= kDriverState *bs, *pnum =3D total_size - aligned_offset; } - refine: /* Clamp pnum and ret to original request */ assert(QEMU_IS_ALIGNED(*pnum, align)); *pnum -=3D offset - aligned_offset; --=20 2.9.4