From patchwork Wed Jun 13 02:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 10461513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF4C960348 for ; Wed, 13 Jun 2018 02:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C412628C8F for ; Wed, 13 Jun 2018 02:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6D7F28DAE; Wed, 13 Jun 2018 02:20:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C041E28C8F for ; Wed, 13 Jun 2018 02:20:26 +0000 (UTC) Received: from localhost ([::1]:59399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSvOc-0003Qw-15 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Jun 2018 22:20:26 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 @@ /* 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 = 0, + BME_FLAG_BIT_IN_USE = BME_FLAG_BIT__BEGIN, + BME_FLAG_BIT_AUTO = 1, + BME_FLAG_BIT_EXTRA = 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] = { + [BME_FLAG_BIT_IN_USE] = BITMAP_FLAG_ENUM_IN_USE, + [BME_FLAG_BIT_AUTO] = BITMAP_FLAG_ENUM_AUTO, + [BME_FLAG_BIT_EXTRA] = BITMAP_FLAG_ENUM_EXTRA_DATA_COMPATIBLE, +}; /* 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) } } +static BitmapFlagEnumList *prepend_bitmap_flag(BitmapFlagEnumList *elist, + BitmapFlagEnum value) +{ + BitmapFlagEnumList *ftmp = g_new0(BitmapFlagEnumList, 1); + ftmp->value = value; + ftmp->next = elist; + return ftmp; +} + +static BitmapFlagEnumList *get_bitmap_flags(uint32_t flags) +{ + int i; + BitmapFlagEnumList *flist = NULL; + + if (flags & BME_RESERVED_FLAGS) { + flist = prepend_bitmap_flag(flist, BITMAP_FLAG_ENUM_RESERVED); + flags &= ~BME_RESERVED_FLAGS; + } + + while (flags) { + i = ctz32(flags); + assert(i >= BME_FLAG_BIT__BEGIN && i < BME_FLAG_BIT__MAX); + flist = prepend_bitmap_flag(flist, BMEFlagMap[i]); + flags &= ~(1 << i); + } + + return flist; +} + +BitmapInfoList *qcow2_get_bitmap_info(BlockDriverState *bs) +{ + Qcow2BitmapList *bm_list; + Qcow2Bitmap *bm; + BitmapInfoList *info_list = NULL; + BitmapInfoList *tmp; + BitmapInfo *bitmap_info; + + bm_list = get_bitmap_list(bs, NULL); + if (!bm_list) { + return info_list; + } + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + bitmap_info = g_new0(BitmapInfo, 1); + bitmap_info->name = g_strdup(bm->name); + if (bm->type == BT_DIRTY_TRACKING_BITMAP) { + bitmap_info->type = BITMAP_TYPE_ENUM_DIRTY_TRACKING; + } else { + bitmap_info->type = BITMAP_TYPE_ENUM_UNKNOWN; + } + bitmap_info->granularity = 1 << bm->granularity_bits; + bitmap_info->count = bdrv_get_dirty_count(bm->dirty_bitmap); + bitmap_info->extra_data = bm->extra_data_size > 0; + bitmap_info->flags = get_bitmap_flags(bm->flags); + bitmap_info->has_flags = !!bitmap_info->flags; + + tmp = g_new0(BitmapInfoList, 1); + tmp->value = bitmap_info; + tmp->next = info_list; + info_list = tmp; + } + + return info_list; +} + int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res, 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(BlockDriverState *bs) BDRVQcow2State *s = bs->opaque; ImageInfoSpecific *spec_info; QCryptoBlockInfo *encrypt_info = NULL; + BitmapInfoList *bitmap_list = NULL; if (s->crypto != NULL) { encrypt_info = qcrypto_block_get_info(s->crypto, &error_abort); @@ -4189,6 +4190,12 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs) spec_info->u.qcow2.data->encrypt = qencrypt; } + bitmap_list = qcow2_get_bitmap_info(bs); + if (bitmap_list) { + spec_info->u.qcow2.data->has_bitmaps = true; + spec_info->u.qcow2.data->bitmaps = bitmap_list; + } + return spec_info; } 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); #endif