qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hanna Reitz <hreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Hanna Reitz <hreitz@redhat.com>,
	qemu-devel@nongnu.org
Subject: [PULL 21/56] block: introduce bdrv_replace_child_bs()
Date: Wed,  1 Sep 2021 17:15:44 +0200	[thread overview]
Message-ID: <20210901151619.689075-22-hreitz@redhat.com> (raw)
In-Reply-To: <20210901151619.689075-1-hreitz@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

Add function to transactionally replace bs inside BdrvChild.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210824083856.17408-2-vsementsov@virtuozzo.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
 include/block/block.h |  2 ++
 block.c               | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/include/block/block.h b/include/block/block.h
index 3477290f9a..740038a892 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -361,6 +361,8 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
                 Error **errp);
 int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
                       Error **errp);
+int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,
+                          Error **errp);
 BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_options,
                                    int flags, Error **errp);
 int bdrv_drop_filter(BlockDriverState *bs, Error **errp);
diff --git a/block.c b/block.c
index e97ce0b1c8..b2b66263f9 100644
--- a/block.c
+++ b/block.c
@@ -5048,6 +5048,37 @@ out:
     return ret;
 }
 
+/* Not for empty child */
+int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,
+                          Error **errp)
+{
+    int ret;
+    Transaction *tran = tran_new();
+    g_autoptr(GHashTable) found = NULL;
+    g_autoptr(GSList) refresh_list = NULL;
+    BlockDriverState *old_bs = child->bs;
+
+    bdrv_ref(old_bs);
+    bdrv_drained_begin(old_bs);
+    bdrv_drained_begin(new_bs);
+
+    bdrv_replace_child_tran(child, new_bs, tran);
+
+    found = g_hash_table_new(NULL, NULL);
+    refresh_list = bdrv_topological_dfs(refresh_list, found, old_bs);
+    refresh_list = bdrv_topological_dfs(refresh_list, found, new_bs);
+
+    ret = bdrv_list_refresh_perms(refresh_list, NULL, tran, errp);
+
+    tran_finalize(tran, ret);
+
+    bdrv_drained_end(old_bs);
+    bdrv_drained_end(new_bs);
+    bdrv_unref(old_bs);
+
+    return ret;
+}
+
 static void bdrv_delete(BlockDriverState *bs)
 {
     assert(bdrv_op_blocker_is_empty(bs));
-- 
2.31.1



  parent reply	other threads:[~2021-09-01 15:38 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 15:15 [PULL 00/56] Block patches Hanna Reitz
2021-09-01 15:15 ` [PULL 01/56] python: qemu: add timer parameter for qmp.accept socket Hanna Reitz
2021-09-01 15:15 ` [PULL 02/56] python: Reduce strictness of pylint's duplicate-code check Hanna Reitz
2021-09-01 15:15 ` [PULL 03/56] python: qemu: pass the wrapper field from QEMUQtestmachine to QEMUMachine Hanna Reitz
2021-09-01 15:15 ` [PULL 04/56] docs/devel/testing: add debug section to the QEMU iotests chapter Hanna Reitz
2021-09-01 15:15 ` [PULL 05/56] qemu-iotests: add option to attach gdbserver Hanna Reitz
2021-09-01 15:15 ` [PULL 06/56] qemu-iotests: delay QMP socket timers Hanna Reitz
2021-09-01 15:15 ` [PULL 07/56] qemu_iotests: insert gdbserver command line as wrapper for qemu binary Hanna Reitz
2021-09-01 15:15 ` [PULL 08/56] qemu-iotests: add gdbserver option to script tests too Hanna Reitz
2021-09-01 15:15 ` [PULL 09/56] docs/devel/testing: add -gdb option to the debugging section of QEMU iotests Hanna Reitz
2021-09-01 15:15 ` [PULL 10/56] qemu-iotests: extend the check script to prepare supporting valgrind for python tests Hanna Reitz
2021-09-01 15:15 ` [PULL 11/56] qemu-iotests: extend QMP socket timeout when using valgrind Hanna Reitz
2021-09-01 15:15 ` [PULL 12/56] qemu-iotests: allow valgrind to read/delete the generated log file Hanna Reitz
2021-09-01 15:15 ` [PULL 13/56] qemu-iotests: insert valgrind command line as wrapper for qemu binary Hanna Reitz
2021-09-01 15:15 ` [PULL 14/56] docs/devel/testing: add -valgrind option to the debug section of QEMU iotests Hanna Reitz
2021-09-01 15:15 ` [PULL 15/56] qemu-iotests: add option to show qemu binary logs on stdout Hanna Reitz
2021-09-01 15:15 ` [PULL 16/56] docs/devel/testing: add -p option to the debug section of QEMU iotests Hanna Reitz
2021-09-01 15:15 ` [PULL 17/56] block/monitor: Consolidate hmp_handle_error calls to reduce redundant code Hanna Reitz
2021-09-01 15:15 ` [PULL 18/56] raw-format: drop WRITE and RESIZE child perms when possible Hanna Reitz
2021-09-01 15:15 ` [PULL 19/56] iotests: use with-statement for open() calls Hanna Reitz
2021-09-01 15:15 ` [PULL 20/56] iotests: use subprocess.DEVNULL instead of open("/dev/null") Hanna Reitz
2021-09-01 15:15 ` Hanna Reitz [this message]
2021-09-01 15:15 ` [PULL 22/56] block: introduce blk_replace_bs Hanna Reitz
2021-09-01 15:15 ` [PULL 23/56] qdev-properties: PropertyInfo: add realized_set_allowed field Hanna Reitz
2021-09-01 15:15 ` [PULL 24/56] qdev: allow setting drive property for realized device Hanna Reitz
2021-09-01 15:15 ` [PULL 25/56] block: rename backup-top to copy-before-write Hanna Reitz
2021-09-01 15:15 ` [PULL 26/56] block-copy: move detecting fleecing scheme to block-copy Hanna Reitz
2021-09-01 15:15 ` [PULL 27/56] block/block-copy: introduce block_copy_set_copy_opts() Hanna Reitz
2021-09-01 15:15 ` [PULL 28/56] block/backup: set copy_range and compress after filter insertion Hanna Reitz
2021-09-01 15:15 ` [PULL 29/56] block/backup: move cluster size calculation to block-copy Hanna Reitz
2021-09-01 15:15 ` [PULL 30/56] block/copy-before-write: relax permission requirements when no parents Hanna Reitz
2021-09-01 15:15 ` [PULL 31/56] block/copy-before-write: drop extra bdrv_unref on failure path Hanna Reitz
2021-09-01 15:15 ` [PULL 32/56] block/copy-before-write: use file child instead of backing Hanna Reitz
2021-09-01 15:15 ` [PULL 33/56] block/copy-before-write: bdrv_cbw_append(): replace child at last Hanna Reitz
2021-09-01 15:15 ` [PULL 34/56] block/copy-before-write: introduce cbw_init() Hanna Reitz
2021-09-01 15:15 ` [PULL 35/56] block/copy-before-write: cbw_init(): rename variables Hanna Reitz
2021-09-01 15:15 ` [PULL 36/56] block/copy-before-write: cbw_init(): use file child after attaching Hanna Reitz
2021-09-01 15:16 ` [PULL 37/56] block/copy-before-write: bdrv_cbw_append(): drop unused compress arg Hanna Reitz
2021-09-01 15:16 ` [PULL 38/56] block/copy-before-write: cbw_init(): use options Hanna Reitz
2021-09-01 15:16 ` [PULL 39/56] block/copy-before-write: initialize block-copy bitmap Hanna Reitz
2021-09-01 15:16 ` [PULL 40/56] block/block-copy: make setting progress optional Hanna Reitz
2021-09-01 15:16 ` [PULL 41/56] block/copy-before-write: make public block driver Hanna Reitz
2021-09-20  9:41   ` Kevin Wolf
2021-09-20 10:08     ` Vladimir Sementsov-Ogievskiy
2021-09-01 15:16 ` [PULL 42/56] qapi: publish copy-before-write filter Hanna Reitz
2021-09-01 15:16 ` [PULL 43/56] python/qemu/machine.py: refactor _qemu_args() Hanna Reitz
2021-09-01 15:16 ` [PULL 44/56] python/qemu/machine: QEMUMachine: improve qmp() method Hanna Reitz
2021-09-01 15:16 ` [PULL 45/56] python:QEMUMachine: template typing for self returning methods Hanna Reitz
2021-09-01 15:16 ` [PULL 46/56] iotests/222: fix pylint and mypy complains Hanna Reitz
2021-09-01 15:16 ` [PULL 47/56] iotests/222: constantly use single quotes for strings Hanna Reitz
2021-09-01 15:16 ` [PULL 48/56] iotests: move 222 to tests/image-fleecing Hanna Reitz
2021-09-01 15:16 ` [PULL 49/56] iotests.py: hmp_qemu_io: support qdev Hanna Reitz
2021-09-01 15:16 ` [PULL 50/56] iotests/image-fleecing: proper source device Hanna Reitz
2021-09-01 15:16 ` [PULL 51/56] iotests/image-fleecing: rename tgt_node Hanna Reitz
2021-09-01 15:16 ` [PULL 52/56] iotests/image-fleecing: prepare for adding new test-case Hanna Reitz
2021-09-01 15:16 ` [PULL 53/56] iotests/image-fleecing: add test-case for copy-before-write filter Hanna Reitz
2021-09-01 15:16 ` [PULL 54/56] block/block-copy: block_copy_state_new(): drop extra arguments Hanna Reitz
2021-09-01 15:16 ` [PULL 55/56] block/export/fuse.c: fix fuse-lseek on uclibc or musl Hanna Reitz
2021-09-01 15:16 ` [PULL 56/56] block/file-win32: add reopen handlers Hanna Reitz
2021-09-02 11:07 ` [PULL 00/56] Block patches Peter Maydell
2021-09-02 11:21   ` Hanna Reitz
2021-09-02 13:56 ` Peter Maydell

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=20210901151619.689075-22-hreitz@redhat.com \
    --to=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.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).