aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2017-06-05 14:38:50 +0200
committerFam Zheng <famz@redhat.com>2017-06-16 07:55:00 +0800
commitd3faa13e5ffda779dcd58f39e8745370adb05d67 (patch)
treeadc8d74261b334cba0a0bc52e30466af3c4694eb /block
parent79f24568e5e70892b9bf4712f88b26f52255077f (diff)
downloadqemu-d3faa13e5ffda779dcd58f39e8745370adb05d67.zip
qemu-d3faa13e5ffda779dcd58f39e8745370adb05d67.tar.gz
qemu-d3faa13e5ffda779dcd58f39e8745370adb05d67.tar.bz2
block: access copy_on_read with atomic ops
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20170605123908.18777-2-pbonzini@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/io.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/block/io.c b/block/io.c
index ed31810..98c690f 100644
--- a/block/io.c
+++ b/block/io.c
@@ -130,13 +130,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
*/
void bdrv_enable_copy_on_read(BlockDriverState *bs)
{
- bs->copy_on_read++;
+ atomic_inc(&bs->copy_on_read);
}
void bdrv_disable_copy_on_read(BlockDriverState *bs)
{
- assert(bs->copy_on_read > 0);
- bs->copy_on_read--;
+ int old = atomic_fetch_dec(&bs->copy_on_read);
+ assert(old >= 1);
}
/* Check if any requests are in-flight (including throttled requests) */
@@ -1144,7 +1144,7 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child,
bdrv_inc_in_flight(bs);
/* Don't do copy-on-read if we read data before write operation */
- if (bs->copy_on_read && !(flags & BDRV_REQ_NO_SERIALISING)) {
+ if (atomic_read(&bs->copy_on_read) && !(flags & BDRV_REQ_NO_SERIALISING)) {
flags |= BDRV_REQ_COPY_ON_READ;
}