From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 04/18] blockdev: transaction: refactor handling transaction properties
Date: Wed, 17 May 2023 18:51:02 +0200 [thread overview]
Message-ID: <20230517165116.475123-5-kwolf@redhat.com> (raw)
In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com>
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Only backup supports GROUPED mode. Make this logic more clear. And
avoid passing extra thing to each action.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20230510150624.310640-5-vsementsov@yandex-team.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
blockdev.c | 96 +++++++++++++-----------------------------------------
1 file changed, 22 insertions(+), 74 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index dd0e98bbe1..a2ebaa5afc 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1230,7 +1230,6 @@ struct BlkActionState {
TransactionAction *action;
const BlkActionOps *ops;
JobTxn *block_job_txn;
- TransactionProperties *txn_props;
QTAILQ_ENTRY(BlkActionState) entry;
};
@@ -1249,19 +1248,6 @@ TransactionActionDrv internal_snapshot_drv = {
.clean = internal_snapshot_clean,
};
-static int action_check_completion_mode(BlkActionState *s, Error **errp)
-{
- if (s->txn_props->completion_mode != ACTION_COMPLETION_MODE_INDIVIDUAL) {
- error_setg(errp,
- "Action '%s' does not support Transaction property "
- "completion-mode = %s",
- TransactionActionKind_str(s->action->type),
- ActionCompletionMode_str(s->txn_props->completion_mode));
- return -1;
- }
- return 0;
-}
-
static void internal_snapshot_action(BlkActionState *common,
Transaction *tran, Error **errp)
{
@@ -1284,15 +1270,9 @@ static void internal_snapshot_action(BlkActionState *common,
tran_add(tran, &internal_snapshot_drv, state);
- /* 1. parse input */
device = internal->device;
name = internal->name;
- /* 2. check for validation */
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
bs = qmp_get_root_bs(device, errp);
if (!bs) {
return;
@@ -1476,9 +1456,6 @@ static void external_snapshot_action(BlkActionState *common, Transaction *tran,
}
/* start processing */
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
state->old_bs = bdrv_lookup_bs(device, node_name, errp);
if (!state->old_bs) {
@@ -2022,10 +1999,6 @@ static void block_dirty_bitmap_add_action(BlkActionState *common,
tran_add(tran, &block_dirty_bitmap_add_drv, state);
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
action = common->action->u.block_dirty_bitmap_add.data;
/* AIO context taken and released within qmp_block_dirty_bitmap_add */
qmp_block_dirty_bitmap_add(action->node, action->name,
@@ -2072,10 +2045,6 @@ static void block_dirty_bitmap_clear_action(BlkActionState *common,
tran_add(tran, &block_dirty_bitmap_clear_drv, state);
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
action = common->action->u.block_dirty_bitmap_clear.data;
state->bitmap = block_dirty_bitmap_lookup(action->node,
action->name,
@@ -2123,10 +2092,6 @@ static void block_dirty_bitmap_enable_action(BlkActionState *common,
tran_add(tran, &block_dirty_bitmap_enable_drv, state);
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
action = common->action->u.block_dirty_bitmap_enable.data;
state->bitmap = block_dirty_bitmap_lookup(action->node,
action->name,
@@ -2168,10 +2133,6 @@ static void block_dirty_bitmap_disable_action(BlkActionState *common,
tran_add(tran, &block_dirty_bitmap_disable_drv, state);
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
action = common->action->u.block_dirty_bitmap_disable.data;
state->bitmap = block_dirty_bitmap_lookup(action->node,
action->name,
@@ -2213,10 +2174,6 @@ static void block_dirty_bitmap_merge_action(BlkActionState *common,
tran_add(tran, &block_dirty_bitmap_merge_drv, state);
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
action = common->action->u.block_dirty_bitmap_merge.data;
state->bitmap = block_dirty_bitmap_merge(action->node, action->target,
@@ -2241,10 +2198,6 @@ static void block_dirty_bitmap_remove_action(BlkActionState *common,
tran_add(tran, &block_dirty_bitmap_remove_drv, state);
- if (action_check_completion_mode(common, errp) < 0) {
- return;
- }
-
action = common->action->u.block_dirty_bitmap_remove.data;
state->bitmap = block_dirty_bitmap_remove(action->node, action->name,
@@ -2348,25 +2301,6 @@ static const BlkActionOps actions_map[] = {
*/
};
-/**
- * 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_completion_mode) {
- props->has_completion_mode = true;
- props->completion_mode = ACTION_COMPLETION_MODE_INDIVIDUAL;
- }
-
- 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.
@@ -2378,24 +2312,42 @@ void qmp_transaction(TransactionActionList *actions,
Error **errp)
{
TransactionActionList *act;
- bool has_properties = !!properties;
JobTxn *block_job_txn = NULL;
Error *local_err = NULL;
- Transaction *tran = tran_new();
+ Transaction *tran;
+ ActionCompletionMode comp_mode =
+ properties ? properties->completion_mode :
+ ACTION_COMPLETION_MODE_INDIVIDUAL;
GLOBAL_STATE_CODE();
/* Does this transaction get canceled as a group on failure?
* If not, we don't really need to make a JobTxn.
*/
- properties = get_transaction_properties(properties);
- if (properties->completion_mode != ACTION_COMPLETION_MODE_INDIVIDUAL) {
+ if (comp_mode != ACTION_COMPLETION_MODE_INDIVIDUAL) {
+ for (act = actions; act; act = act->next) {
+ TransactionActionKind type = act->value->type;
+
+ if (type != TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP &&
+ type != TRANSACTION_ACTION_KIND_DRIVE_BACKUP)
+ {
+ error_setg(errp,
+ "Action '%s' does not support transaction property "
+ "completion-mode = %s",
+ TransactionActionKind_str(type),
+ ActionCompletionMode_str(comp_mode));
+ return;
+ }
+ }
+
block_job_txn = job_txn_new();
}
/* drain all i/o before any operations */
bdrv_drain_all();
+ tran = tran_new();
+
/* We don't do anything in this loop that commits us to the operations */
for (act = actions; act; act = act->next) {
TransactionAction *dev_info = act->value;
@@ -2411,7 +2363,6 @@ void qmp_transaction(TransactionActionList *actions,
state->ops = ops;
state->action = dev_info;
state->block_job_txn = block_job_txn;
- state->txn_props = properties;
state->ops->action(state, tran, &local_err);
if (local_err) {
@@ -2429,9 +2380,6 @@ delete_and_fail:
/* failure, and it is all-or-none; roll back all operations */
tran_abort(tran);
exit:
- if (!has_properties) {
- qapi_free_TransactionProperties(properties);
- }
job_txn_unref(block_job_txn);
}
--
2.40.1
next prev parent reply other threads:[~2023-05-17 16:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 16:50 [PULL 00/18] Block layer patches Kevin Wolf
2023-05-17 16:50 ` [PULL 01/18] blockdev: refactor transaction to use Transaction API Kevin Wolf
2023-05-17 16:51 ` [PULL 02/18] blockdev: transactions: rename some things Kevin Wolf
2023-05-17 16:51 ` [PULL 03/18] blockdev: qmp_transaction: refactor loop to classic for Kevin Wolf
2023-05-17 16:51 ` Kevin Wolf [this message]
2023-05-17 16:51 ` [PULL 05/18] blockdev: use state.bitmap in block-dirty-bitmap-add action Kevin Wolf
2023-05-17 16:51 ` [PULL 06/18] blockdev: qmp_transaction: drop extra generic layer Kevin Wolf
2023-05-17 16:51 ` [PULL 07/18] docs/interop/qcow2.txt: fix description about "zlib" clusters Kevin Wolf
2023-05-17 16:51 ` [PULL 08/18] block: Call .bdrv_co_create(_opts) unlocked Kevin Wolf
2023-05-17 16:51 ` [PULL 09/18] block/export: Fix null pointer dereference in error path Kevin Wolf
2023-05-17 16:51 ` [PULL 10/18] qcow2: Unlock the graph in qcow2_do_open() where necessary Kevin Wolf
2023-05-17 16:51 ` [PULL 11/18] qemu-img: Take graph lock more selectively Kevin Wolf
2023-05-17 16:51 ` [PULL 12/18] test-bdrv-drain: " Kevin Wolf
2023-05-17 16:51 ` [PULL 13/18] test-bdrv-drain: Call bdrv_co_unref() in coroutine context Kevin Wolf
2023-05-17 16:51 ` [PULL 14/18] blockjob: Adhere to rate limit even when reentered early Kevin Wolf
2023-05-17 16:51 ` [PULL 15/18] graph-lock: Honour read locks even in the main thread Kevin Wolf
2023-05-17 16:51 ` [PULL 16/18] iotests/245: Check if 'compress' driver is available Kevin Wolf
2023-05-17 16:51 ` [PULL 17/18] aio-posix: do not nest poll handlers Kevin Wolf
2023-05-18 7:13 ` Michael Tokarev
2023-05-18 15:05 ` Stefan Hajnoczi
2023-05-17 16:51 ` [PULL 18/18] tested: add test for nested aio_poll() in " Kevin Wolf
2023-05-17 19:10 ` Richard Henderson
2023-05-19 9:23 ` Kevin Wolf
2023-05-23 15:36 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230517165116.475123-5-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).