From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com, pbonzini@redhat.com,
famz@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/4] block: Introduce bdrv_replace_child()
Date: Mon, 23 May 2016 18:55:12 +0200 [thread overview]
Message-ID: <1464022515-11390-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1464022515-11390-1-git-send-email-kwolf@redhat.com>
This adds a common function that is called when attaching a new child to
a parent, removing a child from a parent and when reconfiguring the
graph so that an existing child points to a different node now.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 38df365..351344e 100644
--- a/block.c
+++ b/block.c
@@ -1150,18 +1150,32 @@ static int bdrv_fill_options(QDict **options, const char *filename,
return 0;
}
+static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs)
+{
+ BlockDriverState *old_bs = child->bs;
+
+ if (old_bs) {
+ QLIST_REMOVE(child, next_parent);
+ }
+ if (new_bs) {
+ QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
+ }
+
+ child->bs = new_bs;
+}
+
BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
const char *child_name,
const BdrvChildRole *child_role)
{
BdrvChild *child = g_new(BdrvChild, 1);
*child = (BdrvChild) {
- .bs = child_bs,
+ .bs = NULL,
.name = g_strdup(child_name),
.role = child_role,
};
- QLIST_INSERT_HEAD(&child_bs->parents, child, next_parent);
+ bdrv_replace_child(child, child_bs);
return child;
}
@@ -1182,7 +1196,9 @@ static void bdrv_detach_child(BdrvChild *child)
QLIST_REMOVE(child, next);
child->next.le_prev = NULL;
}
- QLIST_REMOVE(child, next_parent);
+
+ bdrv_replace_child(child, NULL);
+
g_free(child->name);
g_free(child);
}
@@ -2203,10 +2219,8 @@ static void change_parent_backing_link(BlockDriverState *from,
QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
assert(c->role != &child_backing);
- c->bs = to;
- QLIST_REMOVE(c, next_parent);
- QLIST_INSERT_HEAD(&to->parents, c, next_parent);
bdrv_ref(to);
+ bdrv_replace_child(c, to);
bdrv_unref(from);
}
}
--
1.8.3.1
next prev parent reply other threads:[~2016-05-23 16:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-23 16:55 [Qemu-devel] [PATCH 0/4] block: BdrvChildRole.drained_begin/end fixes Kevin Wolf
2016-05-23 16:55 ` Kevin Wolf [this message]
2016-05-23 20:02 ` [Qemu-devel] [PATCH 1/4] block: Introduce bdrv_replace_child() Eric Blake
2016-05-23 16:55 ` [Qemu-devel] [PATCH 2/4] block: Make bdrv_drain() use bdrv_drained_begin/end() Kevin Wolf
2016-05-23 21:10 ` Eric Blake
2016-05-23 16:55 ` [Qemu-devel] [PATCH 3/4] block: Fix reconfiguring graph with drained nodes Kevin Wolf
2016-05-23 21:17 ` Eric Blake
2016-05-23 16:55 ` [Qemu-devel] [PATCH 4/4] block: Propagate .drained_begin/end callbacks Kevin Wolf
2016-05-23 21:19 ` Eric Blake
2016-05-24 1:01 ` [Qemu-devel] [PATCH 0/4] block: BdrvChildRole.drained_begin/end fixes Fam Zheng
2016-05-24 7:33 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464022515-11390-2-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=famz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).