1 /* SPDX-License-Identifier: GPL-2.0
3 * FUSE: Filesystem in Userspace
4 * Copyright (c) 2023-2024 DataDirect Networks.
7 #ifndef _FS_FUSE_DEV_URING_I_H
8 #define _FS_FUSE_DEV_URING_I_H
12 #ifdef CONFIG_FUSE_IO_URING
14 #define FUSE_URING_TEARDOWN_TIMEOUT (5 * HZ)
15 #define FUSE_URING_TEARDOWN_INTERVAL (HZ/20)
17 enum fuse_ring_req_state {
20 /* The ring entry received from userspace and it is being processed */
23 /* The ring entry is waiting for new fuse requests */
26 /* The ring entry got assigned a fuse req */
29 /* The ring entry is in or on the way to user space */
32 /* The ring entry is in teardown */
35 /* The ring entry is released, but not freed yet */
39 /** A fuse ring entry, part of the ring queue */
40 struct fuse_ring_ent {
41 /* userspace buffer */
42 struct fuse_uring_req_header __user *headers;
45 /* the ring queue that owns the request */
46 struct fuse_ring_queue *queue;
48 /* fields below are protected by queue->lock */
50 struct io_uring_cmd *cmd;
52 struct list_head list;
54 enum fuse_ring_req_state state;
56 struct fuse_req *fuse_req;
59 struct fuse_ring_queue {
61 * back pointer to the main fuse uring structure that holds this
64 struct fuse_ring *ring;
66 /* queue id, corresponds to the cpu core */
70 * queue lock, taken when any value in the queue changes _and_ also
71 * a ring entry state changes.
75 /* available ring entries (struct fuse_ring_ent) */
76 struct list_head ent_avail_queue;
79 * entries in the process of being committed or in the process
80 * to be sent to userspace
82 struct list_head ent_w_req_queue;
83 struct list_head ent_commit_queue;
85 /* entries in userspace */
86 struct list_head ent_in_userspace;
88 /* entries that are released */
89 struct list_head ent_released;
91 /* fuse requests waiting for an entry slot */
92 struct list_head fuse_req_queue;
94 /* background fuse requests */
95 struct list_head fuse_req_bg_queue;
97 struct fuse_pqueue fpq;
99 unsigned int active_background;
105 * Describes if uring is for communication and holds alls the data needed
106 * for uring communication
110 struct fuse_conn *fc;
112 /* number of ring queues */
115 /* maximum payload/arg size */
116 size_t max_payload_sz;
118 struct fuse_ring_queue **queues;
121 * Log ring entry states on stop when entries cannot be released
123 unsigned int stop_debug_log : 1;
125 wait_queue_head_t stop_waitq;
127 /* async tear down */
128 struct delayed_work async_teardown_work;
131 unsigned long teardown_time;
138 bool fuse_uring_enabled(void);
139 void fuse_uring_destruct(struct fuse_conn *fc);
140 void fuse_uring_stop_queues(struct fuse_ring *ring);
141 void fuse_uring_abort_end_requests(struct fuse_ring *ring);
142 int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags);
143 void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req);
144 bool fuse_uring_queue_bq_req(struct fuse_req *req);
146 static inline void fuse_uring_abort(struct fuse_conn *fc)
148 struct fuse_ring *ring = fc->ring;
153 if (atomic_read(&ring->queue_refs) > 0) {
154 fuse_uring_abort_end_requests(ring);
155 fuse_uring_stop_queues(ring);
159 static inline void fuse_uring_wait_stopped_queues(struct fuse_conn *fc)
161 struct fuse_ring *ring = fc->ring;
164 wait_event(ring->stop_waitq,
165 atomic_read(&ring->queue_refs) == 0);
168 static inline bool fuse_uring_ready(struct fuse_conn *fc)
170 return fc->ring && fc->ring->ready;
173 #else /* CONFIG_FUSE_IO_URING */
177 static inline void fuse_uring_create(struct fuse_conn *fc)
181 static inline void fuse_uring_destruct(struct fuse_conn *fc)
185 static inline bool fuse_uring_enabled(void)
190 static inline void fuse_uring_abort(struct fuse_conn *fc)
194 static inline void fuse_uring_wait_stopped_queues(struct fuse_conn *fc)
198 static inline bool fuse_uring_ready(struct fuse_conn *fc)
203 #endif /* CONFIG_FUSE_IO_URING */
205 #endif /* _FS_FUSE_DEV_URING_I_H */