xref: /openbmc/linux/fs/fuse/fuse_i.h (revision 69e34551152a286f827d54dcb5700da6aeaac1fb)
1d8a5ba45SMiklos Szeredi /*
2d8a5ba45SMiklos Szeredi   FUSE: Filesystem in Userspace
31729a16cSMiklos Szeredi   Copyright (C) 2001-2008  Miklos Szeredi <miklos@szeredi.hu>
4d8a5ba45SMiklos Szeredi 
5d8a5ba45SMiklos Szeredi   This program can be distributed under the terms of the GNU GPL.
6d8a5ba45SMiklos Szeredi   See the file COPYING.
7d8a5ba45SMiklos Szeredi */
8d8a5ba45SMiklos Szeredi 
929d434b3STejun Heo #ifndef _FS_FUSE_I_H
1029d434b3STejun Heo #define _FS_FUSE_I_H
1129d434b3STejun Heo 
12d8a5ba45SMiklos Szeredi #include <linux/fuse.h>
13d8a5ba45SMiklos Szeredi #include <linux/fs.h>
1451eb01e7SMiklos Szeredi #include <linux/mount.h>
15d8a5ba45SMiklos Szeredi #include <linux/wait.h>
16d8a5ba45SMiklos Szeredi #include <linux/list.h>
17d8a5ba45SMiklos Szeredi #include <linux/spinlock.h>
18d8a5ba45SMiklos Szeredi #include <linux/mm.h>
19d8a5ba45SMiklos Szeredi #include <linux/backing-dev.h>
20bafa9654SMiklos Szeredi #include <linux/mutex.h>
213be5a52bSMiklos Szeredi #include <linux/rwsem.h>
2295668a69STejun Heo #include <linux/rbtree.h>
2395668a69STejun Heo #include <linux/poll.h>
245a18ec17SMiklos Szeredi #include <linux/workqueue.h>
25744742d6SSeth Forshee #include <linux/kref.h>
2660bcc88aSSeth Forshee #include <linux/xattr.h>
270b6e9ea0SSeth Forshee #include <linux/pid_namespace.h>
284e8c2eb5SElena Reshetova #include <linux/refcount.h>
298cb08329SEric W. Biederman #include <linux/user_namespace.h>
30d8a5ba45SMiklos Szeredi 
31334f485dSMiklos Szeredi /** Max number of pages that can be used in a single read request */
32334f485dSMiklos Szeredi #define FUSE_MAX_PAGES_PER_REQ 32
33334f485dSMiklos Szeredi 
343be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */
353be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN
363be5a52bSMiklos Szeredi 
371d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */
381d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024
391d3d752bSMiklos Szeredi 
40bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */
4179a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5
42bafa9654SMiklos Szeredi 
434250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */
444250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1
454250c066SMaxim Patlasov 
46bafa9654SMiklos Szeredi /** List of active connections */
47bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list;
48bafa9654SMiklos Szeredi 
49bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */
50bafa9654SMiklos Szeredi extern struct mutex fuse_mutex;
51413ef8cbSMiklos Szeredi 
5279a9d994SCsaba Henk /** Module parameters */
5379a9d994SCsaba Henk extern unsigned max_user_bgreq;
5479a9d994SCsaba Henk extern unsigned max_user_congthresh;
5579a9d994SCsaba Henk 
5607e77dcaSMiklos Szeredi /* One forget request */
5707e77dcaSMiklos Szeredi struct fuse_forget_link {
5802c048b9SMiklos Szeredi 	struct fuse_forget_one forget_one;
5907e77dcaSMiklos Szeredi 	struct fuse_forget_link *next;
6007e77dcaSMiklos Szeredi };
6107e77dcaSMiklos Szeredi 
62d8a5ba45SMiklos Szeredi /** FUSE inode */
63d8a5ba45SMiklos Szeredi struct fuse_inode {
64d8a5ba45SMiklos Szeredi 	/** Inode data */
65d8a5ba45SMiklos Szeredi 	struct inode inode;
66d8a5ba45SMiklos Szeredi 
67d8a5ba45SMiklos Szeredi 	/** Unique ID, which identifies the inode between userspace
68d8a5ba45SMiklos Szeredi 	 * and kernel */
69d8a5ba45SMiklos Szeredi 	u64 nodeid;
70d8a5ba45SMiklos Szeredi 
719e6268dbSMiklos Szeredi 	/** Number of lookups on this inode */
729e6268dbSMiklos Szeredi 	u64 nlookup;
739e6268dbSMiklos Szeredi 
74e5e5558eSMiklos Szeredi 	/** The request used for sending the FORGET message */
7507e77dcaSMiklos Szeredi 	struct fuse_forget_link *forget;
76e5e5558eSMiklos Szeredi 
77d8a5ba45SMiklos Szeredi 	/** Time in jiffies until the file attributes are valid */
780a0898cfSMiklos Szeredi 	u64 i_time;
79ebc14c4dSMiklos Szeredi 
80ebc14c4dSMiklos Szeredi 	/** The sticky bit in inode->i_mode may have been removed, so
81ebc14c4dSMiklos Szeredi 	    preserve the original mode */
82541af6a0SAl Viro 	umode_t orig_i_mode;
831fb69e78SMiklos Szeredi 
8445c72cd7SPavel Shilovsky 	/** 64 bit inode number */
8545c72cd7SPavel Shilovsky 	u64 orig_ino;
8645c72cd7SPavel Shilovsky 
871fb69e78SMiklos Szeredi 	/** Version of last attribute change */
881fb69e78SMiklos Szeredi 	u64 attr_version;
8993a8c3cdSMiklos Szeredi 
9093a8c3cdSMiklos Szeredi 	/** Files usable in writepage.  Protected by fc->lock */
9193a8c3cdSMiklos Szeredi 	struct list_head write_files;
923be5a52bSMiklos Szeredi 
933be5a52bSMiklos Szeredi 	/** Writepages pending on truncate or fsync */
943be5a52bSMiklos Szeredi 	struct list_head queued_writes;
953be5a52bSMiklos Szeredi 
963be5a52bSMiklos Szeredi 	/** Number of sent writes, a negative bias (FUSE_NOWRITE)
973be5a52bSMiklos Szeredi 	 * means more writes are blocked */
983be5a52bSMiklos Szeredi 	int writectr;
993be5a52bSMiklos Szeredi 
1003be5a52bSMiklos Szeredi 	/** Waitq for writepage completion */
1013be5a52bSMiklos Szeredi 	wait_queue_head_t page_waitq;
1023be5a52bSMiklos Szeredi 
1033be5a52bSMiklos Szeredi 	/** List of writepage requestst (pending or sent) */
1043be5a52bSMiklos Szeredi 	struct list_head writepages;
1054582a4abSFeng Shuo 
106*69e34551SMiklos Szeredi 	/* readdir cache */
107*69e34551SMiklos Szeredi 	struct {
108*69e34551SMiklos Szeredi 		/* true if fully cached */
109*69e34551SMiklos Szeredi 		bool cached;
110*69e34551SMiklos Szeredi 
111*69e34551SMiklos Szeredi 		/* size of cache */
112*69e34551SMiklos Szeredi 		loff_t size;
113*69e34551SMiklos Szeredi 
114*69e34551SMiklos Szeredi 		/* position at end of cache (position of next entry) */
115*69e34551SMiklos Szeredi 		loff_t pos;
116*69e34551SMiklos Szeredi 
117*69e34551SMiklos Szeredi 		/* protects above fields */
118*69e34551SMiklos Szeredi 		spinlock_t lock;
119*69e34551SMiklos Szeredi 	} rdc;
120*69e34551SMiklos Szeredi 
1214582a4abSFeng Shuo 	/** Miscellaneous bits describing inode state */
1224582a4abSFeng Shuo 	unsigned long state;
1235c672ab3SMiklos Szeredi 
1245c672ab3SMiklos Szeredi 	/** Lock for serializing lookup and readdir for back compatibility*/
1255c672ab3SMiklos Szeredi 	struct mutex mutex;
1264582a4abSFeng Shuo };
1274582a4abSFeng Shuo 
1284582a4abSFeng Shuo /** FUSE inode state bits */
1294582a4abSFeng Shuo enum {
1304582a4abSFeng Shuo 	/** Advise readdirplus  */
1314582a4abSFeng Shuo 	FUSE_I_ADVISE_RDPLUS,
1326314efeeSMiklos Szeredi 	/** Initialized with readdirplus */
1336314efeeSMiklos Szeredi 	FUSE_I_INIT_RDPLUS,
13406a7c3c2SMaxim Patlasov 	/** An operation changing file size is in progress  */
13506a7c3c2SMaxim Patlasov 	FUSE_I_SIZE_UNSTABLE,
136d8a5ba45SMiklos Szeredi };
137d8a5ba45SMiklos Szeredi 
138da5e4714SMiklos Szeredi struct fuse_conn;
139da5e4714SMiklos Szeredi 
140b6aeadedSMiklos Szeredi /** FUSE specific file data */
141b6aeadedSMiklos Szeredi struct fuse_file {
142da5e4714SMiklos Szeredi 	/** Fuse connection for this file */
143da5e4714SMiklos Szeredi 	struct fuse_conn *fc;
144da5e4714SMiklos Szeredi 
145b6aeadedSMiklos Szeredi 	/** Request reserved for flush and release */
14633649c91SMiklos Szeredi 	struct fuse_req *reserved_req;
147b6aeadedSMiklos Szeredi 
148acf99433STejun Heo 	/** Kernel file handle guaranteed to be unique */
149acf99433STejun Heo 	u64 kh;
150acf99433STejun Heo 
151b6aeadedSMiklos Szeredi 	/** File handle used by userspace */
152b6aeadedSMiklos Szeredi 	u64 fh;
153c756e0a4SMiklos Szeredi 
154da5e4714SMiklos Szeredi 	/** Node id of this file */
155da5e4714SMiklos Szeredi 	u64 nodeid;
156da5e4714SMiklos Szeredi 
157c756e0a4SMiklos Szeredi 	/** Refcount */
1584e8c2eb5SElena Reshetova 	refcount_t count;
15993a8c3cdSMiklos Szeredi 
160c7b7143cSMiklos Szeredi 	/** FOPEN_* flags returned by open */
161c7b7143cSMiklos Szeredi 	u32 open_flags;
162c7b7143cSMiklos Szeredi 
16393a8c3cdSMiklos Szeredi 	/** Entry on inode's write_files list */
16493a8c3cdSMiklos Szeredi 	struct list_head write_entry;
16595668a69STejun Heo 
16695668a69STejun Heo 	/** RB node to be linked on fuse_conn->polled_files */
16795668a69STejun Heo 	struct rb_node polled_node;
16895668a69STejun Heo 
16995668a69STejun Heo 	/** Wait queue head for poll */
17095668a69STejun Heo 	wait_queue_head_t poll_wait;
17137fb3a30SMiklos Szeredi 
17237fb3a30SMiklos Szeredi 	/** Has flock been performed on this file? */
17337fb3a30SMiklos Szeredi 	bool flock:1;
174b6aeadedSMiklos Szeredi };
175b6aeadedSMiklos Szeredi 
176334f485dSMiklos Szeredi /** One input argument of a request */
177334f485dSMiklos Szeredi struct fuse_in_arg {
178334f485dSMiklos Szeredi 	unsigned size;
179334f485dSMiklos Szeredi 	const void *value;
180334f485dSMiklos Szeredi };
181334f485dSMiklos Szeredi 
182334f485dSMiklos Szeredi /** The request input */
183334f485dSMiklos Szeredi struct fuse_in {
184334f485dSMiklos Szeredi 	/** The request header */
185334f485dSMiklos Szeredi 	struct fuse_in_header h;
186334f485dSMiklos Szeredi 
187334f485dSMiklos Szeredi 	/** True if the data for the last argument is in req->pages */
188334f485dSMiklos Szeredi 	unsigned argpages:1;
189334f485dSMiklos Szeredi 
190334f485dSMiklos Szeredi 	/** Number of arguments */
191334f485dSMiklos Szeredi 	unsigned numargs;
192334f485dSMiklos Szeredi 
193334f485dSMiklos Szeredi 	/** Array of arguments */
194334f485dSMiklos Szeredi 	struct fuse_in_arg args[3];
195334f485dSMiklos Szeredi };
196334f485dSMiklos Szeredi 
197334f485dSMiklos Szeredi /** One output argument of a request */
198334f485dSMiklos Szeredi struct fuse_arg {
199334f485dSMiklos Szeredi 	unsigned size;
200334f485dSMiklos Szeredi 	void *value;
201334f485dSMiklos Szeredi };
202334f485dSMiklos Szeredi 
203334f485dSMiklos Szeredi /** The request output */
204334f485dSMiklos Szeredi struct fuse_out {
205334f485dSMiklos Szeredi 	/** Header returned from userspace */
206334f485dSMiklos Szeredi 	struct fuse_out_header h;
207334f485dSMiklos Szeredi 
208095da6cbSMiklos Szeredi 	/*
209095da6cbSMiklos Szeredi 	 * The following bitfields are not changed during the request
210095da6cbSMiklos Szeredi 	 * processing
211095da6cbSMiklos Szeredi 	 */
212095da6cbSMiklos Szeredi 
213334f485dSMiklos Szeredi 	/** Last argument is variable length (can be shorter than
214334f485dSMiklos Szeredi 	    arg->size) */
215334f485dSMiklos Szeredi 	unsigned argvar:1;
216334f485dSMiklos Szeredi 
217334f485dSMiklos Szeredi 	/** Last argument is a list of pages to copy data to */
218334f485dSMiklos Szeredi 	unsigned argpages:1;
219334f485dSMiklos Szeredi 
220334f485dSMiklos Szeredi 	/** Zero partially or not copied pages */
221334f485dSMiklos Szeredi 	unsigned page_zeroing:1;
222334f485dSMiklos Szeredi 
223ce534fb0SMiklos Szeredi 	/** Pages may be replaced with new ones */
224ce534fb0SMiklos Szeredi 	unsigned page_replace:1;
225ce534fb0SMiklos Szeredi 
226334f485dSMiklos Szeredi 	/** Number or arguments */
227334f485dSMiklos Szeredi 	unsigned numargs;
228334f485dSMiklos Szeredi 
229334f485dSMiklos Szeredi 	/** Array of arguments */
230f704dcb5SMiklos Szeredi 	struct fuse_arg args[2];
231334f485dSMiklos Szeredi };
232334f485dSMiklos Szeredi 
233b2430d75SMaxim Patlasov /** FUSE page descriptor */
234b2430d75SMaxim Patlasov struct fuse_page_desc {
235b2430d75SMaxim Patlasov 	unsigned int length;
236b2430d75SMaxim Patlasov 	unsigned int offset;
237b2430d75SMaxim Patlasov };
238b2430d75SMaxim Patlasov 
2397078187aSMiklos Szeredi struct fuse_args {
2407078187aSMiklos Szeredi 	struct {
2417078187aSMiklos Szeredi 		struct {
2427078187aSMiklos Szeredi 			uint32_t opcode;
2437078187aSMiklos Szeredi 			uint64_t nodeid;
2447078187aSMiklos Szeredi 		} h;
2457078187aSMiklos Szeredi 		unsigned numargs;
2467078187aSMiklos Szeredi 		struct fuse_in_arg args[3];
2477078187aSMiklos Szeredi 
2487078187aSMiklos Szeredi 	} in;
2497078187aSMiklos Szeredi 	struct {
2507078187aSMiklos Szeredi 		unsigned argvar:1;
2517078187aSMiklos Szeredi 		unsigned numargs;
2527078187aSMiklos Szeredi 		struct fuse_arg args[2];
2537078187aSMiklos Szeredi 	} out;
2547078187aSMiklos Szeredi };
2557078187aSMiklos Szeredi 
2567078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {}
2577078187aSMiklos Szeredi 
25801e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */
25901e9d11aSMaxim Patlasov struct fuse_io_priv {
260744742d6SSeth Forshee 	struct kref refcnt;
26101e9d11aSMaxim Patlasov 	int async;
26201e9d11aSMaxim Patlasov 	spinlock_t lock;
26301e9d11aSMaxim Patlasov 	unsigned reqs;
26401e9d11aSMaxim Patlasov 	ssize_t bytes;
26501e9d11aSMaxim Patlasov 	size_t size;
26601e9d11aSMaxim Patlasov 	__u64 offset;
26701e9d11aSMaxim Patlasov 	bool write;
26861c12b49SAshish Samant 	bool should_dirty;
26901e9d11aSMaxim Patlasov 	int err;
27001e9d11aSMaxim Patlasov 	struct kiocb *iocb;
2719d5722b7SChristoph Hellwig 	struct completion *done;
2727879c4e5SAshish Sangwan 	bool blocking;
27301e9d11aSMaxim Patlasov };
27401e9d11aSMaxim Patlasov 
275e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \
276744742d6SSeth Forshee {					\
2771e24edcaSPeter Zijlstra 	.refcnt = KREF_INIT(1),		\
278744742d6SSeth Forshee 	.async = 0,			\
279e1c0eecbSMiklos Szeredi 	.iocb = i,			\
280744742d6SSeth Forshee }
281744742d6SSeth Forshee 
282334f485dSMiklos Szeredi /**
283825d6d33SMiklos Szeredi  * Request flags
284825d6d33SMiklos Szeredi  *
285825d6d33SMiklos Szeredi  * FR_ISREPLY:		set if the request has reply
286825d6d33SMiklos Szeredi  * FR_FORCE:		force sending of the request even if interrupted
287825d6d33SMiklos Szeredi  * FR_BACKGROUND:	request is sent in the background
288825d6d33SMiklos Szeredi  * FR_WAITING:		request is counted as "waiting"
289825d6d33SMiklos Szeredi  * FR_ABORTED:		the request was aborted
290825d6d33SMiklos Szeredi  * FR_INTERRUPTED:	the request has been interrupted
291825d6d33SMiklos Szeredi  * FR_LOCKED:		data is being copied to/from the request
29233e14b4dSMiklos Szeredi  * FR_PENDING:		request is not yet in userspace
29333e14b4dSMiklos Szeredi  * FR_SENT:		request is in userspace, waiting for an answer
29433e14b4dSMiklos Szeredi  * FR_FINISHED:		request is finished
29577cd9d48SMiklos Szeredi  * FR_PRIVATE:		request is on private list
296825d6d33SMiklos Szeredi  */
297825d6d33SMiklos Szeredi enum fuse_req_flag {
298825d6d33SMiklos Szeredi 	FR_ISREPLY,
299825d6d33SMiklos Szeredi 	FR_FORCE,
300825d6d33SMiklos Szeredi 	FR_BACKGROUND,
301825d6d33SMiklos Szeredi 	FR_WAITING,
302825d6d33SMiklos Szeredi 	FR_ABORTED,
303825d6d33SMiklos Szeredi 	FR_INTERRUPTED,
304825d6d33SMiklos Szeredi 	FR_LOCKED,
30533e14b4dSMiklos Szeredi 	FR_PENDING,
30633e14b4dSMiklos Szeredi 	FR_SENT,
30733e14b4dSMiklos Szeredi 	FR_FINISHED,
30877cd9d48SMiklos Szeredi 	FR_PRIVATE,
309825d6d33SMiklos Szeredi };
310825d6d33SMiklos Szeredi 
311825d6d33SMiklos Szeredi /**
312334f485dSMiklos Szeredi  * A request to the client
313dc00809aSMiklos Szeredi  *
314dc00809aSMiklos Szeredi  * .waitq.lock protects the following fields:
315dc00809aSMiklos Szeredi  *   - FR_ABORTED
316dc00809aSMiklos Szeredi  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
317334f485dSMiklos Szeredi  */
318334f485dSMiklos Szeredi struct fuse_req {
319ce1d5a49SMiklos Szeredi 	/** This can be on either pending processing or io lists in
320ce1d5a49SMiklos Szeredi 	    fuse_conn */
321334f485dSMiklos Szeredi 	struct list_head list;
322334f485dSMiklos Szeredi 
323a4d27e75SMiklos Szeredi 	/** Entry on the interrupts list  */
324a4d27e75SMiklos Szeredi 	struct list_head intr_entry;
325a4d27e75SMiklos Szeredi 
326334f485dSMiklos Szeredi 	/** refcount */
327ec99f6d3SElena Reshetova 	refcount_t count;
328334f485dSMiklos Szeredi 
329825d6d33SMiklos Szeredi 	/* Request flags, updated with test/set/clear_bit() */
330825d6d33SMiklos Szeredi 	unsigned long flags;
3319bc5dddaSMiklos Szeredi 
332334f485dSMiklos Szeredi 	/** The request input */
333334f485dSMiklos Szeredi 	struct fuse_in in;
334334f485dSMiklos Szeredi 
335334f485dSMiklos Szeredi 	/** The request output */
336334f485dSMiklos Szeredi 	struct fuse_out out;
337334f485dSMiklos Szeredi 
338334f485dSMiklos Szeredi 	/** Used to wake up the task waiting for completion of request*/
339334f485dSMiklos Szeredi 	wait_queue_head_t waitq;
340334f485dSMiklos Szeredi 
341334f485dSMiklos Szeredi 	/** Data for asynchronous requests */
342334f485dSMiklos Szeredi 	union {
343b57d4264SMiklos Szeredi 		struct {
344b57d4264SMiklos Szeredi 			struct fuse_release_in in;
345baebccbeSMiklos Szeredi 			struct inode *inode;
346b57d4264SMiklos Szeredi 		} release;
3473ec870d5SMiklos Szeredi 		struct fuse_init_in init_in;
3483ec870d5SMiklos Szeredi 		struct fuse_init_out init_out;
34908cbf542STejun Heo 		struct cuse_init_in cuse_init_in;
3505c5c5e51SMiklos Szeredi 		struct {
3515c5c5e51SMiklos Szeredi 			struct fuse_read_in in;
3525c5c5e51SMiklos Szeredi 			u64 attr_ver;
3535c5c5e51SMiklos Szeredi 		} read;
354b25e82e5SMiklos Szeredi 		struct {
355b25e82e5SMiklos Szeredi 			struct fuse_write_in in;
356b25e82e5SMiklos Szeredi 			struct fuse_write_out out;
3578b284dc4SMiklos Szeredi 			struct fuse_req *next;
358b25e82e5SMiklos Szeredi 		} write;
3592d45ba38SMiklos Szeredi 		struct fuse_notify_retrieve_in retrieve_in;
360334f485dSMiklos Szeredi 	} misc;
361334f485dSMiklos Szeredi 
362334f485dSMiklos Szeredi 	/** page vector */
3634250c066SMaxim Patlasov 	struct page **pages;
3644250c066SMaxim Patlasov 
365b2430d75SMaxim Patlasov 	/** page-descriptor vector */
366b2430d75SMaxim Patlasov 	struct fuse_page_desc *page_descs;
367b2430d75SMaxim Patlasov 
3684250c066SMaxim Patlasov 	/** size of the 'pages' array */
3694250c066SMaxim Patlasov 	unsigned max_pages;
3704250c066SMaxim Patlasov 
3714250c066SMaxim Patlasov 	/** inline page vector */
3724250c066SMaxim Patlasov 	struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
373334f485dSMiklos Szeredi 
374b2430d75SMaxim Patlasov 	/** inline page-descriptor vector */
375b2430d75SMaxim Patlasov 	struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
376b2430d75SMaxim Patlasov 
377334f485dSMiklos Szeredi 	/** number of pages in vector */
378334f485dSMiklos Szeredi 	unsigned num_pages;
379334f485dSMiklos Szeredi 
380334f485dSMiklos Szeredi 	/** File used in the request (or NULL) */
381c756e0a4SMiklos Szeredi 	struct fuse_file *ff;
38264c6d8edSMiklos Szeredi 
3833be5a52bSMiklos Szeredi 	/** Inode used in the request or NULL */
3843be5a52bSMiklos Szeredi 	struct inode *inode;
3853be5a52bSMiklos Szeredi 
38601e9d11aSMaxim Patlasov 	/** AIO control block */
38701e9d11aSMaxim Patlasov 	struct fuse_io_priv *io;
38801e9d11aSMaxim Patlasov 
3893be5a52bSMiklos Szeredi 	/** Link on fi->writepages */
3903be5a52bSMiklos Szeredi 	struct list_head writepages_entry;
3913be5a52bSMiklos Szeredi 
39264c6d8edSMiklos Szeredi 	/** Request completion callback */
39364c6d8edSMiklos Szeredi 	void (*end)(struct fuse_conn *, struct fuse_req *);
39433649c91SMiklos Szeredi 
39533649c91SMiklos Szeredi 	/** Request is stolen from fuse_file->reserved_req */
39633649c91SMiklos Szeredi 	struct file *stolen_file;
397334f485dSMiklos Szeredi };
398334f485dSMiklos Szeredi 
399f88996a9SMiklos Szeredi struct fuse_iqueue {
400e16714d8SMiklos Szeredi 	/** Connection established */
401e16714d8SMiklos Szeredi 	unsigned connected;
402e16714d8SMiklos Szeredi 
403f88996a9SMiklos Szeredi 	/** Readers of the connection are waiting on this */
404f88996a9SMiklos Szeredi 	wait_queue_head_t waitq;
405f88996a9SMiklos Szeredi 
406f88996a9SMiklos Szeredi 	/** The next unique request id */
407f88996a9SMiklos Szeredi 	u64 reqctr;
408f88996a9SMiklos Szeredi 
409f88996a9SMiklos Szeredi 	/** The list of pending requests */
410f88996a9SMiklos Szeredi 	struct list_head pending;
411f88996a9SMiklos Szeredi 
412f88996a9SMiklos Szeredi 	/** Pending interrupts */
413f88996a9SMiklos Szeredi 	struct list_head interrupts;
414f88996a9SMiklos Szeredi 
415f88996a9SMiklos Szeredi 	/** Queue of pending forgets */
416f88996a9SMiklos Szeredi 	struct fuse_forget_link forget_list_head;
417f88996a9SMiklos Szeredi 	struct fuse_forget_link *forget_list_tail;
418f88996a9SMiklos Szeredi 
419f88996a9SMiklos Szeredi 	/** Batching of FORGET requests (positive indicates FORGET batch) */
420f88996a9SMiklos Szeredi 	int forget_batch;
421f88996a9SMiklos Szeredi 
422f88996a9SMiklos Szeredi 	/** O_ASYNC requests */
423f88996a9SMiklos Szeredi 	struct fasync_struct *fasync;
424f88996a9SMiklos Szeredi };
425f88996a9SMiklos Szeredi 
426be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8
427be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
428be2ff42cSKirill Tkhai 
4293a2b5b9cSMiklos Szeredi struct fuse_pqueue {
430e96edd94SMiklos Szeredi 	/** Connection established */
431e96edd94SMiklos Szeredi 	unsigned connected;
432e96edd94SMiklos Szeredi 
43345a91cb1SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
43445a91cb1SMiklos Szeredi 	spinlock_t lock;
43545a91cb1SMiklos Szeredi 
436be2ff42cSKirill Tkhai 	/** Hash table of requests being processed */
437be2ff42cSKirill Tkhai 	struct list_head *processing;
4383a2b5b9cSMiklos Szeredi 
4393a2b5b9cSMiklos Szeredi 	/** The list of requests under I/O */
4403a2b5b9cSMiklos Szeredi 	struct list_head io;
4413a2b5b9cSMiklos Szeredi };
4423a2b5b9cSMiklos Szeredi 
443d8a5ba45SMiklos Szeredi /**
444cc080e9eSMiklos Szeredi  * Fuse device instance
445cc080e9eSMiklos Szeredi  */
446cc080e9eSMiklos Szeredi struct fuse_dev {
447cc080e9eSMiklos Szeredi 	/** Fuse connection for this device */
448cc080e9eSMiklos Szeredi 	struct fuse_conn *fc;
449cc080e9eSMiklos Szeredi 
450c3696046SMiklos Szeredi 	/** Processing queue */
451c3696046SMiklos Szeredi 	struct fuse_pqueue pq;
452c3696046SMiklos Szeredi 
453cc080e9eSMiklos Szeredi 	/** list entry on fc->devices */
454cc080e9eSMiklos Szeredi 	struct list_head entry;
455cc080e9eSMiklos Szeredi };
456cc080e9eSMiklos Szeredi 
457cc080e9eSMiklos Szeredi /**
458d8a5ba45SMiklos Szeredi  * A Fuse connection.
459d8a5ba45SMiklos Szeredi  *
460d8a5ba45SMiklos Szeredi  * This structure is created, when the filesystem is mounted, and is
461d8a5ba45SMiklos Szeredi  * destroyed, when the client device is closed and the filesystem is
462d8a5ba45SMiklos Szeredi  * unmounted.
463d8a5ba45SMiklos Szeredi  */
464d8a5ba45SMiklos Szeredi struct fuse_conn {
465d7133114SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
466d7133114SMiklos Szeredi 	spinlock_t lock;
467d7133114SMiklos Szeredi 
468bafa9654SMiklos Szeredi 	/** Refcount */
469095fc40aSElena Reshetova 	refcount_t count;
470bafa9654SMiklos Szeredi 
471c3696046SMiklos Szeredi 	/** Number of fuse_dev's */
472c3696046SMiklos Szeredi 	atomic_t dev_count;
473c3696046SMiklos Szeredi 
474dd3e2c55SAl Viro 	struct rcu_head rcu;
475dd3e2c55SAl Viro 
476d8a5ba45SMiklos Szeredi 	/** The user id for this mount */
477499dcf20SEric W. Biederman 	kuid_t user_id;
478d8a5ba45SMiklos Szeredi 
47987729a55SMiklos Szeredi 	/** The group id for this mount */
480499dcf20SEric W. Biederman 	kgid_t group_id;
48187729a55SMiklos Szeredi 
4820b6e9ea0SSeth Forshee 	/** The pid namespace for this mount */
4830b6e9ea0SSeth Forshee 	struct pid_namespace *pid_ns;
4840b6e9ea0SSeth Forshee 
4858cb08329SEric W. Biederman 	/** The user namespace for this mount */
4868cb08329SEric W. Biederman 	struct user_namespace *user_ns;
4878cb08329SEric W. Biederman 
488db50b96cSMiklos Szeredi 	/** Maximum read size */
489db50b96cSMiklos Szeredi 	unsigned max_read;
490db50b96cSMiklos Szeredi 
491413ef8cbSMiklos Szeredi 	/** Maximum write size */
492413ef8cbSMiklos Szeredi 	unsigned max_write;
493413ef8cbSMiklos Szeredi 
494f88996a9SMiklos Szeredi 	/** Input queue */
495f88996a9SMiklos Szeredi 	struct fuse_iqueue iq;
496334f485dSMiklos Szeredi 
497acf99433STejun Heo 	/** The next unique kernel file handle */
498acf99433STejun Heo 	u64 khctr;
499acf99433STejun Heo 
50095668a69STejun Heo 	/** rbtree of fuse_files waiting for poll events indexed by ph */
50195668a69STejun Heo 	struct rb_root polled_files;
50295668a69STejun Heo 
5037a6d3c8bSCsaba Henk 	/** Maximum number of outstanding background requests */
5047a6d3c8bSCsaba Henk 	unsigned max_background;
5057a6d3c8bSCsaba Henk 
5067a6d3c8bSCsaba Henk 	/** Number of background requests at which congestion starts */
5077a6d3c8bSCsaba Henk 	unsigned congestion_threshold;
5087a6d3c8bSCsaba Henk 
50908a53cdcSMiklos Szeredi 	/** Number of requests currently in the background */
51008a53cdcSMiklos Szeredi 	unsigned num_background;
51108a53cdcSMiklos Szeredi 
512d12def1bSMiklos Szeredi 	/** Number of background requests currently queued for userspace */
513d12def1bSMiklos Szeredi 	unsigned active_background;
514d12def1bSMiklos Szeredi 
515d12def1bSMiklos Szeredi 	/** The list of background requests set aside for later queuing */
516d12def1bSMiklos Szeredi 	struct list_head bg_queue;
517d12def1bSMiklos Szeredi 
518ae2dffa3SKirill Tkhai 	/** Protects: max_background, congestion_threshold, num_background,
519ae2dffa3SKirill Tkhai 	 * active_background, bg_queue, blocked */
520ae2dffa3SKirill Tkhai 	spinlock_t bg_lock;
521ae2dffa3SKirill Tkhai 
522796523fbSMaxim Patlasov 	/** Flag indicating that INIT reply has been received. Allocating
523796523fbSMaxim Patlasov 	 * any fuse request will be suspended until the flag is set */
524796523fbSMaxim Patlasov 	int initialized;
525796523fbSMaxim Patlasov 
52608a53cdcSMiklos Szeredi 	/** Flag indicating if connection is blocked.  This will be
52708a53cdcSMiklos Szeredi 	    the case before the INIT reply is received, and if there
52808a53cdcSMiklos Szeredi 	    are too many outstading backgrounds requests */
52908a53cdcSMiklos Szeredi 	int blocked;
53008a53cdcSMiklos Szeredi 
53108a53cdcSMiklos Szeredi 	/** waitq for blocked connection */
53208a53cdcSMiklos Szeredi 	wait_queue_head_t blocked_waitq;
53308a53cdcSMiklos Szeredi 
534de5e3decSMiklos Szeredi 	/** waitq for reserved requests */
535de5e3decSMiklos Szeredi 	wait_queue_head_t reserved_req_waitq;
536de5e3decSMiklos Szeredi 
53769a53bf2SMiklos Szeredi 	/** Connection established, cleared on umount, connection
53869a53bf2SMiklos Szeredi 	    abort and device release */
539095da6cbSMiklos Szeredi 	unsigned connected;
5401e9a4ed9SMiklos Szeredi 
5413b7008b2SSzymon Lukasz 	/** Connection aborted via sysfs */
5423b7008b2SSzymon Lukasz 	bool aborted;
5433b7008b2SSzymon Lukasz 
544095da6cbSMiklos Szeredi 	/** Connection failed (version mismatch).  Cannot race with
545095da6cbSMiklos Szeredi 	    setting other bitfields since it is only set once in INIT
546095da6cbSMiklos Szeredi 	    reply, before any other request, and never cleared */
547334f485dSMiklos Szeredi 	unsigned conn_error:1;
548334f485dSMiklos Szeredi 
5490ec7ca41SMiklos Szeredi 	/** Connection successful.  Only set in INIT */
5500ec7ca41SMiklos Szeredi 	unsigned conn_init:1;
5510ec7ca41SMiklos Szeredi 
5529cd68455SMiklos Szeredi 	/** Do readpages asynchronously?  Only set in INIT */
5539cd68455SMiklos Szeredi 	unsigned async_read:1;
5549cd68455SMiklos Szeredi 
5553b7008b2SSzymon Lukasz 	/** Return an unique read error after abort.  Only set in INIT */
5563b7008b2SSzymon Lukasz 	unsigned abort_err:1;
5573b7008b2SSzymon Lukasz 
5586ff958edSMiklos Szeredi 	/** Do not send separate SETATTR request before open(O_TRUNC)  */
5596ff958edSMiklos Szeredi 	unsigned atomic_o_trunc:1;
5606ff958edSMiklos Szeredi 
56133670fa2SMiklos Szeredi 	/** Filesystem supports NFS exporting.  Only set in INIT */
56233670fa2SMiklos Szeredi 	unsigned export_support:1;
56333670fa2SMiklos Szeredi 
564d5cd66c5SPavel Emelyanov 	/** write-back cache policy (default is write-through) */
565d5cd66c5SPavel Emelyanov 	unsigned writeback_cache:1;
566d5cd66c5SPavel Emelyanov 
5675c672ab3SMiklos Szeredi 	/** allow parallel lookups and readdir (default is serialized) */
5685c672ab3SMiklos Szeredi 	unsigned parallel_dirops:1;
5695c672ab3SMiklos Szeredi 
5705e940c1dSMiklos Szeredi 	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
5715e940c1dSMiklos Szeredi 	unsigned handle_killpriv:1;
5725e940c1dSMiklos Szeredi 
573095da6cbSMiklos Szeredi 	/*
574095da6cbSMiklos Szeredi 	 * The following bitfields are only for optimization purposes
575095da6cbSMiklos Szeredi 	 * and hence races in setting them will not cause malfunction
576095da6cbSMiklos Szeredi 	 */
577095da6cbSMiklos Szeredi 
5787678ac50SAndrew Gallagher 	/** Is open/release not implemented by fs? */
5797678ac50SAndrew Gallagher 	unsigned no_open:1;
5807678ac50SAndrew Gallagher 
581b6aeadedSMiklos Szeredi 	/** Is fsync not implemented by fs? */
582b6aeadedSMiklos Szeredi 	unsigned no_fsync:1;
583b6aeadedSMiklos Szeredi 
58482547981SMiklos Szeredi 	/** Is fsyncdir not implemented by fs? */
58582547981SMiklos Szeredi 	unsigned no_fsyncdir:1;
58682547981SMiklos Szeredi 
587b6aeadedSMiklos Szeredi 	/** Is flush not implemented by fs? */
588b6aeadedSMiklos Szeredi 	unsigned no_flush:1;
589b6aeadedSMiklos Szeredi 
59092a8780eSMiklos Szeredi 	/** Is setxattr not implemented by fs? */
59192a8780eSMiklos Szeredi 	unsigned no_setxattr:1;
59292a8780eSMiklos Szeredi 
59392a8780eSMiklos Szeredi 	/** Is getxattr not implemented by fs? */
59492a8780eSMiklos Szeredi 	unsigned no_getxattr:1;
59592a8780eSMiklos Szeredi 
59692a8780eSMiklos Szeredi 	/** Is listxattr not implemented by fs? */
59792a8780eSMiklos Szeredi 	unsigned no_listxattr:1;
59892a8780eSMiklos Szeredi 
59992a8780eSMiklos Szeredi 	/** Is removexattr not implemented by fs? */
60092a8780eSMiklos Szeredi 	unsigned no_removexattr:1;
60192a8780eSMiklos Szeredi 
60237fb3a30SMiklos Szeredi 	/** Are posix file locking primitives not implemented by fs? */
60371421259SMiklos Szeredi 	unsigned no_lock:1;
60471421259SMiklos Szeredi 
60531d40d74SMiklos Szeredi 	/** Is access not implemented by fs? */
60631d40d74SMiklos Szeredi 	unsigned no_access:1;
60731d40d74SMiklos Szeredi 
608fd72faacSMiklos Szeredi 	/** Is create not implemented by fs? */
609fd72faacSMiklos Szeredi 	unsigned no_create:1;
610fd72faacSMiklos Szeredi 
611a4d27e75SMiklos Szeredi 	/** Is interrupt not implemented by fs? */
612a4d27e75SMiklos Szeredi 	unsigned no_interrupt:1;
613a4d27e75SMiklos Szeredi 
614b2d2272fSMiklos Szeredi 	/** Is bmap not implemented by fs? */
615b2d2272fSMiklos Szeredi 	unsigned no_bmap:1;
616b2d2272fSMiklos Szeredi 
61795668a69STejun Heo 	/** Is poll not implemented by fs? */
61895668a69STejun Heo 	unsigned no_poll:1;
61995668a69STejun Heo 
62078bb6cb9SMiklos Szeredi 	/** Do multi-page cached writes */
62178bb6cb9SMiklos Szeredi 	unsigned big_writes:1;
62278bb6cb9SMiklos Szeredi 
623e0a43ddcSMiklos Szeredi 	/** Don't apply umask to creation modes */
624e0a43ddcSMiklos Szeredi 	unsigned dont_mask:1;
625e0a43ddcSMiklos Szeredi 
62637fb3a30SMiklos Szeredi 	/** Are BSD file locking primitives not implemented by fs? */
62737fb3a30SMiklos Szeredi 	unsigned no_flock:1;
62837fb3a30SMiklos Szeredi 
629519c6040SMiklos Szeredi 	/** Is fallocate not implemented by fs? */
630519c6040SMiklos Szeredi 	unsigned no_fallocate:1;
631519c6040SMiklos Szeredi 
6321560c974SMiklos Szeredi 	/** Is rename with flags implemented by fs? */
6331560c974SMiklos Szeredi 	unsigned no_rename2:1;
6341560c974SMiklos Szeredi 
63572d0d248SBrian Foster 	/** Use enhanced/automatic page cache invalidation. */
63672d0d248SBrian Foster 	unsigned auto_inval_data:1;
63772d0d248SBrian Foster 
638634734b6SEric Wong 	/** Does the filesystem support readdirplus? */
6390b05b183SAnand V. Avati 	unsigned do_readdirplus:1;
6400b05b183SAnand V. Avati 
641634734b6SEric Wong 	/** Does the filesystem want adaptive readdirplus? */
642634734b6SEric Wong 	unsigned readdirplus_auto:1;
643634734b6SEric Wong 
64460b9df7aSMiklos Szeredi 	/** Does the filesystem support asynchronous direct-IO submission? */
64560b9df7aSMiklos Szeredi 	unsigned async_dio:1;
64660b9df7aSMiklos Szeredi 
6470b5da8dbSRavishankar N 	/** Is lseek not implemented by fs? */
6480b5da8dbSRavishankar N 	unsigned no_lseek:1;
6490b5da8dbSRavishankar N 
65060bcc88aSSeth Forshee 	/** Does the filesystem support posix acls? */
65160bcc88aSSeth Forshee 	unsigned posix_acl:1;
65260bcc88aSSeth Forshee 
65329433a29SMiklos Szeredi 	/** Check permissions based on the file mode or not? */
65429433a29SMiklos Szeredi 	unsigned default_permissions:1;
65529433a29SMiklos Szeredi 
65629433a29SMiklos Szeredi 	/** Allow other than the mounter user to access the filesystem ? */
65729433a29SMiklos Szeredi 	unsigned allow_other:1;
65829433a29SMiklos Szeredi 
65988bc7d50SNiels de Vos 	/** Does the filesystem support copy_file_range? */
66088bc7d50SNiels de Vos 	unsigned no_copy_file_range:1;
66188bc7d50SNiels de Vos 
6620cd5b885SMiklos Szeredi 	/** The number of requests waiting for completion */
6630cd5b885SMiklos Szeredi 	atomic_t num_waiting;
6640cd5b885SMiklos Szeredi 
66545714d65SMiklos Szeredi 	/** Negotiated minor version */
66645714d65SMiklos Szeredi 	unsigned minor;
66745714d65SMiklos Szeredi 
668bafa9654SMiklos Szeredi 	/** Entry on the fuse_conn_list */
669bafa9654SMiklos Szeredi 	struct list_head entry;
670bafa9654SMiklos Szeredi 
671b6f2fcbcSMiklos Szeredi 	/** Device ID from super block */
672b6f2fcbcSMiklos Szeredi 	dev_t dev;
673bafa9654SMiklos Szeredi 
674bafa9654SMiklos Szeredi 	/** Dentries in the control filesystem */
675bafa9654SMiklos Szeredi 	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
676bafa9654SMiklos Szeredi 
677bafa9654SMiklos Szeredi 	/** number of dentries used in the above array */
678bafa9654SMiklos Szeredi 	int ctl_ndents;
679385a17bfSJeff Dike 
6809c8ef561SMiklos Szeredi 	/** Key for lock owner ID scrambling */
6819c8ef561SMiklos Szeredi 	u32 scramble_key[4];
6820ec7ca41SMiklos Szeredi 
6830ec7ca41SMiklos Szeredi 	/** Reserved request for the DESTROY message */
6840ec7ca41SMiklos Szeredi 	struct fuse_req *destroy_req;
6851fb69e78SMiklos Szeredi 
6861fb69e78SMiklos Szeredi 	/** Version counter for attribute changes */
6871fb69e78SMiklos Szeredi 	u64 attr_version;
68843901aabSTejun Heo 
68943901aabSTejun Heo 	/** Called on final put */
69043901aabSTejun Heo 	void (*release)(struct fuse_conn *);
6913b463ae0SJohn Muir 
6923b463ae0SJohn Muir 	/** Super block for this connection. */
6933b463ae0SJohn Muir 	struct super_block *sb;
6943b463ae0SJohn Muir 
6953b463ae0SJohn Muir 	/** Read/write semaphore to hold when accessing sb. */
6963b463ae0SJohn Muir 	struct rw_semaphore killsb;
697cc080e9eSMiklos Szeredi 
698cc080e9eSMiklos Szeredi 	/** List of device instances belonging to this connection */
699cc080e9eSMiklos Szeredi 	struct list_head devices;
700d8a5ba45SMiklos Szeredi };
701d8a5ba45SMiklos Szeredi 
702d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
703d8a5ba45SMiklos Szeredi {
7046383bdaaSMiklos Szeredi 	return sb->s_fs_info;
705d8a5ba45SMiklos Szeredi }
706d8a5ba45SMiklos Szeredi 
707d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
708d8a5ba45SMiklos Szeredi {
709d8a5ba45SMiklos Szeredi 	return get_fuse_conn_super(inode->i_sb);
710d8a5ba45SMiklos Szeredi }
711d8a5ba45SMiklos Szeredi 
712d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
713d8a5ba45SMiklos Szeredi {
714d8a5ba45SMiklos Szeredi 	return container_of(inode, struct fuse_inode, inode);
715d8a5ba45SMiklos Szeredi }
716d8a5ba45SMiklos Szeredi 
717d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode)
718d8a5ba45SMiklos Szeredi {
719d8a5ba45SMiklos Szeredi 	return get_fuse_inode(inode)->nodeid;
720d8a5ba45SMiklos Szeredi }
721d8a5ba45SMiklos Szeredi 
722d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid)
723d123d8e1SMiklos Szeredi {
724d123d8e1SMiklos Szeredi 	return !nodeid || nodeid == FUSE_ROOT_ID;
725d123d8e1SMiklos Szeredi }
726d123d8e1SMiklos Szeredi 
727334f485dSMiklos Szeredi /** Device operations */
7284b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations;
729334f485dSMiklos Szeredi 
7304269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations;
7310ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations;
732dbd561d2SMiklos Szeredi 
733d8a5ba45SMiklos Szeredi /**
7343b463ae0SJohn Muir  * Inode to nodeid comparison.
7353b463ae0SJohn Muir  */
7363b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp);
7373b463ae0SJohn Muir 
7383b463ae0SJohn Muir /**
739e5e5558eSMiklos Szeredi  * Get a filled in inode
740e5e5558eSMiklos Szeredi  */
741b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
7421fb69e78SMiklos Szeredi 			int generation, struct fuse_attr *attr,
7431fb69e78SMiklos Szeredi 			u64 attr_valid, u64 attr_version);
744e5e5558eSMiklos Szeredi 
74513983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
74633670fa2SMiklos Szeredi 		     struct fuse_entry_out *outarg, struct inode **inode);
74733670fa2SMiklos Szeredi 
748e5e5558eSMiklos Szeredi /**
749e5e5558eSMiklos Szeredi  * Send FORGET command
750e5e5558eSMiklos Szeredi  */
75107e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
752b48badf0SMiklos Szeredi 		       u64 nodeid, u64 nlookup);
753e5e5558eSMiklos Szeredi 
75407e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void);
75507e77dcaSMiklos Szeredi 
7560b05b183SAnand V. Avati /* Used by READDIRPLUS */
7570b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid);
7580b05b183SAnand V. Avati 
759e5e5558eSMiklos Szeredi /**
760361b1eb5SMiklos Szeredi  * Initialize READ or READDIR request
76104730fefSMiklos Szeredi  */
762a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file,
7632106cb18SMiklos Szeredi 		    loff_t pos, size_t count, int opcode);
76404730fefSMiklos Szeredi 
76504730fefSMiklos Szeredi /**
76604730fefSMiklos Szeredi  * Send OPEN or OPENDIR request
76704730fefSMiklos Szeredi  */
76891fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
76904730fefSMiklos Szeredi 
770acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
771fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff);
772c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file);
773fd72faacSMiklos Szeredi 
7748b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags);
775c756e0a4SMiklos Szeredi 
77604730fefSMiklos Szeredi /**
77704730fefSMiklos Szeredi  * Send RELEASE or RELEASEDIR request
77804730fefSMiklos Szeredi  */
7798b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode);
78004730fefSMiklos Szeredi 
78104730fefSMiklos Szeredi /**
78282547981SMiklos Szeredi  * Send FSYNC or FSYNCDIR request
78382547981SMiklos Szeredi  */
78402c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
78502c24a82SJosef Bacik 		      int datasync, int isdir);
78682547981SMiklos Szeredi 
78782547981SMiklos Szeredi /**
78895668a69STejun Heo  * Notify poll wakeup
78995668a69STejun Heo  */
79095668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc,
79195668a69STejun Heo 			    struct fuse_notify_poll_wakeup_out *outarg);
79295668a69STejun Heo 
79395668a69STejun Heo /**
7941779381dSMiklos Szeredi  * Initialize file operations on a regular file
795b6aeadedSMiklos Szeredi  */
796b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode);
797b6aeadedSMiklos Szeredi 
798b6aeadedSMiklos Szeredi /**
7991779381dSMiklos Szeredi  * Initialize inode operations on regular files and special files
800e5e5558eSMiklos Szeredi  */
801e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode);
802e5e5558eSMiklos Szeredi 
803e5e5558eSMiklos Szeredi /**
8041779381dSMiklos Szeredi  * Initialize inode and file operations on a directory
805e5e5558eSMiklos Szeredi  */
806e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode);
807e5e5558eSMiklos Szeredi 
808e5e5558eSMiklos Szeredi /**
8091779381dSMiklos Szeredi  * Initialize inode operations on a symlink
810e5e5558eSMiklos Szeredi  */
811e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode);
812e5e5558eSMiklos Szeredi 
813e5e5558eSMiklos Szeredi /**
814e5e5558eSMiklos Szeredi  * Change attributes of an inode
815e5e5558eSMiklos Szeredi  */
8161fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
8171fb69e78SMiklos Szeredi 			    u64 attr_valid, u64 attr_version);
818e5e5558eSMiklos Szeredi 
8193be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
8203be5a52bSMiklos Szeredi 				   u64 attr_valid);
8213be5a52bSMiklos Szeredi 
822e5e5558eSMiklos Szeredi /**
823334f485dSMiklos Szeredi  * Initialize the client device
824334f485dSMiklos Szeredi  */
825334f485dSMiklos Szeredi int fuse_dev_init(void);
826334f485dSMiklos Szeredi 
827334f485dSMiklos Szeredi /**
828334f485dSMiklos Szeredi  * Cleanup the client device
829334f485dSMiklos Szeredi  */
830334f485dSMiklos Szeredi void fuse_dev_cleanup(void);
831334f485dSMiklos Szeredi 
832bafa9654SMiklos Szeredi int fuse_ctl_init(void);
8337736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void);
834bafa9654SMiklos Szeredi 
835334f485dSMiklos Szeredi /**
836334f485dSMiklos Szeredi  * Allocate a request
837334f485dSMiklos Szeredi  */
8384250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages);
839334f485dSMiklos Szeredi 
8404250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
8413be5a52bSMiklos Szeredi 
842334f485dSMiklos Szeredi /**
843334f485dSMiklos Szeredi  * Free a request
844334f485dSMiklos Szeredi  */
845334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req);
846334f485dSMiklos Szeredi 
847334f485dSMiklos Szeredi /**
848b111c8c0SMaxim Patlasov  * Get a request, may fail with -ENOMEM,
849b111c8c0SMaxim Patlasov  * caller should specify # elements in req->pages[] explicitly
850334f485dSMiklos Szeredi  */
851b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
8528b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
8538b41e671SMaxim Patlasov 					     unsigned npages);
854b111c8c0SMaxim Patlasov 
85536cf66edSMaxim Patlasov /*
85636cf66edSMaxim Patlasov  * Increment reference count on request
85736cf66edSMaxim Patlasov  */
85836cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req);
85936cf66edSMaxim Patlasov 
860b111c8c0SMaxim Patlasov /**
86133649c91SMiklos Szeredi  * Gets a requests for a file operation, always succeeds
86233649c91SMiklos Szeredi  */
863b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
864b111c8c0SMaxim Patlasov 					     struct file *file);
86533649c91SMiklos Szeredi 
86633649c91SMiklos Szeredi /**
867ce1d5a49SMiklos Szeredi  * Decrement reference count of a request.  If count goes to zero free
868ce1d5a49SMiklos Szeredi  * the request.
869334f485dSMiklos Szeredi  */
870334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
871334f485dSMiklos Szeredi 
872334f485dSMiklos Szeredi /**
8737c352bdfSMiklos Szeredi  * Send a request (synchronous)
874334f485dSMiklos Szeredi  */
875b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
876334f485dSMiklos Szeredi 
877334f485dSMiklos Szeredi /**
8787078187aSMiklos Szeredi  * Simple request sending that does request allocation and freeing
8797078187aSMiklos Szeredi  */
8807078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
8817078187aSMiklos Szeredi 
8827078187aSMiklos Szeredi /**
883334f485dSMiklos Szeredi  * Send a request in the background
884334f485dSMiklos Szeredi  */
885b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
88663825b4eSKirill Tkhai bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
8873be5a52bSMiklos Szeredi 
8885a5fb1eaSMiklos Szeredi /* Abort all requests */
8893b7008b2SSzymon Lukasz void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);
890b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc);
89169a53bf2SMiklos Szeredi 
8921e9a4ed9SMiklos Szeredi /**
893e5e5558eSMiklos Szeredi  * Invalidate inode attributes
894e5e5558eSMiklos Szeredi  */
895e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode);
896bafa9654SMiklos Szeredi 
897dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry);
898dbd561d2SMiklos Szeredi 
899451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode);
900451418fcSAndrew Gallagher 
901d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o);
902d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
903d123d8e1SMiklos Szeredi 
904bafa9654SMiklos Szeredi /**
905bafa9654SMiklos Szeredi  * Acquire reference to fuse_conn
906bafa9654SMiklos Szeredi  */
907bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
908bafa9654SMiklos Szeredi 
909bafa9654SMiklos Szeredi /**
9100d179aa5STejun Heo  * Initialize fuse_conn
9110d179aa5STejun Heo  */
9128cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
9130d179aa5STejun Heo 
9140d179aa5STejun Heo /**
915bafa9654SMiklos Szeredi  * Release reference to fuse_conn
916bafa9654SMiklos Szeredi  */
917bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc);
918bafa9654SMiklos Szeredi 
919cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
920cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud);
921cc080e9eSMiklos Szeredi 
922bafa9654SMiklos Szeredi /**
923bafa9654SMiklos Szeredi  * Add connection to control filesystem
924bafa9654SMiklos Szeredi  */
925bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc);
926bafa9654SMiklos Szeredi 
927bafa9654SMiklos Szeredi /**
928bafa9654SMiklos Szeredi  * Remove connection from control filesystem
929bafa9654SMiklos Szeredi  */
930bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc);
931a5bfffacSTimo Savola 
932a5bfffacSTimo Savola /**
933a5bfffacSTimo Savola  * Is file type valid?
934a5bfffacSTimo Savola  */
935a5bfffacSTimo Savola int fuse_valid_type(int m);
936e57ac683SMiklos Szeredi 
937e57ac683SMiklos Szeredi /**
938c2132c1bSAnatol Pomozov  * Is current process allowed to perform filesystem operation?
939e57ac683SMiklos Szeredi  */
940c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc);
941f3332114SMiklos Szeredi 
942f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
943bcb4be80SMiklos Szeredi 
944703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode);
945703c7362SSeth Forshee 
9465b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file);
9473be5a52bSMiklos Szeredi 
9483be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode);
9493be5a52bSMiklos Szeredi 
9503be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode);
9513be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode);
9525c5c5e51SMiklos Szeredi 
9535c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc);
95429d434b3STejun Heo 
9553b463ae0SJohn Muir /**
9563b463ae0SJohn Muir  * File-system tells the kernel to invalidate cache for the given node id.
9573b463ae0SJohn Muir  */
9583b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
9593b463ae0SJohn Muir 			     loff_t offset, loff_t len);
9603b463ae0SJohn Muir 
9613b463ae0SJohn Muir /**
9623b463ae0SJohn Muir  * File-system tells the kernel to invalidate parent attributes and
9633b463ae0SJohn Muir  * the dentry matching parent/name.
964451d0f59SJohn Muir  *
965451d0f59SJohn Muir  * If the child_nodeid is non-zero and:
966451d0f59SJohn Muir  *    - matches the inode number for the dentry matching parent/name,
967451d0f59SJohn Muir  *    - is not a mount point
968451d0f59SJohn Muir  *    - is a file or oan empty directory
969451d0f59SJohn Muir  * then the dentry is unhashed (d_delete()).
9703b463ae0SJohn Muir  */
9713b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
972451d0f59SJohn Muir 			     u64 child_nodeid, struct qstr *name);
9733b463ae0SJohn Muir 
97408cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
97508cbf542STejun Heo 		 bool isdir);
976ea8cd333SPavel Emelyanov 
977ea8cd333SPavel Emelyanov /**
978ea8cd333SPavel Emelyanov  * fuse_direct_io() flags
979ea8cd333SPavel Emelyanov  */
980ea8cd333SPavel Emelyanov 
981ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */
982ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0)
983ea8cd333SPavel Emelyanov 
984ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
985ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE  (1 << 1)
986ea8cd333SPavel Emelyanov 
987d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
988d22a943fSAl Viro 		       loff_t *ppos, int flags);
98908cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
99008cbf542STejun Heo 		   unsigned int flags);
991b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd,
992b18da0c5SMiklos Szeredi 		       unsigned long arg, unsigned int flags);
993076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait);
99408cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file);
99508cbf542STejun Heo 
996b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos);
997b0aa7606SMaxim Patlasov 
998ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
9991e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1000a1d75f25SMiklos Szeredi 
100162490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1002efb9fa9eSMaxim Patlasov 		    struct file *file);
1003efb9fa9eSMaxim Patlasov 
10049759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc);
10059759bd51SMiklos Szeredi 
100663576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked);
100763576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode);
10085c672ab3SMiklos Szeredi 
100960bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value,
101060bcc88aSSeth Forshee 		  size_t size, int flags);
101160bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
101260bcc88aSSeth Forshee 		      size_t size);
1013703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
101460bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name);
1015703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[];
101660bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1017e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
101860bcc88aSSeth Forshee 
101960bcc88aSSeth Forshee struct posix_acl;
102060bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type);
102160bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
1022703c7362SSeth Forshee 
1023d123d8e1SMiklos Szeredi 
1024d123d8e1SMiklos Szeredi /* readdir.c */
1025d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx);
1026d123d8e1SMiklos Szeredi 
102729d434b3STejun Heo #endif /* _FS_FUSE_I_H */
1028