1 /* SPDX-License-Identifier: GPL-2.0
2 *
3 * FUSE: Filesystem in Userspace
4 * Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
5 */
6 #ifndef _FS_FUSE_DEV_I_H
7 #define _FS_FUSE_DEV_I_H
8
9 #include <linux/types.h>
10
11 /* Ordinary requests have even IDs, while interrupts IDs are odd */
12 #define FUSE_INT_REQ_BIT (1ULL << 0)
13 #define FUSE_REQ_ID_STEP (1ULL << 1)
14
15 extern struct wait_queue_head fuse_dev_waitq;
16
17 struct fuse_arg;
18 struct fuse_args;
19 struct fuse_pqueue;
20 struct fuse_req;
21 struct fuse_iqueue;
22 struct fuse_forget_link;
23
24 struct fuse_copy_state {
25 struct fuse_req *req;
26 struct iov_iter *iter;
27 struct pipe_buffer *pipebufs;
28 struct pipe_buffer *currbuf;
29 struct pipe_inode_info *pipe;
30 unsigned long nr_segs;
31 struct page *pg;
32 unsigned int len;
33 unsigned int offset;
34 bool write:1;
35 bool move_folios:1;
36 bool is_uring:1;
37 struct {
38 unsigned int copied_sz; /* copied size into the user buffer */
39 } ring;
40 };
41
42 /* fud->fc gets assigned to this value when /dev/fuse is closed */
43 #define FUSE_DEV_FC_DISCONNECTED ((struct fuse_conn *) 1)
44
45 /*
46 * Lockless access is OK, because fud->fc is set once during mount and is valid
47 * until the file is released.
48 *
49 * fud->fc is set to FUSE_DEV_FC_DISCONNECTED only after the containing file is
50 * released, so result is safe to dereference in most cases. Exceptions are:
51 * fuse_dev_put() and fuse_fill_super_common().
52 */
fuse_dev_fc_get(struct fuse_dev * fud)53 static inline struct fuse_conn *fuse_dev_fc_get(struct fuse_dev *fud)
54 {
55 /* Pairs with xchg() in fuse_dev_install() */
56 return smp_load_acquire(&fud->fc);
57 }
58
fuse_file_to_fud(struct file * file)59 static inline struct fuse_dev *fuse_file_to_fud(struct file *file)
60 {
61 return file->private_data;
62 }
63
__fuse_get_dev(struct file * file)64 static inline struct fuse_dev *__fuse_get_dev(struct file *file)
65 {
66 struct fuse_dev *fud = fuse_file_to_fud(file);
67
68 if (!fuse_dev_fc_get(fud))
69 return NULL;
70
71 return fud;
72 }
73
74 struct fuse_dev *fuse_get_dev(struct file *file);
75
76 unsigned int fuse_req_hash(u64 unique);
77 struct fuse_req *fuse_request_find(struct fuse_pqueue *fpq, u64 unique);
78
79 void fuse_dev_end_requests(struct list_head *head);
80
81 void fuse_copy_init(struct fuse_copy_state *cs, bool write,
82 struct iov_iter *iter);
83 void fuse_copy_finish(struct fuse_copy_state *cs);
84 int fuse_copy_args(struct fuse_copy_state *cs, unsigned int numargs,
85 unsigned int argpages, struct fuse_arg *args,
86 int zeroing);
87 int fuse_copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args,
88 unsigned int nbytes);
89 void fuse_dev_queue_forget(struct fuse_iqueue *fiq,
90 struct fuse_forget_link *forget);
91 void fuse_dev_queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req);
92 bool fuse_remove_pending_req(struct fuse_req *req, spinlock_t *lock);
93
94 bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list);
95
96 #endif
97
98