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 /** Maximum of max_pages received in init_out */
39 #define FUSE_MAX_MAX_PAGES 256
41 /** Bias for fi->writectr, meaning new writepages must not be sent */
42 #define FUSE_NOWRITE INT_MIN
44 /** It could be as large as PATH_MAX, but would that have any uses? */
45 #define FUSE_NAME_MAX 1024
47 /** Number of dentries for each connection in the control filesystem */
48 #define FUSE_CTL_NUM_DENTRIES 5
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
;
84 /** Unique ID, which identifies the inode between userspace
88 /** Number of lookups on this inode */
91 /** The request used for sending the FORGET message */
92 struct fuse_forget_link
*forget
;
94 /** Time in jiffies until the file attributes are valid */
97 /* Which attributes are invalid */
100 /** The sticky bit in inode->i_mode may have been removed, so
101 preserve the original mode */
104 /* Cache birthtime */
105 struct timespec64 i_btime
;
107 /** 64 bit inode number */
110 /** Version of last attribute change */
114 /* read/write io cache (regular file only) */
116 /* Files usable in writepage. Protected by fi->lock */
117 struct list_head write_files
;
119 /* Writepages pending on truncate or fsync */
120 struct list_head queued_writes
;
122 /* Number of sent writes, a negative bias
123 * (FUSE_NOWRITE) means more writes are blocked */
126 /** Number of files/maps using page cache */
129 /* Waitq for writepage completion */
130 wait_queue_head_t page_waitq
;
132 /* waitq for direct-io completion */
133 wait_queue_head_t direct_io_waitq
;
135 /* List of writepage requestst (pending or sent) */
136 struct rb_root writepages
;
139 /* readdir cache (directory only) */
141 /* true if fully cached */
147 /* position at end of cache (position of next entry) */
150 /* version of the cache */
153 /* modification time of directory when cache was
155 struct timespec64 mtime
;
157 /* iversion of directory when cache was started */
160 /* protects above fields */
165 /** Miscellaneous bits describing inode state */
168 /** Lock for serializing lookup and readdir for back compatibility*/
171 /** Lock to protect write related fields */
174 #ifdef CONFIG_FUSE_DAX
176 * Dax specific inode data
178 struct fuse_inode_dax
*dax
;
180 /** Submount specific lookup tracking */
181 struct fuse_submount_lookup
*submount_lookup
;
184 /** FUSE inode state bits */
186 /** Advise readdirplus */
187 FUSE_I_ADVISE_RDPLUS
,
188 /** Initialized with readdirplus */
190 /** An operation changing file size is in progress */
191 FUSE_I_SIZE_UNSTABLE
,
196 /* Wants or already has page cache IO */
197 FUSE_I_CACHE_IO_MODE
,
202 struct fuse_release_args
;
204 /** FUSE specific file data */
206 /** Fuse connection for this file */
207 struct fuse_mount
*fm
;
209 /* Argument space reserved for release */
210 struct fuse_release_args
*release_args
;
212 /** Kernel file handle guaranteed to be unique */
215 /** File handle used by userspace */
218 /** Node id of this file */
224 /** FOPEN_* flags returned by open */
227 /** Entry on inode's write_files list */
228 struct list_head write_entry
;
230 /* Readdir related */
233 * Protects below fields against (crazy) parallel readdir on
234 * same open file. Uncontended in the normal case.
238 /* Dir stream position */
241 /* Offset in cache */
244 /* Version of cache we are reading */
249 /** RB node to be linked on fuse_conn->polled_files */
250 struct rb_node polled_node
;
252 /** Wait queue head for poll */
253 wait_queue_head_t poll_wait
;
255 /** Does file hold a fi->iocachectr refcount? */
256 enum { IOM_NONE
, IOM_CACHED
, IOM_UNCACHED
} iomode
;
258 /** Has flock been performed on this file? */
262 /** One input argument of a request */
268 /** One output argument of a request */
274 /** FUSE page descriptor */
275 struct fuse_page_desc
{
297 struct fuse_in_arg in_args
[3];
298 struct fuse_arg out_args
[2];
299 void (*end
)(struct fuse_mount
*fm
, struct fuse_args
*args
, int error
);
302 struct fuse_args_pages
{
303 struct fuse_args args
;
305 struct fuse_page_desc
*descs
;
306 unsigned int num_pages
;
309 #define FUSE_ARGS(args) struct fuse_args args = {}
311 /** The request IO state (for asynchronous processing) */
312 struct fuse_io_priv
{
324 struct completion
*done
;
328 #define FUSE_IO_PRIV_SYNC(i) \
330 .refcnt = KREF_INIT(1), \
338 * FR_ISREPLY: set if the request has reply
339 * FR_FORCE: force sending of the request even if interrupted
340 * FR_BACKGROUND: request is sent in the background
341 * FR_WAITING: request is counted as "waiting"
342 * FR_ABORTED: the request was aborted
343 * FR_INTERRUPTED: the request has been interrupted
344 * FR_LOCKED: data is being copied to/from the request
345 * FR_PENDING: request is not yet in userspace
346 * FR_SENT: request is in userspace, waiting for an answer
347 * FR_FINISHED: request is finished
348 * FR_PRIVATE: request is on private list
349 * FR_ASYNC: request is asynchronous
367 * A request to the client
369 * .waitq.lock protects the following fields:
371 * - FR_LOCKED (may also be modified under fc->lock, tested under both)
374 /** This can be on either pending processing or io lists in
376 struct list_head list
;
378 /** Entry on the interrupts list */
379 struct list_head intr_entry
;
381 /* Input/output arguments */
382 struct fuse_args
*args
;
387 /* Request flags, updated with test/set/clear_bit() */
390 /* The request input header */
392 struct fuse_in_header h
;
395 /* The request output header */
397 struct fuse_out_header h
;
400 /** Used to wake up the task waiting for completion of request*/
401 wait_queue_head_t waitq
;
403 #if IS_ENABLED(CONFIG_VIRTIO_FS)
404 /** virtio-fs's physically contiguous buffer for in and out args */
408 /** fuse_mount this request belongs to */
409 struct fuse_mount
*fm
;
415 * Input queue callbacks
417 * Input queue signalling is device-specific. For example, the /dev/fuse file
418 * uses fiq->waitq and fasync to wake processes that are waiting on queue
419 * readiness. These callbacks allow other device types to respond to input
422 struct fuse_iqueue_ops
{
424 * Signal that a forget has been queued
426 void (*wake_forget_and_unlock
)(struct fuse_iqueue
*fiq
)
427 __releases(fiq
->lock
);
430 * Signal that an INTERRUPT request has been queued
432 void (*wake_interrupt_and_unlock
)(struct fuse_iqueue
*fiq
)
433 __releases(fiq
->lock
);
436 * Signal that a request has been queued
438 void (*wake_pending_and_unlock
)(struct fuse_iqueue
*fiq
)
439 __releases(fiq
->lock
);
442 * Clean up when fuse_iqueue is destroyed
444 void (*release
)(struct fuse_iqueue
*fiq
);
447 /** /dev/fuse input queue operations */
448 extern const struct fuse_iqueue_ops fuse_dev_fiq_ops
;
451 /** Connection established */
454 /** Lock protecting accesses to members of this structure */
457 /** Readers of the connection are waiting on this */
458 wait_queue_head_t waitq
;
460 /** The next unique request id */
463 /** The list of pending requests */
464 struct list_head pending
;
466 /** Pending interrupts */
467 struct list_head interrupts
;
469 /** Queue of pending forgets */
470 struct fuse_forget_link forget_list_head
;
471 struct fuse_forget_link
*forget_list_tail
;
473 /** Batching of FORGET requests (positive indicates FORGET batch) */
476 /** O_ASYNC requests */
477 struct fasync_struct
*fasync
;
479 /** Device-specific callbacks */
480 const struct fuse_iqueue_ops
*ops
;
482 /** Device-specific state */
486 #define FUSE_PQ_HASH_BITS 8
487 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
490 /** Connection established */
493 /** Lock protecting accessess to members of this structure */
496 /** Hash table of requests being processed */
497 struct list_head
*processing
;
499 /** The list of requests under I/O */
504 * Fuse device instance
507 /** Fuse connection for this device */
508 struct fuse_conn
*fc
;
510 /** Processing queue */
511 struct fuse_pqueue pq
;
513 /** list entry on fc->devices */
514 struct list_head entry
;
518 FUSE_DAX_INODE_DEFAULT
, /* default */
519 FUSE_DAX_ALWAYS
, /* "-o dax=always" */
520 FUSE_DAX_NEVER
, /* "-o dax=never" */
521 FUSE_DAX_INODE_USER
, /* "-o dax=inode" */
524 static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode
)
526 return mode
== FUSE_DAX_INODE_DEFAULT
|| mode
== FUSE_DAX_INODE_USER
;
529 struct fuse_fs_context
{
532 unsigned int rootmode
;
537 bool rootmode_present
:1;
538 bool user_id_present
:1;
539 bool group_id_present
:1;
540 bool default_permissions
:1;
544 bool no_force_umount
:1;
545 bool legacy_opts_show
:1;
546 enum fuse_dax_mode dax_mode
;
547 unsigned int max_read
;
548 unsigned int blksize
;
551 /* DAX device, may be NULL */
552 struct dax_device
*dax_dev
;
554 /* fuse_dev pointer to fill in, should contain NULL on entry */
558 struct fuse_sync_bucket
{
559 /* count is a possible scalability bottleneck */
561 wait_queue_head_t waitq
;
568 * This structure is created, when the root filesystem is mounted, and
569 * is destroyed, when the client device is closed and the last
570 * fuse_mount is destroyed.
573 /** Lock protecting accessess to members of this structure */
579 /** Number of fuse_dev's */
584 /** The user id for this mount */
587 /** The group id for this mount */
590 /** The pid namespace for this mount */
591 struct pid_namespace
*pid_ns
;
593 /** The user namespace for this mount */
594 struct user_namespace
*user_ns
;
596 /** Maximum read size */
599 /** Maximum write size */
602 /** Maximum number of pages that can be used in a single request */
603 unsigned int max_pages
;
605 /** Constrain ->max_pages to this value during feature negotiation */
606 unsigned int max_pages_limit
;
609 struct fuse_iqueue iq
;
611 /** The next unique kernel file handle */
614 /** rbtree of fuse_files waiting for poll events indexed by ph */
615 struct rb_root polled_files
;
617 /** Maximum number of outstanding background requests */
618 unsigned max_background
;
620 /** Number of background requests at which congestion starts */
621 unsigned congestion_threshold
;
623 /** Number of requests currently in the background */
624 unsigned num_background
;
626 /** Number of background requests currently queued for userspace */
627 unsigned active_background
;
629 /** The list of background requests set aside for later queuing */
630 struct list_head bg_queue
;
632 /** Protects: max_background, congestion_threshold, num_background,
633 * active_background, bg_queue, blocked */
636 /** Flag indicating that INIT reply has been received. Allocating
637 * any fuse request will be suspended until the flag is set */
640 /** Flag indicating if connection is blocked. This will be
641 the case before the INIT reply is received, and if there
642 are too many outstading backgrounds requests */
645 /** waitq for blocked connection */
646 wait_queue_head_t blocked_waitq
;
648 /** Connection established, cleared on umount, connection
649 abort and device release */
652 /** Connection aborted via sysfs */
655 /** Connection failed (version mismatch). Cannot race with
656 setting other bitfields since it is only set once in INIT
657 reply, before any other request, and never cleared */
658 unsigned conn_error
:1;
660 /** Connection successful. Only set in INIT */
661 unsigned conn_init
:1;
663 /** Do readahead asynchronously? Only set in INIT */
664 unsigned async_read
:1;
666 /** Return an unique read error after abort. Only set in INIT */
667 unsigned abort_err
:1;
669 /** Do not send separate SETATTR request before open(O_TRUNC) */
670 unsigned atomic_o_trunc
:1;
672 /** Filesystem supports NFS exporting. Only set in INIT */
673 unsigned export_support
:1;
675 /** write-back cache policy (default is write-through) */
676 unsigned writeback_cache
:1;
678 /** allow parallel lookups and readdir (default is serialized) */
679 unsigned parallel_dirops
:1;
681 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
682 unsigned handle_killpriv
:1;
684 /** cache READLINK responses in page cache */
685 unsigned cache_symlinks
:1;
687 /* show legacy mount options */
688 unsigned int legacy_opts_show
:1;
691 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
692 * write/trunc only if caller did not have CAP_FSETID. sgid is killed
693 * on write/truncate only if caller did not have CAP_FSETID as well as
694 * file has group execute permission.
696 unsigned handle_killpriv_v2
:1;
699 * The following bitfields are only for optimization purposes
700 * and hence races in setting them will not cause malfunction
703 /** Is open/release not implemented by fs? */
706 /** Is opendir/releasedir not implemented by fs? */
707 unsigned no_opendir
:1;
709 /** Is fsync not implemented by fs? */
712 /** Is fsyncdir not implemented by fs? */
713 unsigned no_fsyncdir
:1;
715 /** Is flush not implemented by fs? */
718 /** Is setxattr not implemented by fs? */
719 unsigned no_setxattr
:1;
721 /** Does file server support extended setxattr */
722 unsigned setxattr_ext
:1;
724 /** Is getxattr not implemented by fs? */
725 unsigned no_getxattr
:1;
727 /** Is listxattr not implemented by fs? */
728 unsigned no_listxattr
:1;
730 /** Is removexattr not implemented by fs? */
731 unsigned no_removexattr
:1;
733 /** Are posix file locking primitives not implemented by fs? */
736 /** Is access not implemented by fs? */
737 unsigned no_access
:1;
739 /** Is create not implemented by fs? */
740 unsigned no_create
:1;
742 /** Is interrupt not implemented by fs? */
743 unsigned no_interrupt
:1;
745 /** Is bmap not implemented by fs? */
748 /** Is poll not implemented by fs? */
751 /** Do multi-page cached writes */
752 unsigned big_writes
:1;
754 /** Don't apply umask to creation modes */
755 unsigned dont_mask
:1;
757 /** Are BSD file locking primitives not implemented by fs? */
760 /** Is fallocate not implemented by fs? */
761 unsigned no_fallocate
:1;
763 /** Is rename with flags implemented by fs? */
764 unsigned no_rename2
:1;
766 /** Use enhanced/automatic page cache invalidation. */
767 unsigned auto_inval_data
:1;
769 /** Filesystem is fully responsible for page cache invalidation. */
770 unsigned explicit_inval_data
:1;
772 /** Does the filesystem support readdirplus? */
773 unsigned do_readdirplus
:1;
775 /** Does the filesystem want adaptive readdirplus? */
776 unsigned readdirplus_auto
:1;
778 /** Does the filesystem support asynchronous direct-IO submission? */
779 unsigned async_dio
:1;
781 /** Is lseek not implemented by fs? */
784 /** Does the filesystem support posix acls? */
785 unsigned posix_acl
:1;
787 /** Check permissions based on the file mode or not? */
788 unsigned default_permissions
:1;
790 /** Allow other than the mounter user to access the filesystem ? */
791 unsigned allow_other
:1;
793 /** Does the filesystem support copy_file_range? */
794 unsigned no_copy_file_range
:1;
796 /* Send DESTROY request */
797 unsigned int destroy
:1;
799 /* Delete dentries that have gone stale */
800 unsigned int delete_stale
:1;
802 /** Do not create entry in fusectl fs */
803 unsigned int no_control
:1;
805 /** Do not allow MNT_FORCE umount */
806 unsigned int no_force_umount
:1;
808 /* Auto-mount submounts announced by the server */
809 unsigned int auto_submounts
:1;
811 /* Propagate syncfs() to server */
812 unsigned int sync_fs
:1;
814 /* Initialize security xattrs when creating a new inode */
815 unsigned int init_security
:1;
817 /* Add supplementary group info when creating a new inode */
818 unsigned int create_supp_group
:1;
820 /* Does the filesystem support per inode DAX? */
821 unsigned int inode_dax
:1;
823 /* Is tmpfile not implemented by fs? */
824 unsigned int no_tmpfile
:1;
826 /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
827 unsigned int direct_io_allow_mmap
:1;
829 /* Is statx not implemented by fs? */
830 unsigned int no_statx
:1;
832 /** The number of requests waiting for completion */
833 atomic_t num_waiting
;
835 /** Negotiated minor version */
838 /** Entry on the fuse_mount_list */
839 struct list_head entry
;
841 /** Device ID from the root super block */
844 /** Dentries in the control filesystem */
845 struct dentry
*ctl_dentry
[FUSE_CTL_NUM_DENTRIES
];
847 /** number of dentries used in the above array */
850 /** Key for lock owner ID scrambling */
853 /** Version counter for attribute changes */
854 atomic64_t attr_version
;
856 /** Called on final put */
857 void (*release
)(struct fuse_conn
*);
860 * Read/write semaphore to hold when accessing the sb of any
861 * fuse_mount belonging to this connection
863 struct rw_semaphore killsb
;
865 /** List of device instances belonging to this connection */
866 struct list_head devices
;
868 #ifdef CONFIG_FUSE_DAX
870 enum fuse_dax_mode dax_mode
;
872 /* Dax specific conn data, non-NULL if DAX is enabled */
873 struct fuse_conn_dax
*dax
;
876 /** List of filesystems using this connection */
877 struct list_head mounts
;
879 /* New writepages go into this bucket */
880 struct fuse_sync_bucket __rcu
*curr_bucket
;
884 * Represents a mounted filesystem, potentially a submount.
886 * This object allows sharing a fuse_conn between separate mounts to
887 * allow submounts with dedicated superblocks and thus separate device
891 /* Underlying (potentially shared) connection to the FUSE server */
892 struct fuse_conn
*fc
;
895 * Super block for this connection (fc->killsb must be held when
898 struct super_block
*sb
;
900 /* Entry on fc->mounts */
901 struct list_head fc_entry
;
904 static inline struct fuse_mount
*get_fuse_mount_super(struct super_block
*sb
)
906 return sb
->s_fs_info
;
909 static inline struct fuse_conn
*get_fuse_conn_super(struct super_block
*sb
)
911 return get_fuse_mount_super(sb
)->fc
;
914 static inline struct fuse_mount
*get_fuse_mount(struct inode
*inode
)
916 return get_fuse_mount_super(inode
->i_sb
);
919 static inline struct fuse_conn
*get_fuse_conn(struct inode
*inode
)
921 return get_fuse_mount_super(inode
->i_sb
)->fc
;
924 static inline struct fuse_inode
*get_fuse_inode(struct inode
*inode
)
926 return container_of(inode
, struct fuse_inode
, inode
);
929 static inline u64
get_node_id(struct inode
*inode
)
931 return get_fuse_inode(inode
)->nodeid
;
934 static inline int invalid_nodeid(u64 nodeid
)
936 return !nodeid
|| nodeid
== FUSE_ROOT_ID
;
939 static inline u64
fuse_get_attr_version(struct fuse_conn
*fc
)
941 return atomic64_read(&fc
->attr_version
);
944 static inline bool fuse_stale_inode(const struct inode
*inode
, int generation
,
945 struct fuse_attr
*attr
)
947 return inode
->i_generation
!= generation
||
948 inode_wrong_type(inode
, attr
->mode
);
951 static inline void fuse_make_bad(struct inode
*inode
)
953 remove_inode_hash(inode
);
954 set_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
);
957 static inline bool fuse_is_bad(struct inode
*inode
)
959 return unlikely(test_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
));
962 static inline struct page
**fuse_pages_alloc(unsigned int npages
, gfp_t flags
,
963 struct fuse_page_desc
**desc
)
967 pages
= kzalloc(npages
* (sizeof(struct page
*) +
968 sizeof(struct fuse_page_desc
)), flags
);
969 *desc
= (void *) (pages
+ npages
);
974 static inline void fuse_page_descs_length_init(struct fuse_page_desc
*descs
,
976 unsigned int nr_pages
)
980 for (i
= index
; i
< index
+ nr_pages
; i
++)
981 descs
[i
].length
= PAGE_SIZE
- descs
[i
].offset
;
984 static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket
*bucket
)
986 /* Need RCU protection to prevent use after free after the decrement */
988 if (atomic_dec_and_test(&bucket
->count
))
989 wake_up(&bucket
->waitq
);
993 /** Device operations */
994 extern const struct file_operations fuse_dev_operations
;
996 extern const struct dentry_operations fuse_dentry_operations
;
997 extern const struct dentry_operations fuse_root_dentry_operations
;
1000 * Get a filled in inode
1002 struct inode
*fuse_iget(struct super_block
*sb
, u64 nodeid
,
1003 int generation
, struct fuse_attr
*attr
,
1004 u64 attr_valid
, u64 attr_version
);
1006 int fuse_lookup_name(struct super_block
*sb
, u64 nodeid
, const struct qstr
*name
,
1007 struct fuse_entry_out
*outarg
, struct inode
**inode
);
1010 * Send FORGET command
1012 void fuse_queue_forget(struct fuse_conn
*fc
, struct fuse_forget_link
*forget
,
1013 u64 nodeid
, u64 nlookup
);
1015 struct fuse_forget_link
*fuse_alloc_forget(void);
1017 struct fuse_forget_link
*fuse_dequeue_forget(struct fuse_iqueue
*fiq
,
1019 unsigned int *countp
);
1022 * Initialize READ or READDIR request
1024 struct fuse_io_args
{
1027 struct fuse_read_in in
;
1031 struct fuse_write_in in
;
1032 struct fuse_write_out out
;
1036 struct fuse_args_pages ap
;
1037 struct fuse_io_priv
*io
;
1038 struct fuse_file
*ff
;
1041 void fuse_read_args_fill(struct fuse_io_args
*ia
, struct file
*file
, loff_t pos
,
1042 size_t count
, int opcode
);
1045 struct fuse_file
*fuse_file_alloc(struct fuse_mount
*fm
, bool release
);
1046 void fuse_file_free(struct fuse_file
*ff
);
1047 int fuse_finish_open(struct inode
*inode
, struct file
*file
);
1049 void fuse_sync_release(struct fuse_inode
*fi
, struct fuse_file
*ff
,
1050 unsigned int flags
);
1053 * Send RELEASE or RELEASEDIR request
1055 void fuse_release_common(struct file
*file
, bool isdir
);
1058 * Send FSYNC or FSYNCDIR request
1060 int fuse_fsync_common(struct file
*file
, loff_t start
, loff_t end
,
1061 int datasync
, int opcode
);
1064 * Notify poll wakeup
1066 int fuse_notify_poll_wakeup(struct fuse_conn
*fc
,
1067 struct fuse_notify_poll_wakeup_out
*outarg
);
1070 * Initialize file operations on a regular file
1072 void fuse_init_file_inode(struct inode
*inode
, unsigned int flags
);
1075 * Initialize inode operations on regular files and special files
1077 void fuse_init_common(struct inode
*inode
);
1080 * Initialize inode and file operations on a directory
1082 void fuse_init_dir(struct inode
*inode
);
1085 * Initialize inode operations on a symlink
1087 void fuse_init_symlink(struct inode
*inode
);
1090 * Change attributes of an inode
1092 void fuse_change_attributes(struct inode
*inode
, struct fuse_attr
*attr
,
1093 struct fuse_statx
*sx
,
1094 u64 attr_valid
, u64 attr_version
);
1096 void fuse_change_attributes_common(struct inode
*inode
, struct fuse_attr
*attr
,
1097 struct fuse_statx
*sx
,
1098 u64 attr_valid
, u32 cache_mask
);
1100 u32
fuse_get_cache_mask(struct inode
*inode
);
1103 * Initialize the client device
1105 int fuse_dev_init(void);
1108 * Cleanup the client device
1110 void fuse_dev_cleanup(void);
1112 int fuse_ctl_init(void);
1113 void __exit
fuse_ctl_cleanup(void);
1116 * Simple request sending that does request allocation and freeing
1118 ssize_t
fuse_simple_request(struct fuse_mount
*fm
, struct fuse_args
*args
);
1119 int fuse_simple_background(struct fuse_mount
*fm
, struct fuse_args
*args
,
1123 * End a finished request
1125 void fuse_request_end(struct fuse_req
*req
);
1127 /* Abort all requests */
1128 void fuse_abort_conn(struct fuse_conn
*fc
);
1129 void fuse_wait_aborted(struct fuse_conn
*fc
);
1132 * Invalidate inode attributes
1135 /* Attributes possibly changed on data modification */
1136 #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1138 /* Attributes possibly changed on data and/or size modification */
1139 #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
1141 void fuse_invalidate_attr(struct inode
*inode
);
1142 void fuse_invalidate_attr_mask(struct inode
*inode
, u32 mask
);
1144 void fuse_invalidate_entry_cache(struct dentry
*entry
);
1146 void fuse_invalidate_atime(struct inode
*inode
);
1148 u64
fuse_time_to_jiffies(u64 sec
, u32 nsec
);
1149 #define ATTR_TIMEOUT(o) \
1150 fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
1152 void fuse_change_entry_timeout(struct dentry
*entry
, struct fuse_entry_out
*o
);
1155 * Acquire reference to fuse_conn
1157 struct fuse_conn
*fuse_conn_get(struct fuse_conn
*fc
);
1160 * Initialize fuse_conn
1162 void fuse_conn_init(struct fuse_conn
*fc
, struct fuse_mount
*fm
,
1163 struct user_namespace
*user_ns
,
1164 const struct fuse_iqueue_ops
*fiq_ops
, void *fiq_priv
);
1167 * Release reference to fuse_conn
1169 void fuse_conn_put(struct fuse_conn
*fc
);
1171 struct fuse_dev
*fuse_dev_alloc_install(struct fuse_conn
*fc
);
1172 struct fuse_dev
*fuse_dev_alloc(void);
1173 void fuse_dev_install(struct fuse_dev
*fud
, struct fuse_conn
*fc
);
1174 void fuse_dev_free(struct fuse_dev
*fud
);
1175 void fuse_send_init(struct fuse_mount
*fm
);
1178 * Fill in superblock and initialize fuse connection
1179 * @sb: partially-initialized superblock to fill in
1180 * @ctx: mount context
1182 int fuse_fill_super_common(struct super_block
*sb
, struct fuse_fs_context
*ctx
);
1185 * Remove the mount from the connection
1187 * Returns whether this was the last mount
1189 bool fuse_mount_remove(struct fuse_mount
*fm
);
1192 * Setup context ops for submounts
1194 int fuse_init_fs_context_submount(struct fs_context
*fsc
);
1197 * Shut down the connection (possibly sending DESTROY request).
1199 void fuse_conn_destroy(struct fuse_mount
*fm
);
1201 /* Drop the connection and free the fuse mount */
1202 void fuse_mount_destroy(struct fuse_mount
*fm
);
1205 * Add connection to control filesystem
1207 int fuse_ctl_add_conn(struct fuse_conn
*fc
);
1210 * Remove connection from control filesystem
1212 void fuse_ctl_remove_conn(struct fuse_conn
*fc
);
1215 * Is file type valid?
1217 int fuse_valid_type(int m
);
1219 bool fuse_invalid_attr(struct fuse_attr
*attr
);
1222 * Is current process allowed to perform filesystem operation?
1224 bool fuse_allow_current_process(struct fuse_conn
*fc
);
1226 u64
fuse_lock_owner_id(struct fuse_conn
*fc
, fl_owner_t id
);
1228 void fuse_flush_time_update(struct inode
*inode
);
1229 void fuse_update_ctime(struct inode
*inode
);
1231 int fuse_update_attributes(struct inode
*inode
, struct file
*file
, u32 mask
);
1233 void fuse_flush_writepages(struct inode
*inode
);
1235 void fuse_set_nowrite(struct inode
*inode
);
1236 void fuse_release_nowrite(struct inode
*inode
);
1239 * Scan all fuse_mounts belonging to fc to find the first where
1240 * ilookup5() returns a result. Return that result and the
1241 * respective fuse_mount in *fm (unless fm is NULL).
1243 * The caller must hold fc->killsb.
1245 struct inode
*fuse_ilookup(struct fuse_conn
*fc
, u64 nodeid
,
1246 struct fuse_mount
**fm
);
1249 * File-system tells the kernel to invalidate cache for the given node id.
1251 int fuse_reverse_inval_inode(struct fuse_conn
*fc
, u64 nodeid
,
1252 loff_t offset
, loff_t len
);
1255 * File-system tells the kernel to invalidate parent attributes and
1256 * the dentry matching parent/name.
1258 * If the child_nodeid is non-zero and:
1259 * - matches the inode number for the dentry matching parent/name,
1260 * - is not a mount point
1261 * - is a file or oan empty directory
1262 * then the dentry is unhashed (d_delete()).
1264 int fuse_reverse_inval_entry(struct fuse_conn
*fc
, u64 parent_nodeid
,
1265 u64 child_nodeid
, struct qstr
*name
, u32 flags
);
1267 int fuse_do_open(struct fuse_mount
*fm
, u64 nodeid
, struct file
*file
,
1271 * fuse_direct_io() flags
1274 /** If set, it is WRITE; otherwise - READ */
1275 #define FUSE_DIO_WRITE (1 << 0)
1277 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1278 #define FUSE_DIO_CUSE (1 << 1)
1280 ssize_t
fuse_direct_io(struct fuse_io_priv
*io
, struct iov_iter
*iter
,
1281 loff_t
*ppos
, int flags
);
1282 long fuse_do_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
,
1283 unsigned int flags
);
1284 long fuse_ioctl_common(struct file
*file
, unsigned int cmd
,
1285 unsigned long arg
, unsigned int flags
);
1286 __poll_t
fuse_file_poll(struct file
*file
, poll_table
*wait
);
1287 int fuse_dev_release(struct inode
*inode
, struct file
*file
);
1289 bool fuse_write_update_attr(struct inode
*inode
, loff_t pos
, ssize_t written
);
1291 int fuse_flush_times(struct inode
*inode
, struct fuse_file
*ff
);
1292 int fuse_write_inode(struct inode
*inode
, struct writeback_control
*wbc
);
1294 int fuse_do_setattr(struct dentry
*dentry
, struct iattr
*attr
,
1297 void fuse_set_initialized(struct fuse_conn
*fc
);
1299 void fuse_unlock_inode(struct inode
*inode
, bool locked
);
1300 bool fuse_lock_inode(struct inode
*inode
);
1302 int fuse_setxattr(struct inode
*inode
, const char *name
, const void *value
,
1303 size_t size
, int flags
, unsigned int extra_flags
);
1304 ssize_t
fuse_getxattr(struct inode
*inode
, const char *name
, void *value
,
1306 ssize_t
fuse_listxattr(struct dentry
*entry
, char *list
, size_t size
);
1307 int fuse_removexattr(struct inode
*inode
, const char *name
);
1308 extern const struct xattr_handler
* const fuse_xattr_handlers
[];
1311 struct posix_acl
*fuse_get_inode_acl(struct inode
*inode
, int type
, bool rcu
);
1312 struct posix_acl
*fuse_get_acl(struct mnt_idmap
*idmap
,
1313 struct dentry
*dentry
, int type
);
1314 int fuse_set_acl(struct mnt_idmap
*, struct dentry
*dentry
,
1315 struct posix_acl
*acl
, int type
);
1318 int fuse_readdir(struct file
*file
, struct dir_context
*ctx
);
1321 * Return the number of bytes in an arguments list
1323 unsigned int fuse_len_args(unsigned int numargs
, struct fuse_arg
*args
);
1326 * Get the next unique ID for a request
1328 u64
fuse_get_unique(struct fuse_iqueue
*fiq
);
1329 void fuse_free_conn(struct fuse_conn
*fc
);
1333 #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1335 ssize_t
fuse_dax_read_iter(struct kiocb
*iocb
, struct iov_iter
*to
);
1336 ssize_t
fuse_dax_write_iter(struct kiocb
*iocb
, struct iov_iter
*from
);
1337 int fuse_dax_mmap(struct file
*file
, struct vm_area_struct
*vma
);
1338 int fuse_dax_break_layouts(struct inode
*inode
, u64 dmap_start
, u64 dmap_end
);
1339 int fuse_dax_conn_alloc(struct fuse_conn
*fc
, enum fuse_dax_mode mode
,
1340 struct dax_device
*dax_dev
);
1341 void fuse_dax_conn_free(struct fuse_conn
*fc
);
1342 bool fuse_dax_inode_alloc(struct super_block
*sb
, struct fuse_inode
*fi
);
1343 void fuse_dax_inode_init(struct inode
*inode
, unsigned int flags
);
1344 void fuse_dax_inode_cleanup(struct inode
*inode
);
1345 void fuse_dax_dontcache(struct inode
*inode
, unsigned int flags
);
1346 bool fuse_dax_check_alignment(struct fuse_conn
*fc
, unsigned int map_alignment
);
1347 void fuse_dax_cancel_work(struct fuse_conn
*fc
);
1350 long fuse_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
1351 long fuse_file_compat_ioctl(struct file
*file
, unsigned int cmd
,
1353 int fuse_fileattr_get(struct dentry
*dentry
, struct fileattr
*fa
);
1354 int fuse_fileattr_set(struct mnt_idmap
*idmap
,
1355 struct dentry
*dentry
, struct fileattr
*fa
);
1358 int fuse_file_cached_io_start(struct inode
*inode
, struct fuse_file
*ff
);
1359 int fuse_file_uncached_io_start(struct inode
*inode
, struct fuse_file
*ff
);
1360 void fuse_file_uncached_io_end(struct inode
*inode
, struct fuse_file
*ff
);
1362 int fuse_file_io_open(struct file
*file
, struct inode
*inode
);
1363 void fuse_file_io_release(struct fuse_file
*ff
, struct inode
*inode
);
1366 struct fuse_file
*fuse_file_open(struct fuse_mount
*fm
, u64 nodeid
,
1367 unsigned int open_flags
, bool isdir
);
1368 void fuse_file_release(struct inode
*inode
, struct fuse_file
*ff
,
1369 unsigned int open_flags
, fl_owner_t id
, bool isdir
);
1371 #endif /* _FS_FUSE_I_H */