From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, pbonzini@redhat.com,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 16/19] block: Allow graph changes in subtree drained section
Date: Wed, 20 Dec 2017 11:34:09 +0100 [thread overview]
Message-ID: <20171220103412.13048-17-kwolf@redhat.com> (raw)
In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com>
We need to remember how many of the drain sections in which a node is
were recursive (i.e. subtree drain rather than node drain), so that they
can be correctly applied when children are added or removed during the
drained section.
With this change, it is safe to modify the graph even inside a
bdrv_subtree_drained_begin/end() section.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block.h | 7 +++++--
include/block/block_int.h | 2 ++
block.c | 40 +++++++++++++++++++++++++++++++++++++---
block/io.c | 15 ++++++---------
4 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/include/block/block.h b/include/block/block.h
index de9c5a2b9b..c8e6163cf7 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -610,8 +610,6 @@ void bdrv_drained_begin(BlockDriverState *bs);
/**
* Like bdrv_drained_begin, but recursively begins a quiesced section for
* exclusive access to all child nodes as well.
- *
- * Graph changes are not allowed during a subtree drain section.
*/
void bdrv_subtree_drained_begin(BlockDriverState *bs);
@@ -627,6 +625,11 @@ void bdrv_drained_end(BlockDriverState *bs);
*/
void bdrv_subtree_drained_end(BlockDriverState *bs);
+void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
+ BdrvChild *parent);
+void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
+ BdrvChild *parent);
+
void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child,
Error **errp);
void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index e107163594..c2d3956633 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -717,6 +717,8 @@ struct BlockDriverState {
/* Accessed with atomic ops. */
int quiesce_counter;
+ int recursive_quiesce_counter;
+
unsigned int write_gen; /* Current data generation */
/* Protected by reqs_lock. */
diff --git a/block.c b/block.c
index 5867a2a2a0..37f8639fe9 100644
--- a/block.c
+++ b/block.c
@@ -822,6 +822,26 @@ static void bdrv_child_cb_drained_end(BdrvChild *child)
bdrv_drained_end(bs);
}
+static void bdrv_child_cb_attach(BdrvChild *child)
+{
+ BlockDriverState *bs = child->opaque;
+ int i;
+
+ for (i = 0; i < bs->recursive_quiesce_counter; i++) {
+ bdrv_do_drained_begin(child->bs, true, child);
+ }
+}
+
+static void bdrv_child_cb_detach(BdrvChild *child)
+{
+ BlockDriverState *bs = child->opaque;
+ int i;
+
+ for (i = 0; i < bs->recursive_quiesce_counter; i++) {
+ bdrv_do_drained_end(child->bs, true, child);
+ }
+}
+
static int bdrv_child_cb_inactivate(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;
@@ -889,6 +909,8 @@ const BdrvChildRole child_file = {
.inherit_options = bdrv_inherited_options,
.drained_begin = bdrv_child_cb_drained_begin,
.drained_end = bdrv_child_cb_drained_end,
+ .attach = bdrv_child_cb_attach,
+ .detach = bdrv_child_cb_detach,
.inactivate = bdrv_child_cb_inactivate,
};
@@ -911,6 +933,8 @@ const BdrvChildRole child_format = {
.inherit_options = bdrv_inherited_fmt_options,
.drained_begin = bdrv_child_cb_drained_begin,
.drained_end = bdrv_child_cb_drained_end,
+ .attach = bdrv_child_cb_attach,
+ .detach = bdrv_child_cb_detach,
.inactivate = bdrv_child_cb_inactivate,
};
@@ -953,6 +977,8 @@ static void bdrv_backing_attach(BdrvChild *c)
parent->backing_blocker);
bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET,
parent->backing_blocker);
+
+ bdrv_child_cb_attach(c);
}
static void bdrv_backing_detach(BdrvChild *c)
@@ -963,6 +989,8 @@ static void bdrv_backing_detach(BdrvChild *c)
bdrv_op_unblock_all(c->bs, parent->backing_blocker);
error_free(parent->backing_blocker);
parent->backing_blocker = NULL;
+
+ bdrv_child_cb_detach(c);
}
/*
@@ -1978,14 +2006,17 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs));
}
if (old_bs) {
+ /* Detach first so that the recursive drain sections coming from @child
+ * are already gone and we only end the drain sections that came from
+ * elsewhere. */
+ if (child->role->detach) {
+ child->role->detach(child);
+ }
if (old_bs->quiesce_counter && child->role->drained_end) {
for (i = 0; i < old_bs->quiesce_counter; i++) {
child->role->drained_end(child);
}
}
- if (child->role->detach) {
- child->role->detach(child);
- }
QLIST_REMOVE(child, next_parent);
}
@@ -1999,6 +2030,9 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
}
}
+ /* Attach only after starting new drained sections, so that recursive
+ * drain sections coming from @child don't get an extra .drained_begin
+ * callback. */
if (child->role->attach) {
child->role->attach(child);
}
diff --git a/block/io.c b/block/io.c
index 6befef166d..2eb0783506 100644
--- a/block/io.c
+++ b/block/io.c
@@ -219,11 +219,6 @@ static bool bdrv_drain_recurse(BlockDriverState *bs)
return waited;
}
-static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
- BdrvChild *parent);
-static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
- BdrvChild *parent);
-
static void bdrv_co_drain_bh_cb(void *opaque)
{
BdrvCoDrainData *data = opaque;
@@ -270,8 +265,8 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
assert(data.done);
}
-static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
- BdrvChild *parent)
+void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
+ BdrvChild *parent)
{
BdrvChild *child, *next;
@@ -290,6 +285,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
bdrv_drain_recurse(bs);
if (recursive) {
+ bs->recursive_quiesce_counter++;
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
bdrv_do_drained_begin(child->bs, true, child);
}
@@ -306,8 +302,8 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs)
bdrv_do_drained_begin(bs, true, NULL);
}
-static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
- BdrvChild *parent)
+void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
+ BdrvChild *parent)
{
BdrvChild *child, *next;
int old_quiesce_counter;
@@ -327,6 +323,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
}
if (recursive) {
+ bs->recursive_quiesce_counter--;
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
bdrv_do_drained_end(child->bs, true, child);
}
--
2.13.6
next prev parent reply other threads:[~2017-12-20 10:36 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-20 10:33 [Qemu-devel] [PATCH 00/19] Drain fixes and cleanups, part 2 Kevin Wolf
2017-12-20 10:33 ` [Qemu-devel] [PATCH 01/19] block: Remove unused bdrv_requests_pending Kevin Wolf
2017-12-20 10:33 ` [Qemu-devel] [PATCH 02/19] block: Assert drain_all is only called from main AioContext Kevin Wolf
2017-12-20 12:14 ` Fam Zheng
2017-12-20 10:33 ` [Qemu-devel] [PATCH 03/19] block: Make bdrv_drain() driver callbacks non-recursive Kevin Wolf
2017-12-20 13:16 ` Fam Zheng
2017-12-20 13:24 ` Kevin Wolf
2017-12-20 13:31 ` Fam Zheng
2017-12-20 10:33 ` [Qemu-devel] [PATCH 04/19] test-bdrv-drain: Test callback for bdrv_drain Kevin Wolf
2017-12-20 10:33 ` [Qemu-devel] [PATCH 05/19] test-bdrv-drain: Test bs->quiesce_counter Kevin Wolf
2017-12-20 10:33 ` [Qemu-devel] [PATCH 06/19] blockjob: Pause job on draining any job BDS Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 07/19] test-bdrv-drain: Test drain vs. block jobs Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 08/19] block: Don't block_job_pause_all() in bdrv_drain_all() Kevin Wolf
2017-12-21 23:24 ` Eric Blake
2017-12-20 10:34 ` [Qemu-devel] [PATCH 09/19] block: Nested drain_end must still call callbacks Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 10/19] test-bdrv-drain: Test nested drain sections Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 11/19] block: Don't notify parents in drain call chain Kevin Wolf
2017-12-21 23:26 ` Eric Blake
2017-12-20 10:34 ` [Qemu-devel] [PATCH 12/19] block: Add bdrv_subtree_drained_begin/end() Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 13/19] test-bdrv-drain: Tests for bdrv_subtree_drain Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 14/19] test-bdrv-drain: Test behaviour in coroutine context Kevin Wolf
2017-12-20 10:53 ` Paolo Bonzini
2017-12-20 10:34 ` [Qemu-devel] [PATCH 15/19] test-bdrv-drain: Recursive draining with multiple parents Kevin Wolf
2017-12-20 10:34 ` Kevin Wolf [this message]
2017-12-20 10:51 ` [Qemu-devel] [PATCH 16/19] block: Allow graph changes in subtree drained section Paolo Bonzini
2017-12-20 11:18 ` Kevin Wolf
2017-12-20 11:31 ` [Qemu-devel] [Qemu-block] " Paolo Bonzini
2017-12-20 13:04 ` Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 17/19] test-bdrv-drain: Test graph changes in " Kevin Wolf
2017-12-20 10:34 ` [Qemu-devel] [PATCH 18/19] commit: Simplify reopen of base Kevin Wolf
2017-12-20 13:32 ` Fam Zheng
2017-12-20 10:34 ` [Qemu-devel] [PATCH 19/19] block: Keep nodes drained between reopen_queue/multiple Kevin Wolf
2017-12-20 13:34 ` Fam Zheng
2017-12-20 10:54 ` [Qemu-devel] [PATCH 00/19] Drain fixes and cleanups, part 2 Paolo Bonzini
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=20171220103412.13048-17-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 \
/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).