[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/51] block: refactor bdrv_list_refresh_perms to allow any list o
From: |
Kevin Wolf |
Subject: |
[PULL 04/51] block: refactor bdrv_list_refresh_perms to allow any list of nodes |
Date: |
Wed, 14 Dec 2022 14:44:06 +0100 |
From: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
We are going to increase usage of collecting nodes in a list to then
update, and calling bdrv_topological_dfs() each time is not convenient,
and not correct as we are going to interleave graph modifying with
filling the node list.
So, let's switch to a function that takes any list of nodes, adds all
their subtrees and do topological sort. And finally, refresh
permissions.
While being here, make the function public, as we'll want to use it
from blockdev.c in near future.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221107163558.618889-5-vsementsov@yandex-team.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 51 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/block.c b/block.c
index f2f9178832..385ed3cd53 100644
--- a/block.c
+++ b/block.c
@@ -2521,8 +2521,12 @@ static int bdrv_node_refresh_perm(BlockDriverState *bs,
BlockReopenQueue *q,
return 0;
}
-static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q,
- Transaction *tran, Error **errp)
+/*
+ * @list is a product of bdrv_topological_dfs() (may be called several times) -
+ * a topologically sorted subgraph.
+ */
+static int bdrv_do_refresh_perms(GSList *list, BlockReopenQueue *q,
+ Transaction *tran, Error **errp)
{
int ret;
BlockDriverState *bs;
@@ -2544,6 +2548,24 @@ static int bdrv_list_refresh_perms(GSList *list,
BlockReopenQueue *q,
return 0;
}
+/*
+ * @list is any list of nodes. List is completed by all subtrees and
+ * topologically sorted. It's not a problem if some node occurs in the @list
+ * several times.
+ */
+static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q,
+ Transaction *tran, Error **errp)
+{
+ g_autoptr(GHashTable) found = g_hash_table_new(NULL, NULL);
+ g_autoptr(GSList) refresh_list = NULL;
+
+ for ( ; list; list = list->next) {
+ refresh_list = bdrv_topological_dfs(refresh_list, found, list->data);
+ }
+
+ return bdrv_do_refresh_perms(refresh_list, q, tran, errp);
+}
+
void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
uint64_t *shared_perm)
{
@@ -2604,7 +2626,7 @@ static int bdrv_refresh_perms(BlockDriverState *bs,
Transaction *tran,
tran = local_tran = tran_new();
}
- ret = bdrv_list_refresh_perms(list, NULL, tran, errp);
+ ret = bdrv_do_refresh_perms(list, NULL, tran, errp);
if (local_tran) {
tran_finalize(local_tran, ret);
@@ -4360,7 +4382,6 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue,
Error **errp)
BlockReopenQueueEntry *bs_entry, *next;
AioContext *ctx;
Transaction *tran = tran_new();
- g_autoptr(GHashTable) found = NULL;
g_autoptr(GSList) refresh_list = NULL;
assert(qemu_get_current_aio_context() == qemu_get_aio_context());
@@ -4390,18 +4411,15 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue,
Error **errp)
bs_entry->prepared = true;
}
- found = g_hash_table_new(NULL, NULL);
QTAILQ_FOREACH(bs_entry, bs_queue, entry) {
BDRVReopenState *state = &bs_entry->state;
- refresh_list = bdrv_topological_dfs(refresh_list, found, state->bs);
+ refresh_list = g_slist_prepend(refresh_list, state->bs);
if (state->old_backing_bs) {
- refresh_list = bdrv_topological_dfs(refresh_list, found,
- state->old_backing_bs);
+ refresh_list = g_slist_prepend(refresh_list,
state->old_backing_bs);
}
if (state->old_file_bs) {
- refresh_list = bdrv_topological_dfs(refresh_list, found,
- state->old_file_bs);
+ refresh_list = g_slist_prepend(refresh_list, state->old_file_bs);
}
}
@@ -5118,7 +5136,6 @@ static int bdrv_replace_node_common(BlockDriverState
*from,
Error **errp)
{
Transaction *tran = tran_new();
- g_autoptr(GHashTable) found = NULL;
g_autoptr(GSList) refresh_list = NULL;
BlockDriverState *to_cow_parent = NULL;
int ret;
@@ -5159,10 +5176,8 @@ static int bdrv_replace_node_common(BlockDriverState
*from,
bdrv_remove_child(bdrv_filter_or_cow_child(to_cow_parent), tran);
}
- found = g_hash_table_new(NULL, NULL);
-
- refresh_list = bdrv_topological_dfs(refresh_list, found, to);
- refresh_list = bdrv_topological_dfs(refresh_list, found, from);
+ refresh_list = g_slist_prepend(refresh_list, to);
+ refresh_list = g_slist_prepend(refresh_list, from);
ret = bdrv_list_refresh_perms(refresh_list, NULL, tran, errp);
if (ret < 0) {
@@ -5247,7 +5262,6 @@ int bdrv_replace_child_bs(BdrvChild *child,
BlockDriverState *new_bs,
{
int ret;
Transaction *tran = tran_new();
- g_autoptr(GHashTable) found = NULL;
g_autoptr(GSList) refresh_list = NULL;
BlockDriverState *old_bs = child->bs;
@@ -5259,9 +5273,8 @@ int bdrv_replace_child_bs(BdrvChild *child,
BlockDriverState *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);
+ refresh_list = g_slist_prepend(refresh_list, old_bs);
+ refresh_list = g_slist_prepend(refresh_list, new_bs);
ret = bdrv_list_refresh_perms(refresh_list, NULL, tran, errp);
--
2.38.1
- [PULL 00/51] Block layer patches, Kevin Wolf, 2022/12/14
- [PULL 08/51] block: Remove drained_end_counter, Kevin Wolf, 2022/12/14
- [PULL 02/51] block: drop bdrv_remove_filter_or_cow_child, Kevin Wolf, 2022/12/14
- [PULL 05/51] qed: Don't yield in bdrv_qed_co_drain_begin(), Kevin Wolf, 2022/12/14
- [PULL 07/51] block: Revert .bdrv_drained_begin/end to non-coroutine_fn, Kevin Wolf, 2022/12/14
- [PULL 03/51] block: bdrv_refresh_perms(): allow external tran, Kevin Wolf, 2022/12/14
- [PULL 04/51] block: refactor bdrv_list_refresh_perms to allow any list of nodes,
Kevin Wolf <=
- [PULL 12/51] block: Don't use subtree drains in bdrv_drop_intermediate(), Kevin Wolf, 2022/12/14
- [PULL 15/51] block: Call drain callbacks only once, Kevin Wolf, 2022/12/14
- [PULL 13/51] stream: Replace subtree drain with a single node drain, Kevin Wolf, 2022/12/14
- [PULL 19/51] block: Remove poll parameter from bdrv_parent_drained_begin_single(), Kevin Wolf, 2022/12/14
- [PULL 01/51] block: Inline bdrv_detach_child(), Kevin Wolf, 2022/12/14
- [PULL 10/51] block: Fix locking for bdrv_reopen_queue_child(), Kevin Wolf, 2022/12/14
- [PULL 09/51] block: Inline bdrv_drain_invoke(), Kevin Wolf, 2022/12/14
- [PULL 14/51] block: Remove subtree drains, Kevin Wolf, 2022/12/14
- [PULL 06/51] test-bdrv-drain: Don't yield in .bdrv_co_drained_begin/end(), Kevin Wolf, 2022/12/14
- [PULL 20/51] block-io: introduce coroutine_fn duplicates for bdrv_common_block_status_above callers, Kevin Wolf, 2022/12/14