xref: /openbmc/linux/fs/fuse/fuse_i.h (revision fe0a7bd81bfefe5eb73bce55682586c6c266e21e)
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) */
1146b2fb799SMaxim Patlasov 			struct rb_root 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;
151c2d0ad00SVivek Goyal 
1526ae330caSVivek Goyal 	/**
1536ae330caSVivek Goyal 	 * Can't take inode lock in fault path (leads to circular dependency).
1546ae330caSVivek Goyal 	 * Introduce another semaphore which can be taken in fault path and
1556ae330caSVivek Goyal 	 * then other filesystem paths can take this to block faults.
1566ae330caSVivek Goyal 	 */
1576ae330caSVivek Goyal 	struct rw_semaphore i_mmap_sem;
1586ae330caSVivek Goyal 
159c2d0ad00SVivek Goyal #ifdef CONFIG_FUSE_DAX
160c2d0ad00SVivek Goyal 	/*
161c2d0ad00SVivek Goyal 	 * Dax specific inode data
162c2d0ad00SVivek Goyal 	 */
163c2d0ad00SVivek Goyal 	struct fuse_inode_dax *dax;
164c2d0ad00SVivek Goyal #endif
1654582a4abSFeng Shuo };
1664582a4abSFeng Shuo 
1674582a4abSFeng Shuo /** FUSE inode state bits */
1684582a4abSFeng Shuo enum {
1694582a4abSFeng Shuo 	/** Advise readdirplus  */
1704582a4abSFeng Shuo 	FUSE_I_ADVISE_RDPLUS,
1716314efeeSMiklos Szeredi 	/** Initialized with readdirplus */
1726314efeeSMiklos Szeredi 	FUSE_I_INIT_RDPLUS,
17306a7c3c2SMaxim Patlasov 	/** An operation changing file size is in progress  */
17406a7c3c2SMaxim Patlasov 	FUSE_I_SIZE_UNSTABLE,
1755d069dbeSMiklos Szeredi 	/* Bad inode */
1765d069dbeSMiklos Szeredi 	FUSE_I_BAD,
177d8a5ba45SMiklos Szeredi };
178d8a5ba45SMiklos Szeredi 
179da5e4714SMiklos Szeredi struct fuse_conn;
180fcee216bSMax Reitz struct fuse_mount;
1814cb54866SMiklos Szeredi struct fuse_release_args;
182da5e4714SMiklos Szeredi 
183b6aeadedSMiklos Szeredi /** FUSE specific file data */
184b6aeadedSMiklos Szeredi struct fuse_file {
185da5e4714SMiklos Szeredi 	/** Fuse connection for this file */
186fcee216bSMax Reitz 	struct fuse_mount *fm;
187da5e4714SMiklos Szeredi 
1884cb54866SMiklos Szeredi 	/* Argument space reserved for release */
1894cb54866SMiklos Szeredi 	struct fuse_release_args *release_args;
190b6aeadedSMiklos Szeredi 
191acf99433STejun Heo 	/** Kernel file handle guaranteed to be unique */
192acf99433STejun Heo 	u64 kh;
193acf99433STejun Heo 
194b6aeadedSMiklos Szeredi 	/** File handle used by userspace */
195b6aeadedSMiklos Szeredi 	u64 fh;
196c756e0a4SMiklos Szeredi 
197da5e4714SMiklos Szeredi 	/** Node id of this file */
198da5e4714SMiklos Szeredi 	u64 nodeid;
199da5e4714SMiklos Szeredi 
200c756e0a4SMiklos Szeredi 	/** Refcount */
2014e8c2eb5SElena Reshetova 	refcount_t count;
20293a8c3cdSMiklos Szeredi 
203c7b7143cSMiklos Szeredi 	/** FOPEN_* flags returned by open */
204c7b7143cSMiklos Szeredi 	u32 open_flags;
205c7b7143cSMiklos Szeredi 
20693a8c3cdSMiklos Szeredi 	/** Entry on inode's write_files list */
20793a8c3cdSMiklos Szeredi 	struct list_head write_entry;
20895668a69STejun Heo 
2095d7bc7e8SMiklos Szeredi 	/* Readdir related */
2105d7bc7e8SMiklos Szeredi 	struct {
2115d7bc7e8SMiklos Szeredi 		/*
2125d7bc7e8SMiklos Szeredi 		 * Protects below fields against (crazy) parallel readdir on
2135d7bc7e8SMiklos Szeredi 		 * same open file.  Uncontended in the normal case.
2145d7bc7e8SMiklos Szeredi 		 */
2155d7bc7e8SMiklos Szeredi 		struct mutex lock;
2165d7bc7e8SMiklos Szeredi 
2175d7bc7e8SMiklos Szeredi 		/* Dir stream position */
2185d7bc7e8SMiklos Szeredi 		loff_t pos;
2195d7bc7e8SMiklos Szeredi 
2205d7bc7e8SMiklos Szeredi 		/* Offset in cache */
2215d7bc7e8SMiklos Szeredi 		loff_t cache_off;
2223494927eSMiklos Szeredi 
2233494927eSMiklos Szeredi 		/* Version of cache we are reading */
2243494927eSMiklos Szeredi 		u64 version;
2253494927eSMiklos Szeredi 
2265d7bc7e8SMiklos Szeredi 	} readdir;
2275d7bc7e8SMiklos Szeredi 
22895668a69STejun Heo 	/** RB node to be linked on fuse_conn->polled_files */
22995668a69STejun Heo 	struct rb_node polled_node;
23095668a69STejun Heo 
23195668a69STejun Heo 	/** Wait queue head for poll */
23295668a69STejun Heo 	wait_queue_head_t poll_wait;
23337fb3a30SMiklos Szeredi 
23437fb3a30SMiklos Szeredi 	/** Has flock been performed on this file? */
23537fb3a30SMiklos Szeredi 	bool flock:1;
236b6aeadedSMiklos Szeredi };
237b6aeadedSMiklos Szeredi 
238334f485dSMiklos Szeredi /** One input argument of a request */
239334f485dSMiklos Szeredi struct fuse_in_arg {
240334f485dSMiklos Szeredi 	unsigned size;
241334f485dSMiklos Szeredi 	const void *value;
242334f485dSMiklos Szeredi };
243334f485dSMiklos Szeredi 
244334f485dSMiklos Szeredi /** One output argument of a request */
245334f485dSMiklos Szeredi struct fuse_arg {
246334f485dSMiklos Szeredi 	unsigned size;
247334f485dSMiklos Szeredi 	void *value;
248334f485dSMiklos Szeredi };
249334f485dSMiklos Szeredi 
250b2430d75SMaxim Patlasov /** FUSE page descriptor */
251b2430d75SMaxim Patlasov struct fuse_page_desc {
252b2430d75SMaxim Patlasov 	unsigned int length;
253b2430d75SMaxim Patlasov 	unsigned int offset;
254b2430d75SMaxim Patlasov };
255b2430d75SMaxim Patlasov 
2567078187aSMiklos Szeredi struct fuse_args {
2577078187aSMiklos Szeredi 	uint64_t nodeid;
2581f4e9d03SMiklos Szeredi 	uint32_t opcode;
2591f4e9d03SMiklos Szeredi 	unsigned short in_numargs;
2601f4e9d03SMiklos Szeredi 	unsigned short out_numargs;
261c500ebaaSMiklos Szeredi 	bool force:1;
262454a7613SMiklos Szeredi 	bool noreply:1;
263e413754bSMiklos Szeredi 	bool nocreds:1;
26468583165SMiklos Szeredi 	bool in_pages:1;
26568583165SMiklos Szeredi 	bool out_pages:1;
2661f4e9d03SMiklos Szeredi 	bool out_argvar:1;
26768583165SMiklos Szeredi 	bool page_zeroing:1;
26868583165SMiklos Szeredi 	bool page_replace:1;
269bb737bbeSVivek Goyal 	bool may_block:1;
270d5b48543SMiklos Szeredi 	struct fuse_in_arg in_args[3];
271d5b48543SMiklos Szeredi 	struct fuse_arg out_args[2];
272fcee216bSMax Reitz 	void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error);
2737078187aSMiklos Szeredi };
2747078187aSMiklos Szeredi 
27568583165SMiklos Szeredi struct fuse_args_pages {
27668583165SMiklos Szeredi 	struct fuse_args args;
27768583165SMiklos Szeredi 	struct page **pages;
27868583165SMiklos Szeredi 	struct fuse_page_desc *descs;
27968583165SMiklos Szeredi 	unsigned int num_pages;
28068583165SMiklos Szeredi };
28168583165SMiklos Szeredi 
2827078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {}
2837078187aSMiklos Szeredi 
28401e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */
28501e9d11aSMaxim Patlasov struct fuse_io_priv {
286744742d6SSeth Forshee 	struct kref refcnt;
28701e9d11aSMaxim Patlasov 	int async;
28801e9d11aSMaxim Patlasov 	spinlock_t lock;
28901e9d11aSMaxim Patlasov 	unsigned reqs;
29001e9d11aSMaxim Patlasov 	ssize_t bytes;
29101e9d11aSMaxim Patlasov 	size_t size;
29201e9d11aSMaxim Patlasov 	__u64 offset;
29301e9d11aSMaxim Patlasov 	bool write;
29461c12b49SAshish Samant 	bool should_dirty;
29501e9d11aSMaxim Patlasov 	int err;
29601e9d11aSMaxim Patlasov 	struct kiocb *iocb;
2979d5722b7SChristoph Hellwig 	struct completion *done;
2987879c4e5SAshish Sangwan 	bool blocking;
29901e9d11aSMaxim Patlasov };
30001e9d11aSMaxim Patlasov 
301e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \
302744742d6SSeth Forshee {					\
3031e24edcaSPeter Zijlstra 	.refcnt = KREF_INIT(1),		\
304744742d6SSeth Forshee 	.async = 0,			\
305e1c0eecbSMiklos Szeredi 	.iocb = i,			\
306744742d6SSeth Forshee }
307744742d6SSeth Forshee 
308334f485dSMiklos Szeredi /**
309825d6d33SMiklos Szeredi  * Request flags
310825d6d33SMiklos Szeredi  *
311825d6d33SMiklos Szeredi  * FR_ISREPLY:		set if the request has reply
312825d6d33SMiklos Szeredi  * FR_FORCE:		force sending of the request even if interrupted
313825d6d33SMiklos Szeredi  * FR_BACKGROUND:	request is sent in the background
314825d6d33SMiklos Szeredi  * FR_WAITING:		request is counted as "waiting"
315825d6d33SMiklos Szeredi  * FR_ABORTED:		the request was aborted
316825d6d33SMiklos Szeredi  * FR_INTERRUPTED:	the request has been interrupted
317825d6d33SMiklos Szeredi  * FR_LOCKED:		data is being copied to/from the request
31833e14b4dSMiklos Szeredi  * FR_PENDING:		request is not yet in userspace
31933e14b4dSMiklos Szeredi  * FR_SENT:		request is in userspace, waiting for an answer
32033e14b4dSMiklos Szeredi  * FR_FINISHED:		request is finished
32177cd9d48SMiklos Szeredi  * FR_PRIVATE:		request is on private list
3223e8cb8b2SMiklos Szeredi  * FR_ASYNC:		request is asynchronous
323825d6d33SMiklos Szeredi  */
324825d6d33SMiklos Szeredi enum fuse_req_flag {
325825d6d33SMiklos Szeredi 	FR_ISREPLY,
326825d6d33SMiklos Szeredi 	FR_FORCE,
327825d6d33SMiklos Szeredi 	FR_BACKGROUND,
328825d6d33SMiklos Szeredi 	FR_WAITING,
329825d6d33SMiklos Szeredi 	FR_ABORTED,
330825d6d33SMiklos Szeredi 	FR_INTERRUPTED,
331825d6d33SMiklos Szeredi 	FR_LOCKED,
33233e14b4dSMiklos Szeredi 	FR_PENDING,
33333e14b4dSMiklos Szeredi 	FR_SENT,
33433e14b4dSMiklos Szeredi 	FR_FINISHED,
33577cd9d48SMiklos Szeredi 	FR_PRIVATE,
3363e8cb8b2SMiklos Szeredi 	FR_ASYNC,
337825d6d33SMiklos Szeredi };
338825d6d33SMiklos Szeredi 
339825d6d33SMiklos Szeredi /**
340334f485dSMiklos Szeredi  * A request to the client
341dc00809aSMiklos Szeredi  *
342dc00809aSMiklos Szeredi  * .waitq.lock protects the following fields:
343dc00809aSMiklos Szeredi  *   - FR_ABORTED
344dc00809aSMiklos Szeredi  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
345334f485dSMiklos Szeredi  */
346334f485dSMiklos Szeredi struct fuse_req {
347ce1d5a49SMiklos Szeredi 	/** This can be on either pending processing or io lists in
348ce1d5a49SMiklos Szeredi 	    fuse_conn */
349334f485dSMiklos Szeredi 	struct list_head list;
350334f485dSMiklos Szeredi 
351a4d27e75SMiklos Szeredi 	/** Entry on the interrupts list  */
352a4d27e75SMiklos Szeredi 	struct list_head intr_entry;
353a4d27e75SMiklos Szeredi 
35412597287SMiklos Szeredi 	/* Input/output arguments */
35512597287SMiklos Szeredi 	struct fuse_args *args;
35612597287SMiklos Szeredi 
357334f485dSMiklos Szeredi 	/** refcount */
358ec99f6d3SElena Reshetova 	refcount_t count;
359334f485dSMiklos Szeredi 
360825d6d33SMiklos Szeredi 	/* Request flags, updated with test/set/clear_bit() */
361825d6d33SMiklos Szeredi 	unsigned long flags;
3629bc5dddaSMiklos Szeredi 
363d4993774SMiklos Szeredi 	/* The request input header */
364d4993774SMiklos Szeredi 	struct {
365d4993774SMiklos Szeredi 		struct fuse_in_header h;
366d4993774SMiklos Szeredi 	} in;
367334f485dSMiklos Szeredi 
368d4993774SMiklos Szeredi 	/* The request output header */
369d4993774SMiklos Szeredi 	struct {
370d4993774SMiklos Szeredi 		struct fuse_out_header h;
371d4993774SMiklos Szeredi 	} out;
372334f485dSMiklos Szeredi 
373334f485dSMiklos Szeredi 	/** Used to wake up the task waiting for completion of request*/
374334f485dSMiklos Szeredi 	wait_queue_head_t waitq;
375334f485dSMiklos Szeredi 
376a62a8ef9SStefan Hajnoczi #if IS_ENABLED(CONFIG_VIRTIO_FS)
377a62a8ef9SStefan Hajnoczi 	/** virtio-fs's physically contiguous buffer for in and out args */
378a62a8ef9SStefan Hajnoczi 	void *argbuf;
379a62a8ef9SStefan Hajnoczi #endif
38024754db2SMax Reitz 
381fcee216bSMax Reitz 	/** fuse_mount this request belongs to */
382fcee216bSMax Reitz 	struct fuse_mount *fm;
383334f485dSMiklos Szeredi };
384334f485dSMiklos Szeredi 
385ae3aad77SStefan Hajnoczi struct fuse_iqueue;
386ae3aad77SStefan Hajnoczi 
387ae3aad77SStefan Hajnoczi /**
388ae3aad77SStefan Hajnoczi  * Input queue callbacks
389ae3aad77SStefan Hajnoczi  *
390ae3aad77SStefan Hajnoczi  * Input queue signalling is device-specific.  For example, the /dev/fuse file
391ae3aad77SStefan Hajnoczi  * uses fiq->waitq and fasync to wake processes that are waiting on queue
392ae3aad77SStefan Hajnoczi  * readiness.  These callbacks allow other device types to respond to input
393ae3aad77SStefan Hajnoczi  * queue activity.
394ae3aad77SStefan Hajnoczi  */
395ae3aad77SStefan Hajnoczi struct fuse_iqueue_ops {
396ae3aad77SStefan Hajnoczi 	/**
397ae3aad77SStefan Hajnoczi 	 * Signal that a forget has been queued
398ae3aad77SStefan Hajnoczi 	 */
399ae3aad77SStefan Hajnoczi 	void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
400ae3aad77SStefan Hajnoczi 		__releases(fiq->lock);
401ae3aad77SStefan Hajnoczi 
402ae3aad77SStefan Hajnoczi 	/**
403ae3aad77SStefan Hajnoczi 	 * Signal that an INTERRUPT request has been queued
404ae3aad77SStefan Hajnoczi 	 */
405ae3aad77SStefan Hajnoczi 	void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
406ae3aad77SStefan Hajnoczi 		__releases(fiq->lock);
407ae3aad77SStefan Hajnoczi 
408ae3aad77SStefan Hajnoczi 	/**
409ae3aad77SStefan Hajnoczi 	 * Signal that a request has been queued
410ae3aad77SStefan Hajnoczi 	 */
411ae3aad77SStefan Hajnoczi 	void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
412ae3aad77SStefan Hajnoczi 		__releases(fiq->lock);
413a62a8ef9SStefan Hajnoczi 
414a62a8ef9SStefan Hajnoczi 	/**
415a62a8ef9SStefan Hajnoczi 	 * Clean up when fuse_iqueue is destroyed
416a62a8ef9SStefan Hajnoczi 	 */
417a62a8ef9SStefan Hajnoczi 	void (*release)(struct fuse_iqueue *fiq);
418ae3aad77SStefan Hajnoczi };
419ae3aad77SStefan Hajnoczi 
420ae3aad77SStefan Hajnoczi /** /dev/fuse input queue operations */
421ae3aad77SStefan Hajnoczi extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
422ae3aad77SStefan Hajnoczi 
423f88996a9SMiklos Szeredi struct fuse_iqueue {
424e16714d8SMiklos Szeredi 	/** Connection established */
425e16714d8SMiklos Szeredi 	unsigned connected;
426e16714d8SMiklos Szeredi 
42776e43c8cSEric Biggers 	/** Lock protecting accesses to members of this structure */
42876e43c8cSEric Biggers 	spinlock_t lock;
42976e43c8cSEric Biggers 
430f88996a9SMiklos Szeredi 	/** Readers of the connection are waiting on this */
431f88996a9SMiklos Szeredi 	wait_queue_head_t waitq;
432f88996a9SMiklos Szeredi 
433f88996a9SMiklos Szeredi 	/** The next unique request id */
434f88996a9SMiklos Szeredi 	u64 reqctr;
435f88996a9SMiklos Szeredi 
436f88996a9SMiklos Szeredi 	/** The list of pending requests */
437f88996a9SMiklos Szeredi 	struct list_head pending;
438f88996a9SMiklos Szeredi 
439f88996a9SMiklos Szeredi 	/** Pending interrupts */
440f88996a9SMiklos Szeredi 	struct list_head interrupts;
441f88996a9SMiklos Szeredi 
442f88996a9SMiklos Szeredi 	/** Queue of pending forgets */
443f88996a9SMiklos Szeredi 	struct fuse_forget_link forget_list_head;
444f88996a9SMiklos Szeredi 	struct fuse_forget_link *forget_list_tail;
445f88996a9SMiklos Szeredi 
446f88996a9SMiklos Szeredi 	/** Batching of FORGET requests (positive indicates FORGET batch) */
447f88996a9SMiklos Szeredi 	int forget_batch;
448f88996a9SMiklos Szeredi 
449f88996a9SMiklos Szeredi 	/** O_ASYNC requests */
450f88996a9SMiklos Szeredi 	struct fasync_struct *fasync;
451ae3aad77SStefan Hajnoczi 
452ae3aad77SStefan Hajnoczi 	/** Device-specific callbacks */
453ae3aad77SStefan Hajnoczi 	const struct fuse_iqueue_ops *ops;
454ae3aad77SStefan Hajnoczi 
455ae3aad77SStefan Hajnoczi 	/** Device-specific state */
456ae3aad77SStefan Hajnoczi 	void *priv;
457f88996a9SMiklos Szeredi };
458f88996a9SMiklos Szeredi 
459be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8
460be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
461be2ff42cSKirill Tkhai 
4623a2b5b9cSMiklos Szeredi struct fuse_pqueue {
463e96edd94SMiklos Szeredi 	/** Connection established */
464e96edd94SMiklos Szeredi 	unsigned connected;
465e96edd94SMiklos Szeredi 
46645a91cb1SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
46745a91cb1SMiklos Szeredi 	spinlock_t lock;
46845a91cb1SMiklos Szeredi 
469be2ff42cSKirill Tkhai 	/** Hash table of requests being processed */
470be2ff42cSKirill Tkhai 	struct list_head *processing;
4713a2b5b9cSMiklos Szeredi 
4723a2b5b9cSMiklos Szeredi 	/** The list of requests under I/O */
4733a2b5b9cSMiklos Szeredi 	struct list_head io;
4743a2b5b9cSMiklos Szeredi };
4753a2b5b9cSMiklos Szeredi 
476d8a5ba45SMiklos Szeredi /**
477cc080e9eSMiklos Szeredi  * Fuse device instance
478cc080e9eSMiklos Szeredi  */
479cc080e9eSMiklos Szeredi struct fuse_dev {
480cc080e9eSMiklos Szeredi 	/** Fuse connection for this device */
481cc080e9eSMiklos Szeredi 	struct fuse_conn *fc;
482cc080e9eSMiklos Szeredi 
483c3696046SMiklos Szeredi 	/** Processing queue */
484c3696046SMiklos Szeredi 	struct fuse_pqueue pq;
485c3696046SMiklos Szeredi 
486cc080e9eSMiklos Szeredi 	/** list entry on fc->devices */
487cc080e9eSMiklos Szeredi 	struct list_head entry;
488cc080e9eSMiklos Szeredi };
489cc080e9eSMiklos Szeredi 
4900cc2656cSStefan Hajnoczi struct fuse_fs_context {
4910cc2656cSStefan Hajnoczi 	int fd;
4920cc2656cSStefan Hajnoczi 	unsigned int rootmode;
4930cc2656cSStefan Hajnoczi 	kuid_t user_id;
4940cc2656cSStefan Hajnoczi 	kgid_t group_id;
4950cc2656cSStefan Hajnoczi 	bool is_bdev:1;
4960cc2656cSStefan Hajnoczi 	bool fd_present:1;
4970cc2656cSStefan Hajnoczi 	bool rootmode_present:1;
4980cc2656cSStefan Hajnoczi 	bool user_id_present:1;
4990cc2656cSStefan Hajnoczi 	bool group_id_present:1;
5000cc2656cSStefan Hajnoczi 	bool default_permissions:1;
5010cc2656cSStefan Hajnoczi 	bool allow_other:1;
502783863d6SMiklos Szeredi 	bool destroy:1;
50315c8e72eSVivek Goyal 	bool no_control:1;
50415c8e72eSVivek Goyal 	bool no_force_umount:1;
505f4fd4ae3SVivek Goyal 	bool legacy_opts_show:1;
5061dd53957SVivek Goyal 	bool dax:1;
5070cc2656cSStefan Hajnoczi 	unsigned int max_read;
5080cc2656cSStefan Hajnoczi 	unsigned int blksize;
5090cc2656cSStefan Hajnoczi 	const char *subtype;
5100cc2656cSStefan Hajnoczi 
5111dd53957SVivek Goyal 	/* DAX device, may be NULL */
5121dd53957SVivek Goyal 	struct dax_device *dax_dev;
5131dd53957SVivek Goyal 
5140cc2656cSStefan Hajnoczi 	/* fuse_dev pointer to fill in, should contain NULL on entry */
5150cc2656cSStefan Hajnoczi 	void **fudptr;
5160cc2656cSStefan Hajnoczi };
5170cc2656cSStefan Hajnoczi 
518cc080e9eSMiklos Szeredi /**
519d8a5ba45SMiklos Szeredi  * A Fuse connection.
520d8a5ba45SMiklos Szeredi  *
521fcee216bSMax Reitz  * This structure is created, when the root filesystem is mounted, and
522fcee216bSMax Reitz  * is destroyed, when the client device is closed and the last
523fcee216bSMax Reitz  * fuse_mount is destroyed.
524d8a5ba45SMiklos Szeredi  */
525d8a5ba45SMiklos Szeredi struct fuse_conn {
526d7133114SMiklos Szeredi 	/** Lock protecting accessess to  members of this structure */
527d7133114SMiklos Szeredi 	spinlock_t lock;
528d7133114SMiklos Szeredi 
529bafa9654SMiklos Szeredi 	/** Refcount */
530095fc40aSElena Reshetova 	refcount_t count;
531bafa9654SMiklos Szeredi 
532c3696046SMiklos Szeredi 	/** Number of fuse_dev's */
533c3696046SMiklos Szeredi 	atomic_t dev_count;
534c3696046SMiklos Szeredi 
535dd3e2c55SAl Viro 	struct rcu_head rcu;
536dd3e2c55SAl Viro 
537d8a5ba45SMiklos Szeredi 	/** The user id for this mount */
538499dcf20SEric W. Biederman 	kuid_t user_id;
539d8a5ba45SMiklos Szeredi 
54087729a55SMiklos Szeredi 	/** The group id for this mount */
541499dcf20SEric W. Biederman 	kgid_t group_id;
54287729a55SMiklos Szeredi 
5430b6e9ea0SSeth Forshee 	/** The pid namespace for this mount */
5440b6e9ea0SSeth Forshee 	struct pid_namespace *pid_ns;
5450b6e9ea0SSeth Forshee 
5468cb08329SEric W. Biederman 	/** The user namespace for this mount */
5478cb08329SEric W. Biederman 	struct user_namespace *user_ns;
5488cb08329SEric W. Biederman 
549db50b96cSMiklos Szeredi 	/** Maximum read size */
550db50b96cSMiklos Szeredi 	unsigned max_read;
551db50b96cSMiklos Szeredi 
552413ef8cbSMiklos Szeredi 	/** Maximum write size */
553413ef8cbSMiklos Szeredi 	unsigned max_write;
554413ef8cbSMiklos Szeredi 
5554b91459aSConnor Kuehl 	/** Maximum number of pages that can be used in a single request */
5565da784ccSConstantine Shulyupin 	unsigned int max_pages;
5575da784ccSConstantine Shulyupin 
558a7f0d7aaSConnor Kuehl 	/** Constrain ->max_pages to this value during feature negotiation */
559a7f0d7aaSConnor Kuehl 	unsigned int max_pages_limit;
560a7f0d7aaSConnor Kuehl 
561f88996a9SMiklos Szeredi 	/** Input queue */
562f88996a9SMiklos Szeredi 	struct fuse_iqueue iq;
563334f485dSMiklos Szeredi 
564acf99433STejun Heo 	/** The next unique kernel file handle */
56575126f55SMiklos Szeredi 	atomic64_t khctr;
566acf99433STejun Heo 
56795668a69STejun Heo 	/** rbtree of fuse_files waiting for poll events indexed by ph */
56895668a69STejun Heo 	struct rb_root polled_files;
56995668a69STejun Heo 
5707a6d3c8bSCsaba Henk 	/** Maximum number of outstanding background requests */
5717a6d3c8bSCsaba Henk 	unsigned max_background;
5727a6d3c8bSCsaba Henk 
5737a6d3c8bSCsaba Henk 	/** Number of background requests at which congestion starts */
5747a6d3c8bSCsaba Henk 	unsigned congestion_threshold;
5757a6d3c8bSCsaba Henk 
57608a53cdcSMiklos Szeredi 	/** Number of requests currently in the background */
57708a53cdcSMiklos Szeredi 	unsigned num_background;
57808a53cdcSMiklos Szeredi 
579d12def1bSMiklos Szeredi 	/** Number of background requests currently queued for userspace */
580d12def1bSMiklos Szeredi 	unsigned active_background;
581d12def1bSMiklos Szeredi 
582d12def1bSMiklos Szeredi 	/** The list of background requests set aside for later queuing */
583d12def1bSMiklos Szeredi 	struct list_head bg_queue;
584d12def1bSMiklos Szeredi 
585ae2dffa3SKirill Tkhai 	/** Protects: max_background, congestion_threshold, num_background,
586ae2dffa3SKirill Tkhai 	 * active_background, bg_queue, blocked */
587ae2dffa3SKirill Tkhai 	spinlock_t bg_lock;
588ae2dffa3SKirill Tkhai 
589796523fbSMaxim Patlasov 	/** Flag indicating that INIT reply has been received. Allocating
590796523fbSMaxim Patlasov 	 * any fuse request will be suspended until the flag is set */
591796523fbSMaxim Patlasov 	int initialized;
592796523fbSMaxim Patlasov 
59308a53cdcSMiklos Szeredi 	/** Flag indicating if connection is blocked.  This will be
59408a53cdcSMiklos Szeredi 	    the case before the INIT reply is received, and if there
59508a53cdcSMiklos Szeredi 	    are too many outstading backgrounds requests */
59608a53cdcSMiklos Szeredi 	int blocked;
59708a53cdcSMiklos Szeredi 
59808a53cdcSMiklos Szeredi 	/** waitq for blocked connection */
59908a53cdcSMiklos Szeredi 	wait_queue_head_t blocked_waitq;
60008a53cdcSMiklos Szeredi 
60169a53bf2SMiklos Szeredi 	/** Connection established, cleared on umount, connection
60269a53bf2SMiklos Szeredi 	    abort and device release */
603095da6cbSMiklos Szeredi 	unsigned connected;
6041e9a4ed9SMiklos Szeredi 
6053b7008b2SSzymon Lukasz 	/** Connection aborted via sysfs */
6063b7008b2SSzymon Lukasz 	bool aborted;
6073b7008b2SSzymon Lukasz 
608095da6cbSMiklos Szeredi 	/** Connection failed (version mismatch).  Cannot race with
609095da6cbSMiklos Szeredi 	    setting other bitfields since it is only set once in INIT
610095da6cbSMiklos Szeredi 	    reply, before any other request, and never cleared */
611334f485dSMiklos Szeredi 	unsigned conn_error:1;
612334f485dSMiklos Szeredi 
6130ec7ca41SMiklos Szeredi 	/** Connection successful.  Only set in INIT */
6140ec7ca41SMiklos Szeredi 	unsigned conn_init:1;
6150ec7ca41SMiklos Szeredi 
6169cd68455SMiklos Szeredi 	/** Do readpages asynchronously?  Only set in INIT */
6179cd68455SMiklos Szeredi 	unsigned async_read:1;
6189cd68455SMiklos Szeredi 
6193b7008b2SSzymon Lukasz 	/** Return an unique read error after abort.  Only set in INIT */
6203b7008b2SSzymon Lukasz 	unsigned abort_err:1;
6213b7008b2SSzymon Lukasz 
6226ff958edSMiklos Szeredi 	/** Do not send separate SETATTR request before open(O_TRUNC)  */
6236ff958edSMiklos Szeredi 	unsigned atomic_o_trunc:1;
6246ff958edSMiklos Szeredi 
62533670fa2SMiklos Szeredi 	/** Filesystem supports NFS exporting.  Only set in INIT */
62633670fa2SMiklos Szeredi 	unsigned export_support:1;
62733670fa2SMiklos Szeredi 
628d5cd66c5SPavel Emelyanov 	/** write-back cache policy (default is write-through) */
629d5cd66c5SPavel Emelyanov 	unsigned writeback_cache:1;
630d5cd66c5SPavel Emelyanov 
6315c672ab3SMiklos Szeredi 	/** allow parallel lookups and readdir (default is serialized) */
6325c672ab3SMiklos Szeredi 	unsigned parallel_dirops:1;
6335c672ab3SMiklos Szeredi 
6345e940c1dSMiklos Szeredi 	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
6355e940c1dSMiklos Szeredi 	unsigned handle_killpriv:1;
6365e940c1dSMiklos Szeredi 
6375571f1e6SDan Schatzberg 	/** cache READLINK responses in page cache */
6385571f1e6SDan Schatzberg 	unsigned cache_symlinks:1;
6395571f1e6SDan Schatzberg 
640f4fd4ae3SVivek Goyal 	/* show legacy mount options */
641f4fd4ae3SVivek Goyal 	unsigned int legacy_opts_show:1;
642f4fd4ae3SVivek Goyal 
643095da6cbSMiklos Szeredi 	/*
64463f9909fSVivek Goyal 	 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
64563f9909fSVivek Goyal 	 * write/trunc only if caller did not have CAP_FSETID.  sgid is killed
64663f9909fSVivek Goyal 	 * on write/truncate only if caller did not have CAP_FSETID as well as
64763f9909fSVivek Goyal 	 * file has group execute permission.
64863f9909fSVivek Goyal 	 */
64963f9909fSVivek Goyal 	unsigned handle_killpriv_v2:1;
65063f9909fSVivek Goyal 
65163f9909fSVivek Goyal 	/*
652095da6cbSMiklos Szeredi 	 * The following bitfields are only for optimization purposes
653095da6cbSMiklos Szeredi 	 * and hence races in setting them will not cause malfunction
654095da6cbSMiklos Szeredi 	 */
655095da6cbSMiklos Szeredi 
6567678ac50SAndrew Gallagher 	/** Is open/release not implemented by fs? */
6577678ac50SAndrew Gallagher 	unsigned no_open:1;
6587678ac50SAndrew Gallagher 
659d9a9ea94SChad Austin 	/** Is opendir/releasedir not implemented by fs? */
660d9a9ea94SChad Austin 	unsigned no_opendir:1;
661d9a9ea94SChad Austin 
662b6aeadedSMiklos Szeredi 	/** Is fsync not implemented by fs? */
663b6aeadedSMiklos Szeredi 	unsigned no_fsync:1;
664b6aeadedSMiklos Szeredi 
66582547981SMiklos Szeredi 	/** Is fsyncdir not implemented by fs? */
66682547981SMiklos Szeredi 	unsigned no_fsyncdir:1;
66782547981SMiklos Szeredi 
668b6aeadedSMiklos Szeredi 	/** Is flush not implemented by fs? */
669b6aeadedSMiklos Szeredi 	unsigned no_flush:1;
670b6aeadedSMiklos Szeredi 
67192a8780eSMiklos Szeredi 	/** Is setxattr not implemented by fs? */
67292a8780eSMiklos Szeredi 	unsigned no_setxattr:1;
67392a8780eSMiklos Szeredi 
67452a4c95fSVivek Goyal 	/** Does file server support extended setxattr */
67552a4c95fSVivek Goyal 	unsigned setxattr_ext:1;
67652a4c95fSVivek Goyal 
67792a8780eSMiklos Szeredi 	/** Is getxattr not implemented by fs? */
67892a8780eSMiklos Szeredi 	unsigned no_getxattr:1;
67992a8780eSMiklos Szeredi 
68092a8780eSMiklos Szeredi 	/** Is listxattr not implemented by fs? */
68192a8780eSMiklos Szeredi 	unsigned no_listxattr:1;
68292a8780eSMiklos Szeredi 
68392a8780eSMiklos Szeredi 	/** Is removexattr not implemented by fs? */
68492a8780eSMiklos Szeredi 	unsigned no_removexattr:1;
68592a8780eSMiklos Szeredi 
68637fb3a30SMiklos Szeredi 	/** Are posix file locking primitives not implemented by fs? */
68771421259SMiklos Szeredi 	unsigned no_lock:1;
68871421259SMiklos Szeredi 
68931d40d74SMiklos Szeredi 	/** Is access not implemented by fs? */
69031d40d74SMiklos Szeredi 	unsigned no_access:1;
69131d40d74SMiklos Szeredi 
692fd72faacSMiklos Szeredi 	/** Is create not implemented by fs? */
693fd72faacSMiklos Szeredi 	unsigned no_create:1;
694fd72faacSMiklos Szeredi 
695a4d27e75SMiklos Szeredi 	/** Is interrupt not implemented by fs? */
696a4d27e75SMiklos Szeredi 	unsigned no_interrupt:1;
697a4d27e75SMiklos Szeredi 
698b2d2272fSMiklos Szeredi 	/** Is bmap not implemented by fs? */
699b2d2272fSMiklos Szeredi 	unsigned no_bmap:1;
700b2d2272fSMiklos Szeredi 
70195668a69STejun Heo 	/** Is poll not implemented by fs? */
70295668a69STejun Heo 	unsigned no_poll:1;
70395668a69STejun Heo 
70478bb6cb9SMiklos Szeredi 	/** Do multi-page cached writes */
70578bb6cb9SMiklos Szeredi 	unsigned big_writes:1;
70678bb6cb9SMiklos Szeredi 
707e0a43ddcSMiklos Szeredi 	/** Don't apply umask to creation modes */
708e0a43ddcSMiklos Szeredi 	unsigned dont_mask:1;
709e0a43ddcSMiklos Szeredi 
71037fb3a30SMiklos Szeredi 	/** Are BSD file locking primitives not implemented by fs? */
71137fb3a30SMiklos Szeredi 	unsigned no_flock:1;
71237fb3a30SMiklos Szeredi 
713519c6040SMiklos Szeredi 	/** Is fallocate not implemented by fs? */
714519c6040SMiklos Szeredi 	unsigned no_fallocate:1;
715519c6040SMiklos Szeredi 
7161560c974SMiklos Szeredi 	/** Is rename with flags implemented by fs? */
7171560c974SMiklos Szeredi 	unsigned no_rename2:1;
7181560c974SMiklos Szeredi 
71972d0d248SBrian Foster 	/** Use enhanced/automatic page cache invalidation. */
72072d0d248SBrian Foster 	unsigned auto_inval_data:1;
72172d0d248SBrian Foster 
722aa6ff555SBhaskar Chowdhury 	/** Filesystem is fully responsible for page cache invalidation. */
723ad2ba64dSKirill Smelkov 	unsigned explicit_inval_data:1;
724ad2ba64dSKirill Smelkov 
725634734b6SEric Wong 	/** Does the filesystem support readdirplus? */
7260b05b183SAnand V. Avati 	unsigned do_readdirplus:1;
7270b05b183SAnand V. Avati 
728634734b6SEric Wong 	/** Does the filesystem want adaptive readdirplus? */
729634734b6SEric Wong 	unsigned readdirplus_auto:1;
730634734b6SEric Wong 
73160b9df7aSMiklos Szeredi 	/** Does the filesystem support asynchronous direct-IO submission? */
73260b9df7aSMiklos Szeredi 	unsigned async_dio:1;
73360b9df7aSMiklos Szeredi 
7340b5da8dbSRavishankar N 	/** Is lseek not implemented by fs? */
7350b5da8dbSRavishankar N 	unsigned no_lseek:1;
7360b5da8dbSRavishankar N 
73760bcc88aSSeth Forshee 	/** Does the filesystem support posix acls? */
73860bcc88aSSeth Forshee 	unsigned posix_acl:1;
73960bcc88aSSeth Forshee 
74029433a29SMiklos Szeredi 	/** Check permissions based on the file mode or not? */
74129433a29SMiklos Szeredi 	unsigned default_permissions:1;
74229433a29SMiklos Szeredi 
74329433a29SMiklos Szeredi 	/** Allow other than the mounter user to access the filesystem ? */
74429433a29SMiklos Szeredi 	unsigned allow_other:1;
74529433a29SMiklos Szeredi 
74688bc7d50SNiels de Vos 	/** Does the filesystem support copy_file_range? */
74788bc7d50SNiels de Vos 	unsigned no_copy_file_range:1;
74888bc7d50SNiels de Vos 
7491ccd1ea2SMiklos Szeredi 	/* Send DESTROY request */
7501ccd1ea2SMiklos Szeredi 	unsigned int destroy:1;
7511ccd1ea2SMiklos Szeredi 
7528fab0106SMiklos Szeredi 	/* Delete dentries that have gone stale */
7538fab0106SMiklos Szeredi 	unsigned int delete_stale:1;
7548fab0106SMiklos Szeredi 
75515c8e72eSVivek Goyal 	/** Do not create entry in fusectl fs */
75615c8e72eSVivek Goyal 	unsigned int no_control:1;
75715c8e72eSVivek Goyal 
75815c8e72eSVivek Goyal 	/** Do not allow MNT_FORCE umount */
75915c8e72eSVivek Goyal 	unsigned int no_force_umount:1;
76015c8e72eSVivek Goyal 
761bf109c64SMax Reitz 	/* Auto-mount submounts announced by the server */
762bf109c64SMax Reitz 	unsigned int auto_submounts:1;
763bf109c64SMax Reitz 
7642d82ab25SGreg Kurz 	/* Propagate syncfs() to server */
7652d82ab25SGreg Kurz 	unsigned int sync_fs:1;
7662d82ab25SGreg Kurz 
7670cd5b885SMiklos Szeredi 	/** The number of requests waiting for completion */
7680cd5b885SMiklos Szeredi 	atomic_t num_waiting;
7690cd5b885SMiklos Szeredi 
77045714d65SMiklos Szeredi 	/** Negotiated minor version */
77145714d65SMiklos Szeredi 	unsigned minor;
77245714d65SMiklos Szeredi 
773fcee216bSMax Reitz 	/** Entry on the fuse_mount_list */
774bafa9654SMiklos Szeredi 	struct list_head entry;
775bafa9654SMiklos Szeredi 
776fcee216bSMax Reitz 	/** Device ID from the root super block */
777b6f2fcbcSMiklos Szeredi 	dev_t dev;
778bafa9654SMiklos Szeredi 
779bafa9654SMiklos Szeredi 	/** Dentries in the control filesystem */
780bafa9654SMiklos Szeredi 	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
781bafa9654SMiklos Szeredi 
782bafa9654SMiklos Szeredi 	/** number of dentries used in the above array */
783bafa9654SMiklos Szeredi 	int ctl_ndents;
784385a17bfSJeff Dike 
7859c8ef561SMiklos Szeredi 	/** Key for lock owner ID scrambling */
7869c8ef561SMiklos Szeredi 	u32 scramble_key[4];
7870ec7ca41SMiklos Szeredi 
7881fb69e78SMiklos Szeredi 	/** Version counter for attribute changes */
7894510d86fSKirill Tkhai 	atomic64_t attr_version;
79043901aabSTejun Heo 
79143901aabSTejun Heo 	/** Called on final put */
79243901aabSTejun Heo 	void (*release)(struct fuse_conn *);
7933b463ae0SJohn Muir 
794fcee216bSMax Reitz 	/**
795fcee216bSMax Reitz 	 * Read/write semaphore to hold when accessing the sb of any
796fcee216bSMax Reitz 	 * fuse_mount belonging to this connection
797fcee216bSMax Reitz 	 */
7983b463ae0SJohn Muir 	struct rw_semaphore killsb;
799cc080e9eSMiklos Szeredi 
800cc080e9eSMiklos Szeredi 	/** List of device instances belonging to this connection */
801cc080e9eSMiklos Szeredi 	struct list_head devices;
8021dd53957SVivek Goyal 
8031dd53957SVivek Goyal #ifdef CONFIG_FUSE_DAX
8041dd53957SVivek Goyal 	/* Dax specific conn data, non-NULL if DAX is enabled */
8051dd53957SVivek Goyal 	struct fuse_conn_dax *dax;
8061dd53957SVivek Goyal #endif
807fcee216bSMax Reitz 
808fcee216bSMax Reitz 	/** List of filesystems using this connection */
809fcee216bSMax Reitz 	struct list_head mounts;
810d8a5ba45SMiklos Szeredi };
811d8a5ba45SMiklos Szeredi 
812fcee216bSMax Reitz /*
813fcee216bSMax Reitz  * Represents a mounted filesystem, potentially a submount.
814fcee216bSMax Reitz  *
815fcee216bSMax Reitz  * This object allows sharing a fuse_conn between separate mounts to
816fcee216bSMax Reitz  * allow submounts with dedicated superblocks and thus separate device
817fcee216bSMax Reitz  * IDs.
818fcee216bSMax Reitz  */
819fcee216bSMax Reitz struct fuse_mount {
820fcee216bSMax Reitz 	/* Underlying (potentially shared) connection to the FUSE server */
821fcee216bSMax Reitz 	struct fuse_conn *fc;
822fcee216bSMax Reitz 
823fcee216bSMax Reitz 	/*
824fcee216bSMax Reitz 	 * Super block for this connection (fc->killsb must be held when
825fcee216bSMax Reitz 	 * accessing this).
826fcee216bSMax Reitz 	 */
827fcee216bSMax Reitz 	struct super_block *sb;
828fcee216bSMax Reitz 
829fcee216bSMax Reitz 	/* Entry on fc->mounts */
830fcee216bSMax Reitz 	struct list_head fc_entry;
831fcee216bSMax Reitz };
832fcee216bSMax Reitz 
833fcee216bSMax Reitz static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb)
834d8a5ba45SMiklos Szeredi {
8356383bdaaSMiklos Szeredi 	return sb->s_fs_info;
836d8a5ba45SMiklos Szeredi }
837d8a5ba45SMiklos Szeredi 
838fcee216bSMax Reitz static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
839fcee216bSMax Reitz {
840bd3bf1e8SMiklos Szeredi 	return get_fuse_mount_super(sb)->fc;
841fcee216bSMax Reitz }
842fcee216bSMax Reitz 
843fcee216bSMax Reitz static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
844fcee216bSMax Reitz {
845fcee216bSMax Reitz 	return get_fuse_mount_super(inode->i_sb);
846fcee216bSMax Reitz }
847fcee216bSMax Reitz 
848d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
849d8a5ba45SMiklos Szeredi {
850bd3bf1e8SMiklos Szeredi 	return get_fuse_mount_super(inode->i_sb)->fc;
851d8a5ba45SMiklos Szeredi }
852d8a5ba45SMiklos Szeredi 
853d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
854d8a5ba45SMiklos Szeredi {
855d8a5ba45SMiklos Szeredi 	return container_of(inode, struct fuse_inode, inode);
856d8a5ba45SMiklos Szeredi }
857d8a5ba45SMiklos Szeredi 
858d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode)
859d8a5ba45SMiklos Szeredi {
860d8a5ba45SMiklos Szeredi 	return get_fuse_inode(inode)->nodeid;
861d8a5ba45SMiklos Szeredi }
862d8a5ba45SMiklos Szeredi 
863d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid)
864d123d8e1SMiklos Szeredi {
865d123d8e1SMiklos Szeredi 	return !nodeid || nodeid == FUSE_ROOT_ID;
866d123d8e1SMiklos Szeredi }
867d123d8e1SMiklos Szeredi 
8684510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
8694510d86fSKirill Tkhai {
8704510d86fSKirill Tkhai 	return atomic64_read(&fc->attr_version);
8714510d86fSKirill Tkhai }
8724510d86fSKirill Tkhai 
8735d069dbeSMiklos Szeredi static inline void fuse_make_bad(struct inode *inode)
8745d069dbeSMiklos Szeredi {
875775c5033SAmir Goldstein 	remove_inode_hash(inode);
8765d069dbeSMiklos Szeredi 	set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state);
8775d069dbeSMiklos Szeredi }
8785d069dbeSMiklos Szeredi 
8795d069dbeSMiklos Szeredi static inline bool fuse_is_bad(struct inode *inode)
8805d069dbeSMiklos Szeredi {
8815d069dbeSMiklos Szeredi 	return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
8825d069dbeSMiklos Szeredi }
8835d069dbeSMiklos Szeredi 
8849ac29fd3SMiklos Szeredi static inline struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
8859ac29fd3SMiklos Szeredi 					     struct fuse_page_desc **desc)
8869ac29fd3SMiklos Szeredi {
8879ac29fd3SMiklos Szeredi 	struct page **pages;
8889ac29fd3SMiklos Szeredi 
8899ac29fd3SMiklos Szeredi 	pages = kzalloc(npages * (sizeof(struct page *) +
8909ac29fd3SMiklos Szeredi 				  sizeof(struct fuse_page_desc)), flags);
8919ac29fd3SMiklos Szeredi 	*desc = (void *) (pages + npages);
8929ac29fd3SMiklos Szeredi 
8939ac29fd3SMiklos Szeredi 	return pages;
8949ac29fd3SMiklos Szeredi }
8959ac29fd3SMiklos Szeredi 
8969ac29fd3SMiklos Szeredi static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs,
8979ac29fd3SMiklos Szeredi 					       unsigned int index,
8989ac29fd3SMiklos Szeredi 					       unsigned int nr_pages)
8999ac29fd3SMiklos Szeredi {
9009ac29fd3SMiklos Szeredi 	int i;
9019ac29fd3SMiklos Szeredi 
9029ac29fd3SMiklos Szeredi 	for (i = index; i < index + nr_pages; i++)
9039ac29fd3SMiklos Szeredi 		descs[i].length = PAGE_SIZE - descs[i].offset;
9049ac29fd3SMiklos Szeredi }
9059ac29fd3SMiklos Szeredi 
906334f485dSMiklos Szeredi /** Device operations */
9074b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations;
908334f485dSMiklos Szeredi 
9094269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations;
9100ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations;
911dbd561d2SMiklos Szeredi 
912d8a5ba45SMiklos Szeredi /**
913e5e5558eSMiklos Szeredi  * Get a filled in inode
914e5e5558eSMiklos Szeredi  */
915b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
9161fb69e78SMiklos Szeredi 			int generation, struct fuse_attr *attr,
9171fb69e78SMiklos Szeredi 			u64 attr_valid, u64 attr_version);
918e5e5558eSMiklos Szeredi 
91913983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
92033670fa2SMiklos Szeredi 		     struct fuse_entry_out *outarg, struct inode **inode);
92133670fa2SMiklos Szeredi 
922e5e5558eSMiklos Szeredi /**
923e5e5558eSMiklos Szeredi  * Send FORGET command
924e5e5558eSMiklos Szeredi  */
92507e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
926b48badf0SMiklos Szeredi 		       u64 nodeid, u64 nlookup);
927e5e5558eSMiklos Szeredi 
92807e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void);
92907e77dcaSMiklos Szeredi 
9304388c5aaSVivek Goyal struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq,
9314388c5aaSVivek Goyal 					     unsigned int max,
9324388c5aaSVivek Goyal 					     unsigned int *countp);
9334388c5aaSVivek Goyal 
93443f5098eSMiklos Szeredi /*
935361b1eb5SMiklos Szeredi  * Initialize READ or READDIR request
93604730fefSMiklos Szeredi  */
93743f5098eSMiklos Szeredi struct fuse_io_args {
93843f5098eSMiklos Szeredi 	union {
93943f5098eSMiklos Szeredi 		struct {
94043f5098eSMiklos Szeredi 			struct fuse_read_in in;
94143f5098eSMiklos Szeredi 			u64 attr_ver;
94243f5098eSMiklos Szeredi 		} read;
94343f5098eSMiklos Szeredi 		struct {
94443f5098eSMiklos Szeredi 			struct fuse_write_in in;
94543f5098eSMiklos Szeredi 			struct fuse_write_out out;
9464f06dd92SVivek Goyal 			bool page_locked;
94743f5098eSMiklos Szeredi 		} write;
94843f5098eSMiklos Szeredi 	};
94943f5098eSMiklos Szeredi 	struct fuse_args_pages ap;
95043f5098eSMiklos Szeredi 	struct fuse_io_priv *io;
95143f5098eSMiklos Szeredi 	struct fuse_file *ff;
95243f5098eSMiklos Szeredi };
95343f5098eSMiklos Szeredi 
95443f5098eSMiklos Szeredi void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
95543f5098eSMiklos Szeredi 			 size_t count, int opcode);
95643f5098eSMiklos Szeredi 
95704730fefSMiklos Szeredi 
95804730fefSMiklos Szeredi /**
95904730fefSMiklos Szeredi  * Send OPEN or OPENDIR request
96004730fefSMiklos Szeredi  */
96191fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
96204730fefSMiklos Szeredi 
963fcee216bSMax Reitz struct fuse_file *fuse_file_alloc(struct fuse_mount *fm);
964fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff);
965c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file);
966fd72faacSMiklos Szeredi 
96754d601cbSMiklos Szeredi void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff,
96854d601cbSMiklos Szeredi 		       unsigned int flags);
969c756e0a4SMiklos Szeredi 
97004730fefSMiklos Szeredi /**
97104730fefSMiklos Szeredi  * Send RELEASE or RELEASEDIR request
97204730fefSMiklos Szeredi  */
9732e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir);
97404730fefSMiklos Szeredi 
97504730fefSMiklos Szeredi /**
97682547981SMiklos Szeredi  * Send FSYNC or FSYNCDIR request
97782547981SMiklos Szeredi  */
97802c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
979a9c2d1e8SMiklos Szeredi 		      int datasync, int opcode);
98082547981SMiklos Szeredi 
98182547981SMiklos Szeredi /**
98295668a69STejun Heo  * Notify poll wakeup
98395668a69STejun Heo  */
98495668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc,
98595668a69STejun Heo 			    struct fuse_notify_poll_wakeup_out *outarg);
98695668a69STejun Heo 
98795668a69STejun Heo /**
9881779381dSMiklos Szeredi  * Initialize file operations on a regular file
989b6aeadedSMiklos Szeredi  */
990b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode);
991b6aeadedSMiklos Szeredi 
992b6aeadedSMiklos Szeredi /**
9931779381dSMiklos Szeredi  * Initialize inode operations on regular files and special files
994e5e5558eSMiklos Szeredi  */
995e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode);
996e5e5558eSMiklos Szeredi 
997e5e5558eSMiklos Szeredi /**
9981779381dSMiklos Szeredi  * Initialize inode and file operations on a directory
999e5e5558eSMiklos Szeredi  */
1000e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode);
1001e5e5558eSMiklos Szeredi 
1002e5e5558eSMiklos Szeredi /**
10031779381dSMiklos Szeredi  * Initialize inode operations on a symlink
1004e5e5558eSMiklos Szeredi  */
1005e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode);
1006e5e5558eSMiklos Szeredi 
1007e5e5558eSMiklos Szeredi /**
1008e5e5558eSMiklos Szeredi  * Change attributes of an inode
1009e5e5558eSMiklos Szeredi  */
10101fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
10111fb69e78SMiklos Szeredi 			    u64 attr_valid, u64 attr_version);
1012e5e5558eSMiklos Szeredi 
10133be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
10143be5a52bSMiklos Szeredi 				   u64 attr_valid);
10153be5a52bSMiklos Szeredi 
1016e5e5558eSMiklos Szeredi /**
1017334f485dSMiklos Szeredi  * Initialize the client device
1018334f485dSMiklos Szeredi  */
1019334f485dSMiklos Szeredi int fuse_dev_init(void);
1020334f485dSMiklos Szeredi 
1021334f485dSMiklos Szeredi /**
1022334f485dSMiklos Szeredi  * Cleanup the client device
1023334f485dSMiklos Szeredi  */
1024334f485dSMiklos Szeredi void fuse_dev_cleanup(void);
1025334f485dSMiklos Szeredi 
1026bafa9654SMiklos Szeredi int fuse_ctl_init(void);
10277736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void);
1028bafa9654SMiklos Szeredi 
1029334f485dSMiklos Szeredi /**
10307078187aSMiklos Szeredi  * Simple request sending that does request allocation and freeing
10317078187aSMiklos Szeredi  */
1032fcee216bSMax Reitz ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args);
1033fcee216bSMax Reitz int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
103412597287SMiklos Szeredi 			   gfp_t gfp_flags);
10357078187aSMiklos Szeredi 
103604ec5af0SStefan Hajnoczi /**
103704ec5af0SStefan Hajnoczi  * End a finished request
103804ec5af0SStefan Hajnoczi  */
10398f622e94SMax Reitz void fuse_request_end(struct fuse_req *req);
104004ec5af0SStefan Hajnoczi 
10415a5fb1eaSMiklos Szeredi /* Abort all requests */
1042eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc);
1043b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc);
104469a53bf2SMiklos Szeredi 
10451e9a4ed9SMiklos Szeredi /**
1046e5e5558eSMiklos Szeredi  * Invalidate inode attributes
1047e5e5558eSMiklos Szeredi  */
1048e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode);
1049bafa9654SMiklos Szeredi 
1050dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry);
1051dbd561d2SMiklos Szeredi 
1052451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode);
1053451418fcSAndrew Gallagher 
1054d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o);
1055d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
1056d123d8e1SMiklos Szeredi 
1057bafa9654SMiklos Szeredi /**
1058bafa9654SMiklos Szeredi  * Acquire reference to fuse_conn
1059bafa9654SMiklos Szeredi  */
1060bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
1061bafa9654SMiklos Szeredi 
1062bafa9654SMiklos Szeredi /**
10630d179aa5STejun Heo  * Initialize fuse_conn
10640d179aa5STejun Heo  */
1065fcee216bSMax Reitz void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
1066fcee216bSMax Reitz 		    struct user_namespace *user_ns,
1067ae3aad77SStefan Hajnoczi 		    const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
10680d179aa5STejun Heo 
10690d179aa5STejun Heo /**
1070bafa9654SMiklos Szeredi  * Release reference to fuse_conn
1071bafa9654SMiklos Szeredi  */
1072bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc);
1073bafa9654SMiklos Szeredi 
10740cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
10750cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc(void);
10760cd1eb9aSVivek Goyal void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
1077cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud);
1078fcee216bSMax Reitz void fuse_send_init(struct fuse_mount *fm);
1079cc080e9eSMiklos Szeredi 
1080bafa9654SMiklos Szeredi /**
10810cc2656cSStefan Hajnoczi  * Fill in superblock and initialize fuse connection
10820cc2656cSStefan Hajnoczi  * @sb: partially-initialized superblock to fill in
10830cc2656cSStefan Hajnoczi  * @ctx: mount context
10840cc2656cSStefan Hajnoczi  */
10850cc2656cSStefan Hajnoczi int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
10860cc2656cSStefan Hajnoczi 
10871866d779SMax Reitz /*
10881866d779SMax Reitz  * Fill in superblock for submounts
10891866d779SMax Reitz  * @sb: partially-initialized superblock to fill in
10901866d779SMax Reitz  * @parent_fi: The fuse_inode of the parent filesystem where this submount is
10911866d779SMax Reitz  * 	       mounted
10921866d779SMax Reitz  */
10931866d779SMax Reitz int fuse_fill_super_submount(struct super_block *sb,
10941866d779SMax Reitz 			     struct fuse_inode *parent_fi);
1095fcee216bSMax Reitz 
1096fcee216bSMax Reitz /*
1097fcee216bSMax Reitz  * Remove the mount from the connection
1098783863d6SMiklos Szeredi  *
1099fcee216bSMax Reitz  * Returns whether this was the last mount
1100783863d6SMiklos Szeredi  */
1101fcee216bSMax Reitz bool fuse_mount_remove(struct fuse_mount *fm);
1102fcee216bSMax Reitz 
1103fcee216bSMax Reitz /*
1104*fe0a7bd8SGreg Kurz  * Setup context ops for submounts
1105*fe0a7bd8SGreg Kurz  */
1106*fe0a7bd8SGreg Kurz int fuse_init_fs_context_submount(struct fs_context *fsc);
1107*fe0a7bd8SGreg Kurz 
1108*fe0a7bd8SGreg Kurz /*
1109fcee216bSMax Reitz  * Shut down the connection (possibly sending DESTROY request).
1110fcee216bSMax Reitz  */
1111fcee216bSMax Reitz void fuse_conn_destroy(struct fuse_mount *fm);
1112783863d6SMiklos Szeredi 
1113783863d6SMiklos Szeredi /**
1114bafa9654SMiklos Szeredi  * Add connection to control filesystem
1115bafa9654SMiklos Szeredi  */
1116bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc);
1117bafa9654SMiklos Szeredi 
1118bafa9654SMiklos Szeredi /**
1119bafa9654SMiklos Szeredi  * Remove connection from control filesystem
1120bafa9654SMiklos Szeredi  */
1121bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc);
1122a5bfffacSTimo Savola 
1123a5bfffacSTimo Savola /**
1124a5bfffacSTimo Savola  * Is file type valid?
1125a5bfffacSTimo Savola  */
1126a5bfffacSTimo Savola int fuse_valid_type(int m);
1127e57ac683SMiklos Szeredi 
1128eb59bd17SMiklos Szeredi bool fuse_invalid_attr(struct fuse_attr *attr);
1129eb59bd17SMiklos Szeredi 
1130e57ac683SMiklos Szeredi /**
1131c2132c1bSAnatol Pomozov  * Is current process allowed to perform filesystem operation?
1132e57ac683SMiklos Szeredi  */
1133c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc);
1134f3332114SMiklos Szeredi 
1135f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
1136bcb4be80SMiklos Szeredi 
1137703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode);
1138703c7362SSeth Forshee 
11395b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file);
11403be5a52bSMiklos Szeredi 
11413be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode);
11423be5a52bSMiklos Szeredi 
11433be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode);
11443be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode);
11455c5c5e51SMiklos Szeredi 
11463b463ae0SJohn Muir /**
1147fcee216bSMax Reitz  * Scan all fuse_mounts belonging to fc to find the first where
1148fcee216bSMax Reitz  * ilookup5() returns a result.  Return that result and the
1149fcee216bSMax Reitz  * respective fuse_mount in *fm (unless fm is NULL).
1150fcee216bSMax Reitz  *
1151fcee216bSMax Reitz  * The caller must hold fc->killsb.
1152fcee216bSMax Reitz  */
1153fcee216bSMax Reitz struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
1154fcee216bSMax Reitz 			   struct fuse_mount **fm);
1155fcee216bSMax Reitz 
1156fcee216bSMax Reitz /**
11573b463ae0SJohn Muir  * File-system tells the kernel to invalidate cache for the given node id.
11583b463ae0SJohn Muir  */
1159fcee216bSMax Reitz int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
11603b463ae0SJohn Muir 			     loff_t offset, loff_t len);
11613b463ae0SJohn Muir 
11623b463ae0SJohn Muir /**
11633b463ae0SJohn Muir  * File-system tells the kernel to invalidate parent attributes and
11643b463ae0SJohn Muir  * the dentry matching parent/name.
1165451d0f59SJohn Muir  *
1166451d0f59SJohn Muir  * If the child_nodeid is non-zero and:
1167451d0f59SJohn Muir  *    - matches the inode number for the dentry matching parent/name,
1168451d0f59SJohn Muir  *    - is not a mount point
1169451d0f59SJohn Muir  *    - is a file or oan empty directory
1170451d0f59SJohn Muir  * then the dentry is unhashed (d_delete()).
11713b463ae0SJohn Muir  */
1172fcee216bSMax Reitz int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
1173451d0f59SJohn Muir 			     u64 child_nodeid, struct qstr *name);
11743b463ae0SJohn Muir 
1175fcee216bSMax Reitz int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
117608cbf542STejun Heo 		 bool isdir);
1177ea8cd333SPavel Emelyanov 
1178ea8cd333SPavel Emelyanov /**
1179ea8cd333SPavel Emelyanov  * fuse_direct_io() flags
1180ea8cd333SPavel Emelyanov  */
1181ea8cd333SPavel Emelyanov 
1182ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */
1183ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0)
1184ea8cd333SPavel Emelyanov 
1185ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1186ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE  (1 << 1)
1187ea8cd333SPavel Emelyanov 
1188d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1189d22a943fSAl Viro 		       loff_t *ppos, int flags);
119008cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
119108cbf542STejun Heo 		   unsigned int flags);
1192b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd,
1193b18da0c5SMiklos Szeredi 		       unsigned long arg, unsigned int flags);
1194076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait);
119508cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file);
119608cbf542STejun Heo 
1197b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos);
1198b0aa7606SMaxim Patlasov 
1199ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
12001e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1201a1d75f25SMiklos Szeredi 
120262490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1203efb9fa9eSMaxim Patlasov 		    struct file *file);
1204efb9fa9eSMaxim Patlasov 
12059759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc);
12069759bd51SMiklos Szeredi 
120763576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked);
120863576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode);
12095c672ab3SMiklos Szeredi 
121060bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value,
121152a4c95fSVivek Goyal 		  size_t size, int flags, unsigned int extra_flags);
121260bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
121360bcc88aSSeth Forshee 		      size_t size);
1214703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
121560bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name);
1216703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[];
121760bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1218e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
121960bcc88aSSeth Forshee 
122060bcc88aSSeth Forshee struct posix_acl;
122160bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type);
1222549c7297SChristian Brauner int fuse_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
1223549c7297SChristian Brauner 		 struct posix_acl *acl, int type);
1224d123d8e1SMiklos Szeredi 
1225d123d8e1SMiklos Szeredi /* readdir.c */
1226d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx);
1227d123d8e1SMiklos Szeredi 
122814d46d7aSStefan Hajnoczi /**
122914d46d7aSStefan Hajnoczi  * Return the number of bytes in an arguments list
123014d46d7aSStefan Hajnoczi  */
123114d46d7aSStefan Hajnoczi unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
123214d46d7aSStefan Hajnoczi 
123379d96effSStefan Hajnoczi /**
123479d96effSStefan Hajnoczi  * Get the next unique ID for a request
123579d96effSStefan Hajnoczi  */
123679d96effSStefan Hajnoczi u64 fuse_get_unique(struct fuse_iqueue *fiq);
1237783863d6SMiklos Szeredi void fuse_free_conn(struct fuse_conn *fc);
123879d96effSStefan Hajnoczi 
12391dd53957SVivek Goyal /* dax.c */
12401dd53957SVivek Goyal 
1241c2d0ad00SVivek Goyal #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1242c2d0ad00SVivek Goyal 
1243c2d0ad00SVivek Goyal ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
1244c2d0ad00SVivek Goyal ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
1245c2d0ad00SVivek Goyal int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
12466ae330caSVivek Goyal int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
12471dd53957SVivek Goyal int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev);
12481dd53957SVivek Goyal void fuse_dax_conn_free(struct fuse_conn *fc);
1249c2d0ad00SVivek Goyal bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
1250c2d0ad00SVivek Goyal void fuse_dax_inode_init(struct inode *inode);
1251c2d0ad00SVivek Goyal void fuse_dax_inode_cleanup(struct inode *inode);
1252fd1a1dc6SStefan Hajnoczi bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
12539a752d18SVivek Goyal void fuse_dax_cancel_work(struct fuse_conn *fc);
12541dd53957SVivek Goyal 
12559ac29fd3SMiklos Szeredi /* ioctl.c */
12569ac29fd3SMiklos Szeredi long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
12579ac29fd3SMiklos Szeredi long fuse_file_compat_ioctl(struct file *file, unsigned int cmd,
12589ac29fd3SMiklos Szeredi 			    unsigned long arg);
125972227eacSMiklos Szeredi int fuse_fileattr_get(struct dentry *dentry, struct fileattr *fa);
126072227eacSMiklos Szeredi int fuse_fileattr_set(struct user_namespace *mnt_userns,
126172227eacSMiklos Szeredi 		      struct dentry *dentry, struct fileattr *fa);
12629ac29fd3SMiklos Szeredi 
1263b9d54c6fSMiklos Szeredi /* file.c */
1264b9d54c6fSMiklos Szeredi 
1265b9d54c6fSMiklos Szeredi struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,
1266b9d54c6fSMiklos Szeredi 				 unsigned int open_flags, bool isdir);
1267b9d54c6fSMiklos Szeredi void fuse_file_release(struct inode *inode, struct fuse_file *ff,
1268b9d54c6fSMiklos Szeredi 		       unsigned int open_flags, fl_owner_t id, bool isdir);
1269b9d54c6fSMiklos Szeredi 
127029d434b3STejun Heo #endif /* _FS_FUSE_I_H */
1271