This is simpler than taking and releasing the AioContext lock.  Both
quorum_rewrite_aio_cb and quorum_aio_finalize will be called without
any lock taken.

Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
---
 block/quorum.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/block/quorum.c b/block/quorum.c
index 4e66221..0a42962 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -250,15 +250,10 @@ static void quorum_rewrite_aio_cb(void *opaque, int ret)
 {
     QuorumAIOCB *acb = opaque;
 
-    /* one less rewrite to do */
-    acb->rewrite_count--;
-
     /* wait until all rewrite callbacks have completed */
-    if (acb->rewrite_count) {
-        return;
+    if (atomic_fetch_dec(&acb->rewrite_count) == 1) {
+        quorum_aio_finalize(acb);
     }
-
-    quorum_aio_finalize(acb);
 }
 
 static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb);
@@ -361,7 +356,7 @@ static bool quorum_rewrite_bad_versions(BDRVQuorumState *s, 
QuorumAIOCB *acb,
     }
 
     /* quorum_rewrite_aio_cb will count down this to zero */
-    acb->rewrite_count = count;
+    atomic_mb_set(&acb->rewrite_count, count);
 
     /* now fire the correcting rewrites */
     QLIST_FOREACH(version, &acb->votes.vote_list, next) {
-- 
2.4.3



Reply via email to