qapi: block-dirty-bitmap-remove transaction action
v2 cover qapi: block-dirty-bitmap-remove transaction action
Hi, this is a proposal based off of Vladimir's patchset:
[Qemu-devel] [PATCH 0/4] qapi: block-dirty-bitmap-remove transaction action
It replaces patches two and three with a modified patch (now patch 2) that foregoes the need for a hide()/unhide() bitmap API. I think it's suitable as a smaller alternative, but I'm not sure if it covers all of the use cases of the original series.
Patches 1 and 3 (formerly 4) included as-is.
John Snow (1):
qapi: implement block-dirty-bitmap-remove transaction action
Vladimir Sementsov-Ogievskiy (2):
blockdev: reduce aio_context locked sections in bitmap add/remove
iotests: test bitmap moving inside 254
qapi/transaction.json | 2 + include/block/dirty-bitmap.h | 3 +- block.c | 2 +- block/dirty-bitmap.c | 16 ++--- blockdev.c | 105 ++++++++++++++++++++++++++------- migration/block-dirty-bitmap.c | 2 +- tests/qemu-iotests/254 | 30 +++++++++- tests/qemu-iotests/254.out | 82 +++++++++++++++++++++++++ 8 files changed, 208 insertions(+), 34 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/3 blockdev: reduce aio_context locked sections in bitmap add/remove
From: Vladimir Sementsov-Ogievskiy <[email protected]>
Commit 0a6c86d024c52 returned these locks back to add/remove functionality, to protect from intersection of persistent bitmap related IO with other IO. But other bitmap-related functions called here are unrelated to the problem, and there are no needs to keep these calls inside critical sections.
--- blockdev.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
blockdev.c +13 -17
@@ -2811,7 +2811,6 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name, {BlockDriverState *bs;BdrvDirtyBitmap *bitmap; -AioContext *aio_context =NULL ;if (!name || name[0 ] =='\0' ) {error_setg (errp,"Bitmap name cannot be empty" );
@@ -2847,16 +2846,20 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name, }if (persistent) { - aio_context =bdrv_get_aio_context (bs); +AioContext *aio_context =bdrv_get_aio_context (bs); +bool ok; +aio_context_acquire (aio_context); -if (!bdrv_can_store_new_dirty_bitmap (bs, name, granularity, errp)) { - goto out; + ok =bdrv_can_store_new_dirty_bitmap (bs, name, granularity, errp); +aio_context_release (aio_context); +if (!ok) { +return ; } } bitmap =bdrv_create_dirty_bitmap (bs, granularity, name, errp);if (bitmap ==NULL ) { - goto out; +return ; }if (disabled) {
@@ -2864,10 +2867,6 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name, }bdrv_dirty_bitmap_set_persistence (bitmap, persistent); - out: -if (aio_context) { -aio_context_release (aio_context); - } } void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
@@ -2875,8 +2874,6 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name, {BlockDriverState *bs;BdrvDirtyBitmap *bitmap; -Error *local_err =NULL ; -AioContext *aio_context =NULL ; bitmap =block_dirty_bitmap_lookup (node, name, &bs, errp);if (!bitmap || !bs) {
@@ -2889,20 +2886,19 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name, }if (bdrv_dirty_bitmap_get_persistence (bitmap)) { - aio_context =bdrv_get_aio_context (bs); +AioContext *aio_context =bdrv_get_aio_context (bs); +Error *local_err =NULL ; +aio_context_acquire (aio_context);bdrv_remove_persistent_dirty_bitmap (bs, name, &local_err); +aio_context_release (aio_context);if (local_err !=NULL ) {error_propagate (errp, local_err); - goto out; +return ; } }bdrv_release_dirty_bitmap (bs, bitmap); - out: -if (aio_context) { -aio_context_release (aio_context); - } }/**
Signature · 1 line
2.21.0
PATCH v2 2/3 qapi: implement block-dirty-bitmap-remove transaction action
In reply to John SnowIt is used to do transactional movement of the bitmap (which is possible in conjunction with merge command). Transactional bitmap movement is needed in scenarios with external snapshot, when we don't want to leave copy of the bitmap in the base image.
--- qapi/transaction.json | 2 + include/block/dirty-bitmap.h | 3 +- block.c | 2 +- block/dirty-bitmap.c | 16 +++---- blockdev.c | 79 +++++++++++++++++++++++++++++++--- migration/block-dirty-bitmap.c | 2 +- 6 files changed, 87 insertions(+), 17 deletions(-)
qapi/transaction.json +2 -0
@@ -45,6 +45,7 @@ # # - @abort: since 1.6 # - @block-dirty-bitmap-add: since 2.5 +# - @block-dirty-bitmap-remove: since 4.1 # - @block-dirty-bitmap-clear: since 2.5 # - @block-dirty-bitmap-enable: since 4.0 # - @block-dirty-bitmap-disable: since 4.0
@@ -61,6 +62,7 @@ 'data': { 'abort': 'Abort', 'block-dirty-bitmap-add': 'BlockDirtyBitmapAdd', + 'block-dirty-bitmap-remove': 'BlockDirtyBitmap', 'block-dirty-bitmap-clear': 'BlockDirtyBitmap', 'block-dirty-bitmap-enable': 'BlockDirtyBitmap', 'block-dirty-bitmap-disable': 'BlockDirtyBitmap',
include/block/dirty-bitmap.h +2 -1
@@ -83,7 +83,8 @@ void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);void bdrv_dirty_bitmap_set_busy (BdrvDirtyBitmap *bitmap,bool busy);void bdrv_merge_dirty_bitmap (BdrvDirtyBitmap *dest,const BdrvDirtyBitmap *src,HBitmap **backup,Error **errp); -void bdrv_dirty_bitmap_set_migration (BdrvDirtyBitmap *bitmap,bool migration); +void bdrv_dirty_bitmap_squelch_persistence (BdrvDirtyBitmap *bitmap, +bool squelch);/* Functions that require manual locking. */ void bdrv_dirty_bitmap_lock (BdrvDirtyBitmap *bitmap);
block.c +1 -1
@@ -5316,7 +5316,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,for (bm =bdrv_dirty_bitmap_next (bs,NULL ); bm; bm =bdrv_dirty_bitmap_next (bs, bm)) { -bdrv_dirty_bitmap_set_migration (bm, false); +bdrv_dirty_bitmap_squelch_persistence (bm, false); } ret =refresh_total_sectors (bs, bs->total_sectors);
block/dirty-bitmap.c +8 -8
@@ -48,10 +48,9 @@ struct BdrvDirtyBitmap {bool inconsistent;/* bitmap is persistent, but inconsistent. It cannot be used at all in any way, except a QMP user can remove it. */ -bool migration;/* Bitmap is selected for migration, it should -not be stored on the next inactivation -(persistent flag doesn't matter until next -invalidation).*/ +bool squelch_persistence;/* We are either migrating or deleting this +* bitmap; it should not be stored on the next +* inactivation. */ QLIST_ENTRY (BdrvDirtyBitmap) list; };
@@ -757,16 +756,17 @@ void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap) }/* Called with BQL taken. */ -void bdrv_dirty_bitmap_set_migration (BdrvDirtyBitmap *bitmap,bool migration) +void bdrv_dirty_bitmap_squelch_persistence (BdrvDirtyBitmap *bitmap, +bool squelch) {qemu_mutex_lock (bitmap->mutex); - bitmap->migration = migration; + bitmap->squelch_persistence = squelch;qemu_mutex_unlock (bitmap->mutex); }bool bdrv_dirty_bitmap_get_persistence (BdrvDirtyBitmap *bitmap) { -return bitmap->persistent && !bitmap->migration; +return bitmap->persistent && !bitmap->squelch_persistence; }bool bdrv_dirty_bitmap_inconsistent (const BdrvDirtyBitmap *bitmap)
@@ -778,7 +778,7 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs) {BdrvDirtyBitmap *bm; QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { -if (bm->persistent && !bm->readonly && !bm->migration) { +if (bm->persistent && !bm->readonly && !bm->squelch_persistence) {return true; } }
blockdev.c +73 -6
118 lines not on this page · raw message
migration/block-dirty-bitmap.c +1 -1
@@ -326,7 +326,7 @@ static int init_dirty_bitmap_migration(void)/* unset migration flags here, to not roll back it */ QSIMPLEQ_FOREACH(dbms, &dirty_bitmap_mig_state.dbms_list, entry) { -bdrv_dirty_bitmap_set_migration (dbms->bitmap, true); +bdrv_dirty_bitmap_squelch_persistence (dbms->bitmap, true); }if (QSIMPLEQ_EMPTY (&dirty_bitmap_mig_state.dbms_list)) {
Signature · 1 line
2.21.0
Re: [Qemu-devel] [PATCH v2 2/3] qapi: implement block-dirty-bitmap-remove transaction action
Quoted 15 lines · John Snow
It is used to do transactional movement of the bitmap (which is possible in conjunction with merge command). Transactional bitmap movement is needed in scenarios with external snapshot, when we don't want to leave copy of the bitmap in the base image.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by John Snow <[email protected]>--- qapi/transaction.json | 2 + include/block/dirty-bitmap.h | 3 +- block.c | 2 +- block/dirty-bitmap.c | 16 +++---- blockdev.c | 79 +++++++++++++++++++++++++++++++--- migration/block-dirty-bitmap.c | 2 +- 6 files changed, 87 insertions(+), 17 deletions(-)
[...]
Quoted 5 lines
block/dirty-bitmap.c +0
-0
block/dirty-bitmap.c struct BdrvDirtyBitmap { · line 53
Quoted 10 lines
block/dirty-bitmap.c +3
-4@@ -48,10 +48,9 @@ struct BdrvDirtyBitmap {bool inconsistent;/* bitmap is persistent, but inconsistent. It cannot be used at all in any way, except a QMP user can remove it. */ -bool migration;/* Bitmap is selected for migration, it should -not be stored on the next inactivation -(persistent flag doesn't matter until next -invalidation).*/ +bool squelch_persistence;/* We are either migrating or deleting this +* bitmap; it should not be stored on the next +* inactivation. */
I like the English lessons you give me, but why not just dont_store? Or skip_storing?
Quoted 3 lines
block/dirty-bitmap.c +0
-0QLIST_ENTRY (BdrvDirtyBitmap) list; };
[...]
Quoted 4 lines
blockdev.c +0
-0
[...]
blockdev.c static void block_dirty_bitmap_merge_prepare(BlkActionState *common, · line 2169
Quoted 8 lines
blockdev.c +8
-0+static void block_dirty_bitmap_remove_abort (BlkActionState *common) +{ +BlockDirtyBitmapState *state =DO_UPCAST (BlockDirtyBitmapState, + common, common); + +if (state->bitmap) { +bdrv_dirty_bitmap_squelch_persistence (state->bitmap, false); +bdrv_dirty_bitmap_set_busy (state->bitmap, false);
Don’t you need to undo the removal? Like, re-add it to state->bs, and re-store it?
[...]
Quoted 12 lines
blockdev.c +2
-1@@ -2892,13 +2944,28 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,aio_context_acquire (aio_context);bdrv_remove_persistent_dirty_bitmap (bs, name, &local_err);aio_context_release (aio_context); +if (local_err !=NULL ) {error_propagate (errp, local_err); -return ; +return NULL ; } }
blockdev.c void qmp_block_dirty_bitmap_remove(const char *node, const char *name, · line 2962
Quoted 10 lines
blockdev.c +9
-1-bdrv_release_dirty_bitmap (bs, bitmap); +if (release) { +bdrv_release_dirty_bitmap (bs, bitmap); + } + +if (bitmap_bs) { + *bitmap_bs = bs; + } + +return bitmap;
I’d prefer “release ? NULL : bitmap”.
Max
Quoted 9 lines
blockdev.c +6
-0+} + +void qmp_block_dirty_bitmap_remove (const char *node,const char *name, +Error **errp) +{ +do_block_dirty_bitmap_remove (node, name, true,NULL , errp); }/**
Re: [Qemu-devel] [PATCH v2 2/3] qapi: implement block-dirty-bitmap-remove transaction action
Quoted 51 lines · Max Reitz
Quoted 15 lines · John Snow
It is used to do transactional movement of the bitmap (which is possible in conjunction with merge command). Transactional bitmap movement is needed in scenarios with external snapshot, when we don't want to leave copy of the bitmap in the base image.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by John Snow <[email protected]>--- qapi/transaction.json | 2 + include/block/dirty-bitmap.h | 3 +- block.c | 2 +- block/dirty-bitmap.c | 16 +++---- blockdev.c | 79 +++++++++++++++++++++++++++++++--- migration/block-dirty-bitmap.c | 2 +- 6 files changed, 87 insertions(+), 17 deletions(-)[...]
Quoted 5 lines
block/dirty-bitmap.c +0
-0block/dirty-bitmap.c struct BdrvDirtyBitmap { · line 53
Quoted 10 lines
block/dirty-bitmap.c +3
-4@@ -48,10 +48,9 @@ struct BdrvDirtyBitmap {bool inconsistent;/* bitmap is persistent, but inconsistent. It cannot be used at all in any way, except a QMP user can remove it. */ -bool migration;/* Bitmap is selected for migration, it should -not be stored on the next inactivation -(persistent flag doesn't matter until next -invalidation).*/ +bool squelch_persistence;/* We are either migrating or deleting this +* bitmap; it should not be stored on the next +* inactivation. */ I like the English lessons you give me, but why not just
dont_store? Orskip_storing?Quoted 3 lines
block/dirty-bitmap.c +0
-0QLIST_ENTRY (BdrvDirtyBitmap) list; };[...]
Quoted 4 lines
blockdev.c +0
-0[...]
Quoted 11 lines
blockdev.c static void block_dirty_bitmap_merge_prepare(BlkActionState *common, · line 2169
Quoted 8 lines
blockdev.c +8
-0+static void block_dirty_bitmap_remove_abort (BlkActionState *common) +{ +BlockDirtyBitmapState *state =DO_UPCAST (BlockDirtyBitmapState, + common, common); + +if (state->bitmap) { +bdrv_dirty_bitmap_squelch_persistence (state->bitmap, false); +bdrv_dirty_bitmap_set_busy (state->bitmap, false);Don’t you need to undo the removal? Like, re-add it to
state->bs, and re-store it?
Ah, right, no need to re-add it because without *release(), it was never removed from state->bs.
Having removed the persistent bitmap makes without doing anything here to re-add it to the qcow2 file makes me a bit uneasy, though... (It should be stored automatically when the qcow2 file is closed or anything, but, you know. Feel free to say “Yes, it will be stored automatically, don’t worry.”)
Max
Quoted 39 lines
[...]
Quoted 12 lines
blockdev.c +2
-1@@ -2892,13 +2944,28 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,aio_context_acquire (aio_context);bdrv_remove_persistent_dirty_bitmap (bs, name, &local_err);aio_context_release (aio_context); +if (local_err !=NULL ) {error_propagate (errp, local_err); -return ; +return NULL ; } }blockdev.c void qmp_block_dirty_bitmap_remove(const char *node, const char *name, · line 2962
Quoted 10 lines
blockdev.c +9
-1-bdrv_release_dirty_bitmap (bs, bitmap); +if (release) { +bdrv_release_dirty_bitmap (bs, bitmap); + } + +if (bitmap_bs) { + *bitmap_bs = bs; + } + +return bitmap;I’d prefer “release ? NULL : bitmap”.
Max
Quoted 9 lines
blockdev.c +6
-0+} + +void qmp_block_dirty_bitmap_remove (const char *node,const char *name, +Error **errp) +{ +do_block_dirty_bitmap_remove (node, name, true,NULL , errp); }/**
Re: [Qemu-devel] [PATCH v2 2/3] qapi: implement block-dirty-bitmap-remove transaction action
In reply to Max ReitzQuoted 29 lines · Max Reitz
Quoted 15 lines · John Snow
It is used to do transactional movement of the bitmap (which is possible in conjunction with merge command). Transactional bitmap movement is needed in scenarios with external snapshot, when we don't want to leave copy of the bitmap in the base image.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by John Snow <[email protected]>--- qapi/transaction.json | 2 + include/block/dirty-bitmap.h | 3 +- block.c | 2 +- block/dirty-bitmap.c | 16 +++---- blockdev.c | 79 +++++++++++++++++++++++++++++++--- migration/block-dirty-bitmap.c | 2 +- 6 files changed, 87 insertions(+), 17 deletions(-)[...]
Quoted 10 lines
block/dirty-bitmap.c +0
-2@@ -48,10 +48,9 @@ struct BdrvDirtyBitmap {bool inconsistent;/* bitmap is persistent, but inconsistent. It cannot be used at all in any way, except a QMP user can remove it. */ -bool migration;/* Bitmap is selected for migration, it should -not be stored on the next inactivation
Quoted 9 lines
block/dirty-bitmap.c struct BdrvDirtyBitmap { · line 53
Quoted 5 lines
block/dirty-bitmap.c +3
-2-(persistent flag doesn't matter until next -invalidation).*/ +bool squelch_persistence;/* We are either migrating or deleting this +* bitmap; it should not be stored on the next +* inactivation. */ I like the English lessons you give me, but why not just
dont_store? Orskip_storing?
I have to give you something to look forward to in my patches, don't I?
I also like "suppress_persistence" but I'll settle for "skip_store".
Quoted 25 lines
Quoted 3 lines
block/dirty-bitmap.c +0
-0QLIST_ENTRY (BdrvDirtyBitmap) list; };[...]
Quoted 4 lines
blockdev.c +0
-0[...]
blockdev.c static void block_dirty_bitmap_merge_prepare(BlkActionState *common, · line 2169
Quoted 8 lines
blockdev.c +8
-0+static void block_dirty_bitmap_remove_abort (BlkActionState *common) +{ +BlockDirtyBitmapState *state =DO_UPCAST (BlockDirtyBitmapState, + common, common); + +if (state->bitmap) { +bdrv_dirty_bitmap_squelch_persistence (state->bitmap, false); +bdrv_dirty_bitmap_set_busy (state->bitmap, false);Don’t you need to undo the removal? Like, re-add it to
state->bs, and re-store it?
Quoted 2 lines
[...]
Not right away, anyway; undoing the suppression will allow it to flush out the next time that happens.
Why not flush it RIGHT NOW? Well, we actually never flush bitmaps until final close right now. There has been some contention about how it's pointless to do so as we'd have to re-open the bitmap immediately anyway, and any results you'd get from querying the bitmap outside of QEMU would be meaningless.
It does feel risky, though, and seems to frequently violate the principal of least surprise.
Quoted 25 lines
Quoted 12 lines
blockdev.c +2
-1@@ -2892,13 +2944,28 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,aio_context_acquire (aio_context);bdrv_remove_persistent_dirty_bitmap (bs, name, &local_err);aio_context_release (aio_context); +if (local_err !=NULL ) {error_propagate (errp, local_err); -return ; +return NULL ; } }blockdev.c void qmp_block_dirty_bitmap_remove(const char *node, const char *name, · line 2962
Quoted 10 lines
blockdev.c +9
-1-bdrv_release_dirty_bitmap (bs, bitmap); +if (release) { +bdrv_release_dirty_bitmap (bs, bitmap); + } + +if (bitmap_bs) { + *bitmap_bs = bs; + } + +return bitmap;I’d prefer “release ? NULL : bitmap”.
Quoted 2 lines
Max
Sure.
Quoted 10 lines
Quoted 9 lines
blockdev.c +6
-0+} + +void qmp_block_dirty_bitmap_remove (const char *node,const char *name, +Error **errp) +{ +do_block_dirty_bitmap_remove (node, name, true,NULL , errp); }/**
PATCH v2 3/3 iotests: test bitmap moving inside 254
In reply to John SnowFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Test persistent bitmap copying with and without removal of original bitmap.
--- tests/qemu-iotests/254 | 30 +++++++++++++- tests/qemu-iotests/254.out | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-)
tests/qemu-iotests/254 +28 -2
@@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Test external snapshot with bitmap copying. +# Test external snapshot with bitmap copying and moving. # # Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. #
@@ -32,6 +32,10 @@ vm = iotests.VM().add_drive(disk, opts='node-name=base') vm.launch() vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0') +vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap1', + persistent=True) +vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap2', + persistent=True) vm.hmp_qemu_io('drive0', 'write 0 512K')
@@ -39,16 +43,38 @@ vm.qmp_log('transaction', indent=2, actions=[ {'type': 'blockdev-snapshot-sync', 'data': {'device': 'drive0', 'snapshot-file': top, 'snapshot-node-name': 'snap'}}, + + # copy non-persistent bitmap0 {'type': 'block-dirty-bitmap-add', 'data': {'node': 'snap', 'name': 'bitmap0'}}, {'type': 'block-dirty-bitmap-merge', 'data': {'node': 'snap', 'target': 'bitmap0', - 'bitmaps': [{'node': 'base', 'name': 'bitmap0'}]}} + 'bitmaps': [{'node': 'base', 'name': 'bitmap0'}]}}, + + # copy persistent bitmap1, original will be saved to base image + {'type': 'block-dirty-bitmap-add', + 'data': {'node': 'snap', 'name': 'bitmap1', 'persistent': True}}, + {'type': 'block-dirty-bitmap-merge', + 'data': {'node': 'snap', 'target': 'bitmap1', + 'bitmaps': [{'node': 'base', 'name': 'bitmap1'}]}}, + + # move persistent bitmap1, original will be removed and not saved + # to base image + {'type': 'block-dirty-bitmap-add', + 'data': {'node': 'snap', 'name': 'bitmap2', 'persistent': True}}, + {'type': 'block-dirty-bitmap-merge', + 'data': {'node': 'snap', 'target': 'bitmap2', + 'bitmaps': [{'node': 'base', 'name': 'bitmap2'}]}}, + {'type': 'block-dirty-bitmap-remove', + 'data': {'node': 'base', 'name': 'bitmap2'}} ], filters=[iotests.filter_qmp_testfiles]) result = vm.qmp('query-block')['return'][0] log("query-block: device = {}, node-name = {}, dirty-bitmaps:".format( result['device'], result['inserted']['node-name'])) log(result['dirty-bitmaps'], indent=2) +log("\nbitmaps in backing image:") +log(result['inserted']['image']['backing-image']['format-specific'] \ + ['data']['bitmaps'], indent=2) vm.shutdown()
tests/qemu-iotests/254.out +82 -0
102 lines not on this page · raw message
Signature · 1 line
2.21.0