[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v10 12/14] block: add transactional properties
From: |
John Snow |
Subject: |
[Qemu-block] [PATCH v10 12/14] block: add transactional properties |
Date: |
Fri, 23 Oct 2015 19:56:50 -0400 |
Add both transactional properties to the QMP transactional interface,
and add the BlockJobTxn that we create as a result of the err-cancel
property to the BlkActionState structure.
[split up from a patch originally by Stefan and Fam. --js]
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Fam Zheng <address@hidden>
Signed-off-by: John Snow <address@hidden>
Signed-off-by: John Snow <address@hidden>
---
blockdev.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
qapi-schema.json | 48 +++++++++++++++++++++++++++++++---
qmp-commands.hx | 2 +-
3 files changed, 120 insertions(+), 8 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index d1dcf68..9b5e2fa 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1033,7 +1033,7 @@ static void blockdev_do_action(int kind, void *data,
Error **errp)
action.data = data;
list.value = &action;
list.next = NULL;
- qmp_transaction(&list, errp);
+ qmp_transaction(&list, false, NULL, errp);
}
void qmp_blockdev_snapshot_sync(bool has_device, const char *device,
@@ -1248,6 +1248,7 @@ typedef struct BlkActionOps {
*
* @action: QAPI-defined enum identifying which Action to perform.
* @ops: Table of ActionOps this Action can perform.
+ * @block_job_txn: Transaction which this action belongs to.
* @entry: List membership for all Actions in this Transaction.
*
* This structure must be arranged as first member in a subclassed type,
@@ -1257,6 +1258,8 @@ typedef struct BlkActionOps {
struct BlkActionState {
TransactionAction *action;
const BlkActionOps *ops;
+ BlockJobTxn *block_job_txn;
+ TransactionProperties *txn_props;
QSIMPLEQ_ENTRY(BlkActionState) entry;
};
@@ -1268,6 +1271,20 @@ typedef struct InternalSnapshotState {
QEMUSnapshotInfo sn;
} InternalSnapshotState;
+
+static int action_check_cancel_mode(BlkActionState *s, Error **errp)
+{
+ if (s->txn_props->err_cancel != ACTION_CANCEL_MODE_NONE) {
+ error_setg(errp,
+ "Action '%s' does not support Transaction property "
+ "err-cancel = %s",
+ TransactionActionKind_lookup[s->action->kind],
+ ActionCancelMode_lookup[s->txn_props->err_cancel]);
+ return -1;
+ }
+ return 0;
+}
+
static void internal_snapshot_prepare(BlkActionState *common,
Error **errp)
{
@@ -1293,6 +1310,10 @@ static void internal_snapshot_prepare(BlkActionState
*common,
name = internal->name;
/* 2. check for validation */
+ if (action_check_cancel_mode(common, errp) < 0) {
+ return;
+ }
+
blk = blk_by_name(device);
if (!blk) {
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
@@ -1444,6 +1465,10 @@ static void external_snapshot_prepare(BlkActionState
*common,
}
/* start processing */
+ if (action_check_cancel_mode(common, errp) < 0) {
+ return;
+ }
+
state->old_bs = bdrv_lookup_bs(has_device ? device : NULL,
has_node_name ? node_name : NULL,
&local_err);
@@ -1600,7 +1625,7 @@ static void drive_backup_prepare(BlkActionState *common,
Error **errp)
backup->has_bitmap, backup->bitmap,
backup->has_on_source_error, backup->on_source_error,
backup->has_on_target_error, backup->on_target_error,
- NULL, &local_err);
+ common->block_job_txn, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
@@ -1685,7 +1710,7 @@ static void blockdev_backup_prepare(BlkActionState
*common, Error **errp)
backup->has_speed, backup->speed,
backup->has_on_source_error, backup->on_source_error,
backup->has_on_target_error, backup->on_target_error,
- NULL, &local_err);
+ common->block_job_txn, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
@@ -1732,6 +1757,10 @@ static void
block_dirty_bitmap_add_prepare(BlkActionState *common,
BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
common, common);
+ if (action_check_cancel_mode(common, errp) < 0) {
+ return;
+ }
+
action = common->action->block_dirty_bitmap_add;
/* AIO context taken and released within qmp_block_dirty_bitmap_add */
qmp_block_dirty_bitmap_add(action->node, action->name,
@@ -1767,6 +1796,10 @@ static void
block_dirty_bitmap_clear_prepare(BlkActionState *common,
common, common);
BlockDirtyBitmap *action;
+ if (action_check_cancel_mode(common, errp) < 0) {
+ return;
+ }
+
action = common->action->block_dirty_bitmap_clear;
state->bitmap = block_dirty_bitmap_lookup(action->node,
action->name,
@@ -1869,19 +1902,50 @@ static const BlkActionOps actions[] = {
}
};
+/**
+ * Allocate a TransactionProperties structure if necessary, and fill
+ * that structure with desired defaults if they are unset.
+ */
+static TransactionProperties *get_transaction_properties(
+ TransactionProperties *props)
+{
+ if (!props) {
+ props = g_new0(TransactionProperties, 1);
+ }
+
+ if (!props->has_err_cancel) {
+ props->has_err_cancel = true;
+ props->err_cancel = ACTION_CANCEL_MODE_NONE;
+ }
+
+ return props;
+}
+
/*
* 'Atomic' group operations. The operations are performed as a set, and if
* any fail then we roll back all operations in the group.
*/
-void qmp_transaction(TransactionActionList *dev_list, Error **errp)
+void qmp_transaction(TransactionActionList *dev_list,
+ bool has_props,
+ struct TransactionProperties *props,
+ Error **errp)
{
TransactionActionList *dev_entry = dev_list;
+ BlockJobTxn *block_job_txn = NULL;
BlkActionState *state, *next;
Error *local_err = NULL;
QSIMPLEQ_HEAD(snap_bdrv_states, BlkActionState) snap_bdrv_states;
QSIMPLEQ_INIT(&snap_bdrv_states);
+ /* Does this transaction get canceled as a group on failure?
+ * If not, we don't really need to make a BlockJobTxn.
+ */
+ props = get_transaction_properties(props);
+ if (props->err_cancel != ACTION_CANCEL_MODE_NONE) {
+ block_job_txn = block_job_txn_new();
+ }
+
/* drain all i/o before any operations */
bdrv_drain_all();
@@ -1901,6 +1965,8 @@ void qmp_transaction(TransactionActionList *dev_list,
Error **errp)
state = g_malloc0(ops->instance_size);
state->ops = ops;
state->action = dev_info;
+ state->block_job_txn = block_job_txn;
+ state->txn_props = props;
QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, state, entry);
state->ops->prepare(state, &local_err);
@@ -1933,6 +1999,10 @@ exit:
}
g_free(state);
}
+ if (!has_props) {
+ qapi_free_TransactionProperties(props);
+ }
+ block_job_txn_unref(block_job_txn);
}
diff --git a/qapi-schema.json b/qapi-schema.json
index a73c2c9..86323e1 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1520,6 +1520,24 @@
'data': { } }
##
+# @ActionCancelMode
+#
+# An enumeration of Transactional cancellation modes.
+#
+# @none: Do not attempt to cancel any other Actions if any
+# actions fail after the Transaction request succeeds.
+# This is the default.
+#
+# @all: If any action fails after the Transaction succeeds,
+# cancel all actions. May be rejected by Actions that
+# do not support this cancellation mode.
+#
+# Since: 2.5
+##
+{ 'enum': 'ActionCancelMode',
+ 'data': [ 'none', 'all' ] }
+
+##
# @TransactionAction
#
# A discriminated record of operations that can be performed with
@@ -1546,14 +1564,35 @@
} }
##
+# @TransactionProperties
+#
+# Optional arguments to modify the behavior of a Transaction.
+#
+# @err-cancel: How failures that occur in jobs launched asynchronously
+# by a Transaction that has already completed should be handled.
+# See @ActionCancelMode for details.
+#
+# Since: 2.5
+##
+{ 'struct': 'TransactionProperties',
+ 'data': {
+ '*err-cancel': 'ActionCancelMode'
+ }
+}
+
+##
# @transaction
#
# Executes a number of transactionable QMP commands atomically. If any
# operation fails, then the entire set of actions will be abandoned and the
# appropriate error returned.
#
-# List of:
-# @TransactionAction: information needed for the respective operation
+# @actions: List of @TransactionAction;
+# information needed for the respective operations.
+#
+# @properties: Optional structure of additional options to control the
+# execution of the transaction. See @TransactionProperties
+# for additional detail.
#
# Returns: nothing on success
# Errors depend on the operations of the transaction
@@ -1565,7 +1604,10 @@
# Since 1.1
##
{ 'command': 'transaction',
- 'data': { 'actions': [ 'TransactionAction' ] } }
+ 'data': { 'actions': [ 'TransactionAction' ],
+ '*properties': 'TransactionProperties'
+ }
+}
##
# @human-monitor-command:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 2b52980..4a2cd15 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1262,7 +1262,7 @@ EQMP
},
{
.name = "transaction",
- .args_type = "actions:q",
+ .args_type = "actions:q,properties:q?",
.mhandler.cmd_new = qmp_marshal_transaction,
},
--
2.4.3
- [Qemu-block] [PATCH v10 05/14] blockjob: Introduce reference count and fix reference to job->bs, (continued)
- [Qemu-block] [PATCH v10 05/14] blockjob: Introduce reference count and fix reference to job->bs, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 01/14] qapi: Add transaction support to block-dirty-bitmap operations, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 06/14] blockjob: Add .commit and .abort block job actions, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 07/14] blockjob: Add "completed" and "ret" in BlockJob, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 03/14] block: rename BlkTransactionState and BdrvActionOps, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 08/14] blockjob: Simplify block_job_finish_sync, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 10/14] block/backup: Rely on commit/abort for cleanup, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 11/14] block: Add BlockJobTxn support to backup_run, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 09/14] block: Add block job transactions, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 14/14] tests: add BlockJobTxn unit test, John Snow, 2015/10/23
- [Qemu-block] [PATCH v10 12/14] block: add transactional properties,
John Snow <=
- [Qemu-block] [PATCH v10 13/14] iotests: 124 - transactional failure test, John Snow, 2015/10/23