xref: /linux/fs/fuse/fuse_i.h (revision acf6c670e476304c89b5e9320ca8f9d20c9e0aa8) !
1 /*
2   FUSE: Filesystem in Userspace
3   Copyright (C) 2001-2008  Miklos Szeredi <miklos@szeredi.hu>
4 
5   This program can be distributed under the terms of the GNU GPL.
6   See the file COPYING.
7 */
8 
9 #ifndef _FS_FUSE_I_H
10 #define _FS_FUSE_I_H
11 
12 #ifndef pr_fmt
13 # define pr_fmt(fmt) "fuse: " fmt
14 #endif
15 
16 #include <linux/fuse.h>
17 #include <linux/fs.h>
18 #include <linux/mount.h>
19 #include <linux/wait.h>
20 #include <linux/list.h>
21 #include <linux/spinlock.h>
22 #include <linux/mm.h>
23 #include <linux/backing-dev.h>
24 #include <linux/mutex.h>
25 #include <linux/rwsem.h>
26 #include <linux/rbtree.h>
27 #include <linux/poll.h>
28 #include <linux/workqueue.h>
29 #include <linux/kref.h>
30 #include <linux/xattr.h>
31 #include <linux/pid_namespace.h>
32 #include <linux/refcount.h>
33 #include <linux/user_namespace.h>
34 
35 /** Default max number of pages that can be used in a single read request */
36 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
37 
38 /** Bias for fi->writectr, meaning new writepages must not be sent */
39 #define FUSE_NOWRITE INT_MIN
40 
41 /** Maximum length of a filename, not including terminating null */
42 
43 /* maximum, small enough for FUSE_MIN_READ_BUFFER*/
44 #define FUSE_NAME_LOW_MAX 1024
45 /* maximum, but needs a request buffer > FUSE_MIN_READ_BUFFER */
46 #define FUSE_NAME_MAX (PATH_MAX - 1)
47 
48 /** Number of dentries for each connection in the control filesystem */
49 #define FUSE_CTL_NUM_DENTRIES 5
50 
51 /* Frequency (in seconds) of request timeout checks, if opted into */
52 #define FUSE_TIMEOUT_TIMER_FREQ 15
53 
54 /** Frequency (in jiffies) of request timeout checks, if opted into */
55 extern const unsigned long fuse_timeout_timer_freq;
56 
57 /*
58  * Dentries invalidation workqueue period, in seconds.  The value of this
59  * parameter shall be >= FUSE_DENTRY_INVAL_FREQ_MIN seconds, or 0 (zero), in
60  * which case no workqueue will be created.
61  */
62 extern unsigned inval_wq __read_mostly;
63 
64 /** Maximum of max_pages received in init_out */
65 extern unsigned int fuse_max_pages_limit;
66 /*
67  * Default timeout (in seconds) for the server to reply to a request
68  * before the connection is aborted, if no timeout was specified on mount.
69  */
70 extern unsigned int fuse_default_req_timeout;
71 /*
72  * Max timeout (in seconds) for the server to reply to a request before
73  * the connection is aborted.
74  */
75 extern unsigned int fuse_max_req_timeout;
76 
77 /** List of active connections */
78 extern struct list_head fuse_conn_list;
79 
80 /** Global mutex protecting fuse_conn_list and the control filesystem */
81 extern struct mutex fuse_mutex;
82 
83 /** Module parameters */
84 extern unsigned int max_user_bgreq;
85 extern unsigned int max_user_congthresh;
86 
87 /* One forget request */
88 struct fuse_forget_link {
89 	struct fuse_forget_one forget_one;
90 	struct fuse_forget_link *next;
91 };
92 
93 /* Submount lookup tracking */
94 struct fuse_submount_lookup {
95 	/** Refcount */
96 	refcount_t count;
97 
98 	/** Unique ID, which identifies the inode between userspace
99 	 * and kernel */
100 	u64 nodeid;
101 
102 	/** The request used for sending the FORGET message */
103 	struct fuse_forget_link *forget;
104 };
105 
106 /** Container for data related to mapping to backing file */
107 struct fuse_backing {
108 	struct file *file;
109 	struct cred *cred;
110 
111 	/** refcount */
112 	refcount_t count;
113 	struct rcu_head rcu;
114 };
115 
116 /** FUSE inode */
117 struct fuse_inode {
118 	/** Inode data */
119 	struct inode inode;
120 
121 	/** Unique ID, which identifies the inode between userspace
122 	 * and kernel */
123 	u64 nodeid;
124 
125 	/** Number of lookups on this inode */
126 	u64 nlookup;
127 
128 	/** The request used for sending the FORGET message */
129 	struct fuse_forget_link *forget;
130 
131 	/** Time in jiffies until the file attributes are valid */
132 	u64 i_time;
133 
134 	/* Which attributes are invalid */
135 	u32 inval_mask;
136 
137 	/** The sticky bit in inode->i_mode may have been removed, so
138 	    preserve the original mode */
139 	umode_t orig_i_mode;
140 
141 	/* Cache birthtime */
142 	struct timespec64 i_btime;
143 
144 	/** 64 bit inode number */
145 	u64 orig_ino;
146 
147 	/** Version of last attribute change */
148 	u64 attr_version;
149 
150 	union {
151 		/* read/write io cache (regular file only) */
152 		struct {
153 			/* Files usable in writepage.  Protected by fi->lock */
154 			struct list_head write_files;
155 
156 			/* Writepages pending on truncate or fsync */
157 			struct list_head queued_writes;
158 
159 			/* Number of sent writes, a negative bias
160 			 * (FUSE_NOWRITE) means more writes are blocked */
161 			int writectr;
162 
163 			/** Number of files/maps using page cache */
164 			int iocachectr;
165 
166 			/* Waitq for writepage completion */
167 			wait_queue_head_t page_waitq;
168 
169 			/* waitq for direct-io completion */
170 			wait_queue_head_t direct_io_waitq;
171 		};
172 
173 		/* readdir cache (directory only) */
174 		struct {
175 			/* true if fully cached */
176 			bool cached;
177 
178 			/* size of cache */
179 			loff_t size;
180 
181 			/* position at end of cache (position of next entry) */
182 			loff_t pos;
183 
184 			/* version of the cache */
185 			u64 version;
186 
187 			/* modification time of directory when cache was
188 			 * started */
189 			struct timespec64 mtime;
190 
191 			/* iversion of directory when cache was started */
192 			u64 iversion;
193 
194 			/* protects above fields */
195 			spinlock_t lock;
196 		} rdc;
197 	};
198 
199 	/** Miscellaneous bits describing inode state */
200 	unsigned long state;
201 
202 	/** Lock for serializing lookup and readdir for back compatibility*/
203 	struct mutex mutex;
204 
205 	/** Lock to protect write related fields */
206 	spinlock_t lock;
207 
208 #ifdef CONFIG_FUSE_DAX
209 	/*
210 	 * Dax specific inode data
211 	 */
212 	struct fuse_inode_dax *dax;
213 #endif
214 	/** Submount specific lookup tracking */
215 	struct fuse_submount_lookup *submount_lookup;
216 #ifdef CONFIG_FUSE_PASSTHROUGH
217 	/** Reference to backing file in passthrough mode */
218 	struct fuse_backing *fb;
219 #endif
220 
221 	/*
222 	 * The underlying inode->i_blkbits value will not be modified,
223 	 * so preserve the blocksize specified by the server.
224 	 */
225 	u8 cached_i_blkbits;
226 };
227 
228 /** FUSE inode state bits */
229 enum {
230 	/** Advise readdirplus  */
231 	FUSE_I_ADVISE_RDPLUS,
232 	/** Initialized with readdirplus */
233 	FUSE_I_INIT_RDPLUS,
234 	/** An operation changing file size is in progress  */
235 	FUSE_I_SIZE_UNSTABLE,
236 	/* Bad inode */
237 	FUSE_I_BAD,
238 	/* Has btime */
239 	FUSE_I_BTIME,
240 	/* Wants or already has page cache IO */
241 	FUSE_I_CACHE_IO_MODE,
242 	/*
243 	 * Client has exclusive access to the inode, either because fs is local
244 	 * or the fuse server has an exclusive "lease" on distributed fs
245 	 */
246 	FUSE_I_EXCLUSIVE,
247 };
248 
249 struct fuse_conn;
250 struct fuse_mount;
251 union fuse_file_args;
252 
253 /** FUSE specific file data */
254 struct fuse_file {
255 	/** Fuse connection for this file */
256 	struct fuse_mount *fm;
257 
258 	/* Argument space reserved for open/release */
259 	union fuse_file_args *args;
260 
261 	/** Kernel file handle guaranteed to be unique */
262 	u64 kh;
263 
264 	/** File handle used by userspace */
265 	u64 fh;
266 
267 	/** Node id of this file */
268 	u64 nodeid;
269 
270 	/** Refcount */
271 	refcount_t count;
272 
273 	/** FOPEN_* flags returned by open */
274 	u32 open_flags;
275 
276 	/** Entry on inode's write_files list */
277 	struct list_head write_entry;
278 
279 	/* Readdir related */
280 	struct {
281 		/* Dir stream position */
282 		loff_t pos;
283 
284 		/* Offset in cache */
285 		loff_t cache_off;
286 
287 		/* Version of cache we are reading */
288 		u64 version;
289 
290 	} readdir;
291 
292 	/** RB node to be linked on fuse_conn->polled_files */
293 	struct rb_node polled_node;
294 
295 	/** Wait queue head for poll */
296 	wait_queue_head_t poll_wait;
297 
298 	/** Does file hold a fi->iocachectr refcount? */
299 	enum { IOM_NONE, IOM_CACHED, IOM_UNCACHED } iomode;
300 
301 #ifdef CONFIG_FUSE_PASSTHROUGH
302 	/** Reference to backing file in passthrough mode */
303 	struct file *passthrough;
304 	const struct cred *cred;
305 #endif
306 
307 	/** Has flock been performed on this file? */
308 	bool flock:1;
309 };
310 
311 /** One input argument of a request */
312 struct fuse_in_arg {
313 	unsigned size;
314 	const void *value;
315 };
316 
317 /** One output argument of a request */
318 struct fuse_arg {
319 	unsigned size;
320 	void *value;
321 };
322 
323 /** FUSE folio descriptor */
324 struct fuse_folio_desc {
325 	unsigned int length;
326 	unsigned int offset;
327 };
328 
329 struct fuse_args {
330 	uint64_t nodeid;
331 	uint32_t opcode;
332 	uint8_t in_numargs;
333 	uint8_t out_numargs;
334 	uint8_t ext_idx;
335 	bool force:1;
336 	bool noreply:1;
337 	bool nocreds:1;
338 	bool in_pages:1;
339 	bool out_pages:1;
340 	bool user_pages:1;
341 	bool out_argvar:1;
342 	bool page_zeroing:1;
343 	bool page_replace:1;
344 	bool may_block:1;
345 	bool is_ext:1;
346 	bool is_pinned:1;
347 	bool invalidate_vmap:1;
348 	bool abort_on_kill:1;
349 	struct fuse_in_arg in_args[4];
350 	struct fuse_arg out_args[2];
351 	void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error);
352 	/* Used for kvec iter backed by vmalloc address */
353 	void *vmap_base;
354 };
355 
356 struct fuse_args_pages {
357 	struct fuse_args args;
358 	struct folio **folios;
359 	struct fuse_folio_desc *descs;
360 	unsigned int num_folios;
361 };
362 
363 struct fuse_release_args {
364 	struct fuse_args args;
365 	struct fuse_release_in inarg;
366 	struct inode *inode;
367 };
368 
369 union fuse_file_args {
370 	/* Used during open() */
371 	struct fuse_open_out open_outarg;
372 	/* Used during release() */
373 	struct fuse_release_args release_args;
374 };
375 
376 #define FUSE_ARGS(args) struct fuse_args args = {}
377 
378 /** The request IO state (for asynchronous processing) */
379 struct fuse_io_priv {
380 	struct kref refcnt;
381 	int async;
382 	spinlock_t lock;
383 	unsigned reqs;
384 	ssize_t bytes;
385 	size_t size;
386 	__u64 offset;
387 	bool write;
388 	bool should_dirty;
389 	int err;
390 	struct kiocb *iocb;
391 	struct completion *done;
392 	bool blocking;
393 };
394 
395 #define FUSE_IO_PRIV_SYNC(i) \
396 {					\
397 	.refcnt = KREF_INIT(1),		\
398 	.async = 0,			\
399 	.iocb = i,			\
400 }
401 
402 /**
403  * Request flags
404  *
405  * FR_ISREPLY:		set if the request has reply
406  * FR_FORCE:		force sending of the request even if interrupted
407  * FR_BACKGROUND:	request is sent in the background
408  * FR_WAITING:		request is counted as "waiting"
409  * FR_ABORTED:		the request was aborted
410  * FR_INTERRUPTED:	the request has been interrupted
411  * FR_LOCKED:		data is being copied to/from the request
412  * FR_PENDING:		request is not yet in userspace
413  * FR_SENT:		request is in userspace, waiting for an answer
414  * FR_FINISHED:		request is finished
415  * FR_PRIVATE:		request is on private list
416  * FR_ASYNC:		request is asynchronous
417  * FR_URING:		request is handled through fuse-io-uring
418  */
419 enum fuse_req_flag {
420 	FR_ISREPLY,
421 	FR_FORCE,
422 	FR_BACKGROUND,
423 	FR_WAITING,
424 	FR_ABORTED,
425 	FR_INTERRUPTED,
426 	FR_LOCKED,
427 	FR_PENDING,
428 	FR_SENT,
429 	FR_FINISHED,
430 	FR_PRIVATE,
431 	FR_ASYNC,
432 	FR_URING,
433 };
434 
435 /**
436  * A request to the client
437  *
438  * .waitq.lock protects the following fields:
439  *   - FR_ABORTED
440  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
441  */
442 struct fuse_req {
443 	/** This can be on either pending processing or io lists in
444 	    fuse_conn */
445 	struct list_head list;
446 
447 	/** Entry on the interrupts list  */
448 	struct list_head intr_entry;
449 
450 	/* Input/output arguments */
451 	struct fuse_args *args;
452 
453 	/** refcount */
454 	refcount_t count;
455 
456 	/* Request flags, updated with test/set/clear_bit() */
457 	unsigned long flags;
458 
459 	/* The request input header */
460 	struct {
461 		struct fuse_in_header h;
462 	} in;
463 
464 	/* The request output header */
465 	struct {
466 		struct fuse_out_header h;
467 	} out;
468 
469 	/** Used to wake up the task waiting for completion of request*/
470 	wait_queue_head_t waitq;
471 
472 #if IS_ENABLED(CONFIG_VIRTIO_FS)
473 	/** virtio-fs's physically contiguous buffer for in and out args */
474 	void *argbuf;
475 #endif
476 
477 	/** fuse_mount this request belongs to */
478 	struct fuse_mount *fm;
479 
480 #ifdef CONFIG_FUSE_IO_URING
481 	void *ring_entry;
482 	void *ring_queue;
483 #endif
484 	/** When (in jiffies) the request was created */
485 	unsigned long create_time;
486 };
487 
488 struct fuse_iqueue;
489 
490 /**
491  * Input queue callbacks
492  *
493  * Input queue signalling is device-specific.  For example, the /dev/fuse file
494  * uses fiq->waitq and fasync to wake processes that are waiting on queue
495  * readiness.  These callbacks allow other device types to respond to input
496  * queue activity.
497  */
498 struct fuse_iqueue_ops {
499 	/**
500 	 * Send one forget
501 	 */
502 	void (*send_forget)(struct fuse_iqueue *fiq, struct fuse_forget_link *link);
503 
504 	/**
505 	 * Send interrupt for request
506 	 */
507 	void (*send_interrupt)(struct fuse_iqueue *fiq, struct fuse_req *req);
508 
509 	/**
510 	 * Send one request
511 	 */
512 	void (*send_req)(struct fuse_iqueue *fiq, struct fuse_req *req);
513 
514 	/**
515 	 * Clean up when fuse_iqueue is destroyed
516 	 */
517 	void (*release)(struct fuse_iqueue *fiq);
518 };
519 
520 /** /dev/fuse input queue operations */
521 extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
522 
523 struct fuse_iqueue {
524 	/** Connection established */
525 	unsigned connected;
526 
527 	/** Lock protecting accesses to members of this structure */
528 	spinlock_t lock;
529 
530 	/** Readers of the connection are waiting on this */
531 	wait_queue_head_t waitq;
532 
533 	/** The next unique request id */
534 	u64 reqctr;
535 
536 	/** The list of pending requests */
537 	struct list_head pending;
538 
539 	/** Pending interrupts */
540 	struct list_head interrupts;
541 
542 	/** Queue of pending forgets */
543 	struct fuse_forget_link forget_list_head;
544 	struct fuse_forget_link *forget_list_tail;
545 
546 	/** Batching of FORGET requests (positive indicates FORGET batch) */
547 	int forget_batch;
548 
549 	/** O_ASYNC requests */
550 	struct fasync_struct *fasync;
551 
552 	/** Device-specific callbacks */
553 	const struct fuse_iqueue_ops *ops;
554 
555 	/** Device-specific state */
556 	void *priv;
557 };
558 
559 #define FUSE_PQ_HASH_BITS 8
560 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
561 
562 struct fuse_pqueue {
563 	/** Connection established */
564 	unsigned connected;
565 
566 	/** Lock protecting accessess to  members of this structure */
567 	spinlock_t lock;
568 
569 	/** Hash table of requests being processed */
570 	struct list_head *processing;
571 
572 	/** The list of requests under I/O */
573 	struct list_head io;
574 };
575 
576 /**
577  * Fuse device instance
578  */
579 struct fuse_dev {
580 	/** Reference count of this object */
581 	refcount_t ref;
582 
583 	/** Issue FUSE_INIT synchronously */
584 	bool sync_init;
585 
586 	/** Fuse connection for this device */
587 	struct fuse_conn *fc;
588 
589 	/** Processing queue */
590 	struct fuse_pqueue pq;
591 
592 	/** list entry on fc->devices */
593 	struct list_head entry;
594 };
595 
596 enum fuse_dax_mode {
597 	FUSE_DAX_INODE_DEFAULT,	/* default */
598 	FUSE_DAX_ALWAYS,	/* "-o dax=always" */
599 	FUSE_DAX_NEVER,		/* "-o dax=never" */
600 	FUSE_DAX_INODE_USER,	/* "-o dax=inode" */
601 };
602 
fuse_is_inode_dax_mode(enum fuse_dax_mode mode)603 static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode)
604 {
605 	return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER;
606 }
607 
608 struct fuse_fs_context {
609 	struct fuse_dev *fud;
610 	unsigned int rootmode;
611 	kuid_t user_id;
612 	kgid_t group_id;
613 	bool is_bdev:1;
614 	bool rootmode_present:1;
615 	bool user_id_present:1;
616 	bool group_id_present:1;
617 	bool default_permissions:1;
618 	bool allow_other:1;
619 	bool destroy:1;
620 	bool no_control:1;
621 	bool no_force_umount:1;
622 	bool legacy_opts_show:1;
623 	enum fuse_dax_mode dax_mode;
624 	unsigned int max_read;
625 	unsigned int blksize;
626 	const char *subtype;
627 
628 	/* DAX device, may be NULL */
629 	struct dax_device *dax_dev;
630 };
631 
632 struct fuse_sync_bucket {
633 	/* count is a possible scalability bottleneck */
634 	atomic_t count;
635 	wait_queue_head_t waitq;
636 	struct rcu_head rcu;
637 };
638 
639 /**
640  * A Fuse connection.
641  *
642  * This structure is created, when the root filesystem is mounted, and
643  * is destroyed, when the client device is closed and the last
644  * fuse_mount is destroyed.
645  */
646 struct fuse_conn {
647 	/** Lock protecting accessess to  members of this structure */
648 	spinlock_t lock;
649 
650 	/** Refcount */
651 	refcount_t count;
652 
653 	/** Current epoch for up-to-date dentries */
654 	atomic_t epoch;
655 
656 	struct work_struct epoch_work;
657 
658 	struct rcu_head rcu;
659 
660 	/** The user id for this mount */
661 	kuid_t user_id;
662 
663 	/** The group id for this mount */
664 	kgid_t group_id;
665 
666 	/** The pid namespace for this mount */
667 	struct pid_namespace *pid_ns;
668 
669 	/** The user namespace for this mount */
670 	struct user_namespace *user_ns;
671 
672 	/** Maximum read size */
673 	unsigned max_read;
674 
675 	/** Maximum write size */
676 	unsigned max_write;
677 
678 	/** Maximum number of pages that can be used in a single request */
679 	unsigned int max_pages;
680 
681 	/** Constrain ->max_pages to this value during feature negotiation */
682 	unsigned int max_pages_limit;
683 
684 	/** Input queue */
685 	struct fuse_iqueue iq;
686 
687 	/** The next unique kernel file handle */
688 	atomic64_t khctr;
689 
690 	/** rbtree of fuse_files waiting for poll events indexed by ph */
691 	struct rb_root polled_files;
692 
693 	/** Maximum number of outstanding background requests */
694 	unsigned max_background;
695 
696 	/** Number of background requests at which congestion starts */
697 	unsigned congestion_threshold;
698 
699 	/** Number of requests currently in the background */
700 	unsigned num_background;
701 
702 	/** Number of background requests currently queued for userspace */
703 	unsigned active_background;
704 
705 	/** The list of background requests set aside for later queuing */
706 	struct list_head bg_queue;
707 
708 	/** Protects: max_background, congestion_threshold, num_background,
709 	 * active_background, bg_queue, blocked */
710 	spinlock_t bg_lock;
711 
712 	/** Flag indicating that INIT reply has been received. Allocating
713 	 * any fuse request will be suspended until the flag is set */
714 	int initialized;
715 
716 	/** Flag indicating if connection is blocked.  This will be
717 	    the case before the INIT reply is received, and if there
718 	    are too many outstading backgrounds requests */
719 	int blocked;
720 
721 	/** waitq for blocked connection */
722 	wait_queue_head_t blocked_waitq;
723 
724 	/** Connection established, cleared on umount, connection
725 	    abort and device release */
726 	unsigned connected;
727 
728 	/** Connection aborted via sysfs */
729 	bool aborted;
730 
731 	/** Connection failed (version mismatch).  Cannot race with
732 	    setting other bitfields since it is only set once in INIT
733 	    reply, before any other request, and never cleared */
734 	unsigned conn_error:1;
735 
736 	/** Connection successful.  Only set in INIT */
737 	unsigned conn_init:1;
738 
739 	/** Do readahead asynchronously?  Only set in INIT */
740 	unsigned async_read:1;
741 
742 	/** Return an unique read error after abort.  Only set in INIT */
743 	unsigned abort_err:1;
744 
745 	/** Do not send separate SETATTR request before open(O_TRUNC)  */
746 	unsigned atomic_o_trunc:1;
747 
748 	/** Filesystem supports NFS exporting.  Only set in INIT */
749 	unsigned export_support:1;
750 
751 	/** write-back cache policy (default is write-through) */
752 	unsigned writeback_cache:1;
753 
754 	/** allow parallel lookups and readdir (default is serialized) */
755 	unsigned parallel_dirops:1;
756 
757 	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
758 	unsigned handle_killpriv:1;
759 
760 	/** cache READLINK responses in page cache */
761 	unsigned cache_symlinks:1;
762 
763 	/* show legacy mount options */
764 	unsigned int legacy_opts_show:1;
765 
766 	/*
767 	 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
768 	 * write/trunc only if caller did not have CAP_FSETID.  sgid is killed
769 	 * on write/truncate only if caller did not have CAP_FSETID as well as
770 	 * file has group execute permission.
771 	 */
772 	unsigned handle_killpriv_v2:1;
773 
774 	/*
775 	 * The following bitfields are only for optimization purposes
776 	 * and hence races in setting them will not cause malfunction
777 	 */
778 
779 	/** Is open/release not implemented by fs? */
780 	unsigned no_open:1;
781 
782 	/** Is opendir/releasedir not implemented by fs? */
783 	unsigned no_opendir:1;
784 
785 	/** Is fsync not implemented by fs? */
786 	unsigned no_fsync:1;
787 
788 	/** Is fsyncdir not implemented by fs? */
789 	unsigned no_fsyncdir:1;
790 
791 	/** Is flush not implemented by fs? */
792 	unsigned no_flush:1;
793 
794 	/** Is setxattr not implemented by fs? */
795 	unsigned no_setxattr:1;
796 
797 	/** Does file server support extended setxattr */
798 	unsigned setxattr_ext:1;
799 
800 	/** Is getxattr not implemented by fs? */
801 	unsigned no_getxattr:1;
802 
803 	/** Is listxattr not implemented by fs? */
804 	unsigned no_listxattr:1;
805 
806 	/** Is removexattr not implemented by fs? */
807 	unsigned no_removexattr:1;
808 
809 	/** Are posix file locking primitives not implemented by fs? */
810 	unsigned no_lock:1;
811 
812 	/** Is access not implemented by fs? */
813 	unsigned no_access:1;
814 
815 	/** Is create not implemented by fs? */
816 	unsigned no_create:1;
817 
818 	/** Is interrupt not implemented by fs? */
819 	unsigned no_interrupt:1;
820 
821 	/** Is bmap not implemented by fs? */
822 	unsigned no_bmap:1;
823 
824 	/** Is poll not implemented by fs? */
825 	unsigned no_poll:1;
826 
827 	/** Do multi-page cached writes */
828 	unsigned big_writes:1;
829 
830 	/** Don't apply umask to creation modes */
831 	unsigned dont_mask:1;
832 
833 	/** Are BSD file locking primitives not implemented by fs? */
834 	unsigned no_flock:1;
835 
836 	/** Is fallocate not implemented by fs? */
837 	unsigned no_fallocate:1;
838 
839 	/** Is rename with flags implemented by fs? */
840 	unsigned no_rename2:1;
841 
842 	/** Use enhanced/automatic page cache invalidation. */
843 	unsigned auto_inval_data:1;
844 
845 	/** Filesystem is fully responsible for page cache invalidation. */
846 	unsigned explicit_inval_data:1;
847 
848 	/** Does the filesystem support readdirplus? */
849 	unsigned do_readdirplus:1;
850 
851 	/** Does the filesystem want adaptive readdirplus? */
852 	unsigned readdirplus_auto:1;
853 
854 	/** Does the filesystem support asynchronous direct-IO submission? */
855 	unsigned async_dio:1;
856 
857 	/** Is lseek not implemented by fs? */
858 	unsigned no_lseek:1;
859 
860 	/** Does the filesystem support posix acls? */
861 	unsigned posix_acl:1;
862 
863 	/** Check permissions based on the file mode or not? */
864 	unsigned default_permissions:1;
865 
866 	/** Allow other than the mounter user to access the filesystem ? */
867 	unsigned allow_other:1;
868 
869 	/** Does the filesystem support copy_file_range? */
870 	unsigned no_copy_file_range:1;
871 
872 	/** Does the filesystem support copy_file_range_64? */
873 	unsigned no_copy_file_range_64:1;
874 
875 	/* Send DESTROY request */
876 	unsigned int destroy:1;
877 
878 	/* Delete dentries that have gone stale */
879 	unsigned int delete_stale:1;
880 
881 	/** Do not create entry in fusectl fs */
882 	unsigned int no_control:1;
883 
884 	/** Do not allow MNT_FORCE umount */
885 	unsigned int no_force_umount:1;
886 
887 	/* Auto-mount submounts announced by the server */
888 	unsigned int auto_submounts:1;
889 
890 	/* Propagate syncfs() to server */
891 	unsigned int sync_fs:1;
892 
893 	/* Initialize security xattrs when creating a new inode */
894 	unsigned int init_security:1;
895 
896 	/* Add supplementary group info when creating a new inode */
897 	unsigned int create_supp_group:1;
898 
899 	/* Does the filesystem support per inode DAX? */
900 	unsigned int inode_dax:1;
901 
902 	/* Is tmpfile not implemented by fs? */
903 	unsigned int no_tmpfile:1;
904 
905 	/* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
906 	unsigned int direct_io_allow_mmap:1;
907 
908 	/* Is statx not implemented by fs? */
909 	unsigned int no_statx:1;
910 
911 	/** Passthrough support for read/write IO */
912 	unsigned int passthrough:1;
913 
914 	/* Use pages instead of pointer for kernel I/O */
915 	unsigned int use_pages_for_kvec_io:1;
916 
917 	/* Is link not implemented by fs? */
918 	unsigned int no_link:1;
919 
920 	/* Is synchronous FUSE_INIT allowed? */
921 	unsigned int sync_init:1;
922 
923 	/* Use io_uring for communication */
924 	unsigned int io_uring;
925 
926 	/** Maximum stack depth for passthrough backing files */
927 	int max_stack_depth;
928 
929 	/** The number of requests waiting for completion */
930 	atomic_t num_waiting;
931 
932 	/** Negotiated minor version */
933 	unsigned minor;
934 
935 	/** Entry on the fuse_conn_list */
936 	struct list_head entry;
937 
938 	/** Device ID from the root super block */
939 	dev_t dev;
940 
941 	/** Key for lock owner ID scrambling */
942 	u32 scramble_key[4];
943 
944 	/** Version counter for attribute changes */
945 	atomic64_t attr_version;
946 
947 	/** Version counter for evict inode */
948 	atomic64_t evict_ctr;
949 
950 	/* maximum file name length */
951 	u32 name_max;
952 
953 	/** Called on final put */
954 	void (*release)(struct fuse_conn *);
955 
956 	/**
957 	 * Read/write semaphore to hold when accessing the sb of any
958 	 * fuse_mount belonging to this connection
959 	 */
960 	struct rw_semaphore killsb;
961 
962 	/** List of device instances belonging to this connection */
963 	struct list_head devices;
964 
965 #ifdef CONFIG_FUSE_DAX
966 	/* Dax mode */
967 	enum fuse_dax_mode dax_mode;
968 
969 	/* Dax specific conn data, non-NULL if DAX is enabled */
970 	struct fuse_conn_dax *dax;
971 #endif
972 
973 	/** List of filesystems using this connection */
974 	struct list_head mounts;
975 
976 	/* New writepages go into this bucket */
977 	struct fuse_sync_bucket __rcu *curr_bucket;
978 
979 #ifdef CONFIG_FUSE_PASSTHROUGH
980 	/** IDR for backing files ids */
981 	struct idr backing_files_map;
982 #endif
983 
984 #ifdef CONFIG_FUSE_IO_URING
985 	/**  uring connection information*/
986 	struct fuse_ring *ring;
987 #endif
988 
989 	/** Only used if the connection opts into request timeouts */
990 	struct {
991 		/* Worker for checking if any requests have timed out */
992 		struct delayed_work work;
993 
994 		/* Request timeout (in jiffies). 0 = no timeout */
995 		unsigned int req_timeout;
996 	} timeout;
997 };
998 
999 /*
1000  * Represents a mounted filesystem, potentially a submount.
1001  *
1002  * This object allows sharing a fuse_conn between separate mounts to
1003  * allow submounts with dedicated superblocks and thus separate device
1004  * IDs.
1005  */
1006 struct fuse_mount {
1007 	/* Underlying (potentially shared) connection to the FUSE server */
1008 	struct fuse_conn *fc;
1009 
1010 	/*
1011 	 * Super block for this connection (fc->killsb must be held when
1012 	 * accessing this).
1013 	 */
1014 	struct super_block *sb;
1015 
1016 	/* Entry on fc->mounts */
1017 	struct list_head fc_entry;
1018 	struct rcu_head rcu;
1019 };
1020 
1021 /*
1022  * Empty header for FUSE opcodes without specific header needs.
1023  * Used as a placeholder in args->in_args[0] for consistency
1024  * across all FUSE operations, simplifying request handling.
1025  */
1026 struct fuse_zero_header {};
1027 
fuse_set_zero_arg0(struct fuse_args * args)1028 static inline void fuse_set_zero_arg0(struct fuse_args *args)
1029 {
1030 	args->in_args[0].size = sizeof(struct fuse_zero_header);
1031 	args->in_args[0].value = NULL;
1032 }
1033 
get_fuse_mount_super(struct super_block * sb)1034 static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb)
1035 {
1036 	return sb->s_fs_info;
1037 }
1038 
get_fuse_conn_super(struct super_block * sb)1039 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
1040 {
1041 	return get_fuse_mount_super(sb)->fc;
1042 }
1043 
get_fuse_mount(struct inode * inode)1044 static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
1045 {
1046 	return get_fuse_mount_super(inode->i_sb);
1047 }
1048 
get_fuse_conn(struct inode * inode)1049 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
1050 {
1051 	return get_fuse_mount_super(inode->i_sb)->fc;
1052 }
1053 
get_fuse_inode(const struct inode * inode)1054 static inline struct fuse_inode *get_fuse_inode(const struct inode *inode)
1055 {
1056 	return container_of(inode, struct fuse_inode, inode);
1057 }
1058 
get_node_id(struct inode * inode)1059 static inline u64 get_node_id(struct inode *inode)
1060 {
1061 	return get_fuse_inode(inode)->nodeid;
1062 }
1063 
invalid_nodeid(u64 nodeid)1064 static inline int invalid_nodeid(u64 nodeid)
1065 {
1066 	return !nodeid || nodeid == FUSE_ROOT_ID;
1067 }
1068 
fuse_get_attr_version(struct fuse_conn * fc)1069 static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
1070 {
1071 	return atomic64_read(&fc->attr_version);
1072 }
1073 
fuse_get_evict_ctr(struct fuse_conn * fc)1074 static inline u64 fuse_get_evict_ctr(struct fuse_conn *fc)
1075 {
1076 	return atomic64_read(&fc->evict_ctr);
1077 }
1078 
fuse_stale_inode(const struct inode * inode,int generation,struct fuse_attr * attr)1079 static inline bool fuse_stale_inode(const struct inode *inode, int generation,
1080 				    struct fuse_attr *attr)
1081 {
1082 	return inode->i_generation != generation ||
1083 		inode_wrong_type(inode, attr->mode);
1084 }
1085 
fuse_make_bad(struct inode * inode)1086 static inline void fuse_make_bad(struct inode *inode)
1087 {
1088 	set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state);
1089 }
1090 
fuse_is_bad(struct inode * inode)1091 static inline bool fuse_is_bad(struct inode *inode)
1092 {
1093 	return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
1094 }
1095 
fuse_inode_is_exclusive(const struct inode * inode)1096 static inline bool fuse_inode_is_exclusive(const struct inode *inode)
1097 {
1098 	const struct fuse_inode *fi = get_fuse_inode(inode);
1099 
1100 	return test_bit(FUSE_I_EXCLUSIVE, &fi->state);
1101 }
1102 
fuse_folios_alloc(unsigned int nfolios,gfp_t flags,struct fuse_folio_desc ** desc)1103 static inline struct folio **fuse_folios_alloc(unsigned int nfolios, gfp_t flags,
1104 					       struct fuse_folio_desc **desc)
1105 {
1106 	struct folio **folios;
1107 
1108 	folios = kzalloc(nfolios * (sizeof(struct folio *) +
1109 				    sizeof(struct fuse_folio_desc)), flags);
1110 	*desc = (void *) (folios + nfolios);
1111 
1112 	return folios;
1113 }
1114 
fuse_folio_descs_length_init(struct fuse_folio_desc * descs,unsigned int index,unsigned int nr_folios)1115 static inline void fuse_folio_descs_length_init(struct fuse_folio_desc *descs,
1116 						unsigned int index,
1117 						unsigned int nr_folios)
1118 {
1119 	int i;
1120 
1121 	for (i = index; i < index + nr_folios; i++)
1122 		descs[i].length = PAGE_SIZE - descs[i].offset;
1123 }
1124 
fuse_sync_bucket_dec(struct fuse_sync_bucket * bucket)1125 static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket)
1126 {
1127 	/* Need RCU protection to prevent use after free after the decrement */
1128 	rcu_read_lock();
1129 	if (atomic_dec_and_test(&bucket->count))
1130 		wake_up(&bucket->waitq);
1131 	rcu_read_unlock();
1132 }
1133 
1134 /** Device operations */
1135 extern const struct file_operations fuse_dev_operations;
1136 
1137 extern const struct dentry_operations fuse_dentry_operations;
1138 
1139 /**
1140  * Get a filled in inode
1141  */
1142 struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
1143 			int generation, struct fuse_attr *attr,
1144 			u64 attr_valid, u64 attr_version,
1145 			u64 evict_ctr);
1146 
1147 int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
1148 		     struct fuse_entry_out *outarg, struct inode **inode);
1149 
1150 /**
1151  * Send FORGET command
1152  */
1153 void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
1154 		       u64 nodeid, u64 nlookup);
1155 
1156 struct fuse_forget_link *fuse_alloc_forget(void);
1157 
1158 /*
1159  * Initialize READ or READDIR request
1160  */
1161 struct fuse_io_args {
1162 	union {
1163 		struct {
1164 			struct fuse_read_in in;
1165 			u64 attr_ver;
1166 		} read;
1167 		struct {
1168 			struct fuse_write_in in;
1169 			struct fuse_write_out out;
1170 			bool folio_locked;
1171 		} write;
1172 	};
1173 	struct fuse_args_pages ap;
1174 	struct fuse_io_priv *io;
1175 	struct fuse_file *ff;
1176 };
1177 
1178 void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
1179 			 size_t count, int opcode);
1180 
1181 
1182 struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release);
1183 void fuse_file_free(struct fuse_file *ff);
1184 int fuse_finish_open(struct inode *inode, struct file *file);
1185 
1186 void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff,
1187 		       unsigned int flags);
1188 
1189 /**
1190  * Send RELEASE or RELEASEDIR request
1191  */
1192 void fuse_release_common(struct file *file, bool isdir);
1193 
1194 /**
1195  * Send FSYNC or FSYNCDIR request
1196  */
1197 int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
1198 		      int datasync, int opcode);
1199 
1200 /**
1201  * Notify poll wakeup
1202  */
1203 int fuse_notify_poll_wakeup(struct fuse_conn *fc,
1204 			    struct fuse_notify_poll_wakeup_out *outarg);
1205 
1206 /**
1207  * Initialize file operations on a regular file
1208  */
1209 void fuse_init_file_inode(struct inode *inode, unsigned int flags);
1210 
1211 /**
1212  * Initialize inode operations on regular files and special files
1213  */
1214 void fuse_init_common(struct inode *inode);
1215 
1216 /**
1217  * Initialize inode and file operations on a directory
1218  */
1219 void fuse_init_dir(struct inode *inode);
1220 
1221 /**
1222  * Initialize inode operations on a symlink
1223  */
1224 void fuse_init_symlink(struct inode *inode);
1225 
1226 /**
1227  * Change attributes of an inode
1228  */
1229 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
1230 			    struct fuse_statx *sx,
1231 			    u64 attr_valid, u64 attr_version);
1232 
1233 void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
1234 				   struct fuse_statx *sx,
1235 				   u64 attr_valid, u32 cache_mask,
1236 				   u64 evict_ctr);
1237 
1238 u32 fuse_get_cache_mask(struct inode *inode);
1239 
1240 /**
1241  * Initialize the client device
1242  */
1243 int fuse_dev_init(void);
1244 
1245 /**
1246  * Cleanup the client device
1247  */
1248 void fuse_dev_cleanup(void);
1249 
1250 int fuse_ctl_init(void);
1251 void __exit fuse_ctl_cleanup(void);
1252 
1253 /**
1254  * Simple request sending that does request allocation and freeing
1255  */
1256 ssize_t __fuse_simple_request(struct mnt_idmap *idmap,
1257 			      struct fuse_mount *fm,
1258 			      struct fuse_args *args);
1259 
fuse_simple_request(struct fuse_mount * fm,struct fuse_args * args)1260 static inline ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args)
1261 {
1262 	return __fuse_simple_request(&invalid_mnt_idmap, fm, args);
1263 }
1264 
fuse_simple_idmap_request(struct mnt_idmap * idmap,struct fuse_mount * fm,struct fuse_args * args)1265 static inline ssize_t fuse_simple_idmap_request(struct mnt_idmap *idmap,
1266 						struct fuse_mount *fm,
1267 						struct fuse_args *args)
1268 {
1269 	return __fuse_simple_request(idmap, fm, args);
1270 }
1271 
1272 int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
1273 			   gfp_t gfp_flags);
1274 
1275 /**
1276  * Assign a unique id to a fuse request
1277  */
1278 void fuse_request_assign_unique(struct fuse_iqueue *fiq, struct fuse_req *req);
1279 
1280 /**
1281  * End a finished request
1282  */
1283 void fuse_request_end(struct fuse_req *req);
1284 
1285 /* Abort all requests */
1286 void fuse_abort_conn(struct fuse_conn *fc);
1287 void fuse_wait_aborted(struct fuse_conn *fc);
1288 
1289 /* Check if any requests timed out */
1290 void fuse_check_timeout(struct work_struct *work);
1291 
1292 void fuse_dentry_tree_init(void);
1293 void fuse_dentry_tree_cleanup(void);
1294 
1295 void fuse_epoch_work(struct work_struct *work);
1296 
1297 /**
1298  * Invalidate inode attributes
1299  */
1300 
1301 /* Attributes possibly changed on data modification */
1302 #define FUSE_STATX_MODIFY	(STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1303 
1304 /* Attributes possibly changed on data and/or size modification */
1305 #define FUSE_STATX_MODSIZE	(FUSE_STATX_MODIFY | STATX_SIZE)
1306 
1307 void fuse_invalidate_attr(struct inode *inode);
1308 void fuse_invalidate_attr_mask(struct inode *inode, u32 mask);
1309 
1310 void fuse_invalidate_entry_cache(struct dentry *entry);
1311 
1312 void fuse_invalidate_atime(struct inode *inode);
1313 
1314 u64 fuse_time_to_jiffies(u64 sec, u32 nsec);
1315 #define ATTR_TIMEOUT(o) \
1316 	fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
1317 
1318 void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
1319 
1320 /**
1321  * Acquire reference to fuse_conn
1322  */
1323 struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
1324 
1325 /**
1326  * Initialize the fuse processing queue
1327  */
1328 void fuse_pqueue_init(struct fuse_pqueue *fpq);
1329 
1330 /**
1331  * Initialize fuse_conn
1332  */
1333 void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
1334 		    struct user_namespace *user_ns,
1335 		    const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
1336 
1337 /**
1338  * Release reference to fuse_conn
1339  */
1340 void fuse_conn_put(struct fuse_conn *fc);
1341 
1342 struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
1343 struct fuse_dev *fuse_dev_alloc(void);
1344 void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
1345 void fuse_dev_put(struct fuse_dev *fud);
1346 int fuse_send_init(struct fuse_mount *fm);
1347 
1348 /**
1349  * Fill in superblock and initialize fuse connection
1350  * @sb: partially-initialized superblock to fill in
1351  * @ctx: mount context
1352  */
1353 int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
1354 
1355 /*
1356  * Remove the mount from the connection
1357  *
1358  * Returns whether this was the last mount
1359  */
1360 bool fuse_mount_remove(struct fuse_mount *fm);
1361 
1362 /*
1363  * Setup context ops for submounts
1364  */
1365 int fuse_init_fs_context_submount(struct fs_context *fsc);
1366 
1367 /*
1368  * Shut down the connection (possibly sending DESTROY request).
1369  */
1370 void fuse_conn_destroy(struct fuse_mount *fm);
1371 
1372 /* Drop the connection and free the fuse mount */
1373 void fuse_mount_destroy(struct fuse_mount *fm);
1374 
1375 /**
1376  * Add connection to control filesystem
1377  */
1378 int fuse_ctl_add_conn(struct fuse_conn *fc);
1379 
1380 /**
1381  * Remove connection from control filesystem
1382  */
1383 void fuse_ctl_remove_conn(struct fuse_conn *fc);
1384 
1385 /**
1386  * Is file type valid?
1387  */
1388 int fuse_valid_type(int m);
1389 
1390 bool fuse_invalid_attr(struct fuse_attr *attr);
1391 
1392 /**
1393  * Is current process allowed to perform filesystem operation?
1394  */
1395 bool fuse_allow_current_process(struct fuse_conn *fc);
1396 
1397 u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
1398 
1399 void fuse_flush_time_update(struct inode *inode);
1400 void fuse_update_ctime(struct inode *inode);
1401 
1402 int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask);
1403 
1404 void fuse_flush_writepages(struct inode *inode);
1405 
1406 void fuse_set_nowrite(struct inode *inode);
1407 void fuse_release_nowrite(struct inode *inode);
1408 
1409 /**
1410  * Scan all fuse_mounts belonging to fc to find the first where
1411  * ilookup5() returns a result.  Return that result and the
1412  * respective fuse_mount in *fm (unless fm is NULL).
1413  *
1414  * The caller must hold fc->killsb.
1415  */
1416 struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
1417 			   struct fuse_mount **fm);
1418 
1419 /**
1420  * File-system tells the kernel to invalidate cache for the given node id.
1421  */
1422 int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
1423 			     loff_t offset, loff_t len);
1424 
1425 /**
1426  * File-system tells the kernel to invalidate parent attributes and
1427  * the dentry matching parent/name.
1428  *
1429  * If the child_nodeid is non-zero and:
1430  *    - matches the inode number for the dentry matching parent/name,
1431  *    - is not a mount point
1432  *    - is a file or oan empty directory
1433  * then the dentry is unhashed (d_delete()).
1434  */
1435 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
1436 			     u64 child_nodeid, struct qstr *name, u32 flags);
1437 
1438 /*
1439  * Try to prune this inode.  If neither the inode itself nor dentries associated
1440  * with this inode have any external reference, then the inode can be freed.
1441  */
1442 void fuse_try_prune_one_inode(struct fuse_conn *fc, u64 nodeid);
1443 
1444 int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
1445 		 bool isdir);
1446 
1447 /**
1448  * fuse_direct_io() flags
1449  */
1450 
1451 /** If set, it is WRITE; otherwise - READ */
1452 #define FUSE_DIO_WRITE (1 << 0)
1453 
1454 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1455 #define FUSE_DIO_CUSE  (1 << 1)
1456 
1457 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1458 		       loff_t *ppos, int flags);
1459 long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1460 		   unsigned int flags);
1461 long fuse_ioctl_common(struct file *file, unsigned int cmd,
1462 		       unsigned long arg, unsigned int flags);
1463 __poll_t fuse_file_poll(struct file *file, poll_table *wait);
1464 int fuse_dev_release(struct inode *inode, struct file *file);
1465 
1466 bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written);
1467 
1468 int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
1469 int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1470 
1471 int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
1472 		    struct iattr *attr, struct file *file);
1473 
1474 void fuse_set_initialized(struct fuse_conn *fc);
1475 
1476 void fuse_unlock_inode(struct inode *inode, bool locked);
1477 bool fuse_lock_inode(struct inode *inode);
1478 
1479 int fuse_setxattr(struct inode *inode, const char *name, const void *value,
1480 		  size_t size, int flags, unsigned int extra_flags);
1481 ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
1482 		      size_t size);
1483 ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
1484 int fuse_removexattr(struct inode *inode, const char *name);
1485 extern const struct xattr_handler * const fuse_xattr_handlers[];
1486 
1487 struct posix_acl;
1488 struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu);
1489 struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap,
1490 			       struct dentry *dentry, int type);
1491 int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry,
1492 		 struct posix_acl *acl, int type);
1493 
1494 /* readdir.c */
1495 int fuse_readdir(struct file *file, struct dir_context *ctx);
1496 
1497 /**
1498  * Return the number of bytes in an arguments list
1499  */
1500 unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
1501 
1502 /**
1503  * Get the next unique ID for a request
1504  */
1505 u64 fuse_get_unique(struct fuse_iqueue *fiq);
1506 void fuse_free_conn(struct fuse_conn *fc);
1507 
1508 /* dax.c */
1509 
1510 #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1511 
1512 ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
1513 ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
1514 int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
1515 int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
1516 int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode,
1517 			struct dax_device *dax_dev);
1518 void fuse_dax_conn_free(struct fuse_conn *fc);
1519 bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
1520 void fuse_dax_inode_init(struct inode *inode, unsigned int flags);
1521 void fuse_dax_inode_cleanup(struct inode *inode);
1522 void fuse_dax_dontcache(struct inode *inode, unsigned int flags);
1523 bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
1524 void fuse_dax_cancel_work(struct fuse_conn *fc);
1525 
1526 /* ioctl.c */
1527 long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1528 long fuse_file_compat_ioctl(struct file *file, unsigned int cmd,
1529 			    unsigned long arg);
1530 int fuse_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
1531 int fuse_fileattr_set(struct mnt_idmap *idmap,
1532 		      struct dentry *dentry, struct file_kattr *fa);
1533 
1534 /* iomode.c */
1535 int fuse_file_cached_io_open(struct inode *inode, struct fuse_file *ff);
1536 int fuse_inode_uncached_io_start(struct fuse_inode *fi,
1537 				 struct fuse_backing *fb);
1538 void fuse_inode_uncached_io_end(struct fuse_inode *fi);
1539 
1540 int fuse_file_io_open(struct file *file, struct inode *inode);
1541 void fuse_file_io_release(struct fuse_file *ff, struct inode *inode);
1542 
1543 /* file.c */
1544 struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,
1545 				 unsigned int open_flags, bool isdir);
1546 void fuse_file_release(struct inode *inode, struct fuse_file *ff,
1547 		       unsigned int open_flags, fl_owner_t id, bool isdir);
1548 
1549 /* backing.c */
1550 #ifdef CONFIG_FUSE_PASSTHROUGH
1551 struct fuse_backing *fuse_backing_get(struct fuse_backing *fb);
1552 void fuse_backing_put(struct fuse_backing *fb);
1553 struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id);
1554 #else
1555 
fuse_backing_get(struct fuse_backing * fb)1556 static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
1557 {
1558 	return NULL;
1559 }
1560 
fuse_backing_put(struct fuse_backing * fb)1561 static inline void fuse_backing_put(struct fuse_backing *fb)
1562 {
1563 }
fuse_backing_lookup(struct fuse_conn * fc,int backing_id)1564 static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
1565 						       int backing_id)
1566 {
1567 	return NULL;
1568 }
1569 #endif
1570 
1571 void fuse_backing_files_init(struct fuse_conn *fc);
1572 void fuse_backing_files_free(struct fuse_conn *fc);
1573 int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map);
1574 int fuse_backing_close(struct fuse_conn *fc, int backing_id);
1575 
1576 /* passthrough.c */
fuse_inode_backing(struct fuse_inode * fi)1577 static inline struct fuse_backing *fuse_inode_backing(struct fuse_inode *fi)
1578 {
1579 #ifdef CONFIG_FUSE_PASSTHROUGH
1580 	return READ_ONCE(fi->fb);
1581 #else
1582 	return NULL;
1583 #endif
1584 }
1585 
fuse_inode_backing_set(struct fuse_inode * fi,struct fuse_backing * fb)1586 static inline struct fuse_backing *fuse_inode_backing_set(struct fuse_inode *fi,
1587 							  struct fuse_backing *fb)
1588 {
1589 #ifdef CONFIG_FUSE_PASSTHROUGH
1590 	return xchg(&fi->fb, fb);
1591 #else
1592 	return NULL;
1593 #endif
1594 }
1595 
1596 struct fuse_backing *fuse_passthrough_open(struct file *file, int backing_id);
1597 void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb);
1598 
fuse_file_passthrough(struct fuse_file * ff)1599 static inline struct file *fuse_file_passthrough(struct fuse_file *ff)
1600 {
1601 #ifdef CONFIG_FUSE_PASSTHROUGH
1602 	return ff->passthrough;
1603 #else
1604 	return NULL;
1605 #endif
1606 }
1607 
1608 ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter);
1609 ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *iter);
1610 ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos,
1611 				     struct pipe_inode_info *pipe,
1612 				     size_t len, unsigned int flags);
1613 ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
1614 				      struct file *out, loff_t *ppos,
1615 				      size_t len, unsigned int flags);
1616 ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
1617 
1618 #ifdef CONFIG_SYSCTL
1619 extern int fuse_sysctl_register(void);
1620 extern void fuse_sysctl_unregister(void);
1621 #else
1622 #define fuse_sysctl_register()		(0)
1623 #define fuse_sysctl_unregister()	do { } while (0)
1624 #endif /* CONFIG_SYSCTL */
1625 
1626 #endif /* _FS_FUSE_I_H */
1627