[1/2] block: Drain source node in bdrv_replace_node()
diff mbox series

Message ID 20190521191638.32713-2-kwolf@redhat.com
State New
Headers show
Series
  • commit: Fix crash on job start with active I/O
Related show

Commit Message

Kevin Wolf May 21, 2019, 7:16 p.m. UTC
Instead of just asserting that no requests are in flight in
bdrv_replace_node(), which is a requirement that most callers ignore, we
can just drain the source node right there. This fixes at least starting
a commit job while I/O is active on the backing chain, but probably
other callers, too.

Having requests in flight on the target node isn't a problem because the
target just gets new parents, but the call path of running requests
isn't modified. So we can just drop this assertion without a replacement.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1711643
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Max Reitz May 22, 2019, 11:28 a.m. UTC | #1
On 21.05.19 21:16, Kevin Wolf wrote:
> Instead of just asserting that no requests are in flight in
> bdrv_replace_node(), which is a requirement that most callers ignore, we
> can just drain the source node right there. This fixes at least starting
> a commit job while I/O is active on the backing chain, but probably
> other callers, too.
> 
> Having requests in flight on the target node isn't a problem because the
> target just gets new parents, but the call path of running requests
> isn't modified. So we can just drop this assertion without a replacement.
> 
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1711643
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

I had a similar problem with throttle on a blockdev-mirror job.  I
suppose this is more general than my “Don’t increment in_flight in
bdrv_drain_invoke()” solution, that probably doesn’t even work for your
case. :-)

Reviewed-by: Max Reitz <mreitz@redhat.com>

Patch
diff mbox series

diff --git a/block.c b/block.c
index cb11537029..75f370dbba 100644
--- a/block.c
+++ b/block.c
@@ -4021,13 +4021,13 @@  void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
     uint64_t perm = 0, shared = BLK_PERM_ALL;
     int ret;
 
-    assert(!atomic_read(&from->in_flight));
-    assert(!atomic_read(&to->in_flight));
-
     /* Make sure that @from doesn't go away until we have successfully attached
      * all of its parents to @to. */
     bdrv_ref(from);
 
+    assert(qemu_get_current_aio_context() == qemu_get_aio_context());
+    bdrv_drained_begin(from);
+
     /* Put all parents into @list and calculate their cumulative permissions */
     QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
         assert(c->bs == from);
@@ -4068,6 +4068,7 @@  void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
 
 out:
     g_slist_free(list);
+    bdrv_drained_end(from);
     bdrv_unref(from);
 }