[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/18] blockdev: use state.bitmap in block-dirty-bitmap-add action
From: |
Kevin Wolf |
Subject: |
[PULL 05/18] blockdev: use state.bitmap in block-dirty-bitmap-add action |
Date: |
Wed, 17 May 2023 18:51:03 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Other bitmap related actions use the .bitmap pointer in .abort action,
let's do same here:
1. It helps further refactoring, as bitmap-add is the only bitmap
action that uses state.action in .abort
2. It must be safe: transaction actions rely on the fact that on
.abort() the state is the same as at the end of .prepare(), so that
in .abort() we could precisely rollback the changes done by
.prepare().
The only way to remove the bitmap during transaction should be
block-dirty-bitmap-remove action, but it postpones actual removal to
.commit(), so we are OK on any rollback path. (Note also that
bitmap-remove is the only bitmap action that has .commit() phase,
except for simple g_free the state on .clean())
3. Again, other bitmap actions behave this way: keep the bitmap pointer
during the transaction.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20230510150624.310640-6-vsementsov@yandex-team.ru>
[kwolf: Also remove the now unused BlockDirtyBitmapState.prepared]
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
blockdev.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index a2ebaa5afc..4bf15566b2 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1979,7 +1979,6 @@ typedef struct BlockDirtyBitmapState {
BdrvDirtyBitmap *bitmap;
BlockDriverState *bs;
HBitmap *backup;
- bool prepared;
bool was_enabled;
} BlockDirtyBitmapState;
@@ -2008,7 +2007,8 @@ static void block_dirty_bitmap_add_action(BlkActionState
*common,
&local_err);
if (!local_err) {
- state->prepared = true;
+ state->bitmap = block_dirty_bitmap_lookup(action->node, action->name,
+ NULL, &error_abort);
} else {
error_propagate(errp, local_err);
}
@@ -2016,15 +2016,10 @@ static void
block_dirty_bitmap_add_action(BlkActionState *common,
static void block_dirty_bitmap_add_abort(void *opaque)
{
- BlockDirtyBitmapAdd *action;
BlockDirtyBitmapState *state = opaque;
- action = state->common.action->u.block_dirty_bitmap_add.data;
- /* Should not be able to fail: IF the bitmap was added via .prepare(),
- * then the node reference and bitmap name must have been valid.
- */
- if (state->prepared) {
- qmp_block_dirty_bitmap_remove(action->node, action->name,
&error_abort);
+ if (state->bitmap) {
+ bdrv_release_dirty_bitmap(state->bitmap);
}
}
--
2.40.1
- [PULL 00/18] Block layer patches, Kevin Wolf, 2023/05/17
- [PULL 01/18] blockdev: refactor transaction to use Transaction API, Kevin Wolf, 2023/05/17
- [PULL 02/18] blockdev: transactions: rename some things, Kevin Wolf, 2023/05/17
- [PULL 03/18] blockdev: qmp_transaction: refactor loop to classic for, Kevin Wolf, 2023/05/17
- [PULL 07/18] docs/interop/qcow2.txt: fix description about "zlib" clusters, Kevin Wolf, 2023/05/17
- [PULL 05/18] blockdev: use state.bitmap in block-dirty-bitmap-add action,
Kevin Wolf <=
- [PULL 04/18] blockdev: transaction: refactor handling transaction properties, Kevin Wolf, 2023/05/17
- [PULL 06/18] blockdev: qmp_transaction: drop extra generic layer, Kevin Wolf, 2023/05/17
- [PULL 08/18] block: Call .bdrv_co_create(_opts) unlocked, Kevin Wolf, 2023/05/17
- [PULL 10/18] qcow2: Unlock the graph in qcow2_do_open() where necessary, Kevin Wolf, 2023/05/17
- [PULL 09/18] block/export: Fix null pointer dereference in error path, Kevin Wolf, 2023/05/17
- [PULL 12/18] test-bdrv-drain: Take graph lock more selectively, Kevin Wolf, 2023/05/17
- [PULL 11/18] qemu-img: Take graph lock more selectively, Kevin Wolf, 2023/05/17
- [PULL 14/18] blockjob: Adhere to rate limit even when reentered early, Kevin Wolf, 2023/05/17
- [PULL 16/18] iotests/245: Check if 'compress' driver is available, Kevin Wolf, 2023/05/17
- [PULL 17/18] aio-posix: do not nest poll handlers, Kevin Wolf, 2023/05/17