block: access quiesce_counter with atomic ops
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 5 Jun 2017 12:38:51 +0000 (14:38 +0200)
committerFam Zheng <famz@redhat.com>
Thu, 15 Jun 2017 23:55:00 +0000 (07:55 +0800)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20170605123908.18777-3-pbonzini@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
block/io.c
include/block/block_int.h

index 98c690f306e55fee97dccf456a5924d2b84e8183..70643df494ea1bcde9e095a790296dd4a9b8bc67 100644 (file)
@@ -241,7 +241,7 @@ void bdrv_drained_begin(BlockDriverState *bs)
         return;
     }
 
-    if (!bs->quiesce_counter++) {
+    if (atomic_fetch_inc(&bs->quiesce_counter) == 0) {
         aio_disable_external(bdrv_get_aio_context(bs));
         bdrv_parent_drained_begin(bs);
     }
@@ -252,7 +252,7 @@ void bdrv_drained_begin(BlockDriverState *bs)
 void bdrv_drained_end(BlockDriverState *bs)
 {
     assert(bs->quiesce_counter > 0);
-    if (--bs->quiesce_counter > 0) {
+    if (atomic_fetch_dec(&bs->quiesce_counter) > 1) {
         return;
     }
 
index 49f2ebb95a91f59570132cbeeb2aea5762ea7ac9..1824e0e1356a77a40360bf94b9ff395bc5f424ab 100644 (file)
@@ -637,6 +637,7 @@ struct BlockDriverState {
     /* do we need to tell the quest if we have a volatile write cache? */
     int enable_write_cache;
 
+    /* Accessed with atomic ops.  */
     int quiesce_counter;
 };