diff mbox series

[RFC,3/3] block-copy: add CoMutex lock for BlockCopyCallState list

Message ID 20210420100416.30713-4-eesposit@redhat.com
State New
Headers show
Series block-copy: lock tasks and calls list | expand

Commit Message

Emanuele Giuseppe Esposito April 20, 2021, 10:04 a.m. UTC
Use the same tasks_lock, since the calls list is just used
for debug purposes.

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

Patch

diff --git a/block/block-copy.c b/block/block-copy.c
index e785ac57e0..555f5fb747 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -310,10 +310,9 @@  BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
         s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
     }
 
-    QLIST_INIT(&s->tasks);
     qemu_co_mutex_init(&s->tasks_lock);
+    QLIST_INIT(&s->tasks);
     QLIST_INIT(&s->calls);
-
     return s;
 }
 
@@ -712,7 +711,9 @@  static int coroutine_fn block_copy_common(BlockCopyCallState *call_state)
 {
     int ret;
 
+    qemu_co_mutex_lock(&call_state->s->tasks_lock);
     QLIST_INSERT_HEAD(&call_state->s->calls, call_state, list);
+    qemu_co_mutex_unlock(&call_state->s->tasks_lock);
 
     do {
         ret = block_copy_dirty_clusters(call_state);
@@ -739,7 +740,9 @@  static int coroutine_fn block_copy_common(BlockCopyCallState *call_state)
         call_state->cb(call_state->cb_opaque);
     }
 
+    qemu_co_mutex_lock(&call_state->s->tasks_lock);
     QLIST_REMOVE(call_state, list);
+    qemu_co_mutex_unlock(&call_state->s->tasks_lock);
 
     return ret;
 }