From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479379930236.4363049737218; Mon, 17 Apr 2017 18:36:19 -0700 (PDT) Received: from localhost ([::1]:39489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I42-0006YQ-8X for importer@patchew.org; Mon, 17 Apr 2017 21:36:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I1x-00051S-U3 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I1x-0003Th-5y for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I1v-0003QU-2b; Mon, 17 Apr 2017 21:34:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 030C0C0567B5; Tue, 18 Apr 2017 01:34:06 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5684253C35; Tue, 18 Apr 2017 01:34:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 030C0C0567B5 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 030C0C0567B5 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:26 -0500 Message-Id: <20170418013356.3578-2-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Apr 2017 01:34: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 01/31] block: Drop unused bdrv_round_sectors_to_clusters() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that the last user [mirror_iteration()] has converted to using bytes, we no longer need a function to round sectors to clusters. Signed-off-by: Eric Blake Reviewed-by: John Snow --- include/block/block.h | 4 ---- block/io.c | 21 --------------------- 2 files changed, 25 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 740cb86..86ad511 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -467,10 +467,6 @@ const char *bdrv_get_device_or_node_name(const BlockDr= iverState *bs); int bdrv_get_flags(BlockDriverState *bs); int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs); -void bdrv_round_sectors_to_clusters(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - int64_t *cluster_sector_num, - int *cluster_nb_sectors); void bdrv_round_to_clusters(BlockDriverState *bs, int64_t offset, unsigned int bytes, int64_t *cluster_offset, diff --git a/block/io.c b/block/io.c index d22d35f..d61a906 100644 --- a/block/io.c +++ b/block/io.c @@ -419,27 +419,6 @@ static void mark_request_serialising(BdrvTrackedReques= t *req, uint64_t align) } /** - * Round a region to cluster boundaries (sector-based) - */ -void bdrv_round_sectors_to_clusters(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - int64_t *cluster_sector_num, - int *cluster_nb_sectors) -{ - BlockDriverInfo bdi; - - if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size =3D=3D 0) { - *cluster_sector_num =3D sector_num; - *cluster_nb_sectors =3D nb_sectors; - } else { - int64_t c =3D bdi.cluster_size / BDRV_SECTOR_SIZE; - *cluster_sector_num =3D QEMU_ALIGN_DOWN(sector_num, c); - *cluster_nb_sectors =3D QEMU_ALIGN_UP(sector_num - *cluster_sector= _num + - nb_sectors, c); - } -} - -/** * Round a region to cluster boundaries */ void bdrv_round_to_clusters(BlockDriverState *bs, --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479381518129.22357651412528; Mon, 17 Apr 2017 18:36:21 -0700 (PDT) Received: from localhost ([::1]:39490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I43-0006ZN-V5 for importer@patchew.org; Mon, 17 Apr 2017 21:36:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I22-00055d-8l for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I1z-0003Vk-Sh for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I1w-0003SR-JD; Mon, 17 Apr 2017 21:34:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AA1E80468; Tue, 18 Apr 2017 01:34:07 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B00753C35; Tue, 18 Apr 2017 01:34:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8AA1E80468 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 8AA1E80468 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:27 -0500 Message-Id: <20170418013356.3578-3-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Apr 2017 01:34:07 +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 02/31] block: Make bdrv_round_to_clusters() signature more useful X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In the process of converting sector-based interfaces to bytes, I'm finding it easier to represent a byte count as a 64-bit integer at the block layer (even if we are internally capped by SIZE_MAX or even INT_MAX for individual transactions, it's still nicer to not have to worry about truncation/overflow issues on as many variables). Update the signature of bdrv_round_to_clusters() to uniformly use uint64_t, matching the signature already chosen for bdrv_is_allocated, and adjust clients according to the required fallout. Signed-off-by: Eric Blake --- include/block/block.h | 4 ++-- block/io.c | 7 ++++--- block/mirror.c | 9 ++++----- block/trace-events | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 86ad511..eed1330 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -468,9 +468,9 @@ int bdrv_get_flags(BlockDriverState *bs); int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs); void bdrv_round_to_clusters(BlockDriverState *bs, - int64_t offset, unsigned int bytes, + int64_t offset, int64_t bytes, int64_t *cluster_offset, - unsigned int *cluster_bytes); + int64_t *cluster_bytes); const char *bdrv_get_encrypted_filename(BlockDriverState *bs); void bdrv_get_backing_filename(BlockDriverState *bs, diff --git a/block/io.c b/block/io.c index d61a906..07165dc 100644 --- a/block/io.c +++ b/block/io.c @@ -422,9 +422,9 @@ static void mark_request_serialising(BdrvTrackedRequest= *req, uint64_t align) * Round a region to cluster boundaries */ void bdrv_round_to_clusters(BlockDriverState *bs, - int64_t offset, unsigned int bytes, + int64_t offset, int64_t bytes, int64_t *cluster_offset, - unsigned int *cluster_bytes) + int64_t *cluster_bytes) { BlockDriverInfo bdi; @@ -920,7 +920,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvCh= ild *child, struct iovec iov; QEMUIOVector bounce_qiov; int64_t cluster_offset; - unsigned int cluster_bytes; + int64_t cluster_bytes; size_t skip_bytes; int ret; @@ -941,6 +941,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvCh= ild *child, trace_bdrv_co_do_copy_on_readv(bs, offset, bytes, cluster_offset, cluster_bytes); + assert(cluster_bytes < SIZE_MAX); iov.iov_len =3D cluster_bytes; iov.iov_base =3D bounce_buffer =3D qemu_try_blockalign(bs, iov.iov_len= ); if (bounce_buffer =3D=3D NULL) { diff --git a/block/mirror.c b/block/mirror.c index 846e392..2510793 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -177,7 +177,7 @@ static void mirror_read_complete(void *opaque, int ret) /* Clip bytes relative to offset to not exceed end-of-file */ static inline void mirror_clip_bytes(MirrorBlockJob *s, int64_t offset, - unsigned int *bytes) + int64_t *bytes) { *bytes =3D MIN(*bytes, s->bdev_length - offset); } @@ -190,10 +190,9 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t= *offset, bool need_cow; int ret =3D 0; int64_t align_offset =3D *offset; - unsigned int align_bytes =3D *bytes; + int64_t align_bytes =3D *bytes; int max_bytes =3D s->granularity * s->max_iov; - assert(*bytes < INT_MAX); need_cow =3D !test_bit(*offset / s->granularity, s->cow_bitmap); need_cow |=3D !test_bit((*offset + *bytes - 1) / s->granularity, s->cow_bitmap); @@ -384,7 +383,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) while (nb_chunks > 0 && offset < s->bdev_length) { int64_t ret; int io_sectors; - unsigned int io_bytes; + int64_t io_bytes; int64_t io_bytes_acct; BlockDriverState *file; enum MirrorMethod { @@ -410,7 +409,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) io_bytes =3D s->granularity; } else if (ret >=3D 0 && !(ret & BDRV_BLOCK_DATA)) { int64_t target_offset; - unsigned int target_bytes; + int64_t target_bytes; bdrv_round_to_clusters(blk_bs(s->target), offset, io_bytes, &target_offset, &target_bytes); if (target_offset =3D=3D offset && diff --git a/block/trace-events b/block/trace-events index 04f6463..2301a50 100644 --- a/block/trace-events +++ b/block/trace-events @@ -15,7 +15,7 @@ bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sect= ors, void *opaque) "bs bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_n= um %"PRId64" nb_sectors %d" bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_= num %"PRId64" nb_sectors %d" bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs = %p offset %"PRId64" count %d flags %#x" -bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int= 64_t cluster_offset, unsigned int cluster_bytes) "bs %p offset %"PRId64" by= tes %u cluster_offset %"PRId64" cluster_bytes %u" +bdrv_co_do_copy_on_readv(void *bs, int64_t offset, int64_t bytes, int64_t = cluster_offset, unsigned int cluster_bytes) "bs %p offset %"PRId64" bytes %= "PRId64" cluster_offset %"PRId64" cluster_bytes %u" # block/stream.c stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_alloc= ated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d" --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479532312873.3715364636153; Mon, 17 Apr 2017 18:38:52 -0700 (PDT) Received: from localhost ([::1]:39499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I6V-0000FR-0g for importer@patchew.org; Mon, 17 Apr 2017 21:38:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I23-00056M-AZ for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I22-0003a7-Ef for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40064) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I1x-0003Tl-Re; Mon, 17 Apr 2017 21:34:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4DDB81235; Tue, 18 Apr 2017 01:34:08 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id C059553C35; Tue, 18 Apr 2017 01:34:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4DDB81235 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 B4DDB81235 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:28 -0500 Message-Id: <20170418013356.3578-4-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 18 Apr 2017 01:34:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/31] qcow2: Switch is_zero_sectors() to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , kwolf@nongnu.org, jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change), and rename it to is_zero_above() in the process. Signed-off-by: Eric Blake --- block/qcow2.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 4d34610..fe4ccf6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2442,23 +2442,30 @@ finish: } -static bool is_zero_sectors(BlockDriverState *bs, int64_t start, - uint32_t count) +static bool is_zero_above(BlockDriverState *bs, int64_t offset, int64_t by= tes) { int nr; BlockDriverState *file; int64_t res; + int64_t start; - if (start + count > bs->total_sectors) { - count =3D bs->total_sectors - start; + /* Widen to sector boundaries, then clamp to image length, before + * checking status of underlying sectors */ + start =3D QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); + bytes =3D QEMU_ALIGN_UP(offset + bytes, BDRV_SECTOR_SIZE) - start; + + if (start + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { + bytes =3D bs->total_sectors * BDRV_SECTOR_SIZE - offset; } - if (!count) { + if (!bytes) { return true; } - res =3D bdrv_get_block_status_above(bs, NULL, start, count, + res =3D bdrv_get_block_status_above(bs, NULL, start >> BDRV_SECTOR_BIT= S, + bytes >> BDRV_SECTOR_BITS, &nr, &file); - return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr =3D=3D count; + return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && + nr * BDRV_SECTOR_SIZE =3D=3D bytes; } static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, @@ -2476,24 +2483,21 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(Bloc= kDriverState *bs, } if (head || tail) { - int64_t cl_start =3D (offset - head) >> BDRV_SECTOR_BITS; uint64_t off; unsigned int nr; assert(head + count <=3D s->cluster_size); /* check whether remainder of cluster already reads as zero */ - if (!(is_zero_sectors(bs, cl_start, - DIV_ROUND_UP(head, BDRV_SECTOR_SIZE)) && - is_zero_sectors(bs, (offset + count) >> BDRV_SECTOR_BITS, - DIV_ROUND_UP(-tail & (s->cluster_size - 1), - BDRV_SECTOR_SIZE)))) { + if (!(is_zero_above(bs, offset - head, head) && + is_zero_above(bs, offset + count, + tail ? s->cluster_size - tail : 0))) { return -ENOTSUP; } qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ - offset =3D cl_start << BDRV_SECTOR_BITS; + offset =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); count =3D s->cluster_size; nr =3D s->cluster_size; ret =3D qcow2_get_cluster_offset(bs, offset, &nr, &off); --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479530226941.8996454193098; Mon, 17 Apr 2017 18:38:50 -0700 (PDT) Received: from localhost ([::1]:39497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I6R-0000C5-M2 for importer@patchew.org; Mon, 17 Apr 2017 21:38:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I25-00058E-3t for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I23-0003cv-R1 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I1z-0003UR-5B; Mon, 17 Apr 2017 21:34:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23C8780F90; Tue, 18 Apr 2017 01:34:10 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB44A53C35; Tue, 18 Apr 2017 01:34:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 23C8780F90 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 23C8780F90 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:29 -0500 Message-Id: <20170418013356.3578-5-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Apr 2017 01:34:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/31] block: Switch bdrv_make_zero() to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of zeroing a device to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are sector-aligned). Signed-off-by: Eric Blake --- block/io.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index 07165dc..1f8ae81 100644 --- a/block/io.c +++ b/block/io.c @@ -666,39 +666,39 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offs= et, */ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) { - int64_t target_sectors, ret, nb_sectors, sector_num =3D 0; + int64_t target_size, ret, bytes, offset =3D 0; BlockDriverState *bs =3D child->bs; BlockDriverState *file; - int n; + int n; /* sectors */ - target_sectors =3D bdrv_nb_sectors(bs); - if (target_sectors < 0) { - return target_sectors; + target_size =3D bdrv_getlength(bs); + if (target_size < 0) { + return target_size; } for (;;) { - nb_sectors =3D MIN(target_sectors - sector_num, BDRV_REQUEST_MAX_S= ECTORS); - if (nb_sectors <=3D 0) { + bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <=3D 0) { return 0; } - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &n, &fil= e); + ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &n, &file); if (ret < 0) { - error_report("error getting block status at sector %" PRId64 "= : %s", - sector_num, strerror(-ret)); + error_report("error getting block status at offset %" PRId64 "= : %s", + offset, strerror(-ret)); return ret; } if (ret & BDRV_BLOCK_ZERO) { - sector_num +=3D n; + offset +=3D n * BDRV_SECTOR_BITS; continue; } - ret =3D bdrv_pwrite_zeroes(child, sector_num << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, flags); + ret =3D bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, fl= ags); if (ret < 0) { - error_report("error writing zeroes at sector %" PRId64 ": %s", - sector_num, strerror(-ret)); + error_report("error writing zeroes at offset %" PRId64 ": %s", + offset, strerror(-ret)); return ret; } - sector_num +=3D n; + offset +=3D n * BDRV_SECTOR_SIZE; } } --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479530773696.0592544658126; Mon, 17 Apr 2017 18:38:50 -0700 (PDT) Received: from localhost ([::1]:39498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I6S-0000D1-44 for importer@patchew.org; Mon, 17 Apr 2017 21:38:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I24-00057j-H8 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I23-0003cX-M6 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I20-0003VR-BZ; Mon, 17 Apr 2017 21:34:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CC097267A; Tue, 18 Apr 2017 01:34:11 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5937353C35; Tue, 18 Apr 2017 01:34:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4CC097267A Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4CC097267A From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:30 -0500 Message-Id: <20170418013356.3578-6-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Apr 2017 01:34:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/31] qemu-img: Switch get_block_status() to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , kwolf@nongnu.org, jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Continue by converting an internal function (no semantic change), and simplifying its caller accordingly. Signed-off-by: Eric Blake --- qemu-img.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d96b4d6..8cb5165 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2662,14 +2662,16 @@ static void dump_map_entry(OutputFormat output_form= at, MapEntry *e, } } -static int get_block_status(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, MapEntry *e) +static int get_block_status(BlockDriverState *bs, int64_t offset, + int64_t bytes, MapEntry *e) { int64_t ret; int depth; BlockDriverState *file; bool has_offset; + int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; + assert(bytes < INT_MAX); /* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same * range repeatedly. @@ -2677,8 +2679,8 @@ static int get_block_status(BlockDriverState *bs, int= 64_t sector_num, depth =3D 0; for (;;) { - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &nb_sect= ors, - &file); + ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_s= ectors, + &nb_sectors, &file); if (ret < 0) { return ret; } @@ -2698,7 +2700,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t sector_num, has_offset =3D !!(ret & BDRV_BLOCK_OFFSET_VALID); *e =3D (MapEntry) { - .start =3D sector_num * BDRV_SECTOR_SIZE, + .start =3D offset, .length =3D nb_sectors * BDRV_SECTOR_SIZE, .data =3D !!(ret & BDRV_BLOCK_DATA), .zero =3D !!(ret & BDRV_BLOCK_ZERO), @@ -2823,16 +2825,12 @@ static int img_map(int argc, char **argv) length =3D blk_getlength(blk); while (curr.start + curr.length < length) { - int64_t nsectors_left; - int64_t sector_num; - int n; - - sector_num =3D (curr.start + curr.length) >> BDRV_SECTOR_BITS; + int64_t offset =3D curr.start + curr.length; + int64_t n; /* Probe up to 1 GiB at a time. */ - nsectors_left =3D DIV_ROUND_UP(length, BDRV_SECTOR_SIZE) - sector_= num; - n =3D MIN(1 << (30 - BDRV_SECTOR_BITS), nsectors_left); - ret =3D get_block_status(bs, sector_num, n, &next); + n =3D QEMU_ALIGN_DOWN(MIN(1 << 30, length - offset), BDRV_SECTOR_S= IZE); + ret =3D get_block_status(bs, offset, n, &next); if (ret < 0) { error_report("Could not read file metadata: %s", strerror(-ret= )); --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479675352373.42753134453346; Mon, 17 Apr 2017 18:41:15 -0700 (PDT) Received: from localhost ([::1]:39515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I8n-0002IG-V7 for importer@patchew.org; Mon, 17 Apr 2017 21:41:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I27-00059U-0k for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I25-0003er-EK for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40676) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I21-0003Y1-Sm; Mon, 17 Apr 2017 21:34:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B66E6C04B937; Tue, 18 Apr 2017 01:34:12 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85F8253C35; Tue, 18 Apr 2017 01:34:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B66E6C04B937 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 B66E6C04B937 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:31 -0500 Message-Id: <20170418013356.3578-7-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Apr 2017 01:34:12 +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 06/31] block: Convert bdrv_get_block_status() to bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the name of the function from bdrv_get_block_status() to bdrv_block_status() ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned, but that can be relaxed when a later patch implements byte-based block status in the drivers. Note that we have an inherent limitation in the BDRV_BLOCK_* return values: BDRV_BLOCK_OFFSET_VALID can only return the start of a sector, even if we later relax the interface to query for the status starting at an intermediate byte; document the obvious interpretation that valid offsets are always sector-relative. Therefore, for the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_block_status(). But some code, particularly bdrv_is_allocated(), gets a lot simpler because it no longer has to mess with sectors; also, it is now possible to pass NULL if the caller does not care how much of the image is allocated beyond the initial offset. For ease of review, bdrv_get_block_status_above() will be tackled separately. Signed-off-by: Eric Blake --- include/block/block.h | 15 +++++++++------ block/io.c | 51 ++++++++++++++++++++++++++---------------------= ---- block/qcow2-cluster.c | 2 +- qemu-img.c | 19 ++++++++++--------- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index eed1330..b9e7281 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -121,10 +121,10 @@ typedef struct HDGeometry { /* * Allocation status flags - * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_get_block_st= atus. + * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_block_status. * BDRV_BLOCK_ZERO: sectors read as zero * BDRV_BLOCK_OFFSET_VALID: sector stored as raw data in a file returned by - * bdrv_get_block_status. + * bdrv_block_status. * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this * layer (as opposed to the backing file) * BDRV_BLOCK_RAW: used internally to indicate that the request @@ -132,7 +132,10 @@ typedef struct HDGeometry { * should look in bs->file directly. * * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in - * bs->file where sector data can be read from as raw data. + * bs->file that begins the sector containing the address in question, + * where the sector can be read from as raw data with individual bytes + * at the same sector-relative locations (and thus, this bit cannot be + * set for mappings which are not equivalent modulo 512). * * DATA =3D=3D 0 && ZERO =3D=3D 0 means that data is read from backing_hd = if present. * @@ -414,9 +417,9 @@ int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); -int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file); +int64_t bdrv_block_status(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum, + BlockDriverState **file); int64_t bdrv_get_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t sector_num, diff --git a/block/io.c b/block/io.c index 1f8ae81..5cdb1f0 100644 --- a/block/io.c +++ b/block/io.c @@ -669,7 +669,6 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags f= lags) int64_t target_size, ret, bytes, offset =3D 0; BlockDriverState *bs =3D child->bs; BlockDriverState *file; - int n; /* sectors */ target_size =3D bdrv_getlength(bs); if (target_size < 0) { @@ -681,24 +680,23 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) if (bytes <=3D 0) { return 0; } - ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, &n, &file); + ret =3D bdrv_block_status(bs, offset, bytes, &bytes, &file); if (ret < 0) { error_report("error getting block status at offset %" PRId64 "= : %s", offset, strerror(-ret)); return ret; } if (ret & BDRV_BLOCK_ZERO) { - offset +=3D n * BDRV_SECTOR_BITS; + offset +=3D bytes; continue; } - ret =3D bdrv_pwrite_zeroes(child, offset, n * BDRV_SECTOR_SIZE, fl= ags); + ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); if (ret < 0) { error_report("error writing zeroes at offset %" PRId64 ": %s", offset, strerror(-ret)); return ret; } - offset +=3D n * BDRV_SECTOR_SIZE; + offset +=3D bytes; } } @@ -1754,9 +1752,13 @@ static int64_t coroutine_fn bdrv_co_get_block_status= (BlockDriverState *bs, } if (ret & BDRV_BLOCK_RAW) { + int64_t bytes =3D *pnum * BDRV_SECTOR_SIZE; + assert(ret & BDRV_BLOCK_OFFSET_VALID); - ret =3D bdrv_get_block_status(*file, ret >> BDRV_SECTOR_BITS, - *pnum, pnum, file); + ret =3D bdrv_block_status(*file, ret & BDRV_BLOCK_OFFSET_MASK, + bytes, &bytes, file); + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); + *pnum =3D bytes >> BDRV_SECTOR_BITS; goto out; } @@ -1874,35 +1876,34 @@ int64_t bdrv_get_block_status_above(BlockDriverStat= e *bs, return data.ret; } -int64_t bdrv_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +int64_t bdrv_block_status(BlockDriverState *bs, + int64_t offset, int64_t bytes, int64_t *pnum, + BlockDriverState **file) { - return bdrv_get_block_status_above(bs, backing_bs(bs), - sector_num, nb_sectors, pnum, file); + int64_t ret; + int n; + + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); + assert(bytes <=3D BDRV_REQUEST_MAX_BYTES); + ret =3D bdrv_get_block_status_above(bs, backing_bs(bs), + offset >> BDRV_SECTOR_BITS, + bytes >> BDRV_SECTOR_BITS, &n, file); + if (pnum) { + *pnum =3D n * BDRV_SECTOR_SIZE; + } + return ret; } int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum) { BlockDriverState *file; - int64_t sector_num =3D offset >> BDRV_SECTOR_BITS; - int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; int64_t ret; - int psectors; - assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE) && - bytes < INT_MAX * BDRV_SECTOR_SIZE); - ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &psectors, - &file); + ret =3D bdrv_block_status(bs, offset, bytes, pnum, &file); if (ret < 0) { return ret; } - if (pnum) { - *pnum =3D psectors * BDRV_SECTOR_SIZE; - } return !!(ret & BDRV_BLOCK_ALLOCATED); } diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index bc59cb8..e5feb89 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1465,7 +1465,7 @@ static int discard_single_l2(BlockDriverState *bs, ui= nt64_t offset, * cluster is already marked as zero, or if it's unallocated and we * don't have a backing file. * - * TODO We might want to use bdrv_get_block_status(bs) here, but w= e're + * TODO We might want to use bdrv_block_status(bs) here, but we're * holding s->lock, so that doesn't work today. * * If full_discard is true, the sector should not read back as zer= oes, diff --git a/qemu-img.c b/qemu-img.c index 8cb5165..7ed77d5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1558,12 +1558,16 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) if (s->sector_next_status <=3D sector_num) { BlockDriverState *file; - ret =3D bdrv_get_block_status(blk_bs(s->src[src_cur]), - sector_num - src_cur_offset, - n, &n, &file); + int64_t count =3D n * BDRV_SECTOR_SIZE; + + ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), + (sector_num - src_cur_offset) * BDRV_SECTO= R_SIZE, + count, &count, &file); if (ret < 0) { return ret; } + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; if (ret & BDRV_BLOCK_ZERO) { s->status =3D BLK_ZERO; @@ -2669,9 +2673,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, int depth; BlockDriverState *file; bool has_offset; - int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; - assert(bytes < INT_MAX); /* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same * range repeatedly. @@ -2679,12 +2681,11 @@ static int get_block_status(BlockDriverState *bs, i= nt64_t offset, depth =3D 0; for (;;) { - ret =3D bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_s= ectors, - &nb_sectors, &file); + ret =3D bdrv_block_status(bs, offset, bytes, &bytes, &file); if (ret < 0) { return ret; } - assert(nb_sectors); + assert(bytes); if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) { break; } @@ -2701,7 +2702,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, *e =3D (MapEntry) { .start =3D offset, - .length =3D nb_sectors * BDRV_SECTOR_SIZE, + .length =3D bytes, .data =3D !!(ret & BDRV_BLOCK_DATA), .zero =3D !!(ret & BDRV_BLOCK_ZERO), .offset =3D ret & BDRV_BLOCK_OFFSET_MASK, --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479822945517.2099652215703; Mon, 17 Apr 2017 18:43:42 -0700 (PDT) Received: from localhost ([::1]:39526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IBB-0004O5-6L for importer@patchew.org; Mon, 17 Apr 2017 21:43:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I27-00059W-79 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I26-0003fV-10 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I23-0003aG-5O; Mon, 17 Apr 2017 21:34:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 205FD7F3F5; Tue, 18 Apr 2017 01:34:14 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id E69687835E; Tue, 18 Apr 2017 01:34:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 205FD7F3F5 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 205FD7F3F5 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:32 -0500 Message-Id: <20170418013356.3578-8-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 18 Apr 2017 01:34: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 07/31] block: Switch bdrv_co_get_block_status() to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change), and as with its public counterpart, rename to bdrv_co_block_status() to make the compiler enforce that we catch all uses. For now, we assert that callers still pass aligned data, but ultimately, this will be the function where we hand off to a byte-based driver callback, and will eventually need to add logic to ensure we round calls according to the driver's request_alignment then touch up the result handed back to the caller, if we start permitting a caller to pass unaligned offsets. While at it, adjust the function to accept NULL for pnum or file, while still guaranteeing the driver callback has a non-NULL pointer to write into. Signed-off-by: Eric Blake --- block/io.c | 88 +++++++++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/block/io.c b/block/io.c index 5cdb1f0..e804bdd 100644 --- a/block/io.c +++ b/block/io.c @@ -1696,69 +1696,83 @@ typedef struct BdrvCoGetBlockStatusData { * Drivers not implementing the functionality are assumed to not support * backing files, hence all their sectors are reported as allocated. * - * 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 - * allocated/unallocated state. + * '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. It may be NULL. * - * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors g= oes + * 'bytes' is the max value 'pnum' should be set to. If bytes goes * beyond the end of the disk image it will be clamped. * - * If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, '= file' - * points to the BDS which the sector range is allocated in. + * If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, a= nd + * 'file' is not NULL, then *file points to the BDS which owns the allocat= ed + * sector that contains offset. */ -static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *= pnum, - BlockDriverState **fi= le) +static int64_t coroutine_fn bdrv_co_block_status(BlockDriverState *bs, + int64_t offset, int64_t b= ytes, + int64_t *pnum, + BlockDriverState **file) { - int64_t total_sectors; - int64_t n; + int64_t total_size; + int64_t n; /* bytes */ int64_t ret, ret2; + int count; /* sectors */ + BlockDriverState *tmp_file; - total_sectors =3D bdrv_nb_sectors(bs); - if (total_sectors < 0) { - return total_sectors; + total_size =3D bdrv_getlength(bs); + if (total_size < 0) { + return total_size; } - if (sector_num >=3D total_sectors) { + if (!pnum) { + pnum =3D &n; + } + if (offset >=3D total_size) { *pnum =3D 0; return 0; } - n =3D total_sectors - sector_num; - if (n < nb_sectors) { - nb_sectors =3D n; + n =3D total_size - offset; + if (n < bytes) { + bytes =3D n; } if (!bs->drv->bdrv_co_get_block_status) { - *pnum =3D nb_sectors; + *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; if (bs->drv->protocol_name) { - ret |=3D BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_S= IZE); + ret |=3D BDRV_BLOCK_OFFSET_VALID | (offset & BDRV_BLOCK_OFFSET= _MASK); } return ret; } + if (!file) { + file =3D &tmp_file; + } *file =3D NULL; bdrv_inc_in_flight(bs); - ret =3D bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, = pnum, + /* TODO: Rather than require aligned offsets, we could instead + * round to the driver's request_alignment here, then touch up + * count afterwards back to the caller's expectations. But first + * we want to switch the driver callback to likewise be + * byte-based. */ + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); + ret =3D bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTOR_BI= TS, + bytes >> BDRV_SECTOR_BITS, &co= unt, file); if (ret < 0) { *pnum =3D 0; goto out; } + *pnum =3D count * BDRV_SECTOR_SIZE; if (ret & BDRV_BLOCK_RAW) { - int64_t bytes =3D *pnum * BDRV_SECTOR_SIZE; - assert(ret & BDRV_BLOCK_OFFSET_VALID); ret =3D bdrv_block_status(*file, ret & BDRV_BLOCK_OFFSET_MASK, - bytes, &bytes, file); - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); - *pnum =3D bytes >> BDRV_SECTOR_BITS; + *pnum, pnum, file); + assert(QEMU_IS_ALIGNED(*pnum, BDRV_SECTOR_SIZE)); goto out; } @@ -1769,8 +1783,8 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, ret |=3D BDRV_BLOCK_ZERO; } else if (bs->backing) { BlockDriverState *bs2 =3D bs->backing->bs; - int64_t nb_sectors2 =3D bdrv_nb_sectors(bs2); - if (nb_sectors2 >=3D 0 && sector_num >=3D nb_sectors2) { + int64_t size2 =3D bdrv_getlength(bs2); + if (size2 >=3D 0 && offset >=3D size2) { ret |=3D BDRV_BLOCK_ZERO; } } @@ -1779,11 +1793,10 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, if (*file && *file !=3D bs && (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID)) { - BlockDriverState *file2; - int file_pnum; + int64_t file_pnum; - ret2 =3D bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS, - *pnum, &file_pnum, &file2); + ret2 =3D bdrv_co_block_status(*file, ret & BDRV_BLOCK_OFFSET_MASK, + *pnum, &file_pnum, NULL); if (ret2 >=3D 0) { /* Ignore errors. This is just providing extra information, it * is useful but not necessary. @@ -1818,7 +1831,12 @@ static int64_t coroutine_fn bdrv_co_get_block_status= _above(BlockDriverState *bs, assert(bs !=3D base); for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { - ret =3D bdrv_co_get_block_status(p, sector_num, nb_sectors, pnum, = file); + int64_t count; + + ret =3D bdrv_co_block_status(p, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, &count, + file); + *pnum =3D count >> BDRV_SECTOR_BITS; if (ret < 0 || ret & BDRV_BLOCK_ALLOCATED) { break; } --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479417873738.9642944743008; Mon, 17 Apr 2017 18:36:57 -0700 (PDT) Received: from localhost ([::1]:39491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I4e-00072u-Do for importer@patchew.org; Mon, 17 Apr 2017 21:36:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I28-0005BV-Sw for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I27-0003gE-Qz for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40710) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I24-0003d8-N9; Mon, 17 Apr 2017 21:34:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABEA7C04B924; Tue, 18 Apr 2017 01:34:15 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5618253C35; Tue, 18 Apr 2017 01:34:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ABEA7C04B924 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 ABEA7C04B924 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:33 -0500 Message-Id: <20170418013356.3578-9-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Apr 2017 01:34:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/31] block: Switch BdrvCoGetBlockStatusData to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal type (no semantic change), and rename it to match the corresponding public function rename. Signed-off-by: Eric Blake --- block/io.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/block/io.c b/block/io.c index e804bdd..f7ece8d 100644 --- a/block/io.c +++ b/block/io.c @@ -1680,16 +1680,16 @@ int bdrv_flush_all(void) } -typedef struct BdrvCoGetBlockStatusData { +typedef struct BdrvCoBlockStatusData { BlockDriverState *bs; BlockDriverState *base; BlockDriverState **file; - int64_t sector_num; - int nb_sectors; - int *pnum; + int64_t offset; + int64_t bytes; + int64_t *pnum; int64_t ret; bool done; -} BdrvCoGetBlockStatusData; +} BdrvCoBlockStatusData; /* * Returns the allocation status of the specified sectors. @@ -1850,13 +1850,15 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s_above(BlockDriverState *bs, /* Coroutine wrapper for bdrv_get_block_status_above() */ static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque) { - BdrvCoGetBlockStatusData *data =3D opaque; + BdrvCoBlockStatusData *data =3D opaque; + int n; data->ret =3D bdrv_co_get_block_status_above(data->bs, data->base, - data->sector_num, - data->nb_sectors, - data->pnum, + data->offset >> BDRV_SECTOR= _BITS, + data->bytes >> BDRV_SECTOR_= BITS, + &n, data->file); + *data->pnum =3D n * BDRV_SECTOR_SIZE; data->done =3D true; } @@ -1872,13 +1874,14 @@ int64_t bdrv_get_block_status_above(BlockDriverStat= e *bs, BlockDriverState **file) { Coroutine *co; - BdrvCoGetBlockStatusData data =3D { + int64_t n; + BdrvCoBlockStatusData data =3D { .bs =3D bs, .base =3D base, .file =3D file, - .sector_num =3D sector_num, - .nb_sectors =3D nb_sectors, - .pnum =3D pnum, + .offset =3D sector_num * BDRV_SECTOR_SIZE, + .bytes =3D nb_sectors * BDRV_SECTOR_SIZE, + .pnum =3D &n, .done =3D false, }; @@ -1891,6 +1894,7 @@ int64_t bdrv_get_block_status_above(BlockDriverState = *bs, bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } + *pnum =3D n >> BDRV_SECTOR_BITS; return data.ret; } --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480032727860.4286751330875; Mon, 17 Apr 2017 18:47:12 -0700 (PDT) Received: from localhost ([::1]:39550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IEZ-0007H0-7q for importer@patchew.org; Mon, 17 Apr 2017 21:47:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2D-0005HB-SD for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2C-0003hR-Vh for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59118) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I28-0003g6-3P; Mon, 17 Apr 2017 21:34:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 177613B70C; Tue, 18 Apr 2017 01:34:19 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id E17947835E; Tue, 18 Apr 2017 01:34:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 177613B70C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 177613B70C From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:34 -0500 Message-Id: <20170418013356.3578-10-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Apr 2017 01:34:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/31] block: Switch bdrv_co_get_block_status_above() to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal type (no semantic change), and rename it to match the corresponding public function rename. Signed-off-by: Eric Blake --- block/io.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/block/io.c b/block/io.c index f7ece8d..10bc011 100644 --- a/block/io.c +++ b/block/io.c @@ -1819,11 +1819,11 @@ out: return ret; } -static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverStat= e *bs, +static int64_t coroutine_fn bdrv_co_block_status_above(BlockDriverState *b= s, BlockDriverState *base, - int64_t sector_num, - int nb_sectors, - int *pnum, + int64_t offset, + int64_t bytes, + int64_t *pnum, BlockDriverState **file) { BlockDriverState *p; @@ -1831,41 +1831,32 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s_above(BlockDriverState *bs, assert(bs !=3D base); for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { - int64_t count; - - ret =3D bdrv_co_block_status(p, sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, &count, - file); - *pnum =3D count >> BDRV_SECTOR_BITS; + ret =3D bdrv_co_block_status(p, offset, bytes, pnum, file); if (ret < 0 || ret & BDRV_BLOCK_ALLOCATED) { break; } - /* [sector_num, pnum] unallocated on this layer, which could be on= ly - * the first part of [sector_num, nb_sectors]. */ - nb_sectors =3D MIN(nb_sectors, *pnum); + /* [offset, pnum] unallocated on this layer, which could be only + * the first part of [offset, bytes]. */ + bytes =3D MIN(bytes, *pnum); } return ret; } /* Coroutine wrapper for bdrv_get_block_status_above() */ -static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque) +static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; - int n; - data->ret =3D bdrv_co_get_block_status_above(data->bs, data->base, - data->offset >> BDRV_SECTOR= _BITS, - data->bytes >> BDRV_SECTOR_= BITS, - &n, - data->file); - *data->pnum =3D n * BDRV_SECTOR_SIZE; + data->ret =3D bdrv_co_block_status_above(data->bs, data->base, + data->offset, data->bytes, + data->pnum, data->file); data->done =3D true; } /* - * Synchronous wrapper around bdrv_co_get_block_status_above(). + * Synchronous wrapper around bdrv_co_block_status_above(). * - * See bdrv_co_get_block_status_above() for details. + * See bdrv_co_block_status_above() for details. */ int64_t bdrv_get_block_status_above(BlockDriverState *bs, BlockDriverState *base, @@ -1887,10 +1878,9 @@ int64_t bdrv_get_block_status_above(BlockDriverState= *bs, if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ - bdrv_get_block_status_above_co_entry(&data); + bdrv_block_status_above_co_entry(&data); } else { - co =3D qemu_coroutine_create(bdrv_get_block_status_above_co_entry, - &data); + co =3D qemu_coroutine_create(bdrv_block_status_above_co_entry, &da= ta); bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479568540885.5925532706665; Mon, 17 Apr 2017 18:39:28 -0700 (PDT) Received: from localhost ([::1]:39500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I75-0000kl-3u for importer@patchew.org; Mon, 17 Apr 2017 21:39:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2I-0005Lq-HA for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2G-0003jZ-PP for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59180) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2D-0003hJ-1d; Mon, 17 Apr 2017 21:34:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 052F53D967; Tue, 18 Apr 2017 01:34:24 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52F2D53C35; Tue, 18 Apr 2017 01:34:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 052F53D967 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 052F53D967 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:35 -0500 Message-Id: <20170418013356.3578-11-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Apr 2017 01:34:24 +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 10/31] block: Convert bdrv_get_block_status_above() to bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the name of the function from bdrv_get_block_status_above() to bdrv_block_status_above() ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned, but that can be relaxed when a later patch implements byte-based block status in the drivers. For the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_block_status(). But some code, particularly bdrv_block_status(), gets a lot simpler because it no longer has to mess with sectors; also, it is now possible to pass NULL if the caller does not care how much of the image is allocated beyond the initial offset, or which BDS in the chain owns the sector. For ease of review, bdrv_get_block_status() was tackled separately. Signed-off-by: Eric Blake --- include/block/block.h | 10 +++++----- block/io.c | 36 +++++++++++------------------------- block/mirror.c | 14 +++++--------- block/qcow2.c | 10 +++------- qemu-img.c | 37 +++++++++++++++++++++---------------- 5 files changed, 45 insertions(+), 62 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index b9e7281..8f2b8a2 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -420,11 +420,11 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverStat= e *bs); int64_t bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **file); -int64_t bdrv_get_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file); +int64_t bdrv_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + int64_t offset, + int64_t bytes, int64_t *pnum, + BlockDriverState **file); int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, diff --git a/block/io.c b/block/io.c index 10bc011..1b101cf 100644 --- a/block/io.c +++ b/block/io.c @@ -1842,7 +1842,7 @@ static int64_t coroutine_fn bdrv_co_block_status_abov= e(BlockDriverState *bs, return ret; } -/* Coroutine wrapper for bdrv_get_block_status_above() */ +/* Coroutine wrapper for bdrv_block_status_above() */ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; @@ -1858,21 +1858,19 @@ static void coroutine_fn bdrv_block_status_above_co= _entry(void *opaque) * * See bdrv_co_block_status_above() for details. */ -int64_t bdrv_get_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +int64_t bdrv_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + int64_t offset, int64_t bytes, int64_t *pn= um, + BlockDriverState **file) { Coroutine *co; - int64_t n; BdrvCoBlockStatusData data =3D { .bs =3D bs, .base =3D base, .file =3D file, - .offset =3D sector_num * BDRV_SECTOR_SIZE, - .bytes =3D nb_sectors * BDRV_SECTOR_SIZE, - .pnum =3D &n, + .offset =3D offset, + .bytes =3D bytes, + .pnum =3D pnum, .done =3D false, }; @@ -1884,7 +1882,6 @@ int64_t bdrv_get_block_status_above(BlockDriverState = *bs, bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } - *pnum =3D n >> BDRV_SECTOR_BITS; return data.ret; } @@ -1892,27 +1889,16 @@ int64_t bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **file) { - int64_t ret; - int n; - - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); - assert(bytes <=3D BDRV_REQUEST_MAX_BYTES); - ret =3D bdrv_get_block_status_above(bs, backing_bs(bs), - offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, &n, file); - if (pnum) { - *pnum =3D n * BDRV_SECTOR_SIZE; - } - return ret; + return bdrv_block_status_above(bs, backing_bs(bs), + offset, bytes, pnum, file); } int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum) { - BlockDriverState *file; int64_t ret; - ret =3D bdrv_block_status(bs, offset, bytes, pnum, &file); + ret =3D bdrv_block_status(bs, offset, bytes, pnum, NULL); if (ret < 0) { return ret; } diff --git a/block/mirror.c b/block/mirror.c index 2510793..750be1f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -328,7 +328,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) uint64_t delay_ns =3D 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks =3D 1; - int sectors_per_chunk =3D s->granularity >> BDRV_SECTOR_BITS; bool write_zeroes_ok =3D bdrv_can_write_zeroes_with_unmap(blk_bs(s->ta= rget)); int max_io_bytes =3D MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); @@ -374,7 +373,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) } /* Clear dirty bits before querying the block status, because - * calling bdrv_get_block_status_above could yield - if some blocks are + * calling bdrv_block_status_above could yield - if some blocks are * marked dirty in this window, we need to know. */ bdrv_reset_dirty_bitmap(s->dirty_bitmap, offset, @@ -382,10 +381,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks); while (nb_chunks > 0 && offset < s->bdev_length) { int64_t ret; - int io_sectors; int64_t io_bytes; int64_t io_bytes_acct; - BlockDriverState *file; enum MirrorMethod { MIRROR_METHOD_COPY, MIRROR_METHOD_ZERO, @@ -393,11 +390,10 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) } mirror_method =3D MIRROR_METHOD_COPY; assert(!(offset % s->granularity)); - ret =3D bdrv_get_block_status_above(source, NULL, - offset >> BDRV_SECTOR_BITS, - nb_chunks * sectors_per_chunk, - &io_sectors, &file); - io_bytes =3D io_sectors * BDRV_SECTOR_SIZE; + ret =3D bdrv_block_status_above(source, NULL, + offset, + nb_chunks * s->granularity, + &io_bytes, NULL); if (ret < 0) { io_bytes =3D MIN(nb_chunks * s->granularity, max_io_bytes); } else if (ret & BDRV_BLOCK_DATA) { diff --git a/block/qcow2.c b/block/qcow2.c index fe4ccf6..4272cca 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2444,8 +2444,7 @@ finish: static bool is_zero_above(BlockDriverState *bs, int64_t offset, int64_t by= tes) { - int nr; - BlockDriverState *file; + int64_t nr; int64_t res; int64_t start; @@ -2461,11 +2460,8 @@ static bool is_zero_above(BlockDriverState *bs, int6= 4_t offset, int64_t bytes) if (!bytes) { return true; } - res =3D bdrv_get_block_status_above(bs, NULL, start >> BDRV_SECTOR_BIT= S, - bytes >> BDRV_SECTOR_BITS, - &nr, &file); - return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && - nr * BDRV_SECTOR_SIZE =3D=3D bytes; + res =3D bdrv_block_status_above(bs, NULL, start, bytes, &nr, NULL); + return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr =3D=3D bytes; } static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, diff --git a/qemu-img.c b/qemu-img.c index 7ed77d5..2fbd956 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1194,7 +1194,7 @@ static int img_compare(int argc, char **argv) BlockDriverState *bs1, *bs2; int64_t total_sectors1, total_sectors2; uint8_t *buf1 =3D NULL, *buf2 =3D NULL; - int pnum1, pnum2; + int64_t pnum1, pnum2; int allocated1, allocated2; int ret =3D 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress =3D false, quiet =3D false, strict =3D false; @@ -1336,15 +1336,16 @@ static int img_compare(int argc, char **argv) for (;;) { int64_t status1, status2; - BlockDriverState *file; nb_sectors =3D sectors_to_process(total_sectors, sector_num); if (nb_sectors <=3D 0) { break; } - status1 =3D bdrv_get_block_status_above(bs1, NULL, sector_num, - total_sectors1 - sector_num, - &pnum1, &file); + status1 =3D bdrv_block_status_above(bs1, NULL, + sector_num * BDRV_SECTOR_SIZE, + (total_sectors1 - sector_num) * + BDRV_SECTOR_SIZE, + &pnum1, NULL); if (status1 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename1= ); @@ -1352,9 +1353,11 @@ static int img_compare(int argc, char **argv) } allocated1 =3D status1 & BDRV_BLOCK_ALLOCATED; - status2 =3D bdrv_get_block_status_above(bs2, NULL, sector_num, - total_sectors2 - sector_num, - &pnum2, &file); + status2 =3D bdrv_block_status_above(bs2, NULL, + sector_num * BDRV_SECTOR_SIZE, + (total_sectors2 - sector_num) * + BDRV_SECTOR_SIZE, + &pnum2, NULL); if (status2 < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", filename2= ); @@ -1362,10 +1365,10 @@ static int img_compare(int argc, char **argv) } allocated2 =3D status2 & BDRV_BLOCK_ALLOCATED; if (pnum1) { - nb_sectors =3D MIN(nb_sectors, pnum1); + nb_sectors =3D MIN(nb_sectors, pnum1 >> BDRV_SECTOR_BITS); } if (pnum2) { - nb_sectors =3D MIN(nb_sectors, pnum2); + nb_sectors =3D MIN(nb_sectors, pnum2 >> BDRV_SECTOR_BITS); } if (strict) { @@ -1379,7 +1382,7 @@ static int img_compare(int argc, char **argv) } } if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) { - nb_sectors =3D MIN(pnum1, pnum2); + nb_sectors =3D MIN(pnum1, pnum2) >> BDRV_SECTOR_BITS; } else if (allocated1 =3D=3D allocated2) { if (allocated1) { ret =3D blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, bu= f1, @@ -1557,12 +1560,11 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) n =3D MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); if (s->sector_next_status <=3D sector_num) { - BlockDriverState *file; int64_t count =3D n * BDRV_SECTOR_SIZE; ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), (sector_num - src_cur_offset) * BDRV_SECTO= R_SIZE, - count, &count, &file); + count, &count, NULL); if (ret < 0) { return ret; } @@ -1579,9 +1581,12 @@ static int convert_iteration_sectors(ImgConvertState= *s, int64_t sector_num) /* Check block status of the backing file chain to avoid * needlessly reading zeroes and limiting the iteration to the * buffer size */ - ret =3D bdrv_get_block_status_above(blk_bs(s->src[src_cur]), N= ULL, - sector_num - src_cur_offset, - n, &n, &file); + ret =3D bdrv_block_status_above(blk_bs(s->src[src_cur]), NULL, + (sector_num - src_cur_offset) * + BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, &count, NU= LL); + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; if (ret < 0) { return ret; } --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479714688515.189910713428; Mon, 17 Apr 2017 18:41:54 -0700 (PDT) Received: from localhost ([::1]:39518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I9R-0002r4-4u for importer@patchew.org; Mon, 17 Apr 2017 21:41:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2K-0005M6-8S for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2H-0003jm-4L for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2E-0003hk-Gz; Mon, 17 Apr 2017 21:34:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73ADD8046D; Tue, 18 Apr 2017 01:34:25 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CCC753C35; Tue, 18 Apr 2017 01:34:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 73ADD8046D 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 73ADD8046D From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:36 -0500 Message-Id: <20170418013356.3578-12-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Apr 2017 01:34:25 +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 11/31] 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, 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, and update the block layer to ensure that the callback is only used with inputs aligned to the device's request_alignment. Subsequent patches will then update individual drivers, and then finally remove .bdrv_co_get_block_status(). Signed-off-by: Eric Blake --- include/block/block_int.h | 12 ++++++++++++ block/io.c | 47 +++++++++++++++++++++++++++++++++++--------= ---- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index bc3a28a..8f20bc3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -163,11 +163,23 @@ struct BlockDriver { */ int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, int64_t offset, int count, BdrvRequestFlags flags); + int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, int64_t offset, int count); + + /* + * Building block for bdrv_block_status[_above]. The block layer + * guarantees input aligned to request_alignment, as well as + * non-NULL pnum and file; and the result only has to worry about + * BDRV_BLOCK_DATA, _ZERO, _OFFSET_VALID, and _RAW, and only + * according to the current BDS. + */ 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, + 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 1b101cf..361eeb8 100644 --- a/block/io.c +++ b/block/io.c @@ -1718,7 +1718,6 @@ static int64_t coroutine_fn bdrv_co_block_status(Bloc= kDriverState *bs, int64_t total_size; int64_t n; /* bytes */ int64_t ret, ret2; - int count; /* sectors */ BlockDriverState *tmp_file; total_size =3D bdrv_getlength(bs); @@ -1739,7 +1738,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 (bs->drv->protocol_name) { @@ -1753,20 +1752,44 @@ static int64_t coroutine_fn bdrv_co_block_status(Bl= ockDriverState *bs, } *file =3D NULL; bdrv_inc_in_flight(bs); - /* TODO: Rather than require aligned offsets, we could instead - * round to the driver's request_alignment here, then touch up - * count afterwards back to the caller's expectations. But first - * we want to switch the driver callback to likewise be - * byte-based. */ - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); - ret =3D bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTOR_BI= TS, - bytes >> BDRV_SECTOR_BITS, &co= unt, - file); + if (bs->drv->bdrv_co_get_block_status) { + int count; /* sectors */ + + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); + ret =3D bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTO= R_BITS, + bytes >> BDRV_SECTOR_BITS, + &count, file); + *pnum =3D count * BDRV_SECTOR_SIZE; + } else { + /* Round out to request_alignment boundaries */ + int64_t aligned_offset, aligned_bytes; + + aligned_offset =3D QEMU_ALIGN_DOWN(offset, bs->bl.request_alignmen= t); + aligned_bytes =3D ROUND_UP(offset + bytes, + bs->bl.request_alignment) - aligned_offse= t; + ret =3D bs->drv->bdrv_co_block_status(bs, aligned_offset, aligned_= bytes, + &n, file); + /* Clamp pnum and ret to original request */ + if (aligned_offset !=3D offset && ret >=3D 0) { + int sectors =3D DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) - + DIV_ROUND_UP(aligned_offset, BDRV_SECTOR_SIZE); + + assert(n >=3D offset - aligned_offset); + n -=3D offset - aligned_offset; + if (sectors) { + ret +=3D sectors * BDRV_SECTOR_SIZE; + } + } + if (ret >=3D 0 && n > bytes) { + assert(aligned_bytes !=3D bytes); + n =3D bytes; + } + *pnum =3D n; + } if (ret < 0) { *pnum =3D 0; goto out; } - *pnum =3D count * BDRV_SECTOR_SIZE; if (ret & BDRV_BLOCK_RAW) { assert(ret & BDRV_BLOCK_OFFSET_VALID); --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479684739967.5825977919231; Mon, 17 Apr 2017 18:41:24 -0700 (PDT) Received: from localhost ([::1]:39516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I8x-0002Sf-4x for importer@patchew.org; Mon, 17 Apr 2017 21:41:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2K-0005M7-8g for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2H-0003k6-U3 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2F-0003j3-Ti; Mon, 17 Apr 2017 21:34:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DEE4D6AADF; Tue, 18 Apr 2017 01:34:26 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id A28CB53C35; Tue, 18 Apr 2017 01:34:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DEE4D6AADF 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 DEE4D6AADF From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:37 -0500 Message-Id: <20170418013356.3578-13-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Apr 2017 01:34: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 12/31] commit: 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: Kevin Wolf , qemu-block@nongnu.org, Jeff Cody , Max Reitz , kwolf@nongnu.org, 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 commit driver accordingly. Signed-off-by: Eric Blake --- block/commit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/commit.c b/block/commit.c index 989de7d..1cc7a00 100644 --- a/block/commit.c +++ b/block/commit.c @@ -228,14 +228,14 @@ static int coroutine_fn bdrv_commit_top_preadv(BlockD= riverState *bs, return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } -static int64_t coroutine_fn bdrv_commit_top_get_block_status( - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, +static int64_t coroutine_fn bdrv_commit_top_block_status( + BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **file) { - *pnum =3D nb_sectors; + *pnum =3D bytes; *file =3D bs->backing->bs; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } static void bdrv_commit_top_refresh_filename(BlockDriverState *bs, QDict *= opts) @@ -263,7 +263,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_commit_top_get_block_status, + .bdrv_co_block_status =3D bdrv_commit_top_block_status, .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, --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479860419276.6785837604358; Mon, 17 Apr 2017 18:44:20 -0700 (PDT) Received: from localhost ([::1]:39529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IBm-0004uD-O1 for importer@patchew.org; Mon, 17 Apr 2017 21:44:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2O-0005Na-8H for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2N-0003ly-87 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2H-0003jU-7a; Mon, 17 Apr 2017 21:34:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 329264E338; Tue, 18 Apr 2017 01:34:28 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22DE753C35; Tue, 18 Apr 2017 01:34:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 329264E338 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 329264E338 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:38 -0500 Message-Id: <20170418013356.3578-14-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Apr 2017 01:34:28 +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 13/31] 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: Kevin Wolf , kwolf@nongnu.org, jsnow@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. Signed-off-by: Eric Blake --- block/file-posix.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 1941fb6..690bd45 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1832,22 +1832,22 @@ static int find_allocation(BlockDriverState *bs, of= f_t start, /* * Returns the allocation status of the specified sectors. * - * 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, + 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; @@ -1856,39 +1856,38 @@ 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); + 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, @@ -1963,7 +1962,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479688952665.0979952810895; Mon, 17 Apr 2017 18:41:28 -0700 (PDT) Received: from localhost ([::1]:39517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I91-0002VT-DV for importer@patchew.org; Mon, 17 Apr 2017 21:41:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2O-0005Ng-Ar for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2N-0003m7-CL for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2I-0003kF-TH; Mon, 17 Apr 2017 21:34:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE331C05973C; Tue, 18 Apr 2017 01:34:29 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 689A753C35; Tue, 18 Apr 2017 01:34:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE331C05973C 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 CE331C05973C From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:39 -0500 Message-Id: <20170418013356.3578-15-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Apr 2017 01:34: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 14/31] 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: Kevin Wolf , qemu-block@nongnu.org, Jeff Cody , Max Reitz , kwolf@nongnu.org, 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. Signed-off-by: Eric Blake Reviewed-by: Niels de Vos --- block/gluster.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 1d4e2f7..3f252c6 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1332,24 +1332,24 @@ exit: /* * Returns the allocation status of the specified sectors. * - * 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, +static int64_t coroutine_fn qemu_gluster_co_block_status( + BlockDriverState *bs, 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; @@ -1357,41 +1357,40 @@ 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); + 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) { + } else if (data =3D=3D offset) { /* On a data extent, compute sectors 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); + 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); } @@ -1419,7 +1418,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, }; @@ -1447,7 +1446,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, }; @@ -1475,7 +1474,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, }; @@ -1509,7 +1508,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149247983208859.467369303238; Mon, 17 Apr 2017 18:43:52 -0700 (PDT) Received: from localhost ([::1]:39527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IBK-0004WL-8c for importer@patchew.org; Mon, 17 Apr 2017 21:43:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2U-0005Uf-M6 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2T-0003oe-J9 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2O-0003mW-MC; Mon, 17 Apr 2017 21:34:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FEA78046D; Tue, 18 Apr 2017 01:34:35 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10BBF53C35; Tue, 18 Apr 2017 01:34:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FEA78046D 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 9FEA78046D From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:40 -0500 Message-Id: <20170418013356.3578-16-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Apr 2017 01:34: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 15/31] 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: Kevin Wolf , qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , kwolf@nongnu.org, 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 --- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 5daa201..9648a45 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; } @@ -1944,8 +1958,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); } @@ -2143,7 +2157,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479976863904.3421087608998; Mon, 17 Apr 2017 18:46:16 -0700 (PDT) Received: from localhost ([::1]:39547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IDf-0006ZL-Dg for importer@patchew.org; Mon, 17 Apr 2017 21:46:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2X-0005XV-CQ for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2W-0003pj-5C for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41918) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2S-0003o4-Qx; Mon, 17 Apr 2017 21:34:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 931B3627D8; Tue, 18 Apr 2017 01:34:39 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3A2A783E3; Tue, 18 Apr 2017 01:34:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 931B3627D8 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 931B3627D8 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:41 -0500 Message-Id: <20170418013356.3578-17-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Apr 2017 01:34:39 +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 16/31] 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: Kevin Wolf , qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , kwolf@nongnu.org, 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 --- block/iscsi.c | 90 +++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 9648a45..e51fdfb 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, - count >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, count); 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, - count >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, count); r =3D iTask.err_code; goto out_unlock; } if (flags & BDRV_REQ_MAY_UNMAP) { - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, count); } else { - iscsi_allocmap_set_allocated(iscsilun, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_allocated(iscsilun, offset, count); } out_unlock: --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480138696973.068038991767; Mon, 17 Apr 2017 18:48:58 -0700 (PDT) Received: from localhost ([::1]:39558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IGG-0000Fb-W3 for importer@patchew.org; Mon, 17 Apr 2017 21:48:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2Y-0005YT-DS for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2X-0003q9-AB for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40950) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2U-0003oa-7W; Mon, 17 Apr 2017 21:34:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1ACB8C054912; Tue, 18 Apr 2017 01:34:41 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id C60587835E; Tue, 18 Apr 2017 01:34:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1ACB8C054912 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 1ACB8C054912 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:42 -0500 Message-Id: <20170418013356.3578-18-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Apr 2017 01:34: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 17/31] 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: Kevin Wolf , qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , kwolf@nongnu.org, 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. Signed-off-by: Eric Blake --- block/iscsi.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index e51fdfb..f7c8a32 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -680,9 +680,9 @@ 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, + int64_t offset, + int64_t bytes, int64_t *= pnum, BlockDriverState **file) { IscsiLun *iscsilun =3D bs->opaque; @@ -693,15 +693,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 +711,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 +750,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 +766,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 +780,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 +819,23 @@ 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, 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; } @@ -2198,7 +2194,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, @@ -2233,7 +2229,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480296391896.0801105745304; Mon, 17 Apr 2017 18:51:36 -0700 (PDT) Received: from localhost ([::1]:39576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IIo-0002Ne-3u for importer@patchew.org; Mon, 17 Apr 2017 21:51:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2Y-0005YQ-AX for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2X-0003qN-I0 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46438) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2V-0003pE-Dm; Mon, 17 Apr 2017 21:34:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F4D22E607A; Tue, 18 Apr 2017 01:34:42 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50F9C53C35; Tue, 18 Apr 2017 01:34:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5F4D22E607A 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 5F4D22E607A From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:43 -0500 Message-Id: <20170418013356.3578-19-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Apr 2017 01:34:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 18/31] mirror: 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: Kevin Wolf , qemu-block@nongnu.org, Jeff Cody , Max Reitz , kwolf@nongnu.org, 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 mirror driver accordingly. Signed-off-by: Eric Blake --- block/mirror.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 750be1f..ebd0adf 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1027,14 +1027,14 @@ static int coroutine_fn bdrv_mirror_top_flush(Block= DriverState *bs) return bdrv_co_flush(bs->backing->bs); } -static int64_t coroutine_fn bdrv_mirror_top_get_block_status( - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, +static int64_t coroutine_fn bdrv_mirror_top_block_status( + BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **file) { - *pnum =3D nb_sectors; + *pnum =3D bytes; *file =3D bs->backing->bs; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, @@ -1083,7 +1083,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_mirror_top_get_block_status, + .bdrv_co_block_status =3D bdrv_mirror_top_block_status, .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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480032238932.447195210482; Mon, 17 Apr 2017 18:47:12 -0700 (PDT) Received: from localhost ([::1]:39549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IEY-0007GP-OA for importer@patchew.org; Mon, 17 Apr 2017 21:47:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2e-0005dG-6m for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2d-0003sB-5r for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41258) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2Y-0003qY-N4; Mon, 17 Apr 2017 21:34:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A41A3C04B924; Tue, 18 Apr 2017 01:34:45 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95B4753C35; Tue, 18 Apr 2017 01:34:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A41A3C04B924 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 A41A3C04B924 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:44 -0500 Message-Id: <20170418013356.3578-20-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Apr 2017 01:34: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 19/31] 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , kwolf@nongnu.org, 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 null driver accordingly. Signed-off-by: Eric Blake --- block/null.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/block/null.c b/block/null.c index b300390..2dc2dd7 100644 --- a/block/null.c +++ b/block/null.c @@ -204,22 +204,21 @@ 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, + 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 +249,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 +268,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480194519462.15177177358544; Mon, 17 Apr 2017 18:49:54 -0700 (PDT) Received: from localhost ([::1]:39563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IHB-0000y0-5D for importer@patchew.org; Mon, 17 Apr 2017 21:49:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2f-0005ed-F8 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2e-0003sm-Jy for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2c-0003rl-Bs; Mon, 17 Apr 2017 21:34:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34AC33DBD0; Tue, 18 Apr 2017 01:34:49 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDF2B53C35; Tue, 18 Apr 2017 01:34:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 34AC33DBD0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 34AC33DBD0 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:45 -0500 Message-Id: <20170418013356.3578-21-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Apr 2017 01:34:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 20/31] 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: Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , "Denis V. Lunev" , kwolf@nongnu.org, 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. Signed-off-by: Eric Blake Reviewed-by: Denis V. Lunev --- block/parallels.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 8be46a7..2bc1918 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -274,22 +274,25 @@ 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, + 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; } @@ -775,7 +778,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492479852173897.8928466362312; Mon, 17 Apr 2017 18:44:12 -0700 (PDT) Received: from localhost ([::1]:39528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IBe-0004nX-NP for importer@patchew.org; Mon, 17 Apr 2017 21:44:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2g-0005fz-PP for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2g-0003tO-1J for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2d-0003s8-IR; Mon, 17 Apr 2017 21:34:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CEDCC054905; Tue, 18 Apr 2017 01:34:50 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B9D97835E; Tue, 18 Apr 2017 01:34:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5CEDCC054905 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 5CEDCC054905 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:46 -0500 Message-Id: <20170418013356.3578-22-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Apr 2017 01:34:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 21/31] 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: Kevin Wolf , kwolf@nongnu.org, jsnow@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. Signed-off-by: Eric Blake --- block/qcow.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 5d147b9..d7dfa08 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -515,20 +515,22 @@ 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, + int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **f= ile) { 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; @@ -536,7 +538,7 @@ static int64_t coroutine_fn qcow_co_get_block_status(Bl= ockDriverState *bs, if ((cluster_offset & QCOW_OFLAG_COMPRESSED) || s->cipher) { 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; } @@ -1061,7 +1063,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_set_key =3D qcow_set_key, .bdrv_make_empty =3D qcow_make_empty, --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480420991210.15207791588227; Mon, 17 Apr 2017 18:53:40 -0700 (PDT) Received: from localhost ([::1]:39584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IKp-00047r-JV for importer@patchew.org; Mon, 17 Apr 2017 21:53:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2i-0005i8-Ha for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2h-0003u4-Kg for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46602) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2e-0003sU-K6; Mon, 17 Apr 2017 21:34:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 874D437EE1; Tue, 18 Apr 2017 01:34:51 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92B1353C35; Tue, 18 Apr 2017 01:34:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 874D437EE1 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 874D437EE1 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:47 -0500 Message-Id: <20170418013356.3578-23-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Apr 2017 01:34:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 22/31] 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: Kevin Wolf , kwolf@nongnu.org, jsnow@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. Signed-off-by: Eric Blake --- block/qcow2.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 4272cca..0de7210 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1358,8 +1358,8 @@ 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, + int64_t offset, int64_t count, int64_t *pnum, BlockDriverState **f= ile) { BDRVQcow2State *s =3D bs->opaque; uint64_t cluster_offset; @@ -1367,21 +1367,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->cipher) { - 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; } @@ -3429,7 +3428,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_set_key =3D qcow2_set_key, .bdrv_co_preadv =3D qcow2_co_preadv, --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480524598486.9986653081785; Mon, 17 Apr 2017 18:55:24 -0700 (PDT) Received: from localhost ([::1]:39597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IMV-0005Xm-Bu for importer@patchew.org; Mon, 17 Apr 2017 21:55:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2l-0005k3-CM for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2k-0003w4-CU for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:34:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58792) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2g-0003tK-Al; Mon, 17 Apr 2017 21:34:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46892804F3; Tue, 18 Apr 2017 01:34:53 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD27953C35; Tue, 18 Apr 2017 01:34:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 46892804F3 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 46892804F3 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:48 -0500 Message-Id: <20170418013356.3578-24-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Apr 2017 01:34: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 23/31] 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: Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, 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. Signed-off-by: Eric Blake --- block/qed.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/block/qed.c b/block/qed.c index fd76817..336dae4 100644 --- a/block/qed.c +++ b/block/qed.c @@ -729,7 +729,7 @@ typedef struct { Coroutine *co; uint64_t pos; int64_t status; - int *pnum; + int64_t *pnum; BlockDriverState **file; } QEDIsAllocatedCB; @@ -737,10 +737,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_VALID; cb->status =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; *cb->file =3D cb->bs->file->bs; break; @@ -762,23 +762,23 @@ 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, + int64_t offset, + 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; QEDIsAllocatedCB cb =3D { .bs =3D bs, - .pos =3D (uint64_t)sector_num * BDRV_SECTOR_SIZE, + .pos =3D offset, .status =3D BDRV_BLOCK_OFFSET_MASK, .pnum =3D pnum, .file =3D file, }; QEDRequest request =3D { .l2_table =3D NULL }; - qed_find_cluster(s, &request, cb.pos, len, qed_is_allocated_cb, &cb); + qed_find_cluster(s, &request, cb.pos, bytes, qed_is_allocated_cb, &cb); /* Now sleep if the callback wasn't invoked immediately */ while (cb.status =3D=3D BDRV_BLOCK_OFFSET_MASK) { @@ -1710,7 +1710,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_aio_readv =3D bdrv_qed_aio_readv, .bdrv_aio_writev =3D bdrv_qed_aio_writev, .bdrv_co_pwrite_zeroes =3D bdrv_qed_co_pwrite_zeroes, --=20 2.9.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480349017230.0067297424182; Mon, 17 Apr 2017 18:52:29 -0700 (PDT) Received: from localhost ([::1]:39578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IJf-00037M-LV for importer@patchew.org; Mon, 17 Apr 2017 21:52:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2n-0005m2-9F for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2m-0003wX-AW for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2h-0003tq-Q8; Mon, 17 Apr 2017 21:34:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDB1E4E338; Tue, 18 Apr 2017 01:34:54 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7971353C35; Tue, 18 Apr 2017 01:34:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BDB1E4E338 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 BDB1E4E338 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:49 -0500 Message-Id: <20170418013356.3578-25-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Apr 2017 01:34:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 24/31] 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: Kevin Wolf , kwolf@nongnu.org, jsnow@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 --- block/raw-format.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/block/raw-format.c b/block/raw-format.c index 36e6503..746beed 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -250,17 +250,17 @@ fail: return ret; } -static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum, - BlockDriverState **file) +static int64_t coroutine_fn raw_co_block_status(BlockDriverState *bs, + 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 | BDRV_BLOCK_DATA | - (sector_num << BDRV_SECTOR_BITS); + (offset & BDRV_BLOCK_OFFSET_MASK); } static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, @@ -475,7 +475,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149248046427474.92944147448873; Mon, 17 Apr 2017 18:54:24 -0700 (PDT) Received: from localhost ([::1]:39586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0ILW-0004hU-NW for importer@patchew.org; Mon, 17 Apr 2017 21:54:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2p-0005oy-AJ for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2o-0003xS-96 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2l-0003w8-NM; Mon, 17 Apr 2017 21:34:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9260480468; Tue, 18 Apr 2017 01:34:58 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00F5453C35; Tue, 18 Apr 2017 01:34:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9260480468 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 9260480468 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:50 -0500 Message-Id: <20170418013356.3578-26-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Apr 2017 01:34: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 25/31] 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: Kevin Wolf , "open list:Sheepdog" , qemu-block@nongnu.org, Hitoshi Mitake , Jeff Cody , Max Reitz , Liu Yuan , kwolf@nongnu.org, 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 --- block/sheepdog.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 1ccb81b..be7cc39 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2971,18 +2971,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, 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) { @@ -2999,9 +2998,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; @@ -3079,7 +3078,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, @@ -3115,7 +3114,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, @@ -3151,7 +3150,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480555828759.8108254913665; Mon, 17 Apr 2017 18:55:55 -0700 (PDT) Received: from localhost ([::1]:39598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IN0-0005sv-F2 for importer@patchew.org; Mon, 17 Apr 2017 21:55:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2q-0005r1-13 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2p-0003yg-B0 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2n-0003wb-5H; Mon, 17 Apr 2017 21:35:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19DBE80F6B; Tue, 18 Apr 2017 01:35:00 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id C83007835E; Tue, 18 Apr 2017 01:34:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 19DBE80F6B 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 19DBE80F6B From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:51 -0500 Message-Id: <20170418013356.3578-27-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Apr 2017 01:35:00 +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 26/31] 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: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Max Reitz , kwolf@nongnu.org, 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" Rework the debug define so that we always get -Wformat checking, even when debugging is disabled. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Weil --- block/vdi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index d12d9cd..a70b969 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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480071133982.3878605245856; Mon, 17 Apr 2017 18:47:51 -0700 (PDT) Received: from localhost ([::1]:39552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IFB-0007rd-NB for importer@patchew.org; Mon, 17 Apr 2017 21:47:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2u-0005xH-Cx for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2r-0003zD-Ay for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2o-0003xJ-I5; Mon, 17 Apr 2017 21:35:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E0C6C054C5C; Tue, 18 Apr 2017 01:35:01 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CC7153C35; Tue, 18 Apr 2017 01:35:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7E0C6C054C5C 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 7E0C6C054C5C From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:52 -0500 Message-Id: <20170418013356.3578-28-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Apr 2017 01:35:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 27/31] 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: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Max Reitz , kwolf@nongnu.org, 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 --- block/vdi.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index a70b969..390e2f1 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,17 @@ 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, + int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **f= ile) { - /* 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 +523,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; } @@ -901,7 +892,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480310504609.8327793327977; Mon, 17 Apr 2017 18:51:50 -0700 (PDT) Received: from localhost ([::1]:39577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IJ3-0002bF-40 for importer@patchew.org; Mon, 17 Apr 2017 21:51:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2w-00060F-Nx for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2v-00045G-P6 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46734) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2s-0003zV-Ov; Mon, 17 Apr 2017 21:35:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B717A31F40F; Tue, 18 Apr 2017 01:35:05 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id B284F7835E; Tue, 18 Apr 2017 01:35:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B717A31F40F 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 B717A31F40F From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:53 -0500 Message-Id: <20170418013356.3578-29-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Apr 2017 01:35:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 28/31] 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , kwolf@nongnu.org, 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 vmdk driver accordingly. Signed-off-by: Eric Blake --- block/vmdk.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index c61b9cc..c85ce96 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1286,25 +1286,24 @@ 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, + int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **f= ile) { 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 +1318,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; } @@ -2362,7 +2358,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149248067751453.53744980897625; Mon, 17 Apr 2017 18:57:57 -0700 (PDT) Received: from localhost ([::1]:39610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IOy-000798-19 for importer@patchew.org; Mon, 17 Apr 2017 21:57:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2z-00063u-Pl for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2y-00046V-Qe for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58998) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2u-00041T-8H; Mon, 17 Apr 2017 21:35:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B93F61BB0; Tue, 18 Apr 2017 01:35:07 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED2A953C35; Tue, 18 Apr 2017 01:35:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B93F61BB0 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2B93F61BB0 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:54 -0500 Message-Id: <20170418013356.3578-30-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Apr 2017 01:35:07 +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 29/31] 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: Kevin Wolf , kwolf@nongnu.org, jsnow@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. Signed-off-by: Eric Blake --- block/vpc.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index ecfee77..3cd56e7 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -689,46 +689,45 @@ 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, + int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **f= ile) { 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 | BDRV_BLOCK_DATA | - (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_sector_offset(bs, offset, 0); } while (offset =3D=3D -1); return 0; @@ -1074,7 +1073,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480617539184.65777824883014; Mon, 17 Apr 2017 18:56:57 -0700 (PDT) Received: from localhost ([::1]:39608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0INz-0006aa-Ji for importer@patchew.org; Mon, 17 Apr 2017 21:56:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I2z-00063o-Lf for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I2y-00046a-Rc for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2v-00043W-Fi; Mon, 17 Apr 2017 21:35:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 740874E35B; Tue, 18 Apr 2017 01:35:08 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55EEC7835E; Tue, 18 Apr 2017 01:35:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 740874E35B 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 740874E35B From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:55 -0500 Message-Id: <20170418013356.3578-31-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Apr 2017 01:35:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 30/31] 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: Kevin Wolf , kwolf@nongnu.org, jsnow@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. Signed-off-by: Eric Blake --- block/vvfat.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index bef2056..825fe72 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2961,13 +2961,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 **file) +static int64_t coroutine_fn vvfat_co_block_status(BlockDriverState *bs, + int64_t offset, int64_t bytes, int64_t *n, BlockDriverState **file) { BDRVVVFATState* s =3D bs->opaque; - *n =3D s->sector_count - sector_num; - if (*n > nb_sectors) { - *n =3D nb_sectors; + *n =3D s->sector_count * BDRV_SECTOR_SIZE - offset; + if (*n > bytes) { + *n =3D bytes; } else if (*n < 0) { return 0; } @@ -3124,7 +3124,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.3 From nobody Tue Apr 30 07:18:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492480428416420.570450586578; Mon, 17 Apr 2017 18:53:48 -0700 (PDT) Received: from localhost ([::1]:39585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0IKx-0004DW-24 for importer@patchew.org; Mon, 17 Apr 2017 21:53:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0I36-00068v-PJ for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0I35-00048H-L5 for qemu-devel@nongnu.org; Mon, 17 Apr 2017 21:35:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59068) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0I2y-00046F-Mk; Mon, 17 Apr 2017 21:35:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5FAB80F6B; Tue, 18 Apr 2017 01:35:11 +0000 (UTC) Received: from red.redhat.com (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB2317835E; Tue, 18 Apr 2017 01:35:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A5FAB80F6B 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 A5FAB80F6B From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 17 Apr 2017 20:33:56 -0500 Message-Id: <20170418013356.3578-32-eblake@redhat.com> In-Reply-To: <20170418013356.3578-1-eblake@redhat.com> References: <20170418013356.3578-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Apr 2017 01:35:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 31/31] 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , kwolf@nongnu.org, 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 --- include/block/block_int.h | 3 --- block/io.c | 59 ++++++++++++++++++++-----------------------= ---- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 8f20bc3..25197d7 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -174,9 +174,6 @@ struct BlockDriver { * BDRV_BLOCK_DATA, _ZERO, _OFFSET_VALID, and _RAW, and only * according to the current BDS. */ - 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, int64_t offset, int64_t bytes, int64_t *pnum, BlockDriverState **file); diff --git a/block/io.c b/block/io.c index 361eeb8..0488d08 100644 --- a/block/io.c +++ b/block/io.c @@ -1719,6 +1719,7 @@ static int64_t coroutine_fn bdrv_co_block_status(Bloc= kDriverState *bs, int64_t n; /* bytes */ int64_t ret, ret2; BlockDriverState *tmp_file; + int64_t aligned_offset, aligned_bytes; total_size =3D bdrv_getlength(bs); if (total_size < 0) { @@ -1738,7 +1739,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 (bs->drv->protocol_name) { @@ -1752,45 +1753,35 @@ static int64_t coroutine_fn bdrv_co_block_status(Bl= ockDriverState *bs, } *file =3D NULL; bdrv_inc_in_flight(bs); - if (bs->drv->bdrv_co_get_block_status) { - int count; /* sectors */ - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); - ret =3D bs->drv->bdrv_co_get_block_status(bs, offset >> BDRV_SECTO= R_BITS, - bytes >> BDRV_SECTOR_BITS, - &count, file); - *pnum =3D count * BDRV_SECTOR_SIZE; - } else { - /* Round out to request_alignment boundaries */ - int64_t aligned_offset, aligned_bytes; - - aligned_offset =3D QEMU_ALIGN_DOWN(offset, bs->bl.request_alignmen= t); - aligned_bytes =3D ROUND_UP(offset + bytes, - bs->bl.request_alignment) - aligned_offse= t; - ret =3D bs->drv->bdrv_co_block_status(bs, aligned_offset, aligned_= bytes, - &n, file); - /* Clamp pnum and ret to original request */ - if (aligned_offset !=3D offset && ret >=3D 0) { - int sectors =3D DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) - - DIV_ROUND_UP(aligned_offset, BDRV_SECTOR_SIZE); - - assert(n >=3D offset - aligned_offset); - n -=3D offset - aligned_offset; - if (sectors) { - ret +=3D sectors * BDRV_SECTOR_SIZE; - } - } - if (ret >=3D 0 && n > bytes) { - assert(aligned_bytes !=3D bytes); - n =3D bytes; - } - *pnum =3D n; - } + /* Round out to request_alignment boundaries */ + aligned_offset =3D QEMU_ALIGN_DOWN(offset, bs->bl.request_alignment); + aligned_bytes =3D ROUND_UP(offset + bytes, + bs->bl.request_alignment) - aligned_offset; + ret =3D bs->drv->bdrv_co_block_status(bs, aligned_offset, aligned_byte= s, + &n, file); if (ret < 0) { *pnum =3D 0; goto out; } + /* Clamp pnum and ret to original request */ + if (aligned_offset !=3D offset && ret >=3D 0) { + int sectors =3D DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) - + DIV_ROUND_UP(aligned_offset, BDRV_SECTOR_SIZE); + + assert(n >=3D offset - aligned_offset); + n -=3D offset - aligned_offset; + if (sectors) { + ret +=3D sectors * BDRV_SECTOR_SIZE; + } + } + if (n > bytes) { + assert(aligned_bytes !=3D bytes); + n =3D bytes; + } + *pnum =3D n; + if (ret & BDRV_BLOCK_RAW) { assert(ret & BDRV_BLOCK_OFFSET_VALID); ret =3D bdrv_block_status(*file, ret & BDRV_BLOCK_OFFSET_MASK, --=20 2.9.3