2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
13 # define pr_fmt(fmt) "fuse: " fmt
16 #include <linux/fuse.h>
18 #include <linux/mount.h>
19 #include <linux/wait.h>
20 #include <linux/list.h>
21 #include <linux/spinlock.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>
35 /** Default max number of pages that can be used in a single read request */
36 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
38 /** Bias for fi->writectr, meaning new writepages must not be sent */
39 #define FUSE_NOWRITE INT_MIN
41 /** Maximum length of a filename, not including terminating null */
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)
48 /** Number of dentries for each connection in the control filesystem */
49 #define FUSE_CTL_NUM_DENTRIES 5
51 /* Frequency (in seconds) of request timeout checks, if opted into */
52 #define FUSE_TIMEOUT_TIMER_FREQ 15
54 /** Frequency (in jiffies) of request timeout checks, if opted into */
55 extern const unsigned long fuse_timeout_timer_freq
;
57 /** Maximum of max_pages received in init_out */
58 extern unsigned int fuse_max_pages_limit
;
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.
63 extern unsigned int fuse_default_req_timeout
;
65 * Max timeout (in seconds) for the server to reply to a request before
66 * the connection is aborted.
68 extern unsigned int fuse_max_req_timeout
;
70 /** List of active connections */
71 extern struct list_head fuse_conn_list
;
73 /** Global mutex protecting fuse_conn_list and the control filesystem */
74 extern struct mutex fuse_mutex
;
76 /** Module parameters */
77 extern unsigned int max_user_bgreq
;
78 extern unsigned int max_user_congthresh
;
80 /* One forget request */
81 struct fuse_forget_link
{
82 struct fuse_forget_one forget_one
;
83 struct fuse_forget_link
*next
;
86 /* Submount lookup tracking */
87 struct fuse_submount_lookup
{
91 /** Unique ID, which identifies the inode between userspace
95 /** The request used for sending the FORGET message */
96 struct fuse_forget_link
*forget
;
99 /** Container for data related to mapping to backing file */
100 struct fuse_backing
{
114 /** Unique ID, which identifies the inode between userspace
118 /** Number of lookups on this inode */
121 /** The request used for sending the FORGET message */
122 struct fuse_forget_link
*forget
;
124 /** Time in jiffies until the file attributes are valid */
127 /* Which attributes are invalid */
130 /** The sticky bit in inode->i_mode may have been removed, so
131 preserve the original mode */
134 /* Cache birthtime */
135 struct timespec64 i_btime
;
137 /** 64 bit inode number */
140 /** Version of last attribute change */
144 /* read/write io cache (regular file only) */
146 /* Files usable in writepage. Protected by fi->lock */
147 struct list_head write_files
;
149 /* Writepages pending on truncate or fsync */
150 struct list_head queued_writes
;
152 /* Number of sent writes, a negative bias
153 * (FUSE_NOWRITE) means more writes are blocked */
156 /** Number of files/maps using page cache */
159 /* Waitq for writepage completion */
160 wait_queue_head_t page_waitq
;
162 /* waitq for direct-io completion */
163 wait_queue_head_t direct_io_waitq
;
166 /* readdir cache (directory only) */
168 /* true if fully cached */
174 /* position at end of cache (position of next entry) */
177 /* version of the cache */
180 /* modification time of directory when cache was
182 struct timespec64 mtime
;
184 /* iversion of directory when cache was started */
187 /* protects above fields */
192 /** Miscellaneous bits describing inode state */
195 /** Lock for serializing lookup and readdir for back compatibility*/
198 /** Lock to protect write related fields */
201 #ifdef CONFIG_FUSE_DAX
203 * Dax specific inode data
205 struct fuse_inode_dax
*dax
;
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
;
215 /** FUSE inode state bits */
217 /** Advise readdirplus */
218 FUSE_I_ADVISE_RDPLUS
,
219 /** Initialized with readdirplus */
221 /** An operation changing file size is in progress */
222 FUSE_I_SIZE_UNSTABLE
,
227 /* Wants or already has page cache IO */
228 FUSE_I_CACHE_IO_MODE
,
233 union fuse_file_args
;
235 /** FUSE specific file data */
237 /** Fuse connection for this file */
238 struct fuse_mount
*fm
;
240 /* Argument space reserved for open/release */
241 union fuse_file_args
*args
;
243 /** Kernel file handle guaranteed to be unique */
246 /** File handle used by userspace */
249 /** Node id of this file */
255 /** FOPEN_* flags returned by open */
258 /** Entry on inode's write_files list */
259 struct list_head write_entry
;
261 /* Readdir related */
263 /* Dir stream position */
266 /* Offset in cache */
269 /* Version of cache we are reading */
274 /** RB node to be linked on fuse_conn->polled_files */
275 struct rb_node polled_node
;
277 /** Wait queue head for poll */
278 wait_queue_head_t poll_wait
;
280 /** Does file hold a fi->iocachectr refcount? */
281 enum { IOM_NONE
, IOM_CACHED
, IOM_UNCACHED
} iomode
;
283 #ifdef CONFIG_FUSE_PASSTHROUGH
284 /** Reference to backing file in passthrough mode */
285 struct file
*passthrough
;
286 const struct cred
*cred
;
289 /** Has flock been performed on this file? */
293 /** One input argument of a request */
299 /** One output argument of a request */
305 /** FUSE folio descriptor */
306 struct fuse_folio_desc
{
329 bool invalidate_vmap
:1;
330 struct fuse_in_arg in_args
[4];
331 struct fuse_arg out_args
[2];
332 void (*end
)(struct fuse_mount
*fm
, struct fuse_args
*args
, int error
);
333 /* Used for kvec iter backed by vmalloc address */
337 struct fuse_args_pages
{
338 struct fuse_args args
;
339 struct folio
**folios
;
340 struct fuse_folio_desc
*descs
;
341 unsigned int num_folios
;
344 struct fuse_release_args
{
345 struct fuse_args args
;
346 struct fuse_release_in inarg
;
350 union fuse_file_args
{
351 /* Used during open() */
352 struct fuse_open_out open_outarg
;
353 /* Used during release() */
354 struct fuse_release_args release_args
;
357 #define FUSE_ARGS(args) struct fuse_args args = {}
359 /** The request IO state (for asynchronous processing) */
360 struct fuse_io_priv
{
372 struct completion
*done
;
376 #define FUSE_IO_PRIV_SYNC(i) \
378 .refcnt = KREF_INIT(1), \
386 * FR_ISREPLY: set if the request has reply
387 * FR_FORCE: force sending of the request even if interrupted
388 * FR_BACKGROUND: request is sent in the background
389 * FR_WAITING: request is counted as "waiting"
390 * FR_ABORTED: the request was aborted
391 * FR_INTERRUPTED: the request has been interrupted
392 * FR_LOCKED: data is being copied to/from the request
393 * FR_PENDING: request is not yet in userspace
394 * FR_SENT: request is in userspace, waiting for an answer
395 * FR_FINISHED: request is finished
396 * FR_PRIVATE: request is on private list
397 * FR_ASYNC: request is asynchronous
398 * FR_URING: request is handled through fuse-io-uring
417 * A request to the client
419 * .waitq.lock protects the following fields:
421 * - FR_LOCKED (may also be modified under fc->lock, tested under both)
424 /** This can be on either pending processing or io lists in
426 struct list_head list
;
428 /** Entry on the interrupts list */
429 struct list_head intr_entry
;
431 /* Input/output arguments */
432 struct fuse_args
*args
;
437 /* Request flags, updated with test/set/clear_bit() */
440 /* The request input header */
442 struct fuse_in_header h
;
445 /* The request output header */
447 struct fuse_out_header h
;
450 /** Used to wake up the task waiting for completion of request*/
451 wait_queue_head_t waitq
;
453 #if IS_ENABLED(CONFIG_VIRTIO_FS)
454 /** virtio-fs's physically contiguous buffer for in and out args */
458 /** fuse_mount this request belongs to */
459 struct fuse_mount
*fm
;
461 #ifdef CONFIG_FUSE_IO_URING
465 /** When (in jiffies) the request was created */
466 unsigned long create_time
;
472 * Input queue callbacks
474 * Input queue signalling is device-specific. For example, the /dev/fuse file
475 * uses fiq->waitq and fasync to wake processes that are waiting on queue
476 * readiness. These callbacks allow other device types to respond to input
479 struct fuse_iqueue_ops
{
483 void (*send_forget
)(struct fuse_iqueue
*fiq
, struct fuse_forget_link
*link
);
486 * Send interrupt for request
488 void (*send_interrupt
)(struct fuse_iqueue
*fiq
, struct fuse_req
*req
);
493 void (*send_req
)(struct fuse_iqueue
*fiq
, struct fuse_req
*req
);
496 * Clean up when fuse_iqueue is destroyed
498 void (*release
)(struct fuse_iqueue
*fiq
);
501 /** /dev/fuse input queue operations */
502 extern const struct fuse_iqueue_ops fuse_dev_fiq_ops
;
505 /** Connection established */
508 /** Lock protecting accesses to members of this structure */
511 /** Readers of the connection are waiting on this */
512 wait_queue_head_t waitq
;
514 /** The next unique request id */
517 /** The list of pending requests */
518 struct list_head pending
;
520 /** Pending interrupts */
521 struct list_head interrupts
;
523 /** Queue of pending forgets */
524 struct fuse_forget_link forget_list_head
;
525 struct fuse_forget_link
*forget_list_tail
;
527 /** Batching of FORGET requests (positive indicates FORGET batch) */
530 /** O_ASYNC requests */
531 struct fasync_struct
*fasync
;
533 /** Device-specific callbacks */
534 const struct fuse_iqueue_ops
*ops
;
536 /** Device-specific state */
540 #define FUSE_PQ_HASH_BITS 8
541 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
544 /** Connection established */
547 /** Lock protecting accessess to members of this structure */
550 /** Hash table of requests being processed */
551 struct list_head
*processing
;
553 /** The list of requests under I/O */
558 * Fuse device instance
561 /** Fuse connection for this device */
562 struct fuse_conn
*fc
;
564 /** Processing queue */
565 struct fuse_pqueue pq
;
567 /** list entry on fc->devices */
568 struct list_head entry
;
572 FUSE_DAX_INODE_DEFAULT
, /* default */
573 FUSE_DAX_ALWAYS
, /* "-o dax=always" */
574 FUSE_DAX_NEVER
, /* "-o dax=never" */
575 FUSE_DAX_INODE_USER
, /* "-o dax=inode" */
578 static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode
)
580 return mode
== FUSE_DAX_INODE_DEFAULT
|| mode
== FUSE_DAX_INODE_USER
;
583 struct fuse_fs_context
{
586 unsigned int rootmode
;
591 bool rootmode_present
:1;
592 bool user_id_present
:1;
593 bool group_id_present
:1;
594 bool default_permissions
:1;
598 bool no_force_umount
:1;
599 bool legacy_opts_show
:1;
600 enum fuse_dax_mode dax_mode
;
601 unsigned int max_read
;
602 unsigned int blksize
;
605 /* DAX device, may be NULL */
606 struct dax_device
*dax_dev
;
608 /* fuse_dev pointer to fill in, should contain NULL on entry */
612 struct fuse_sync_bucket
{
613 /* count is a possible scalability bottleneck */
615 wait_queue_head_t waitq
;
622 * This structure is created, when the root filesystem is mounted, and
623 * is destroyed, when the client device is closed and the last
624 * fuse_mount is destroyed.
627 /** Lock protecting accessess to members of this structure */
633 /** Number of fuse_dev's */
636 /** Current epoch for up-to-date dentries */
641 /** The user id for this mount */
644 /** The group id for this mount */
647 /** The pid namespace for this mount */
648 struct pid_namespace
*pid_ns
;
650 /** The user namespace for this mount */
651 struct user_namespace
*user_ns
;
653 /** Maximum read size */
656 /** Maximum write size */
659 /** Maximum number of pages that can be used in a single request */
660 unsigned int max_pages
;
662 /** Constrain ->max_pages to this value during feature negotiation */
663 unsigned int max_pages_limit
;
666 struct fuse_iqueue iq
;
668 /** The next unique kernel file handle */
671 /** rbtree of fuse_files waiting for poll events indexed by ph */
672 struct rb_root polled_files
;
674 /** Maximum number of outstanding background requests */
675 unsigned max_background
;
677 /** Number of background requests at which congestion starts */
678 unsigned congestion_threshold
;
680 /** Number of requests currently in the background */
681 unsigned num_background
;
683 /** Number of background requests currently queued for userspace */
684 unsigned active_background
;
686 /** The list of background requests set aside for later queuing */
687 struct list_head bg_queue
;
689 /** Protects: max_background, congestion_threshold, num_background,
690 * active_background, bg_queue, blocked */
693 /** Flag indicating that INIT reply has been received. Allocating
694 * any fuse request will be suspended until the flag is set */
697 /** Flag indicating if connection is blocked. This will be
698 the case before the INIT reply is received, and if there
699 are too many outstading backgrounds requests */
702 /** waitq for blocked connection */
703 wait_queue_head_t blocked_waitq
;
705 /** Connection established, cleared on umount, connection
706 abort and device release */
709 /** Connection aborted via sysfs */
712 /** Connection failed (version mismatch). Cannot race with
713 setting other bitfields since it is only set once in INIT
714 reply, before any other request, and never cleared */
715 unsigned conn_error
:1;
717 /** Connection successful. Only set in INIT */
718 unsigned conn_init
:1;
720 /** Do readahead asynchronously? Only set in INIT */
721 unsigned async_read
:1;
723 /** Return an unique read error after abort. Only set in INIT */
724 unsigned abort_err
:1;
726 /** Do not send separate SETATTR request before open(O_TRUNC) */
727 unsigned atomic_o_trunc
:1;
729 /** Filesystem supports NFS exporting. Only set in INIT */
730 unsigned export_support
:1;
732 /** write-back cache policy (default is write-through) */
733 unsigned writeback_cache
:1;
735 /** allow parallel lookups and readdir (default is serialized) */
736 unsigned parallel_dirops
:1;
738 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
739 unsigned handle_killpriv
:1;
741 /** cache READLINK responses in page cache */
742 unsigned cache_symlinks
:1;
744 /* show legacy mount options */
745 unsigned int legacy_opts_show
:1;
748 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
749 * write/trunc only if caller did not have CAP_FSETID. sgid is killed
750 * on write/truncate only if caller did not have CAP_FSETID as well as
751 * file has group execute permission.
753 unsigned handle_killpriv_v2
:1;
756 * The following bitfields are only for optimization purposes
757 * and hence races in setting them will not cause malfunction
760 /** Is open/release not implemented by fs? */
763 /** Is opendir/releasedir not implemented by fs? */
764 unsigned no_opendir
:1;
766 /** Is fsync not implemented by fs? */
769 /** Is fsyncdir not implemented by fs? */
770 unsigned no_fsyncdir
:1;
772 /** Is flush not implemented by fs? */
775 /** Is setxattr not implemented by fs? */
776 unsigned no_setxattr
:1;
778 /** Does file server support extended setxattr */
779 unsigned setxattr_ext
:1;
781 /** Is getxattr not implemented by fs? */
782 unsigned no_getxattr
:1;
784 /** Is listxattr not implemented by fs? */
785 unsigned no_listxattr
:1;
787 /** Is removexattr not implemented by fs? */
788 unsigned no_removexattr
:1;
790 /** Are posix file locking primitives not implemented by fs? */
793 /** Is access not implemented by fs? */
794 unsigned no_access
:1;
796 /** Is create not implemented by fs? */
797 unsigned no_create
:1;
799 /** Is interrupt not implemented by fs? */
800 unsigned no_interrupt
:1;
802 /** Is bmap not implemented by fs? */
805 /** Is poll not implemented by fs? */
808 /** Do multi-page cached writes */
809 unsigned big_writes
:1;
811 /** Don't apply umask to creation modes */
812 unsigned dont_mask
:1;
814 /** Are BSD file locking primitives not implemented by fs? */
817 /** Is fallocate not implemented by fs? */
818 unsigned no_fallocate
:1;
820 /** Is rename with flags implemented by fs? */
821 unsigned no_rename2
:1;
823 /** Use enhanced/automatic page cache invalidation. */
824 unsigned auto_inval_data
:1;
826 /** Filesystem is fully responsible for page cache invalidation. */
827 unsigned explicit_inval_data
:1;
829 /** Does the filesystem support readdirplus? */
830 unsigned do_readdirplus
:1;
832 /** Does the filesystem want adaptive readdirplus? */
833 unsigned readdirplus_auto
:1;
835 /** Does the filesystem support asynchronous direct-IO submission? */
836 unsigned async_dio
:1;
838 /** Is lseek not implemented by fs? */
841 /** Does the filesystem support posix acls? */
842 unsigned posix_acl
:1;
844 /** Check permissions based on the file mode or not? */
845 unsigned default_permissions
:1;
847 /** Allow other than the mounter user to access the filesystem ? */
848 unsigned allow_other
:1;
850 /** Does the filesystem support copy_file_range? */
851 unsigned no_copy_file_range
:1;
853 /* Send DESTROY request */
854 unsigned int destroy
:1;
856 /* Delete dentries that have gone stale */
857 unsigned int delete_stale
:1;
859 /** Do not create entry in fusectl fs */
860 unsigned int no_control
:1;
862 /** Do not allow MNT_FORCE umount */
863 unsigned int no_force_umount
:1;
865 /* Auto-mount submounts announced by the server */
866 unsigned int auto_submounts
:1;
868 /* Propagate syncfs() to server */
869 unsigned int sync_fs
:1;
871 /* Initialize security xattrs when creating a new inode */
872 unsigned int init_security
:1;
874 /* Add supplementary group info when creating a new inode */
875 unsigned int create_supp_group
:1;
877 /* Does the filesystem support per inode DAX? */
878 unsigned int inode_dax
:1;
880 /* Is tmpfile not implemented by fs? */
881 unsigned int no_tmpfile
:1;
883 /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
884 unsigned int direct_io_allow_mmap
:1;
886 /* Is statx not implemented by fs? */
887 unsigned int no_statx
:1;
889 /** Passthrough support for read/write IO */
890 unsigned int passthrough
:1;
892 /* Use pages instead of pointer for kernel I/O */
893 unsigned int use_pages_for_kvec_io
:1;
895 /* Is link not implemented by fs? */
896 unsigned int no_link
:1;
898 /* Use io_uring for communication */
899 unsigned int io_uring
;
901 /** Maximum stack depth for passthrough backing files */
904 /** The number of requests waiting for completion */
905 atomic_t num_waiting
;
907 /** Negotiated minor version */
910 /** Entry on the fuse_conn_list */
911 struct list_head entry
;
913 /** Device ID from the root super block */
916 /** Dentries in the control filesystem */
917 struct dentry
*ctl_dentry
[FUSE_CTL_NUM_DENTRIES
];
919 /** number of dentries used in the above array */
922 /** Key for lock owner ID scrambling */
925 /** Version counter for attribute changes */
926 atomic64_t attr_version
;
928 /** Version counter for evict inode */
929 atomic64_t evict_ctr
;
931 /* maximum file name length */
934 /** Called on final put */
935 void (*release
)(struct fuse_conn
*);
938 * Read/write semaphore to hold when accessing the sb of any
939 * fuse_mount belonging to this connection
941 struct rw_semaphore killsb
;
943 /** List of device instances belonging to this connection */
944 struct list_head devices
;
946 #ifdef CONFIG_FUSE_DAX
948 enum fuse_dax_mode dax_mode
;
950 /* Dax specific conn data, non-NULL if DAX is enabled */
951 struct fuse_conn_dax
*dax
;
954 /** List of filesystems using this connection */
955 struct list_head mounts
;
957 /* New writepages go into this bucket */
958 struct fuse_sync_bucket __rcu
*curr_bucket
;
960 #ifdef CONFIG_FUSE_PASSTHROUGH
961 /** IDR for backing files ids */
962 struct idr backing_files_map
;
965 #ifdef CONFIG_FUSE_IO_URING
966 /** uring connection information*/
967 struct fuse_ring
*ring
;
970 /** Only used if the connection opts into request timeouts */
972 /* Worker for checking if any requests have timed out */
973 struct delayed_work work
;
975 /* Request timeout (in jiffies). 0 = no timeout */
976 unsigned int req_timeout
;
981 * Represents a mounted filesystem, potentially a submount.
983 * This object allows sharing a fuse_conn between separate mounts to
984 * allow submounts with dedicated superblocks and thus separate device
988 /* Underlying (potentially shared) connection to the FUSE server */
989 struct fuse_conn
*fc
;
992 * Super block for this connection (fc->killsb must be held when
995 struct super_block
*sb
;
997 /* Entry on fc->mounts */
998 struct list_head fc_entry
;
1003 * Empty header for FUSE opcodes without specific header needs.
1004 * Used as a placeholder in args->in_args[0] for consistency
1005 * across all FUSE operations, simplifying request handling.
1007 struct fuse_zero_header
{};
1009 static inline void fuse_set_zero_arg0(struct fuse_args
*args
)
1011 args
->in_args
[0].size
= sizeof(struct fuse_zero_header
);
1012 args
->in_args
[0].value
= NULL
;
1015 static inline struct fuse_mount
*get_fuse_mount_super(struct super_block
*sb
)
1017 return sb
->s_fs_info
;
1020 static inline struct fuse_conn
*get_fuse_conn_super(struct super_block
*sb
)
1022 return get_fuse_mount_super(sb
)->fc
;
1025 static inline struct fuse_mount
*get_fuse_mount(struct inode
*inode
)
1027 return get_fuse_mount_super(inode
->i_sb
);
1030 static inline struct fuse_conn
*get_fuse_conn(struct inode
*inode
)
1032 return get_fuse_mount_super(inode
->i_sb
)->fc
;
1035 static inline struct fuse_inode
*get_fuse_inode(struct inode
*inode
)
1037 return container_of(inode
, struct fuse_inode
, inode
);
1040 static inline u64
get_node_id(struct inode
*inode
)
1042 return get_fuse_inode(inode
)->nodeid
;
1045 static inline int invalid_nodeid(u64 nodeid
)
1047 return !nodeid
|| nodeid
== FUSE_ROOT_ID
;
1050 static inline u64
fuse_get_attr_version(struct fuse_conn
*fc
)
1052 return atomic64_read(&fc
->attr_version
);
1055 static inline u64
fuse_get_evict_ctr(struct fuse_conn
*fc
)
1057 return atomic64_read(&fc
->evict_ctr
);
1060 static inline bool fuse_stale_inode(const struct inode
*inode
, int generation
,
1061 struct fuse_attr
*attr
)
1063 return inode
->i_generation
!= generation
||
1064 inode_wrong_type(inode
, attr
->mode
);
1067 static inline void fuse_make_bad(struct inode
*inode
)
1069 set_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
);
1072 static inline bool fuse_is_bad(struct inode
*inode
)
1074 return unlikely(test_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
));
1077 static inline struct folio
**fuse_folios_alloc(unsigned int nfolios
, gfp_t flags
,
1078 struct fuse_folio_desc
**desc
)
1080 struct folio
**folios
;
1082 folios
= kzalloc(nfolios
* (sizeof(struct folio
*) +
1083 sizeof(struct fuse_folio_desc
)), flags
);
1084 *desc
= (void *) (folios
+ nfolios
);
1089 static inline void fuse_folio_descs_length_init(struct fuse_folio_desc
*descs
,
1091 unsigned int nr_folios
)
1095 for (i
= index
; i
< index
+ nr_folios
; i
++)
1096 descs
[i
].length
= PAGE_SIZE
- descs
[i
].offset
;
1099 static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket
*bucket
)
1101 /* Need RCU protection to prevent use after free after the decrement */
1103 if (atomic_dec_and_test(&bucket
->count
))
1104 wake_up(&bucket
->waitq
);
1108 /** Device operations */
1109 extern const struct file_operations fuse_dev_operations
;
1111 extern const struct dentry_operations fuse_dentry_operations
;
1112 extern const struct dentry_operations fuse_root_dentry_operations
;
1115 * Get a filled in inode
1117 struct inode
*fuse_iget(struct super_block
*sb
, u64 nodeid
,
1118 int generation
, struct fuse_attr
*attr
,
1119 u64 attr_valid
, u64 attr_version
,
1122 int fuse_lookup_name(struct super_block
*sb
, u64 nodeid
, const struct qstr
*name
,
1123 struct fuse_entry_out
*outarg
, struct inode
**inode
);
1126 * Send FORGET command
1128 void fuse_queue_forget(struct fuse_conn
*fc
, struct fuse_forget_link
*forget
,
1129 u64 nodeid
, u64 nlookup
);
1131 struct fuse_forget_link
*fuse_alloc_forget(void);
1134 * Initialize READ or READDIR request
1136 struct fuse_io_args
{
1139 struct fuse_read_in in
;
1143 struct fuse_write_in in
;
1144 struct fuse_write_out out
;
1148 struct fuse_args_pages ap
;
1149 struct fuse_io_priv
*io
;
1150 struct fuse_file
*ff
;
1153 void fuse_read_args_fill(struct fuse_io_args
*ia
, struct file
*file
, loff_t pos
,
1154 size_t count
, int opcode
);
1157 struct fuse_file
*fuse_file_alloc(struct fuse_mount
*fm
, bool release
);
1158 void fuse_file_free(struct fuse_file
*ff
);
1159 int fuse_finish_open(struct inode
*inode
, struct file
*file
);
1161 void fuse_sync_release(struct fuse_inode
*fi
, struct fuse_file
*ff
,
1162 unsigned int flags
);
1165 * Send RELEASE or RELEASEDIR request
1167 void fuse_release_common(struct file
*file
, bool isdir
);
1170 * Send FSYNC or FSYNCDIR request
1172 int fuse_fsync_common(struct file
*file
, loff_t start
, loff_t end
,
1173 int datasync
, int opcode
);
1176 * Notify poll wakeup
1178 int fuse_notify_poll_wakeup(struct fuse_conn
*fc
,
1179 struct fuse_notify_poll_wakeup_out
*outarg
);
1182 * Initialize file operations on a regular file
1184 void fuse_init_file_inode(struct inode
*inode
, unsigned int flags
);
1187 * Initialize inode operations on regular files and special files
1189 void fuse_init_common(struct inode
*inode
);
1192 * Initialize inode and file operations on a directory
1194 void fuse_init_dir(struct inode
*inode
);
1197 * Initialize inode operations on a symlink
1199 void fuse_init_symlink(struct inode
*inode
);
1202 * Change attributes of an inode
1204 void fuse_change_attributes(struct inode
*inode
, struct fuse_attr
*attr
,
1205 struct fuse_statx
*sx
,
1206 u64 attr_valid
, u64 attr_version
);
1208 void fuse_change_attributes_common(struct inode
*inode
, struct fuse_attr
*attr
,
1209 struct fuse_statx
*sx
,
1210 u64 attr_valid
, u32 cache_mask
,
1213 u32
fuse_get_cache_mask(struct inode
*inode
);
1216 * Initialize the client device
1218 int fuse_dev_init(void);
1221 * Cleanup the client device
1223 void fuse_dev_cleanup(void);
1225 int fuse_ctl_init(void);
1226 void __exit
fuse_ctl_cleanup(void);
1229 * Simple request sending that does request allocation and freeing
1231 ssize_t
__fuse_simple_request(struct mnt_idmap
*idmap
,
1232 struct fuse_mount
*fm
,
1233 struct fuse_args
*args
);
1235 static inline ssize_t
fuse_simple_request(struct fuse_mount
*fm
, struct fuse_args
*args
)
1237 return __fuse_simple_request(&invalid_mnt_idmap
, fm
, args
);
1240 static inline ssize_t
fuse_simple_idmap_request(struct mnt_idmap
*idmap
,
1241 struct fuse_mount
*fm
,
1242 struct fuse_args
*args
)
1244 return __fuse_simple_request(idmap
, fm
, args
);
1247 int fuse_simple_background(struct fuse_mount
*fm
, struct fuse_args
*args
,
1251 * End a finished request
1253 void fuse_request_end(struct fuse_req
*req
);
1255 /* Abort all requests */
1256 void fuse_abort_conn(struct fuse_conn
*fc
);
1257 void fuse_wait_aborted(struct fuse_conn
*fc
);
1259 /* Check if any requests timed out */
1260 void fuse_check_timeout(struct work_struct
*work
);
1263 * Invalidate inode attributes
1266 /* Attributes possibly changed on data modification */
1267 #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1269 /* Attributes possibly changed on data and/or size modification */
1270 #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
1272 void fuse_invalidate_attr(struct inode
*inode
);
1273 void fuse_invalidate_attr_mask(struct inode
*inode
, u32 mask
);
1275 void fuse_invalidate_entry_cache(struct dentry
*entry
);
1277 void fuse_invalidate_atime(struct inode
*inode
);
1279 u64
fuse_time_to_jiffies(u64 sec
, u32 nsec
);
1280 #define ATTR_TIMEOUT(o) \
1281 fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
1283 void fuse_change_entry_timeout(struct dentry
*entry
, struct fuse_entry_out
*o
);
1286 * Acquire reference to fuse_conn
1288 struct fuse_conn
*fuse_conn_get(struct fuse_conn
*fc
);
1291 * Initialize the fuse processing queue
1293 void fuse_pqueue_init(struct fuse_pqueue
*fpq
);
1296 * Initialize fuse_conn
1298 void fuse_conn_init(struct fuse_conn
*fc
, struct fuse_mount
*fm
,
1299 struct user_namespace
*user_ns
,
1300 const struct fuse_iqueue_ops
*fiq_ops
, void *fiq_priv
);
1303 * Release reference to fuse_conn
1305 void fuse_conn_put(struct fuse_conn
*fc
);
1307 struct fuse_dev
*fuse_dev_alloc_install(struct fuse_conn
*fc
);
1308 struct fuse_dev
*fuse_dev_alloc(void);
1309 void fuse_dev_install(struct fuse_dev
*fud
, struct fuse_conn
*fc
);
1310 void fuse_dev_free(struct fuse_dev
*fud
);
1311 void fuse_send_init(struct fuse_mount
*fm
);
1314 * Fill in superblock and initialize fuse connection
1315 * @sb: partially-initialized superblock to fill in
1316 * @ctx: mount context
1318 int fuse_fill_super_common(struct super_block
*sb
, struct fuse_fs_context
*ctx
);
1321 * Remove the mount from the connection
1323 * Returns whether this was the last mount
1325 bool fuse_mount_remove(struct fuse_mount
*fm
);
1328 * Setup context ops for submounts
1330 int fuse_init_fs_context_submount(struct fs_context
*fsc
);
1333 * Shut down the connection (possibly sending DESTROY request).
1335 void fuse_conn_destroy(struct fuse_mount
*fm
);
1337 /* Drop the connection and free the fuse mount */
1338 void fuse_mount_destroy(struct fuse_mount
*fm
);
1341 * Add connection to control filesystem
1343 int fuse_ctl_add_conn(struct fuse_conn
*fc
);
1346 * Remove connection from control filesystem
1348 void fuse_ctl_remove_conn(struct fuse_conn
*fc
);
1351 * Is file type valid?
1353 int fuse_valid_type(int m
);
1355 bool fuse_invalid_attr(struct fuse_attr
*attr
);
1358 * Is current process allowed to perform filesystem operation?
1360 bool fuse_allow_current_process(struct fuse_conn
*fc
);
1362 u64
fuse_lock_owner_id(struct fuse_conn
*fc
, fl_owner_t id
);
1364 void fuse_flush_time_update(struct inode
*inode
);
1365 void fuse_update_ctime(struct inode
*inode
);
1367 int fuse_update_attributes(struct inode
*inode
, struct file
*file
, u32 mask
);
1369 void fuse_flush_writepages(struct inode
*inode
);
1371 void fuse_set_nowrite(struct inode
*inode
);
1372 void fuse_release_nowrite(struct inode
*inode
);
1375 * Scan all fuse_mounts belonging to fc to find the first where
1376 * ilookup5() returns a result. Return that result and the
1377 * respective fuse_mount in *fm (unless fm is NULL).
1379 * The caller must hold fc->killsb.
1381 struct inode
*fuse_ilookup(struct fuse_conn
*fc
, u64 nodeid
,
1382 struct fuse_mount
**fm
);
1385 * File-system tells the kernel to invalidate cache for the given node id.
1387 int fuse_reverse_inval_inode(struct fuse_conn
*fc
, u64 nodeid
,
1388 loff_t offset
, loff_t len
);
1391 * File-system tells the kernel to invalidate parent attributes and
1392 * the dentry matching parent/name.
1394 * If the child_nodeid is non-zero and:
1395 * - matches the inode number for the dentry matching parent/name,
1396 * - is not a mount point
1397 * - is a file or oan empty directory
1398 * then the dentry is unhashed (d_delete()).
1400 int fuse_reverse_inval_entry(struct fuse_conn
*fc
, u64 parent_nodeid
,
1401 u64 child_nodeid
, struct qstr
*name
, u32 flags
);
1403 int fuse_do_open(struct fuse_mount
*fm
, u64 nodeid
, struct file
*file
,
1407 * fuse_direct_io() flags
1410 /** If set, it is WRITE; otherwise - READ */
1411 #define FUSE_DIO_WRITE (1 << 0)
1413 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1414 #define FUSE_DIO_CUSE (1 << 1)
1416 ssize_t
fuse_direct_io(struct fuse_io_priv
*io
, struct iov_iter
*iter
,
1417 loff_t
*ppos
, int flags
);
1418 long fuse_do_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
,
1419 unsigned int flags
);
1420 long fuse_ioctl_common(struct file
*file
, unsigned int cmd
,
1421 unsigned long arg
, unsigned int flags
);
1422 __poll_t
fuse_file_poll(struct file
*file
, poll_table
*wait
);
1423 int fuse_dev_release(struct inode
*inode
, struct file
*file
);
1425 bool fuse_write_update_attr(struct inode
*inode
, loff_t pos
, ssize_t written
);
1427 int fuse_flush_times(struct inode
*inode
, struct fuse_file
*ff
);
1428 int fuse_write_inode(struct inode
*inode
, struct writeback_control
*wbc
);
1430 int fuse_do_setattr(struct mnt_idmap
*idmap
, struct dentry
*dentry
,
1431 struct iattr
*attr
, struct file
*file
);
1433 void fuse_set_initialized(struct fuse_conn
*fc
);
1435 void fuse_unlock_inode(struct inode
*inode
, bool locked
);
1436 bool fuse_lock_inode(struct inode
*inode
);
1438 int fuse_setxattr(struct inode
*inode
, const char *name
, const void *value
,
1439 size_t size
, int flags
, unsigned int extra_flags
);
1440 ssize_t
fuse_getxattr(struct inode
*inode
, const char *name
, void *value
,
1442 ssize_t
fuse_listxattr(struct dentry
*entry
, char *list
, size_t size
);
1443 int fuse_removexattr(struct inode
*inode
, const char *name
);
1444 extern const struct xattr_handler
* const fuse_xattr_handlers
[];
1447 struct posix_acl
*fuse_get_inode_acl(struct inode
*inode
, int type
, bool rcu
);
1448 struct posix_acl
*fuse_get_acl(struct mnt_idmap
*idmap
,
1449 struct dentry
*dentry
, int type
);
1450 int fuse_set_acl(struct mnt_idmap
*, struct dentry
*dentry
,
1451 struct posix_acl
*acl
, int type
);
1454 int fuse_readdir(struct file
*file
, struct dir_context
*ctx
);
1457 * Return the number of bytes in an arguments list
1459 unsigned int fuse_len_args(unsigned int numargs
, struct fuse_arg
*args
);
1462 * Get the next unique ID for a request
1464 u64
fuse_get_unique(struct fuse_iqueue
*fiq
);
1465 void fuse_free_conn(struct fuse_conn
*fc
);
1469 #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1471 ssize_t
fuse_dax_read_iter(struct kiocb
*iocb
, struct iov_iter
*to
);
1472 ssize_t
fuse_dax_write_iter(struct kiocb
*iocb
, struct iov_iter
*from
);
1473 int fuse_dax_mmap(struct file
*file
, struct vm_area_struct
*vma
);
1474 int fuse_dax_break_layouts(struct inode
*inode
, u64 dmap_start
, u64 dmap_end
);
1475 int fuse_dax_conn_alloc(struct fuse_conn
*fc
, enum fuse_dax_mode mode
,
1476 struct dax_device
*dax_dev
);
1477 void fuse_dax_conn_free(struct fuse_conn
*fc
);
1478 bool fuse_dax_inode_alloc(struct super_block
*sb
, struct fuse_inode
*fi
);
1479 void fuse_dax_inode_init(struct inode
*inode
, unsigned int flags
);
1480 void fuse_dax_inode_cleanup(struct inode
*inode
);
1481 void fuse_dax_dontcache(struct inode
*inode
, unsigned int flags
);
1482 bool fuse_dax_check_alignment(struct fuse_conn
*fc
, unsigned int map_alignment
);
1483 void fuse_dax_cancel_work(struct fuse_conn
*fc
);
1486 long fuse_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
1487 long fuse_file_compat_ioctl(struct file
*file
, unsigned int cmd
,
1489 int fuse_fileattr_get(struct dentry
*dentry
, struct fileattr
*fa
);
1490 int fuse_fileattr_set(struct mnt_idmap
*idmap
,
1491 struct dentry
*dentry
, struct fileattr
*fa
);
1494 int fuse_file_cached_io_open(struct inode
*inode
, struct fuse_file
*ff
);
1495 int fuse_inode_uncached_io_start(struct fuse_inode
*fi
,
1496 struct fuse_backing
*fb
);
1497 void fuse_inode_uncached_io_end(struct fuse_inode
*fi
);
1499 int fuse_file_io_open(struct file
*file
, struct inode
*inode
);
1500 void fuse_file_io_release(struct fuse_file
*ff
, struct inode
*inode
);
1503 struct fuse_file
*fuse_file_open(struct fuse_mount
*fm
, u64 nodeid
,
1504 unsigned int open_flags
, bool isdir
);
1505 void fuse_file_release(struct inode
*inode
, struct fuse_file
*ff
,
1506 unsigned int open_flags
, fl_owner_t id
, bool isdir
);
1509 static inline struct fuse_backing
*fuse_inode_backing(struct fuse_inode
*fi
)
1511 #ifdef CONFIG_FUSE_PASSTHROUGH
1512 return READ_ONCE(fi
->fb
);
1518 static inline struct fuse_backing
*fuse_inode_backing_set(struct fuse_inode
*fi
,
1519 struct fuse_backing
*fb
)
1521 #ifdef CONFIG_FUSE_PASSTHROUGH
1522 return xchg(&fi
->fb
, fb
);
1528 #ifdef CONFIG_FUSE_PASSTHROUGH
1529 struct fuse_backing
*fuse_backing_get(struct fuse_backing
*fb
);
1530 void fuse_backing_put(struct fuse_backing
*fb
);
1533 static inline struct fuse_backing
*fuse_backing_get(struct fuse_backing
*fb
)
1538 static inline void fuse_backing_put(struct fuse_backing
*fb
)
1543 void fuse_backing_files_init(struct fuse_conn
*fc
);
1544 void fuse_backing_files_free(struct fuse_conn
*fc
);
1545 int fuse_backing_open(struct fuse_conn
*fc
, struct fuse_backing_map
*map
);
1546 int fuse_backing_close(struct fuse_conn
*fc
, int backing_id
);
1548 struct fuse_backing
*fuse_passthrough_open(struct file
*file
,
1549 struct inode
*inode
,
1551 void fuse_passthrough_release(struct fuse_file
*ff
, struct fuse_backing
*fb
);
1553 static inline struct file
*fuse_file_passthrough(struct fuse_file
*ff
)
1555 #ifdef CONFIG_FUSE_PASSTHROUGH
1556 return ff
->passthrough
;
1562 ssize_t
fuse_passthrough_read_iter(struct kiocb
*iocb
, struct iov_iter
*iter
);
1563 ssize_t
fuse_passthrough_write_iter(struct kiocb
*iocb
, struct iov_iter
*iter
);
1564 ssize_t
fuse_passthrough_splice_read(struct file
*in
, loff_t
*ppos
,
1565 struct pipe_inode_info
*pipe
,
1566 size_t len
, unsigned int flags
);
1567 ssize_t
fuse_passthrough_splice_write(struct pipe_inode_info
*pipe
,
1568 struct file
*out
, loff_t
*ppos
,
1569 size_t len
, unsigned int flags
);
1570 ssize_t
fuse_passthrough_mmap(struct file
*file
, struct vm_area_struct
*vma
);
1572 #ifdef CONFIG_SYSCTL
1573 extern int fuse_sysctl_register(void);
1574 extern void fuse_sysctl_unregister(void);
1576 #define fuse_sysctl_register() (0)
1577 #define fuse_sysctl_unregister() do { } while (0)
1578 #endif /* CONFIG_SYSCTL */
1580 #endif /* _FS_FUSE_I_H */