@@ -2302,8 +2302,8 @@ static TransactionActionDrv bdrv_replace_child_drv = {
};
/* Caller is responsible to refresh permissions in @refresh_list */
-static void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *new_bs,
- GSList **refresh_list, Transaction *tran)
+void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *new_bs,
+ GSList **refresh_list, Transaction *tran)
{
BdrvReplaceChildState *s = g_new(BdrvReplaceChildState, 1);
*s = (BdrvReplaceChildState) {
@@ -2147,8 +2147,9 @@ static void abort_commit(void *opaque)
static int blockdev_del(const char *node_name, GSList **detached,
Transaction *tran, Error **errp);
-static int blockdev_replace(BlockdevReplace *repl, Transaction *tran,
- Error **errp)
+/* Caller is responsible to update permission of nodes added to @update_list */
+static int blockdev_replace(BlockdevReplace *repl, GSList **refresh_list,
+ Transaction *tran, Error **errp)
{
BdrvChild *child = NULL;
BlockDriverState *new_child_bs;
@@ -2201,14 +2202,27 @@ static int blockdev_replace(BlockdevReplace *repl, Transaction *tran,
return -EINVAL;
}
- return bdrv_replace_child_bs(child, new_child_bs, tran, errp);
+ bdrv_replace_child_tran(child, new_child_bs, refresh_list, tran);
+ return 0;
}
void qmp_x_blockdev_replace(BlockdevReplace *repl, Error **errp)
{
+ int ret;
Transaction *tran = tran_new();
- int ret = blockdev_replace(repl, tran, errp);
+ g_autoptr(GSList) update_list = NULL;
+
+ ret = blockdev_replace(repl, &update_list, tran, errp);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = bdrv_list_refresh_perms(update_list, NULL, tran, errp);
+ if (ret < 0) {
+ goto out;
+ }
+
+out:
tran_finalize(tran, ret);
}
@@ -2268,6 +2282,10 @@ static void transaction_action(TransactionAction *act, JobTxn *block_job_txn,
blockdev_add(act->u.blockdev_add.data,
refresh_list, tran, errp);
return;
+ case TRANSACTION_ACTION_KIND_X_BLOCKDEV_REPLACE:
+ blockdev_replace(act->u.x_blockdev_replace.data,
+ refresh_list, tran, errp);
+ return;
/*
* Where are transactions for MIRROR, COMMIT and STREAM?
* Although these blockjobs use transaction callbacks like the backup job,
@@ -2332,7 +2350,8 @@ void qmp_transaction(TransactionActionList *actions,
if (refresh_list &&
type != TRANSACTION_ACTION_KIND_BLOCKDEV_DEL &&
- type != TRANSACTION_ACTION_KIND_BLOCKDEV_ADD)
+ type != TRANSACTION_ACTION_KIND_BLOCKDEV_ADD &&
+ type != TRANSACTION_ACTION_KIND_X_BLOCKDEV_REPLACE)
{
ret = bdrv_list_refresh_perms(refresh_list, NULL, tran, errp);
if (ret < 0) {
@@ -406,6 +406,8 @@ int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
Error **errp);
int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,
Transaction *tran, Error **errp);
+void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *new_bs,
+ GSList **refresh_list, Transaction *tran);
BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_options,
int flags, Error **errp);
int bdrv_drop_filter(BlockDriverState *bs, Error **errp);
@@ -54,10 +54,13 @@
# @blockdev-snapshot-sync: since 1.1
# @drive-backup: Since 1.6
# @blockdev-del: since 7.1
+# @blockdev-add: since 7.1
+# @x-blockdev-replace: since 7.1
#
# Features:
# @deprecated: Member @drive-backup is deprecated. Use member
# @blockdev-backup instead.
+# @unstable: Member @x-blockdev-replace is experimental
#
# Since: 1.1
##
@@ -68,6 +71,7 @@
'blockdev-backup', 'blockdev-snapshot',
'blockdev-snapshot-internal-sync', 'blockdev-snapshot-sync',
'blockdev-del', 'blockdev-add',
+ { 'name': 'x-blockdev-replace', 'features': [ 'unstable' ] },
{ 'name': 'drive-backup', 'features': [ 'deprecated' ] } ] }
##
@@ -158,6 +162,14 @@
{ 'struct': 'BlockdevAddWrapper',
'data': { 'data': 'BlockdevOptions' } }
+##
+# @BlockdevReplaceWrapper:
+#
+# Since: 7.1
+##
+{ 'struct': 'BlockdevReplaceWrapper',
+ 'data': { 'data': 'BlockdevReplace' } }
+
##
# @TransactionAction:
#
@@ -183,7 +195,8 @@
'blockdev-snapshot-sync': 'BlockdevSnapshotSyncWrapper',
'blockdev-del': 'BlockdevDelWrapper',
'blockdev-add': 'BlockdevAddWrapper',
- 'drive-backup': 'DriveBackupWrapper'
+ 'drive-backup': 'DriveBackupWrapper',
+ 'x-blockdev-replace': 'BlockdevReplaceWrapper'
} }
##
Support blockdev-replace in a transaction. Signed-off-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru> --- block.c | 4 ++-- blockdev.c | 29 ++++++++++++++++++++++++----- include/block/block.h | 2 ++ qapi/transaction.json | 15 ++++++++++++++- 4 files changed, 42 insertions(+), 8 deletions(-)