diff mbox series

[RFC,v2,8/8] mirror: protect drains in coroutine with rdlock

Message ID 20220426085114.199647-9-eesposit@redhat.com
State New
Headers show
Series Removal of AioContext lock, bs->parents and ->children: new rwlock | expand

Commit Message

Emanuele Giuseppe Esposito April 26, 2022, 8:51 a.m. UTC
Drain performed in coroutine schedules a bh in the main loop.
However, drain itself still is a read, and we need to signal
the writer that we are going through the graph.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 block/mirror.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/block/mirror.c b/block/mirror.c
index ce6bc58d1f..de86729f9b 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -1065,10 +1065,14 @@  static int coroutine_fn mirror_run(Job *job, Error **errp)
             trace_mirror_before_drain(s, cnt);
 
             s->in_drain = true;
+            bdrv_graph_co_rdlock();
             bdrv_drained_begin(bs);
+            bdrv_graph_co_rdunlock();
             cnt = bdrv_get_dirty_count(s->dirty_bitmap);
             if (cnt > 0 || mirror_flush(s) < 0) {
+                bdrv_graph_co_rdlock();
                 bdrv_drained_end(bs);
+                bdrv_graph_co_rdunlock();
                 s->in_drain = false;
                 continue;
             }
@@ -1110,7 +1114,9 @@  immediate_exit:
 
     if (need_drain) {
         s->in_drain = true;
+        bdrv_graph_co_rdlock();
         bdrv_drained_begin(bs);
+        bdrv_graph_co_rdunlock();
     }
 
     return ret;