xref: /openbmc/linux/fs/fuse/fuse_i.h (revision 261aaba72fdba17b74a3a434d9f925b43d90e958)
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 
10669e34551SMiklos Szeredi 	/* readdir cache */
10769e34551SMiklos Szeredi 	struct {
10869e34551SMiklos Szeredi 		/* true if fully cached */
10969e34551SMiklos Szeredi 		bool cached;
11069e34551SMiklos Szeredi 
11169e34551SMiklos Szeredi 		/* size of cache */
11269e34551SMiklos Szeredi 		loff_t size;
11369e34551SMiklos Szeredi 
11469e34551SMiklos Szeredi 		/* position at end of cache (position of next entry) */
11569e34551SMiklos Szeredi 		loff_t pos;
11669e34551SMiklos Szeredi 
1173494927eSMiklos Szeredi 		/* version of the cache */
1183494927eSMiklos Szeredi 		u64 version;
1193494927eSMiklos Szeredi 
1207118883bSMiklos Szeredi 		/* modification time of directory when cache was started */
1217118883bSMiklos Szeredi 		struct timespec64 mtime;
1227118883bSMiklos Szeredi 
123*261aaba7SMiklos Szeredi 		/* iversion of directory when cache was started */
124*261aaba7SMiklos Szeredi 		u64 iversion;
125*261aaba7SMiklos Szeredi 
12669e34551SMiklos Szeredi 		/* protects above fields */
12769e34551SMiklos Szeredi 		spinlock_t lock;
12869e34551SMiklos Szeredi 	} rdc;
12969e34551SMiklos Szeredi 
1304582a4abSFeng Shuo 	/** Miscellaneous bits describing inode state */
1314582a4abSFeng Shuo 	unsigned long state;
1325c672ab3SMiklos Szeredi 
1335c672ab3SMiklos Szeredi 	/** Lock for serializing lookup and readdir for back compatibility*/
1345c672ab3SMiklos Szeredi 	struct mutex mutex;
1354582a4abSFeng Shuo };
1364582a4abSFeng Shuo 
1374582a4abSFeng Shuo /** FUSE inode state bits */
1384582a4abSFeng Shuo enum {
1394582a4abSFeng Shuo 	/** Advise readdirplus  */
1404582a4abSFeng Shuo 	FUSE_I_ADVISE_RDPLUS,
1416314efeeSMiklos Szeredi 	/** Initialized with readdirplus */
1426314efeeSMiklos Szeredi 	FUSE_I_INIT_RDPLUS,
14306a7c3c2SMaxim Patlasov 	/** An operation changing file size is in progress  */
14406a7c3c2SMaxim Patlasov 	FUSE_I_SIZE_UNSTABLE,
145d8a5ba45SMiklos Szeredi };
146d8a5ba45SMiklos Szeredi 
147da5e4714SMiklos Szeredi struct fuse_conn;
148da5e4714SMiklos Szeredi 
149b6aeadedSMiklos Szeredi /** FUSE specific file data */
150b6aeadedSMiklos Szeredi struct fuse_file {
151da5e4714SMiklos Szeredi 	/** Fuse connection for this file */
152da5e4714SMiklos Szeredi 	struct fuse_conn *fc;
153da5e4714SMiklos Szeredi 
154b6aeadedSMiklos Szeredi 	/** Request reserved for flush and release */
15533649c91SMiklos Szeredi 	struct fuse_req *reserved_req;
156b6aeadedSMiklos Szeredi 
157acf99433STejun Heo 	/** Kernel file handle guaranteed to be unique */
158acf99433STejun Heo 	u64 kh;
159acf99433STejun Heo 
160b6aeadedSMiklos Szeredi 	/** File handle used by userspace */
161b6aeadedSMiklos Szeredi 	u64 fh;
162c756e0a4SMiklos Szeredi 
163da5e4714SMiklos Szeredi 	/** Node id of this file */
164da5e4714SMiklos Szeredi 	u64 nodeid;
165da5e4714SMiklos Szeredi 
166c756e0a4SMiklos Szeredi 	/** Refcount */
1674e8c2eb5SElena Reshetova 	refcount_t count;
16893a8c3cdSMiklos Szeredi 
169c7b7143cSMiklos Szeredi 	/** FOPEN_* flags returned by open */
170c7b7143cSMiklos Szeredi 	u32 open_flags;
171c7b7143cSMiklos Szeredi 
17293a8c3cdSMiklos Szeredi 	/** Entry on inode's write_files list */
17393a8c3cdSMiklos Szeredi 	struct list_head write_entry;
17495668a69STejun Heo 
1755d7bc7e8SMiklos Szeredi 	/* Readdir related */
1765d7bc7e8SMiklos Szeredi 	struct {
1775d7bc7e8SMiklos Szeredi 		/*
1785d7bc7e8SMiklos Szeredi 		 * Protects below fields against (crazy) parallel readdir on
1795d7bc7e8SMiklos Szeredi 		 * same open file.  Uncontended in the normal case.
1805d7bc7e8SMiklos Szeredi 		 */
1815d7bc7e8SMiklos Szeredi 		struct mutex lock;
1825d7bc7e8SMiklos Szeredi 
1835d7bc7e8SMiklos Szeredi 		/* Dir stream position */
1845d7bc7e8SMiklos Szeredi 		loff_t pos;
1855d7bc7e8SMiklos Szeredi 
1865d7bc7e8SMiklos Szeredi 		/* Offset in cache */
1875d7bc7e8SMiklos Szeredi 		loff_t cache_off;
1883494927eSMiklos Szeredi 
1893494927eSMiklos Szeredi 		/* Version of cache we are reading */
1903494927eSMiklos Szeredi 		u64 version;
1913494927eSMiklos Szeredi 
1925d7bc7e8SMiklos Szeredi 	} readdir;
1935d7bc7e8SMiklos Szeredi 
19495668a69STejun Heo 	/** RB node to be linked on fuse_conn->polled_files */
19595668a69STejun Heo 	struct rb_node polled_node;
19695668a69STejun Heo 
19795668a69STejun Heo 	/** Wait queue head for poll */
19895668a69STejun Heo 	wait_queue_head_t poll_wait;
19937fb3a30SMiklos Szeredi 
20037fb3a30SMiklos Szeredi 	/** Has flock been performed on this file? */
20137fb3a30SMiklos Szeredi 	bool flock:1;
202b6aeadedSMiklos Szeredi };
203b6aeadedSMiklos Szeredi 
204334f485dSMiklos Szeredi /** One input argument of a request */
205334f485dSMiklos Szeredi struct fuse_in_arg {
206334f485dSMiklos Szeredi 	unsigned size;
207334f485dSMiklos Szeredi 	const void *value;
208334f485dSMiklos Szeredi };
209334f485dSMiklos Szeredi 
210334f485dSMiklos Szeredi /** The request input */
211334f485dSMiklos Szeredi struct fuse_in {
212334f485dSMiklos Szeredi 	/** The request header */
213334f485dSMiklos Szeredi 	struct fuse_in_header h;
214334f485dSMiklos Szeredi 
215334f485dSMiklos Szeredi 	/** True if the data for the last argument is in req->pages */
216334f485dSMiklos Szeredi 	unsigned argpages:1;
217334f485dSMiklos Szeredi 
218334f485dSMiklos Szeredi 	/** Number of arguments */
219334f485dSMiklos Szeredi 	unsigned numargs;
220334f485dSMiklos Szeredi 
221334f485dSMiklos Szeredi 	/** Array of arguments */
222334f485dSMiklos Szeredi 	struct fuse_in_arg args[3];
223334f485dSMiklos Szeredi };
224334f485dSMiklos Szeredi 
225334f485dSMiklos Szeredi /** One output argument of a request */
226334f485dSMiklos Szeredi struct fuse_arg {
227334f485dSMiklos Szeredi 	unsigned size;
228334f485dSMiklos Szeredi 	void *value;
229334f485dSMiklos Szeredi };
230334f485dSMiklos Szeredi 
231334f485dSMiklos Szeredi /** The request output */
232334f485dSMiklos Szeredi struct fuse_out {
233334f485dSMiklos Szeredi 	/** Header returned from userspace */
234334f485dSMiklos Szeredi 	struct fuse_out_header h;
235334f485dSMiklos Szeredi 
236095da6cbSMiklos Szeredi 	/*
237095da6cbSMiklos Szeredi 	 * The following bitfields are not changed during the request
238095da6cbSMiklos Szeredi 	 * processing
239095da6cbSMiklos Szeredi 	 */
240095da6cbSMiklos Szeredi 
241334f485dSMiklos Szeredi 	/** Last argument is variable length (can be shorter than
242334f485dSMiklos Szeredi 	    arg->size) */
243334f485dSMiklos Szeredi 	unsigned argvar:1;
244334f485dSMiklos Szeredi 
245334f485dSMiklos Szeredi 	/** Last argument is a list of pages to copy data to */
246334f485dSMiklos Szeredi 	unsigned argpages:1;
247334f485dSMiklos Szeredi 
248334f485dSMiklos Szeredi 	/** Zero partially or not copied pages */
249334f485dSMiklos Szeredi 	unsigned page_zeroing:1;
250334f485dSMiklos Szeredi 
251ce534fb0SMiklos Szeredi 	/** Pages may be replaced with new ones */
252ce534fb0SMiklos Szeredi 	unsigned page_replace:1;
253ce534fb0SMiklos Szeredi 
254334f485dSMiklos Szeredi 	/** Number or arguments */
255334f485dSMiklos Szeredi 	unsigned numargs;
256334f485dSMiklos Szeredi 
257334f485dSMiklos Szeredi 	/** Array of arguments */
258f704dcb5SMiklos Szeredi 	struct fuse_arg args[2];
259334f485dSMiklos Szeredi };
260334f485dSMiklos Szeredi 
261b2430d75SMaxim Patlasov /** FUSE page descriptor */
262b2430d75SMaxim Patlasov struct fuse_page_desc {
263b2430d75SMaxim Patlasov 	unsigned int length;
264b2430d75SMaxim Patlasov 	unsigned int offset;
265b2430d75SMaxim Patlasov };
266b2430d75SMaxim Patlasov 
2677078187aSMiklos Szeredi struct fuse_args {
2687078187aSMiklos Szeredi 	struct {
2697078187aSMiklos Szeredi 		struct {
2707078187aSMiklos Szeredi 			uint32_t opcode;
2717078187aSMiklos Szeredi 			uint64_t nodeid;
2727078187aSMiklos Szeredi 		} h;
2737078187aSMiklos Szeredi 		unsigned numargs;
2747078187aSMiklos Szeredi 		struct fuse_in_arg args[3];
2757078187aSMiklos Szeredi 
2767078187aSMiklos Szeredi 	} in;
2777078187aSMiklos Szeredi 	struct {
2787078187aSMiklos Szeredi 		unsigned argvar:1;
2797078187aSMiklos Szeredi 		unsigned numargs;
2807078187aSMiklos Szeredi 		struct fuse_arg args[2];
2817078187aSMiklos Szeredi 	} out;
2827078187aSMiklos Szeredi };
2837078187aSMiklos Szeredi 
2847078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {}
2857078187aSMiklos Szeredi 
28601e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */
28701e9d11aSMaxim Patlasov struct fuse_io_priv {
288744742d6SSeth Forshee 	struct kref refcnt;
28901e9d11aSMaxim Patlasov 	int async;
29001e9d11aSMaxim Patlasov 	spinlock_t lock;
29101e9d11aSMaxim Patlasov 	unsigned reqs;
29201e9d11aSMaxim Patlasov 	ssize_t bytes;
29301e9d11aSMaxim Patlasov 	size_t size;
29401e9d11aSMaxim Patlasov 	__u64 offset;
29501e9d11aSMaxim Patlasov 	bool write;
29661c12b49SAshish Samant 	bool should_dirty;
29701e9d11aSMaxim Patlasov 	int err;
29801e9d11aSMaxim Patlasov 	struct kiocb *iocb;
2999d5722b7SChristoph Hellwig 	struct completion *done;
3007879c4e5SAshish Sangwan 	bool blocking;
30101e9d11aSMaxim Patlasov };
30201e9d11aSMaxim Patlasov 
303e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \
304744742d6SSeth Forshee {					\
3051e24edcaSPeter Zijlstra 	.refcnt = KREF_INIT(1),		\
306744742d6SSeth Forshee 	.async = 0,			\
307e1c0eecbSMiklos Szeredi 	.iocb = i,			\
308744742d6SSeth Forshee }
309744742d6SSeth Forshee 
310334f485dSMiklos Szeredi /**
311825d6d33SMiklos Szeredi  * Request flags
312825d6d33SMiklos Szeredi  *
313825d6d33SMiklos Szeredi  * FR_ISREPLY:		set if the request has reply
314825d6d33SMiklos Szeredi  * FR_FORCE:		force sending of the request even if interrupted
315825d6d33SMiklos Szeredi  * FR_BACKGROUND:	request is sent in the background
316825d6d33SMiklos Szeredi  * FR_WAITING:		request is counted as "waiting"
317825d6d33SMiklos Szeredi  * FR_ABORTED:		the request was aborted
318825d6d33SMiklos Szeredi  * FR_INTERRUPTED:	the request has been interrupted
319825d6d33SMiklos Szeredi  * FR_LOCKED:		data is being copied to/from the request
32033e14b4dSMiklos Szeredi  * FR_PENDING:		request is not yet in userspace
32133e14b4dSMiklos Szeredi  * FR_SENT:		request is in userspace, waiting for an answer
32233e14b4dSMiklos Szeredi  * FR_FINISHED:		request is finished
32377cd9d48SMiklos Szeredi  * FR_PRIVATE:		request is on private list
324825d6d33SMiklos Szeredi  */
325825d6d33SMiklos Szeredi enum fuse_req_flag {
326825d6d33SMiklos Szeredi 	FR_ISREPLY,
327825d6d33SMiklos Szeredi 	FR_FORCE,
328825d6d33SMiklos Szeredi 	FR_BACKGROUND,
329825d6d33SMiklos Szeredi 	FR_WAITING,
330825d6d33SMiklos Szeredi 	FR_ABORTED,
331825d6d33SMiklos Szeredi 	FR_INTERRUPTED,
332825d6d33SMiklos Szeredi 	FR_LOCKED,
33333e14b4dSMiklos Szeredi 	FR_PENDING,
33433e14b4dSMiklos Szeredi 	FR_SENT,
33533e14b4dSMiklos Szeredi 	FR_FINISHED,
33677cd9d48SMiklos Szeredi 	FR_PRIVATE,
337825d6d33SMiklos Szeredi };
338825d6d33SMiklos Szeredi 
339825d6d33SMiklos Szeredi /**
340334f485dSMiklos Szeredi  * A request to the client
341dc00809aSMiklos Szeredi  *
342dc00809aSMiklos Szeredi  * .waitq.lock protects the following fields:
343dc00809aSMiklos Szeredi  *   - FR_ABORTED
344dc00809aSMiklos Szeredi  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
345334f485dSMiklos Szeredi  */
346334f485dSMiklos Szeredi struct fuse_req {
347ce1d5a49SMiklos Szeredi 	/** This can be on either pending processing or io lists in
348ce1d5a49SMiklos Szeredi 	    fuse_conn */
349334f485dSMiklos Szeredi 	struct list_head list;
350334f485dSMiklos Szeredi 
351a4d27e75SMiklos Szeredi 	/** Entry on the interrupts list  */
352a4d27e75SMiklos Szeredi 	struct list_head intr_entry;
353a4d27e75SMiklos Szeredi 
354334f485dSMiklos Szeredi 	/** refcount */
355ec99f6d3SElena Reshetova 	refcount_t count;
356334f485dSMiklos Szeredi 
357825d6d33SMiklos Szeredi 	/* Request flags, updated with test/set/clear_bit() */
358825d6d33SMiklos Szeredi 	unsigned long flags;
3599bc5dddaSMiklos Szeredi 
360334f485dSMiklos Szeredi 	/** The request input */
361334f485dSMiklos Szeredi 	struct fuse_in in;
362334f485dSMiklos Szeredi 
363334f485dSMiklos Szeredi 	/** The request output */
364334f485dSMiklos Szeredi 	struct fuse_out out;
365334f485dSMiklos Szeredi 
366334f485dSMiklos Szeredi 	/** Used to wake up the task waiting for completion of request*/
367334f485dSMiklos Szeredi 	wait_queue_head_t waitq;
368334f485dSMiklos Szeredi 
369334f485dSMiklos Szeredi 	/** Data for asynchronous requests */
370334f485dSMiklos Szeredi 	union {
371b57d4264SMiklos Szeredi 		struct {
372b57d4264SMiklos Szeredi 			struct fuse_release_in in;
373baebccbeSMiklos Szeredi 			struct inode *inode;
374b57d4264SMiklos Szeredi 		} release;
3753ec870d5SMiklos Szeredi 		struct fuse_init_in init_in;
3763ec870d5SMiklos Szeredi 		struct fuse_init_out init_out;
37708cbf542STejun Heo 		struct cuse_init_in cuse_init_in;
3785c5c5e51SMiklos Szeredi 		struct {
3795c5c5e51SMiklos Szeredi 			struct fuse_read_in in;
3805c5c5e51SMiklos Szeredi 			u64 attr_ver;
3815c5c5e51SMiklos Szeredi 		} read;
382b25e82e5SMiklos Szeredi 		struct {
383b25e82e5SMiklos Szeredi 			struct fuse_write_in in;
384b25e82e5SMiklos Szeredi 			struct fuse_write_out out;
3858b284dc4SMiklos Szeredi 			struct fuse_req *next;
386b25e82e5SMiklos Szeredi 		} write;
3872d45ba38SMiklos Szeredi 		struct fuse_notify_retrieve_in retrieve_in;
388334f485dSMiklos Szeredi 	} misc;
389334f485dSMiklos Szeredi 
390334f485dSMiklos Szeredi 	/** page vector */
3914250c066SMaxim Patlasov 	struct page **pages;
3924250c066SMaxim Patlasov 
393b2430d75SMaxim Patlasov 	/** page-descriptor vector */
394b2430d75SMaxim Patlasov 	struct fuse_page_desc *page_descs;
395b2430d75SMaxim Patlasov 
3964250c066SMaxim Patlasov 	/** size of the 'pages' array */
3974250c066SMaxim Patlasov 	unsigned max_pages;
3984250c066SMaxim Patlasov 
3994250c066SMaxim Patlasov 	/** inline page vector */
4004250c066SMaxim Patlasov 	struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
401334f485dSMiklos Szeredi 
402b2430d75SMaxim Patlasov 	/** inline page-descriptor vector */
403b2430d75SMaxim Patlasov 	struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
404b2430d75SMaxim Patlasov 
405334f485dSMiklos Szeredi 	/** number of pages in vector */
406334f485dSMiklos Szeredi 	unsigned num_pages;
407334f485dSMiklos Szeredi 
408334f485dSMiklos Szeredi 	/** File used in the request (or NULL) */
409c756e0a4SMiklos Szeredi 	struct fuse_file *ff;
41064c6d8edSMiklos Szeredi 
4113be5a52bSMiklos Szeredi 	/** Inode used in the request or NULL */
4123be5a52bSMiklos Szeredi 	struct inode *inode;
4133be5a52bSMiklos Szeredi 
41401e9d11aSMaxim Patlasov 	/** AIO control block */
41501e9d11aSMaxim Patlasov 	struct fuse_io_priv *io;
41601e9d11aSMaxim Patlasov 
4173be5a52bSMiklos Szeredi 	/** Link on fi->writepages */
4183be5a52bSMiklos Szeredi 	struct list_head writepages_entry;
4193be5a52bSMiklos Szeredi 
42064c6d8edSMiklos Szeredi 	/** Request completion callback */
42164c6d8edSMiklos Szeredi 	void (*end)(struct fuse_conn *, struct fuse_req *);
42233649c91SMiklos Szeredi 
42333649c91SMiklos Szeredi 	/** Request is stolen from fuse_file->reserved_req */
42433649c91SMiklos Szeredi 	struct file *stolen_file;
425334f485dSMiklos Szeredi };
426334f485dSMiklos Szeredi 
427f88996a9SMiklos Szeredi struct fuse_iqueue {
428e16714d8SMiklos Szeredi 	/** Connection established */
429e16714d8SMiklos Szeredi 	unsigned connected;
430e16714d8SMiklos Szeredi 
431f88996a9SMiklos Szeredi 	/** Readers of the connection are waiting on this */
432f88996a9SMiklos Szeredi 	wait_queue_head_t waitq;
433f88996a9SMiklos Szeredi 
434f88996a9SMiklos Szeredi 	/** The next unique request id */
435f88996a9SMiklos Szeredi 	u64 reqctr;
436f88996a9SMiklos Szeredi 
437f88996a9SMiklos Szeredi 	/** The list of pending requests */
438f88996a9SMiklos Szeredi 	struct list_head pending;
439f88996a9SMiklos Szeredi 
440f88996a9SMiklos Szeredi 	/** Pending interrupts */
441f88996a9SMiklos Szeredi 	struct list_head interrupts;
442f88996a9SMiklos Szeredi 
443f88996a9SMiklos Szeredi 	/** Queue of pending forgets */
444f88996a9SMiklos Szeredi 	struct fuse_forget_link forget_list_head;
445f88996a9SMiklos Szeredi 	struct fuse_forget_link *forget_list_tail;
446f88996a9SMiklos Szeredi 
447f88996a9SMiklos Szeredi 	/** Batching of FORGET requests (positive indicates FORGET batch) */
448f88996a9SMiklos Szeredi 	int forget_batch;
449f88996a9SMiklos Szeredi 
450f88996a9SMiklos Szeredi 	/** O_ASYNC requests */
451f88996a9SMiklos Szeredi 	struct fasync_struct *fasync;
452f88996a9SMiklos Szeredi };
453f88996a9SMiklos Szeredi 
454be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8
455be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
456be2ff42cSKirill Tkhai 
4573a2b5b9cSMiklos Szeredi struct fuse_pqueue {
458e96edd94SMiklos Szeredi 	/** Connection established */
459e96edd94SMiklos Szeredi 	unsigned connected;
460e96edd94SMiklos Szeredi 
46145a91cb1SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
46245a91cb1SMiklos Szeredi 	spinlock_t lock;
46345a91cb1SMiklos Szeredi 
464be2ff42cSKirill Tkhai 	/** Hash table of requests being processed */
465be2ff42cSKirill Tkhai 	struct list_head *processing;
4663a2b5b9cSMiklos Szeredi 
4673a2b5b9cSMiklos Szeredi 	/** The list of requests under I/O */
4683a2b5b9cSMiklos Szeredi 	struct list_head io;
4693a2b5b9cSMiklos Szeredi };
4703a2b5b9cSMiklos Szeredi 
471d8a5ba45SMiklos Szeredi /**
472cc080e9eSMiklos Szeredi  * Fuse device instance
473cc080e9eSMiklos Szeredi  */
474cc080e9eSMiklos Szeredi struct fuse_dev {
475cc080e9eSMiklos Szeredi 	/** Fuse connection for this device */
476cc080e9eSMiklos Szeredi 	struct fuse_conn *fc;
477cc080e9eSMiklos Szeredi 
478c3696046SMiklos Szeredi 	/** Processing queue */
479c3696046SMiklos Szeredi 	struct fuse_pqueue pq;
480c3696046SMiklos Szeredi 
481cc080e9eSMiklos Szeredi 	/** list entry on fc->devices */
482cc080e9eSMiklos Szeredi 	struct list_head entry;
483cc080e9eSMiklos Szeredi };
484cc080e9eSMiklos Szeredi 
485cc080e9eSMiklos Szeredi /**
486d8a5ba45SMiklos Szeredi  * A Fuse connection.
487d8a5ba45SMiklos Szeredi  *
488d8a5ba45SMiklos Szeredi  * This structure is created, when the filesystem is mounted, and is
489d8a5ba45SMiklos Szeredi  * destroyed, when the client device is closed and the filesystem is
490d8a5ba45SMiklos Szeredi  * unmounted.
491d8a5ba45SMiklos Szeredi  */
492d8a5ba45SMiklos Szeredi struct fuse_conn {
493d7133114SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
494d7133114SMiklos Szeredi 	spinlock_t lock;
495d7133114SMiklos Szeredi 
496bafa9654SMiklos Szeredi 	/** Refcount */
497095fc40aSElena Reshetova 	refcount_t count;
498bafa9654SMiklos Szeredi 
499c3696046SMiklos Szeredi 	/** Number of fuse_dev's */
500c3696046SMiklos Szeredi 	atomic_t dev_count;
501c3696046SMiklos Szeredi 
502dd3e2c55SAl Viro 	struct rcu_head rcu;
503dd3e2c55SAl Viro 
504d8a5ba45SMiklos Szeredi 	/** The user id for this mount */
505499dcf20SEric W. Biederman 	kuid_t user_id;
506d8a5ba45SMiklos Szeredi 
50787729a55SMiklos Szeredi 	/** The group id for this mount */
508499dcf20SEric W. Biederman 	kgid_t group_id;
50987729a55SMiklos Szeredi 
5100b6e9ea0SSeth Forshee 	/** The pid namespace for this mount */
5110b6e9ea0SSeth Forshee 	struct pid_namespace *pid_ns;
5120b6e9ea0SSeth Forshee 
5138cb08329SEric W. Biederman 	/** The user namespace for this mount */
5148cb08329SEric W. Biederman 	struct user_namespace *user_ns;
5158cb08329SEric W. Biederman 
516db50b96cSMiklos Szeredi 	/** Maximum read size */
517db50b96cSMiklos Szeredi 	unsigned max_read;
518db50b96cSMiklos Szeredi 
519413ef8cbSMiklos Szeredi 	/** Maximum write size */
520413ef8cbSMiklos Szeredi 	unsigned max_write;
521413ef8cbSMiklos Szeredi 
522f88996a9SMiklos Szeredi 	/** Input queue */
523f88996a9SMiklos Szeredi 	struct fuse_iqueue iq;
524334f485dSMiklos Szeredi 
525acf99433STejun Heo 	/** The next unique kernel file handle */
526acf99433STejun Heo 	u64 khctr;
527acf99433STejun Heo 
52895668a69STejun Heo 	/** rbtree of fuse_files waiting for poll events indexed by ph */
52995668a69STejun Heo 	struct rb_root polled_files;
53095668a69STejun Heo 
5317a6d3c8bSCsaba Henk 	/** Maximum number of outstanding background requests */
5327a6d3c8bSCsaba Henk 	unsigned max_background;
5337a6d3c8bSCsaba Henk 
5347a6d3c8bSCsaba Henk 	/** Number of background requests at which congestion starts */
5357a6d3c8bSCsaba Henk 	unsigned congestion_threshold;
5367a6d3c8bSCsaba Henk 
53708a53cdcSMiklos Szeredi 	/** Number of requests currently in the background */
53808a53cdcSMiklos Szeredi 	unsigned num_background;
53908a53cdcSMiklos Szeredi 
540d12def1bSMiklos Szeredi 	/** Number of background requests currently queued for userspace */
541d12def1bSMiklos Szeredi 	unsigned active_background;
542d12def1bSMiklos Szeredi 
543d12def1bSMiklos Szeredi 	/** The list of background requests set aside for later queuing */
544d12def1bSMiklos Szeredi 	struct list_head bg_queue;
545d12def1bSMiklos Szeredi 
546ae2dffa3SKirill Tkhai 	/** Protects: max_background, congestion_threshold, num_background,
547ae2dffa3SKirill Tkhai 	 * active_background, bg_queue, blocked */
548ae2dffa3SKirill Tkhai 	spinlock_t bg_lock;
549ae2dffa3SKirill Tkhai 
550796523fbSMaxim Patlasov 	/** Flag indicating that INIT reply has been received. Allocating
551796523fbSMaxim Patlasov 	 * any fuse request will be suspended until the flag is set */
552796523fbSMaxim Patlasov 	int initialized;
553796523fbSMaxim Patlasov 
55408a53cdcSMiklos Szeredi 	/** Flag indicating if connection is blocked.  This will be
55508a53cdcSMiklos Szeredi 	    the case before the INIT reply is received, and if there
55608a53cdcSMiklos Szeredi 	    are too many outstading backgrounds requests */
55708a53cdcSMiklos Szeredi 	int blocked;
55808a53cdcSMiklos Szeredi 
55908a53cdcSMiklos Szeredi 	/** waitq for blocked connection */
56008a53cdcSMiklos Szeredi 	wait_queue_head_t blocked_waitq;
56108a53cdcSMiklos Szeredi 
562de5e3decSMiklos Szeredi 	/** waitq for reserved requests */
563de5e3decSMiklos Szeredi 	wait_queue_head_t reserved_req_waitq;
564de5e3decSMiklos Szeredi 
56569a53bf2SMiklos Szeredi 	/** Connection established, cleared on umount, connection
56669a53bf2SMiklos Szeredi 	    abort and device release */
567095da6cbSMiklos Szeredi 	unsigned connected;
5681e9a4ed9SMiklos Szeredi 
5693b7008b2SSzymon Lukasz 	/** Connection aborted via sysfs */
5703b7008b2SSzymon Lukasz 	bool aborted;
5713b7008b2SSzymon Lukasz 
572095da6cbSMiklos Szeredi 	/** Connection failed (version mismatch).  Cannot race with
573095da6cbSMiklos Szeredi 	    setting other bitfields since it is only set once in INIT
574095da6cbSMiklos Szeredi 	    reply, before any other request, and never cleared */
575334f485dSMiklos Szeredi 	unsigned conn_error:1;
576334f485dSMiklos Szeredi 
5770ec7ca41SMiklos Szeredi 	/** Connection successful.  Only set in INIT */
5780ec7ca41SMiklos Szeredi 	unsigned conn_init:1;
5790ec7ca41SMiklos Szeredi 
5809cd68455SMiklos Szeredi 	/** Do readpages asynchronously?  Only set in INIT */
5819cd68455SMiklos Szeredi 	unsigned async_read:1;
5829cd68455SMiklos Szeredi 
5833b7008b2SSzymon Lukasz 	/** Return an unique read error after abort.  Only set in INIT */
5843b7008b2SSzymon Lukasz 	unsigned abort_err:1;
5853b7008b2SSzymon Lukasz 
5866ff958edSMiklos Szeredi 	/** Do not send separate SETATTR request before open(O_TRUNC)  */
5876ff958edSMiklos Szeredi 	unsigned atomic_o_trunc:1;
5886ff958edSMiklos Szeredi 
58933670fa2SMiklos Szeredi 	/** Filesystem supports NFS exporting.  Only set in INIT */
59033670fa2SMiklos Szeredi 	unsigned export_support:1;
59133670fa2SMiklos Szeredi 
592d5cd66c5SPavel Emelyanov 	/** write-back cache policy (default is write-through) */
593d5cd66c5SPavel Emelyanov 	unsigned writeback_cache:1;
594d5cd66c5SPavel Emelyanov 
5955c672ab3SMiklos Szeredi 	/** allow parallel lookups and readdir (default is serialized) */
5965c672ab3SMiklos Szeredi 	unsigned parallel_dirops:1;
5975c672ab3SMiklos Szeredi 
5985e940c1dSMiklos Szeredi 	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
5995e940c1dSMiklos Szeredi 	unsigned handle_killpriv:1;
6005e940c1dSMiklos Szeredi 
601095da6cbSMiklos Szeredi 	/*
602095da6cbSMiklos Szeredi 	 * The following bitfields are only for optimization purposes
603095da6cbSMiklos Szeredi 	 * and hence races in setting them will not cause malfunction
604095da6cbSMiklos Szeredi 	 */
605095da6cbSMiklos Szeredi 
6067678ac50SAndrew Gallagher 	/** Is open/release not implemented by fs? */
6077678ac50SAndrew Gallagher 	unsigned no_open:1;
6087678ac50SAndrew Gallagher 
609b6aeadedSMiklos Szeredi 	/** Is fsync not implemented by fs? */
610b6aeadedSMiklos Szeredi 	unsigned no_fsync:1;
611b6aeadedSMiklos Szeredi 
61282547981SMiklos Szeredi 	/** Is fsyncdir not implemented by fs? */
61382547981SMiklos Szeredi 	unsigned no_fsyncdir:1;
61482547981SMiklos Szeredi 
615b6aeadedSMiklos Szeredi 	/** Is flush not implemented by fs? */
616b6aeadedSMiklos Szeredi 	unsigned no_flush:1;
617b6aeadedSMiklos Szeredi 
61892a8780eSMiklos Szeredi 	/** Is setxattr not implemented by fs? */
61992a8780eSMiklos Szeredi 	unsigned no_setxattr:1;
62092a8780eSMiklos Szeredi 
62192a8780eSMiklos Szeredi 	/** Is getxattr not implemented by fs? */
62292a8780eSMiklos Szeredi 	unsigned no_getxattr:1;
62392a8780eSMiklos Szeredi 
62492a8780eSMiklos Szeredi 	/** Is listxattr not implemented by fs? */
62592a8780eSMiklos Szeredi 	unsigned no_listxattr:1;
62692a8780eSMiklos Szeredi 
62792a8780eSMiklos Szeredi 	/** Is removexattr not implemented by fs? */
62892a8780eSMiklos Szeredi 	unsigned no_removexattr:1;
62992a8780eSMiklos Szeredi 
63037fb3a30SMiklos Szeredi 	/** Are posix file locking primitives not implemented by fs? */
63171421259SMiklos Szeredi 	unsigned no_lock:1;
63271421259SMiklos Szeredi 
63331d40d74SMiklos Szeredi 	/** Is access not implemented by fs? */
63431d40d74SMiklos Szeredi 	unsigned no_access:1;
63531d40d74SMiklos Szeredi 
636fd72faacSMiklos Szeredi 	/** Is create not implemented by fs? */
637fd72faacSMiklos Szeredi 	unsigned no_create:1;
638fd72faacSMiklos Szeredi 
639a4d27e75SMiklos Szeredi 	/** Is interrupt not implemented by fs? */
640a4d27e75SMiklos Szeredi 	unsigned no_interrupt:1;
641a4d27e75SMiklos Szeredi 
642b2d2272fSMiklos Szeredi 	/** Is bmap not implemented by fs? */
643b2d2272fSMiklos Szeredi 	unsigned no_bmap:1;
644b2d2272fSMiklos Szeredi 
64595668a69STejun Heo 	/** Is poll not implemented by fs? */
64695668a69STejun Heo 	unsigned no_poll:1;
64795668a69STejun Heo 
64878bb6cb9SMiklos Szeredi 	/** Do multi-page cached writes */
64978bb6cb9SMiklos Szeredi 	unsigned big_writes:1;
65078bb6cb9SMiklos Szeredi 
651e0a43ddcSMiklos Szeredi 	/** Don't apply umask to creation modes */
652e0a43ddcSMiklos Szeredi 	unsigned dont_mask:1;
653e0a43ddcSMiklos Szeredi 
65437fb3a30SMiklos Szeredi 	/** Are BSD file locking primitives not implemented by fs? */
65537fb3a30SMiklos Szeredi 	unsigned no_flock:1;
65637fb3a30SMiklos Szeredi 
657519c6040SMiklos Szeredi 	/** Is fallocate not implemented by fs? */
658519c6040SMiklos Szeredi 	unsigned no_fallocate:1;
659519c6040SMiklos Szeredi 
6601560c974SMiklos Szeredi 	/** Is rename with flags implemented by fs? */
6611560c974SMiklos Szeredi 	unsigned no_rename2:1;
6621560c974SMiklos Szeredi 
66372d0d248SBrian Foster 	/** Use enhanced/automatic page cache invalidation. */
66472d0d248SBrian Foster 	unsigned auto_inval_data:1;
66572d0d248SBrian Foster 
666634734b6SEric Wong 	/** Does the filesystem support readdirplus? */
6670b05b183SAnand V. Avati 	unsigned do_readdirplus:1;
6680b05b183SAnand V. Avati 
669634734b6SEric Wong 	/** Does the filesystem want adaptive readdirplus? */
670634734b6SEric Wong 	unsigned readdirplus_auto:1;
671634734b6SEric Wong 
67260b9df7aSMiklos Szeredi 	/** Does the filesystem support asynchronous direct-IO submission? */
67360b9df7aSMiklos Szeredi 	unsigned async_dio:1;
67460b9df7aSMiklos Szeredi 
6750b5da8dbSRavishankar N 	/** Is lseek not implemented by fs? */
6760b5da8dbSRavishankar N 	unsigned no_lseek:1;
6770b5da8dbSRavishankar N 
67860bcc88aSSeth Forshee 	/** Does the filesystem support posix acls? */
67960bcc88aSSeth Forshee 	unsigned posix_acl:1;
68060bcc88aSSeth Forshee 
68129433a29SMiklos Szeredi 	/** Check permissions based on the file mode or not? */
68229433a29SMiklos Szeredi 	unsigned default_permissions:1;
68329433a29SMiklos Szeredi 
68429433a29SMiklos Szeredi 	/** Allow other than the mounter user to access the filesystem ? */
68529433a29SMiklos Szeredi 	unsigned allow_other:1;
68629433a29SMiklos Szeredi 
68788bc7d50SNiels de Vos 	/** Does the filesystem support copy_file_range? */
68888bc7d50SNiels de Vos 	unsigned no_copy_file_range:1;
68988bc7d50SNiels de Vos 
6900cd5b885SMiklos Szeredi 	/** The number of requests waiting for completion */
6910cd5b885SMiklos Szeredi 	atomic_t num_waiting;
6920cd5b885SMiklos Szeredi 
69345714d65SMiklos Szeredi 	/** Negotiated minor version */
69445714d65SMiklos Szeredi 	unsigned minor;
69545714d65SMiklos Szeredi 
696bafa9654SMiklos Szeredi 	/** Entry on the fuse_conn_list */
697bafa9654SMiklos Szeredi 	struct list_head entry;
698bafa9654SMiklos Szeredi 
699b6f2fcbcSMiklos Szeredi 	/** Device ID from super block */
700b6f2fcbcSMiklos Szeredi 	dev_t dev;
701bafa9654SMiklos Szeredi 
702bafa9654SMiklos Szeredi 	/** Dentries in the control filesystem */
703bafa9654SMiklos Szeredi 	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
704bafa9654SMiklos Szeredi 
705bafa9654SMiklos Szeredi 	/** number of dentries used in the above array */
706bafa9654SMiklos Szeredi 	int ctl_ndents;
707385a17bfSJeff Dike 
7089c8ef561SMiklos Szeredi 	/** Key for lock owner ID scrambling */
7099c8ef561SMiklos Szeredi 	u32 scramble_key[4];
7100ec7ca41SMiklos Szeredi 
7110ec7ca41SMiklos Szeredi 	/** Reserved request for the DESTROY message */
7120ec7ca41SMiklos Szeredi 	struct fuse_req *destroy_req;
7131fb69e78SMiklos Szeredi 
7141fb69e78SMiklos Szeredi 	/** Version counter for attribute changes */
7151fb69e78SMiklos Szeredi 	u64 attr_version;
71643901aabSTejun Heo 
71743901aabSTejun Heo 	/** Called on final put */
71843901aabSTejun Heo 	void (*release)(struct fuse_conn *);
7193b463ae0SJohn Muir 
7203b463ae0SJohn Muir 	/** Super block for this connection. */
7213b463ae0SJohn Muir 	struct super_block *sb;
7223b463ae0SJohn Muir 
7233b463ae0SJohn Muir 	/** Read/write semaphore to hold when accessing sb. */
7243b463ae0SJohn Muir 	struct rw_semaphore killsb;
725cc080e9eSMiklos Szeredi 
726cc080e9eSMiklos Szeredi 	/** List of device instances belonging to this connection */
727cc080e9eSMiklos Szeredi 	struct list_head devices;
728d8a5ba45SMiklos Szeredi };
729d8a5ba45SMiklos Szeredi 
730d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
731d8a5ba45SMiklos Szeredi {
7326383bdaaSMiklos Szeredi 	return sb->s_fs_info;
733d8a5ba45SMiklos Szeredi }
734d8a5ba45SMiklos Szeredi 
735d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
736d8a5ba45SMiklos Szeredi {
737d8a5ba45SMiklos Szeredi 	return get_fuse_conn_super(inode->i_sb);
738d8a5ba45SMiklos Szeredi }
739d8a5ba45SMiklos Szeredi 
740d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
741d8a5ba45SMiklos Szeredi {
742d8a5ba45SMiklos Szeredi 	return container_of(inode, struct fuse_inode, inode);
743d8a5ba45SMiklos Szeredi }
744d8a5ba45SMiklos Szeredi 
745d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode)
746d8a5ba45SMiklos Szeredi {
747d8a5ba45SMiklos Szeredi 	return get_fuse_inode(inode)->nodeid;
748d8a5ba45SMiklos Szeredi }
749d8a5ba45SMiklos Szeredi 
750d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid)
751d123d8e1SMiklos Szeredi {
752d123d8e1SMiklos Szeredi 	return !nodeid || nodeid == FUSE_ROOT_ID;
753d123d8e1SMiklos Szeredi }
754d123d8e1SMiklos Szeredi 
755334f485dSMiklos Szeredi /** Device operations */
7564b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations;
757334f485dSMiklos Szeredi 
7584269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations;
7590ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations;
760dbd561d2SMiklos Szeredi 
761d8a5ba45SMiklos Szeredi /**
7623b463ae0SJohn Muir  * Inode to nodeid comparison.
7633b463ae0SJohn Muir  */
7643b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp);
7653b463ae0SJohn Muir 
7663b463ae0SJohn Muir /**
767e5e5558eSMiklos Szeredi  * Get a filled in inode
768e5e5558eSMiklos Szeredi  */
769b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
7701fb69e78SMiklos Szeredi 			int generation, struct fuse_attr *attr,
7711fb69e78SMiklos Szeredi 			u64 attr_valid, u64 attr_version);
772e5e5558eSMiklos Szeredi 
77313983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
77433670fa2SMiklos Szeredi 		     struct fuse_entry_out *outarg, struct inode **inode);
77533670fa2SMiklos Szeredi 
776e5e5558eSMiklos Szeredi /**
777e5e5558eSMiklos Szeredi  * Send FORGET command
778e5e5558eSMiklos Szeredi  */
77907e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
780b48badf0SMiklos Szeredi 		       u64 nodeid, u64 nlookup);
781e5e5558eSMiklos Szeredi 
78207e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void);
78307e77dcaSMiklos Szeredi 
7840b05b183SAnand V. Avati /* Used by READDIRPLUS */
7850b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid);
7860b05b183SAnand V. Avati 
787e5e5558eSMiklos Szeredi /**
788361b1eb5SMiklos Szeredi  * Initialize READ or READDIR request
78904730fefSMiklos Szeredi  */
790a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file,
7912106cb18SMiklos Szeredi 		    loff_t pos, size_t count, int opcode);
79204730fefSMiklos Szeredi 
79304730fefSMiklos Szeredi /**
79404730fefSMiklos Szeredi  * Send OPEN or OPENDIR request
79504730fefSMiklos Szeredi  */
79691fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
79704730fefSMiklos Szeredi 
798acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
799fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff);
800c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file);
801fd72faacSMiklos Szeredi 
8028b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags);
803c756e0a4SMiklos Szeredi 
80404730fefSMiklos Szeredi /**
80504730fefSMiklos Szeredi  * Send RELEASE or RELEASEDIR request
80604730fefSMiklos Szeredi  */
8078b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode);
80804730fefSMiklos Szeredi 
80904730fefSMiklos Szeredi /**
81082547981SMiklos Szeredi  * Send FSYNC or FSYNCDIR request
81182547981SMiklos Szeredi  */
81202c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
81302c24a82SJosef Bacik 		      int datasync, int isdir);
81482547981SMiklos Szeredi 
81582547981SMiklos Szeredi /**
81695668a69STejun Heo  * Notify poll wakeup
81795668a69STejun Heo  */
81895668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc,
81995668a69STejun Heo 			    struct fuse_notify_poll_wakeup_out *outarg);
82095668a69STejun Heo 
82195668a69STejun Heo /**
8221779381dSMiklos Szeredi  * Initialize file operations on a regular file
823b6aeadedSMiklos Szeredi  */
824b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode);
825b6aeadedSMiklos Szeredi 
826b6aeadedSMiklos Szeredi /**
8271779381dSMiklos Szeredi  * Initialize inode operations on regular files and special files
828e5e5558eSMiklos Szeredi  */
829e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode);
830e5e5558eSMiklos Szeredi 
831e5e5558eSMiklos Szeredi /**
8321779381dSMiklos Szeredi  * Initialize inode and file operations on a directory
833e5e5558eSMiklos Szeredi  */
834e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode);
835e5e5558eSMiklos Szeredi 
836e5e5558eSMiklos Szeredi /**
8371779381dSMiklos Szeredi  * Initialize inode operations on a symlink
838e5e5558eSMiklos Szeredi  */
839e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode);
840e5e5558eSMiklos Szeredi 
841e5e5558eSMiklos Szeredi /**
842e5e5558eSMiklos Szeredi  * Change attributes of an inode
843e5e5558eSMiklos Szeredi  */
8441fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
8451fb69e78SMiklos Szeredi 			    u64 attr_valid, u64 attr_version);
846e5e5558eSMiklos Szeredi 
8473be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
8483be5a52bSMiklos Szeredi 				   u64 attr_valid);
8493be5a52bSMiklos Szeredi 
850e5e5558eSMiklos Szeredi /**
851334f485dSMiklos Szeredi  * Initialize the client device
852334f485dSMiklos Szeredi  */
853334f485dSMiklos Szeredi int fuse_dev_init(void);
854334f485dSMiklos Szeredi 
855334f485dSMiklos Szeredi /**
856334f485dSMiklos Szeredi  * Cleanup the client device
857334f485dSMiklos Szeredi  */
858334f485dSMiklos Szeredi void fuse_dev_cleanup(void);
859334f485dSMiklos Szeredi 
860bafa9654SMiklos Szeredi int fuse_ctl_init(void);
8617736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void);
862bafa9654SMiklos Szeredi 
863334f485dSMiklos Szeredi /**
864334f485dSMiklos Szeredi  * Allocate a request
865334f485dSMiklos Szeredi  */
8664250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages);
867334f485dSMiklos Szeredi 
8684250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
8693be5a52bSMiklos Szeredi 
870334f485dSMiklos Szeredi /**
871334f485dSMiklos Szeredi  * Free a request
872334f485dSMiklos Szeredi  */
873334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req);
874334f485dSMiklos Szeredi 
875334f485dSMiklos Szeredi /**
876b111c8c0SMaxim Patlasov  * Get a request, may fail with -ENOMEM,
877b111c8c0SMaxim Patlasov  * caller should specify # elements in req->pages[] explicitly
878334f485dSMiklos Szeredi  */
879b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
8808b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
8818b41e671SMaxim Patlasov 					     unsigned npages);
882b111c8c0SMaxim Patlasov 
88336cf66edSMaxim Patlasov /*
88436cf66edSMaxim Patlasov  * Increment reference count on request
88536cf66edSMaxim Patlasov  */
88636cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req);
88736cf66edSMaxim Patlasov 
888b111c8c0SMaxim Patlasov /**
88933649c91SMiklos Szeredi  * Gets a requests for a file operation, always succeeds
89033649c91SMiklos Szeredi  */
891b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
892b111c8c0SMaxim Patlasov 					     struct file *file);
89333649c91SMiklos Szeredi 
89433649c91SMiklos Szeredi /**
895ce1d5a49SMiklos Szeredi  * Decrement reference count of a request.  If count goes to zero free
896ce1d5a49SMiklos Szeredi  * the request.
897334f485dSMiklos Szeredi  */
898334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
899334f485dSMiklos Szeredi 
900334f485dSMiklos Szeredi /**
9017c352bdfSMiklos Szeredi  * Send a request (synchronous)
902334f485dSMiklos Szeredi  */
903b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
904334f485dSMiklos Szeredi 
905334f485dSMiklos Szeredi /**
9067078187aSMiklos Szeredi  * Simple request sending that does request allocation and freeing
9077078187aSMiklos Szeredi  */
9087078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
9097078187aSMiklos Szeredi 
9107078187aSMiklos Szeredi /**
911334f485dSMiklos Szeredi  * Send a request in the background
912334f485dSMiklos Szeredi  */
913b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
91463825b4eSKirill Tkhai bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
9153be5a52bSMiklos Szeredi 
9165a5fb1eaSMiklos Szeredi /* Abort all requests */
9173b7008b2SSzymon Lukasz void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);
918b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc);
91969a53bf2SMiklos Szeredi 
9201e9a4ed9SMiklos Szeredi /**
921e5e5558eSMiklos Szeredi  * Invalidate inode attributes
922e5e5558eSMiklos Szeredi  */
923e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode);
924bafa9654SMiklos Szeredi 
925dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry);
926dbd561d2SMiklos Szeredi 
927451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode);
928451418fcSAndrew Gallagher 
929d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o);
930d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
931d123d8e1SMiklos Szeredi 
932bafa9654SMiklos Szeredi /**
933bafa9654SMiklos Szeredi  * Acquire reference to fuse_conn
934bafa9654SMiklos Szeredi  */
935bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
936bafa9654SMiklos Szeredi 
937bafa9654SMiklos Szeredi /**
9380d179aa5STejun Heo  * Initialize fuse_conn
9390d179aa5STejun Heo  */
9408cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
9410d179aa5STejun Heo 
9420d179aa5STejun Heo /**
943bafa9654SMiklos Szeredi  * Release reference to fuse_conn
944bafa9654SMiklos Szeredi  */
945bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc);
946bafa9654SMiklos Szeredi 
947cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
948cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud);
949cc080e9eSMiklos Szeredi 
950bafa9654SMiklos Szeredi /**
951bafa9654SMiklos Szeredi  * Add connection to control filesystem
952bafa9654SMiklos Szeredi  */
953bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc);
954bafa9654SMiklos Szeredi 
955bafa9654SMiklos Szeredi /**
956bafa9654SMiklos Szeredi  * Remove connection from control filesystem
957bafa9654SMiklos Szeredi  */
958bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc);
959a5bfffacSTimo Savola 
960a5bfffacSTimo Savola /**
961a5bfffacSTimo Savola  * Is file type valid?
962a5bfffacSTimo Savola  */
963a5bfffacSTimo Savola int fuse_valid_type(int m);
964e57ac683SMiklos Szeredi 
965e57ac683SMiklos Szeredi /**
966c2132c1bSAnatol Pomozov  * Is current process allowed to perform filesystem operation?
967e57ac683SMiklos Szeredi  */
968c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc);
969f3332114SMiklos Szeredi 
970f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
971bcb4be80SMiklos Szeredi 
972703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode);
973703c7362SSeth Forshee 
9745b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file);
9753be5a52bSMiklos Szeredi 
9763be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode);
9773be5a52bSMiklos Szeredi 
9783be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode);
9793be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode);
9805c5c5e51SMiklos Szeredi 
9815c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc);
98229d434b3STejun Heo 
9833b463ae0SJohn Muir /**
9843b463ae0SJohn Muir  * File-system tells the kernel to invalidate cache for the given node id.
9853b463ae0SJohn Muir  */
9863b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
9873b463ae0SJohn Muir 			     loff_t offset, loff_t len);
9883b463ae0SJohn Muir 
9893b463ae0SJohn Muir /**
9903b463ae0SJohn Muir  * File-system tells the kernel to invalidate parent attributes and
9913b463ae0SJohn Muir  * the dentry matching parent/name.
992451d0f59SJohn Muir  *
993451d0f59SJohn Muir  * If the child_nodeid is non-zero and:
994451d0f59SJohn Muir  *    - matches the inode number for the dentry matching parent/name,
995451d0f59SJohn Muir  *    - is not a mount point
996451d0f59SJohn Muir  *    - is a file or oan empty directory
997451d0f59SJohn Muir  * then the dentry is unhashed (d_delete()).
9983b463ae0SJohn Muir  */
9993b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
1000451d0f59SJohn Muir 			     u64 child_nodeid, struct qstr *name);
10013b463ae0SJohn Muir 
100208cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
100308cbf542STejun Heo 		 bool isdir);
1004ea8cd333SPavel Emelyanov 
1005ea8cd333SPavel Emelyanov /**
1006ea8cd333SPavel Emelyanov  * fuse_direct_io() flags
1007ea8cd333SPavel Emelyanov  */
1008ea8cd333SPavel Emelyanov 
1009ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */
1010ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0)
1011ea8cd333SPavel Emelyanov 
1012ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1013ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE  (1 << 1)
1014ea8cd333SPavel Emelyanov 
1015d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1016d22a943fSAl Viro 		       loff_t *ppos, int flags);
101708cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
101808cbf542STejun Heo 		   unsigned int flags);
1019b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd,
1020b18da0c5SMiklos Szeredi 		       unsigned long arg, unsigned int flags);
1021076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait);
102208cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file);
102308cbf542STejun Heo 
1024b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos);
1025b0aa7606SMaxim Patlasov 
1026ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
10271e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1028a1d75f25SMiklos Szeredi 
102962490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1030efb9fa9eSMaxim Patlasov 		    struct file *file);
1031efb9fa9eSMaxim Patlasov 
10329759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc);
10339759bd51SMiklos Szeredi 
103463576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked);
103563576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode);
10365c672ab3SMiklos Szeredi 
103760bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value,
103860bcc88aSSeth Forshee 		  size_t size, int flags);
103960bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
104060bcc88aSSeth Forshee 		      size_t size);
1041703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
104260bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name);
1043703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[];
104460bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1045e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
104660bcc88aSSeth Forshee 
104760bcc88aSSeth Forshee struct posix_acl;
104860bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type);
104960bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
1050703c7362SSeth Forshee 
1051d123d8e1SMiklos Szeredi 
1052d123d8e1SMiklos Szeredi /* readdir.c */
1053d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx);
1054d123d8e1SMiklos Szeredi 
105529d434b3STejun Heo #endif /* _FS_FUSE_I_H */
1056