From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, armbru@redhat.com,
eblake@redhat.com, jsnow@redhat.com, famz@redhat.com,
den@openvz.org, stefanha@redhat.com, vsementsov@virtuozzo.com,
pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v20 25/30] qmp: add x-debug-block-dirty-bitmap-sha256
Date: Fri, 2 Jun 2017 14:21:53 +0300 [thread overview]
Message-ID: <20170602112158.232757-26-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20170602112158.232757-1-vsementsov@virtuozzo.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
---
block/dirty-bitmap.c | 5 +++++
blockdev.c | 29 +++++++++++++++++++++++++++++
include/block/dirty-bitmap.h | 2 ++
include/qemu/hbitmap.h | 8 ++++++++
qapi/block-core.json | 27 +++++++++++++++++++++++++++
tests/Makefile.include | 2 +-
util/hbitmap.c | 11 +++++++++++
7 files changed, 83 insertions(+), 1 deletion(-)
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index ca60602b48..2ae64fc9e8 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -621,3 +621,8 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
return bitmap == NULL ? QLIST_FIRST(&bs->dirty_bitmaps) :
QLIST_NEXT(bitmap, list);
}
+
+char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp)
+{
+ return hbitmap_sha256(bitmap->bitmap, errp);
+}
diff --git a/blockdev.c b/blockdev.c
index d04432172a..e3dbef7427 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2857,6 +2857,35 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
aio_context_release(aio_context);
}
+BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *node,
+ const char *name,
+ Error **errp)
+{
+ AioContext *aio_context;
+ BdrvDirtyBitmap *bitmap;
+ BlockDriverState *bs;
+ BlockDirtyBitmapSha256 *ret = NULL;
+ char *sha256;
+
+ bitmap = block_dirty_bitmap_lookup(node, name, &bs, &aio_context, errp);
+ if (!bitmap || !bs) {
+ return NULL;
+ }
+
+ sha256 = bdrv_dirty_bitmap_sha256(bitmap, errp);
+ if (sha256 == NULL) {
+ goto out;
+ }
+
+ ret = g_new(BlockDirtyBitmapSha256, 1);
+ ret->sha256 = sha256;
+
+out:
+ aio_context_release(aio_context);
+
+ return ret;
+}
+
void hmp_drive_del(Monitor *mon, const QDict *qdict)
{
const char *id = qdict_get_str(qdict, "id");
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index a3ac9c3640..00b298330c 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -90,4 +90,6 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
BdrvDirtyBitmap *bitmap);
+char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
+
#endif
diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
index b52304ac29..d3a74a21fc 100644
--- a/include/qemu/hbitmap.h
+++ b/include/qemu/hbitmap.h
@@ -253,6 +253,14 @@ void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count,
void hbitmap_deserialize_finish(HBitmap *hb);
/**
+ * hbitmap_sha256:
+ * @bitmap: HBitmap to operate on.
+ *
+ * Returns SHA256 hash of the last level.
+ */
+char *hbitmap_sha256(const HBitmap *bitmap, Error **errp);
+
+/**
* hbitmap_free:
* @hb: HBitmap to operate on.
*
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 9134a317e5..3dd9f92e5a 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1643,6 +1643,33 @@
'data': 'BlockDirtyBitmap' }
##
+# @BlockDirtyBitmapSha256:
+#
+# SHA256 hash of dirty bitmap data
+#
+# @sha256: ASCII representation of SHA256 bitmap hash
+#
+# Since: 2.10
+##
+ { 'struct': 'BlockDirtyBitmapSha256',
+ 'data': {'sha256': 'str'} }
+
+##
+# @x-debug-block-dirty-bitmap-sha256:
+#
+# Get bitmap SHA256
+#
+# Returns: BlockDirtyBitmapSha256 on success
+# If @node is not a valid block device, DeviceNotFound
+# If @name is not found or if hashing has failed, GenericError with an
+# explanation
+#
+# Since: 2.10
+##
+ { 'command': 'x-debug-block-dirty-bitmap-sha256',
+ 'data': 'BlockDirtyBitmap', 'returns': 'BlockDirtyBitmapSha256' }
+
+##
# @blockdev-mirror:
#
# Start mirroring a block device's writes to a new destination.
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 75893838e5..38dbd2d9c8 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -552,7 +552,7 @@ tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(test-u
tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-obj-y) $(test-util-obj-y)
tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y)
tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y)
-tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y)
+tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(test-crypto-obj-y)
tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o
tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o migration/page_cache.o $(test-util-obj-y)
tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 0c1591a594..21535cc90b 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -13,6 +13,7 @@
#include "qemu/hbitmap.h"
#include "qemu/host-utils.h"
#include "trace.h"
+#include "crypto/hash.h"
/* HBitmaps provides an array of bits. The bits are stored as usual in an
* array of unsigned longs, but HBitmap is also optimized to provide fast
@@ -727,3 +728,13 @@ void hbitmap_free_meta(HBitmap *hb)
hbitmap_free(hb->meta);
hb->meta = NULL;
}
+
+char *hbitmap_sha256(const HBitmap *bitmap, Error **errp)
+{
+ size_t size = bitmap->sizes[HBITMAP_LEVELS - 1] * sizeof(unsigned long);
+ char *data = (char *)bitmap->levels[HBITMAP_LEVELS - 1];
+ char *hash = NULL;
+ qcrypto_hash_digest(QCRYPTO_HASH_ALG_SHA256, data, size, &hash, errp);
+
+ return hash;
+}
--
2.11.1
next prev parent reply other threads:[~2017-06-02 11:22 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-02 11:21 [Qemu-devel] [PATCH v20 00/30] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 01/30] specs/qcow2: fix bitmap granularity qemu-specific note Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 02/30] specs/qcow2: do not use wording 'bitmap header' Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 03/30] hbitmap: improve dirty iter Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 04/30] tests: add hbitmap iter test Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 05/30] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 06/30] block/dirty-bitmap: add deserialize_ones func Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 07/30] qcow2-refcount: rename inc_refcounts() and make it public Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 08/30] qcow2: add bitmaps extension Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 09/30] block/dirty-bitmap: fix comment for BlockDirtyBitmap.disabled field Vladimir Sementsov-Ogievskiy
2017-06-02 21:02 ` John Snow
2017-06-09 12:29 ` Max Reitz
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 10/30] block/dirty-bitmap: add readonly field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2017-06-02 21:02 ` John Snow
2017-06-03 17:19 ` Sementsov-Ogievskiy Vladimir
2017-06-09 12:56 ` Max Reitz
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 11/30] qcow2: autoloading dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-06-02 21:48 ` John Snow
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 12/30] block: refactor bdrv_reopen_commit Vladimir Sementsov-Ogievskiy
2017-06-02 21:57 ` John Snow
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 13/30] block: new bdrv_reopen_bitmaps_rw interface Vladimir Sementsov-Ogievskiy
2017-06-02 22:17 ` John Snow
2017-06-03 16:53 ` Sementsov-Ogievskiy Vladimir
2017-06-09 13:27 ` Max Reitz
2017-06-13 10:25 ` Vladimir Sementsov-Ogievskiy
2017-06-13 15:28 ` Max Reitz
2017-06-14 9:03 ` Vladimir Sementsov-Ogievskiy
2017-06-14 12:04 ` Max Reitz
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 14/30] qcow2: support .bdrv_reopen_bitmaps_rw Vladimir Sementsov-Ogievskiy
2017-06-02 23:09 ` John Snow
2017-06-09 13:38 ` Max Reitz
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 15/30] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 16/30] block: bdrv_close: release bitmaps after drv->bdrv_close Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 17/30] block: introduce persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 18/30] block/dirty-bitmap: add bdrv_dirty_bitmap_next() Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 19/30] qcow2: add persistent dirty bitmaps support Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 20/30] qcow2: store bitmaps on reopening image as read-only Vladimir Sementsov-Ogievskiy
2017-06-09 13:48 ` Max Reitz
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 21/30] block: add bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 22/30] qcow2: add .bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 23/30] qmp: add persistent flag to block-dirty-bitmap-add Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 24/30] qmp: add autoload parameter " Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` Vladimir Sementsov-Ogievskiy [this message]
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 26/30] iotests: test qcow2 persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 27/30] block/dirty-bitmap: add bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 28/30] qcow2: add .bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 29/30] qmp: block-dirty-bitmap-remove: remove persistent Vladimir Sementsov-Ogievskiy
2017-06-02 11:21 ` [Qemu-devel] [PATCH v20 30/30] block: release persistent bitmaps on inactivate Vladimir Sementsov-Ogievskiy
2017-06-09 14:01 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170602112158.232757-26-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).