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 /* Write related fields (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 /* Waitq for writepage completion */
127 wait_queue_head_t page_waitq
;
129 /* List of writepage requestst (pending or sent) */
130 struct rb_root writepages
;
133 /* readdir cache (directory only) */
135 /* true if fully cached */
141 /* position at end of cache (position of next entry) */
144 /* version of the cache */
147 /* modification time of directory when cache was
149 struct timespec64 mtime
;
151 /* iversion of directory when cache was started */
154 /* protects above fields */
159 /** Miscellaneous bits describing inode state */
162 /** Lock for serializing lookup and readdir for back compatibility*/
165 /** Lock to protect write related fields */
168 #ifdef CONFIG_FUSE_DAX
170 * Dax specific inode data
172 struct fuse_inode_dax
*dax
;
174 /** Submount specific lookup tracking */
175 struct fuse_submount_lookup
*submount_lookup
;
178 /** FUSE inode state bits */
180 /** Advise readdirplus */
181 FUSE_I_ADVISE_RDPLUS
,
182 /** Initialized with readdirplus */
184 /** An operation changing file size is in progress */
185 FUSE_I_SIZE_UNSTABLE
,
194 struct fuse_release_args
;
196 /** FUSE specific file data */
198 /** Fuse connection for this file */
199 struct fuse_mount
*fm
;
201 /* Argument space reserved for release */
202 struct fuse_release_args
*release_args
;
204 /** Kernel file handle guaranteed to be unique */
207 /** File handle used by userspace */
210 /** Node id of this file */
216 /** FOPEN_* flags returned by open */
219 /** Entry on inode's write_files list */
220 struct list_head write_entry
;
222 /* Readdir related */
225 * Protects below fields against (crazy) parallel readdir on
226 * same open file. Uncontended in the normal case.
230 /* Dir stream position */
233 /* Offset in cache */
236 /* Version of cache we are reading */
241 /** RB node to be linked on fuse_conn->polled_files */
242 struct rb_node polled_node
;
244 /** Wait queue head for poll */
245 wait_queue_head_t poll_wait
;
247 /** Has flock been performed on this file? */
251 /** One input argument of a request */
257 /** One output argument of a request */
263 /** FUSE page descriptor */
264 struct fuse_page_desc
{
286 struct fuse_in_arg in_args
[3];
287 struct fuse_arg out_args
[2];
288 void (*end
)(struct fuse_mount
*fm
, struct fuse_args
*args
, int error
);
291 struct fuse_args_pages
{
292 struct fuse_args args
;
294 struct fuse_page_desc
*descs
;
295 unsigned int num_pages
;
298 #define FUSE_ARGS(args) struct fuse_args args = {}
300 /** The request IO state (for asynchronous processing) */
301 struct fuse_io_priv
{
313 struct completion
*done
;
317 #define FUSE_IO_PRIV_SYNC(i) \
319 .refcnt = KREF_INIT(1), \
327 * FR_ISREPLY: set if the request has reply
328 * FR_FORCE: force sending of the request even if interrupted
329 * FR_BACKGROUND: request is sent in the background
330 * FR_WAITING: request is counted as "waiting"
331 * FR_ABORTED: the request was aborted
332 * FR_INTERRUPTED: the request has been interrupted
333 * FR_LOCKED: data is being copied to/from the request
334 * FR_PENDING: request is not yet in userspace
335 * FR_SENT: request is in userspace, waiting for an answer
336 * FR_FINISHED: request is finished
337 * FR_PRIVATE: request is on private list
338 * FR_ASYNC: request is asynchronous
356 * A request to the client
358 * .waitq.lock protects the following fields:
360 * - FR_LOCKED (may also be modified under fc->lock, tested under both)
363 /** This can be on either pending processing or io lists in
365 struct list_head list
;
367 /** Entry on the interrupts list */
368 struct list_head intr_entry
;
370 /* Input/output arguments */
371 struct fuse_args
*args
;
376 /* Request flags, updated with test/set/clear_bit() */
379 /* The request input header */
381 struct fuse_in_header h
;
384 /* The request output header */
386 struct fuse_out_header h
;
389 /** Used to wake up the task waiting for completion of request*/
390 wait_queue_head_t waitq
;
392 #if IS_ENABLED(CONFIG_VIRTIO_FS)
393 /** virtio-fs's physically contiguous buffer for in and out args */
397 /** fuse_mount this request belongs to */
398 struct fuse_mount
*fm
;
404 * Input queue callbacks
406 * Input queue signalling is device-specific. For example, the /dev/fuse file
407 * uses fiq->waitq and fasync to wake processes that are waiting on queue
408 * readiness. These callbacks allow other device types to respond to input
411 struct fuse_iqueue_ops
{
413 * Signal that a forget has been queued
415 void (*wake_forget_and_unlock
)(struct fuse_iqueue
*fiq
)
416 __releases(fiq
->lock
);
419 * Signal that an INTERRUPT request has been queued
421 void (*wake_interrupt_and_unlock
)(struct fuse_iqueue
*fiq
)
422 __releases(fiq
->lock
);
425 * Signal that a request has been queued
427 void (*wake_pending_and_unlock
)(struct fuse_iqueue
*fiq
)
428 __releases(fiq
->lock
);
431 * Clean up when fuse_iqueue is destroyed
433 void (*release
)(struct fuse_iqueue
*fiq
);
436 /** /dev/fuse input queue operations */
437 extern const struct fuse_iqueue_ops fuse_dev_fiq_ops
;
440 /** Connection established */
443 /** Lock protecting accesses to members of this structure */
446 /** Readers of the connection are waiting on this */
447 wait_queue_head_t waitq
;
449 /** The next unique request id */
452 /** The list of pending requests */
453 struct list_head pending
;
455 /** Pending interrupts */
456 struct list_head interrupts
;
458 /** Queue of pending forgets */
459 struct fuse_forget_link forget_list_head
;
460 struct fuse_forget_link
*forget_list_tail
;
462 /** Batching of FORGET requests (positive indicates FORGET batch) */
465 /** O_ASYNC requests */
466 struct fasync_struct
*fasync
;
468 /** Device-specific callbacks */
469 const struct fuse_iqueue_ops
*ops
;
471 /** Device-specific state */
475 #define FUSE_PQ_HASH_BITS 8
476 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
479 /** Connection established */
482 /** Lock protecting accessess to members of this structure */
485 /** Hash table of requests being processed */
486 struct list_head
*processing
;
488 /** The list of requests under I/O */
493 * Fuse device instance
496 /** Fuse connection for this device */
497 struct fuse_conn
*fc
;
499 /** Processing queue */
500 struct fuse_pqueue pq
;
502 /** list entry on fc->devices */
503 struct list_head entry
;
507 FUSE_DAX_INODE_DEFAULT
, /* default */
508 FUSE_DAX_ALWAYS
, /* "-o dax=always" */
509 FUSE_DAX_NEVER
, /* "-o dax=never" */
510 FUSE_DAX_INODE_USER
, /* "-o dax=inode" */
513 static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode
)
515 return mode
== FUSE_DAX_INODE_DEFAULT
|| mode
== FUSE_DAX_INODE_USER
;
518 struct fuse_fs_context
{
521 unsigned int rootmode
;
526 bool rootmode_present
:1;
527 bool user_id_present
:1;
528 bool group_id_present
:1;
529 bool default_permissions
:1;
533 bool no_force_umount
:1;
534 bool legacy_opts_show
:1;
535 enum fuse_dax_mode dax_mode
;
536 unsigned int max_read
;
537 unsigned int blksize
;
540 /* DAX device, may be NULL */
541 struct dax_device
*dax_dev
;
543 /* fuse_dev pointer to fill in, should contain NULL on entry */
547 struct fuse_sync_bucket
{
548 /* count is a possible scalability bottleneck */
550 wait_queue_head_t waitq
;
557 * This structure is created, when the root filesystem is mounted, and
558 * is destroyed, when the client device is closed and the last
559 * fuse_mount is destroyed.
562 /** Lock protecting accessess to members of this structure */
568 /** Number of fuse_dev's */
573 /** The user id for this mount */
576 /** The group id for this mount */
579 /** The pid namespace for this mount */
580 struct pid_namespace
*pid_ns
;
582 /** The user namespace for this mount */
583 struct user_namespace
*user_ns
;
585 /** Maximum read size */
588 /** Maximum write size */
591 /** Maximum number of pages that can be used in a single request */
592 unsigned int max_pages
;
594 /** Constrain ->max_pages to this value during feature negotiation */
595 unsigned int max_pages_limit
;
598 struct fuse_iqueue iq
;
600 /** The next unique kernel file handle */
603 /** rbtree of fuse_files waiting for poll events indexed by ph */
604 struct rb_root polled_files
;
606 /** Maximum number of outstanding background requests */
607 unsigned max_background
;
609 /** Number of background requests at which congestion starts */
610 unsigned congestion_threshold
;
612 /** Number of requests currently in the background */
613 unsigned num_background
;
615 /** Number of background requests currently queued for userspace */
616 unsigned active_background
;
618 /** The list of background requests set aside for later queuing */
619 struct list_head bg_queue
;
621 /** Protects: max_background, congestion_threshold, num_background,
622 * active_background, bg_queue, blocked */
625 /** Flag indicating that INIT reply has been received. Allocating
626 * any fuse request will be suspended until the flag is set */
629 /** Flag indicating if connection is blocked. This will be
630 the case before the INIT reply is received, and if there
631 are too many outstading backgrounds requests */
634 /** waitq for blocked connection */
635 wait_queue_head_t blocked_waitq
;
637 /** Connection established, cleared on umount, connection
638 abort and device release */
641 /** Connection aborted via sysfs */
644 /** Connection failed (version mismatch). Cannot race with
645 setting other bitfields since it is only set once in INIT
646 reply, before any other request, and never cleared */
647 unsigned conn_error
:1;
649 /** Connection successful. Only set in INIT */
650 unsigned conn_init
:1;
652 /** Do readahead asynchronously? Only set in INIT */
653 unsigned async_read
:1;
655 /** Return an unique read error after abort. Only set in INIT */
656 unsigned abort_err
:1;
658 /** Do not send separate SETATTR request before open(O_TRUNC) */
659 unsigned atomic_o_trunc
:1;
661 /** Filesystem supports NFS exporting. Only set in INIT */
662 unsigned export_support
:1;
664 /** write-back cache policy (default is write-through) */
665 unsigned writeback_cache
:1;
667 /** allow parallel lookups and readdir (default is serialized) */
668 unsigned parallel_dirops
:1;
670 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
671 unsigned handle_killpriv
:1;
673 /** cache READLINK responses in page cache */
674 unsigned cache_symlinks
:1;
676 /* show legacy mount options */
677 unsigned int legacy_opts_show
:1;
680 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
681 * write/trunc only if caller did not have CAP_FSETID. sgid is killed
682 * on write/truncate only if caller did not have CAP_FSETID as well as
683 * file has group execute permission.
685 unsigned handle_killpriv_v2
:1;
688 * The following bitfields are only for optimization purposes
689 * and hence races in setting them will not cause malfunction
692 /** Is open/release not implemented by fs? */
695 /** Is opendir/releasedir not implemented by fs? */
696 unsigned no_opendir
:1;
698 /** Is fsync not implemented by fs? */
701 /** Is fsyncdir not implemented by fs? */
702 unsigned no_fsyncdir
:1;
704 /** Is flush not implemented by fs? */
707 /** Is setxattr not implemented by fs? */
708 unsigned no_setxattr
:1;
710 /** Does file server support extended setxattr */
711 unsigned setxattr_ext
:1;
713 /** Is getxattr not implemented by fs? */
714 unsigned no_getxattr
:1;
716 /** Is listxattr not implemented by fs? */
717 unsigned no_listxattr
:1;
719 /** Is removexattr not implemented by fs? */
720 unsigned no_removexattr
:1;
722 /** Are posix file locking primitives not implemented by fs? */
725 /** Is access not implemented by fs? */
726 unsigned no_access
:1;
728 /** Is create not implemented by fs? */
729 unsigned no_create
:1;
731 /** Is interrupt not implemented by fs? */
732 unsigned no_interrupt
:1;
734 /** Is bmap not implemented by fs? */
737 /** Is poll not implemented by fs? */
740 /** Do multi-page cached writes */
741 unsigned big_writes
:1;
743 /** Don't apply umask to creation modes */
744 unsigned dont_mask
:1;
746 /** Are BSD file locking primitives not implemented by fs? */
749 /** Is fallocate not implemented by fs? */
750 unsigned no_fallocate
:1;
752 /** Is rename with flags implemented by fs? */
753 unsigned no_rename2
:1;
755 /** Use enhanced/automatic page cache invalidation. */
756 unsigned auto_inval_data
:1;
758 /** Filesystem is fully responsible for page cache invalidation. */
759 unsigned explicit_inval_data
:1;
761 /** Does the filesystem support readdirplus? */
762 unsigned do_readdirplus
:1;
764 /** Does the filesystem want adaptive readdirplus? */
765 unsigned readdirplus_auto
:1;
767 /** Does the filesystem support asynchronous direct-IO submission? */
768 unsigned async_dio
:1;
770 /** Is lseek not implemented by fs? */
773 /** Does the filesystem support posix acls? */
774 unsigned posix_acl
:1;
776 /** Check permissions based on the file mode or not? */
777 unsigned default_permissions
:1;
779 /** Allow other than the mounter user to access the filesystem ? */
780 unsigned allow_other
:1;
782 /** Does the filesystem support copy_file_range? */
783 unsigned no_copy_file_range
:1;
785 /* Send DESTROY request */
786 unsigned int destroy
:1;
788 /* Delete dentries that have gone stale */
789 unsigned int delete_stale
:1;
791 /** Do not create entry in fusectl fs */
792 unsigned int no_control
:1;
794 /** Do not allow MNT_FORCE umount */
795 unsigned int no_force_umount
:1;
797 /* Auto-mount submounts announced by the server */
798 unsigned int auto_submounts
:1;
800 /* Propagate syncfs() to server */
801 unsigned int sync_fs
:1;
803 /* Initialize security xattrs when creating a new inode */
804 unsigned int init_security
:1;
806 /* Add supplementary group info when creating a new inode */
807 unsigned int create_supp_group
:1;
809 /* Does the filesystem support per inode DAX? */
810 unsigned int inode_dax
:1;
812 /* Is tmpfile not implemented by fs? */
813 unsigned int no_tmpfile
:1;
815 /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
816 unsigned int direct_io_allow_mmap
:1;
818 /* Is statx not implemented by fs? */
819 unsigned int no_statx
:1;
821 /** The number of requests waiting for completion */
822 atomic_t num_waiting
;
824 /** Negotiated minor version */
827 /** Entry on the fuse_mount_list */
828 struct list_head entry
;
830 /** Device ID from the root super block */
833 /** Dentries in the control filesystem */
834 struct dentry
*ctl_dentry
[FUSE_CTL_NUM_DENTRIES
];
836 /** number of dentries used in the above array */
839 /** Key for lock owner ID scrambling */
842 /** Version counter for attribute changes */
843 atomic64_t attr_version
;
845 /** Called on final put */
846 void (*release
)(struct fuse_conn
*);
849 * Read/write semaphore to hold when accessing the sb of any
850 * fuse_mount belonging to this connection
852 struct rw_semaphore killsb
;
854 /** List of device instances belonging to this connection */
855 struct list_head devices
;
857 #ifdef CONFIG_FUSE_DAX
859 enum fuse_dax_mode dax_mode
;
861 /* Dax specific conn data, non-NULL if DAX is enabled */
862 struct fuse_conn_dax
*dax
;
865 /** List of filesystems using this connection */
866 struct list_head mounts
;
868 /* New writepages go into this bucket */
869 struct fuse_sync_bucket __rcu
*curr_bucket
;
873 * Represents a mounted filesystem, potentially a submount.
875 * This object allows sharing a fuse_conn between separate mounts to
876 * allow submounts with dedicated superblocks and thus separate device
880 /* Underlying (potentially shared) connection to the FUSE server */
881 struct fuse_conn
*fc
;
884 * Super block for this connection (fc->killsb must be held when
887 struct super_block
*sb
;
889 /* Entry on fc->mounts */
890 struct list_head fc_entry
;
893 static inline struct fuse_mount
*get_fuse_mount_super(struct super_block
*sb
)
895 return sb
->s_fs_info
;
898 static inline struct fuse_conn
*get_fuse_conn_super(struct super_block
*sb
)
900 return get_fuse_mount_super(sb
)->fc
;
903 static inline struct fuse_mount
*get_fuse_mount(struct inode
*inode
)
905 return get_fuse_mount_super(inode
->i_sb
);
908 static inline struct fuse_conn
*get_fuse_conn(struct inode
*inode
)
910 return get_fuse_mount_super(inode
->i_sb
)->fc
;
913 static inline struct fuse_inode
*get_fuse_inode(struct inode
*inode
)
915 return container_of(inode
, struct fuse_inode
, inode
);
918 static inline u64
get_node_id(struct inode
*inode
)
920 return get_fuse_inode(inode
)->nodeid
;
923 static inline int invalid_nodeid(u64 nodeid
)
925 return !nodeid
|| nodeid
== FUSE_ROOT_ID
;
928 static inline u64
fuse_get_attr_version(struct fuse_conn
*fc
)
930 return atomic64_read(&fc
->attr_version
);
933 static inline bool fuse_stale_inode(const struct inode
*inode
, int generation
,
934 struct fuse_attr
*attr
)
936 return inode
->i_generation
!= generation
||
937 inode_wrong_type(inode
, attr
->mode
);
940 static inline void fuse_make_bad(struct inode
*inode
)
942 remove_inode_hash(inode
);
943 set_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
);
946 static inline bool fuse_is_bad(struct inode
*inode
)
948 return unlikely(test_bit(FUSE_I_BAD
, &get_fuse_inode(inode
)->state
));
951 static inline struct page
**fuse_pages_alloc(unsigned int npages
, gfp_t flags
,
952 struct fuse_page_desc
**desc
)
956 pages
= kzalloc(npages
* (sizeof(struct page
*) +
957 sizeof(struct fuse_page_desc
)), flags
);
958 *desc
= (void *) (pages
+ npages
);
963 static inline void fuse_page_descs_length_init(struct fuse_page_desc
*descs
,
965 unsigned int nr_pages
)
969 for (i
= index
; i
< index
+ nr_pages
; i
++)
970 descs
[i
].length
= PAGE_SIZE
- descs
[i
].offset
;
973 static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket
*bucket
)
975 /* Need RCU protection to prevent use after free after the decrement */
977 if (atomic_dec_and_test(&bucket
->count
))
978 wake_up(&bucket
->waitq
);
982 /** Device operations */
983 extern const struct file_operations fuse_dev_operations
;
985 extern const struct dentry_operations fuse_dentry_operations
;
986 extern const struct dentry_operations fuse_root_dentry_operations
;
989 * Get a filled in inode
991 struct inode
*fuse_iget(struct super_block
*sb
, u64 nodeid
,
992 int generation
, struct fuse_attr
*attr
,
993 u64 attr_valid
, u64 attr_version
);
995 int fuse_lookup_name(struct super_block
*sb
, u64 nodeid
, const struct qstr
*name
,
996 struct fuse_entry_out
*outarg
, struct inode
**inode
);
999 * Send FORGET command
1001 void fuse_queue_forget(struct fuse_conn
*fc
, struct fuse_forget_link
*forget
,
1002 u64 nodeid
, u64 nlookup
);
1004 struct fuse_forget_link
*fuse_alloc_forget(void);
1006 struct fuse_forget_link
*fuse_dequeue_forget(struct fuse_iqueue
*fiq
,
1008 unsigned int *countp
);
1011 * Initialize READ or READDIR request
1013 struct fuse_io_args
{
1016 struct fuse_read_in in
;
1020 struct fuse_write_in in
;
1021 struct fuse_write_out out
;
1025 struct fuse_args_pages ap
;
1026 struct fuse_io_priv
*io
;
1027 struct fuse_file
*ff
;
1030 void fuse_read_args_fill(struct fuse_io_args
*ia
, struct file
*file
, loff_t pos
,
1031 size_t count
, int opcode
);
1035 * Send OPEN or OPENDIR request
1037 int fuse_open_common(struct inode
*inode
, struct file
*file
, bool isdir
);
1039 struct fuse_file
*fuse_file_alloc(struct fuse_mount
*fm
);
1040 void fuse_file_free(struct fuse_file
*ff
);
1041 void fuse_finish_open(struct inode
*inode
, struct file
*file
);
1043 void fuse_sync_release(struct fuse_inode
*fi
, struct fuse_file
*ff
,
1044 unsigned int flags
);
1047 * Send RELEASE or RELEASEDIR request
1049 void fuse_release_common(struct file
*file
, bool isdir
);
1052 * Send FSYNC or FSYNCDIR request
1054 int fuse_fsync_common(struct file
*file
, loff_t start
, loff_t end
,
1055 int datasync
, int opcode
);
1058 * Notify poll wakeup
1060 int fuse_notify_poll_wakeup(struct fuse_conn
*fc
,
1061 struct fuse_notify_poll_wakeup_out
*outarg
);
1064 * Initialize file operations on a regular file
1066 void fuse_init_file_inode(struct inode
*inode
, unsigned int flags
);
1069 * Initialize inode operations on regular files and special files
1071 void fuse_init_common(struct inode
*inode
);
1074 * Initialize inode and file operations on a directory
1076 void fuse_init_dir(struct inode
*inode
);
1079 * Initialize inode operations on a symlink
1081 void fuse_init_symlink(struct inode
*inode
);
1084 * Change attributes of an inode
1086 void fuse_change_attributes(struct inode
*inode
, struct fuse_attr
*attr
,
1087 struct fuse_statx
*sx
,
1088 u64 attr_valid
, u64 attr_version
);
1090 void fuse_change_attributes_common(struct inode
*inode
, struct fuse_attr
*attr
,
1091 struct fuse_statx
*sx
,
1092 u64 attr_valid
, u32 cache_mask
);
1094 u32
fuse_get_cache_mask(struct inode
*inode
);
1097 * Initialize the client device
1099 int fuse_dev_init(void);
1102 * Cleanup the client device
1104 void fuse_dev_cleanup(void);
1106 int fuse_ctl_init(void);
1107 void __exit
fuse_ctl_cleanup(void);
1110 * Simple request sending that does request allocation and freeing
1112 ssize_t
fuse_simple_request(struct fuse_mount
*fm
, struct fuse_args
*args
);
1113 int fuse_simple_background(struct fuse_mount
*fm
, struct fuse_args
*args
,
1117 * End a finished request
1119 void fuse_request_end(struct fuse_req
*req
);
1121 /* Abort all requests */
1122 void fuse_abort_conn(struct fuse_conn
*fc
);
1123 void fuse_wait_aborted(struct fuse_conn
*fc
);
1126 * Invalidate inode attributes
1129 /* Attributes possibly changed on data modification */
1130 #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1132 /* Attributes possibly changed on data and/or size modification */
1133 #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
1135 void fuse_invalidate_attr(struct inode
*inode
);
1136 void fuse_invalidate_attr_mask(struct inode
*inode
, u32 mask
);
1138 void fuse_invalidate_entry_cache(struct dentry
*entry
);
1140 void fuse_invalidate_atime(struct inode
*inode
);
1142 u64
fuse_time_to_jiffies(u64 sec
, u32 nsec
);
1143 #define ATTR_TIMEOUT(o) \
1144 fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
1146 void fuse_change_entry_timeout(struct dentry
*entry
, struct fuse_entry_out
*o
);
1149 * Acquire reference to fuse_conn
1151 struct fuse_conn
*fuse_conn_get(struct fuse_conn
*fc
);
1154 * Initialize fuse_conn
1156 void fuse_conn_init(struct fuse_conn
*fc
, struct fuse_mount
*fm
,
1157 struct user_namespace
*user_ns
,
1158 const struct fuse_iqueue_ops
*fiq_ops
, void *fiq_priv
);
1161 * Release reference to fuse_conn
1163 void fuse_conn_put(struct fuse_conn
*fc
);
1165 struct fuse_dev
*fuse_dev_alloc_install(struct fuse_conn
*fc
);
1166 struct fuse_dev
*fuse_dev_alloc(void);
1167 void fuse_dev_install(struct fuse_dev
*fud
, struct fuse_conn
*fc
);
1168 void fuse_dev_free(struct fuse_dev
*fud
);
1169 void fuse_send_init(struct fuse_mount
*fm
);
1172 * Fill in superblock and initialize fuse connection
1173 * @sb: partially-initialized superblock to fill in
1174 * @ctx: mount context
1176 int fuse_fill_super_common(struct super_block
*sb
, struct fuse_fs_context
*ctx
);
1179 * Remove the mount from the connection
1181 * Returns whether this was the last mount
1183 bool fuse_mount_remove(struct fuse_mount
*fm
);
1186 * Setup context ops for submounts
1188 int fuse_init_fs_context_submount(struct fs_context
*fsc
);
1191 * Shut down the connection (possibly sending DESTROY request).
1193 void fuse_conn_destroy(struct fuse_mount
*fm
);
1195 /* Drop the connection and free the fuse mount */
1196 void fuse_mount_destroy(struct fuse_mount
*fm
);
1199 * Add connection to control filesystem
1201 int fuse_ctl_add_conn(struct fuse_conn
*fc
);
1204 * Remove connection from control filesystem
1206 void fuse_ctl_remove_conn(struct fuse_conn
*fc
);
1209 * Is file type valid?
1211 int fuse_valid_type(int m
);
1213 bool fuse_invalid_attr(struct fuse_attr
*attr
);
1216 * Is current process allowed to perform filesystem operation?
1218 bool fuse_allow_current_process(struct fuse_conn
*fc
);
1220 u64
fuse_lock_owner_id(struct fuse_conn
*fc
, fl_owner_t id
);
1222 void fuse_flush_time_update(struct inode
*inode
);
1223 void fuse_update_ctime(struct inode
*inode
);
1225 int fuse_update_attributes(struct inode
*inode
, struct file
*file
, u32 mask
);
1227 void fuse_flush_writepages(struct inode
*inode
);
1229 void fuse_set_nowrite(struct inode
*inode
);
1230 void fuse_release_nowrite(struct inode
*inode
);
1233 * Scan all fuse_mounts belonging to fc to find the first where
1234 * ilookup5() returns a result. Return that result and the
1235 * respective fuse_mount in *fm (unless fm is NULL).
1237 * The caller must hold fc->killsb.
1239 struct inode
*fuse_ilookup(struct fuse_conn
*fc
, u64 nodeid
,
1240 struct fuse_mount
**fm
);
1243 * File-system tells the kernel to invalidate cache for the given node id.
1245 int fuse_reverse_inval_inode(struct fuse_conn
*fc
, u64 nodeid
,
1246 loff_t offset
, loff_t len
);
1249 * File-system tells the kernel to invalidate parent attributes and
1250 * the dentry matching parent/name.
1252 * If the child_nodeid is non-zero and:
1253 * - matches the inode number for the dentry matching parent/name,
1254 * - is not a mount point
1255 * - is a file or oan empty directory
1256 * then the dentry is unhashed (d_delete()).
1258 int fuse_reverse_inval_entry(struct fuse_conn
*fc
, u64 parent_nodeid
,
1259 u64 child_nodeid
, struct qstr
*name
, u32 flags
);
1261 int fuse_do_open(struct fuse_mount
*fm
, u64 nodeid
, struct file
*file
,
1265 * fuse_direct_io() flags
1268 /** If set, it is WRITE; otherwise - READ */
1269 #define FUSE_DIO_WRITE (1 << 0)
1271 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1272 #define FUSE_DIO_CUSE (1 << 1)
1274 ssize_t
fuse_direct_io(struct fuse_io_priv
*io
, struct iov_iter
*iter
,
1275 loff_t
*ppos
, int flags
);
1276 long fuse_do_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
,
1277 unsigned int flags
);
1278 long fuse_ioctl_common(struct file
*file
, unsigned int cmd
,
1279 unsigned long arg
, unsigned int flags
);
1280 __poll_t
fuse_file_poll(struct file
*file
, poll_table
*wait
);
1281 int fuse_dev_release(struct inode
*inode
, struct file
*file
);
1283 bool fuse_write_update_attr(struct inode
*inode
, loff_t pos
, ssize_t written
);
1285 int fuse_flush_times(struct inode
*inode
, struct fuse_file
*ff
);
1286 int fuse_write_inode(struct inode
*inode
, struct writeback_control
*wbc
);
1288 int fuse_do_setattr(struct dentry
*dentry
, struct iattr
*attr
,
1291 void fuse_set_initialized(struct fuse_conn
*fc
);
1293 void fuse_unlock_inode(struct inode
*inode
, bool locked
);
1294 bool fuse_lock_inode(struct inode
*inode
);
1296 int fuse_setxattr(struct inode
*inode
, const char *name
, const void *value
,
1297 size_t size
, int flags
, unsigned int extra_flags
);
1298 ssize_t
fuse_getxattr(struct inode
*inode
, const char *name
, void *value
,
1300 ssize_t
fuse_listxattr(struct dentry
*entry
, char *list
, size_t size
);
1301 int fuse_removexattr(struct inode
*inode
, const char *name
);
1302 extern const struct xattr_handler
* const fuse_xattr_handlers
[];
1305 struct posix_acl
*fuse_get_inode_acl(struct inode
*inode
, int type
, bool rcu
);
1306 struct posix_acl
*fuse_get_acl(struct mnt_idmap
*idmap
,
1307 struct dentry
*dentry
, int type
);
1308 int fuse_set_acl(struct mnt_idmap
*, struct dentry
*dentry
,
1309 struct posix_acl
*acl
, int type
);
1312 int fuse_readdir(struct file
*file
, struct dir_context
*ctx
);
1315 * Return the number of bytes in an arguments list
1317 unsigned int fuse_len_args(unsigned int numargs
, struct fuse_arg
*args
);
1320 * Get the next unique ID for a request
1322 u64
fuse_get_unique(struct fuse_iqueue
*fiq
);
1323 void fuse_free_conn(struct fuse_conn
*fc
);
1327 #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1329 ssize_t
fuse_dax_read_iter(struct kiocb
*iocb
, struct iov_iter
*to
);
1330 ssize_t
fuse_dax_write_iter(struct kiocb
*iocb
, struct iov_iter
*from
);
1331 int fuse_dax_mmap(struct file
*file
, struct vm_area_struct
*vma
);
1332 int fuse_dax_break_layouts(struct inode
*inode
, u64 dmap_start
, u64 dmap_end
);
1333 int fuse_dax_conn_alloc(struct fuse_conn
*fc
, enum fuse_dax_mode mode
,
1334 struct dax_device
*dax_dev
);
1335 void fuse_dax_conn_free(struct fuse_conn
*fc
);
1336 bool fuse_dax_inode_alloc(struct super_block
*sb
, struct fuse_inode
*fi
);
1337 void fuse_dax_inode_init(struct inode
*inode
, unsigned int flags
);
1338 void fuse_dax_inode_cleanup(struct inode
*inode
);
1339 void fuse_dax_dontcache(struct inode
*inode
, unsigned int flags
);
1340 bool fuse_dax_check_alignment(struct fuse_conn
*fc
, unsigned int map_alignment
);
1341 void fuse_dax_cancel_work(struct fuse_conn
*fc
);
1344 long fuse_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
1345 long fuse_file_compat_ioctl(struct file
*file
, unsigned int cmd
,
1347 int fuse_fileattr_get(struct dentry
*dentry
, struct fileattr
*fa
);
1348 int fuse_fileattr_set(struct mnt_idmap
*idmap
,
1349 struct dentry
*dentry
, struct fileattr
*fa
);
1353 struct fuse_file
*fuse_file_open(struct fuse_mount
*fm
, u64 nodeid
,
1354 unsigned int open_flags
, bool isdir
);
1355 void fuse_file_release(struct inode
*inode
, struct fuse_file
*ff
,
1356 unsigned int open_flags
, fl_owner_t id
, bool isdir
);
1358 #endif /* _FS_FUSE_I_H */