block: access wakeup with atomic ops

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20170605123908.18777-6-pbonzini@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
master
Paolo Bonzini 2017-06-05 14:38:54 +02:00 committed by Fam Zheng
parent 20fc71b25c
commit e2a6ae7fe5
5 changed files with 15 additions and 7 deletions

View File

@ -501,7 +501,8 @@ static void dummy_bh_cb(void *opaque)
void bdrv_wakeup(BlockDriverState *bs)
{
if (bs->wakeup) {
/* The barrier (or an atomic op) is in the caller. */
if (atomic_read(&bs->wakeup)) {
aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL);
}
}

View File

@ -730,7 +730,9 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
if (task->ret < 0) {
error_report("NFS Error: %s", nfs_get_error(nfs));
}
task->complete = 1;
/* Set task->complete before reading bs->wakeup. */
atomic_mb_set(&task->complete, 1);
bdrv_wakeup(task->bs);
}

View File

@ -698,7 +698,8 @@ out:
srco->co = NULL;
srco->ret = ret;
srco->finished = true;
/* Set srco->finished before reading bs->wakeup. */
atomic_mb_set(&srco->finished, true);
if (srco->bs) {
bdrv_wakeup(srco->bs);
}

View File

@ -402,7 +402,8 @@ void bdrv_drain_all(void);
* block_job_defer_to_main_loop for how to do it). \
*/ \
assert(!bs_->wakeup); \
bs_->wakeup = true; \
/* Set bs->wakeup before evaluating cond. */ \
atomic_mb_set(&bs_->wakeup, true); \
while (busy_) { \
if ((cond)) { \
waited_ = busy_ = true; \
@ -414,7 +415,7 @@ void bdrv_drain_all(void);
waited_ |= busy_; \
} \
} \
bs_->wakeup = false; \
atomic_set(&bs_->wakeup, false); \
} \
waited_; })

View File

@ -604,8 +604,6 @@ struct BlockDriverState {
/* Callback before write request is processed */
NotifierWithReturnList before_write_notifiers;
bool wakeup;
/* Offset after the highest byte written to */
uint64_t wr_highest_offset;
@ -636,6 +634,11 @@ struct BlockDriverState {
unsigned int in_flight;
unsigned int serialising_in_flight;
/* Internal to BDRV_POLL_WHILE and bdrv_wakeup. Accessed with atomic
* ops.
*/
bool wakeup;
/* do we need to tell the quest if we have a volatile write cache? */
int enable_write_cache;