[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/39] block: introduce bdrv_drop_filter()
From: |
Kevin Wolf |
Subject: |
[PULL 23/39] block: introduce bdrv_drop_filter() |
Date: |
Fri, 30 Apr 2021 12:51:31 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Using bdrv_replace_node() for removing filter is not good enough: it
keeps child reference of the filter, which may conflict with original
top node during permission update.
Instead let's create new interface, which will do all graph
modifications first and then update permissions.
Let's modify bdrv_replace_node_common(), allowing it additionally drop
backing chain child link pointing to new node. This is quite
appropriate for bdrv_drop_intermediate() and makes possible to add
new bdrv_drop_filter() as a simple wrapper.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210428151804.439460-24-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block.h | 1 +
block.c | 43 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/include/block/block.h b/include/block/block.h
index 16e496a5c4..85481a05c6 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -362,6 +362,7 @@ int bdrv_replace_node(BlockDriverState *from,
BlockDriverState *to,
Error **errp);
BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_options,
int flags, Error **errp);
+int bdrv_drop_filter(BlockDriverState *bs, Error **errp);
int bdrv_parse_aio(const char *mode, int *flags);
int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough);
diff --git a/block.c b/block.c
index 2ea9cc110d..68dfd822dd 100644
--- a/block.c
+++ b/block.c
@@ -5041,7 +5041,6 @@ static TransactionActionDrv
bdrv_remove_filter_or_cow_child_drv = {
* format nodes (always .backing) and filter child for filters (may be .file or
* .backing)
*/
-__attribute__((unused))
static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs,
Transaction *tran)
{
@@ -5105,16 +5104,32 @@ static int bdrv_replace_node_noperm(BlockDriverState
*from,
*
* With auto_skip=false the error is returned if from has a parent which should
* not be updated.
+ *
+ * With @detach_subchain=true @to must be in a backing chain of @from. In this
+ * case backing link of the cow-parent of @to is removed.
*/
static int bdrv_replace_node_common(BlockDriverState *from,
BlockDriverState *to,
- bool auto_skip, Error **errp)
+ bool auto_skip, bool detach_subchain,
+ Error **errp)
{
Transaction *tran = tran_new();
g_autoptr(GHashTable) found = NULL;
g_autoptr(GSList) refresh_list = NULL;
+ BlockDriverState *to_cow_parent;
int ret;
+ if (detach_subchain) {
+ assert(bdrv_chain_contains(from, to));
+ assert(from != to);
+ for (to_cow_parent = from;
+ bdrv_filter_or_cow_bs(to_cow_parent) != to;
+ to_cow_parent = bdrv_filter_or_cow_bs(to_cow_parent))
+ {
+ ;
+ }
+ }
+
/* Make sure that @from doesn't go away until we have successfully attached
* all of its parents to @to. */
bdrv_ref(from);
@@ -5134,6 +5149,10 @@ static int bdrv_replace_node_common(BlockDriverState
*from,
goto out;
}
+ if (detach_subchain) {
+ bdrv_remove_filter_or_cow_child(to_cow_parent, tran);
+ }
+
found = g_hash_table_new(NULL, NULL);
refresh_list = bdrv_topological_dfs(refresh_list, found, to);
@@ -5158,7 +5177,13 @@ out:
int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
Error **errp)
{
- return bdrv_replace_node_common(from, to, true, errp);
+ return bdrv_replace_node_common(from, to, true, false, errp);
+}
+
+int bdrv_drop_filter(BlockDriverState *bs, Error **errp)
+{
+ return bdrv_replace_node_common(bs, bdrv_filter_or_cow_bs(bs), true, true,
+ errp);
}
/*
@@ -5493,7 +5518,17 @@ int bdrv_drop_intermediate(BlockDriverState *top,
BlockDriverState *base,
updated_children = g_slist_prepend(updated_children, c);
}
- bdrv_replace_node_common(top, base, false, &local_err);
+ /*
+ * It seems correct to pass detach_subchain=true here, but it triggers
+ * one more yet not fixed bug, when due to nested aio_poll loop we switch
to
+ * another drained section, which modify the graph (for example, removing
+ * the child, which we keep in updated_children list). So, it's a TODO.
+ *
+ * Note, bug triggered if pass detach_subchain=true here and run
+ * test-bdrv-drain. test_drop_intermediate_poll() test-case will crash.
+ * That's a FIXME.
+ */
+ bdrv_replace_node_common(top, base, false, false, &local_err);
if (local_err) {
error_report_err(local_err);
goto exit;
--
2.30.2
- [PULL 10/39] block: refactor bdrv_child* permission functions, (continued)
- [PULL 10/39] block: refactor bdrv_child* permission functions, Kevin Wolf, 2021/04/30
- [PULL 12/39] block: inline bdrv_child_*() permission functions calls, Kevin Wolf, 2021/04/30
- [PULL 13/39] block: use topological sort for permission update, Kevin Wolf, 2021/04/30
- [PULL 14/39] block: add bdrv_drv_set_perm transaction action, Kevin Wolf, 2021/04/30
- [PULL 15/39] block: add bdrv_list_* permission update functions, Kevin Wolf, 2021/04/30
- [PULL 17/39] block: fix bdrv_replace_node_common, Kevin Wolf, 2021/04/30
- [PULL 19/39] block: add bdrv_attach_child_noperm() transaction action, Kevin Wolf, 2021/04/30
- [PULL 18/39] block: add bdrv_attach_child_common() transaction action, Kevin Wolf, 2021/04/30
- [PULL 20/39] block: split out bdrv_replace_node_noperm(), Kevin Wolf, 2021/04/30
- [PULL 16/39] block: add bdrv_replace_child_safe() transaction action, Kevin Wolf, 2021/04/30
- [PULL 23/39] block: introduce bdrv_drop_filter(),
Kevin Wolf <=
- [PULL 22/39] block: add bdrv_remove_filter_or_cow transaction action, Kevin Wolf, 2021/04/30
- [PULL 21/39] block: adapt bdrv_append() for inserting filters, Kevin Wolf, 2021/04/30
- [PULL 24/39] block/backup-top: drop .active, Kevin Wolf, 2021/04/30
- [PULL 25/39] block: drop ignore_children for permission update functions, Kevin Wolf, 2021/04/30
- [PULL 26/39] block: make bdrv_unset_inherits_from to be a transaction action, Kevin Wolf, 2021/04/30
- [PULL 28/39] block: add bdrv_set_backing_noperm() transaction action, Kevin Wolf, 2021/04/30
- [PULL 29/39] block: bdrv_reopen_multiple(): move bdrv_flush to separate pre-prepare, Kevin Wolf, 2021/04/30
- [PULL 34/39] block: refactor bdrv_child_set_perm_safe() transaction action, Kevin Wolf, 2021/04/30
- [PULL 33/39] block: inline bdrv_replace_child(), Kevin Wolf, 2021/04/30
- [PULL 27/39] block: make bdrv_refresh_limits() to be a transaction action, Kevin Wolf, 2021/04/30