Skip to content

Commit

Permalink
blockdev: use state.bitmap in block-dirty-bitmap-add action
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and kevmw committed May 19, 2023
1 parent c85f34c commit c85feaf
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,6 @@ typedef struct BlockDirtyBitmapState {
BdrvDirtyBitmap *bitmap;
BlockDriverState *bs;
HBitmap *backup;
bool prepared;
bool was_enabled;
} BlockDirtyBitmapState;

Expand Down Expand Up @@ -2008,23 +2007,19 @@ 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);
}
}

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);
}
}

Expand Down

0 comments on commit c85feaf

Please sign in to comment.