From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6Msw-0003J6-AK for qemu-devel@nongnu.org; Mon, 14 Nov 2016 14:25:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6Msv-0000H2-8i for qemu-devel@nongnu.org; Mon, 14 Nov 2016 14:25:42 -0500 References: <1478715476-132280-1-git-send-email-vsementsov@virtuozzo.com> <1478715476-132280-19-git-send-email-vsementsov@virtuozzo.com> From: John Snow Message-ID: <80172069-b3cd-9d6b-a9e1-fb0b89f8e64b@redhat.com> Date: Mon, 14 Nov 2016 14:25:33 -0500 MIME-Version: 1.0 In-Reply-To: <1478715476-132280-19-git-send-email-vsementsov@virtuozzo.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 18/21] qmp: add x-debug-block-dirty-bitmap-sha256 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, den@openvz.org On 11/09/2016 01:17 PM, Vladimir Sementsov-Ogievskiy wrote: > Signed-off-by: Vladimir Sementsov-Ogievskiy > --- > block/dirty-bitmap.c | 5 +++++ > blockdev.c | 33 +++++++++++++++++++++++++++++++++ > include/block/dirty-bitmap.h | 2 ++ > include/qemu/hbitmap.h | 8 ++++++++ > qapi/block-core.json | 26 ++++++++++++++++++++++++++ > util/hbitmap.c | 11 +++++++++++ > 6 files changed, 85 insertions(+) > > diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c > index fe34d48..775181c 100644 > --- a/block/dirty-bitmap.c > +++ b/block/dirty-bitmap.c > @@ -589,3 +589,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 db2bdbb..c028070 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -2811,6 +2811,39 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name, > aio_context_release(aio_context); > } > > +/** > + * Completely clear a bitmap, for the purposes of synchronizing a bitmap > + * immediately after a full backup operation. > + */ > +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 d71edc4..b022b34 100644 > --- a/include/block/dirty-bitmap.h > +++ b/include/block/dirty-bitmap.h > @@ -86,4 +86,6 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, > > bool bdrv_has_persistent_bitmaps(BlockDriverState *bs); > > +char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp); > + > #endif > diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h > index 5c9dd74..d6f3838 100644 > --- a/include/qemu/hbitmap.h > +++ b/include/qemu/hbitmap.h > @@ -240,6 +240,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 2c33a30..f72cfef 100644 > --- a/qapi/block-core.json > +++ b/qapi/block-core.json > @@ -1289,6 +1289,32 @@ > 'data': 'BlockDirtyBitmap' } > > ## > +# @BlockDirtyBitmapSha256: > +# > +# SHA256 hash of dirty bitmap data > +# > +# @sha256: bitmap SHA256 hash > +# > +# Since: 2.8 > +## > + { '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, GenericError with an explanation > +# > +# Since 2.8 > +## > + { '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/util/hbitmap.c b/util/hbitmap.c > index 72623f4..96af071 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 > @@ -707,3 +708,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); By adding this here, you're adding a linking dependency to libqemuutil.a, which causes the test-hbitmap test to fail to link from this patch forward. I'm not sure what the correct approach should be, but at a minimum we need to link crypto/hash.o to test/test-hbitmap.o to be able to run that test. We get build failures otherwise. > + > + return hash; > +} >