diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2017-06-05 14:38:50 +0200 |
---|---|---|
committer | Fam Zheng <famz@redhat.com> | 2017-06-16 07:55:00 +0800 |
commit | d3faa13e5ffda779dcd58f39e8745370adb05d67 (patch) | |
tree | adc8d74261b334cba0a0bc52e30466af3c4694eb /block | |
parent | 79f24568e5e70892b9bf4712f88b26f52255077f (diff) | |
download | qemu-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.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -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; } |