summaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2017-03-01 17:30:41 +0100
committerKevin Wolf <kwolf@redhat.com>2017-03-07 14:53:28 +0100
commitd0ac038025bb6e7886c2324258d24e71215b5d35 (patch)
tree5011f97225bd77570c5d6e20da4f5fd4498b6f5a /block.c
parent067acf28d1d726059f994356f25e054ce2926acf (diff)
downloadqemu-d0ac038025bb6e7886c2324258d24e71215b5d35.tar.gz
block: Factor out should_update_child()
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Diffstat (limited to 'block.c')
-rw-r--r--block.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/block.c b/block.c
index f293ccb5af..6dc02b85aa 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