Browse Source

block: access quiesce_counter with atomic ops

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>
pull/53/head
Paolo Bonzini 9 years ago
committed by Fam Zheng
parent
commit
414c2ec358
  1. 4
      block/io.c
  2. 1
      include/block/block_int.h

4
block/io.c

@ -241,7 +241,7 @@ void bdrv_drained_begin(BlockDriverState *bs)
return; return;
} }
if (!bs->quiesce_counter++) { if (atomic_fetch_inc(&bs->quiesce_counter) == 0) {
aio_disable_external(bdrv_get_aio_context(bs)); aio_disable_external(bdrv_get_aio_context(bs));
bdrv_parent_drained_begin(bs); bdrv_parent_drained_begin(bs);
} }
@ -252,7 +252,7 @@ void bdrv_drained_begin(BlockDriverState *bs)
void bdrv_drained_end(BlockDriverState *bs) void bdrv_drained_end(BlockDriverState *bs)
{ {
assert(bs->quiesce_counter > 0); assert(bs->quiesce_counter > 0);
if (--bs->quiesce_counter > 0) { if (atomic_fetch_dec(&bs->quiesce_counter) > 1) {
return; return;
} }

1
include/block/block_int.h

@ -637,6 +637,7 @@ struct BlockDriverState {
/* do we need to tell the quest if we have a volatile write cache? */ /* do we need to tell the quest if we have a volatile write cache? */
int enable_write_cache; int enable_write_cache;
/* Accessed with atomic ops. */
int quiesce_counter; int quiesce_counter;
}; };

Loading…
Cancel
Save