From nobody Mon Feb 9 09:34:00 2026 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 1494967809374164.33751073494125; Tue, 16 May 2017 13:50:09 -0700 (PDT) Received: from localhost ([::1]:43951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAjPz-00047b-Vn for importer@patchew.org; Tue, 16 May 2017 16:50:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAjNl-0002eg-9j for qemu-devel@nongnu.org; Tue, 16 May 2017 16:47:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dAjNk-0003af-CZ for qemu-devel@nongnu.org; Tue, 16 May 2017 16:47:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dAjNe-0003TS-LI; Tue, 16 May 2017 16:47:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C4DE7F6C7; Tue, 16 May 2017 20:47:41 +0000 (UTC) Received: from red.redhat.com (ovpn-123-244.rdu2.redhat.com [10.10.123.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57D4C5C466; Tue, 16 May 2017 20:47:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6C4DE7F6C7 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 6C4DE7F6C7 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 16 May 2017 15:47:16 -0500 Message-Id: <20170516204724.1617-5-eblake@redhat.com> In-Reply-To: <20170516204724.1617-1-eblake@redhat.com> References: <20170516204724.1617-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 16 May 2017 20:47:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 04/12] dirty-bitmap: Track size in 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 , 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 still using an internal hbitmap that tracks a size in sectors, with the granularity scaled down accordingly, because it lets us use a shortcut for our iterators which are currently sector-based. But there's no reason we can't track the dirty bitmap size in bytes, since it is an internal-only variable. Use is_power_of_2() while at it, instead of open-coding that. Signed-off-by: Eric Blake Reviewed-by: John Snow --- v2: tweak commit message, no code change --- block/dirty-bitmap.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 32698d5..a413df1 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -41,7 +41,7 @@ struct BdrvDirtyBitmap { HBitmap *meta; /* Meta dirty bitmap */ BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status = */ char *name; /* Optional non-empty unique ID */ - int64_t size; /* Size of the bitmap (Number of sectors) = */ + int64_t size; /* Size of the bitmap, in bytes */ bool disabled; /* Bitmap is read-only */ int active_iterators; /* How many iterators are active */ QLIST_ENTRY(BdrvDirtyBitmap) list; @@ -79,24 +79,26 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverSt= ate *bs, { int64_t bitmap_size; BdrvDirtyBitmap *bitmap; - uint32_t sector_granularity; - assert((granularity & (granularity - 1)) =3D=3D 0); + assert(is_power_of_2(granularity) && granularity >=3D BDRV_SECTOR_SIZE= ); if (name && bdrv_find_dirty_bitmap(bs, name)) { error_setg(errp, "Bitmap already exists: %s", name); return NULL; } - sector_granularity =3D granularity >> BDRV_SECTOR_BITS; - assert(sector_granularity); - bitmap_size =3D bdrv_nb_sectors(bs); + bitmap_size =3D bdrv_getlength(bs); if (bitmap_size < 0) { error_setg_errno(errp, -bitmap_size, "could not get length of devi= ce"); errno =3D -bitmap_size; return NULL; } bitmap =3D g_new0(BdrvDirtyBitmap, 1); - bitmap->bitmap =3D hbitmap_alloc(bitmap_size, ctz32(sector_granularity= )); + /* + * TODO - let hbitmap track full granularity. For now, it is tracking + * only sector granularity, as a shortcut for our iterators. + */ + bitmap->bitmap =3D hbitmap_alloc(bitmap_size >> BDRV_SECTOR_BITS, + ctz32(granularity) - BDRV_SECTOR_BITS); bitmap->size =3D bitmap_size; bitmap->name =3D g_strdup(name); bitmap->disabled =3D false; @@ -246,12 +248,13 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDrive= rState *bs, void bdrv_dirty_bitmap_truncate(BlockDriverState *bs) { BdrvDirtyBitmap *bitmap; - uint64_t size =3D bdrv_nb_sectors(bs); + int64_t size =3D bdrv_getlength(bs); + assert(size >=3D 0); QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); assert(!bitmap->active_iterators); - hbitmap_truncate(bitmap->bitmap, size); + hbitmap_truncate(bitmap->bitmap, size >> BDRV_SECTOR_BITS); bitmap->size =3D size; } } @@ -419,7 +422,7 @@ void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, H= Bitmap **out) hbitmap_reset_all(bitmap->bitmap); } else { HBitmap *backup =3D bitmap->bitmap; - bitmap->bitmap =3D hbitmap_alloc(bitmap->size, + bitmap->bitmap =3D hbitmap_alloc(bitmap->size >> BDRV_SECTOR_BITS, hbitmap_granularity(backup)); *out =3D backup; } --=20 2.9.4