xref: /openbmc/linux/fs/fuse/fuse_i.h (revision 76e43c8ccaa35c30d5df853013561145a0f750a5)
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 
12f2294482SKirill Smelkov #ifndef pr_fmt
13f2294482SKirill Smelkov # define pr_fmt(fmt) "fuse: " fmt
14f2294482SKirill Smelkov #endif
15f2294482SKirill Smelkov 
16d8a5ba45SMiklos Szeredi #include <linux/fuse.h>
17d8a5ba45SMiklos Szeredi #include <linux/fs.h>
1851eb01e7SMiklos Szeredi #include <linux/mount.h>
19d8a5ba45SMiklos Szeredi #include <linux/wait.h>
20d8a5ba45SMiklos Szeredi #include <linux/list.h>
21d8a5ba45SMiklos Szeredi #include <linux/spinlock.h>
22d8a5ba45SMiklos Szeredi #include <linux/mm.h>
23d8a5ba45SMiklos Szeredi #include <linux/backing-dev.h>
24bafa9654SMiklos Szeredi #include <linux/mutex.h>
253be5a52bSMiklos Szeredi #include <linux/rwsem.h>
2695668a69STejun Heo #include <linux/rbtree.h>
2795668a69STejun Heo #include <linux/poll.h>
285a18ec17SMiklos Szeredi #include <linux/workqueue.h>
29744742d6SSeth Forshee #include <linux/kref.h>
3060bcc88aSSeth Forshee #include <linux/xattr.h>
310b6e9ea0SSeth Forshee #include <linux/pid_namespace.h>
324e8c2eb5SElena Reshetova #include <linux/refcount.h>
338cb08329SEric W. Biederman #include <linux/user_namespace.h>
34d8a5ba45SMiklos Szeredi 
355da784ccSConstantine Shulyupin /** Default max number of pages that can be used in a single read request */
365da784ccSConstantine Shulyupin #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
375da784ccSConstantine Shulyupin 
385da784ccSConstantine Shulyupin /** Maximum of max_pages received in init_out */
395da784ccSConstantine Shulyupin #define FUSE_MAX_MAX_PAGES 256
40334f485dSMiklos Szeredi 
413be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */
423be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN
433be5a52bSMiklos Szeredi 
441d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */
451d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024
461d3d752bSMiklos Szeredi 
47bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */
4879a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5
49bafa9654SMiklos Szeredi 
504250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */
514250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1
524250c066SMaxim Patlasov 
53bafa9654SMiklos Szeredi /** List of active connections */
54bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list;
55bafa9654SMiklos Szeredi 
56bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */
57bafa9654SMiklos Szeredi extern struct mutex fuse_mutex;
58413ef8cbSMiklos Szeredi 
5979a9d994SCsaba Henk /** Module parameters */
6079a9d994SCsaba Henk extern unsigned max_user_bgreq;
6179a9d994SCsaba Henk extern unsigned max_user_congthresh;
6279a9d994SCsaba Henk 
6307e77dcaSMiklos Szeredi /* One forget request */
6407e77dcaSMiklos Szeredi struct fuse_forget_link {
6502c048b9SMiklos Szeredi 	struct fuse_forget_one forget_one;
6607e77dcaSMiklos Szeredi 	struct fuse_forget_link *next;
6707e77dcaSMiklos Szeredi };
6807e77dcaSMiklos Szeredi 
69d8a5ba45SMiklos Szeredi /** FUSE inode */
70d8a5ba45SMiklos Szeredi struct fuse_inode {
71d8a5ba45SMiklos Szeredi 	/** Inode data */
72d8a5ba45SMiklos Szeredi 	struct inode inode;
73d8a5ba45SMiklos Szeredi 
74d8a5ba45SMiklos Szeredi 	/** Unique ID, which identifies the inode between userspace
75d8a5ba45SMiklos Szeredi 	 * and kernel */
76d8a5ba45SMiklos Szeredi 	u64 nodeid;
77d8a5ba45SMiklos Szeredi 
789e6268dbSMiklos Szeredi 	/** Number of lookups on this inode */
799e6268dbSMiklos Szeredi 	u64 nlookup;
809e6268dbSMiklos Szeredi 
81e5e5558eSMiklos Szeredi 	/** The request used for sending the FORGET message */
8207e77dcaSMiklos Szeredi 	struct fuse_forget_link *forget;
83e5e5558eSMiklos Szeredi 
84d8a5ba45SMiklos Szeredi 	/** Time in jiffies until the file attributes are valid */
850a0898cfSMiklos Szeredi 	u64 i_time;
86ebc14c4dSMiklos Szeredi 
872f1e8196SMiklos Szeredi 	/* Which attributes are invalid */
882f1e8196SMiklos Szeredi 	u32 inval_mask;
892f1e8196SMiklos Szeredi 
90ebc14c4dSMiklos Szeredi 	/** The sticky bit in inode->i_mode may have been removed, so
91ebc14c4dSMiklos Szeredi 	    preserve the original mode */
92541af6a0SAl Viro 	umode_t orig_i_mode;
931fb69e78SMiklos Szeredi 
9445c72cd7SPavel Shilovsky 	/** 64 bit inode number */
9545c72cd7SPavel Shilovsky 	u64 orig_ino;
9645c72cd7SPavel Shilovsky 
971fb69e78SMiklos Szeredi 	/** Version of last attribute change */
981fb69e78SMiklos Szeredi 	u64 attr_version;
9993a8c3cdSMiklos Szeredi 
100ab2257e9SMiklos Szeredi 	union {
101ab2257e9SMiklos Szeredi 		/* Write related fields (regular file only) */
102ab2257e9SMiklos Szeredi 		struct {
103f15ecfefSKirill Tkhai 			/* Files usable in writepage.  Protected by fi->lock */
10493a8c3cdSMiklos Szeredi 			struct list_head write_files;
1053be5a52bSMiklos Szeredi 
106ab2257e9SMiklos Szeredi 			/* Writepages pending on truncate or fsync */
1073be5a52bSMiklos Szeredi 			struct list_head queued_writes;
1083be5a52bSMiklos Szeredi 
109ab2257e9SMiklos Szeredi 			/* Number of sent writes, a negative bias
110ab2257e9SMiklos Szeredi 			 * (FUSE_NOWRITE) means more writes are blocked */
1113be5a52bSMiklos Szeredi 			int writectr;
1123be5a52bSMiklos Szeredi 
113ab2257e9SMiklos Szeredi 			/* Waitq for writepage completion */
1143be5a52bSMiklos Szeredi 			wait_queue_head_t page_waitq;
1153be5a52bSMiklos Szeredi 
116ab2257e9SMiklos Szeredi 			/* List of writepage requestst (pending or sent) */
1173be5a52bSMiklos Szeredi 			struct list_head writepages;
118ab2257e9SMiklos Szeredi 		};
1194582a4abSFeng Shuo 
120ab2257e9SMiklos Szeredi 		/* readdir cache (directory only) */
12169e34551SMiklos Szeredi 		struct {
12269e34551SMiklos Szeredi 			/* true if fully cached */
12369e34551SMiklos Szeredi 			bool cached;
12469e34551SMiklos Szeredi 
12569e34551SMiklos Szeredi 			/* size of cache */
12669e34551SMiklos Szeredi 			loff_t size;
12769e34551SMiklos Szeredi 
12869e34551SMiklos Szeredi 			/* position at end of cache (position of next entry) */
12969e34551SMiklos Szeredi 			loff_t pos;
13069e34551SMiklos Szeredi 
1313494927eSMiklos Szeredi 			/* version of the cache */
1323494927eSMiklos Szeredi 			u64 version;
1333494927eSMiklos Szeredi 
134ab2257e9SMiklos Szeredi 			/* modification time of directory when cache was
135ab2257e9SMiklos Szeredi 			 * started */
1367118883bSMiklos Szeredi 			struct timespec64 mtime;
1377118883bSMiklos Szeredi 
138261aaba7SMiklos Szeredi 			/* iversion of directory when cache was started */
139261aaba7SMiklos Szeredi 			u64 iversion;
140261aaba7SMiklos Szeredi 
14169e34551SMiklos Szeredi 			/* protects above fields */
14269e34551SMiklos Szeredi 			spinlock_t lock;
14369e34551SMiklos Szeredi 		} rdc;
144ab2257e9SMiklos Szeredi 	};
14569e34551SMiklos Szeredi 
1464582a4abSFeng Shuo 	/** Miscellaneous bits describing inode state */
1474582a4abSFeng Shuo 	unsigned long state;
1485c672ab3SMiklos Szeredi 
1495c672ab3SMiklos Szeredi 	/** Lock for serializing lookup and readdir for back compatibility*/
1505c672ab3SMiklos Szeredi 	struct mutex mutex;
151f15ecfefSKirill Tkhai 
152f15ecfefSKirill Tkhai 	/** Lock to protect write related fields */
153f15ecfefSKirill Tkhai 	spinlock_t lock;
1544582a4abSFeng Shuo };
1554582a4abSFeng Shuo 
1564582a4abSFeng Shuo /** FUSE inode state bits */
1574582a4abSFeng Shuo enum {
1584582a4abSFeng Shuo 	/** Advise readdirplus  */
1594582a4abSFeng Shuo 	FUSE_I_ADVISE_RDPLUS,
1606314efeeSMiklos Szeredi 	/** Initialized with readdirplus */
1616314efeeSMiklos Szeredi 	FUSE_I_INIT_RDPLUS,
16206a7c3c2SMaxim Patlasov 	/** An operation changing file size is in progress  */
16306a7c3c2SMaxim Patlasov 	FUSE_I_SIZE_UNSTABLE,
164d8a5ba45SMiklos Szeredi };
165d8a5ba45SMiklos Szeredi 
166da5e4714SMiklos Szeredi struct fuse_conn;
167da5e4714SMiklos Szeredi 
168b6aeadedSMiklos Szeredi /** FUSE specific file data */
169b6aeadedSMiklos Szeredi struct fuse_file {
170da5e4714SMiklos Szeredi 	/** Fuse connection for this file */
171da5e4714SMiklos Szeredi 	struct fuse_conn *fc;
172da5e4714SMiklos Szeredi 
1736b675738SKirill Tkhai 	/*
1746b675738SKirill Tkhai 	 * Request reserved for flush and release.
1756b675738SKirill Tkhai 	 * Modified under relative fuse_inode::lock.
1766b675738SKirill Tkhai 	 */
17733649c91SMiklos Szeredi 	struct fuse_req *reserved_req;
178b6aeadedSMiklos Szeredi 
179acf99433STejun Heo 	/** Kernel file handle guaranteed to be unique */
180acf99433STejun Heo 	u64 kh;
181acf99433STejun Heo 
182b6aeadedSMiklos Szeredi 	/** File handle used by userspace */
183b6aeadedSMiklos Szeredi 	u64 fh;
184c756e0a4SMiklos Szeredi 
185da5e4714SMiklos Szeredi 	/** Node id of this file */
186da5e4714SMiklos Szeredi 	u64 nodeid;
187da5e4714SMiklos Szeredi 
188c756e0a4SMiklos Szeredi 	/** Refcount */
1894e8c2eb5SElena Reshetova 	refcount_t count;
19093a8c3cdSMiklos Szeredi 
191c7b7143cSMiklos Szeredi 	/** FOPEN_* flags returned by open */
192c7b7143cSMiklos Szeredi 	u32 open_flags;
193c7b7143cSMiklos Szeredi 
19493a8c3cdSMiklos Szeredi 	/** Entry on inode's write_files list */
19593a8c3cdSMiklos Szeredi 	struct list_head write_entry;
19695668a69STejun Heo 
1975d7bc7e8SMiklos Szeredi 	/* Readdir related */
1985d7bc7e8SMiklos Szeredi 	struct {
1995d7bc7e8SMiklos Szeredi 		/*
2005d7bc7e8SMiklos Szeredi 		 * Protects below fields against (crazy) parallel readdir on
2015d7bc7e8SMiklos Szeredi 		 * same open file.  Uncontended in the normal case.
2025d7bc7e8SMiklos Szeredi 		 */
2035d7bc7e8SMiklos Szeredi 		struct mutex lock;
2045d7bc7e8SMiklos Szeredi 
2055d7bc7e8SMiklos Szeredi 		/* Dir stream position */
2065d7bc7e8SMiklos Szeredi 		loff_t pos;
2075d7bc7e8SMiklos Szeredi 
2085d7bc7e8SMiklos Szeredi 		/* Offset in cache */
2095d7bc7e8SMiklos Szeredi 		loff_t cache_off;
2103494927eSMiklos Szeredi 
2113494927eSMiklos Szeredi 		/* Version of cache we are reading */
2123494927eSMiklos Szeredi 		u64 version;
2133494927eSMiklos Szeredi 
2145d7bc7e8SMiklos Szeredi 	} readdir;
2155d7bc7e8SMiklos Szeredi 
21695668a69STejun Heo 	/** RB node to be linked on fuse_conn->polled_files */
21795668a69STejun Heo 	struct rb_node polled_node;
21895668a69STejun Heo 
21995668a69STejun Heo 	/** Wait queue head for poll */
22095668a69STejun Heo 	wait_queue_head_t poll_wait;
22137fb3a30SMiklos Szeredi 
22237fb3a30SMiklos Szeredi 	/** Has flock been performed on this file? */
22337fb3a30SMiklos Szeredi 	bool flock:1;
224b6aeadedSMiklos Szeredi };
225b6aeadedSMiklos Szeredi 
226334f485dSMiklos Szeredi /** One input argument of a request */
227334f485dSMiklos Szeredi struct fuse_in_arg {
228334f485dSMiklos Szeredi 	unsigned size;
229334f485dSMiklos Szeredi 	const void *value;
230334f485dSMiklos Szeredi };
231334f485dSMiklos Szeredi 
232334f485dSMiklos Szeredi /** The request input */
233334f485dSMiklos Szeredi struct fuse_in {
234334f485dSMiklos Szeredi 	/** The request header */
235334f485dSMiklos Szeredi 	struct fuse_in_header h;
236334f485dSMiklos Szeredi 
237334f485dSMiklos Szeredi 	/** True if the data for the last argument is in req->pages */
238334f485dSMiklos Szeredi 	unsigned argpages:1;
239334f485dSMiklos Szeredi 
240334f485dSMiklos Szeredi 	/** Number of arguments */
241334f485dSMiklos Szeredi 	unsigned numargs;
242334f485dSMiklos Szeredi 
243334f485dSMiklos Szeredi 	/** Array of arguments */
244334f485dSMiklos Szeredi 	struct fuse_in_arg args[3];
245334f485dSMiklos Szeredi };
246334f485dSMiklos Szeredi 
247334f485dSMiklos Szeredi /** One output argument of a request */
248334f485dSMiklos Szeredi struct fuse_arg {
249334f485dSMiklos Szeredi 	unsigned size;
250334f485dSMiklos Szeredi 	void *value;
251334f485dSMiklos Szeredi };
252334f485dSMiklos Szeredi 
253334f485dSMiklos Szeredi /** The request output */
254334f485dSMiklos Szeredi struct fuse_out {
255334f485dSMiklos Szeredi 	/** Header returned from userspace */
256334f485dSMiklos Szeredi 	struct fuse_out_header h;
257334f485dSMiklos Szeredi 
258095da6cbSMiklos Szeredi 	/*
259095da6cbSMiklos Szeredi 	 * The following bitfields are not changed during the request
260095da6cbSMiklos Szeredi 	 * processing
261095da6cbSMiklos Szeredi 	 */
262095da6cbSMiklos Szeredi 
263334f485dSMiklos Szeredi 	/** Last argument is variable length (can be shorter than
264334f485dSMiklos Szeredi 	    arg->size) */
265334f485dSMiklos Szeredi 	unsigned argvar:1;
266334f485dSMiklos Szeredi 
267334f485dSMiklos Szeredi 	/** Last argument is a list of pages to copy data to */
268334f485dSMiklos Szeredi 	unsigned argpages:1;
269334f485dSMiklos Szeredi 
270334f485dSMiklos Szeredi 	/** Zero partially or not copied pages */
271334f485dSMiklos Szeredi 	unsigned page_zeroing:1;
272334f485dSMiklos Szeredi 
273ce534fb0SMiklos Szeredi 	/** Pages may be replaced with new ones */
274ce534fb0SMiklos Szeredi 	unsigned page_replace:1;
275ce534fb0SMiklos Szeredi 
276334f485dSMiklos Szeredi 	/** Number or arguments */
277334f485dSMiklos Szeredi 	unsigned numargs;
278334f485dSMiklos Szeredi 
279334f485dSMiklos Szeredi 	/** Array of arguments */
280f704dcb5SMiklos Szeredi 	struct fuse_arg args[2];
281334f485dSMiklos Szeredi };
282334f485dSMiklos Szeredi 
283b2430d75SMaxim Patlasov /** FUSE page descriptor */
284b2430d75SMaxim Patlasov struct fuse_page_desc {
285b2430d75SMaxim Patlasov 	unsigned int length;
286b2430d75SMaxim Patlasov 	unsigned int offset;
287b2430d75SMaxim Patlasov };
288b2430d75SMaxim Patlasov 
2897078187aSMiklos Szeredi struct fuse_args {
2907078187aSMiklos Szeredi 	struct {
2917078187aSMiklos Szeredi 		struct {
2927078187aSMiklos Szeredi 			uint32_t opcode;
2937078187aSMiklos Szeredi 			uint64_t nodeid;
2947078187aSMiklos Szeredi 		} h;
2957078187aSMiklos Szeredi 		unsigned numargs;
2967078187aSMiklos Szeredi 		struct fuse_in_arg args[3];
2977078187aSMiklos Szeredi 
2987078187aSMiklos Szeredi 	} in;
2997078187aSMiklos Szeredi 	struct {
3007078187aSMiklos Szeredi 		unsigned argvar:1;
3017078187aSMiklos Szeredi 		unsigned numargs;
3027078187aSMiklos Szeredi 		struct fuse_arg args[2];
3037078187aSMiklos Szeredi 	} out;
3047078187aSMiklos Szeredi };
3057078187aSMiklos Szeredi 
3067078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {}
3077078187aSMiklos Szeredi 
30801e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */
30901e9d11aSMaxim Patlasov struct fuse_io_priv {
310744742d6SSeth Forshee 	struct kref refcnt;
31101e9d11aSMaxim Patlasov 	int async;
31201e9d11aSMaxim Patlasov 	spinlock_t lock;
31301e9d11aSMaxim Patlasov 	unsigned reqs;
31401e9d11aSMaxim Patlasov 	ssize_t bytes;
31501e9d11aSMaxim Patlasov 	size_t size;
31601e9d11aSMaxim Patlasov 	__u64 offset;
31701e9d11aSMaxim Patlasov 	bool write;
31861c12b49SAshish Samant 	bool should_dirty;
31901e9d11aSMaxim Patlasov 	int err;
32001e9d11aSMaxim Patlasov 	struct kiocb *iocb;
3219d5722b7SChristoph Hellwig 	struct completion *done;
3227879c4e5SAshish Sangwan 	bool blocking;
32301e9d11aSMaxim Patlasov };
32401e9d11aSMaxim Patlasov 
325e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \
326744742d6SSeth Forshee {					\
3271e24edcaSPeter Zijlstra 	.refcnt = KREF_INIT(1),		\
328744742d6SSeth Forshee 	.async = 0,			\
329e1c0eecbSMiklos Szeredi 	.iocb = i,			\
330744742d6SSeth Forshee }
331744742d6SSeth Forshee 
332334f485dSMiklos Szeredi /**
333825d6d33SMiklos Szeredi  * Request flags
334825d6d33SMiklos Szeredi  *
335825d6d33SMiklos Szeredi  * FR_ISREPLY:		set if the request has reply
336825d6d33SMiklos Szeredi  * FR_FORCE:		force sending of the request even if interrupted
337825d6d33SMiklos Szeredi  * FR_BACKGROUND:	request is sent in the background
338825d6d33SMiklos Szeredi  * FR_WAITING:		request is counted as "waiting"
339825d6d33SMiklos Szeredi  * FR_ABORTED:		the request was aborted
340825d6d33SMiklos Szeredi  * FR_INTERRUPTED:	the request has been interrupted
341825d6d33SMiklos Szeredi  * FR_LOCKED:		data is being copied to/from the request
34233e14b4dSMiklos Szeredi  * FR_PENDING:		request is not yet in userspace
34333e14b4dSMiklos Szeredi  * FR_SENT:		request is in userspace, waiting for an answer
34433e14b4dSMiklos Szeredi  * FR_FINISHED:		request is finished
34577cd9d48SMiklos Szeredi  * FR_PRIVATE:		request is on private list
346825d6d33SMiklos Szeredi  */
347825d6d33SMiklos Szeredi enum fuse_req_flag {
348825d6d33SMiklos Szeredi 	FR_ISREPLY,
349825d6d33SMiklos Szeredi 	FR_FORCE,
350825d6d33SMiklos Szeredi 	FR_BACKGROUND,
351825d6d33SMiklos Szeredi 	FR_WAITING,
352825d6d33SMiklos Szeredi 	FR_ABORTED,
353825d6d33SMiklos Szeredi 	FR_INTERRUPTED,
354825d6d33SMiklos Szeredi 	FR_LOCKED,
35533e14b4dSMiklos Szeredi 	FR_PENDING,
35633e14b4dSMiklos Szeredi 	FR_SENT,
35733e14b4dSMiklos Szeredi 	FR_FINISHED,
35877cd9d48SMiklos Szeredi 	FR_PRIVATE,
359825d6d33SMiklos Szeredi };
360825d6d33SMiklos Szeredi 
361825d6d33SMiklos Szeredi /**
362334f485dSMiklos Szeredi  * A request to the client
363dc00809aSMiklos Szeredi  *
364dc00809aSMiklos Szeredi  * .waitq.lock protects the following fields:
365dc00809aSMiklos Szeredi  *   - FR_ABORTED
366dc00809aSMiklos Szeredi  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
367334f485dSMiklos Szeredi  */
368334f485dSMiklos Szeredi struct fuse_req {
369ce1d5a49SMiklos Szeredi 	/** This can be on either pending processing or io lists in
370ce1d5a49SMiklos Szeredi 	    fuse_conn */
371334f485dSMiklos Szeredi 	struct list_head list;
372334f485dSMiklos Szeredi 
373a4d27e75SMiklos Szeredi 	/** Entry on the interrupts list  */
374a4d27e75SMiklos Szeredi 	struct list_head intr_entry;
375a4d27e75SMiklos Szeredi 
376334f485dSMiklos Szeredi 	/** refcount */
377ec99f6d3SElena Reshetova 	refcount_t count;
378334f485dSMiklos Szeredi 
379825d6d33SMiklos Szeredi 	/* Request flags, updated with test/set/clear_bit() */
380825d6d33SMiklos Szeredi 	unsigned long flags;
3819bc5dddaSMiklos Szeredi 
382334f485dSMiklos Szeredi 	/** The request input */
383334f485dSMiklos Szeredi 	struct fuse_in in;
384334f485dSMiklos Szeredi 
385334f485dSMiklos Szeredi 	/** The request output */
386334f485dSMiklos Szeredi 	struct fuse_out out;
387334f485dSMiklos Szeredi 
388334f485dSMiklos Szeredi 	/** Used to wake up the task waiting for completion of request*/
389334f485dSMiklos Szeredi 	wait_queue_head_t waitq;
390334f485dSMiklos Szeredi 
391334f485dSMiklos Szeredi 	/** Data for asynchronous requests */
392334f485dSMiklos Szeredi 	union {
393b57d4264SMiklos Szeredi 		struct {
394b57d4264SMiklos Szeredi 			struct fuse_release_in in;
395baebccbeSMiklos Szeredi 			struct inode *inode;
396b57d4264SMiklos Szeredi 		} release;
3973ec870d5SMiklos Szeredi 		struct fuse_init_in init_in;
3983ec870d5SMiklos Szeredi 		struct fuse_init_out init_out;
39908cbf542STejun Heo 		struct cuse_init_in cuse_init_in;
4005c5c5e51SMiklos Szeredi 		struct {
4015c5c5e51SMiklos Szeredi 			struct fuse_read_in in;
4025c5c5e51SMiklos Szeredi 			u64 attr_ver;
4035c5c5e51SMiklos Szeredi 		} read;
404b25e82e5SMiklos Szeredi 		struct {
405b25e82e5SMiklos Szeredi 			struct fuse_write_in in;
406b25e82e5SMiklos Szeredi 			struct fuse_write_out out;
4078b284dc4SMiklos Szeredi 			struct fuse_req *next;
408b25e82e5SMiklos Szeredi 		} write;
4092d45ba38SMiklos Szeredi 		struct fuse_notify_retrieve_in retrieve_in;
410334f485dSMiklos Szeredi 	} misc;
411334f485dSMiklos Szeredi 
412334f485dSMiklos Szeredi 	/** page vector */
4134250c066SMaxim Patlasov 	struct page **pages;
4144250c066SMaxim Patlasov 
415b2430d75SMaxim Patlasov 	/** page-descriptor vector */
416b2430d75SMaxim Patlasov 	struct fuse_page_desc *page_descs;
417b2430d75SMaxim Patlasov 
4184250c066SMaxim Patlasov 	/** size of the 'pages' array */
4194250c066SMaxim Patlasov 	unsigned max_pages;
4204250c066SMaxim Patlasov 
4214250c066SMaxim Patlasov 	/** inline page vector */
4224250c066SMaxim Patlasov 	struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
423334f485dSMiklos Szeredi 
424b2430d75SMaxim Patlasov 	/** inline page-descriptor vector */
425b2430d75SMaxim Patlasov 	struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
426b2430d75SMaxim Patlasov 
427334f485dSMiklos Szeredi 	/** number of pages in vector */
428334f485dSMiklos Szeredi 	unsigned num_pages;
429334f485dSMiklos Szeredi 
430334f485dSMiklos Szeredi 	/** File used in the request (or NULL) */
431c756e0a4SMiklos Szeredi 	struct fuse_file *ff;
43264c6d8edSMiklos Szeredi 
4333be5a52bSMiklos Szeredi 	/** Inode used in the request or NULL */
4343be5a52bSMiklos Szeredi 	struct inode *inode;
4353be5a52bSMiklos Szeredi 
43601e9d11aSMaxim Patlasov 	/** AIO control block */
43701e9d11aSMaxim Patlasov 	struct fuse_io_priv *io;
43801e9d11aSMaxim Patlasov 
4393be5a52bSMiklos Szeredi 	/** Link on fi->writepages */
4403be5a52bSMiklos Szeredi 	struct list_head writepages_entry;
4413be5a52bSMiklos Szeredi 
44264c6d8edSMiklos Szeredi 	/** Request completion callback */
44364c6d8edSMiklos Szeredi 	void (*end)(struct fuse_conn *, struct fuse_req *);
44433649c91SMiklos Szeredi 
44533649c91SMiklos Szeredi 	/** Request is stolen from fuse_file->reserved_req */
44633649c91SMiklos Szeredi 	struct file *stolen_file;
447334f485dSMiklos Szeredi };
448334f485dSMiklos Szeredi 
449f88996a9SMiklos Szeredi struct fuse_iqueue {
450e16714d8SMiklos Szeredi 	/** Connection established */
451e16714d8SMiklos Szeredi 	unsigned connected;
452e16714d8SMiklos Szeredi 
453*76e43c8cSEric Biggers 	/** Lock protecting accesses to members of this structure */
454*76e43c8cSEric Biggers 	spinlock_t lock;
455*76e43c8cSEric Biggers 
456f88996a9SMiklos Szeredi 	/** Readers of the connection are waiting on this */
457f88996a9SMiklos Szeredi 	wait_queue_head_t waitq;
458f88996a9SMiklos Szeredi 
459f88996a9SMiklos Szeredi 	/** The next unique request id */
460f88996a9SMiklos Szeredi 	u64 reqctr;
461f88996a9SMiklos Szeredi 
462f88996a9SMiklos Szeredi 	/** The list of pending requests */
463f88996a9SMiklos Szeredi 	struct list_head pending;
464f88996a9SMiklos Szeredi 
465f88996a9SMiklos Szeredi 	/** Pending interrupts */
466f88996a9SMiklos Szeredi 	struct list_head interrupts;
467f88996a9SMiklos Szeredi 
468f88996a9SMiklos Szeredi 	/** Queue of pending forgets */
469f88996a9SMiklos Szeredi 	struct fuse_forget_link forget_list_head;
470f88996a9SMiklos Szeredi 	struct fuse_forget_link *forget_list_tail;
471f88996a9SMiklos Szeredi 
472f88996a9SMiklos Szeredi 	/** Batching of FORGET requests (positive indicates FORGET batch) */
473f88996a9SMiklos Szeredi 	int forget_batch;
474f88996a9SMiklos Szeredi 
475f88996a9SMiklos Szeredi 	/** O_ASYNC requests */
476f88996a9SMiklos Szeredi 	struct fasync_struct *fasync;
477f88996a9SMiklos Szeredi };
478f88996a9SMiklos Szeredi 
479be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8
480be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
481be2ff42cSKirill Tkhai 
4823a2b5b9cSMiklos Szeredi struct fuse_pqueue {
483e96edd94SMiklos Szeredi 	/** Connection established */
484e96edd94SMiklos Szeredi 	unsigned connected;
485e96edd94SMiklos Szeredi 
48645a91cb1SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
48745a91cb1SMiklos Szeredi 	spinlock_t lock;
48845a91cb1SMiklos Szeredi 
489be2ff42cSKirill Tkhai 	/** Hash table of requests being processed */
490be2ff42cSKirill Tkhai 	struct list_head *processing;
4913a2b5b9cSMiklos Szeredi 
4923a2b5b9cSMiklos Szeredi 	/** The list of requests under I/O */
4933a2b5b9cSMiklos Szeredi 	struct list_head io;
4943a2b5b9cSMiklos Szeredi };
4953a2b5b9cSMiklos Szeredi 
496d8a5ba45SMiklos Szeredi /**
497cc080e9eSMiklos Szeredi  * Fuse device instance
498cc080e9eSMiklos Szeredi  */
499cc080e9eSMiklos Szeredi struct fuse_dev {
500cc080e9eSMiklos Szeredi 	/** Fuse connection for this device */
501cc080e9eSMiklos Szeredi 	struct fuse_conn *fc;
502cc080e9eSMiklos Szeredi 
503c3696046SMiklos Szeredi 	/** Processing queue */
504c3696046SMiklos Szeredi 	struct fuse_pqueue pq;
505c3696046SMiklos Szeredi 
506cc080e9eSMiklos Szeredi 	/** list entry on fc->devices */
507cc080e9eSMiklos Szeredi 	struct list_head entry;
508cc080e9eSMiklos Szeredi };
509cc080e9eSMiklos Szeredi 
510cc080e9eSMiklos Szeredi /**
511d8a5ba45SMiklos Szeredi  * A Fuse connection.
512d8a5ba45SMiklos Szeredi  *
513d8a5ba45SMiklos Szeredi  * This structure is created, when the filesystem is mounted, and is
514d8a5ba45SMiklos Szeredi  * destroyed, when the client device is closed and the filesystem is
515d8a5ba45SMiklos Szeredi  * unmounted.
516d8a5ba45SMiklos Szeredi  */
517d8a5ba45SMiklos Szeredi struct fuse_conn {
518d7133114SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
519d7133114SMiklos Szeredi 	spinlock_t lock;
520d7133114SMiklos Szeredi 
521bafa9654SMiklos Szeredi 	/** Refcount */
522095fc40aSElena Reshetova 	refcount_t count;
523bafa9654SMiklos Szeredi 
524c3696046SMiklos Szeredi 	/** Number of fuse_dev's */
525c3696046SMiklos Szeredi 	atomic_t dev_count;
526c3696046SMiklos Szeredi 
527dd3e2c55SAl Viro 	struct rcu_head rcu;
528dd3e2c55SAl Viro 
529d8a5ba45SMiklos Szeredi 	/** The user id for this mount */
530499dcf20SEric W. Biederman 	kuid_t user_id;
531d8a5ba45SMiklos Szeredi 
53287729a55SMiklos Szeredi 	/** The group id for this mount */
533499dcf20SEric W. Biederman 	kgid_t group_id;
53487729a55SMiklos Szeredi 
5350b6e9ea0SSeth Forshee 	/** The pid namespace for this mount */
5360b6e9ea0SSeth Forshee 	struct pid_namespace *pid_ns;
5370b6e9ea0SSeth Forshee 
5388cb08329SEric W. Biederman 	/** The user namespace for this mount */
5398cb08329SEric W. Biederman 	struct user_namespace *user_ns;
5408cb08329SEric W. Biederman 
541db50b96cSMiklos Szeredi 	/** Maximum read size */
542db50b96cSMiklos Szeredi 	unsigned max_read;
543db50b96cSMiklos Szeredi 
544413ef8cbSMiklos Szeredi 	/** Maximum write size */
545413ef8cbSMiklos Szeredi 	unsigned max_write;
546413ef8cbSMiklos Szeredi 
5475da784ccSConstantine Shulyupin 	/** Maxmum number of pages that can be used in a single request */
5485da784ccSConstantine Shulyupin 	unsigned int max_pages;
5495da784ccSConstantine Shulyupin 
550f88996a9SMiklos Szeredi 	/** Input queue */
551f88996a9SMiklos Szeredi 	struct fuse_iqueue iq;
552334f485dSMiklos Szeredi 
553acf99433STejun Heo 	/** The next unique kernel file handle */
55475126f55SMiklos Szeredi 	atomic64_t khctr;
555acf99433STejun Heo 
55695668a69STejun Heo 	/** rbtree of fuse_files waiting for poll events indexed by ph */
55795668a69STejun Heo 	struct rb_root polled_files;
55895668a69STejun Heo 
5597a6d3c8bSCsaba Henk 	/** Maximum number of outstanding background requests */
5607a6d3c8bSCsaba Henk 	unsigned max_background;
5617a6d3c8bSCsaba Henk 
5627a6d3c8bSCsaba Henk 	/** Number of background requests at which congestion starts */
5637a6d3c8bSCsaba Henk 	unsigned congestion_threshold;
5647a6d3c8bSCsaba Henk 
56508a53cdcSMiklos Szeredi 	/** Number of requests currently in the background */
56608a53cdcSMiklos Szeredi 	unsigned num_background;
56708a53cdcSMiklos Szeredi 
568d12def1bSMiklos Szeredi 	/** Number of background requests currently queued for userspace */
569d12def1bSMiklos Szeredi 	unsigned active_background;
570d12def1bSMiklos Szeredi 
571d12def1bSMiklos Szeredi 	/** The list of background requests set aside for later queuing */
572d12def1bSMiklos Szeredi 	struct list_head bg_queue;
573d12def1bSMiklos Szeredi 
574ae2dffa3SKirill Tkhai 	/** Protects: max_background, congestion_threshold, num_background,
575ae2dffa3SKirill Tkhai 	 * active_background, bg_queue, blocked */
576ae2dffa3SKirill Tkhai 	spinlock_t bg_lock;
577ae2dffa3SKirill Tkhai 
578796523fbSMaxim Patlasov 	/** Flag indicating that INIT reply has been received. Allocating
579796523fbSMaxim Patlasov 	 * any fuse request will be suspended until the flag is set */
580796523fbSMaxim Patlasov 	int initialized;
581796523fbSMaxim Patlasov 
58208a53cdcSMiklos Szeredi 	/** Flag indicating if connection is blocked.  This will be
58308a53cdcSMiklos Szeredi 	    the case before the INIT reply is received, and if there
58408a53cdcSMiklos Szeredi 	    are too many outstading backgrounds requests */
58508a53cdcSMiklos Szeredi 	int blocked;
58608a53cdcSMiklos Szeredi 
58708a53cdcSMiklos Szeredi 	/** waitq for blocked connection */
58808a53cdcSMiklos Szeredi 	wait_queue_head_t blocked_waitq;
58908a53cdcSMiklos Szeredi 
590de5e3decSMiklos Szeredi 	/** waitq for reserved requests */
591de5e3decSMiklos Szeredi 	wait_queue_head_t reserved_req_waitq;
592de5e3decSMiklos Szeredi 
59369a53bf2SMiklos Szeredi 	/** Connection established, cleared on umount, connection
59469a53bf2SMiklos Szeredi 	    abort and device release */
595095da6cbSMiklos Szeredi 	unsigned connected;
5961e9a4ed9SMiklos Szeredi 
5973b7008b2SSzymon Lukasz 	/** Connection aborted via sysfs */
5983b7008b2SSzymon Lukasz 	bool aborted;
5993b7008b2SSzymon Lukasz 
600095da6cbSMiklos Szeredi 	/** Connection failed (version mismatch).  Cannot race with
601095da6cbSMiklos Szeredi 	    setting other bitfields since it is only set once in INIT
602095da6cbSMiklos Szeredi 	    reply, before any other request, and never cleared */
603334f485dSMiklos Szeredi 	unsigned conn_error:1;
604334f485dSMiklos Szeredi 
6050ec7ca41SMiklos Szeredi 	/** Connection successful.  Only set in INIT */
6060ec7ca41SMiklos Szeredi 	unsigned conn_init:1;
6070ec7ca41SMiklos Szeredi 
6089cd68455SMiklos Szeredi 	/** Do readpages asynchronously?  Only set in INIT */
6099cd68455SMiklos Szeredi 	unsigned async_read:1;
6109cd68455SMiklos Szeredi 
6113b7008b2SSzymon Lukasz 	/** Return an unique read error after abort.  Only set in INIT */
6123b7008b2SSzymon Lukasz 	unsigned abort_err:1;
6133b7008b2SSzymon Lukasz 
6146ff958edSMiklos Szeredi 	/** Do not send separate SETATTR request before open(O_TRUNC)  */
6156ff958edSMiklos Szeredi 	unsigned atomic_o_trunc:1;
6166ff958edSMiklos Szeredi 
61733670fa2SMiklos Szeredi 	/** Filesystem supports NFS exporting.  Only set in INIT */
61833670fa2SMiklos Szeredi 	unsigned export_support:1;
61933670fa2SMiklos Szeredi 
620d5cd66c5SPavel Emelyanov 	/** write-back cache policy (default is write-through) */
621d5cd66c5SPavel Emelyanov 	unsigned writeback_cache:1;
622d5cd66c5SPavel Emelyanov 
6235c672ab3SMiklos Szeredi 	/** allow parallel lookups and readdir (default is serialized) */
6245c672ab3SMiklos Szeredi 	unsigned parallel_dirops:1;
6255c672ab3SMiklos Szeredi 
6265e940c1dSMiklos Szeredi 	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
6275e940c1dSMiklos Szeredi 	unsigned handle_killpriv:1;
6285e940c1dSMiklos Szeredi 
6295571f1e6SDan Schatzberg 	/** cache READLINK responses in page cache */
6305571f1e6SDan Schatzberg 	unsigned cache_symlinks:1;
6315571f1e6SDan Schatzberg 
632095da6cbSMiklos Szeredi 	/*
633095da6cbSMiklos Szeredi 	 * The following bitfields are only for optimization purposes
634095da6cbSMiklos Szeredi 	 * and hence races in setting them will not cause malfunction
635095da6cbSMiklos Szeredi 	 */
636095da6cbSMiklos Szeredi 
6377678ac50SAndrew Gallagher 	/** Is open/release not implemented by fs? */
6387678ac50SAndrew Gallagher 	unsigned no_open:1;
6397678ac50SAndrew Gallagher 
640d9a9ea94SChad Austin 	/** Is opendir/releasedir not implemented by fs? */
641d9a9ea94SChad Austin 	unsigned no_opendir:1;
642d9a9ea94SChad Austin 
643b6aeadedSMiklos Szeredi 	/** Is fsync not implemented by fs? */
644b6aeadedSMiklos Szeredi 	unsigned no_fsync:1;
645b6aeadedSMiklos Szeredi 
64682547981SMiklos Szeredi 	/** Is fsyncdir not implemented by fs? */
64782547981SMiklos Szeredi 	unsigned no_fsyncdir:1;
64882547981SMiklos Szeredi 
649b6aeadedSMiklos Szeredi 	/** Is flush not implemented by fs? */
650b6aeadedSMiklos Szeredi 	unsigned no_flush:1;
651b6aeadedSMiklos Szeredi 
65292a8780eSMiklos Szeredi 	/** Is setxattr not implemented by fs? */
65392a8780eSMiklos Szeredi 	unsigned no_setxattr:1;
65492a8780eSMiklos Szeredi 
65592a8780eSMiklos Szeredi 	/** Is getxattr not implemented by fs? */
65692a8780eSMiklos Szeredi 	unsigned no_getxattr:1;
65792a8780eSMiklos Szeredi 
65892a8780eSMiklos Szeredi 	/** Is listxattr not implemented by fs? */
65992a8780eSMiklos Szeredi 	unsigned no_listxattr:1;
66092a8780eSMiklos Szeredi 
66192a8780eSMiklos Szeredi 	/** Is removexattr not implemented by fs? */
66292a8780eSMiklos Szeredi 	unsigned no_removexattr:1;
66392a8780eSMiklos Szeredi 
66437fb3a30SMiklos Szeredi 	/** Are posix file locking primitives not implemented by fs? */
66571421259SMiklos Szeredi 	unsigned no_lock:1;
66671421259SMiklos Szeredi 
66731d40d74SMiklos Szeredi 	/** Is access not implemented by fs? */
66831d40d74SMiklos Szeredi 	unsigned no_access:1;
66931d40d74SMiklos Szeredi 
670fd72faacSMiklos Szeredi 	/** Is create not implemented by fs? */
671fd72faacSMiklos Szeredi 	unsigned no_create:1;
672fd72faacSMiklos Szeredi 
673a4d27e75SMiklos Szeredi 	/** Is interrupt not implemented by fs? */
674a4d27e75SMiklos Szeredi 	unsigned no_interrupt:1;
675a4d27e75SMiklos Szeredi 
676b2d2272fSMiklos Szeredi 	/** Is bmap not implemented by fs? */
677b2d2272fSMiklos Szeredi 	unsigned no_bmap:1;
678b2d2272fSMiklos Szeredi 
67995668a69STejun Heo 	/** Is poll not implemented by fs? */
68095668a69STejun Heo 	unsigned no_poll:1;
68195668a69STejun Heo 
68278bb6cb9SMiklos Szeredi 	/** Do multi-page cached writes */
68378bb6cb9SMiklos Szeredi 	unsigned big_writes:1;
68478bb6cb9SMiklos Szeredi 
685e0a43ddcSMiklos Szeredi 	/** Don't apply umask to creation modes */
686e0a43ddcSMiklos Szeredi 	unsigned dont_mask:1;
687e0a43ddcSMiklos Szeredi 
68837fb3a30SMiklos Szeredi 	/** Are BSD file locking primitives not implemented by fs? */
68937fb3a30SMiklos Szeredi 	unsigned no_flock:1;
69037fb3a30SMiklos Szeredi 
691519c6040SMiklos Szeredi 	/** Is fallocate not implemented by fs? */
692519c6040SMiklos Szeredi 	unsigned no_fallocate:1;
693519c6040SMiklos Szeredi 
6941560c974SMiklos Szeredi 	/** Is rename with flags implemented by fs? */
6951560c974SMiklos Szeredi 	unsigned no_rename2:1;
6961560c974SMiklos Szeredi 
69772d0d248SBrian Foster 	/** Use enhanced/automatic page cache invalidation. */
69872d0d248SBrian Foster 	unsigned auto_inval_data:1;
69972d0d248SBrian Foster 
700ad2ba64dSKirill Smelkov 	/** Filesystem is fully reponsible for page cache invalidation. */
701ad2ba64dSKirill Smelkov 	unsigned explicit_inval_data:1;
702ad2ba64dSKirill Smelkov 
703634734b6SEric Wong 	/** Does the filesystem support readdirplus? */
7040b05b183SAnand V. Avati 	unsigned do_readdirplus:1;
7050b05b183SAnand V. Avati 
706634734b6SEric Wong 	/** Does the filesystem want adaptive readdirplus? */
707634734b6SEric Wong 	unsigned readdirplus_auto:1;
708634734b6SEric Wong 
70960b9df7aSMiklos Szeredi 	/** Does the filesystem support asynchronous direct-IO submission? */
71060b9df7aSMiklos Szeredi 	unsigned async_dio:1;
71160b9df7aSMiklos Szeredi 
7120b5da8dbSRavishankar N 	/** Is lseek not implemented by fs? */
7130b5da8dbSRavishankar N 	unsigned no_lseek:1;
7140b5da8dbSRavishankar N 
71560bcc88aSSeth Forshee 	/** Does the filesystem support posix acls? */
71660bcc88aSSeth Forshee 	unsigned posix_acl:1;
71760bcc88aSSeth Forshee 
71829433a29SMiklos Szeredi 	/** Check permissions based on the file mode or not? */
71929433a29SMiklos Szeredi 	unsigned default_permissions:1;
72029433a29SMiklos Szeredi 
72129433a29SMiklos Szeredi 	/** Allow other than the mounter user to access the filesystem ? */
72229433a29SMiklos Szeredi 	unsigned allow_other:1;
72329433a29SMiklos Szeredi 
72488bc7d50SNiels de Vos 	/** Does the filesystem support copy_file_range? */
72588bc7d50SNiels de Vos 	unsigned no_copy_file_range:1;
72688bc7d50SNiels de Vos 
7270cd5b885SMiklos Szeredi 	/** The number of requests waiting for completion */
7280cd5b885SMiklos Szeredi 	atomic_t num_waiting;
7290cd5b885SMiklos Szeredi 
73045714d65SMiklos Szeredi 	/** Negotiated minor version */
73145714d65SMiklos Szeredi 	unsigned minor;
73245714d65SMiklos Szeredi 
733bafa9654SMiklos Szeredi 	/** Entry on the fuse_conn_list */
734bafa9654SMiklos Szeredi 	struct list_head entry;
735bafa9654SMiklos Szeredi 
736b6f2fcbcSMiklos Szeredi 	/** Device ID from super block */
737b6f2fcbcSMiklos Szeredi 	dev_t dev;
738bafa9654SMiklos Szeredi 
739bafa9654SMiklos Szeredi 	/** Dentries in the control filesystem */
740bafa9654SMiklos Szeredi 	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
741bafa9654SMiklos Szeredi 
742bafa9654SMiklos Szeredi 	/** number of dentries used in the above array */
743bafa9654SMiklos Szeredi 	int ctl_ndents;
744385a17bfSJeff Dike 
7459c8ef561SMiklos Szeredi 	/** Key for lock owner ID scrambling */
7469c8ef561SMiklos Szeredi 	u32 scramble_key[4];
7470ec7ca41SMiklos Szeredi 
7480ec7ca41SMiklos Szeredi 	/** Reserved request for the DESTROY message */
7490ec7ca41SMiklos Szeredi 	struct fuse_req *destroy_req;
7501fb69e78SMiklos Szeredi 
7511fb69e78SMiklos Szeredi 	/** Version counter for attribute changes */
7524510d86fSKirill Tkhai 	atomic64_t attr_version;
75343901aabSTejun Heo 
75443901aabSTejun Heo 	/** Called on final put */
75543901aabSTejun Heo 	void (*release)(struct fuse_conn *);
7563b463ae0SJohn Muir 
7573b463ae0SJohn Muir 	/** Super block for this connection. */
7583b463ae0SJohn Muir 	struct super_block *sb;
7593b463ae0SJohn Muir 
7603b463ae0SJohn Muir 	/** Read/write semaphore to hold when accessing sb. */
7613b463ae0SJohn Muir 	struct rw_semaphore killsb;
762cc080e9eSMiklos Szeredi 
763cc080e9eSMiklos Szeredi 	/** List of device instances belonging to this connection */
764cc080e9eSMiklos Szeredi 	struct list_head devices;
765d8a5ba45SMiklos Szeredi };
766d8a5ba45SMiklos Szeredi 
767d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
768d8a5ba45SMiklos Szeredi {
7696383bdaaSMiklos Szeredi 	return sb->s_fs_info;
770d8a5ba45SMiklos Szeredi }
771d8a5ba45SMiklos Szeredi 
772d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
773d8a5ba45SMiklos Szeredi {
774d8a5ba45SMiklos Szeredi 	return get_fuse_conn_super(inode->i_sb);
775d8a5ba45SMiklos Szeredi }
776d8a5ba45SMiklos Szeredi 
777d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
778d8a5ba45SMiklos Szeredi {
779d8a5ba45SMiklos Szeredi 	return container_of(inode, struct fuse_inode, inode);
780d8a5ba45SMiklos Szeredi }
781d8a5ba45SMiklos Szeredi 
782d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode)
783d8a5ba45SMiklos Szeredi {
784d8a5ba45SMiklos Szeredi 	return get_fuse_inode(inode)->nodeid;
785d8a5ba45SMiklos Szeredi }
786d8a5ba45SMiklos Szeredi 
787d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid)
788d123d8e1SMiklos Szeredi {
789d123d8e1SMiklos Szeredi 	return !nodeid || nodeid == FUSE_ROOT_ID;
790d123d8e1SMiklos Szeredi }
791d123d8e1SMiklos Szeredi 
7924510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
7934510d86fSKirill Tkhai {
7944510d86fSKirill Tkhai 	return atomic64_read(&fc->attr_version);
7954510d86fSKirill Tkhai }
7964510d86fSKirill Tkhai 
797334f485dSMiklos Szeredi /** Device operations */
7984b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations;
799334f485dSMiklos Szeredi 
8004269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations;
8010ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations;
802dbd561d2SMiklos Szeredi 
803d8a5ba45SMiklos Szeredi /**
8043b463ae0SJohn Muir  * Inode to nodeid comparison.
8053b463ae0SJohn Muir  */
8063b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp);
8073b463ae0SJohn Muir 
8083b463ae0SJohn Muir /**
809e5e5558eSMiklos Szeredi  * Get a filled in inode
810e5e5558eSMiklos Szeredi  */
811b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
8121fb69e78SMiklos Szeredi 			int generation, struct fuse_attr *attr,
8131fb69e78SMiklos Szeredi 			u64 attr_valid, u64 attr_version);
814e5e5558eSMiklos Szeredi 
81513983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
81633670fa2SMiklos Szeredi 		     struct fuse_entry_out *outarg, struct inode **inode);
81733670fa2SMiklos Szeredi 
818e5e5558eSMiklos Szeredi /**
819e5e5558eSMiklos Szeredi  * Send FORGET command
820e5e5558eSMiklos Szeredi  */
82107e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
822b48badf0SMiklos Szeredi 		       u64 nodeid, u64 nlookup);
823e5e5558eSMiklos Szeredi 
82407e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void);
82507e77dcaSMiklos Szeredi 
8260b05b183SAnand V. Avati /* Used by READDIRPLUS */
8270b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid);
8280b05b183SAnand V. Avati 
829e5e5558eSMiklos Szeredi /**
830361b1eb5SMiklos Szeredi  * Initialize READ or READDIR request
83104730fefSMiklos Szeredi  */
832a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file,
8332106cb18SMiklos Szeredi 		    loff_t pos, size_t count, int opcode);
83404730fefSMiklos Szeredi 
83504730fefSMiklos Szeredi /**
83604730fefSMiklos Szeredi  * Send OPEN or OPENDIR request
83704730fefSMiklos Szeredi  */
83891fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
83904730fefSMiklos Szeredi 
840acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
841fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff);
842c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file);
843fd72faacSMiklos Szeredi 
844ebf84d0cSKirill Tkhai void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
845c756e0a4SMiklos Szeredi 
84604730fefSMiklos Szeredi /**
84704730fefSMiklos Szeredi  * Send RELEASE or RELEASEDIR request
84804730fefSMiklos Szeredi  */
8492e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir);
85004730fefSMiklos Szeredi 
85104730fefSMiklos Szeredi /**
85282547981SMiklos Szeredi  * Send FSYNC or FSYNCDIR request
85382547981SMiklos Szeredi  */
85402c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
855a9c2d1e8SMiklos Szeredi 		      int datasync, int opcode);
85682547981SMiklos Szeredi 
85782547981SMiklos Szeredi /**
85895668a69STejun Heo  * Notify poll wakeup
85995668a69STejun Heo  */
86095668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc,
86195668a69STejun Heo 			    struct fuse_notify_poll_wakeup_out *outarg);
86295668a69STejun Heo 
86395668a69STejun Heo /**
8641779381dSMiklos Szeredi  * Initialize file operations on a regular file
865b6aeadedSMiklos Szeredi  */
866b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode);
867b6aeadedSMiklos Szeredi 
868b6aeadedSMiklos Szeredi /**
8691779381dSMiklos Szeredi  * Initialize inode operations on regular files and special files
870e5e5558eSMiklos Szeredi  */
871e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode);
872e5e5558eSMiklos Szeredi 
873e5e5558eSMiklos Szeredi /**
8741779381dSMiklos Szeredi  * Initialize inode and file operations on a directory
875e5e5558eSMiklos Szeredi  */
876e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode);
877e5e5558eSMiklos Szeredi 
878e5e5558eSMiklos Szeredi /**
8791779381dSMiklos Szeredi  * Initialize inode operations on a symlink
880e5e5558eSMiklos Szeredi  */
881e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode);
882e5e5558eSMiklos Szeredi 
883e5e5558eSMiklos Szeredi /**
884e5e5558eSMiklos Szeredi  * Change attributes of an inode
885e5e5558eSMiklos Szeredi  */
8861fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
8871fb69e78SMiklos Szeredi 			    u64 attr_valid, u64 attr_version);
888e5e5558eSMiklos Szeredi 
8893be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
8903be5a52bSMiklos Szeredi 				   u64 attr_valid);
8913be5a52bSMiklos Szeredi 
892e5e5558eSMiklos Szeredi /**
893334f485dSMiklos Szeredi  * Initialize the client device
894334f485dSMiklos Szeredi  */
895334f485dSMiklos Szeredi int fuse_dev_init(void);
896334f485dSMiklos Szeredi 
897334f485dSMiklos Szeredi /**
898334f485dSMiklos Szeredi  * Cleanup the client device
899334f485dSMiklos Szeredi  */
900334f485dSMiklos Szeredi void fuse_dev_cleanup(void);
901334f485dSMiklos Szeredi 
902bafa9654SMiklos Szeredi int fuse_ctl_init(void);
9037736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void);
904bafa9654SMiklos Szeredi 
905334f485dSMiklos Szeredi /**
906334f485dSMiklos Szeredi  * Allocate a request
907334f485dSMiklos Szeredi  */
9084250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages);
909334f485dSMiklos Szeredi 
9104250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
9113be5a52bSMiklos Szeredi 
912e52a8250SMiklos Szeredi bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req,
913e52a8250SMiklos Szeredi 			    gfp_t flags);
914e52a8250SMiklos Szeredi 
915e52a8250SMiklos Szeredi 
916334f485dSMiklos Szeredi /**
917334f485dSMiklos Szeredi  * Free a request
918334f485dSMiklos Szeredi  */
919334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req);
920334f485dSMiklos Szeredi 
921334f485dSMiklos Szeredi /**
922b111c8c0SMaxim Patlasov  * Get a request, may fail with -ENOMEM,
923b111c8c0SMaxim Patlasov  * caller should specify # elements in req->pages[] explicitly
924334f485dSMiklos Szeredi  */
925b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
9268b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
9278b41e671SMaxim Patlasov 					     unsigned npages);
928b111c8c0SMaxim Patlasov 
92936cf66edSMaxim Patlasov /*
93036cf66edSMaxim Patlasov  * Increment reference count on request
93136cf66edSMaxim Patlasov  */
93236cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req);
93336cf66edSMaxim Patlasov 
934b111c8c0SMaxim Patlasov /**
93533649c91SMiklos Szeredi  * Gets a requests for a file operation, always succeeds
93633649c91SMiklos Szeredi  */
937b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
938b111c8c0SMaxim Patlasov 					     struct file *file);
93933649c91SMiklos Szeredi 
94033649c91SMiklos Szeredi /**
941ce1d5a49SMiklos Szeredi  * Decrement reference count of a request.  If count goes to zero free
942ce1d5a49SMiklos Szeredi  * the request.
943334f485dSMiklos Szeredi  */
944334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
945334f485dSMiklos Szeredi 
946334f485dSMiklos Szeredi /**
9477c352bdfSMiklos Szeredi  * Send a request (synchronous)
948334f485dSMiklos Szeredi  */
949b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
950334f485dSMiklos Szeredi 
951334f485dSMiklos Szeredi /**
9527078187aSMiklos Szeredi  * Simple request sending that does request allocation and freeing
9537078187aSMiklos Szeredi  */
9547078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
9557078187aSMiklos Szeredi 
9567078187aSMiklos Szeredi /**
957334f485dSMiklos Szeredi  * Send a request in the background
958334f485dSMiklos Szeredi  */
959b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
96063825b4eSKirill Tkhai bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
9613be5a52bSMiklos Szeredi 
9625a5fb1eaSMiklos Szeredi /* Abort all requests */
963eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc);
964b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc);
96569a53bf2SMiklos Szeredi 
9661e9a4ed9SMiklos Szeredi /**
967e5e5558eSMiklos Szeredi  * Invalidate inode attributes
968e5e5558eSMiklos Szeredi  */
969e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode);
970bafa9654SMiklos Szeredi 
971dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry);
972dbd561d2SMiklos Szeredi 
973451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode);
974451418fcSAndrew Gallagher 
975d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o);
976d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
977d123d8e1SMiklos Szeredi 
978bafa9654SMiklos Szeredi /**
979bafa9654SMiklos Szeredi  * Acquire reference to fuse_conn
980bafa9654SMiklos Szeredi  */
981bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
982bafa9654SMiklos Szeredi 
983bafa9654SMiklos Szeredi /**
9840d179aa5STejun Heo  * Initialize fuse_conn
9850d179aa5STejun Heo  */
9868cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
9870d179aa5STejun Heo 
9880d179aa5STejun Heo /**
989bafa9654SMiklos Szeredi  * Release reference to fuse_conn
990bafa9654SMiklos Szeredi  */
991bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc);
992bafa9654SMiklos Szeredi 
993cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
994cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud);
995cc080e9eSMiklos Szeredi 
996bafa9654SMiklos Szeredi /**
997bafa9654SMiklos Szeredi  * Add connection to control filesystem
998bafa9654SMiklos Szeredi  */
999bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc);
1000bafa9654SMiklos Szeredi 
1001bafa9654SMiklos Szeredi /**
1002bafa9654SMiklos Szeredi  * Remove connection from control filesystem
1003bafa9654SMiklos Szeredi  */
1004bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc);
1005a5bfffacSTimo Savola 
1006a5bfffacSTimo Savola /**
1007a5bfffacSTimo Savola  * Is file type valid?
1008a5bfffacSTimo Savola  */
1009a5bfffacSTimo Savola int fuse_valid_type(int m);
1010e57ac683SMiklos Szeredi 
1011e57ac683SMiklos Szeredi /**
1012c2132c1bSAnatol Pomozov  * Is current process allowed to perform filesystem operation?
1013e57ac683SMiklos Szeredi  */
1014c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc);
1015f3332114SMiklos Szeredi 
1016f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
1017bcb4be80SMiklos Szeredi 
1018703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode);
1019703c7362SSeth Forshee 
10205b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file);
10213be5a52bSMiklos Szeredi 
10223be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode);
10233be5a52bSMiklos Szeredi 
10243be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode);
10253be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode);
10265c5c5e51SMiklos Szeredi 
10273b463ae0SJohn Muir /**
10283b463ae0SJohn Muir  * File-system tells the kernel to invalidate cache for the given node id.
10293b463ae0SJohn Muir  */
10303b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
10313b463ae0SJohn Muir 			     loff_t offset, loff_t len);
10323b463ae0SJohn Muir 
10333b463ae0SJohn Muir /**
10343b463ae0SJohn Muir  * File-system tells the kernel to invalidate parent attributes and
10353b463ae0SJohn Muir  * the dentry matching parent/name.
1036451d0f59SJohn Muir  *
1037451d0f59SJohn Muir  * If the child_nodeid is non-zero and:
1038451d0f59SJohn Muir  *    - matches the inode number for the dentry matching parent/name,
1039451d0f59SJohn Muir  *    - is not a mount point
1040451d0f59SJohn Muir  *    - is a file or oan empty directory
1041451d0f59SJohn Muir  * then the dentry is unhashed (d_delete()).
10423b463ae0SJohn Muir  */
10433b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
1044451d0f59SJohn Muir 			     u64 child_nodeid, struct qstr *name);
10453b463ae0SJohn Muir 
104608cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
104708cbf542STejun Heo 		 bool isdir);
1048ea8cd333SPavel Emelyanov 
1049ea8cd333SPavel Emelyanov /**
1050ea8cd333SPavel Emelyanov  * fuse_direct_io() flags
1051ea8cd333SPavel Emelyanov  */
1052ea8cd333SPavel Emelyanov 
1053ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */
1054ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0)
1055ea8cd333SPavel Emelyanov 
1056ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1057ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE  (1 << 1)
1058ea8cd333SPavel Emelyanov 
1059d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1060d22a943fSAl Viro 		       loff_t *ppos, int flags);
106108cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
106208cbf542STejun Heo 		   unsigned int flags);
1063b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd,
1064b18da0c5SMiklos Szeredi 		       unsigned long arg, unsigned int flags);
1065076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait);
106608cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file);
106708cbf542STejun Heo 
1068b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos);
1069b0aa7606SMaxim Patlasov 
1070ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
10711e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1072a1d75f25SMiklos Szeredi 
107362490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1074efb9fa9eSMaxim Patlasov 		    struct file *file);
1075efb9fa9eSMaxim Patlasov 
10769759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc);
10779759bd51SMiklos Szeredi 
107863576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked);
107963576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode);
10805c672ab3SMiklos Szeredi 
108160bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value,
108260bcc88aSSeth Forshee 		  size_t size, int flags);
108360bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
108460bcc88aSSeth Forshee 		      size_t size);
1085703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
108660bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name);
1087703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[];
108860bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1089e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
109060bcc88aSSeth Forshee 
109160bcc88aSSeth Forshee struct posix_acl;
109260bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type);
109360bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
1094703c7362SSeth Forshee 
1095d123d8e1SMiklos Szeredi 
1096d123d8e1SMiklos Szeredi /* readdir.c */
1097d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx);
1098d123d8e1SMiklos Szeredi 
109929d434b3STejun Heo #endif /* _FS_FUSE_I_H */
1100