mirror of https://gitee.com/openkylin/qemu.git
blockdev: rename BlkTransactionStates to singular
The QMP 'transaction' command keeps a list of in-flight transactions. The transaction state structure is called BlkTransactionStates even though it only deals with a single transaction. The only plural thing is the linked list of transaction states. I find it confusing to call the single structure "States". This patch renames it to "State", just like BlockDriverState is singular. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
99a9addf56
commit
ba5d6ab68f
104
blockdev.c
104
blockdev.c
|
@ -780,7 +780,7 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
|
||||||
|
|
||||||
/* New and old BlockDriverState structs for group snapshots */
|
/* New and old BlockDriverState structs for group snapshots */
|
||||||
|
|
||||||
typedef struct BlkTransactionStates BlkTransactionStates;
|
typedef struct BlkTransactionState BlkTransactionState;
|
||||||
|
|
||||||
/* Only prepare() may fail. In a single transaction, only one of commit() or
|
/* 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. */
|
abort() will be called, clean() will always be called if it present. */
|
||||||
|
@ -788,13 +788,13 @@ typedef struct BdrvActionOps {
|
||||||
/* Size of state struct, in bytes. */
|
/* Size of state struct, in bytes. */
|
||||||
size_t instance_size;
|
size_t instance_size;
|
||||||
/* Prepare the work, must NOT be NULL. */
|
/* Prepare the work, must NOT be NULL. */
|
||||||
void (*prepare)(BlkTransactionStates *common, Error **errp);
|
void (*prepare)(BlkTransactionState *common, Error **errp);
|
||||||
/* Commit the changes, must NOT be NULL. */
|
/* Commit the changes, must NOT be NULL. */
|
||||||
void (*commit)(BlkTransactionStates *common);
|
void (*commit)(BlkTransactionState *common);
|
||||||
/* Abort the changes on fail, can be NULL. */
|
/* Abort the changes on fail, can be NULL. */
|
||||||
void (*abort)(BlkTransactionStates *common);
|
void (*abort)(BlkTransactionState *common);
|
||||||
/* Clean up resource in the end, can be NULL. */
|
/* Clean up resource in the end, can be NULL. */
|
||||||
void (*clean)(BlkTransactionStates *common);
|
void (*clean)(BlkTransactionState *common);
|
||||||
} BdrvActionOps;
|
} BdrvActionOps;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -802,20 +802,20 @@ typedef struct BdrvActionOps {
|
||||||
* that compiler will also arrange it to the same address with parent instance.
|
* that compiler will also arrange it to the same address with parent instance.
|
||||||
* Later it will be used in free().
|
* Later it will be used in free().
|
||||||
*/
|
*/
|
||||||
struct BlkTransactionStates {
|
struct BlkTransactionState {
|
||||||
TransactionAction *action;
|
TransactionAction *action;
|
||||||
const BdrvActionOps *ops;
|
const BdrvActionOps *ops;
|
||||||
QSIMPLEQ_ENTRY(BlkTransactionStates) entry;
|
QSIMPLEQ_ENTRY(BlkTransactionState) entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* external snapshot private data */
|
/* external snapshot private data */
|
||||||
typedef struct ExternalSnapshotStates {
|
typedef struct ExternalSnapshotState {
|
||||||
BlkTransactionStates common;
|
BlkTransactionState common;
|
||||||
BlockDriverState *old_bs;
|
BlockDriverState *old_bs;
|
||||||
BlockDriverState *new_bs;
|
BlockDriverState *new_bs;
|
||||||
} ExternalSnapshotStates;
|
} ExternalSnapshotState;
|
||||||
|
|
||||||
static void external_snapshot_prepare(BlkTransactionStates *common,
|
static void external_snapshot_prepare(BlkTransactionState *common,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriver *drv;
|
BlockDriver *drv;
|
||||||
|
@ -825,8 +825,8 @@ static void external_snapshot_prepare(BlkTransactionStates *common,
|
||||||
const char *new_image_file;
|
const char *new_image_file;
|
||||||
const char *format = "qcow2";
|
const char *format = "qcow2";
|
||||||
enum NewImageMode mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
|
enum NewImageMode mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
|
||||||
ExternalSnapshotStates *states =
|
ExternalSnapshotState *state =
|
||||||
DO_UPCAST(ExternalSnapshotStates, common, common);
|
DO_UPCAST(ExternalSnapshotState, common, common);
|
||||||
TransactionAction *action = common->action;
|
TransactionAction *action = common->action;
|
||||||
|
|
||||||
/* get parameters */
|
/* get parameters */
|
||||||
|
@ -848,36 +848,36 @@ static void external_snapshot_prepare(BlkTransactionStates *common,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
states->old_bs = bdrv_find(device);
|
state->old_bs = bdrv_find(device);
|
||||||
if (!states->old_bs) {
|
if (!state->old_bs) {
|
||||||
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
|
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bdrv_is_inserted(states->old_bs)) {
|
if (!bdrv_is_inserted(state->old_bs)) {
|
||||||
error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
|
error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bdrv_in_use(states->old_bs)) {
|
if (bdrv_in_use(state->old_bs)) {
|
||||||
error_set(errp, QERR_DEVICE_IN_USE, device);
|
error_set(errp, QERR_DEVICE_IN_USE, device);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bdrv_is_read_only(states->old_bs)) {
|
if (!bdrv_is_read_only(state->old_bs)) {
|
||||||
if (bdrv_flush(states->old_bs)) {
|
if (bdrv_flush(state->old_bs)) {
|
||||||
error_set(errp, QERR_IO_ERROR);
|
error_set(errp, QERR_IO_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = states->old_bs->open_flags;
|
flags = state->old_bs->open_flags;
|
||||||
|
|
||||||
/* create new image w/backing file */
|
/* create new image w/backing file */
|
||||||
if (mode != NEW_IMAGE_MODE_EXISTING) {
|
if (mode != NEW_IMAGE_MODE_EXISTING) {
|
||||||
bdrv_img_create(new_image_file, format,
|
bdrv_img_create(new_image_file, format,
|
||||||
states->old_bs->filename,
|
state->old_bs->filename,
|
||||||
states->old_bs->drv->format_name,
|
state->old_bs->drv->format_name,
|
||||||
NULL, -1, flags, &local_err, false);
|
NULL, -1, flags, &local_err, false);
|
||||||
if (error_is_set(&local_err)) {
|
if (error_is_set(&local_err)) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
|
@ -886,42 +886,42 @@ static void external_snapshot_prepare(BlkTransactionStates *common,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We will manually add the backing_hd field to the bs later */
|
/* We will manually add the backing_hd field to the bs later */
|
||||||
states->new_bs = bdrv_new("");
|
state->new_bs = bdrv_new("");
|
||||||
/* TODO Inherit bs->options or only take explicit options with an
|
/* TODO Inherit bs->options or only take explicit options with an
|
||||||
* extended QMP command? */
|
* extended QMP command? */
|
||||||
ret = bdrv_open(states->new_bs, new_image_file, NULL,
|
ret = bdrv_open(state->new_bs, new_image_file, NULL,
|
||||||
flags | BDRV_O_NO_BACKING, drv);
|
flags | BDRV_O_NO_BACKING, drv);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
error_setg_file_open(errp, -ret, new_image_file);
|
error_setg_file_open(errp, -ret, new_image_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void external_snapshot_commit(BlkTransactionStates *common)
|
static void external_snapshot_commit(BlkTransactionState *common)
|
||||||
{
|
{
|
||||||
ExternalSnapshotStates *states =
|
ExternalSnapshotState *state =
|
||||||
DO_UPCAST(ExternalSnapshotStates, common, common);
|
DO_UPCAST(ExternalSnapshotState, common, common);
|
||||||
|
|
||||||
/* This removes our old bs from the bdrv_states, and adds the new bs */
|
/* This removes our old bs and adds the new bs */
|
||||||
bdrv_append(states->new_bs, states->old_bs);
|
bdrv_append(state->new_bs, state->old_bs);
|
||||||
/* We don't need (or want) to use the transactional
|
/* We don't need (or want) to use the transactional
|
||||||
* bdrv_reopen_multiple() across all the entries at once, because we
|
* bdrv_reopen_multiple() across all the entries at once, because we
|
||||||
* don't want to abort all of them if one of them fails the reopen */
|
* don't want to abort all of them if one of them fails the reopen */
|
||||||
bdrv_reopen(states->new_bs, states->new_bs->open_flags & ~BDRV_O_RDWR,
|
bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void external_snapshot_abort(BlkTransactionStates *common)
|
static void external_snapshot_abort(BlkTransactionState *common)
|
||||||
{
|
{
|
||||||
ExternalSnapshotStates *states =
|
ExternalSnapshotState *state =
|
||||||
DO_UPCAST(ExternalSnapshotStates, common, common);
|
DO_UPCAST(ExternalSnapshotState, common, common);
|
||||||
if (states->new_bs) {
|
if (state->new_bs) {
|
||||||
bdrv_delete(states->new_bs);
|
bdrv_delete(state->new_bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BdrvActionOps actions[] = {
|
static const BdrvActionOps actions[] = {
|
||||||
[TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = {
|
[TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = {
|
||||||
.instance_size = sizeof(ExternalSnapshotStates),
|
.instance_size = sizeof(ExternalSnapshotState),
|
||||||
.prepare = external_snapshot_prepare,
|
.prepare = external_snapshot_prepare,
|
||||||
.commit = external_snapshot_commit,
|
.commit = external_snapshot_commit,
|
||||||
.abort = external_snapshot_abort,
|
.abort = external_snapshot_abort,
|
||||||
|
@ -936,10 +936,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;
|
||||||
BlkTransactionStates *states, *next;
|
BlkTransactionState *state, *next;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionStates) snap_bdrv_states;
|
QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states;
|
||||||
QSIMPLEQ_INIT(&snap_bdrv_states);
|
QSIMPLEQ_INIT(&snap_bdrv_states);
|
||||||
|
|
||||||
/* drain all i/o before any snapshots */
|
/* drain all i/o before any snapshots */
|
||||||
|
@ -956,20 +956,20 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp)
|
||||||
assert(dev_info->kind < ARRAY_SIZE(actions));
|
assert(dev_info->kind < ARRAY_SIZE(actions));
|
||||||
|
|
||||||
ops = &actions[dev_info->kind];
|
ops = &actions[dev_info->kind];
|
||||||
states = g_malloc0(ops->instance_size);
|
state = g_malloc0(ops->instance_size);
|
||||||
states->ops = ops;
|
state->ops = ops;
|
||||||
states->action = dev_info;
|
state->action = dev_info;
|
||||||
QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, states, entry);
|
QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, state, entry);
|
||||||
|
|
||||||
states->ops->prepare(states, &local_err);
|
state->ops->prepare(state, &local_err);
|
||||||
if (error_is_set(&local_err)) {
|
if (error_is_set(&local_err)) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
goto delete_and_fail;
|
goto delete_and_fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
|
QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) {
|
||||||
states->ops->commit(states);
|
state->ops->commit(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* success */
|
/* success */
|
||||||
|
@ -980,17 +980,17 @@ delete_and_fail:
|
||||||
* failure, and it is all-or-none; abandon each new bs, and keep using
|
* failure, and it is all-or-none; abandon each new bs, and keep using
|
||||||
* the original bs for all images
|
* the original bs for all images
|
||||||
*/
|
*/
|
||||||
QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {
|
QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) {
|
||||||
if (states->ops->abort) {
|
if (state->ops->abort) {
|
||||||
states->ops->abort(states);
|
state->ops->abort(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
QSIMPLEQ_FOREACH_SAFE(states, &snap_bdrv_states, entry, next) {
|
QSIMPLEQ_FOREACH_SAFE(state, &snap_bdrv_states, entry, next) {
|
||||||
if (states->ops->clean) {
|
if (state->ops->clean) {
|
||||||
states->ops->clean(states);
|
state->ops->clean(state);
|
||||||
}
|
}
|
||||||
g_free(states);
|
g_free(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue