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 /** It could be as large as PATH_MAX, but would that have any uses? */
42 #define FUSE_NAME_MAX 1024
44 /** Number of dentries for each connection in the control filesystem */
45 #define FUSE_CTL_NUM_DENTRIES 5
47 /** Maximum of max_pages received in init_out */
48 extern unsigned int fuse_max_pages_limit
;
50 /** List of active connections */
51 extern struct list_head fuse_conn_list
;
53 /** Global mutex protecting fuse_conn_list and the control filesystem */
54 extern struct mutex fuse_mutex
;
56 /** Module parameters */
57 extern unsigned max_user_bgreq
;
58 extern unsigned max_user_congthresh
;
60 /* One forget request */
61 struct fuse_forget_link
{
62 struct fuse_forget_one forget_one
;
63 struct fuse_forget_link
*next
;
66 /* Submount lookup tracking */
67 struct fuse_submount_lookup
{
71 /** Unique ID, which identifies the inode between userspace
75 /** The request used for sending the FORGET message */
76 struct fuse_forget_link
*forget
;
79 /** Container for data related to mapping to backing file */
94 /** Unique ID, which identifies the inode between userspace
98 /** Number of lookups on this inode */
101 /** The request used for sending the FORGET message */
102 struct fuse_forget_link
*forget
;
104 /** Time in jiffies until the file attributes are valid */
107 /* Which attributes are invalid */
110 /** The sticky bit in inode->i_mode may have been removed, so
111 preserve the original mode */
114 /* Cache birthtime */
115 struct timespec64 i_btime
;
117 /** 64 bit inode number */
120 /** Version of last attribute change */
124 /* read/write io cache (regular file only) */
126 /* Files usable in writepage. Protected by fi->lock */
127 struct list_head write_files
;
129 /* Writepages pending on truncate or fsync */
130 struct list_head queued_writes
;
132 /* Number of sent writes, a negative bias
133 * (FUSE_NOWRITE) means more writes are blocked */
136 /** Number of files/maps using page cache */
139 /* Waitq for writepage completion */
140 wait_queue_head_t page_waitq
;
142 /* waitq for direct-io completion */
143 wait_queue_head_t direct_io_waitq
;
145 /* List of writepage requestst (pending or sent) */
146 struct rb_root writepages
;
149 /* readdir cache (directory only) */
151 /* true if fully cached */
157 /* position at end of cache (position of next entry) */
160 /* version of the cache */
163 /* modification time of directory when cache was
165 struct timespec64 mtime
;
167 /* iversion of directory when cache was started */
170 /* protects above fields */
175 /** Miscellaneous bits describing inode state */
178 /** Lock for serializing lookup and readdir for back compatibility*/
181 /** Lock to protect write related fields */
184 #ifdef CONFIG_FUSE_DAX
186 * Dax specific inode data
188 struct fuse_inode_dax
*dax
;
190 /** Submount specific lookup tracking */
191 struct fuse_submount_lookup
*submount_lookup
;
192 #ifdef CONFIG_FUSE_PASSTHROUGH
193 /** Reference to backing file in passthrough mode */
194 struct fuse_backing
*fb
;
198 /** FUSE inode state bits */
200 /** Advise readdirplus */
201 FUSE_I_ADVISE_RDPLUS
,
202 /** Initialized with readdirplus */
204 /** An operation changing file size is in progress */
205 FUSE_I_SIZE_UNSTABLE
,
210 /* Wants or already has page cache IO */
211 FUSE_I_CACHE_IO_MODE
,
216 union fuse_file_args
;
218 /** FUSE specific file data */
220 /** Fuse connection for this file */
221 struct fuse_mount
*fm
;
223 /* Argument space reserved for open/release */
224 union fuse_file_args
*args
;
226 /** Kernel file handle guaranteed to be unique */
229 /** File handle used by userspace */
232 /** Node id of this file */
238 /** FOPEN_* flags returned by open */
241 /** Entry on inode's write_files list */
242 struct list_head write_entry
;
244 /* Readdir related */
246 /* Dir stream position */
249 /* Offset in cache */
252 /* Version of cache we are reading */
257 /** RB node to be linked on fuse_conn->polled_files */
258 struct rb_node polled_node
;
260 /** Wait queue head for poll */
261 wait_queue_head_t poll_wait
;
263 /** Does file hold a fi->iocachectr refcount? */
264 enum { IOM_NONE
, IOM_CACHED
, IOM_UNCACHED
} iomode
;
266 #ifdef CONFIG_FUSE_PASSTHROUGH
267 /** Reference to backing file in passthrough mode */
268 struct file
*passthrough
;
269 const struct cred
*cred
;
272 /** Has flock been performed on this file? */
276 /** One input argument of a request */
282 /** One output argument of a request */
288 /** FUSE folio descriptor */
289 struct fuse_folio_desc
{
312 bool invalidate_vmap
:1;
313 struct fuse_in_arg in_args
[3];
314 struct fuse_arg out_args
[2];
315 void (*end
)(struct fuse_mount
*fm
, struct fuse_args
*args
, int error
);
316 /* Used for kvec iter backed by vmalloc address */
320 struct fuse_args_pages
{
321 struct fuse_args args
;
322 struct folio
**folios
;
323 struct fuse_folio_desc
*descs
;
324 unsigned int num_folios
;
327 struct fuse_release_args
{
328 struct fuse_args args
;
329 struct fuse_release_in inarg
;
333 union fuse_file_args
{
334 /* Used during open() */
335 struct fuse_open_out open_outarg
;
336 /* Used during release() */
337 struct fuse_release_args release_args
;
340 #define FUSE_ARGS(args) struct fuse_args args = {}
342 /** The request IO state (for asynchronous processing) */
343 struct fuse_io_priv
{
355 struct completion
*done
;
359 #define FUSE_IO_PRIV_SYNC(i) \
361 .refcnt = KREF_INIT(1), \
369 * FR_ISREPLY: set if the request has reply
370 * FR_FORCE: force sending of the request even if interrupted
371 * FR_BACKGROUND: request is sent in the background
372 * FR_WAITING: request is counted as "waiting"
373 * FR_ABORTED: the request was aborted
374 * FR_INTERRUPTED: the request has been interrupted
375 * FR_LOCKED: data is being copied to/from the request
376 * FR_PENDING: request is not yet in userspace
377 * FR_SENT: request is in userspace, waiting for an answer
378 * FR_FINISHED: request is finished
379 * FR_PRIVATE: request is on private list
380 * FR_ASYNC: request is asynchronous
398 * A request to the client
400 * .waitq.lock protects the following fields:
402 * - FR_LOCKED (may also be modified under fc->lock, tested under both)
405 /** This can be on either pending processing or io lists in
407 struct list_head list
;
409 /** Entry on the interrupts list */
410 struct list_head intr_entry
;
412 /* Input/output arguments */
413 struct fuse_args
*args
;
418 /* Request flags, updated with test/set/clear_bit() */
421 /* The request input header */
423 struct fuse_in_header h
;
426 /* The request output header */
428 struct fuse_out_header h
;
431 /** Used to wake up the task waiting for completion of request*/
432 wait_queue_head_t waitq
;
434 #if IS_ENABLED(CONFIG_VIRTIO_FS)
435 /** virtio-fs's physically contiguous buffer for in and out args */
439 /** fuse_mount this request belongs to */
440 struct fuse_mount
*fm
;
446 * Input queue callbacks
448 * Input queue signalling is device-specific. For example, the /dev/fuse file
449 * uses fiq->waitq and fasync to wake processes that are waiting on queue
450 * readiness. These callbacks allow other device types to respond to input
453 struct fuse_iqueue_ops
{
457 void (*send_forget
)(struct fuse_iqueue
*fiq
, struct fuse_forget_link
*link
);
460 * Send interrupt for request
462 void (*send_interrupt
)(struct fuse_iqueue
*fiq
, struct fuse_req
*req
);
467 void (*send_req
)(struct fuse_iqueue
*fiq
, struct fuse_req
*req
);
470 * Clean up when fuse_iqueue is destroyed
472 void (*release
)(struct fuse_iqueue
*fiq
);
475 /** /dev/fuse input queue operations */
476 extern const struct fuse_iqueue_ops fuse_dev_fiq_ops
;
479 /** Connection established */
482 /** Lock protecting accesses to members of this structure */
485 /** Readers of the connection are waiting on this */
486 wait_queue_head_t waitq
;
488 /** The next unique request id */
491 /** The list of pending requests */
492 struct list_head pending
;
494 /** Pending interrupts */
495 struct list_head interrupts
;
497 /** Queue of pending forgets */
498 struct fuse_forget_link forget_list_head
;
499 struct fuse_forget_link
*forget_list_tail
;
501 /** Batching of FORGET requests (positive indicates FORGET batch) */
504 /** O_ASYNC requests */
505 struct fasync_struct
*fasync
;
507 /** Device-specific callbacks */
508 const struct fuse_iqueue_ops
*ops
;
510 /** Device-specific state */
514 #define FUSE_PQ_HASH_BITS 8
515 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
518 /** Connection established */
521 /** Lock protecting accessess to members of this structure */
524 /** Hash table of requests being processed */
525 struct list_head
*processing
;
527 /** The list of requests under I/O */
532 * Fuse device instance
535 /** Fuse connection for this device */
536 struct fuse_conn
*fc
;
538 /** Processing queue */
539 struct fuse_pqueue pq
;
541 /** list entry on fc->devices */
542 struct list_head entry
;
546 FUSE_DAX_INODE_DEFAULT
, /* default */
547 FUSE_DAX_ALWAYS
, /* "-o dax=always" */
548 FUSE_DAX_NEVER
, /* "-o dax=never" */
549 FUSE_DAX_INODE_USER
, /* "-o dax=inode" */
552 static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode
)
554 return mode
== FUSE_DAX_INODE_DEFAULT
|| mode
== FUSE_DAX_INODE_USER
;
557 struct fuse_fs_context
{
560 unsigned int rootmode
;
565 bool rootmode_present
:1;
566 bool user_id_present
:1;
567 bool group_id_present
:1;
568 bool default_permissions
:1;
572 bool no_force_umount
:1;
573 bool legacy_opts_show
:1;
574 enum fuse_dax_mode dax_mode
;
575 unsigned int max_read
;
576 unsigned int blksize
;
579 /* DAX device, may be NULL */
580 struct dax_device
*dax_dev
;
582 /* fuse_dev pointer to fill in, should contain NULL on entry */
586 struct fuse_sync_bucket
{
587 /* count is a possible scalability bottleneck */
589 wait_queue_head_t waitq
;
596 * This structure is created, when the root filesystem is mounted, and
597 * is destroyed, when the client device is closed and the last
598 * fuse_mount is destroyed.
601 /** Lock protecting accessess to members of this structure */
607 /** Number of fuse_dev's */
612 /** The user id for this mount */
615 /** The group id for this mount */
618 /** The pid namespace for this mount */
619 struct pid_namespace
*pid_ns
;
621 /** The user namespace for this mount */
622 struct user_namespace
*user_ns
;
624 /** Maximum read size */
627 /** Maximum write size */
630 /** Maximum number of pages that can be used in a single request */
631 unsigned int max_pages
;
633 /** Constrain ->max_pages to this value during feature negotiation */
634 unsigned int max_pages_limit
;
637 struct fuse_iqueue iq
;
639 /** The next unique kernel file handle */
642 /** rbtree of fuse_files waiting for poll events indexed by ph */
643 struct rb_root polled_files
;
645 /** Maximum number of outstanding background requests */
646 unsigned max_background
;
648 /** Number of background requests at which congestion starts */
649 unsigned congestion_threshold
;
651 /** Number of requests currently in the background */
652 unsigned num_background
;
654 /** Number of background requests currently queued for userspace */
655 unsigned active_background
;
657 /** The list of background requests set aside for later queuing */
658 struct list_head bg_queue
;
660 /** Protects: max_background, congestion_threshold, num_background,
661 * active_background, bg_queue, blocked */
664 /** Flag indicating that INIT reply has been received. Allocating
665 * any fuse request will be suspended until the flag is set */
668 /** Flag indicating if connection is blocked. This will be
669 the case before the INIT reply is received, and if there
670 are too many outstading backgrounds requests */
673 /** waitq for blocked connection */
674 wait_queue_head_t blocked_waitq
;
676 /** Connection established, cleared on umount, connection
677 abort and device release */
680 /** Connection aborted via sysfs */
683 /** Connection failed (version mismatch). Cannot race with
684 setting other bitfields since it is only set once in INIT
685 reply, before any other request, and never cleared */
686 unsigned conn_error
:1;
688 /** Connection successful. Only set in INIT */
689 unsigned conn_init
:1;
691 /** Do readahead asynchronously? Only set in INIT */
692 unsigned async_read
:1;
694 /** Return an unique read error after abort. Only set in INIT */
695 unsigned abort_err
:1;
697 /** Do not send separate SETATTR request before open(O_TRUNC) */
698 unsigned atomic_o_trunc
:1;
700 /** Filesystem supports NFS exporting. Only set in INIT */
701 unsigned export_support
:1;
703 /** write-back cache policy (default is write-through) */
704 unsigned writeback_cache
:1;
706 /** allow parallel lookups and readdir (default is serialized) */
707 unsigned parallel_dirops
:1;
709 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
710 unsigned handle_killpriv
:1;
712 /** cache READLINK responses in page cache */
713 unsigned cache_symlinks
:1;
715 /* show legacy mount options */
716 unsigned int legacy_opts_show
:1;
719 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
720 * write/trunc only if caller did not have CAP_FSETID. sgid is killed
721 * on write/truncate only if caller did not have CAP_FSETID as well as
722 * file has group execute permission.
724 unsigned handle_killpriv_v2
:1;
727 * The following bitfields are only for optimization purposes
728 * and hence races in setting them will not cause malfunction
731 /** Is open/release not implemented by fs? */
734 /** Is opendir/releasedir not implemented by fs? */
735 unsigned no_opendir
:1;
737 /** Is fsync not implemented by fs? */
740 /** Is fsyncdir not implemented by fs? */
741 unsigned no_fsyncdir
:1;
743 /** Is flush not implemented by fs? */
746 /** Is setxattr not implemented by fs? */
747 unsigned no_setxattr
:1;
749 /** Does file server support extended setxattr */
750 unsigned setxattr_ext
:1;
752 /** Is getxattr not implemented by fs? */
753 unsigned no_getxattr
:1;
755 /** Is listxattr not implemented by fs? */
756 unsigned no_listxattr
:1;
758 /** Is removexattr not implemented by fs? */
759 unsigned no_removexattr
:1;
761 /** Are posix file locking primitives not implemented by fs? */
764 /** Is access not implemented by fs? */
765 unsigned no_access
:1;
767 /** Is create not implemented by fs? */
768 unsigned no_create
:1;
770 /** Is interrupt not implemented by fs? */
771 unsigned no_interrupt
:1;
773 /** Is bmap not implemented by fs? */
776 /** Is poll not implemented by fs? */
779 /** Do multi-page cached writes */
780 unsigned big_writes
:1;
782 /** Don't apply umask to creation modes */
783 unsigned dont_mask
:1;
785 /** Are BSD file locking primitives not implemented by fs? */
788 /** Is fallocate not implemented by fs? */
789 unsigned no_fallocate
:1;
791 /** Is rename with flags implemented by fs? */
792 unsigned no_rename2
:1;
794 /** Use enhanced/automatic page cache invalidation. */
795 unsigned auto_inval_data
:1;
797 /** Filesystem is fully responsible for page cache invalidation. */
798 unsigned explicit_inval_data
:1;
800 /** Does the filesystem support readdirplus? */
801 unsigned do_readdirplus
:1;
803 /** Does the filesystem want adaptive readdirplus? */
804 unsigned readdirplus_auto
:1;
806 /** Does the filesystem support asynchronous direct-IO submission? */
807 unsigned async_dio
:1;
809 /** Is lseek not implemented by fs? */
812 /** Does the filesystem support posix acls? */
813 unsigned posix_acl
:1;
815 /** Check permissions based on the file mode or not? */
816 unsigned default_permissions
:1;
818 /** Allow other than the mounter user to access the filesystem ? */
819 unsigned allow_other
:1;
821 /** Does the filesystem support copy_file_range? */
822 unsigned no_copy_file_range
:1;
824 /* Send DESTROY request */
825 unsigned int destroy
:1;
827 /* Delete dentries that have gone stale */
828 unsigned int delete_stale
:1;
830 /** Do not create entry in fusectl fs */
831 unsigned int no_control
:1;
833 /** Do not allow MNT_FORCE umount */
834 unsigned int no_force_umount
:1;
836 /* Auto-mount submounts announced by the server */
837 unsigned int auto_submounts
:1;
839 /* Propagate syncfs() to server */
840 unsigned int sync_fs
:1;
842 /* Initialize security xattrs when creating a new inode */
843 unsigned int init_security
:1;
845 /* Add supplementary group info when creating a new inode */
846 unsigned int create_supp_group
:1;
848 /* Does the filesystem support per inode DAX? */
849 unsigned int inode_dax
:1;
851 /* Is tmpfile not implemented by fs? */
852 unsigned int no_tmpfile
:1;
854 /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
855 unsigned int direct_io_allow_mmap
:1;
857 /* Is statx not implemented by fs? */
858 unsigned int no_statx
:1;
860 /** Passthrough support for read/write IO */
861 unsigned int passthrough
:1;
863 /* Use pages instead of pointer for kernel I/O */
864 unsigned int use_pages_for_kvec_io
:1;
866 /** Maximum stack depth for passthrough backing files */
869 /** The number of requests waiting for completion */
870 atomic_t num_waiting
;
872 /** Negotiated minor version */
875 /** Entry on the fuse_conn_list */
876 struct list_head entry
;
878 /** Device ID from the root super block */
881 /** Dentries in the control filesystem */
882 struct dentry
*ctl_dentry
[FUSE_CTL_NUM_DENTRIES
];
884 /** number of dentries used in the above array */
887 /** Key for lock owner ID scrambling */
890 /** Version counter for attribute changes */
891 atomic64_t attr_version
;
893 /** Version counter for evict inode */
894 atomic64_t evict_ctr
;
896 /** Called on final put */
897 void (*release
)(struct fuse_conn
*);
900 * Read/write semaphore to hold when accessing the sb of any
901 * fuse_mount belonging to this connection
903 struct rw_semaphore killsb
;
905 /** List of device instances belonging to this connection */
906 struct list_head devices
;
908 #ifdef CONFIG_FUSE_DAX
910 enum fuse_dax_mode dax_mode
;
912 /* Dax specific conn data, non-NULL if DAX is enabled */
913 struct fuse_conn_dax
*dax
;
916 /** List of filesystems using this connection */
917 struct list_head mounts
;
919 /* New writepages go into this bucket */
920 struct fuse_sync_bucket __rcu
*curr_bucket
;
922 #ifdef CONFIG_FUSE_PASSTHROUGH
923 /** IDR for backing files ids */
924 struct idr backing_files_map
;
929 * Represents a mounted filesystem, potentially a submount.
931 * This object allows sharing a fuse_conn between separate mounts to
932 * allow submounts with dedicated superblocks and thus separate device
936 /* Underlying (potentially shared) connection to the FUSE server */
937 struct fuse_conn
*fc
;
940 * Super block for this connection (fc->killsb must be held when
943 struct super_block
*sb
;
945 /* Entry on fc->mounts */
946 struct list_head fc_entry
;
950 static inline struct fuse_mount
*get_fuse_mount_super(struct super_block
*sb
)
952 return sb
->s_fs_info
;
955 static inline struct fuse_conn
*get_fuse_conn_super(struct super_block
*sb
)
957 return get_fuse_mount_super(sb
)->fc
;
960 static inline struct fuse_mount
*get_fuse_mount(struct inode
*inode
)
962 return get_fuse_mount_super(inode
->i_sb
);
965 static inline struct fuse_conn
*get_fuse_conn(struct inode
*inode
)
967 return get_fuse_mount_super(inode
->i_sb
)->fc
;
970 static inline struct fuse_inode
*get_fuse_inode(struct inode
*inode
)
972 return container_of(inode
, struct fuse_inode
, inode
);
975 static inline u64
get_node_id(struct inode
*inode
)
977 return get_fuse_inode(inode
)->nodeid
;
980 static inline int invalid_nodeid(u64 nodeid
)
982 return !nodeid
|| nodeid
== FUSE_ROOT_ID
;
985 static inline u64
fuse_get_attr_version(struct fuse_conn
*fc
)
987 return atomic64_read(&fc
->attr_version
);
990 static inline u64
fuse_get_evict_ctr(struct fuse_conn
*fc
)
992 return atomic64_read(&fc
->evict_ctr
);
995 static inline bool fuse_stale_inode(const struct inode
*inode
, int generation
,
996 struct fuse_attr
*attr
)
998 return inode
->i_generation
!= generation
||
999 inode_wrong_type(inode
, attr
->mode
);
1002 static inline void fuse_make_bad(struct inode
*inode
)
1004 set_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
);
1007 static inline bool fuse_is_bad(struct inode
*inode
)
1009 return unlikely(test_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
));
1012 static inline struct folio
**fuse_folios_alloc(unsigned int nfolios
, gfp_t flags
,
1013 struct fuse_folio_desc
**desc
)
1015 struct folio
**folios
;
1017 folios
= kzalloc(nfolios
* (sizeof(struct folio
*) +
1018 sizeof(struct fuse_folio_desc
)), flags
);
1019 *desc
= (void *) (folios
+ nfolios
);
1024 static inline void fuse_folio_descs_length_init(struct fuse_folio_desc
*descs
,
1026 unsigned int nr_folios
)
1030 for (i
= index
; i
< index
+ nr_folios
; i
++)
1031 descs
[i
].length
= PAGE_SIZE
- descs
[i
].offset
;
1034 static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket
*bucket
)
1036 /* Need RCU protection to prevent use after free after the decrement */
1038 if (atomic_dec_and_test(&bucket
->count
))
1039 wake_up(&bucket
->waitq
);
1043 /** Device operations */
1044 extern const struct file_operations fuse_dev_operations
;
1046 extern const struct dentry_operations fuse_dentry_operations
;
1047 extern const struct dentry_operations fuse_root_dentry_operations
;
1050 * Get a filled in inode
1052 struct inode
*fuse_iget(struct super_block
*sb
, u64 nodeid
,
1053 int generation
, struct fuse_attr
*attr
,
1054 u64 attr_valid
, u64 attr_version
,
1057 int fuse_lookup_name(struct super_block
*sb
, u64 nodeid
, const struct qstr
*name
,
1058 struct fuse_entry_out
*outarg
, struct inode
**inode
);
1061 * Send FORGET command
1063 void fuse_queue_forget(struct fuse_conn
*fc
, struct fuse_forget_link
*forget
,
1064 u64 nodeid
, u64 nlookup
);
1066 struct fuse_forget_link
*fuse_alloc_forget(void);
1069 * Initialize READ or READDIR request
1071 struct fuse_io_args
{
1074 struct fuse_read_in in
;
1078 struct fuse_write_in in
;
1079 struct fuse_write_out out
;
1083 struct fuse_args_pages ap
;
1084 struct fuse_io_priv
*io
;
1085 struct fuse_file
*ff
;
1088 void fuse_read_args_fill(struct fuse_io_args
*ia
, struct file
*file
, loff_t pos
,
1089 size_t count
, int opcode
);
1092 struct fuse_file
*fuse_file_alloc(struct fuse_mount
*fm
, bool release
);
1093 void fuse_file_free(struct fuse_file
*ff
);
1094 int fuse_finish_open(struct inode
*inode
, struct file
*file
);
1096 void fuse_sync_release(struct fuse_inode
*fi
, struct fuse_file
*ff
,
1097 unsigned int flags
);
1100 * Send RELEASE or RELEASEDIR request
1102 void fuse_release_common(struct file
*file
, bool isdir
);
1105 * Send FSYNC or FSYNCDIR request
1107 int fuse_fsync_common(struct file
*file
, loff_t start
, loff_t end
,
1108 int datasync
, int opcode
);
1111 * Notify poll wakeup
1113 int fuse_notify_poll_wakeup(struct fuse_conn
*fc
,
1114 struct fuse_notify_poll_wakeup_out
*outarg
);
1117 * Initialize file operations on a regular file
1119 void fuse_init_file_inode(struct inode
*inode
, unsigned int flags
);
1122 * Initialize inode operations on regular files and special files
1124 void fuse_init_common(struct inode
*inode
);
1127 * Initialize inode and file operations on a directory
1129 void fuse_init_dir(struct inode
*inode
);
1132 * Initialize inode operations on a symlink
1134 void fuse_init_symlink(struct inode
*inode
);
1137 * Change attributes of an inode
1139 void fuse_change_attributes(struct inode
*inode
, struct fuse_attr
*attr
,
1140 struct fuse_statx
*sx
,
1141 u64 attr_valid
, u64 attr_version
);
1143 void fuse_change_attributes_common(struct inode
*inode
, struct fuse_attr
*attr
,
1144 struct fuse_statx
*sx
,
1145 u64 attr_valid
, u32 cache_mask
,
1148 u32
fuse_get_cache_mask(struct inode
*inode
);
1151 * Initialize the client device
1153 int fuse_dev_init(void);
1156 * Cleanup the client device
1158 void fuse_dev_cleanup(void);
1160 int fuse_ctl_init(void);
1161 void __exit
fuse_ctl_cleanup(void);
1164 * Simple request sending that does request allocation and freeing
1166 ssize_t
__fuse_simple_request(struct mnt_idmap
*idmap
,
1167 struct fuse_mount
*fm
,
1168 struct fuse_args
*args
);
1170 static inline ssize_t
fuse_simple_request(struct fuse_mount
*fm
, struct fuse_args
*args
)
1172 return __fuse_simple_request(&invalid_mnt_idmap
, fm
, args
);
1175 static inline ssize_t
fuse_simple_idmap_request(struct mnt_idmap
*idmap
,
1176 struct fuse_mount
*fm
,
1177 struct fuse_args
*args
)
1179 return __fuse_simple_request(idmap
, fm
, args
);
1182 int fuse_simple_background(struct fuse_mount
*fm
, struct fuse_args
*args
,
1186 * End a finished request
1188 void fuse_request_end(struct fuse_req
*req
);
1190 /* Abort all requests */
1191 void fuse_abort_conn(struct fuse_conn
*fc
);
1192 void fuse_wait_aborted(struct fuse_conn
*fc
);
1195 * Invalidate inode attributes
1198 /* Attributes possibly changed on data modification */
1199 #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1201 /* Attributes possibly changed on data and/or size modification */
1202 #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
1204 void fuse_invalidate_attr(struct inode
*inode
);
1205 void fuse_invalidate_attr_mask(struct inode
*inode
, u32 mask
);
1207 void fuse_invalidate_entry_cache(struct dentry
*entry
);
1209 void fuse_invalidate_atime(struct inode
*inode
);
1211 u64
fuse_time_to_jiffies(u64 sec
, u32 nsec
);
1212 #define ATTR_TIMEOUT(o) \
1213 fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
1215 void fuse_change_entry_timeout(struct dentry
*entry
, struct fuse_entry_out
*o
);
1218 * Acquire reference to fuse_conn
1220 struct fuse_conn
*fuse_conn_get(struct fuse_conn
*fc
);
1223 * Initialize fuse_conn
1225 void fuse_conn_init(struct fuse_conn
*fc
, struct fuse_mount
*fm
,
1226 struct user_namespace
*user_ns
,
1227 const struct fuse_iqueue_ops
*fiq_ops
, void *fiq_priv
);
1230 * Release reference to fuse_conn
1232 void fuse_conn_put(struct fuse_conn
*fc
);
1234 struct fuse_dev
*fuse_dev_alloc_install(struct fuse_conn
*fc
);
1235 struct fuse_dev
*fuse_dev_alloc(void);
1236 void fuse_dev_install(struct fuse_dev
*fud
, struct fuse_conn
*fc
);
1237 void fuse_dev_free(struct fuse_dev
*fud
);
1238 void fuse_send_init(struct fuse_mount
*fm
);
1241 * Fill in superblock and initialize fuse connection
1242 * @sb: partially-initialized superblock to fill in
1243 * @ctx: mount context
1245 int fuse_fill_super_common(struct super_block
*sb
, struct fuse_fs_context
*ctx
);
1248 * Remove the mount from the connection
1250 * Returns whether this was the last mount
1252 bool fuse_mount_remove(struct fuse_mount
*fm
);
1255 * Setup context ops for submounts
1257 int fuse_init_fs_context_submount(struct fs_context
*fsc
);
1260 * Shut down the connection (possibly sending DESTROY request).
1262 void fuse_conn_destroy(struct fuse_mount
*fm
);
1264 /* Drop the connection and free the fuse mount */
1265 void fuse_mount_destroy(struct fuse_mount
*fm
);
1268 * Add connection to control filesystem
1270 int fuse_ctl_add_conn(struct fuse_conn
*fc
);
1273 * Remove connection from control filesystem
1275 void fuse_ctl_remove_conn(struct fuse_conn
*fc
);
1278 * Is file type valid?
1280 int fuse_valid_type(int m
);
1282 bool fuse_invalid_attr(struct fuse_attr
*attr
);
1285 * Is current process allowed to perform filesystem operation?
1287 bool fuse_allow_current_process(struct fuse_conn
*fc
);
1289 u64
fuse_lock_owner_id(struct fuse_conn
*fc
, fl_owner_t id
);
1291 void fuse_flush_time_update(struct inode
*inode
);
1292 void fuse_update_ctime(struct inode
*inode
);
1294 int fuse_update_attributes(struct inode
*inode
, struct file
*file
, u32 mask
);
1296 void fuse_flush_writepages(struct inode
*inode
);
1298 void fuse_set_nowrite(struct inode
*inode
);
1299 void fuse_release_nowrite(struct inode
*inode
);
1302 * Scan all fuse_mounts belonging to fc to find the first where
1303 * ilookup5() returns a result. Return that result and the
1304 * respective fuse_mount in *fm (unless fm is NULL).
1306 * The caller must hold fc->killsb.
1308 struct inode
*fuse_ilookup(struct fuse_conn
*fc
, u64 nodeid
,
1309 struct fuse_mount
**fm
);
1312 * File-system tells the kernel to invalidate cache for the given node id.
1314 int fuse_reverse_inval_inode(struct fuse_conn
*fc
, u64 nodeid
,
1315 loff_t offset
, loff_t len
);
1318 * File-system tells the kernel to invalidate parent attributes and
1319 * the dentry matching parent/name.
1321 * If the child_nodeid is non-zero and:
1322 * - matches the inode number for the dentry matching parent/name,
1323 * - is not a mount point
1324 * - is a file or oan empty directory
1325 * then the dentry is unhashed (d_delete()).
1327 int fuse_reverse_inval_entry(struct fuse_conn
*fc
, u64 parent_nodeid
,
1328 u64 child_nodeid
, struct qstr
*name
, u32 flags
);
1330 int fuse_do_open(struct fuse_mount
*fm
, u64 nodeid
, struct file
*file
,
1334 * fuse_direct_io() flags
1337 /** If set, it is WRITE; otherwise - READ */
1338 #define FUSE_DIO_WRITE (1 << 0)
1340 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1341 #define FUSE_DIO_CUSE (1 << 1)
1343 ssize_t
fuse_direct_io(struct fuse_io_priv
*io
, struct iov_iter
*iter
,
1344 loff_t
*ppos
, int flags
);
1345 long fuse_do_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
,
1346 unsigned int flags
);
1347 long fuse_ioctl_common(struct file
*file
, unsigned int cmd
,
1348 unsigned long arg
, unsigned int flags
);
1349 __poll_t
fuse_file_poll(struct file
*file
, poll_table
*wait
);
1350 int fuse_dev_release(struct inode
*inode
, struct file
*file
);
1352 bool fuse_write_update_attr(struct inode
*inode
, loff_t pos
, ssize_t written
);
1354 int fuse_flush_times(struct inode
*inode
, struct fuse_file
*ff
);
1355 int fuse_write_inode(struct inode
*inode
, struct writeback_control
*wbc
);
1357 int fuse_do_setattr(struct mnt_idmap
*idmap
, struct dentry
*dentry
,
1358 struct iattr
*attr
, struct file
*file
);
1360 void fuse_set_initialized(struct fuse_conn
*fc
);
1362 void fuse_unlock_inode(struct inode
*inode
, bool locked
);
1363 bool fuse_lock_inode(struct inode
*inode
);
1365 int fuse_setxattr(struct inode
*inode
, const char *name
, const void *value
,
1366 size_t size
, int flags
, unsigned int extra_flags
);
1367 ssize_t
fuse_getxattr(struct inode
*inode
, const char *name
, void *value
,
1369 ssize_t
fuse_listxattr(struct dentry
*entry
, char *list
, size_t size
);
1370 int fuse_removexattr(struct inode
*inode
, const char *name
);
1371 extern const struct xattr_handler
* const fuse_xattr_handlers
[];
1374 struct posix_acl
*fuse_get_inode_acl(struct inode
*inode
, int type
, bool rcu
);
1375 struct posix_acl
*fuse_get_acl(struct mnt_idmap
*idmap
,
1376 struct dentry
*dentry
, int type
);
1377 int fuse_set_acl(struct mnt_idmap
*, struct dentry
*dentry
,
1378 struct posix_acl
*acl
, int type
);
1381 int fuse_readdir(struct file
*file
, struct dir_context
*ctx
);
1384 * Return the number of bytes in an arguments list
1386 unsigned int fuse_len_args(unsigned int numargs
, struct fuse_arg
*args
);
1389 * Get the next unique ID for a request
1391 u64
fuse_get_unique(struct fuse_iqueue
*fiq
);
1392 void fuse_free_conn(struct fuse_conn
*fc
);
1396 #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1398 ssize_t
fuse_dax_read_iter(struct kiocb
*iocb
, struct iov_iter
*to
);
1399 ssize_t
fuse_dax_write_iter(struct kiocb
*iocb
, struct iov_iter
*from
);
1400 int fuse_dax_mmap(struct file
*file
, struct vm_area_struct
*vma
);
1401 int fuse_dax_break_layouts(struct inode
*inode
, u64 dmap_start
, u64 dmap_end
);
1402 int fuse_dax_conn_alloc(struct fuse_conn
*fc
, enum fuse_dax_mode mode
,
1403 struct dax_device
*dax_dev
);
1404 void fuse_dax_conn_free(struct fuse_conn
*fc
);
1405 bool fuse_dax_inode_alloc(struct super_block
*sb
, struct fuse_inode
*fi
);
1406 void fuse_dax_inode_init(struct inode
*inode
, unsigned int flags
);
1407 void fuse_dax_inode_cleanup(struct inode
*inode
);
1408 void fuse_dax_dontcache(struct inode
*inode
, unsigned int flags
);
1409 bool fuse_dax_check_alignment(struct fuse_conn
*fc
, unsigned int map_alignment
);
1410 void fuse_dax_cancel_work(struct fuse_conn
*fc
);
1413 long fuse_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
1414 long fuse_file_compat_ioctl(struct file
*file
, unsigned int cmd
,
1416 int fuse_fileattr_get(struct dentry
*dentry
, struct fileattr
*fa
);
1417 int fuse_fileattr_set(struct mnt_idmap
*idmap
,
1418 struct dentry
*dentry
, struct fileattr
*fa
);
1421 int fuse_file_cached_io_open(struct inode
*inode
, struct fuse_file
*ff
);
1422 int fuse_inode_uncached_io_start(struct fuse_inode
*fi
,
1423 struct fuse_backing
*fb
);
1424 void fuse_inode_uncached_io_end(struct fuse_inode
*fi
);
1426 int fuse_file_io_open(struct file
*file
, struct inode
*inode
);
1427 void fuse_file_io_release(struct fuse_file
*ff
, struct inode
*inode
);
1430 struct fuse_file
*fuse_file_open(struct fuse_mount
*fm
, u64 nodeid
,
1431 unsigned int open_flags
, bool isdir
);
1432 void fuse_file_release(struct inode
*inode
, struct fuse_file
*ff
,
1433 unsigned int open_flags
, fl_owner_t id
, bool isdir
);
1436 static inline struct fuse_backing
*fuse_inode_backing(struct fuse_inode
*fi
)
1438 #ifdef CONFIG_FUSE_PASSTHROUGH
1439 return READ_ONCE(fi
->fb
);
1445 static inline struct fuse_backing
*fuse_inode_backing_set(struct fuse_inode
*fi
,
1446 struct fuse_backing
*fb
)
1448 #ifdef CONFIG_FUSE_PASSTHROUGH
1449 return xchg(&fi
->fb
, fb
);
1455 #ifdef CONFIG_FUSE_PASSTHROUGH
1456 struct fuse_backing
*fuse_backing_get(struct fuse_backing
*fb
);
1457 void fuse_backing_put(struct fuse_backing
*fb
);
1460 static inline struct fuse_backing
*fuse_backing_get(struct fuse_backing
*fb
)
1465 static inline void fuse_backing_put(struct fuse_backing
*fb
)
1470 void fuse_backing_files_init(struct fuse_conn
*fc
);
1471 void fuse_backing_files_free(struct fuse_conn
*fc
);
1472 int fuse_backing_open(struct fuse_conn
*fc
, struct fuse_backing_map
*map
);
1473 int fuse_backing_close(struct fuse_conn
*fc
, int backing_id
);
1475 struct fuse_backing
*fuse_passthrough_open(struct file
*file
,
1476 struct inode
*inode
,
1478 void fuse_passthrough_release(struct fuse_file
*ff
, struct fuse_backing
*fb
);
1480 static inline struct file
*fuse_file_passthrough(struct fuse_file
*ff
)
1482 #ifdef CONFIG_FUSE_PASSTHROUGH
1483 return ff
->passthrough
;
1489 ssize_t
fuse_passthrough_read_iter(struct kiocb
*iocb
, struct iov_iter
*iter
);
1490 ssize_t
fuse_passthrough_write_iter(struct kiocb
*iocb
, struct iov_iter
*iter
);
1491 ssize_t
fuse_passthrough_splice_read(struct file
*in
, loff_t
*ppos
,
1492 struct pipe_inode_info
*pipe
,
1493 size_t len
, unsigned int flags
);
1494 ssize_t
fuse_passthrough_splice_write(struct pipe_inode_info
*pipe
,
1495 struct file
*out
, loff_t
*ppos
,
1496 size_t len
, unsigned int flags
);
1497 ssize_t
fuse_passthrough_mmap(struct file
*file
, struct vm_area_struct
*vma
);
1499 #ifdef CONFIG_SYSCTL
1500 extern int fuse_sysctl_register(void);
1501 extern void fuse_sysctl_unregister(void);
1503 #define fuse_sysctl_register() (0)
1504 #define fuse_sysctl_unregister() do { } while (0)
1505 #endif /* CONFIG_SYSCTL */
1507 #endif /* _FS_FUSE_I_H */