[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 21/36] block: adapt bdrv_append() for inserting filters
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 21/36] block: adapt bdrv_append() for inserting filters |
Date: |
Wed, 17 Mar 2021 17:35:14 +0300 |
bdrv_append is not very good for inserting filters: it does extra
permission update as part of bdrv_set_backing_hd(). During this update
filter may conflict with other parents of top_bs.
Instead, let's first do all graph modifications and after it update
permissions.
append-greedy-filter test-case in test-bdrv-graph-mod is now works, so
move it out of debug option.
Note: bdrv_append() is still only works for backing-child based
filters. It's something to improve later.
Note2: we use the fact that bdrv_append() is used to append new nodes,
without backing child, so we don't need frozen check and inherits_from
logic from bdrv_set_backing_hd().
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block.c | 27 ++++++++++++++++++++-------
tests/unit/test-bdrv-graph-mod.c | 17 ++---------------
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/block.c b/block.c
index 433cae1181..11f7ad0818 100644
--- a/block.c
+++ b/block.c
@@ -5053,25 +5053,38 @@ int bdrv_replace_node(BlockDriverState *from,
BlockDriverState *to,
* This will modify the BlockDriverState fields, and swap contents
* between bs_new and bs_top. Both bs_new and bs_top are modified.
*
- * bs_new must not be attached to a BlockBackend.
+ * bs_new must not be attached to a BlockBackend and must not have backing
+ * child.
*
* This function does not create any image files.
*/
int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
Error **errp)
{
- int ret = bdrv_set_backing_hd(bs_new, bs_top, errp);
+ int ret;
+ Transaction *tran = tran_new();
+
+ assert(!bs_new->backing);
+
+ ret = bdrv_attach_child_noperm(bs_new, bs_top, "backing",
+ &child_of_bds, bdrv_backing_role(bs_new),
+ &bs_new->backing, tran, errp);
if (ret < 0) {
- return ret;
+ goto out;
}
- ret = bdrv_replace_node(bs_top, bs_new, errp);
+ ret = bdrv_replace_node_noperm(bs_top, bs_new, true, tran, errp);
if (ret < 0) {
- bdrv_set_backing_hd(bs_new, NULL, &error_abort);
- return ret;
+ goto out;
}
- return 0;
+ ret = bdrv_refresh_perms(bs_new, errp);
+out:
+ tran_finalize(tran, ret);
+
+ bdrv_refresh_limits(bs_top, NULL);
+
+ return ret;
}
static void bdrv_delete(BlockDriverState *bs)
diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c
index b81787487a..f6077a6525 100644
--- a/tests/unit/test-bdrv-graph-mod.c
+++ b/tests/unit/test-bdrv-graph-mod.c
@@ -387,16 +387,6 @@ static void test_append_greedy_filter(void)
int main(int argc, char *argv[])
{
- int i;
- bool debug = false;
-
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-d")) {
- debug = true;
- break;
- }
- }
-
bdrv_init();
qemu_init_main_loop(&error_abort);
@@ -409,11 +399,8 @@ int main(int argc, char *argv[])
test_parallel_perm_update);
g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write",
test_parallel_exclusive_write);
-
- if (debug) {
- g_test_add_func("/bdrv-graph-mod/append-greedy-filter",
- test_append_greedy_filter);
- }
+ g_test_add_func("/bdrv-graph-mod/append-greedy-filter",
+ test_append_greedy_filter);
return g_test_run();
}
--
2.29.2
- [PATCH v3 08/36] util: add transactions.c, (continued)
- [PATCH v3 08/36] util: add transactions.c, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 05/36] block: BdrvChildClass: add .get_parent_aio_context handler, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 09/36] block: bdrv_refresh_perms: check for parents permissions conflict, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 10/36] block: refactor bdrv_child* permission functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 12/36] block: inline bdrv_child_*() permission functions calls, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 11/36] block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 17/36] block: fix bdrv_replace_node_common, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 13/36] block: use topological sort for permission update, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 19/36] block: add bdrv_attach_child_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 20/36] block: split out bdrv_replace_node_noperm(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 21/36] block: adapt bdrv_append() for inserting filters,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v3 18/36] block: add bdrv_attach_child_common() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 14/36] block: add bdrv_drv_set_perm transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 25/36] block: drop ignore_children for permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 23/36] block: introduce bdrv_drop_filter(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 22/36] block: add bdrv_remove_filter_or_cow transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 27/36] block: make bdrv_refresh_limits() to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 32/36] block: inline bdrv_check_perm_common(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 26/36] block: make bdrv_unset_inherits_from to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 24/36] block/backup-top: drop .active, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 28/36] block: add bdrv_set_backing_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17