2 * QEMU aio implementation
4 * Copyright IBM, Corp. 2008
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
17 #include "qemu-common.h"
18 #include "qemu-char.h"
20 typedef struct BlockDriverAIOCB BlockDriverAIOCB
;
21 typedef void BlockDriverCompletionFunc(void *opaque
, int ret
);
23 typedef struct AIOPool
{
24 void (*cancel
)(BlockDriverAIOCB
*acb
);
26 BlockDriverAIOCB
*free_aiocb
;
29 struct BlockDriverAIOCB
{
32 BlockDriverCompletionFunc
*cb
;
34 BlockDriverAIOCB
*next
;
37 void *qemu_aio_get(AIOPool
*pool
, BlockDriverState
*bs
,
38 BlockDriverCompletionFunc
*cb
, void *opaque
);
39 void qemu_aio_release(void *p
);
41 /* Returns 1 if there are still outstanding AIO requests; 0 otherwise */
42 typedef int (AioFlushHandler
)(void *opaque
);
44 /* Flush any pending AIO operation. This function will block until all
45 * outstanding AIO operations have been completed or cancelled. */
46 void qemu_aio_flush(void);
48 /* Wait for a single AIO completion to occur. This function will wait
49 * until a single AIO event has completed and it will ensure something
50 * has moved before returning. This can issue new pending aio as
51 * result of executing I/O completion or bh callbacks.
53 * Return whether there is still any pending AIO operation. */
54 bool qemu_aio_wait(void);
56 /* Register a file descriptor and associated callbacks. Behaves very similarly
57 * to qemu_set_fd_handler2. Unlike qemu_set_fd_handler2, these callbacks will
58 * be invoked when using either qemu_aio_wait() or qemu_aio_flush().
60 * Code that invokes AIO completion functions should rely on this function
61 * instead of qemu_set_fd_handler[2].
63 int qemu_aio_set_fd_handler(int fd
,
66 AioFlushHandler
*io_flush
,