block: Use new AsyncContext for bdrv_read/write emulation
bdrv_read/write emulation is used as the perfect example why we need something like AsyncContexts. So maybe they better start using it. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
9a1e948129
commit
65d6b3d885
22
block.c
22
block.c
@ -1696,19 +1696,26 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
|
||||
struct iovec iov;
|
||||
QEMUIOVector qiov;
|
||||
|
||||
async_context_push();
|
||||
|
||||
async_ret = NOT_DONE;
|
||||
iov.iov_base = (void *)buf;
|
||||
iov.iov_len = nb_sectors * 512;
|
||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
||||
acb = bdrv_aio_readv(bs, sector_num, &qiov, nb_sectors,
|
||||
bdrv_rw_em_cb, &async_ret);
|
||||
if (acb == NULL)
|
||||
return -1;
|
||||
if (acb == NULL) {
|
||||
async_ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while (async_ret == NOT_DONE) {
|
||||
qemu_aio_wait();
|
||||
}
|
||||
|
||||
|
||||
fail:
|
||||
async_context_pop();
|
||||
return async_ret;
|
||||
}
|
||||
|
||||
@ -1720,17 +1727,24 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
|
||||
struct iovec iov;
|
||||
QEMUIOVector qiov;
|
||||
|
||||
async_context_push();
|
||||
|
||||
async_ret = NOT_DONE;
|
||||
iov.iov_base = (void *)buf;
|
||||
iov.iov_len = nb_sectors * 512;
|
||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
||||
acb = bdrv_aio_writev(bs, sector_num, &qiov, nb_sectors,
|
||||
bdrv_rw_em_cb, &async_ret);
|
||||
if (acb == NULL)
|
||||
return -1;
|
||||
if (acb == NULL) {
|
||||
async_ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
while (async_ret == NOT_DONE) {
|
||||
qemu_aio_wait();
|
||||
}
|
||||
|
||||
fail:
|
||||
async_context_pop();
|
||||
return async_ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user