ioq.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Linux AIO request queue
  3. *
  4. * Copyright 2012 IBM, Corp.
  5. * Copyright 2012 Red Hat, Inc. and/or its affiliates
  6. *
  7. * Authors:
  8. * Stefan Hajnoczi <stefanha@redhat.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  11. * See the COPYING file in the top-level directory.
  12. *
  13. */
  14. #ifndef IOQ_H
  15. #define IOQ_H
  16. #include <libaio.h>
  17. #include "qemu/event_notifier.h"
  18. typedef struct {
  19. int fd; /* file descriptor */
  20. unsigned int max_reqs; /* max length of freelist and queue */
  21. io_context_t io_ctx; /* Linux AIO context */
  22. EventNotifier io_notifier; /* Linux AIO eventfd */
  23. /* Requests can complete in any order so a free list is necessary to manage
  24. * available iocbs.
  25. */
  26. struct iocb **freelist; /* free iocbs */
  27. unsigned int freelist_idx;
  28. /* Multiple requests are queued up before submitting them all in one go */
  29. struct iocb **queue; /* queued iocbs */
  30. unsigned int queue_idx;
  31. } IOQueue;
  32. void ioq_init(IOQueue *ioq, int fd, unsigned int max_reqs);
  33. void ioq_cleanup(IOQueue *ioq);
  34. EventNotifier *ioq_get_notifier(IOQueue *ioq);
  35. struct iocb *ioq_get_iocb(IOQueue *ioq);
  36. void ioq_put_iocb(IOQueue *ioq, struct iocb *iocb);
  37. struct iocb *ioq_rdwr(IOQueue *ioq, bool read, struct iovec *iov,
  38. unsigned int count, long long offset);
  39. int ioq_submit(IOQueue *ioq);
  40. static inline unsigned int ioq_num_queued(IOQueue *ioq)
  41. {
  42. return ioq->queue_idx;
  43. }
  44. typedef void IOQueueCompletion(struct iocb *iocb, ssize_t ret, void *opaque);
  45. int ioq_run_completion(IOQueue *ioq, IOQueueCompletion *completion,
  46. void *opaque);
  47. #endif /* IOQ_H */