dev_uring_i.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * FUSE: Filesystem in Userspace
  4. * Copyright (c) 2023-2024 DataDirect Networks.
  5. */
  6. #ifndef _FS_FUSE_DEV_URING_I_H
  7. #define _FS_FUSE_DEV_URING_I_H
  8. #include "fuse_i.h"
  9. #ifdef CONFIG_FUSE_IO_URING
  10. #define FUSE_URING_TEARDOWN_TIMEOUT (5 * HZ)
  11. #define FUSE_URING_TEARDOWN_INTERVAL (HZ/20)
  12. enum fuse_ring_req_state {
  13. FRRS_INVALID = 0,
  14. /* The ring entry received from userspace and it is being processed */
  15. FRRS_COMMIT,
  16. /* The ring entry is waiting for new fuse requests */
  17. FRRS_AVAILABLE,
  18. /* The ring entry got assigned a fuse req */
  19. FRRS_FUSE_REQ,
  20. /* The ring entry is in or on the way to user space */
  21. FRRS_USERSPACE,
  22. /* The ring entry is in teardown */
  23. FRRS_TEARDOWN,
  24. /* The ring entry is released, but not freed yet */
  25. FRRS_RELEASED,
  26. };
  27. /** A fuse ring entry, part of the ring queue */
  28. struct fuse_ring_ent {
  29. /* userspace buffer */
  30. struct fuse_uring_req_header __user *headers;
  31. void __user *payload;
  32. /* the ring queue that owns the request */
  33. struct fuse_ring_queue *queue;
  34. /* fields below are protected by queue->lock */
  35. struct io_uring_cmd *cmd;
  36. struct list_head list;
  37. enum fuse_ring_req_state state;
  38. struct fuse_req *fuse_req;
  39. };
  40. struct fuse_ring_queue {
  41. /*
  42. * back pointer to the main fuse uring structure that holds this
  43. * queue
  44. */
  45. struct fuse_ring *ring;
  46. /* queue id, corresponds to the cpu core */
  47. unsigned int qid;
  48. /*
  49. * queue lock, taken when any value in the queue changes _and_ also
  50. * a ring entry state changes.
  51. */
  52. spinlock_t lock;
  53. /* available ring entries (struct fuse_ring_ent) */
  54. struct list_head ent_avail_queue;
  55. /*
  56. * entries in the process of being committed or in the process
  57. * to be sent to userspace
  58. */
  59. struct list_head ent_w_req_queue;
  60. struct list_head ent_commit_queue;
  61. /* entries in userspace */
  62. struct list_head ent_in_userspace;
  63. /* entries that are released */
  64. struct list_head ent_released;
  65. /* fuse requests waiting for an entry slot */
  66. struct list_head fuse_req_queue;
  67. /* background fuse requests */
  68. struct list_head fuse_req_bg_queue;
  69. struct fuse_pqueue fpq;
  70. unsigned int active_background;
  71. bool stopped;
  72. };
  73. /**
  74. * Describes if uring is for communication and holds alls the data needed
  75. * for uring communication
  76. */
  77. struct fuse_ring {
  78. /* back pointer */
  79. struct fuse_conn *fc;
  80. /* number of ring queues */
  81. size_t nr_queues;
  82. /* maximum payload/arg size */
  83. size_t max_payload_sz;
  84. struct fuse_ring_queue **queues;
  85. /*
  86. * Log ring entry states on stop when entries cannot be released
  87. */
  88. unsigned int stop_debug_log : 1;
  89. wait_queue_head_t stop_waitq;
  90. /* async tear down */
  91. struct delayed_work async_teardown_work;
  92. /* log */
  93. unsigned long teardown_time;
  94. atomic_t queue_refs;
  95. bool ready;
  96. };
  97. bool fuse_uring_enabled(void);
  98. void fuse_uring_destruct(struct fuse_conn *fc);
  99. void fuse_uring_stop_queues(struct fuse_ring *ring);
  100. void fuse_uring_abort_end_requests(struct fuse_ring *ring);
  101. int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags);
  102. void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req);
  103. bool fuse_uring_queue_bq_req(struct fuse_req *req);
  104. bool fuse_uring_remove_pending_req(struct fuse_req *req);
  105. bool fuse_uring_request_expired(struct fuse_conn *fc);
  106. static inline void fuse_uring_abort(struct fuse_conn *fc)
  107. {
  108. struct fuse_ring *ring = fc->ring;
  109. if (ring == NULL)
  110. return;
  111. if (atomic_read(&ring->queue_refs) > 0) {
  112. fuse_uring_abort_end_requests(ring);
  113. fuse_uring_stop_queues(ring);
  114. }
  115. }
  116. static inline void fuse_uring_wait_stopped_queues(struct fuse_conn *fc)
  117. {
  118. struct fuse_ring *ring = fc->ring;
  119. if (ring)
  120. wait_event(ring->stop_waitq,
  121. atomic_read(&ring->queue_refs) == 0);
  122. }
  123. static inline bool fuse_uring_ready(struct fuse_conn *fc)
  124. {
  125. return fc->ring && fc->ring->ready;
  126. }
  127. #else /* CONFIG_FUSE_IO_URING */
  128. static inline void fuse_uring_destruct(struct fuse_conn *fc)
  129. {
  130. }
  131. static inline bool fuse_uring_enabled(void)
  132. {
  133. return false;
  134. }
  135. static inline void fuse_uring_abort(struct fuse_conn *fc)
  136. {
  137. }
  138. static inline void fuse_uring_wait_stopped_queues(struct fuse_conn *fc)
  139. {
  140. }
  141. static inline bool fuse_uring_ready(struct fuse_conn *fc)
  142. {
  143. return false;
  144. }
  145. static inline bool fuse_uring_remove_pending_req(struct fuse_req *req)
  146. {
  147. return false;
  148. }
  149. static inline bool fuse_uring_request_expired(struct fuse_conn *fc)
  150. {
  151. return false;
  152. }
  153. #endif /* CONFIG_FUSE_IO_URING */
  154. #endif /* _FS_FUSE_DEV_URING_I_H */