[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 06/10] block: Factor out should_update_child()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH 06/10] block: Factor out should_update_child() |
Date: |
Mon, 6 Mar 2017 17:21:58 +0100 |
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 42 +++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/block.c b/block.c
index f293ccb..6dc02b8 100644
--- a/block.c
+++ b/block.c
@@ -2886,28 +2886,40 @@ void bdrv_close_all(void)
assert(QTAILQ_EMPTY(&all_bdrv_states));
}
+static bool should_update_child(BdrvChild *c, BlockDriverState *to)
+{
+ BdrvChild *to_c;
+
+ if (c->role->stay_at_node) {
+ return false;
+ }
+
+ if (c->role == &child_backing) {
+ /* If @from is a backing file of @to, ignore the child to avoid
+ * creating a loop. We only want to change the pointer of other
+ * parents. */
+ QLIST_FOREACH(to_c, &to->children, next) {
+ if (to_c == c) {
+ break;
+ }
+ }
+ if (to_c) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static void change_parent_backing_link(BlockDriverState *from,
BlockDriverState *to)
{
- BdrvChild *c, *next, *to_c;
+ BdrvChild *c, *next;
QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
- if (c->role->stay_at_node) {
+ if (!should_update_child(c, to)) {
continue;
}
- if (c->role == &child_backing) {
- /* If @from is a backing file of @to, ignore the child to avoid
- * creating a loop. We only want to change the pointer of other
- * parents. */
- QLIST_FOREACH(to_c, &to->children, next) {
- if (to_c == c) {
- break;
- }
- }
- if (to_c) {
- continue;
- }
- }
bdrv_ref(to);
/* FIXME Are we sure that bdrv_replace_child() can't run into
--
1.8.3.1
- Re: [Qemu-block] [Qemu-devel] [PATCH 01/10] commit: Fix error handling, (continued)
- [Qemu-block] [PATCH 02/10] mirror: Fix permission problem with 'replaces', Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 03/10] mirror: Fix permissions for removing mirror_top_bs, Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 04/10] mirror: Fix error path for dirty bitmap creation, Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 05/10] block: Fix blockdev-snapshot error handling, Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 06/10] block: Factor out should_update_child(),
Kevin Wolf <=
- [Qemu-block] [PATCH 07/10] block: Factor out bdrv_replace_child_noperm(), Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 08/10] block: Ignore multiple children in bdrv_check_update_perm(), Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 09/10] block: Handle permission errors in change_parent_backing_link(), Kevin Wolf, 2017/03/06
- [Qemu-block] [PATCH 10/10] block: Fix error handling in bdrv_replace_in_backing_chain(), Kevin Wolf, 2017/03/06