block: rename BlkTransactionState and BdrvActionOps

These structures are misnomers, somewhat.

(1) BlockTransactionState is not state for a transaction,
    but is rather state for a single transaction action.
    Rename it "BlkActionState" to be more accurate.

(2) The BdrvActionOps describes operations for the BlkActionState,
    above. This name might imply a 'BdrvAction' or a 'BdrvActionState',
    which there isn't.
    Rename this to 'BlkActionOps' to match 'BlkActionState'.

Lastly, update the surrounding in-line documentation and comments
to reflect the current nature of how Transactions operate.

This patch changes only comments and names, and should not affect
behavior in any way.

Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1446765200-3054-4-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
John Snow 2015-11-05 18:13:09 -05:00 committed by Kevin Wolf
parent 749ad5e887
commit 50f43f0ff9
1 changed files with 71 additions and 57 deletions

View File

@ -1359,44 +1359,58 @@ static BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node,
/* New and old BlockDriverState structs for atomic group operations */ /* New and old BlockDriverState structs for atomic group operations */
typedef struct BlkTransactionState BlkTransactionState; typedef struct BlkActionState BlkActionState;
/* Only prepare() may fail. In a single transaction, only one of commit() or /**
abort() will be called, clean() will always be called if it present. */ * BlkActionOps:
typedef struct BdrvActionOps { * Table of operations that define an Action.
/* Size of state struct, in bytes. */ *
size_t instance_size; * @instance_size: Size of state struct, in bytes.
/* Prepare the work, must NOT be NULL. */ * @prepare: Prepare the work, must NOT be NULL.
void (*prepare)(BlkTransactionState *common, Error **errp); * @commit: Commit the changes, can be NULL.
/* Commit the changes, can be NULL. */ * @abort: Abort the changes on fail, can be NULL.
void (*commit)(BlkTransactionState *common); * @clean: Clean up resources after all transaction actions have called
/* Abort the changes on fail, can be NULL. */ * commit() or abort(). Can be NULL.
void (*abort)(BlkTransactionState *common); *
/* Clean up resource in the end, can be NULL. */ * Only prepare() may fail. In a single transaction, only one of commit() or
void (*clean)(BlkTransactionState *common); * abort() will be called. clean() will always be called if it is present.
} BdrvActionOps;
/*
* This structure must be arranged as first member in child type, assuming
* that compiler will also arrange it to the same address with parent instance.
* Later it will be used in free().
*/ */
struct BlkTransactionState { typedef struct BlkActionOps {
size_t instance_size;
void (*prepare)(BlkActionState *common, Error **errp);
void (*commit)(BlkActionState *common);
void (*abort)(BlkActionState *common);
void (*clean)(BlkActionState *common);
} BlkActionOps;
/**
* BlkActionState:
* Describes one Action's state within a Transaction.
*
* @action: QAPI-defined enum identifying which Action to perform.
* @ops: Table of ActionOps this Action can perform.
* @entry: List membership for all Actions in this Transaction.
*
* This structure must be arranged as first member in a subclassed type,
* assuming that the compiler will also arrange it to the same offsets as the
* base class.
*/
struct BlkActionState {
TransactionAction *action; TransactionAction *action;
const BdrvActionOps *ops; const BlkActionOps *ops;
QSIMPLEQ_ENTRY(BlkTransactionState) entry; QSIMPLEQ_ENTRY(BlkActionState) entry;
}; };
/* internal snapshot private data */ /* internal snapshot private data */
typedef struct InternalSnapshotState { typedef struct InternalSnapshotState {
BlkTransactionState common; BlkActionState common;
BlockDriverState *bs; BlockDriverState *bs;
AioContext *aio_context; AioContext *aio_context;
QEMUSnapshotInfo sn; QEMUSnapshotInfo sn;
bool created; bool created;
} InternalSnapshotState; } InternalSnapshotState;
static void internal_snapshot_prepare(BlkTransactionState *common, static void internal_snapshot_prepare(BlkActionState *common,
Error **errp) Error **errp)
{ {
Error *local_err = NULL; Error *local_err = NULL;
@ -1495,7 +1509,7 @@ static void internal_snapshot_prepare(BlkTransactionState *common,
state->created = true; state->created = true;
} }
static void internal_snapshot_abort(BlkTransactionState *common) static void internal_snapshot_abort(BlkActionState *common)
{ {
InternalSnapshotState *state = InternalSnapshotState *state =
DO_UPCAST(InternalSnapshotState, common, common); DO_UPCAST(InternalSnapshotState, common, common);
@ -1518,7 +1532,7 @@ static void internal_snapshot_abort(BlkTransactionState *common)
} }
} }
static void internal_snapshot_clean(BlkTransactionState *common) static void internal_snapshot_clean(BlkActionState *common)
{ {
InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState, InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState,
common, common); common, common);
@ -1533,13 +1547,13 @@ static void internal_snapshot_clean(BlkTransactionState *common)
/* external snapshot private data */ /* external snapshot private data */
typedef struct ExternalSnapshotState { typedef struct ExternalSnapshotState {
BlkTransactionState common; BlkActionState common;
BlockDriverState *old_bs; BlockDriverState *old_bs;
BlockDriverState *new_bs; BlockDriverState *new_bs;
AioContext *aio_context; AioContext *aio_context;
} ExternalSnapshotState; } ExternalSnapshotState;
static void external_snapshot_prepare(BlkTransactionState *common, static void external_snapshot_prepare(BlkActionState *common,
Error **errp) Error **errp)
{ {
int flags = 0, ret; int flags = 0, ret;
@ -1686,7 +1700,7 @@ static void external_snapshot_prepare(BlkTransactionState *common,
} }
} }
static void external_snapshot_commit(BlkTransactionState *common) static void external_snapshot_commit(BlkActionState *common)
{ {
ExternalSnapshotState *state = ExternalSnapshotState *state =
DO_UPCAST(ExternalSnapshotState, common, common); DO_UPCAST(ExternalSnapshotState, common, common);
@ -1702,7 +1716,7 @@ static void external_snapshot_commit(BlkTransactionState *common)
NULL); NULL);
} }
static void external_snapshot_abort(BlkTransactionState *common) static void external_snapshot_abort(BlkActionState *common)
{ {
ExternalSnapshotState *state = ExternalSnapshotState *state =
DO_UPCAST(ExternalSnapshotState, common, common); DO_UPCAST(ExternalSnapshotState, common, common);
@ -1711,7 +1725,7 @@ static void external_snapshot_abort(BlkTransactionState *common)
} }
} }
static void external_snapshot_clean(BlkTransactionState *common) static void external_snapshot_clean(BlkActionState *common)
{ {
ExternalSnapshotState *state = ExternalSnapshotState *state =
DO_UPCAST(ExternalSnapshotState, common, common); DO_UPCAST(ExternalSnapshotState, common, common);
@ -1722,13 +1736,13 @@ static void external_snapshot_clean(BlkTransactionState *common)
} }
typedef struct DriveBackupState { typedef struct DriveBackupState {
BlkTransactionState common; BlkActionState common;
BlockDriverState *bs; BlockDriverState *bs;
AioContext *aio_context; AioContext *aio_context;
BlockJob *job; BlockJob *job;
} DriveBackupState; } DriveBackupState;
static void drive_backup_prepare(BlkTransactionState *common, Error **errp) static void drive_backup_prepare(BlkActionState *common, Error **errp)
{ {
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
BlockBackend *blk; BlockBackend *blk;
@ -1773,7 +1787,7 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp)
state->job = state->bs->job; state->job = state->bs->job;
} }
static void drive_backup_abort(BlkTransactionState *common) static void drive_backup_abort(BlkActionState *common)
{ {
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
BlockDriverState *bs = state->bs; BlockDriverState *bs = state->bs;
@ -1784,7 +1798,7 @@ static void drive_backup_abort(BlkTransactionState *common)
} }
} }
static void drive_backup_clean(BlkTransactionState *common) static void drive_backup_clean(BlkActionState *common)
{ {
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
@ -1795,13 +1809,13 @@ static void drive_backup_clean(BlkTransactionState *common)
} }
typedef struct BlockdevBackupState { typedef struct BlockdevBackupState {
BlkTransactionState common; BlkActionState common;
BlockDriverState *bs; BlockDriverState *bs;
BlockJob *job; BlockJob *job;
AioContext *aio_context; AioContext *aio_context;
} BlockdevBackupState; } BlockdevBackupState;
static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp) static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
{ {
BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
BlockdevBackup *backup; BlockdevBackup *backup;
@ -1853,7 +1867,7 @@ static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp)
state->job = state->bs->job; state->job = state->bs->job;
} }
static void blockdev_backup_abort(BlkTransactionState *common) static void blockdev_backup_abort(BlkActionState *common)
{ {
BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
BlockDriverState *bs = state->bs; BlockDriverState *bs = state->bs;
@ -1864,7 +1878,7 @@ static void blockdev_backup_abort(BlkTransactionState *common)
} }
} }
static void blockdev_backup_clean(BlkTransactionState *common) static void blockdev_backup_clean(BlkActionState *common)
{ {
BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
@ -1875,7 +1889,7 @@ static void blockdev_backup_clean(BlkTransactionState *common)
} }
typedef struct BlockDirtyBitmapState { typedef struct BlockDirtyBitmapState {
BlkTransactionState common; BlkActionState common;
BdrvDirtyBitmap *bitmap; BdrvDirtyBitmap *bitmap;
BlockDriverState *bs; BlockDriverState *bs;
AioContext *aio_context; AioContext *aio_context;
@ -1883,7 +1897,7 @@ typedef struct BlockDirtyBitmapState {
bool prepared; bool prepared;
} BlockDirtyBitmapState; } BlockDirtyBitmapState;
static void block_dirty_bitmap_add_prepare(BlkTransactionState *common, static void block_dirty_bitmap_add_prepare(BlkActionState *common,
Error **errp) Error **errp)
{ {
Error *local_err = NULL; Error *local_err = NULL;
@ -1891,7 +1905,7 @@ static void block_dirty_bitmap_add_prepare(BlkTransactionState *common,
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common); common, common);
action = common->action->block_dirty_bitmap_add; action = common->action->u.block_dirty_bitmap_add;
/* AIO context taken and released within qmp_block_dirty_bitmap_add */ /* AIO context taken and released within qmp_block_dirty_bitmap_add */
qmp_block_dirty_bitmap_add(action->node, action->name, qmp_block_dirty_bitmap_add(action->node, action->name,
action->has_granularity, action->granularity, action->has_granularity, action->granularity,
@ -1904,13 +1918,13 @@ static void block_dirty_bitmap_add_prepare(BlkTransactionState *common,
} }
} }
static void block_dirty_bitmap_add_abort(BlkTransactionState *common) static void block_dirty_bitmap_add_abort(BlkActionState *common)
{ {
BlockDirtyBitmapAdd *action; BlockDirtyBitmapAdd *action;
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common); common, common);
action = common->action->block_dirty_bitmap_add; action = common->action->u.block_dirty_bitmap_add;
/* Should not be able to fail: IF the bitmap was added via .prepare(), /* Should not be able to fail: IF the bitmap was added via .prepare(),
* then the node reference and bitmap name must have been valid. * then the node reference and bitmap name must have been valid.
*/ */
@ -1919,14 +1933,14 @@ static void block_dirty_bitmap_add_abort(BlkTransactionState *common)
} }
} }
static void block_dirty_bitmap_clear_prepare(BlkTransactionState *common, static void block_dirty_bitmap_clear_prepare(BlkActionState *common,
Error **errp) Error **errp)
{ {
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common); common, common);
BlockDirtyBitmap *action; BlockDirtyBitmap *action;
action = common->action->block_dirty_bitmap_clear; action = common->action->u.block_dirty_bitmap_clear;
state->bitmap = block_dirty_bitmap_lookup(action->node, state->bitmap = block_dirty_bitmap_lookup(action->node,
action->name, action->name,
&state->bs, &state->bs,
@ -1948,7 +1962,7 @@ static void block_dirty_bitmap_clear_prepare(BlkTransactionState *common,
/* AioContext is released in .clean() */ /* AioContext is released in .clean() */
} }
static void block_dirty_bitmap_clear_abort(BlkTransactionState *common) static void block_dirty_bitmap_clear_abort(BlkActionState *common)
{ {
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common); common, common);
@ -1956,7 +1970,7 @@ static void block_dirty_bitmap_clear_abort(BlkTransactionState *common)
bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup); bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup);
} }
static void block_dirty_bitmap_clear_commit(BlkTransactionState *common) static void block_dirty_bitmap_clear_commit(BlkActionState *common)
{ {
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common); common, common);
@ -1964,7 +1978,7 @@ static void block_dirty_bitmap_clear_commit(BlkTransactionState *common)
hbitmap_free(state->backup); hbitmap_free(state->backup);
} }
static void block_dirty_bitmap_clear_clean(BlkTransactionState *common) static void block_dirty_bitmap_clear_clean(BlkActionState *common)
{ {
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common); common, common);
@ -1974,17 +1988,17 @@ static void block_dirty_bitmap_clear_clean(BlkTransactionState *common)
} }
} }
static void abort_prepare(BlkTransactionState *common, Error **errp) static void abort_prepare(BlkActionState *common, Error **errp)
{ {
error_setg(errp, "Transaction aborted using Abort action"); error_setg(errp, "Transaction aborted using Abort action");
} }
static void abort_commit(BlkTransactionState *common) static void abort_commit(BlkActionState *common)
{ {
g_assert_not_reached(); /* this action never succeeds */ g_assert_not_reached(); /* this action never succeeds */
} }
static const BdrvActionOps actions[] = { static const BlkActionOps actions[] = {
[TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT] = { [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT] = {
.instance_size = sizeof(ExternalSnapshotState), .instance_size = sizeof(ExternalSnapshotState),
.prepare = external_snapshot_prepare, .prepare = external_snapshot_prepare,
@ -2011,7 +2025,7 @@ static const BdrvActionOps actions[] = {
.clean = blockdev_backup_clean, .clean = blockdev_backup_clean,
}, },
[TRANSACTION_ACTION_KIND_ABORT] = { [TRANSACTION_ACTION_KIND_ABORT] = {
.instance_size = sizeof(BlkTransactionState), .instance_size = sizeof(BlkActionState),
.prepare = abort_prepare, .prepare = abort_prepare,
.commit = abort_commit, .commit = abort_commit,
}, },
@ -2042,10 +2056,10 @@ static const BdrvActionOps actions[] = {
void qmp_transaction(TransactionActionList *dev_list, Error **errp) void qmp_transaction(TransactionActionList *dev_list, Error **errp)
{ {
TransactionActionList *dev_entry = dev_list; TransactionActionList *dev_entry = dev_list;
BlkTransactionState *state, *next; BlkActionState *state, *next;
Error *local_err = NULL; Error *local_err = NULL;
QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states; QSIMPLEQ_HEAD(snap_bdrv_states, BlkActionState) snap_bdrv_states;
QSIMPLEQ_INIT(&snap_bdrv_states); QSIMPLEQ_INIT(&snap_bdrv_states);
/* drain all i/o before any operations */ /* drain all i/o before any operations */
@ -2054,7 +2068,7 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp)
/* We don't do anything in this loop that commits us to the operations */ /* We don't do anything in this loop that commits us to the operations */
while (NULL != dev_entry) { while (NULL != dev_entry) {
TransactionAction *dev_info = NULL; TransactionAction *dev_info = NULL;
const BdrvActionOps *ops; const BlkActionOps *ops;
dev_info = dev_entry->value; dev_info = dev_entry->value;
dev_entry = dev_entry->next; dev_entry = dev_entry->next;