From nobody Sun Oct 5 21:16:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505762125109181.26956371614267; Mon, 18 Sep 2017 12:15:25 -0700 (PDT) Received: from localhost ([::1]:38457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1du1Vs-0000ke-CX for importer@patchew.org; Mon, 18 Sep 2017 15:15:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1du1GI-0002fy-E7 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 14:59:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1du1GH-0006lV-Gd for qemu-devel@nongnu.org; Mon, 18 Sep 2017 14:59:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45870) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1du1GE-0006ht-P2; Mon, 18 Sep 2017 14:59:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF3487E43B; Mon, 18 Sep 2017 18:59:13 +0000 (UTC) Received: from red.redhat.com (ovpn-124-97.rdu2.redhat.com [10.10.124.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 814255C1A3; Mon, 18 Sep 2017 18:59:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AF3487E43B Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 13:58:17 -0500 Message-Id: <20170918185819.5984-19-eblake@redhat.com> In-Reply-To: <20170918185819.5984-1-eblake@redhat.com> References: <20170918185819.5984-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 18 Sep 2017 18:59:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 18/20] qcow2: Switch store_bitmap_data() to byte-based iteration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, 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" Now that we have adjusted the majority of the calls this function makes to be byte-based, it is easier to read the code if it makes passes over the image using bytes rather than sectors. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- v7: rebase to earlier change, make rounding of offset obvious (no semantic change, so R-b kept) [Kevin] v5-v6: no change v4: new patch --- block/qcow2-bitmap.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 692ce0de88..302fffd6e1 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1072,10 +1072,9 @@ static uint64_t *store_bitmap_data(BlockDriverState = *bs, { int ret; BDRVQcow2State *s =3D bs->opaque; - int64_t sector; - uint64_t limit, sbc; + int64_t offset; + uint64_t limit; uint64_t bm_size =3D bdrv_dirty_bitmap_size(bitmap); - uint64_t bm_sectors =3D DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); const char *bm_name =3D bdrv_dirty_bitmap_name(bitmap); uint8_t *buf =3D NULL; BdrvDirtyBitmapIter *dbi; @@ -1100,18 +1099,17 @@ static uint64_t *store_bitmap_data(BlockDriverState= *bs, dbi =3D bdrv_dirty_iter_new(bitmap); buf =3D g_malloc(s->cluster_size); limit =3D bytes_covered_by_bitmap_cluster(s, bitmap); - sbc =3D limit >> BDRV_SECTOR_BITS; assert(DIV_ROUND_UP(bm_size, limit) =3D=3D tb_size); - while ((sector =3D bdrv_dirty_iter_next(dbi) >> BDRV_SECTOR_BITS) >=3D= 0) { - uint64_t cluster =3D sector / sbc; + while ((offset =3D bdrv_dirty_iter_next(dbi)) >=3D 0) { + uint64_t cluster =3D offset / limit; uint64_t end, write_size; int64_t off; - sector =3D cluster * sbc; - end =3D MIN(bm_sectors, sector + sbc); - write_size =3D bdrv_dirty_bitmap_serialization_size(bitmap, - sector * BDRV_SECTOR_SIZE, (end - sector) * BDRV_SECTOR_SIZE); + offset =3D QEMU_ALIGN_DOWN(offset, limit); + end =3D MIN(bm_size, offset + limit); + write_size =3D bdrv_dirty_bitmap_serialization_size(bitmap, offset, + end - offset); assert(write_size <=3D s->cluster_size); off =3D qcow2_alloc_clusters(bs, s->cluster_size); @@ -1123,9 +1121,7 @@ static uint64_t *store_bitmap_data(BlockDriverState *= bs, } tb[cluster] =3D off; - bdrv_dirty_bitmap_serialize_part(bitmap, buf, - sector * BDRV_SECTOR_SIZE, - (end - sector) * BDRV_SECTOR_SIZE= ); + bdrv_dirty_bitmap_serialize_part(bitmap, buf, offset, end - offset= ); if (write_size < s->cluster_size) { memset(buf + write_size, 0, s->cluster_size - write_size); } @@ -1143,11 +1139,11 @@ static uint64_t *store_bitmap_data(BlockDriverState= *bs, goto fail; } - if (end >=3D bm_sectors) { + if (end >=3D bm_size) { break; } - bdrv_set_dirty_iter(dbi, end * BDRV_SECTOR_SIZE); + bdrv_set_dirty_iter(dbi, end); } *bitmap_table_size =3D tb_size; --=20 2.13.5