From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528856918951445.99606646337156; Tue, 12 Jun 2018 19:28:38 -0700 (PDT) Received: from localhost ([::1]:59453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvWY-0000kZ-9o for importer@patchew.org; Tue, 12 Jun 2018 22:28:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAz-0001OU-OW for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001ej-UN for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53548 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAs-0001ZO-OD; Tue, 12 Jun 2018 22:06:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D5B5859AE; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07B8D2028674; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:04 -0400 Message-Id: <20180613020613.1343-2-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:14 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 01/10] qcow2/bitmap: remove redundant arguments from bitmap_list_load 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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 always call it with the same fields of the struct we always pass. We can split this out later if we really wind up needing to. Signed-off-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-bitmap.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 69485aa1de..0670e5eb41 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -535,8 +535,7 @@ static uint32_t bitmap_list_count(Qcow2BitmapList *bm_l= ist) * Get bitmap list from qcow2 image. Actually reads bitmap directory, * checks it and convert to bitmap list. */ -static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t of= fset, - uint64_t size, Error **errp) +static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, Error **err= p) { int ret; BDRVQcow2State *s =3D bs->opaque; @@ -544,6 +543,8 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, uint64_t offset, Qcow2BitmapDirEntry *e; uint32_t nb_dir_entries =3D 0; Qcow2BitmapList *bm_list =3D NULL; + uint64_t offset =3D s->bitmap_directory_offset; + uint64_t size =3D s->bitmap_directory_size; =20 if (size =3D=3D 0) { error_setg(errp, "Requested bitmap directory size is zero"); @@ -655,8 +656,7 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, return ret; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, NULL); + bm_list =3D bitmap_list_load(bs, NULL); if (bm_list =3D=3D NULL) { res->corruptions++; return -EINVAL; @@ -952,8 +952,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp) return false; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); + bm_list =3D bitmap_list_load(bs, errp); if (bm_list =3D=3D NULL) { return false; } @@ -1026,8 +1025,7 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs= , bool *header_updated, return -EINVAL; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); + bm_list =3D bitmap_list_load(bs, errp); if (bm_list =3D=3D NULL) { return -EINVAL; } @@ -1276,8 +1274,7 @@ void qcow2_remove_persistent_dirty_bitmap(BlockDriver= State *bs, return; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); + bm_list =3D bitmap_list_load(bs, errp); if (bm_list =3D=3D NULL) { return; } @@ -1329,8 +1326,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) if (s->nb_bitmaps =3D=3D 0) { bm_list =3D bitmap_list_new(); } else { - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); + bm_list =3D bitmap_list_load(bs, errp); if (bm_list =3D=3D NULL) { return; } @@ -1494,8 +1490,7 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverStat= e *bs, goto fail; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); + bm_list =3D bitmap_list_load(bs, errp); if (bm_list =3D=3D NULL) { goto fail; } --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528855784806349.36744544473606; Tue, 12 Jun 2018 19:09:44 -0700 (PDT) Received: from localhost ([::1]:59332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvEG-0003bc-1Y for importer@patchew.org; Tue, 12 Jun 2018 22:09:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAz-0001O4-Bd for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAy-0001eu-1q for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56544 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAt-0001Zb-2U; Tue, 12 Jun 2018 22:06:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93E0140AC6DF; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F52C20284E6; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:05 -0400 Message-Id: <20180613020613.1343-3-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 13 Jun 2018 02:06:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 13 Jun 2018 02:06:14 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 02/10] qcow2/bitmap: avoid adjusting bm->flags for RO bitmaps 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" Instead of always setting IN_USE, do this conditionally based on whether or not the bitmap is read-only. Eliminate the two-pass processing and move the second loop to the failure case. This will allow us to show the flags exactly as they appear on-disk for bitmaps in `qemu-img info`. Signed-off-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-bitmap.c | 51 +++++++++++++++++++++---------------------------= --- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 0670e5eb41..85c1b5afe3 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -919,13 +919,6 @@ fail: return ret; } =20 -/* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */ -static void release_dirty_bitmap_helper(gpointer bitmap, - gpointer bs) -{ - bdrv_release_dirty_bitmap(bs, bitmap); -} - /* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */ static void set_readonly_helper(gpointer bitmap, gpointer value) { @@ -944,8 +937,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp) BDRVQcow2State *s =3D bs->opaque; Qcow2BitmapList *bm_list; Qcow2Bitmap *bm; - GSList *created_dirty_bitmaps =3D NULL; - bool header_updated =3D false; + bool needs_update =3D false; =20 if (s->nb_bitmaps =3D=3D 0) { /* No bitmaps - nothing to do */ @@ -968,35 +960,34 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, E= rror **errp) bdrv_disable_dirty_bitmap(bitmap); } bdrv_dirty_bitmap_set_persistance(bitmap, true); - bm->flags |=3D BME_FLAG_IN_USE; - created_dirty_bitmaps =3D - g_slist_append(created_dirty_bitmaps, bitmap); - } - } - - if (created_dirty_bitmaps !=3D NULL) { - if (can_write(bs)) { - /* in_use flags must be updated */ - int ret =3D update_ext_header_and_dir_in_place(bs, bm_list); - if (ret < 0) { - error_setg_errno(errp, -ret, "Can't update bitmap director= y"); - goto fail; + if (can_write(bs)) { + bm->flags |=3D BME_FLAG_IN_USE; + needs_update =3D true; + } else { + bdrv_dirty_bitmap_set_readonly(bitmap, true); } - header_updated =3D true; - } else { - g_slist_foreach(created_dirty_bitmaps, set_readonly_helper, - (gpointer)true); } } =20 - g_slist_free(created_dirty_bitmaps); + /* in_use flags must be updated */ + if (needs_update) { + int ret =3D update_ext_header_and_dir_in_place(bs, bm_list); + if (ret < 0) { + error_setg_errno(errp, -ret, "Can't update bitmap directory"); + goto fail; + } + } + bitmap_list_free(bm_list); =20 - return header_updated; + return needs_update; =20 fail: - g_slist_foreach(created_dirty_bitmaps, release_dirty_bitmap_helper, bs= ); - g_slist_free(created_dirty_bitmaps); + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if (bm->dirty_bitmap) { + bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap); + } + } bitmap_list_free(bm_list); =20 return false; --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528855962674359.3526058517597; Tue, 12 Jun 2018 19:12:42 -0700 (PDT) Received: from localhost ([::1]:59354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvH7-0006Dg-Qz for importer@patchew.org; Tue, 12 Jun 2018 22:12:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvB0-0001P3-57 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAy-0001f4-3h for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53550 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAt-0001Zh-7q; Tue, 12 Jun 2018 22:06:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7A2A859B2; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9691F20284F0; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:06 -0400 Message-Id: <20180613020613.1343-4-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:14 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 03/10] qcow2/bitmap: cache bm_list 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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 don't need to re-read this list every time, exactly. We can keep it cach= ed and delete our copy when we flush to disk. Because we don't try to flush bitmaps on close if there's nothing to flush, add a new conditional to delete the state anyway for a clean exit. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 74 ++++++++++++++++++++++++++++++++++--------------= ---- block/qcow2.c | 2 ++ block/qcow2.h | 2 ++ 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 85c1b5afe3..5ae9b17928 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -636,6 +636,34 @@ fail: return NULL; } =20 +static Qcow2BitmapList *get_bitmap_list(BlockDriverState *bs, Error **errp) +{ + BDRVQcow2State *s =3D bs->opaque; + Qcow2BitmapList *bm_list; + + if (s->bitmap_list) { + return (Qcow2BitmapList *)s->bitmap_list; + } + + if (s->nb_bitmaps) { + bm_list =3D bitmap_list_load(bs, errp); + } else { + bm_list =3D bitmap_list_new(); + } + s->bitmap_list =3D bm_list; + return bm_list; +} + +static void del_bitmap_list(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + + if (s->bitmap_list) { + bitmap_list_free(s->bitmap_list); + s->bitmap_list =3D NULL; + } +} + int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, void **refcount_table, int64_t *refcount_table_size) @@ -656,7 +684,7 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, return ret; } =20 - bm_list =3D bitmap_list_load(bs, NULL); + bm_list =3D get_bitmap_list(bs, NULL); if (bm_list =3D=3D NULL) { res->corruptions++; return -EINVAL; @@ -706,8 +734,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, } =20 out: - bitmap_list_free(bm_list); - return ret; } =20 @@ -944,7 +970,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp) return false; } =20 - bm_list =3D bitmap_list_load(bs, errp); + bm_list =3D get_bitmap_list(bs, errp); if (bm_list =3D=3D NULL) { return false; } @@ -978,8 +1004,6 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Er= ror **errp) } } =20 - bitmap_list_free(bm_list); - return needs_update; =20 fail: @@ -988,8 +1012,7 @@ fail: bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap); } } - bitmap_list_free(bm_list); - + del_bitmap_list(bs); return false; } =20 @@ -1016,7 +1039,7 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs= , bool *header_updated, return -EINVAL; } =20 - bm_list =3D bitmap_list_load(bs, errp); + bm_list =3D get_bitmap_list(bs, errp); if (bm_list =3D=3D NULL) { return -EINVAL; } @@ -1056,7 +1079,6 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs= , bool *header_updated, =20 out: g_slist_free(ro_dirty_bitmaps); - bitmap_list_free(bm_list); =20 return ret; } @@ -1265,7 +1287,7 @@ void qcow2_remove_persistent_dirty_bitmap(BlockDriver= State *bs, return; } =20 - bm_list =3D bitmap_list_load(bs, errp); + bm_list =3D get_bitmap_list(bs, errp); if (bm_list =3D=3D NULL) { return; } @@ -1287,7 +1309,11 @@ void qcow2_remove_persistent_dirty_bitmap(BlockDrive= rState *bs, =20 fail: bitmap_free(bm); - bitmap_list_free(bm_list); +} + +void qcow2_persistent_dirty_bitmaps_cache_destroy(BlockDriverState *bs) +{ + del_bitmap_list(bs); } =20 void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) @@ -1304,23 +1330,19 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriv= erState *bs, Error **errp) =20 if (!bdrv_has_changed_persistent_bitmaps(bs)) { /* nothing to do */ - return; + goto out; } =20 if (!can_write(bs)) { error_setg(errp, "No write access"); - return; + goto out; } =20 QSIMPLEQ_INIT(&drop_tables); =20 - if (s->nb_bitmaps =3D=3D 0) { - bm_list =3D bitmap_list_new(); - } else { - bm_list =3D bitmap_list_load(bs, errp); - if (bm_list =3D=3D NULL) { - return; - } + bm_list =3D get_bitmap_list(bs, errp); + if (bm_list =3D=3D NULL) { + goto out; } =20 /* check constraints and names */ @@ -1400,8 +1422,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) g_free(tb); } =20 - bitmap_list_free(bm_list); - return; + goto out; =20 fail: QSIMPLEQ_FOREACH(bm, bm_list, entry) { @@ -1416,7 +1437,9 @@ fail: g_free(tb); } =20 - bitmap_list_free(bm_list); + out: + del_bitmap_list(bs); + return; } =20 int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp) @@ -1481,13 +1504,12 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverSt= ate *bs, goto fail; } =20 - bm_list =3D bitmap_list_load(bs, errp); + bm_list =3D get_bitmap_list(bs, errp); if (bm_list =3D=3D NULL) { goto fail; } =20 found =3D find_bitmap_by_name(bm_list, name); - bitmap_list_free(bm_list); if (found) { error_setg(errp, "Bitmap with the same name is already stored"); goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 6fa5e1d71a..dbd334b150 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2148,6 +2148,8 @@ static void qcow2_close(BlockDriverState *bs) =20 if (!(s->flags & BDRV_O_INACTIVE)) { qcow2_inactivate(bs); + } else { + qcow2_persistent_dirty_bitmaps_cache_destroy(bs); } =20 cache_clean_timer_del(bs); diff --git a/block/qcow2.h b/block/qcow2.h index 01b5250415..29b637a0ee 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -295,6 +295,7 @@ typedef struct BDRVQcow2State { uint64_t bitmap_directory_size; uint64_t bitmap_directory_offset; bool dirty_bitmaps_loaded; + void *bitmap_list; =20 int flags; int qcow_version; @@ -671,6 +672,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp); int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_update= d, Error **errp); int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); +void qcow2_persistent_dirty_bitmaps_cache_destroy(BlockDriverState *bs); void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs, --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528856295565283.92021474886826; Tue, 12 Jun 2018 19:18:15 -0700 (PDT) Received: from localhost ([::1]:59389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvMN-0001zy-Q3 for importer@patchew.org; Tue, 12 Jun 2018 22:18:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAy-0001N2-8F for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001de-3J for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53554 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAt-0001aA-Iw; Tue, 12 Jun 2018 22:06:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B5F5859BA; Wed, 13 Jun 2018 02:06:15 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE09D20284E6; Wed, 13 Jun 2018 02:06:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:07 -0400 Message-Id: <20180613020613.1343-5-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 04/10] qcow2/bitmap: cache loaded bitmaps 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" For bitmaps that we succeeded in loading, we can cache a reference to that object. This will let us iterate over the more convenient form of in-memory bitmaps for qemu-img bitmap manipulation tools. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 5ae9b17928..d94b6bd5cf 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -981,6 +981,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp) if (bitmap =3D=3D NULL) { goto fail; } + bm->dirty_bitmap =3D bitmap; =20 if (!(bm->flags & BME_FLAG_AUTO)) { bdrv_disable_dirty_bitmap(bitmap); @@ -1382,6 +1383,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) bm->name =3D g_strdup(name); QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry); } else { + assert(bitmap =3D=3D bm->dirty_bitmap); if (!(bm->flags & BME_FLAG_IN_USE)) { error_setg(errp, "Bitmap '%s' already exists in the image", name); --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528856816877457.6643553539093; Tue, 12 Jun 2018 19:26:56 -0700 (PDT) Received: from localhost ([::1]:59448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvUu-00085N-7N for importer@patchew.org; Tue, 12 Jun 2018 22:26:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAz-0001Ni-3Q for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001eP-KH for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52804 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAt-0001aO-Ry; Tue, 12 Jun 2018 22:06:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76C2F87A85; Wed, 13 Jun 2018 02:06:15 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3145C20284E4; Wed, 13 Jun 2018 02:06:15 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:08 -0400 Message-Id: <20180613020613.1343-6-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 13 Jun 2018 02:06:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 13 Jun 2018 02:06:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 05/10] qcow2/bitmap: reject IN_USE bitmaps on rw reload 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" Presently, an image with IN_USE bitmaps cannot be loaded as RO. In preparation for changing that, IN_USE bitmaps ought to create an error on reload instead of being skipped. While we're here, update the function to work with two new facts: - All bm_list entries will have a BdrvDirtyBitmap (because we load and disable bitmaps when the autoload flag isn't set), and - The dirty_bitmap will be cached, so we don't have to look it up. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index d94b6bd5cf..859819639b 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1046,23 +1046,22 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *= bs, bool *header_updated, } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { - if (!(bm->flags & BME_FLAG_IN_USE)) { - BdrvDirtyBitmap *bitmap =3D bdrv_find_dirty_bitmap(bs, bm->nam= e); - if (bitmap =3D=3D NULL) { - continue; - } - - if (!bdrv_dirty_bitmap_readonly(bitmap)) { - error_setg(errp, "Bitmap %s is not readonly but not marked" - "'IN_USE' in the image. Something went wr= ong," - "all the bitmaps may be corrupted", bm->n= ame); - ret =3D -EINVAL; - goto out; - } - - bm->flags |=3D BME_FLAG_IN_USE; - ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bitmap); + if (bm->flags & BME_FLAG_IN_USE) { + error_setg(errp, "Bitmap '%s' is in use; can't reopen RW", + bm->name); + ret =3D -EINVAL; + goto out; + } else if (!bdrv_dirty_bitmap_readonly(bm->dirty_bitmap)) { + error_setg(errp, "Bitmap %s is neither readonly nor 'IN_USE' i= n " + "the image. Something went wrong, all the bitmaps m= ay " + "be corrupted. Please report this to the developers= at " + " qemu-devel@nongnu.org", bm->name); + ret =3D -EINVAL; + goto out; } + + bm->flags |=3D BME_FLAG_IN_USE; + ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bm->dirty_bi= tmap); } =20 if (ro_dirty_bitmaps !=3D NULL) { --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528855922687817.507574423797; Tue, 12 Jun 2018 19:12:02 -0700 (PDT) Received: from localhost ([::1]:59352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvGP-0005d6-4t for importer@patchew.org; Tue, 12 Jun 2018 22:11:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAy-0001NM-Ma for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001dw-B0 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53558 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAu-0001aZ-6F; Tue, 12 Jun 2018 22:06:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C00E6859BF; Wed, 13 Jun 2018 02:06:15 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C14720284E8; Wed, 13 Jun 2018 02:06:15 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:09 -0400 Message-Id: <20180613020613.1343-7-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 06/10] qcow2/bitmap: load IN_USE bitmaps if disk is RO 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" For the purposes of qemu-img manipulation and querying of bitmaps, load bitmaps that are "in use" -- if the image is read only. This will allow us to diagnose problems with this flag using the qemu-img tool. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 859819639b..6c4fe9b281 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -345,7 +345,7 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *b= s, uint32_t granularity; BdrvDirtyBitmap *bitmap =3D NULL; =20 - if (bm->flags & BME_FLAG_IN_USE) { + if (can_write(bs) && (bm->flags & BME_FLAG_IN_USE)) { error_setg(errp, "Bitmap '%s' is in use", bm->name); goto fail; } @@ -976,23 +976,21 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, E= rror **errp) } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { - if (!(bm->flags & BME_FLAG_IN_USE)) { - BdrvDirtyBitmap *bitmap =3D load_bitmap(bs, bm, errp); - if (bitmap =3D=3D NULL) { - goto fail; - } - bm->dirty_bitmap =3D bitmap; + BdrvDirtyBitmap *bitmap =3D load_bitmap(bs, bm, errp); + if (bitmap =3D=3D NULL) { + goto fail; + } + bm->dirty_bitmap =3D bitmap; =20 - if (!(bm->flags & BME_FLAG_AUTO)) { - bdrv_disable_dirty_bitmap(bitmap); - } - bdrv_dirty_bitmap_set_persistance(bitmap, true); - if (can_write(bs)) { - bm->flags |=3D BME_FLAG_IN_USE; - needs_update =3D true; - } else { - bdrv_dirty_bitmap_set_readonly(bitmap, true); - } + if (!(bm->flags & BME_FLAG_AUTO)) { + bdrv_disable_dirty_bitmap(bitmap); + } + bdrv_dirty_bitmap_set_persistance(bitmap, true); + if (can_write(bs)) { + bm->flags |=3D BME_FLAG_IN_USE; + needs_update =3D true; + } else { + bdrv_dirty_bitmap_set_readonly(bitmap, true); } } =20 --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152885607871488.9513459635682; Tue, 12 Jun 2018 19:14:38 -0700 (PDT) Received: from localhost ([::1]:59365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvIz-0007sy-Uv for importer@patchew.org; Tue, 12 Jun 2018 22:14:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAz-0001Nk-4C for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001eG-Hd for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56550 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAu-0001aw-Hc; Tue, 12 Jun 2018 22:06:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 150214000D08; Wed, 13 Jun 2018 02:06:16 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id C519120284EF; Wed, 13 Jun 2018 02:06:15 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:10 -0400 Message-Id: <20180613020613.1343-8-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 13 Jun 2018 02:06:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 13 Jun 2018 02:06:16 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 07/10] qcow2/bitmap: track bitmap type 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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 only have one type of persistent bitmap right now, but I'd like the qemu-img tool to be able to give good diagnostic information if it sees an unknown/unsupported type. We do enforce it to be the dirty tracking type in check_dir_entry, but I wanted positive affirmation of the type in the forthcoming info script. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 6c4fe9b281..36573f7b52 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -83,6 +83,7 @@ typedef QSIMPLEQ_HEAD(Qcow2BitmapTableList, Qcow2BitmapTa= ble) typedef struct Qcow2Bitmap { Qcow2BitmapTable table; uint32_t flags; + uint8_t type; uint8_t granularity_bits; char *name; =20 @@ -607,6 +608,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, Error **errp) bm->table.offset =3D e->bitmap_table_offset; bm->table.size =3D e->bitmap_table_size; bm->flags =3D e->flags; + bm->type =3D e->type; bm->granularity_bits =3D e->granularity_bits; bm->name =3D dir_entry_copy_name(e); QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry); @@ -777,7 +779,7 @@ static int bitmap_list_store(BlockDriverState *bs, Qcow= 2BitmapList *bm_list, e->bitmap_table_offset =3D bm->table.offset; e->bitmap_table_size =3D bm->table.size; e->flags =3D bm->flags; - e->type =3D BT_DIRTY_TRACKING_BITMAP; + e->type =3D bm->type; e->granularity_bits =3D bm->granularity_bits; e->name_size =3D strlen(bm->name); e->extra_data_size =3D 0; @@ -1393,6 +1395,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) } bm->flags =3D bdrv_dirty_bitmap_enabled(bitmap) ? BME_FLAG_AUTO : = 0; bm->granularity_bits =3D ctz32(bdrv_dirty_bitmap_granularity(bitma= p)); + bm->type =3D BT_DIRTY_TRACKING_BITMAP; bm->dirty_bitmap =3D bitmap; } =20 --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528856678427791.5594530074069; Tue, 12 Jun 2018 19:24:38 -0700 (PDT) Received: from localhost ([::1]:59437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvSd-0006Zr-N4 for importer@patchew.org; Tue, 12 Jun 2018 22:24:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAy-0001NG-Hh for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001e6-CO for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53562 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAu-0001bC-PP; Tue, 12 Jun 2018 22:06:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 651668886E; Wed, 13 Jun 2018 02:06:16 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 239FE20284E6; Wed, 13 Jun 2018 02:06:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:11 -0400 Message-Id: <20180613020613.1343-9-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:16 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 08/10] qcow2/bitmap: track extra_data_size 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" Similarly to the last patch, track the extra_data_size field that we read. We do reject anything other than zero, but if this restriction is lifted in the future, we'll need to update the _info field, so loosen this now. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 36573f7b52..3c2e974458 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -86,6 +86,7 @@ typedef struct Qcow2Bitmap { uint8_t type; uint8_t granularity_bits; char *name; + uint32_t extra_data_size; =20 BdrvDirtyBitmap *dirty_bitmap; =20 @@ -609,6 +610,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, Error **errp) bm->table.size =3D e->bitmap_table_size; bm->flags =3D e->flags; bm->type =3D e->type; + bm->extra_data_size =3D e->extra_data_size; bm->granularity_bits =3D e->granularity_bits; bm->name =3D dir_entry_copy_name(e); QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry); @@ -782,7 +784,7 @@ static int bitmap_list_store(BlockDriverState *bs, Qcow= 2BitmapList *bm_list, e->type =3D bm->type; e->granularity_bits =3D bm->granularity_bits; e->name_size =3D strlen(bm->name); - e->extra_data_size =3D 0; + e->extra_data_size =3D bm->extra_data_size; memcpy(e + 1, bm->name, e->name_size); =20 if (check_dir_entry(bs, e) < 0) { --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528856248265733.6951049598017; Tue, 12 Jun 2018 19:17:28 -0700 (PDT) Received: from localhost ([::1]:59388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvLa-0001QZ-0N for importer@patchew.org; Tue, 12 Jun 2018 22:17:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvAz-0001OD-Hk for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAx-0001eo-Uo for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53566 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAv-0001bP-2U; Tue, 12 Jun 2018 22:06:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0DF38A3C3; Wed, 13 Jun 2018 02:06:16 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BC8E20284E5; Wed, 13 Jun 2018 02:06:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:12 -0400 Message-Id: <20180613020613.1343-10-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 13 Jun 2018 02:06:16 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 09/10] qapi: add bitmap info 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" Add some of the necessary scaffolding for reporting bitmap information. Signed-off-by: John Snow --- qapi/block-core.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index fff23fc82b..da82a82779 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -34,6 +34,65 @@ 'date-sec': 'int', 'date-nsec': 'int', 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } } =20 +## +# @BitmapTypeEnum: +# +# An enumeration of possible serialized bitmap types. +# +# @dirty-tracking: This bitmap records information on dirty +# segments within the file. +# +# @unknown: This bitmap is an unknown/reserved type. +# +# Since: 3.0 +## +{ 'enum': 'BitmapTypeEnum', 'data': [ 'dirty-tracking', 'unknown' ] } + +## +# @BitmapFlagEnum: +# +# An enumeration of possible flags for serialized bitmaps. +# +# @in-use: This bitmap is considered to be in-use, and may now be inconsis= tent. +# +# @auto: This bitmap must reflect any and all changes to the file it descr= ibes. +# +# @extra-data-compatible: The extra data associated with this bitmap can be +# safely ignored if it is opaque to the reader. If +# this flag is absent while extra data is present = and +# opaque to the reader, the bitmap must not be use= d. +# +# @reserved: This bitmap has reserved flags set. +# +# Since: 3.0 +## +{ 'enum': 'BitmapFlagEnum', 'data': [ 'in-use', 'auto', + 'extra-data-compatible', 'reserved' = ] } + +## +# @BitmapInfo: +# +# @name: The name of the bitmap. +# +# @type: The type of bitmap. +# +# @granularity: Bitmap granularity, in bytes. +# +# @count: Overall bitmap dirtiness, in bytes. +# +# @extra-data: True if this bitmap has extra data attached. +# +# @flags: Bitmap flags, if any. +# +# Since: 3.0 +# +## +{ 'struct': 'BitmapInfo', + 'data': { 'name': 'str', 'type': 'BitmapTypeEnum', 'granularity': 'int', + 'count': 'int', 'extra-data': 'bool', '*flags': ['BitmapFlagEn= um'] + } +} + ## # @ImageInfoSpecificQCow2EncryptionBase: # @@ -70,6 +129,8 @@ # @encrypt: details about encryption parameters; only set if image # is encrypted (since 2.10) # +# @bitmaps: list of image bitmaps (since 3.0) +# # Since: 1.7 ## { 'struct': 'ImageInfoSpecificQCow2', @@ -78,7 +139,8 @@ '*lazy-refcounts': 'bool', '*corrupt': 'bool', 'refcount-bits': 'int', - '*encrypt': 'ImageInfoSpecificQCow2Encryption' + '*encrypt': 'ImageInfoSpecificQCow2Encryption', + '*bitmaps': ['BitmapInfo'] } } =20 ## --=20 2.14.3 From nobody Sat Apr 20 11:49: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.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528856411118414.07678513649023; Tue, 12 Jun 2018 19:20:11 -0700 (PDT) Received: from localhost ([::1]:59399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvOH-0003Qw-DE for importer@patchew.org; Tue, 12 Jun 2018 22:20:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvB0-0001Po-Ju for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSvAz-0001gB-90 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 22:06:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40396 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSvAv-0001bd-D0; Tue, 12 Jun 2018 22:06:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 049EB401EF30; Wed, 13 Jun 2018 02:06:17 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id B722620284E5; Wed, 13 Jun 2018 02:06:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 22:06:13 -0400 Message-Id: <20180613020613.1343-11-jsnow@redhat.com> In-Reply-To: <20180613020613.1343-1-jsnow@redhat.com> References: <20180613020613.1343-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 13 Jun 2018 02:06:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 13 Jun 2018 02:06:17 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 10/10] qcow2/bitmap: add basic bitmaps info 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 , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Max Reitz , John Snow 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" Add functions for querying the basic information inside of bitmaps. Restructure the bitmaps flags masks to facilitate providing a list of flags belonging to the bitmap(s) being queried. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++= ++-- block/qcow2.c | 7 +++++ block/qcow2.h | 1 + 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 3c2e974458..80bd31bfc1 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -49,8 +49,25 @@ =20 /* Bitmap directory entry flags */ #define BME_RESERVED_FLAGS 0xfffffffcU -#define BME_FLAG_IN_USE (1U << 0) -#define BME_FLAG_AUTO (1U << 1) + +enum BME_FLAG_BITS { + BME_FLAG_BIT__BEGIN =3D 0, + BME_FLAG_BIT_IN_USE =3D BME_FLAG_BIT__BEGIN, + BME_FLAG_BIT_AUTO =3D 1, + BME_FLAG_BIT_EXTRA =3D 2, + BME_FLAG_BIT__MAX, +}; + +#define BME_FLAG_IN_USE (1U << BME_FLAG_BIT_IN_USE) +#define BME_FLAG_AUTO (1U << BME_FLAG_BIT_AUTO) +#define BME_FLAG_EXTRA (1U << BME_FLAG_BIT_EXTRA) + +/* Correlate canonical spec values to autogenerated QAPI values */ +int BMEFlagMap[BME_FLAG_BIT__MAX] =3D { + [BME_FLAG_BIT_IN_USE] =3D BITMAP_FLAG_ENUM_IN_USE, + [BME_FLAG_BIT_AUTO] =3D BITMAP_FLAG_ENUM_AUTO, + [BME_FLAG_BIT_EXTRA] =3D BITMAP_FLAG_ENUM_EXTRA_DATA_COMPATIBLE, +}; =20 /* bits [1, 8] U [56, 63] are reserved */ #define BME_TABLE_ENTRY_RESERVED_MASK 0xff000000000001feULL @@ -668,6 +685,71 @@ static void del_bitmap_list(BlockDriverState *bs) } } =20 +static BitmapFlagEnumList *prepend_bitmap_flag(BitmapFlagEnumList *elist, + BitmapFlagEnum value) +{ + BitmapFlagEnumList *ftmp =3D g_new0(BitmapFlagEnumList, 1); + ftmp->value =3D value; + ftmp->next =3D elist; + return ftmp; +} + +static BitmapFlagEnumList *get_bitmap_flags(uint32_t flags) +{ + int i; + BitmapFlagEnumList *flist =3D NULL; + + if (flags & BME_RESERVED_FLAGS) { + flist =3D prepend_bitmap_flag(flist, BITMAP_FLAG_ENUM_RESERVED); + flags &=3D ~BME_RESERVED_FLAGS; + } + + while (flags) { + i =3D ctz32(flags); + assert(i >=3D BME_FLAG_BIT__BEGIN && i < BME_FLAG_BIT__MAX); + flist =3D prepend_bitmap_flag(flist, BMEFlagMap[i]); + flags &=3D ~(1 << i); + } + + return flist; +} + +BitmapInfoList *qcow2_get_bitmap_info(BlockDriverState *bs) +{ + Qcow2BitmapList *bm_list; + Qcow2Bitmap *bm; + BitmapInfoList *info_list =3D NULL; + BitmapInfoList *tmp; + BitmapInfo *bitmap_info; + + bm_list =3D get_bitmap_list(bs, NULL); + if (!bm_list) { + return info_list; + } + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + bitmap_info =3D g_new0(BitmapInfo, 1); + bitmap_info->name =3D g_strdup(bm->name); + if (bm->type =3D=3D BT_DIRTY_TRACKING_BITMAP) { + bitmap_info->type =3D BITMAP_TYPE_ENUM_DIRTY_TRACKING; + } else { + bitmap_info->type =3D BITMAP_TYPE_ENUM_UNKNOWN; + } + bitmap_info->granularity =3D 1 << bm->granularity_bits; + bitmap_info->count =3D bdrv_get_dirty_count(bm->dirty_bitmap); + bitmap_info->extra_data =3D bm->extra_data_size > 0; + bitmap_info->flags =3D get_bitmap_flags(bm->flags); + bitmap_info->has_flags =3D !!bitmap_info->flags; + + tmp =3D g_new0(BitmapInfoList, 1); + tmp->value =3D bitmap_info; + tmp->next =3D info_list; + info_list =3D tmp; + } + + return info_list; +} + int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, void **refcount_table, int64_t *refcount_table_size) diff --git a/block/qcow2.c b/block/qcow2.c index dbd334b150..2a52771ac8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4133,6 +4133,7 @@ static ImageInfoSpecific *qcow2_get_specific_info(Blo= ckDriverState *bs) BDRVQcow2State *s =3D bs->opaque; ImageInfoSpecific *spec_info; QCryptoBlockInfo *encrypt_info =3D NULL; + BitmapInfoList *bitmap_list =3D NULL; =20 if (s->crypto !=3D NULL) { encrypt_info =3D qcrypto_block_get_info(s->crypto, &error_abort); @@ -4189,6 +4190,12 @@ static ImageInfoSpecific *qcow2_get_specific_info(Bl= ockDriverState *bs) spec_info->u.qcow2.data->encrypt =3D qencrypt; } =20 + bitmap_list =3D qcow2_get_bitmap_info(bs); + if (bitmap_list) { + spec_info->u.qcow2.data->has_bitmaps =3D true; + spec_info->u.qcow2.data->bitmaps =3D bitmap_list; + } + return spec_info; } =20 diff --git a/block/qcow2.h b/block/qcow2.h index 29b637a0ee..d3fe766a1f 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -682,5 +682,6 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverState = *bs, void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, Error **errp); +BitmapInfoList *qcow2_get_bitmap_info(BlockDriverState *bs); =20 #endif --=20 2.14.3