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