qemu-aio.h 2.1 KB

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