xref: /linux/fs/fuse/fuse_dev_i.h (revision 6238729bfce13f94b701766996a5d116d2df8bff)
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 #define FUSE_DEV_SYNC_INIT ((struct fuse_dev *) 1)
43 #define FUSE_DEV_PTR_MASK (~1UL)
44 
__fuse_get_dev(struct file * file)45 static inline struct fuse_dev *__fuse_get_dev(struct file *file)
46 {
47 	/*
48 	 * Lockless access is OK, because file->private data is set
49 	 * once during mount and is valid until the file is released.
50 	 */
51 	struct fuse_dev *fud = READ_ONCE(file->private_data);
52 
53 	return (typeof(fud)) ((unsigned long) fud & FUSE_DEV_PTR_MASK);
54 }
55 
56 struct fuse_dev *fuse_get_dev(struct file *file);
57 
58 unsigned int fuse_req_hash(u64 unique);
59 struct fuse_req *fuse_request_find(struct fuse_pqueue *fpq, u64 unique);
60 
61 void fuse_dev_end_requests(struct list_head *head);
62 
63 void fuse_copy_init(struct fuse_copy_state *cs, bool write,
64 			   struct iov_iter *iter);
65 int fuse_copy_args(struct fuse_copy_state *cs, unsigned int numargs,
66 		   unsigned int argpages, struct fuse_arg *args,
67 		   int zeroing);
68 int fuse_copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args,
69 		       unsigned int nbytes);
70 void fuse_dev_queue_forget(struct fuse_iqueue *fiq,
71 			   struct fuse_forget_link *forget);
72 void fuse_dev_queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req);
73 bool fuse_remove_pending_req(struct fuse_req *req, spinlock_t *lock);
74 
75 bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list);
76 
77 #endif
78 
79