Skip to content

Commit

Permalink
block: Add bdrv_aio_cancel_async
Browse files Browse the repository at this point in the history
This is the async version of bdrv_aio_cancel, which doesn't block the
caller. It guarantees that the cb is called either before returning or
some time later.

bdrv_aio_cancel can base on bdrv_aio_cancel_async, later we can convert
all .io_cancel implementations to .io_cancel_async, and the aio_poll is
the common logic. In the end, .io_cancel can be dropped.

Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
Fam Zheng authored and stefanhaRH committed Sep 22, 2014
1 parent f197fe2 commit 02c50ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
27 changes: 26 additions & 1 deletion block.c
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,32 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)

void bdrv_aio_cancel(BlockDriverAIOCB *acb)
{
acb->aiocb_info->cancel(acb);
if (acb->aiocb_info->cancel) {
acb->aiocb_info->cancel(acb);
} else {
qemu_aio_ref(acb);
bdrv_aio_cancel_async(acb);
while (acb->refcnt > 1) {
if (acb->aiocb_info->get_aio_context) {
aio_poll(acb->aiocb_info->get_aio_context(acb), true);
} else if (acb->bs) {
aio_poll(bdrv_get_aio_context(acb->bs), true);
} else {
abort();
}
}
qemu_aio_release(acb);
}
}

/* Async version of aio cancel. The caller is not blocked if the acb implements
* cancel_async, otherwise we do nothing and let the request normally complete.
* In either case the completion callback must be called. */
void bdrv_aio_cancel_async(BlockDriverAIOCB *acb)
{
if (acb->aiocb_info->cancel_async) {
acb->aiocb_info->cancel_async(acb);
}
}

/**************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions include/block/aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ typedef void BlockDriverCompletionFunc(void *opaque, int ret);

typedef struct AIOCBInfo {
void (*cancel)(BlockDriverAIOCB *acb);
void (*cancel_async)(BlockDriverAIOCB *acb);
AioContext *(*get_aio_context)(BlockDriverAIOCB *acb);
size_t aiocb_size;
} AIOCBInfo;

Expand Down
1 change: 1 addition & 0 deletions include/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
int64_t sector_num, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque);
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
void bdrv_aio_cancel_async(BlockDriverAIOCB *acb);

typedef struct BlockRequest {
/* Fields to be filled by multiwrite caller */
Expand Down

0 comments on commit 02c50ef

Please sign in to comment.