xref: /openbmc/linux/fs/fuse/fuse_i.h (revision 15c8e72e88e0b707ffefd524ca33f28cdb3db487)
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 
50bafa9654SMiklos Szeredi /** List of active connections */
51bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list;
52bafa9654SMiklos Szeredi 
53bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */
54bafa9654SMiklos Szeredi extern struct mutex fuse_mutex;
55413ef8cbSMiklos Szeredi 
5679a9d994SCsaba Henk /** Module parameters */
5779a9d994SCsaba Henk extern unsigned max_user_bgreq;
5879a9d994SCsaba Henk extern unsigned max_user_congthresh;
5979a9d994SCsaba Henk 
6007e77dcaSMiklos Szeredi /* One forget request */
6107e77dcaSMiklos Szeredi struct fuse_forget_link {
6202c048b9SMiklos Szeredi 	struct fuse_forget_one forget_one;
6307e77dcaSMiklos Szeredi 	struct fuse_forget_link *next;
6407e77dcaSMiklos Szeredi };
6507e77dcaSMiklos Szeredi 
66d8a5ba45SMiklos Szeredi /** FUSE inode */
67d8a5ba45SMiklos Szeredi struct fuse_inode {
68d8a5ba45SMiklos Szeredi 	/** Inode data */
69d8a5ba45SMiklos Szeredi 	struct inode inode;
70d8a5ba45SMiklos Szeredi 
71d8a5ba45SMiklos Szeredi 	/** Unique ID, which identifies the inode between userspace
72d8a5ba45SMiklos Szeredi 	 * and kernel */
73d8a5ba45SMiklos Szeredi 	u64 nodeid;
74d8a5ba45SMiklos Szeredi 
759e6268dbSMiklos Szeredi 	/** Number of lookups on this inode */
769e6268dbSMiklos Szeredi 	u64 nlookup;
779e6268dbSMiklos Szeredi 
78e5e5558eSMiklos Szeredi 	/** The request used for sending the FORGET message */
7907e77dcaSMiklos Szeredi 	struct fuse_forget_link *forget;
80e5e5558eSMiklos Szeredi 
81d8a5ba45SMiklos Szeredi 	/** Time in jiffies until the file attributes are valid */
820a0898cfSMiklos Szeredi 	u64 i_time;
83ebc14c4dSMiklos Szeredi 
842f1e8196SMiklos Szeredi 	/* Which attributes are invalid */
852f1e8196SMiklos Szeredi 	u32 inval_mask;
862f1e8196SMiklos Szeredi 
87ebc14c4dSMiklos Szeredi 	/** The sticky bit in inode->i_mode may have been removed, so
88ebc14c4dSMiklos Szeredi 	    preserve the original mode */
89541af6a0SAl Viro 	umode_t orig_i_mode;
901fb69e78SMiklos Szeredi 
9145c72cd7SPavel Shilovsky 	/** 64 bit inode number */
9245c72cd7SPavel Shilovsky 	u64 orig_ino;
9345c72cd7SPavel Shilovsky 
941fb69e78SMiklos Szeredi 	/** Version of last attribute change */
951fb69e78SMiklos Szeredi 	u64 attr_version;
9693a8c3cdSMiklos Szeredi 
97ab2257e9SMiklos Szeredi 	union {
98ab2257e9SMiklos Szeredi 		/* Write related fields (regular file only) */
99ab2257e9SMiklos Szeredi 		struct {
100f15ecfefSKirill Tkhai 			/* Files usable in writepage.  Protected by fi->lock */
10193a8c3cdSMiklos Szeredi 			struct list_head write_files;
1023be5a52bSMiklos Szeredi 
103ab2257e9SMiklos Szeredi 			/* Writepages pending on truncate or fsync */
1043be5a52bSMiklos Szeredi 			struct list_head queued_writes;
1053be5a52bSMiklos Szeredi 
106ab2257e9SMiklos Szeredi 			/* Number of sent writes, a negative bias
107ab2257e9SMiklos Szeredi 			 * (FUSE_NOWRITE) means more writes are blocked */
1083be5a52bSMiklos Szeredi 			int writectr;
1093be5a52bSMiklos Szeredi 
110ab2257e9SMiklos Szeredi 			/* Waitq for writepage completion */
1113be5a52bSMiklos Szeredi 			wait_queue_head_t page_waitq;
1123be5a52bSMiklos Szeredi 
113ab2257e9SMiklos Szeredi 			/* List of writepage requestst (pending or sent) */
1143be5a52bSMiklos Szeredi 			struct list_head writepages;
115ab2257e9SMiklos Szeredi 		};
1164582a4abSFeng Shuo 
117ab2257e9SMiklos Szeredi 		/* readdir cache (directory only) */
11869e34551SMiklos Szeredi 		struct {
11969e34551SMiklos Szeredi 			/* true if fully cached */
12069e34551SMiklos Szeredi 			bool cached;
12169e34551SMiklos Szeredi 
12269e34551SMiklos Szeredi 			/* size of cache */
12369e34551SMiklos Szeredi 			loff_t size;
12469e34551SMiklos Szeredi 
12569e34551SMiklos Szeredi 			/* position at end of cache (position of next entry) */
12669e34551SMiklos Szeredi 			loff_t pos;
12769e34551SMiklos Szeredi 
1283494927eSMiklos Szeredi 			/* version of the cache */
1293494927eSMiklos Szeredi 			u64 version;
1303494927eSMiklos Szeredi 
131ab2257e9SMiklos Szeredi 			/* modification time of directory when cache was
132ab2257e9SMiklos Szeredi 			 * started */
1337118883bSMiklos Szeredi 			struct timespec64 mtime;
1347118883bSMiklos Szeredi 
135261aaba7SMiklos Szeredi 			/* iversion of directory when cache was started */
136261aaba7SMiklos Szeredi 			u64 iversion;
137261aaba7SMiklos Szeredi 
13869e34551SMiklos Szeredi 			/* protects above fields */
13969e34551SMiklos Szeredi 			spinlock_t lock;
14069e34551SMiklos Szeredi 		} rdc;
141ab2257e9SMiklos Szeredi 	};
14269e34551SMiklos Szeredi 
1434582a4abSFeng Shuo 	/** Miscellaneous bits describing inode state */
1444582a4abSFeng Shuo 	unsigned long state;
1455c672ab3SMiklos Szeredi 
1465c672ab3SMiklos Szeredi 	/** Lock for serializing lookup and readdir for back compatibility*/
1475c672ab3SMiklos Szeredi 	struct mutex mutex;
148f15ecfefSKirill Tkhai 
149f15ecfefSKirill Tkhai 	/** Lock to protect write related fields */
150f15ecfefSKirill Tkhai 	spinlock_t lock;
1514582a4abSFeng Shuo };
1524582a4abSFeng Shuo 
1534582a4abSFeng Shuo /** FUSE inode state bits */
1544582a4abSFeng Shuo enum {
1554582a4abSFeng Shuo 	/** Advise readdirplus  */
1564582a4abSFeng Shuo 	FUSE_I_ADVISE_RDPLUS,
1576314efeeSMiklos Szeredi 	/** Initialized with readdirplus */
1586314efeeSMiklos Szeredi 	FUSE_I_INIT_RDPLUS,
15906a7c3c2SMaxim Patlasov 	/** An operation changing file size is in progress  */
16006a7c3c2SMaxim Patlasov 	FUSE_I_SIZE_UNSTABLE,
161d8a5ba45SMiklos Szeredi };
162d8a5ba45SMiklos Szeredi 
163da5e4714SMiklos Szeredi struct fuse_conn;
1644cb54866SMiklos Szeredi struct fuse_release_args;
165da5e4714SMiklos Szeredi 
166b6aeadedSMiklos Szeredi /** FUSE specific file data */
167b6aeadedSMiklos Szeredi struct fuse_file {
168da5e4714SMiklos Szeredi 	/** Fuse connection for this file */
169da5e4714SMiklos Szeredi 	struct fuse_conn *fc;
170da5e4714SMiklos Szeredi 
1714cb54866SMiklos Szeredi 	/* Argument space reserved for release */
1724cb54866SMiklos Szeredi 	struct fuse_release_args *release_args;
173b6aeadedSMiklos Szeredi 
174acf99433STejun Heo 	/** Kernel file handle guaranteed to be unique */
175acf99433STejun Heo 	u64 kh;
176acf99433STejun Heo 
177b6aeadedSMiklos Szeredi 	/** File handle used by userspace */
178b6aeadedSMiklos Szeredi 	u64 fh;
179c756e0a4SMiklos Szeredi 
180da5e4714SMiklos Szeredi 	/** Node id of this file */
181da5e4714SMiklos Szeredi 	u64 nodeid;
182da5e4714SMiklos Szeredi 
183c756e0a4SMiklos Szeredi 	/** Refcount */
1844e8c2eb5SElena Reshetova 	refcount_t count;
18593a8c3cdSMiklos Szeredi 
186c7b7143cSMiklos Szeredi 	/** FOPEN_* flags returned by open */
187c7b7143cSMiklos Szeredi 	u32 open_flags;
188c7b7143cSMiklos Szeredi 
18993a8c3cdSMiklos Szeredi 	/** Entry on inode's write_files list */
19093a8c3cdSMiklos Szeredi 	struct list_head write_entry;
19195668a69STejun Heo 
1925d7bc7e8SMiklos Szeredi 	/* Readdir related */
1935d7bc7e8SMiklos Szeredi 	struct {
1945d7bc7e8SMiklos Szeredi 		/*
1955d7bc7e8SMiklos Szeredi 		 * Protects below fields against (crazy) parallel readdir on
1965d7bc7e8SMiklos Szeredi 		 * same open file.  Uncontended in the normal case.
1975d7bc7e8SMiklos Szeredi 		 */
1985d7bc7e8SMiklos Szeredi 		struct mutex lock;
1995d7bc7e8SMiklos Szeredi 
2005d7bc7e8SMiklos Szeredi 		/* Dir stream position */
2015d7bc7e8SMiklos Szeredi 		loff_t pos;
2025d7bc7e8SMiklos Szeredi 
2035d7bc7e8SMiklos Szeredi 		/* Offset in cache */
2045d7bc7e8SMiklos Szeredi 		loff_t cache_off;
2053494927eSMiklos Szeredi 
2063494927eSMiklos Szeredi 		/* Version of cache we are reading */
2073494927eSMiklos Szeredi 		u64 version;
2083494927eSMiklos Szeredi 
2095d7bc7e8SMiklos Szeredi 	} readdir;
2105d7bc7e8SMiklos Szeredi 
21195668a69STejun Heo 	/** RB node to be linked on fuse_conn->polled_files */
21295668a69STejun Heo 	struct rb_node polled_node;
21395668a69STejun Heo 
21495668a69STejun Heo 	/** Wait queue head for poll */
21595668a69STejun Heo 	wait_queue_head_t poll_wait;
21637fb3a30SMiklos Szeredi 
21737fb3a30SMiklos Szeredi 	/** Has flock been performed on this file? */
21837fb3a30SMiklos Szeredi 	bool flock:1;
219b6aeadedSMiklos Szeredi };
220b6aeadedSMiklos Szeredi 
221334f485dSMiklos Szeredi /** One input argument of a request */
222334f485dSMiklos Szeredi struct fuse_in_arg {
223334f485dSMiklos Szeredi 	unsigned size;
224334f485dSMiklos Szeredi 	const void *value;
225334f485dSMiklos Szeredi };
226334f485dSMiklos Szeredi 
227334f485dSMiklos Szeredi /** One output argument of a request */
228334f485dSMiklos Szeredi struct fuse_arg {
229334f485dSMiklos Szeredi 	unsigned size;
230334f485dSMiklos Szeredi 	void *value;
231334f485dSMiklos Szeredi };
232334f485dSMiklos Szeredi 
233b2430d75SMaxim Patlasov /** FUSE page descriptor */
234b2430d75SMaxim Patlasov struct fuse_page_desc {
235b2430d75SMaxim Patlasov 	unsigned int length;
236b2430d75SMaxim Patlasov 	unsigned int offset;
237b2430d75SMaxim Patlasov };
238b2430d75SMaxim Patlasov 
2397078187aSMiklos Szeredi struct fuse_args {
2407078187aSMiklos Szeredi 	uint64_t nodeid;
2411f4e9d03SMiklos Szeredi 	uint32_t opcode;
2421f4e9d03SMiklos Szeredi 	unsigned short in_numargs;
2431f4e9d03SMiklos Szeredi 	unsigned short out_numargs;
244c500ebaaSMiklos Szeredi 	bool force:1;
245454a7613SMiklos Szeredi 	bool noreply:1;
246e413754bSMiklos Szeredi 	bool nocreds:1;
24768583165SMiklos Szeredi 	bool in_pages:1;
24868583165SMiklos Szeredi 	bool out_pages:1;
2491f4e9d03SMiklos Szeredi 	bool out_argvar:1;
25068583165SMiklos Szeredi 	bool page_zeroing:1;
25168583165SMiklos Szeredi 	bool page_replace:1;
252d5b48543SMiklos Szeredi 	struct fuse_in_arg in_args[3];
253d5b48543SMiklos Szeredi 	struct fuse_arg out_args[2];
25412597287SMiklos Szeredi 	void (*end)(struct fuse_conn *fc, struct fuse_args *args, int error);
2557078187aSMiklos Szeredi };
2567078187aSMiklos Szeredi 
25768583165SMiklos Szeredi struct fuse_args_pages {
25868583165SMiklos Szeredi 	struct fuse_args args;
25968583165SMiklos Szeredi 	struct page **pages;
26068583165SMiklos Szeredi 	struct fuse_page_desc *descs;
26168583165SMiklos Szeredi 	unsigned int num_pages;
26268583165SMiklos Szeredi };
26368583165SMiklos Szeredi 
2647078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {}
2657078187aSMiklos Szeredi 
26601e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */
26701e9d11aSMaxim Patlasov struct fuse_io_priv {
268744742d6SSeth Forshee 	struct kref refcnt;
26901e9d11aSMaxim Patlasov 	int async;
27001e9d11aSMaxim Patlasov 	spinlock_t lock;
27101e9d11aSMaxim Patlasov 	unsigned reqs;
27201e9d11aSMaxim Patlasov 	ssize_t bytes;
27301e9d11aSMaxim Patlasov 	size_t size;
27401e9d11aSMaxim Patlasov 	__u64 offset;
27501e9d11aSMaxim Patlasov 	bool write;
27661c12b49SAshish Samant 	bool should_dirty;
27701e9d11aSMaxim Patlasov 	int err;
27801e9d11aSMaxim Patlasov 	struct kiocb *iocb;
2799d5722b7SChristoph Hellwig 	struct completion *done;
2807879c4e5SAshish Sangwan 	bool blocking;
28101e9d11aSMaxim Patlasov };
28201e9d11aSMaxim Patlasov 
283e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \
284744742d6SSeth Forshee {					\
2851e24edcaSPeter Zijlstra 	.refcnt = KREF_INIT(1),		\
286744742d6SSeth Forshee 	.async = 0,			\
287e1c0eecbSMiklos Szeredi 	.iocb = i,			\
288744742d6SSeth Forshee }
289744742d6SSeth Forshee 
290334f485dSMiklos Szeredi /**
291825d6d33SMiklos Szeredi  * Request flags
292825d6d33SMiklos Szeredi  *
293825d6d33SMiklos Szeredi  * FR_ISREPLY:		set if the request has reply
294825d6d33SMiklos Szeredi  * FR_FORCE:		force sending of the request even if interrupted
295825d6d33SMiklos Szeredi  * FR_BACKGROUND:	request is sent in the background
296825d6d33SMiklos Szeredi  * FR_WAITING:		request is counted as "waiting"
297825d6d33SMiklos Szeredi  * FR_ABORTED:		the request was aborted
298825d6d33SMiklos Szeredi  * FR_INTERRUPTED:	the request has been interrupted
299825d6d33SMiklos Szeredi  * FR_LOCKED:		data is being copied to/from the request
30033e14b4dSMiklos Szeredi  * FR_PENDING:		request is not yet in userspace
30133e14b4dSMiklos Szeredi  * FR_SENT:		request is in userspace, waiting for an answer
30233e14b4dSMiklos Szeredi  * FR_FINISHED:		request is finished
30377cd9d48SMiklos Szeredi  * FR_PRIVATE:		request is on private list
304825d6d33SMiklos Szeredi  */
305825d6d33SMiklos Szeredi enum fuse_req_flag {
306825d6d33SMiklos Szeredi 	FR_ISREPLY,
307825d6d33SMiklos Szeredi 	FR_FORCE,
308825d6d33SMiklos Szeredi 	FR_BACKGROUND,
309825d6d33SMiklos Szeredi 	FR_WAITING,
310825d6d33SMiklos Szeredi 	FR_ABORTED,
311825d6d33SMiklos Szeredi 	FR_INTERRUPTED,
312825d6d33SMiklos Szeredi 	FR_LOCKED,
31333e14b4dSMiklos Szeredi 	FR_PENDING,
31433e14b4dSMiklos Szeredi 	FR_SENT,
31533e14b4dSMiklos Szeredi 	FR_FINISHED,
31677cd9d48SMiklos Szeredi 	FR_PRIVATE,
317825d6d33SMiklos Szeredi };
318825d6d33SMiklos Szeredi 
319825d6d33SMiklos Szeredi /**
320334f485dSMiklos Szeredi  * A request to the client
321dc00809aSMiklos Szeredi  *
322dc00809aSMiklos Szeredi  * .waitq.lock protects the following fields:
323dc00809aSMiklos Szeredi  *   - FR_ABORTED
324dc00809aSMiklos Szeredi  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
325334f485dSMiklos Szeredi  */
326334f485dSMiklos Szeredi struct fuse_req {
327ce1d5a49SMiklos Szeredi 	/** This can be on either pending processing or io lists in
328ce1d5a49SMiklos Szeredi 	    fuse_conn */
329334f485dSMiklos Szeredi 	struct list_head list;
330334f485dSMiklos Szeredi 
331a4d27e75SMiklos Szeredi 	/** Entry on the interrupts list  */
332a4d27e75SMiklos Szeredi 	struct list_head intr_entry;
333a4d27e75SMiklos Szeredi 
33412597287SMiklos Szeredi 	/* Input/output arguments */
33512597287SMiklos Szeredi 	struct fuse_args *args;
33612597287SMiklos Szeredi 
337334f485dSMiklos Szeredi 	/** refcount */
338ec99f6d3SElena Reshetova 	refcount_t count;
339334f485dSMiklos Szeredi 
340825d6d33SMiklos Szeredi 	/* Request flags, updated with test/set/clear_bit() */
341825d6d33SMiklos Szeredi 	unsigned long flags;
3429bc5dddaSMiklos Szeredi 
343d4993774SMiklos Szeredi 	/* The request input header */
344d4993774SMiklos Szeredi 	struct {
345d4993774SMiklos Szeredi 		struct fuse_in_header h;
346d4993774SMiklos Szeredi 	} in;
347334f485dSMiklos Szeredi 
348d4993774SMiklos Szeredi 	/* The request output header */
349d4993774SMiklos Szeredi 	struct {
350d4993774SMiklos Szeredi 		struct fuse_out_header h;
351d4993774SMiklos Szeredi 	} out;
352334f485dSMiklos Szeredi 
353334f485dSMiklos Szeredi 	/** Used to wake up the task waiting for completion of request*/
354334f485dSMiklos Szeredi 	wait_queue_head_t waitq;
355334f485dSMiklos Szeredi 
356334f485dSMiklos Szeredi };
357334f485dSMiklos Szeredi 
358ae3aad77SStefan Hajnoczi struct fuse_iqueue;
359ae3aad77SStefan Hajnoczi 
360ae3aad77SStefan Hajnoczi /**
361ae3aad77SStefan Hajnoczi  * Input queue callbacks
362ae3aad77SStefan Hajnoczi  *
363ae3aad77SStefan Hajnoczi  * Input queue signalling is device-specific.  For example, the /dev/fuse file
364ae3aad77SStefan Hajnoczi  * uses fiq->waitq and fasync to wake processes that are waiting on queue
365ae3aad77SStefan Hajnoczi  * readiness.  These callbacks allow other device types to respond to input
366ae3aad77SStefan Hajnoczi  * queue activity.
367ae3aad77SStefan Hajnoczi  */
368ae3aad77SStefan Hajnoczi struct fuse_iqueue_ops {
369ae3aad77SStefan Hajnoczi 	/**
370ae3aad77SStefan Hajnoczi 	 * Signal that a forget has been queued
371ae3aad77SStefan Hajnoczi 	 */
372ae3aad77SStefan Hajnoczi 	void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
373ae3aad77SStefan Hajnoczi 		__releases(fiq->lock);
374ae3aad77SStefan Hajnoczi 
375ae3aad77SStefan Hajnoczi 	/**
376ae3aad77SStefan Hajnoczi 	 * Signal that an INTERRUPT request has been queued
377ae3aad77SStefan Hajnoczi 	 */
378ae3aad77SStefan Hajnoczi 	void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
379ae3aad77SStefan Hajnoczi 		__releases(fiq->lock);
380ae3aad77SStefan Hajnoczi 
381ae3aad77SStefan Hajnoczi 	/**
382ae3aad77SStefan Hajnoczi 	 * Signal that a request has been queued
383ae3aad77SStefan Hajnoczi 	 */
384ae3aad77SStefan Hajnoczi 	void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
385ae3aad77SStefan Hajnoczi 		__releases(fiq->lock);
386ae3aad77SStefan Hajnoczi };
387ae3aad77SStefan Hajnoczi 
388ae3aad77SStefan Hajnoczi /** /dev/fuse input queue operations */
389ae3aad77SStefan Hajnoczi extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
390ae3aad77SStefan Hajnoczi 
391f88996a9SMiklos Szeredi struct fuse_iqueue {
392e16714d8SMiklos Szeredi 	/** Connection established */
393e16714d8SMiklos Szeredi 	unsigned connected;
394e16714d8SMiklos Szeredi 
39576e43c8cSEric Biggers 	/** Lock protecting accesses to members of this structure */
39676e43c8cSEric Biggers 	spinlock_t lock;
39776e43c8cSEric Biggers 
398f88996a9SMiklos Szeredi 	/** Readers of the connection are waiting on this */
399f88996a9SMiklos Szeredi 	wait_queue_head_t waitq;
400f88996a9SMiklos Szeredi 
401f88996a9SMiklos Szeredi 	/** The next unique request id */
402f88996a9SMiklos Szeredi 	u64 reqctr;
403f88996a9SMiklos Szeredi 
404f88996a9SMiklos Szeredi 	/** The list of pending requests */
405f88996a9SMiklos Szeredi 	struct list_head pending;
406f88996a9SMiklos Szeredi 
407f88996a9SMiklos Szeredi 	/** Pending interrupts */
408f88996a9SMiklos Szeredi 	struct list_head interrupts;
409f88996a9SMiklos Szeredi 
410f88996a9SMiklos Szeredi 	/** Queue of pending forgets */
411f88996a9SMiklos Szeredi 	struct fuse_forget_link forget_list_head;
412f88996a9SMiklos Szeredi 	struct fuse_forget_link *forget_list_tail;
413f88996a9SMiklos Szeredi 
414f88996a9SMiklos Szeredi 	/** Batching of FORGET requests (positive indicates FORGET batch) */
415f88996a9SMiklos Szeredi 	int forget_batch;
416f88996a9SMiklos Szeredi 
417f88996a9SMiklos Szeredi 	/** O_ASYNC requests */
418f88996a9SMiklos Szeredi 	struct fasync_struct *fasync;
419ae3aad77SStefan Hajnoczi 
420ae3aad77SStefan Hajnoczi 	/** Device-specific callbacks */
421ae3aad77SStefan Hajnoczi 	const struct fuse_iqueue_ops *ops;
422ae3aad77SStefan Hajnoczi 
423ae3aad77SStefan Hajnoczi 	/** Device-specific state */
424ae3aad77SStefan Hajnoczi 	void *priv;
425f88996a9SMiklos Szeredi };
426f88996a9SMiklos Szeredi 
427be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8
428be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
429be2ff42cSKirill Tkhai 
4303a2b5b9cSMiklos Szeredi struct fuse_pqueue {
431e96edd94SMiklos Szeredi 	/** Connection established */
432e96edd94SMiklos Szeredi 	unsigned connected;
433e96edd94SMiklos Szeredi 
43445a91cb1SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
43545a91cb1SMiklos Szeredi 	spinlock_t lock;
43645a91cb1SMiklos Szeredi 
437be2ff42cSKirill Tkhai 	/** Hash table of requests being processed */
438be2ff42cSKirill Tkhai 	struct list_head *processing;
4393a2b5b9cSMiklos Szeredi 
4403a2b5b9cSMiklos Szeredi 	/** The list of requests under I/O */
4413a2b5b9cSMiklos Szeredi 	struct list_head io;
4423a2b5b9cSMiklos Szeredi };
4433a2b5b9cSMiklos Szeredi 
444d8a5ba45SMiklos Szeredi /**
445cc080e9eSMiklos Szeredi  * Fuse device instance
446cc080e9eSMiklos Szeredi  */
447cc080e9eSMiklos Szeredi struct fuse_dev {
448cc080e9eSMiklos Szeredi 	/** Fuse connection for this device */
449cc080e9eSMiklos Szeredi 	struct fuse_conn *fc;
450cc080e9eSMiklos Szeredi 
451c3696046SMiklos Szeredi 	/** Processing queue */
452c3696046SMiklos Szeredi 	struct fuse_pqueue pq;
453c3696046SMiklos Szeredi 
454cc080e9eSMiklos Szeredi 	/** list entry on fc->devices */
455cc080e9eSMiklos Szeredi 	struct list_head entry;
456cc080e9eSMiklos Szeredi };
457cc080e9eSMiklos Szeredi 
4580cc2656cSStefan Hajnoczi struct fuse_fs_context {
4590cc2656cSStefan Hajnoczi 	int fd;
4600cc2656cSStefan Hajnoczi 	unsigned int rootmode;
4610cc2656cSStefan Hajnoczi 	kuid_t user_id;
4620cc2656cSStefan Hajnoczi 	kgid_t group_id;
4630cc2656cSStefan Hajnoczi 	bool is_bdev:1;
4640cc2656cSStefan Hajnoczi 	bool fd_present:1;
4650cc2656cSStefan Hajnoczi 	bool rootmode_present:1;
4660cc2656cSStefan Hajnoczi 	bool user_id_present:1;
4670cc2656cSStefan Hajnoczi 	bool group_id_present:1;
4680cc2656cSStefan Hajnoczi 	bool default_permissions:1;
4690cc2656cSStefan Hajnoczi 	bool allow_other:1;
470783863d6SMiklos Szeredi 	bool destroy:1;
471*15c8e72eSVivek Goyal 	bool no_control:1;
472*15c8e72eSVivek Goyal 	bool no_force_umount:1;
4730cc2656cSStefan Hajnoczi 	unsigned int max_read;
4740cc2656cSStefan Hajnoczi 	unsigned int blksize;
4750cc2656cSStefan Hajnoczi 	const char *subtype;
4760cc2656cSStefan Hajnoczi 
4770cc2656cSStefan Hajnoczi 	/* fuse_dev pointer to fill in, should contain NULL on entry */
4780cc2656cSStefan Hajnoczi 	void **fudptr;
4790cc2656cSStefan Hajnoczi };
4800cc2656cSStefan Hajnoczi 
481cc080e9eSMiklos Szeredi /**
482d8a5ba45SMiklos Szeredi  * A Fuse connection.
483d8a5ba45SMiklos Szeredi  *
484d8a5ba45SMiklos Szeredi  * This structure is created, when the filesystem is mounted, and is
485d8a5ba45SMiklos Szeredi  * destroyed, when the client device is closed and the filesystem is
486d8a5ba45SMiklos Szeredi  * unmounted.
487d8a5ba45SMiklos Szeredi  */
488d8a5ba45SMiklos Szeredi struct fuse_conn {
489d7133114SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
490d7133114SMiklos Szeredi 	spinlock_t lock;
491d7133114SMiklos Szeredi 
492bafa9654SMiklos Szeredi 	/** Refcount */
493095fc40aSElena Reshetova 	refcount_t count;
494bafa9654SMiklos Szeredi 
495c3696046SMiklos Szeredi 	/** Number of fuse_dev's */
496c3696046SMiklos Szeredi 	atomic_t dev_count;
497c3696046SMiklos Szeredi 
498dd3e2c55SAl Viro 	struct rcu_head rcu;
499dd3e2c55SAl Viro 
500d8a5ba45SMiklos Szeredi 	/** The user id for this mount */
501499dcf20SEric W. Biederman 	kuid_t user_id;
502d8a5ba45SMiklos Szeredi 
50387729a55SMiklos Szeredi 	/** The group id for this mount */
504499dcf20SEric W. Biederman 	kgid_t group_id;
50587729a55SMiklos Szeredi 
5060b6e9ea0SSeth Forshee 	/** The pid namespace for this mount */
5070b6e9ea0SSeth Forshee 	struct pid_namespace *pid_ns;
5080b6e9ea0SSeth Forshee 
5098cb08329SEric W. Biederman 	/** The user namespace for this mount */
5108cb08329SEric W. Biederman 	struct user_namespace *user_ns;
5118cb08329SEric W. Biederman 
512db50b96cSMiklos Szeredi 	/** Maximum read size */
513db50b96cSMiklos Szeredi 	unsigned max_read;
514db50b96cSMiklos Szeredi 
515413ef8cbSMiklos Szeredi 	/** Maximum write size */
516413ef8cbSMiklos Szeredi 	unsigned max_write;
517413ef8cbSMiklos Szeredi 
5185da784ccSConstantine Shulyupin 	/** Maxmum number of pages that can be used in a single request */
5195da784ccSConstantine Shulyupin 	unsigned int max_pages;
5205da784ccSConstantine Shulyupin 
521f88996a9SMiklos Szeredi 	/** Input queue */
522f88996a9SMiklos Szeredi 	struct fuse_iqueue iq;
523334f485dSMiklos Szeredi 
524acf99433STejun Heo 	/** The next unique kernel file handle */
52575126f55SMiklos Szeredi 	atomic64_t khctr;
526acf99433STejun Heo 
52795668a69STejun Heo 	/** rbtree of fuse_files waiting for poll events indexed by ph */
52895668a69STejun Heo 	struct rb_root polled_files;
52995668a69STejun Heo 
5307a6d3c8bSCsaba Henk 	/** Maximum number of outstanding background requests */
5317a6d3c8bSCsaba Henk 	unsigned max_background;
5327a6d3c8bSCsaba Henk 
5337a6d3c8bSCsaba Henk 	/** Number of background requests at which congestion starts */
5347a6d3c8bSCsaba Henk 	unsigned congestion_threshold;
5357a6d3c8bSCsaba Henk 
53608a53cdcSMiklos Szeredi 	/** Number of requests currently in the background */
53708a53cdcSMiklos Szeredi 	unsigned num_background;
53808a53cdcSMiklos Szeredi 
539d12def1bSMiklos Szeredi 	/** Number of background requests currently queued for userspace */
540d12def1bSMiklos Szeredi 	unsigned active_background;
541d12def1bSMiklos Szeredi 
542d12def1bSMiklos Szeredi 	/** The list of background requests set aside for later queuing */
543d12def1bSMiklos Szeredi 	struct list_head bg_queue;
544d12def1bSMiklos Szeredi 
545ae2dffa3SKirill Tkhai 	/** Protects: max_background, congestion_threshold, num_background,
546ae2dffa3SKirill Tkhai 	 * active_background, bg_queue, blocked */
547ae2dffa3SKirill Tkhai 	spinlock_t bg_lock;
548ae2dffa3SKirill Tkhai 
549796523fbSMaxim Patlasov 	/** Flag indicating that INIT reply has been received. Allocating
550796523fbSMaxim Patlasov 	 * any fuse request will be suspended until the flag is set */
551796523fbSMaxim Patlasov 	int initialized;
552796523fbSMaxim Patlasov 
55308a53cdcSMiklos Szeredi 	/** Flag indicating if connection is blocked.  This will be
55408a53cdcSMiklos Szeredi 	    the case before the INIT reply is received, and if there
55508a53cdcSMiklos Szeredi 	    are too many outstading backgrounds requests */
55608a53cdcSMiklos Szeredi 	int blocked;
55708a53cdcSMiklos Szeredi 
55808a53cdcSMiklos Szeredi 	/** waitq for blocked connection */
55908a53cdcSMiklos Szeredi 	wait_queue_head_t blocked_waitq;
56008a53cdcSMiklos Szeredi 
56169a53bf2SMiklos Szeredi 	/** Connection established, cleared on umount, connection
56269a53bf2SMiklos Szeredi 	    abort and device release */
563095da6cbSMiklos Szeredi 	unsigned connected;
5641e9a4ed9SMiklos Szeredi 
5653b7008b2SSzymon Lukasz 	/** Connection aborted via sysfs */
5663b7008b2SSzymon Lukasz 	bool aborted;
5673b7008b2SSzymon Lukasz 
568095da6cbSMiklos Szeredi 	/** Connection failed (version mismatch).  Cannot race with
569095da6cbSMiklos Szeredi 	    setting other bitfields since it is only set once in INIT
570095da6cbSMiklos Szeredi 	    reply, before any other request, and never cleared */
571334f485dSMiklos Szeredi 	unsigned conn_error:1;
572334f485dSMiklos Szeredi 
5730ec7ca41SMiklos Szeredi 	/** Connection successful.  Only set in INIT */
5740ec7ca41SMiklos Szeredi 	unsigned conn_init:1;
5750ec7ca41SMiklos Szeredi 
5769cd68455SMiklos Szeredi 	/** Do readpages asynchronously?  Only set in INIT */
5779cd68455SMiklos Szeredi 	unsigned async_read:1;
5789cd68455SMiklos Szeredi 
5793b7008b2SSzymon Lukasz 	/** Return an unique read error after abort.  Only set in INIT */
5803b7008b2SSzymon Lukasz 	unsigned abort_err:1;
5813b7008b2SSzymon Lukasz 
5826ff958edSMiklos Szeredi 	/** Do not send separate SETATTR request before open(O_TRUNC)  */
5836ff958edSMiklos Szeredi 	unsigned atomic_o_trunc:1;
5846ff958edSMiklos Szeredi 
58533670fa2SMiklos Szeredi 	/** Filesystem supports NFS exporting.  Only set in INIT */
58633670fa2SMiklos Szeredi 	unsigned export_support:1;
58733670fa2SMiklos Szeredi 
588d5cd66c5SPavel Emelyanov 	/** write-back cache policy (default is write-through) */
589d5cd66c5SPavel Emelyanov 	unsigned writeback_cache:1;
590d5cd66c5SPavel Emelyanov 
5915c672ab3SMiklos Szeredi 	/** allow parallel lookups and readdir (default is serialized) */
5925c672ab3SMiklos Szeredi 	unsigned parallel_dirops:1;
5935c672ab3SMiklos Szeredi 
5945e940c1dSMiklos Szeredi 	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
5955e940c1dSMiklos Szeredi 	unsigned handle_killpriv:1;
5965e940c1dSMiklos Szeredi 
5975571f1e6SDan Schatzberg 	/** cache READLINK responses in page cache */
5985571f1e6SDan Schatzberg 	unsigned cache_symlinks:1;
5995571f1e6SDan Schatzberg 
600095da6cbSMiklos Szeredi 	/*
601095da6cbSMiklos Szeredi 	 * The following bitfields are only for optimization purposes
602095da6cbSMiklos Szeredi 	 * and hence races in setting them will not cause malfunction
603095da6cbSMiklos Szeredi 	 */
604095da6cbSMiklos Szeredi 
6057678ac50SAndrew Gallagher 	/** Is open/release not implemented by fs? */
6067678ac50SAndrew Gallagher 	unsigned no_open:1;
6077678ac50SAndrew Gallagher 
608d9a9ea94SChad Austin 	/** Is opendir/releasedir not implemented by fs? */
609d9a9ea94SChad Austin 	unsigned no_opendir:1;
610d9a9ea94SChad Austin 
611b6aeadedSMiklos Szeredi 	/** Is fsync not implemented by fs? */
612b6aeadedSMiklos Szeredi 	unsigned no_fsync:1;
613b6aeadedSMiklos Szeredi 
61482547981SMiklos Szeredi 	/** Is fsyncdir not implemented by fs? */
61582547981SMiklos Szeredi 	unsigned no_fsyncdir:1;
61682547981SMiklos Szeredi 
617b6aeadedSMiklos Szeredi 	/** Is flush not implemented by fs? */
618b6aeadedSMiklos Szeredi 	unsigned no_flush:1;
619b6aeadedSMiklos Szeredi 
62092a8780eSMiklos Szeredi 	/** Is setxattr not implemented by fs? */
62192a8780eSMiklos Szeredi 	unsigned no_setxattr:1;
62292a8780eSMiklos Szeredi 
62392a8780eSMiklos Szeredi 	/** Is getxattr not implemented by fs? */
62492a8780eSMiklos Szeredi 	unsigned no_getxattr:1;
62592a8780eSMiklos Szeredi 
62692a8780eSMiklos Szeredi 	/** Is listxattr not implemented by fs? */
62792a8780eSMiklos Szeredi 	unsigned no_listxattr:1;
62892a8780eSMiklos Szeredi 
62992a8780eSMiklos Szeredi 	/** Is removexattr not implemented by fs? */
63092a8780eSMiklos Szeredi 	unsigned no_removexattr:1;
63192a8780eSMiklos Szeredi 
63237fb3a30SMiklos Szeredi 	/** Are posix file locking primitives not implemented by fs? */
63371421259SMiklos Szeredi 	unsigned no_lock:1;
63471421259SMiklos Szeredi 
63531d40d74SMiklos Szeredi 	/** Is access not implemented by fs? */
63631d40d74SMiklos Szeredi 	unsigned no_access:1;
63731d40d74SMiklos Szeredi 
638fd72faacSMiklos Szeredi 	/** Is create not implemented by fs? */
639fd72faacSMiklos Szeredi 	unsigned no_create:1;
640fd72faacSMiklos Szeredi 
641a4d27e75SMiklos Szeredi 	/** Is interrupt not implemented by fs? */
642a4d27e75SMiklos Szeredi 	unsigned no_interrupt:1;
643a4d27e75SMiklos Szeredi 
644b2d2272fSMiklos Szeredi 	/** Is bmap not implemented by fs? */
645b2d2272fSMiklos Szeredi 	unsigned no_bmap:1;
646b2d2272fSMiklos Szeredi 
64795668a69STejun Heo 	/** Is poll not implemented by fs? */
64895668a69STejun Heo 	unsigned no_poll:1;
64995668a69STejun Heo 
65078bb6cb9SMiklos Szeredi 	/** Do multi-page cached writes */
65178bb6cb9SMiklos Szeredi 	unsigned big_writes:1;
65278bb6cb9SMiklos Szeredi 
653e0a43ddcSMiklos Szeredi 	/** Don't apply umask to creation modes */
654e0a43ddcSMiklos Szeredi 	unsigned dont_mask:1;
655e0a43ddcSMiklos Szeredi 
65637fb3a30SMiklos Szeredi 	/** Are BSD file locking primitives not implemented by fs? */
65737fb3a30SMiklos Szeredi 	unsigned no_flock:1;
65837fb3a30SMiklos Szeredi 
659519c6040SMiklos Szeredi 	/** Is fallocate not implemented by fs? */
660519c6040SMiklos Szeredi 	unsigned no_fallocate:1;
661519c6040SMiklos Szeredi 
6621560c974SMiklos Szeredi 	/** Is rename with flags implemented by fs? */
6631560c974SMiklos Szeredi 	unsigned no_rename2:1;
6641560c974SMiklos Szeredi 
66572d0d248SBrian Foster 	/** Use enhanced/automatic page cache invalidation. */
66672d0d248SBrian Foster 	unsigned auto_inval_data:1;
66772d0d248SBrian Foster 
668ad2ba64dSKirill Smelkov 	/** Filesystem is fully reponsible for page cache invalidation. */
669ad2ba64dSKirill Smelkov 	unsigned explicit_inval_data:1;
670ad2ba64dSKirill Smelkov 
671634734b6SEric Wong 	/** Does the filesystem support readdirplus? */
6720b05b183SAnand V. Avati 	unsigned do_readdirplus:1;
6730b05b183SAnand V. Avati 
674634734b6SEric Wong 	/** Does the filesystem want adaptive readdirplus? */
675634734b6SEric Wong 	unsigned readdirplus_auto:1;
676634734b6SEric Wong 
67760b9df7aSMiklos Szeredi 	/** Does the filesystem support asynchronous direct-IO submission? */
67860b9df7aSMiklos Szeredi 	unsigned async_dio:1;
67960b9df7aSMiklos Szeredi 
6800b5da8dbSRavishankar N 	/** Is lseek not implemented by fs? */
6810b5da8dbSRavishankar N 	unsigned no_lseek:1;
6820b5da8dbSRavishankar N 
68360bcc88aSSeth Forshee 	/** Does the filesystem support posix acls? */
68460bcc88aSSeth Forshee 	unsigned posix_acl:1;
68560bcc88aSSeth Forshee 
68629433a29SMiklos Szeredi 	/** Check permissions based on the file mode or not? */
68729433a29SMiklos Szeredi 	unsigned default_permissions:1;
68829433a29SMiklos Szeredi 
68929433a29SMiklos Szeredi 	/** Allow other than the mounter user to access the filesystem ? */
69029433a29SMiklos Szeredi 	unsigned allow_other:1;
69129433a29SMiklos Szeredi 
69288bc7d50SNiels de Vos 	/** Does the filesystem support copy_file_range? */
69388bc7d50SNiels de Vos 	unsigned no_copy_file_range:1;
69488bc7d50SNiels de Vos 
6951ccd1ea2SMiklos Szeredi 	/* Send DESTROY request */
6961ccd1ea2SMiklos Szeredi 	unsigned int destroy:1;
6971ccd1ea2SMiklos Szeredi 
6988fab0106SMiklos Szeredi 	/* Delete dentries that have gone stale */
6998fab0106SMiklos Szeredi 	unsigned int delete_stale:1;
7008fab0106SMiklos Szeredi 
701*15c8e72eSVivek Goyal 	/** Do not create entry in fusectl fs */
702*15c8e72eSVivek Goyal 	unsigned int no_control:1;
703*15c8e72eSVivek Goyal 
704*15c8e72eSVivek Goyal 	/** Do not allow MNT_FORCE umount */
705*15c8e72eSVivek Goyal 	unsigned int no_force_umount:1;
706*15c8e72eSVivek Goyal 
7070cd5b885SMiklos Szeredi 	/** The number of requests waiting for completion */
7080cd5b885SMiklos Szeredi 	atomic_t num_waiting;
7090cd5b885SMiklos Szeredi 
71045714d65SMiklos Szeredi 	/** Negotiated minor version */
71145714d65SMiklos Szeredi 	unsigned minor;
71245714d65SMiklos Szeredi 
713bafa9654SMiklos Szeredi 	/** Entry on the fuse_conn_list */
714bafa9654SMiklos Szeredi 	struct list_head entry;
715bafa9654SMiklos Szeredi 
716b6f2fcbcSMiklos Szeredi 	/** Device ID from super block */
717b6f2fcbcSMiklos Szeredi 	dev_t dev;
718bafa9654SMiklos Szeredi 
719bafa9654SMiklos Szeredi 	/** Dentries in the control filesystem */
720bafa9654SMiklos Szeredi 	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
721bafa9654SMiklos Szeredi 
722bafa9654SMiklos Szeredi 	/** number of dentries used in the above array */
723bafa9654SMiklos Szeredi 	int ctl_ndents;
724385a17bfSJeff Dike 
7259c8ef561SMiklos Szeredi 	/** Key for lock owner ID scrambling */
7269c8ef561SMiklos Szeredi 	u32 scramble_key[4];
7270ec7ca41SMiklos Szeredi 
7281fb69e78SMiklos Szeredi 	/** Version counter for attribute changes */
7294510d86fSKirill Tkhai 	atomic64_t attr_version;
73043901aabSTejun Heo 
73143901aabSTejun Heo 	/** Called on final put */
73243901aabSTejun Heo 	void (*release)(struct fuse_conn *);
7333b463ae0SJohn Muir 
7343b463ae0SJohn Muir 	/** Super block for this connection. */
7353b463ae0SJohn Muir 	struct super_block *sb;
7363b463ae0SJohn Muir 
7373b463ae0SJohn Muir 	/** Read/write semaphore to hold when accessing sb. */
7383b463ae0SJohn Muir 	struct rw_semaphore killsb;
739cc080e9eSMiklos Szeredi 
740cc080e9eSMiklos Szeredi 	/** List of device instances belonging to this connection */
741cc080e9eSMiklos Szeredi 	struct list_head devices;
742d8a5ba45SMiklos Szeredi };
743d8a5ba45SMiklos Szeredi 
744d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
745d8a5ba45SMiklos Szeredi {
7466383bdaaSMiklos Szeredi 	return sb->s_fs_info;
747d8a5ba45SMiklos Szeredi }
748d8a5ba45SMiklos Szeredi 
749d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
750d8a5ba45SMiklos Szeredi {
751d8a5ba45SMiklos Szeredi 	return get_fuse_conn_super(inode->i_sb);
752d8a5ba45SMiklos Szeredi }
753d8a5ba45SMiklos Szeredi 
754d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
755d8a5ba45SMiklos Szeredi {
756d8a5ba45SMiklos Szeredi 	return container_of(inode, struct fuse_inode, inode);
757d8a5ba45SMiklos Szeredi }
758d8a5ba45SMiklos Szeredi 
759d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode)
760d8a5ba45SMiklos Szeredi {
761d8a5ba45SMiklos Szeredi 	return get_fuse_inode(inode)->nodeid;
762d8a5ba45SMiklos Szeredi }
763d8a5ba45SMiklos Szeredi 
764d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid)
765d123d8e1SMiklos Szeredi {
766d123d8e1SMiklos Szeredi 	return !nodeid || nodeid == FUSE_ROOT_ID;
767d123d8e1SMiklos Szeredi }
768d123d8e1SMiklos Szeredi 
7694510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
7704510d86fSKirill Tkhai {
7714510d86fSKirill Tkhai 	return atomic64_read(&fc->attr_version);
7724510d86fSKirill Tkhai }
7734510d86fSKirill Tkhai 
774334f485dSMiklos Szeredi /** Device operations */
7754b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations;
776334f485dSMiklos Szeredi 
7774269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations;
7780ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations;
779dbd561d2SMiklos Szeredi 
780d8a5ba45SMiklos Szeredi /**
7813b463ae0SJohn Muir  * Inode to nodeid comparison.
7823b463ae0SJohn Muir  */
7833b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp);
7843b463ae0SJohn Muir 
7853b463ae0SJohn Muir /**
786e5e5558eSMiklos Szeredi  * Get a filled in inode
787e5e5558eSMiklos Szeredi  */
788b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
7891fb69e78SMiklos Szeredi 			int generation, struct fuse_attr *attr,
7901fb69e78SMiklos Szeredi 			u64 attr_valid, u64 attr_version);
791e5e5558eSMiklos Szeredi 
79213983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
79333670fa2SMiklos Szeredi 		     struct fuse_entry_out *outarg, struct inode **inode);
79433670fa2SMiklos Szeredi 
795e5e5558eSMiklos Szeredi /**
796e5e5558eSMiklos Szeredi  * Send FORGET command
797e5e5558eSMiklos Szeredi  */
79807e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
799b48badf0SMiklos Szeredi 		       u64 nodeid, u64 nlookup);
800e5e5558eSMiklos Szeredi 
80107e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void);
80207e77dcaSMiklos Szeredi 
8034388c5aaSVivek Goyal struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq,
8044388c5aaSVivek Goyal 					     unsigned int max,
8054388c5aaSVivek Goyal 					     unsigned int *countp);
8064388c5aaSVivek Goyal 
80743f5098eSMiklos Szeredi /*
808361b1eb5SMiklos Szeredi  * Initialize READ or READDIR request
80904730fefSMiklos Szeredi  */
81043f5098eSMiklos Szeredi struct fuse_io_args {
81143f5098eSMiklos Szeredi 	union {
81243f5098eSMiklos Szeredi 		struct {
81343f5098eSMiklos Szeredi 			struct fuse_read_in in;
81443f5098eSMiklos Szeredi 			u64 attr_ver;
81543f5098eSMiklos Szeredi 		} read;
81643f5098eSMiklos Szeredi 		struct {
81743f5098eSMiklos Szeredi 			struct fuse_write_in in;
81843f5098eSMiklos Szeredi 			struct fuse_write_out out;
81943f5098eSMiklos Szeredi 		} write;
82043f5098eSMiklos Szeredi 	};
82143f5098eSMiklos Szeredi 	struct fuse_args_pages ap;
82243f5098eSMiklos Szeredi 	struct fuse_io_priv *io;
82343f5098eSMiklos Szeredi 	struct fuse_file *ff;
82443f5098eSMiklos Szeredi };
82543f5098eSMiklos Szeredi 
82643f5098eSMiklos Szeredi void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
82743f5098eSMiklos Szeredi 			 size_t count, int opcode);
82843f5098eSMiklos Szeredi 
82904730fefSMiklos Szeredi 
83004730fefSMiklos Szeredi /**
83104730fefSMiklos Szeredi  * Send OPEN or OPENDIR request
83204730fefSMiklos Szeredi  */
83391fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
83404730fefSMiklos Szeredi 
835acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
836fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff);
837c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file);
838fd72faacSMiklos Szeredi 
839ebf84d0cSKirill Tkhai void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
840c756e0a4SMiklos Szeredi 
84104730fefSMiklos Szeredi /**
84204730fefSMiklos Szeredi  * Send RELEASE or RELEASEDIR request
84304730fefSMiklos Szeredi  */
8442e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir);
84504730fefSMiklos Szeredi 
84604730fefSMiklos Szeredi /**
84782547981SMiklos Szeredi  * Send FSYNC or FSYNCDIR request
84882547981SMiklos Szeredi  */
84902c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
850a9c2d1e8SMiklos Szeredi 		      int datasync, int opcode);
85182547981SMiklos Szeredi 
85282547981SMiklos Szeredi /**
85395668a69STejun Heo  * Notify poll wakeup
85495668a69STejun Heo  */
85595668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc,
85695668a69STejun Heo 			    struct fuse_notify_poll_wakeup_out *outarg);
85795668a69STejun Heo 
85895668a69STejun Heo /**
8591779381dSMiklos Szeredi  * Initialize file operations on a regular file
860b6aeadedSMiklos Szeredi  */
861b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode);
862b6aeadedSMiklos Szeredi 
863b6aeadedSMiklos Szeredi /**
8641779381dSMiklos Szeredi  * Initialize inode operations on regular files and special files
865e5e5558eSMiklos Szeredi  */
866e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode);
867e5e5558eSMiklos Szeredi 
868e5e5558eSMiklos Szeredi /**
8691779381dSMiklos Szeredi  * Initialize inode and file operations on a directory
870e5e5558eSMiklos Szeredi  */
871e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode);
872e5e5558eSMiklos Szeredi 
873e5e5558eSMiklos Szeredi /**
8741779381dSMiklos Szeredi  * Initialize inode operations on a symlink
875e5e5558eSMiklos Szeredi  */
876e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode);
877e5e5558eSMiklos Szeredi 
878e5e5558eSMiklos Szeredi /**
879e5e5558eSMiklos Szeredi  * Change attributes of an inode
880e5e5558eSMiklos Szeredi  */
8811fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
8821fb69e78SMiklos Szeredi 			    u64 attr_valid, u64 attr_version);
883e5e5558eSMiklos Szeredi 
8843be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
8853be5a52bSMiklos Szeredi 				   u64 attr_valid);
8863be5a52bSMiklos Szeredi 
887e5e5558eSMiklos Szeredi /**
888334f485dSMiklos Szeredi  * Initialize the client device
889334f485dSMiklos Szeredi  */
890334f485dSMiklos Szeredi int fuse_dev_init(void);
891334f485dSMiklos Szeredi 
892334f485dSMiklos Szeredi /**
893334f485dSMiklos Szeredi  * Cleanup the client device
894334f485dSMiklos Szeredi  */
895334f485dSMiklos Szeredi void fuse_dev_cleanup(void);
896334f485dSMiklos Szeredi 
897bafa9654SMiklos Szeredi int fuse_ctl_init(void);
8987736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void);
899bafa9654SMiklos Szeredi 
900334f485dSMiklos Szeredi /**
9017078187aSMiklos Szeredi  * Simple request sending that does request allocation and freeing
9027078187aSMiklos Szeredi  */
9037078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
90412597287SMiklos Szeredi int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,
90512597287SMiklos Szeredi 			   gfp_t gfp_flags);
9067078187aSMiklos Szeredi 
90704ec5af0SStefan Hajnoczi /**
90804ec5af0SStefan Hajnoczi  * End a finished request
90904ec5af0SStefan Hajnoczi  */
91004ec5af0SStefan Hajnoczi void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req);
91104ec5af0SStefan Hajnoczi 
9125a5fb1eaSMiklos Szeredi /* Abort all requests */
913eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc);
914b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc);
91569a53bf2SMiklos Szeredi 
9161e9a4ed9SMiklos Szeredi /**
917e5e5558eSMiklos Szeredi  * Invalidate inode attributes
918e5e5558eSMiklos Szeredi  */
919e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode);
920bafa9654SMiklos Szeredi 
921dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry);
922dbd561d2SMiklos Szeredi 
923451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode);
924451418fcSAndrew Gallagher 
925d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o);
926d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
927d123d8e1SMiklos Szeredi 
928bafa9654SMiklos Szeredi /**
929bafa9654SMiklos Szeredi  * Acquire reference to fuse_conn
930bafa9654SMiklos Szeredi  */
931bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
932bafa9654SMiklos Szeredi 
933bafa9654SMiklos Szeredi /**
9340d179aa5STejun Heo  * Initialize fuse_conn
9350d179aa5STejun Heo  */
936ae3aad77SStefan Hajnoczi void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
937ae3aad77SStefan Hajnoczi 		    const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
9380d179aa5STejun Heo 
9390d179aa5STejun Heo /**
940bafa9654SMiklos Szeredi  * Release reference to fuse_conn
941bafa9654SMiklos Szeredi  */
942bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc);
943bafa9654SMiklos Szeredi 
9440cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
9450cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc(void);
9460cd1eb9aSVivek Goyal void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
947cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud);
94895a84cdbSVivek Goyal void fuse_send_init(struct fuse_conn *fc);
949cc080e9eSMiklos Szeredi 
950bafa9654SMiklos Szeredi /**
9510cc2656cSStefan Hajnoczi  * Fill in superblock and initialize fuse connection
9520cc2656cSStefan Hajnoczi  * @sb: partially-initialized superblock to fill in
9530cc2656cSStefan Hajnoczi  * @ctx: mount context
9540cc2656cSStefan Hajnoczi  */
9550cc2656cSStefan Hajnoczi int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
9560cc2656cSStefan Hajnoczi 
9570cc2656cSStefan Hajnoczi /**
958783863d6SMiklos Szeredi  * Disassociate fuse connection from superblock and kill the superblock
959783863d6SMiklos Szeredi  *
960783863d6SMiklos Szeredi  * Calls kill_anon_super(), do not use with bdev mounts.
961783863d6SMiklos Szeredi  */
962783863d6SMiklos Szeredi void fuse_kill_sb_anon(struct super_block *sb);
963783863d6SMiklos Szeredi 
964783863d6SMiklos Szeredi /**
965bafa9654SMiklos Szeredi  * Add connection to control filesystem
966bafa9654SMiklos Szeredi  */
967bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc);
968bafa9654SMiklos Szeredi 
969bafa9654SMiklos Szeredi /**
970bafa9654SMiklos Szeredi  * Remove connection from control filesystem
971bafa9654SMiklos Szeredi  */
972bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc);
973a5bfffacSTimo Savola 
974a5bfffacSTimo Savola /**
975a5bfffacSTimo Savola  * Is file type valid?
976a5bfffacSTimo Savola  */
977a5bfffacSTimo Savola int fuse_valid_type(int m);
978e57ac683SMiklos Szeredi 
979e57ac683SMiklos Szeredi /**
980c2132c1bSAnatol Pomozov  * Is current process allowed to perform filesystem operation?
981e57ac683SMiklos Szeredi  */
982c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc);
983f3332114SMiklos Szeredi 
984f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
985bcb4be80SMiklos Szeredi 
986703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode);
987703c7362SSeth Forshee 
9885b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file);
9893be5a52bSMiklos Szeredi 
9903be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode);
9913be5a52bSMiklos Szeredi 
9923be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode);
9933be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode);
9945c5c5e51SMiklos Szeredi 
9953b463ae0SJohn Muir /**
9963b463ae0SJohn Muir  * File-system tells the kernel to invalidate cache for the given node id.
9973b463ae0SJohn Muir  */
9983b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
9993b463ae0SJohn Muir 			     loff_t offset, loff_t len);
10003b463ae0SJohn Muir 
10013b463ae0SJohn Muir /**
10023b463ae0SJohn Muir  * File-system tells the kernel to invalidate parent attributes and
10033b463ae0SJohn Muir  * the dentry matching parent/name.
1004451d0f59SJohn Muir  *
1005451d0f59SJohn Muir  * If the child_nodeid is non-zero and:
1006451d0f59SJohn Muir  *    - matches the inode number for the dentry matching parent/name,
1007451d0f59SJohn Muir  *    - is not a mount point
1008451d0f59SJohn Muir  *    - is a file or oan empty directory
1009451d0f59SJohn Muir  * then the dentry is unhashed (d_delete()).
10103b463ae0SJohn Muir  */
10113b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
1012451d0f59SJohn Muir 			     u64 child_nodeid, struct qstr *name);
10133b463ae0SJohn Muir 
101408cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
101508cbf542STejun Heo 		 bool isdir);
1016ea8cd333SPavel Emelyanov 
1017ea8cd333SPavel Emelyanov /**
1018ea8cd333SPavel Emelyanov  * fuse_direct_io() flags
1019ea8cd333SPavel Emelyanov  */
1020ea8cd333SPavel Emelyanov 
1021ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */
1022ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0)
1023ea8cd333SPavel Emelyanov 
1024ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1025ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE  (1 << 1)
1026ea8cd333SPavel Emelyanov 
1027d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1028d22a943fSAl Viro 		       loff_t *ppos, int flags);
102908cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
103008cbf542STejun Heo 		   unsigned int flags);
1031b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd,
1032b18da0c5SMiklos Szeredi 		       unsigned long arg, unsigned int flags);
1033076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait);
103408cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file);
103508cbf542STejun Heo 
1036b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos);
1037b0aa7606SMaxim Patlasov 
1038ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
10391e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1040a1d75f25SMiklos Szeredi 
104162490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1042efb9fa9eSMaxim Patlasov 		    struct file *file);
1043efb9fa9eSMaxim Patlasov 
10449759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc);
10459759bd51SMiklos Szeredi 
104663576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked);
104763576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode);
10485c672ab3SMiklos Szeredi 
104960bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value,
105060bcc88aSSeth Forshee 		  size_t size, int flags);
105160bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
105260bcc88aSSeth Forshee 		      size_t size);
1053703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
105460bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name);
1055703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[];
105660bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1057e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
105860bcc88aSSeth Forshee 
105960bcc88aSSeth Forshee struct posix_acl;
106060bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type);
106160bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
1062703c7362SSeth Forshee 
1063d123d8e1SMiklos Szeredi 
1064d123d8e1SMiklos Szeredi /* readdir.c */
1065d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx);
1066d123d8e1SMiklos Szeredi 
106714d46d7aSStefan Hajnoczi /**
106814d46d7aSStefan Hajnoczi  * Return the number of bytes in an arguments list
106914d46d7aSStefan Hajnoczi  */
107014d46d7aSStefan Hajnoczi unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
107114d46d7aSStefan Hajnoczi 
107279d96effSStefan Hajnoczi /**
107379d96effSStefan Hajnoczi  * Get the next unique ID for a request
107479d96effSStefan Hajnoczi  */
107579d96effSStefan Hajnoczi u64 fuse_get_unique(struct fuse_iqueue *fiq);
1076783863d6SMiklos Szeredi void fuse_free_conn(struct fuse_conn *fc);
107779d96effSStefan Hajnoczi 
107829d434b3STejun Heo #endif /* _FS_FUSE_I_H */
1079