1d8a5ba45SMiklos Szeredi /* 2d8a5ba45SMiklos Szeredi FUSE: Filesystem in Userspace 31729a16cSMiklos Szeredi Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu> 4d8a5ba45SMiklos Szeredi 5d8a5ba45SMiklos Szeredi This program can be distributed under the terms of the GNU GPL. 6d8a5ba45SMiklos Szeredi See the file COPYING. 7d8a5ba45SMiklos Szeredi */ 8d8a5ba45SMiklos Szeredi 929d434b3STejun Heo #ifndef _FS_FUSE_I_H 1029d434b3STejun Heo #define _FS_FUSE_I_H 1129d434b3STejun Heo 12f2294482SKirill Smelkov #ifndef pr_fmt 13f2294482SKirill Smelkov # define pr_fmt(fmt) "fuse: " fmt 14f2294482SKirill Smelkov #endif 15f2294482SKirill Smelkov 16d8a5ba45SMiklos Szeredi #include <linux/fuse.h> 17d8a5ba45SMiklos Szeredi #include <linux/fs.h> 1851eb01e7SMiklos Szeredi #include <linux/mount.h> 19d8a5ba45SMiklos Szeredi #include <linux/wait.h> 20d8a5ba45SMiklos Szeredi #include <linux/list.h> 21d8a5ba45SMiklos Szeredi #include <linux/spinlock.h> 22d8a5ba45SMiklos Szeredi #include <linux/mm.h> 23d8a5ba45SMiklos Szeredi #include <linux/backing-dev.h> 24bafa9654SMiklos Szeredi #include <linux/mutex.h> 253be5a52bSMiklos Szeredi #include <linux/rwsem.h> 2695668a69STejun Heo #include <linux/rbtree.h> 2795668a69STejun Heo #include <linux/poll.h> 285a18ec17SMiklos Szeredi #include <linux/workqueue.h> 29744742d6SSeth Forshee #include <linux/kref.h> 3060bcc88aSSeth Forshee #include <linux/xattr.h> 310b6e9ea0SSeth Forshee #include <linux/pid_namespace.h> 324e8c2eb5SElena Reshetova #include <linux/refcount.h> 338cb08329SEric W. Biederman #include <linux/user_namespace.h> 34d8a5ba45SMiklos Szeredi 355da784ccSConstantine Shulyupin /** Default max number of pages that can be used in a single read request */ 365da784ccSConstantine Shulyupin #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 375da784ccSConstantine Shulyupin 385da784ccSConstantine Shulyupin /** Maximum of max_pages received in init_out */ 395da784ccSConstantine Shulyupin #define FUSE_MAX_MAX_PAGES 256 40334f485dSMiklos Szeredi 413be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 423be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 433be5a52bSMiklos Szeredi 441d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 451d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 461d3d752bSMiklos Szeredi 47bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4879a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 49bafa9654SMiklos Szeredi 50bafa9654SMiklos Szeredi /** List of active connections */ 51bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 52bafa9654SMiklos Szeredi 53bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 54bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 55413ef8cbSMiklos Szeredi 5679a9d994SCsaba Henk /** Module parameters */ 5779a9d994SCsaba Henk extern unsigned max_user_bgreq; 5879a9d994SCsaba Henk extern unsigned max_user_congthresh; 5979a9d994SCsaba Henk 6007e77dcaSMiklos Szeredi /* One forget request */ 6107e77dcaSMiklos Szeredi struct fuse_forget_link { 6202c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 6307e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6407e77dcaSMiklos Szeredi }; 6507e77dcaSMiklos Szeredi 66d8a5ba45SMiklos Szeredi /** FUSE inode */ 67d8a5ba45SMiklos Szeredi struct fuse_inode { 68d8a5ba45SMiklos Szeredi /** Inode data */ 69d8a5ba45SMiklos Szeredi struct inode inode; 70d8a5ba45SMiklos Szeredi 71d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 72d8a5ba45SMiklos Szeredi * and kernel */ 73d8a5ba45SMiklos Szeredi u64 nodeid; 74d8a5ba45SMiklos Szeredi 759e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 769e6268dbSMiklos Szeredi u64 nlookup; 779e6268dbSMiklos Szeredi 78e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7907e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 80e5e5558eSMiklos Szeredi 81d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 820a0898cfSMiklos Szeredi u64 i_time; 83ebc14c4dSMiklos Szeredi 842f1e8196SMiklos Szeredi /* Which attributes are invalid */ 852f1e8196SMiklos Szeredi u32 inval_mask; 862f1e8196SMiklos Szeredi 87ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 88ebc14c4dSMiklos Szeredi preserve the original mode */ 89541af6a0SAl Viro umode_t orig_i_mode; 901fb69e78SMiklos Szeredi 91*972f4c46SMiklos Szeredi /* Cache birthtime */ 92*972f4c46SMiklos Szeredi struct timespec64 i_btime; 93*972f4c46SMiklos Szeredi 9445c72cd7SPavel Shilovsky /** 64 bit inode number */ 9545c72cd7SPavel Shilovsky u64 orig_ino; 9645c72cd7SPavel Shilovsky 971fb69e78SMiklos Szeredi /** Version of last attribute change */ 981fb69e78SMiklos Szeredi u64 attr_version; 9993a8c3cdSMiklos Szeredi 100ab2257e9SMiklos Szeredi union { 101ab2257e9SMiklos Szeredi /* Write related fields (regular file only) */ 102ab2257e9SMiklos Szeredi struct { 103f15ecfefSKirill Tkhai /* Files usable in writepage. Protected by fi->lock */ 10493a8c3cdSMiklos Szeredi struct list_head write_files; 1053be5a52bSMiklos Szeredi 106ab2257e9SMiklos Szeredi /* Writepages pending on truncate or fsync */ 1073be5a52bSMiklos Szeredi struct list_head queued_writes; 1083be5a52bSMiklos Szeredi 109ab2257e9SMiklos Szeredi /* Number of sent writes, a negative bias 110ab2257e9SMiklos Szeredi * (FUSE_NOWRITE) means more writes are blocked */ 1113be5a52bSMiklos Szeredi int writectr; 1123be5a52bSMiklos Szeredi 113ab2257e9SMiklos Szeredi /* Waitq for writepage completion */ 1143be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1153be5a52bSMiklos Szeredi 116ab2257e9SMiklos Szeredi /* List of writepage requestst (pending or sent) */ 1176b2fb799SMaxim Patlasov struct rb_root writepages; 118ab2257e9SMiklos Szeredi }; 1194582a4abSFeng Shuo 120ab2257e9SMiklos Szeredi /* readdir cache (directory only) */ 12169e34551SMiklos Szeredi struct { 12269e34551SMiklos Szeredi /* true if fully cached */ 12369e34551SMiklos Szeredi bool cached; 12469e34551SMiklos Szeredi 12569e34551SMiklos Szeredi /* size of cache */ 12669e34551SMiklos Szeredi loff_t size; 12769e34551SMiklos Szeredi 12869e34551SMiklos Szeredi /* position at end of cache (position of next entry) */ 12969e34551SMiklos Szeredi loff_t pos; 13069e34551SMiklos Szeredi 1313494927eSMiklos Szeredi /* version of the cache */ 1323494927eSMiklos Szeredi u64 version; 1333494927eSMiklos Szeredi 134ab2257e9SMiklos Szeredi /* modification time of directory when cache was 135ab2257e9SMiklos Szeredi * started */ 1367118883bSMiklos Szeredi struct timespec64 mtime; 1377118883bSMiklos Szeredi 138261aaba7SMiklos Szeredi /* iversion of directory when cache was started */ 139261aaba7SMiklos Szeredi u64 iversion; 140261aaba7SMiklos Szeredi 14169e34551SMiklos Szeredi /* protects above fields */ 14269e34551SMiklos Szeredi spinlock_t lock; 14369e34551SMiklos Szeredi } rdc; 144ab2257e9SMiklos Szeredi }; 14569e34551SMiklos Szeredi 1464582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1474582a4abSFeng Shuo unsigned long state; 1485c672ab3SMiklos Szeredi 1495c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1505c672ab3SMiklos Szeredi struct mutex mutex; 151f15ecfefSKirill Tkhai 152f15ecfefSKirill Tkhai /** Lock to protect write related fields */ 153f15ecfefSKirill Tkhai spinlock_t lock; 154c2d0ad00SVivek Goyal 155c2d0ad00SVivek Goyal #ifdef CONFIG_FUSE_DAX 156c2d0ad00SVivek Goyal /* 157c2d0ad00SVivek Goyal * Dax specific inode data 158c2d0ad00SVivek Goyal */ 159c2d0ad00SVivek Goyal struct fuse_inode_dax *dax; 160c2d0ad00SVivek Goyal #endif 1614582a4abSFeng Shuo }; 1624582a4abSFeng Shuo 1634582a4abSFeng Shuo /** FUSE inode state bits */ 1644582a4abSFeng Shuo enum { 1654582a4abSFeng Shuo /** Advise readdirplus */ 1664582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1676314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1686314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 16906a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 17006a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 1715d069dbeSMiklos Szeredi /* Bad inode */ 1725d069dbeSMiklos Szeredi FUSE_I_BAD, 173*972f4c46SMiklos Szeredi /* Has btime */ 174*972f4c46SMiklos Szeredi FUSE_I_BTIME, 175d8a5ba45SMiklos Szeredi }; 176d8a5ba45SMiklos Szeredi 177da5e4714SMiklos Szeredi struct fuse_conn; 178fcee216bSMax Reitz struct fuse_mount; 1794cb54866SMiklos Szeredi struct fuse_release_args; 180da5e4714SMiklos Szeredi 181b6aeadedSMiklos Szeredi /** FUSE specific file data */ 182b6aeadedSMiklos Szeredi struct fuse_file { 183da5e4714SMiklos Szeredi /** Fuse connection for this file */ 184fcee216bSMax Reitz struct fuse_mount *fm; 185da5e4714SMiklos Szeredi 1864cb54866SMiklos Szeredi /* Argument space reserved for release */ 1874cb54866SMiklos Szeredi struct fuse_release_args *release_args; 188b6aeadedSMiklos Szeredi 189acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 190acf99433STejun Heo u64 kh; 191acf99433STejun Heo 192b6aeadedSMiklos Szeredi /** File handle used by userspace */ 193b6aeadedSMiklos Szeredi u64 fh; 194c756e0a4SMiklos Szeredi 195da5e4714SMiklos Szeredi /** Node id of this file */ 196da5e4714SMiklos Szeredi u64 nodeid; 197da5e4714SMiklos Szeredi 198c756e0a4SMiklos Szeredi /** Refcount */ 1994e8c2eb5SElena Reshetova refcount_t count; 20093a8c3cdSMiklos Szeredi 201c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 202c7b7143cSMiklos Szeredi u32 open_flags; 203c7b7143cSMiklos Szeredi 20493a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 20593a8c3cdSMiklos Szeredi struct list_head write_entry; 20695668a69STejun Heo 2075d7bc7e8SMiklos Szeredi /* Readdir related */ 2085d7bc7e8SMiklos Szeredi struct { 2095d7bc7e8SMiklos Szeredi /* 2105d7bc7e8SMiklos Szeredi * Protects below fields against (crazy) parallel readdir on 2115d7bc7e8SMiklos Szeredi * same open file. Uncontended in the normal case. 2125d7bc7e8SMiklos Szeredi */ 2135d7bc7e8SMiklos Szeredi struct mutex lock; 2145d7bc7e8SMiklos Szeredi 2155d7bc7e8SMiklos Szeredi /* Dir stream position */ 2165d7bc7e8SMiklos Szeredi loff_t pos; 2175d7bc7e8SMiklos Szeredi 2185d7bc7e8SMiklos Szeredi /* Offset in cache */ 2195d7bc7e8SMiklos Szeredi loff_t cache_off; 2203494927eSMiklos Szeredi 2213494927eSMiklos Szeredi /* Version of cache we are reading */ 2223494927eSMiklos Szeredi u64 version; 2233494927eSMiklos Szeredi 2245d7bc7e8SMiklos Szeredi } readdir; 2255d7bc7e8SMiklos Szeredi 22695668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 22795668a69STejun Heo struct rb_node polled_node; 22895668a69STejun Heo 22995668a69STejun Heo /** Wait queue head for poll */ 23095668a69STejun Heo wait_queue_head_t poll_wait; 23137fb3a30SMiklos Szeredi 23237fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 23337fb3a30SMiklos Szeredi bool flock:1; 234b6aeadedSMiklos Szeredi }; 235b6aeadedSMiklos Szeredi 236334f485dSMiklos Szeredi /** One input argument of a request */ 237334f485dSMiklos Szeredi struct fuse_in_arg { 238334f485dSMiklos Szeredi unsigned size; 239334f485dSMiklos Szeredi const void *value; 240334f485dSMiklos Szeredi }; 241334f485dSMiklos Szeredi 242334f485dSMiklos Szeredi /** One output argument of a request */ 243334f485dSMiklos Szeredi struct fuse_arg { 244334f485dSMiklos Szeredi unsigned size; 245334f485dSMiklos Szeredi void *value; 246334f485dSMiklos Szeredi }; 247334f485dSMiklos Szeredi 248b2430d75SMaxim Patlasov /** FUSE page descriptor */ 249b2430d75SMaxim Patlasov struct fuse_page_desc { 250b2430d75SMaxim Patlasov unsigned int length; 251b2430d75SMaxim Patlasov unsigned int offset; 252b2430d75SMaxim Patlasov }; 253b2430d75SMaxim Patlasov 2547078187aSMiklos Szeredi struct fuse_args { 2557078187aSMiklos Szeredi uint64_t nodeid; 2561f4e9d03SMiklos Szeredi uint32_t opcode; 25715d937d7SMiklos Szeredi uint8_t in_numargs; 25815d937d7SMiklos Szeredi uint8_t out_numargs; 25915d937d7SMiklos Szeredi uint8_t ext_idx; 260c500ebaaSMiklos Szeredi bool force:1; 261454a7613SMiklos Szeredi bool noreply:1; 262e413754bSMiklos Szeredi bool nocreds:1; 26368583165SMiklos Szeredi bool in_pages:1; 26468583165SMiklos Szeredi bool out_pages:1; 2650c4bcfdeSMiklos Szeredi bool user_pages:1; 2661f4e9d03SMiklos Szeredi bool out_argvar:1; 26768583165SMiklos Szeredi bool page_zeroing:1; 26868583165SMiklos Szeredi bool page_replace:1; 269bb737bbeSVivek Goyal bool may_block:1; 27015d937d7SMiklos Szeredi bool is_ext:1; 271d5b48543SMiklos Szeredi struct fuse_in_arg in_args[3]; 272d5b48543SMiklos Szeredi struct fuse_arg out_args[2]; 273fcee216bSMax Reitz void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error); 2747078187aSMiklos Szeredi }; 2757078187aSMiklos Szeredi 27668583165SMiklos Szeredi struct fuse_args_pages { 27768583165SMiklos Szeredi struct fuse_args args; 27868583165SMiklos Szeredi struct page **pages; 27968583165SMiklos Szeredi struct fuse_page_desc *descs; 28068583165SMiklos Szeredi unsigned int num_pages; 28168583165SMiklos Szeredi }; 28268583165SMiklos Szeredi 2837078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2847078187aSMiklos Szeredi 28501e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 28601e9d11aSMaxim Patlasov struct fuse_io_priv { 287744742d6SSeth Forshee struct kref refcnt; 28801e9d11aSMaxim Patlasov int async; 28901e9d11aSMaxim Patlasov spinlock_t lock; 29001e9d11aSMaxim Patlasov unsigned reqs; 29101e9d11aSMaxim Patlasov ssize_t bytes; 29201e9d11aSMaxim Patlasov size_t size; 29301e9d11aSMaxim Patlasov __u64 offset; 29401e9d11aSMaxim Patlasov bool write; 29561c12b49SAshish Samant bool should_dirty; 29601e9d11aSMaxim Patlasov int err; 29701e9d11aSMaxim Patlasov struct kiocb *iocb; 2989d5722b7SChristoph Hellwig struct completion *done; 2997879c4e5SAshish Sangwan bool blocking; 30001e9d11aSMaxim Patlasov }; 30101e9d11aSMaxim Patlasov 302e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 303744742d6SSeth Forshee { \ 3041e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 305744742d6SSeth Forshee .async = 0, \ 306e1c0eecbSMiklos Szeredi .iocb = i, \ 307744742d6SSeth Forshee } 308744742d6SSeth Forshee 309334f485dSMiklos Szeredi /** 310825d6d33SMiklos Szeredi * Request flags 311825d6d33SMiklos Szeredi * 312825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 313825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 314825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 315825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 316825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 317825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 318825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 31933e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 32033e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 32133e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 32277cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 3233e8cb8b2SMiklos Szeredi * FR_ASYNC: request is asynchronous 324825d6d33SMiklos Szeredi */ 325825d6d33SMiklos Szeredi enum fuse_req_flag { 326825d6d33SMiklos Szeredi FR_ISREPLY, 327825d6d33SMiklos Szeredi FR_FORCE, 328825d6d33SMiklos Szeredi FR_BACKGROUND, 329825d6d33SMiklos Szeredi FR_WAITING, 330825d6d33SMiklos Szeredi FR_ABORTED, 331825d6d33SMiklos Szeredi FR_INTERRUPTED, 332825d6d33SMiklos Szeredi FR_LOCKED, 33333e14b4dSMiklos Szeredi FR_PENDING, 33433e14b4dSMiklos Szeredi FR_SENT, 33533e14b4dSMiklos Szeredi FR_FINISHED, 33677cd9d48SMiklos Szeredi FR_PRIVATE, 3373e8cb8b2SMiklos Szeredi FR_ASYNC, 338825d6d33SMiklos Szeredi }; 339825d6d33SMiklos Szeredi 340825d6d33SMiklos Szeredi /** 341334f485dSMiklos Szeredi * A request to the client 342dc00809aSMiklos Szeredi * 343dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 344dc00809aSMiklos Szeredi * - FR_ABORTED 345dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 346334f485dSMiklos Szeredi */ 347334f485dSMiklos Szeredi struct fuse_req { 348ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 349ce1d5a49SMiklos Szeredi fuse_conn */ 350334f485dSMiklos Szeredi struct list_head list; 351334f485dSMiklos Szeredi 352a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 353a4d27e75SMiklos Szeredi struct list_head intr_entry; 354a4d27e75SMiklos Szeredi 35512597287SMiklos Szeredi /* Input/output arguments */ 35612597287SMiklos Szeredi struct fuse_args *args; 35712597287SMiklos Szeredi 358334f485dSMiklos Szeredi /** refcount */ 359ec99f6d3SElena Reshetova refcount_t count; 360334f485dSMiklos Szeredi 361825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 362825d6d33SMiklos Szeredi unsigned long flags; 3639bc5dddaSMiklos Szeredi 364d4993774SMiklos Szeredi /* The request input header */ 365d4993774SMiklos Szeredi struct { 366d4993774SMiklos Szeredi struct fuse_in_header h; 367d4993774SMiklos Szeredi } in; 368334f485dSMiklos Szeredi 369d4993774SMiklos Szeredi /* The request output header */ 370d4993774SMiklos Szeredi struct { 371d4993774SMiklos Szeredi struct fuse_out_header h; 372d4993774SMiklos Szeredi } out; 373334f485dSMiklos Szeredi 374334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 375334f485dSMiklos Szeredi wait_queue_head_t waitq; 376334f485dSMiklos Szeredi 377a62a8ef9SStefan Hajnoczi #if IS_ENABLED(CONFIG_VIRTIO_FS) 378a62a8ef9SStefan Hajnoczi /** virtio-fs's physically contiguous buffer for in and out args */ 379a62a8ef9SStefan Hajnoczi void *argbuf; 380a62a8ef9SStefan Hajnoczi #endif 38124754db2SMax Reitz 382fcee216bSMax Reitz /** fuse_mount this request belongs to */ 383fcee216bSMax Reitz struct fuse_mount *fm; 384334f485dSMiklos Szeredi }; 385334f485dSMiklos Szeredi 386ae3aad77SStefan Hajnoczi struct fuse_iqueue; 387ae3aad77SStefan Hajnoczi 388ae3aad77SStefan Hajnoczi /** 389ae3aad77SStefan Hajnoczi * Input queue callbacks 390ae3aad77SStefan Hajnoczi * 391ae3aad77SStefan Hajnoczi * Input queue signalling is device-specific. For example, the /dev/fuse file 392ae3aad77SStefan Hajnoczi * uses fiq->waitq and fasync to wake processes that are waiting on queue 393ae3aad77SStefan Hajnoczi * readiness. These callbacks allow other device types to respond to input 394ae3aad77SStefan Hajnoczi * queue activity. 395ae3aad77SStefan Hajnoczi */ 396ae3aad77SStefan Hajnoczi struct fuse_iqueue_ops { 397ae3aad77SStefan Hajnoczi /** 398ae3aad77SStefan Hajnoczi * Signal that a forget has been queued 399ae3aad77SStefan Hajnoczi */ 400ae3aad77SStefan Hajnoczi void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq) 401ae3aad77SStefan Hajnoczi __releases(fiq->lock); 402ae3aad77SStefan Hajnoczi 403ae3aad77SStefan Hajnoczi /** 404ae3aad77SStefan Hajnoczi * Signal that an INTERRUPT request has been queued 405ae3aad77SStefan Hajnoczi */ 406ae3aad77SStefan Hajnoczi void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq) 407ae3aad77SStefan Hajnoczi __releases(fiq->lock); 408ae3aad77SStefan Hajnoczi 409ae3aad77SStefan Hajnoczi /** 410ae3aad77SStefan Hajnoczi * Signal that a request has been queued 411ae3aad77SStefan Hajnoczi */ 412ae3aad77SStefan Hajnoczi void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq) 413ae3aad77SStefan Hajnoczi __releases(fiq->lock); 414a62a8ef9SStefan Hajnoczi 415a62a8ef9SStefan Hajnoczi /** 416a62a8ef9SStefan Hajnoczi * Clean up when fuse_iqueue is destroyed 417a62a8ef9SStefan Hajnoczi */ 418a62a8ef9SStefan Hajnoczi void (*release)(struct fuse_iqueue *fiq); 419ae3aad77SStefan Hajnoczi }; 420ae3aad77SStefan Hajnoczi 421ae3aad77SStefan Hajnoczi /** /dev/fuse input queue operations */ 422ae3aad77SStefan Hajnoczi extern const struct fuse_iqueue_ops fuse_dev_fiq_ops; 423ae3aad77SStefan Hajnoczi 424f88996a9SMiklos Szeredi struct fuse_iqueue { 425e16714d8SMiklos Szeredi /** Connection established */ 426e16714d8SMiklos Szeredi unsigned connected; 427e16714d8SMiklos Szeredi 42876e43c8cSEric Biggers /** Lock protecting accesses to members of this structure */ 42976e43c8cSEric Biggers spinlock_t lock; 43076e43c8cSEric Biggers 431f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 432f88996a9SMiklos Szeredi wait_queue_head_t waitq; 433f88996a9SMiklos Szeredi 434f88996a9SMiklos Szeredi /** The next unique request id */ 435f88996a9SMiklos Szeredi u64 reqctr; 436f88996a9SMiklos Szeredi 437f88996a9SMiklos Szeredi /** The list of pending requests */ 438f88996a9SMiklos Szeredi struct list_head pending; 439f88996a9SMiklos Szeredi 440f88996a9SMiklos Szeredi /** Pending interrupts */ 441f88996a9SMiklos Szeredi struct list_head interrupts; 442f88996a9SMiklos Szeredi 443f88996a9SMiklos Szeredi /** Queue of pending forgets */ 444f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 445f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 446f88996a9SMiklos Szeredi 447f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 448f88996a9SMiklos Szeredi int forget_batch; 449f88996a9SMiklos Szeredi 450f88996a9SMiklos Szeredi /** O_ASYNC requests */ 451f88996a9SMiklos Szeredi struct fasync_struct *fasync; 452ae3aad77SStefan Hajnoczi 453ae3aad77SStefan Hajnoczi /** Device-specific callbacks */ 454ae3aad77SStefan Hajnoczi const struct fuse_iqueue_ops *ops; 455ae3aad77SStefan Hajnoczi 456ae3aad77SStefan Hajnoczi /** Device-specific state */ 457ae3aad77SStefan Hajnoczi void *priv; 458f88996a9SMiklos Szeredi }; 459f88996a9SMiklos Szeredi 460be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 461be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 462be2ff42cSKirill Tkhai 4633a2b5b9cSMiklos Szeredi struct fuse_pqueue { 464e96edd94SMiklos Szeredi /** Connection established */ 465e96edd94SMiklos Szeredi unsigned connected; 466e96edd94SMiklos Szeredi 46745a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 46845a91cb1SMiklos Szeredi spinlock_t lock; 46945a91cb1SMiklos Szeredi 470be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 471be2ff42cSKirill Tkhai struct list_head *processing; 4723a2b5b9cSMiklos Szeredi 4733a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4743a2b5b9cSMiklos Szeredi struct list_head io; 4753a2b5b9cSMiklos Szeredi }; 4763a2b5b9cSMiklos Szeredi 477d8a5ba45SMiklos Szeredi /** 478cc080e9eSMiklos Szeredi * Fuse device instance 479cc080e9eSMiklos Szeredi */ 480cc080e9eSMiklos Szeredi struct fuse_dev { 481cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 482cc080e9eSMiklos Szeredi struct fuse_conn *fc; 483cc080e9eSMiklos Szeredi 484c3696046SMiklos Szeredi /** Processing queue */ 485c3696046SMiklos Szeredi struct fuse_pqueue pq; 486c3696046SMiklos Szeredi 487cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 488cc080e9eSMiklos Szeredi struct list_head entry; 489cc080e9eSMiklos Szeredi }; 490cc080e9eSMiklos Szeredi 491780b1b95SJeffle Xu enum fuse_dax_mode { 492780b1b95SJeffle Xu FUSE_DAX_INODE_DEFAULT, /* default */ 493780b1b95SJeffle Xu FUSE_DAX_ALWAYS, /* "-o dax=always" */ 494780b1b95SJeffle Xu FUSE_DAX_NEVER, /* "-o dax=never" */ 495780b1b95SJeffle Xu FUSE_DAX_INODE_USER, /* "-o dax=inode" */ 496780b1b95SJeffle Xu }; 497780b1b95SJeffle Xu 498780b1b95SJeffle Xu static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode) 499780b1b95SJeffle Xu { 500780b1b95SJeffle Xu return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER; 501780b1b95SJeffle Xu } 502780b1b95SJeffle Xu 5030cc2656cSStefan Hajnoczi struct fuse_fs_context { 5040cc2656cSStefan Hajnoczi int fd; 50562dd1fc8SMiklos Szeredi struct file *file; 5060cc2656cSStefan Hajnoczi unsigned int rootmode; 5070cc2656cSStefan Hajnoczi kuid_t user_id; 5080cc2656cSStefan Hajnoczi kgid_t group_id; 5090cc2656cSStefan Hajnoczi bool is_bdev:1; 5100cc2656cSStefan Hajnoczi bool fd_present:1; 5110cc2656cSStefan Hajnoczi bool rootmode_present:1; 5120cc2656cSStefan Hajnoczi bool user_id_present:1; 5130cc2656cSStefan Hajnoczi bool group_id_present:1; 5140cc2656cSStefan Hajnoczi bool default_permissions:1; 5150cc2656cSStefan Hajnoczi bool allow_other:1; 516783863d6SMiklos Szeredi bool destroy:1; 51715c8e72eSVivek Goyal bool no_control:1; 51815c8e72eSVivek Goyal bool no_force_umount:1; 519f4fd4ae3SVivek Goyal bool legacy_opts_show:1; 520780b1b95SJeffle Xu enum fuse_dax_mode dax_mode; 5210cc2656cSStefan Hajnoczi unsigned int max_read; 5220cc2656cSStefan Hajnoczi unsigned int blksize; 5230cc2656cSStefan Hajnoczi const char *subtype; 5240cc2656cSStefan Hajnoczi 5251dd53957SVivek Goyal /* DAX device, may be NULL */ 5261dd53957SVivek Goyal struct dax_device *dax_dev; 5271dd53957SVivek Goyal 5280cc2656cSStefan Hajnoczi /* fuse_dev pointer to fill in, should contain NULL on entry */ 5290cc2656cSStefan Hajnoczi void **fudptr; 5300cc2656cSStefan Hajnoczi }; 5310cc2656cSStefan Hajnoczi 532660585b5SMiklos Szeredi struct fuse_sync_bucket { 533660585b5SMiklos Szeredi /* count is a possible scalability bottleneck */ 534660585b5SMiklos Szeredi atomic_t count; 535660585b5SMiklos Szeredi wait_queue_head_t waitq; 536660585b5SMiklos Szeredi struct rcu_head rcu; 537660585b5SMiklos Szeredi }; 538660585b5SMiklos Szeredi 539cc080e9eSMiklos Szeredi /** 540d8a5ba45SMiklos Szeredi * A Fuse connection. 541d8a5ba45SMiklos Szeredi * 542fcee216bSMax Reitz * This structure is created, when the root filesystem is mounted, and 543fcee216bSMax Reitz * is destroyed, when the client device is closed and the last 544fcee216bSMax Reitz * fuse_mount is destroyed. 545d8a5ba45SMiklos Szeredi */ 546d8a5ba45SMiklos Szeredi struct fuse_conn { 547d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 548d7133114SMiklos Szeredi spinlock_t lock; 549d7133114SMiklos Szeredi 550bafa9654SMiklos Szeredi /** Refcount */ 551095fc40aSElena Reshetova refcount_t count; 552bafa9654SMiklos Szeredi 553c3696046SMiklos Szeredi /** Number of fuse_dev's */ 554c3696046SMiklos Szeredi atomic_t dev_count; 555c3696046SMiklos Szeredi 556dd3e2c55SAl Viro struct rcu_head rcu; 557dd3e2c55SAl Viro 558d8a5ba45SMiklos Szeredi /** The user id for this mount */ 559499dcf20SEric W. Biederman kuid_t user_id; 560d8a5ba45SMiklos Szeredi 56187729a55SMiklos Szeredi /** The group id for this mount */ 562499dcf20SEric W. Biederman kgid_t group_id; 56387729a55SMiklos Szeredi 5640b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 5650b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 5660b6e9ea0SSeth Forshee 5678cb08329SEric W. Biederman /** The user namespace for this mount */ 5688cb08329SEric W. Biederman struct user_namespace *user_ns; 5698cb08329SEric W. Biederman 570db50b96cSMiklos Szeredi /** Maximum read size */ 571db50b96cSMiklos Szeredi unsigned max_read; 572db50b96cSMiklos Szeredi 573413ef8cbSMiklos Szeredi /** Maximum write size */ 574413ef8cbSMiklos Szeredi unsigned max_write; 575413ef8cbSMiklos Szeredi 5764b91459aSConnor Kuehl /** Maximum number of pages that can be used in a single request */ 5775da784ccSConstantine Shulyupin unsigned int max_pages; 5785da784ccSConstantine Shulyupin 579a7f0d7aaSConnor Kuehl /** Constrain ->max_pages to this value during feature negotiation */ 580a7f0d7aaSConnor Kuehl unsigned int max_pages_limit; 581a7f0d7aaSConnor Kuehl 582f88996a9SMiklos Szeredi /** Input queue */ 583f88996a9SMiklos Szeredi struct fuse_iqueue iq; 584334f485dSMiklos Szeredi 585acf99433STejun Heo /** The next unique kernel file handle */ 58675126f55SMiklos Szeredi atomic64_t khctr; 587acf99433STejun Heo 58895668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 58995668a69STejun Heo struct rb_root polled_files; 59095668a69STejun Heo 5917a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 5927a6d3c8bSCsaba Henk unsigned max_background; 5937a6d3c8bSCsaba Henk 5947a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 5957a6d3c8bSCsaba Henk unsigned congestion_threshold; 5967a6d3c8bSCsaba Henk 59708a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 59808a53cdcSMiklos Szeredi unsigned num_background; 59908a53cdcSMiklos Szeredi 600d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 601d12def1bSMiklos Szeredi unsigned active_background; 602d12def1bSMiklos Szeredi 603d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 604d12def1bSMiklos Szeredi struct list_head bg_queue; 605d12def1bSMiklos Szeredi 606ae2dffa3SKirill Tkhai /** Protects: max_background, congestion_threshold, num_background, 607ae2dffa3SKirill Tkhai * active_background, bg_queue, blocked */ 608ae2dffa3SKirill Tkhai spinlock_t bg_lock; 609ae2dffa3SKirill Tkhai 610796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 611796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 612796523fbSMaxim Patlasov int initialized; 613796523fbSMaxim Patlasov 61408a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 61508a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 61608a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 61708a53cdcSMiklos Szeredi int blocked; 61808a53cdcSMiklos Szeredi 61908a53cdcSMiklos Szeredi /** waitq for blocked connection */ 62008a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 62108a53cdcSMiklos Szeredi 62269a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 62369a53bf2SMiklos Szeredi abort and device release */ 624095da6cbSMiklos Szeredi unsigned connected; 6251e9a4ed9SMiklos Szeredi 6263b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 6273b7008b2SSzymon Lukasz bool aborted; 6283b7008b2SSzymon Lukasz 629095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 630095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 631095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 632334f485dSMiklos Szeredi unsigned conn_error:1; 633334f485dSMiklos Szeredi 6340ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 6350ec7ca41SMiklos Szeredi unsigned conn_init:1; 6360ec7ca41SMiklos Szeredi 637704528d8SMatthew Wilcox (Oracle) /** Do readahead asynchronously? Only set in INIT */ 6389cd68455SMiklos Szeredi unsigned async_read:1; 6399cd68455SMiklos Szeredi 6403b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 6413b7008b2SSzymon Lukasz unsigned abort_err:1; 6423b7008b2SSzymon Lukasz 6436ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 6446ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 6456ff958edSMiklos Szeredi 64633670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 64733670fa2SMiklos Szeredi unsigned export_support:1; 64833670fa2SMiklos Szeredi 649d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 650d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 651d5cd66c5SPavel Emelyanov 6525c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 6535c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 6545c672ab3SMiklos Szeredi 6555e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 6565e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 6575e940c1dSMiklos Szeredi 6585571f1e6SDan Schatzberg /** cache READLINK responses in page cache */ 6595571f1e6SDan Schatzberg unsigned cache_symlinks:1; 6605571f1e6SDan Schatzberg 661f4fd4ae3SVivek Goyal /* show legacy mount options */ 662f4fd4ae3SVivek Goyal unsigned int legacy_opts_show:1; 663f4fd4ae3SVivek Goyal 664095da6cbSMiklos Szeredi /* 66563f9909fSVivek Goyal * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on 66663f9909fSVivek Goyal * write/trunc only if caller did not have CAP_FSETID. sgid is killed 66763f9909fSVivek Goyal * on write/truncate only if caller did not have CAP_FSETID as well as 66863f9909fSVivek Goyal * file has group execute permission. 66963f9909fSVivek Goyal */ 67063f9909fSVivek Goyal unsigned handle_killpriv_v2:1; 67163f9909fSVivek Goyal 67263f9909fSVivek Goyal /* 673095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 674095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 675095da6cbSMiklos Szeredi */ 676095da6cbSMiklos Szeredi 6777678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 6787678ac50SAndrew Gallagher unsigned no_open:1; 6797678ac50SAndrew Gallagher 680d9a9ea94SChad Austin /** Is opendir/releasedir not implemented by fs? */ 681d9a9ea94SChad Austin unsigned no_opendir:1; 682d9a9ea94SChad Austin 683b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 684b6aeadedSMiklos Szeredi unsigned no_fsync:1; 685b6aeadedSMiklos Szeredi 68682547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 68782547981SMiklos Szeredi unsigned no_fsyncdir:1; 68882547981SMiklos Szeredi 689b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 690b6aeadedSMiklos Szeredi unsigned no_flush:1; 691b6aeadedSMiklos Szeredi 69292a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 69392a8780eSMiklos Szeredi unsigned no_setxattr:1; 69492a8780eSMiklos Szeredi 69552a4c95fSVivek Goyal /** Does file server support extended setxattr */ 69652a4c95fSVivek Goyal unsigned setxattr_ext:1; 69752a4c95fSVivek Goyal 69892a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 69992a8780eSMiklos Szeredi unsigned no_getxattr:1; 70092a8780eSMiklos Szeredi 70192a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 70292a8780eSMiklos Szeredi unsigned no_listxattr:1; 70392a8780eSMiklos Szeredi 70492a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 70592a8780eSMiklos Szeredi unsigned no_removexattr:1; 70692a8780eSMiklos Szeredi 70737fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 70871421259SMiklos Szeredi unsigned no_lock:1; 70971421259SMiklos Szeredi 71031d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 71131d40d74SMiklos Szeredi unsigned no_access:1; 71231d40d74SMiklos Szeredi 713fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 714fd72faacSMiklos Szeredi unsigned no_create:1; 715fd72faacSMiklos Szeredi 716a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 717a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 718a4d27e75SMiklos Szeredi 719b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 720b2d2272fSMiklos Szeredi unsigned no_bmap:1; 721b2d2272fSMiklos Szeredi 72295668a69STejun Heo /** Is poll not implemented by fs? */ 72395668a69STejun Heo unsigned no_poll:1; 72495668a69STejun Heo 72578bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 72678bb6cb9SMiklos Szeredi unsigned big_writes:1; 72778bb6cb9SMiklos Szeredi 728e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 729e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 730e0a43ddcSMiklos Szeredi 73137fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 73237fb3a30SMiklos Szeredi unsigned no_flock:1; 73337fb3a30SMiklos Szeredi 734519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 735519c6040SMiklos Szeredi unsigned no_fallocate:1; 736519c6040SMiklos Szeredi 7371560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 7381560c974SMiklos Szeredi unsigned no_rename2:1; 7391560c974SMiklos Szeredi 74072d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 74172d0d248SBrian Foster unsigned auto_inval_data:1; 74272d0d248SBrian Foster 743aa6ff555SBhaskar Chowdhury /** Filesystem is fully responsible for page cache invalidation. */ 744ad2ba64dSKirill Smelkov unsigned explicit_inval_data:1; 745ad2ba64dSKirill Smelkov 746634734b6SEric Wong /** Does the filesystem support readdirplus? */ 7470b05b183SAnand V. Avati unsigned do_readdirplus:1; 7480b05b183SAnand V. Avati 749634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 750634734b6SEric Wong unsigned readdirplus_auto:1; 751634734b6SEric Wong 75260b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 75360b9df7aSMiklos Szeredi unsigned async_dio:1; 75460b9df7aSMiklos Szeredi 7550b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 7560b5da8dbSRavishankar N unsigned no_lseek:1; 7570b5da8dbSRavishankar N 75860bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 75960bcc88aSSeth Forshee unsigned posix_acl:1; 76060bcc88aSSeth Forshee 76129433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 76229433a29SMiklos Szeredi unsigned default_permissions:1; 76329433a29SMiklos Szeredi 76429433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 76529433a29SMiklos Szeredi unsigned allow_other:1; 76629433a29SMiklos Szeredi 76788bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 76888bc7d50SNiels de Vos unsigned no_copy_file_range:1; 76988bc7d50SNiels de Vos 7701ccd1ea2SMiklos Szeredi /* Send DESTROY request */ 7711ccd1ea2SMiklos Szeredi unsigned int destroy:1; 7721ccd1ea2SMiklos Szeredi 7738fab0106SMiklos Szeredi /* Delete dentries that have gone stale */ 7748fab0106SMiklos Szeredi unsigned int delete_stale:1; 7758fab0106SMiklos Szeredi 77615c8e72eSVivek Goyal /** Do not create entry in fusectl fs */ 77715c8e72eSVivek Goyal unsigned int no_control:1; 77815c8e72eSVivek Goyal 77915c8e72eSVivek Goyal /** Do not allow MNT_FORCE umount */ 78015c8e72eSVivek Goyal unsigned int no_force_umount:1; 78115c8e72eSVivek Goyal 782bf109c64SMax Reitz /* Auto-mount submounts announced by the server */ 783bf109c64SMax Reitz unsigned int auto_submounts:1; 784bf109c64SMax Reitz 7852d82ab25SGreg Kurz /* Propagate syncfs() to server */ 7862d82ab25SGreg Kurz unsigned int sync_fs:1; 7872d82ab25SGreg Kurz 7883e2b6fdbSVivek Goyal /* Initialize security xattrs when creating a new inode */ 7893e2b6fdbSVivek Goyal unsigned int init_security:1; 7903e2b6fdbSVivek Goyal 7918ed7cb3fSMiklos Szeredi /* Add supplementary group info when creating a new inode */ 7928ed7cb3fSMiklos Szeredi unsigned int create_supp_group:1; 7938ed7cb3fSMiklos Szeredi 7942ee019faSJeffle Xu /* Does the filesystem support per inode DAX? */ 7952ee019faSJeffle Xu unsigned int inode_dax:1; 7962ee019faSJeffle Xu 7977d375390SMiklos Szeredi /* Is tmpfile not implemented by fs? */ 7987d375390SMiklos Szeredi unsigned int no_tmpfile:1; 7997d375390SMiklos Szeredi 800e78662e8SHao Xu /* relax restrictions in FOPEN_DIRECT_IO mode */ 801e78662e8SHao Xu unsigned int direct_io_relax:1; 802e78662e8SHao Xu 803d3045530SMiklos Szeredi /* Is statx not implemented by fs? */ 804d3045530SMiklos Szeredi unsigned int no_statx:1; 805d3045530SMiklos Szeredi 8060cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 8070cd5b885SMiklos Szeredi atomic_t num_waiting; 8080cd5b885SMiklos Szeredi 80945714d65SMiklos Szeredi /** Negotiated minor version */ 81045714d65SMiklos Szeredi unsigned minor; 81145714d65SMiklos Szeredi 812fcee216bSMax Reitz /** Entry on the fuse_mount_list */ 813bafa9654SMiklos Szeredi struct list_head entry; 814bafa9654SMiklos Szeredi 815fcee216bSMax Reitz /** Device ID from the root super block */ 816b6f2fcbcSMiklos Szeredi dev_t dev; 817bafa9654SMiklos Szeredi 818bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 819bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 820bafa9654SMiklos Szeredi 821bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 822bafa9654SMiklos Szeredi int ctl_ndents; 823385a17bfSJeff Dike 8249c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 8259c8ef561SMiklos Szeredi u32 scramble_key[4]; 8260ec7ca41SMiklos Szeredi 8271fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 8284510d86fSKirill Tkhai atomic64_t attr_version; 82943901aabSTejun Heo 83043901aabSTejun Heo /** Called on final put */ 83143901aabSTejun Heo void (*release)(struct fuse_conn *); 8323b463ae0SJohn Muir 833fcee216bSMax Reitz /** 834fcee216bSMax Reitz * Read/write semaphore to hold when accessing the sb of any 835fcee216bSMax Reitz * fuse_mount belonging to this connection 836fcee216bSMax Reitz */ 8373b463ae0SJohn Muir struct rw_semaphore killsb; 838cc080e9eSMiklos Szeredi 839cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 840cc080e9eSMiklos Szeredi struct list_head devices; 8411dd53957SVivek Goyal 8421dd53957SVivek Goyal #ifdef CONFIG_FUSE_DAX 843780b1b95SJeffle Xu /* Dax mode */ 844780b1b95SJeffle Xu enum fuse_dax_mode dax_mode; 845780b1b95SJeffle Xu 8461dd53957SVivek Goyal /* Dax specific conn data, non-NULL if DAX is enabled */ 8471dd53957SVivek Goyal struct fuse_conn_dax *dax; 8481dd53957SVivek Goyal #endif 849fcee216bSMax Reitz 850fcee216bSMax Reitz /** List of filesystems using this connection */ 851fcee216bSMax Reitz struct list_head mounts; 852660585b5SMiklos Szeredi 853660585b5SMiklos Szeredi /* New writepages go into this bucket */ 854660585b5SMiklos Szeredi struct fuse_sync_bucket __rcu *curr_bucket; 855d8a5ba45SMiklos Szeredi }; 856d8a5ba45SMiklos Szeredi 857fcee216bSMax Reitz /* 858fcee216bSMax Reitz * Represents a mounted filesystem, potentially a submount. 859fcee216bSMax Reitz * 860fcee216bSMax Reitz * This object allows sharing a fuse_conn between separate mounts to 861fcee216bSMax Reitz * allow submounts with dedicated superblocks and thus separate device 862fcee216bSMax Reitz * IDs. 863fcee216bSMax Reitz */ 864fcee216bSMax Reitz struct fuse_mount { 865fcee216bSMax Reitz /* Underlying (potentially shared) connection to the FUSE server */ 866fcee216bSMax Reitz struct fuse_conn *fc; 867fcee216bSMax Reitz 868fcee216bSMax Reitz /* 869fcee216bSMax Reitz * Super block for this connection (fc->killsb must be held when 870fcee216bSMax Reitz * accessing this). 871fcee216bSMax Reitz */ 872fcee216bSMax Reitz struct super_block *sb; 873fcee216bSMax Reitz 874fcee216bSMax Reitz /* Entry on fc->mounts */ 875fcee216bSMax Reitz struct list_head fc_entry; 876fcee216bSMax Reitz }; 877fcee216bSMax Reitz 878fcee216bSMax Reitz static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb) 879d8a5ba45SMiklos Szeredi { 8806383bdaaSMiklos Szeredi return sb->s_fs_info; 881d8a5ba45SMiklos Szeredi } 882d8a5ba45SMiklos Szeredi 883fcee216bSMax Reitz static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 884fcee216bSMax Reitz { 885bd3bf1e8SMiklos Szeredi return get_fuse_mount_super(sb)->fc; 886fcee216bSMax Reitz } 887fcee216bSMax Reitz 888fcee216bSMax Reitz static inline struct fuse_mount *get_fuse_mount(struct inode *inode) 889fcee216bSMax Reitz { 890fcee216bSMax Reitz return get_fuse_mount_super(inode->i_sb); 891fcee216bSMax Reitz } 892fcee216bSMax Reitz 893d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 894d8a5ba45SMiklos Szeredi { 895bd3bf1e8SMiklos Szeredi return get_fuse_mount_super(inode->i_sb)->fc; 896d8a5ba45SMiklos Szeredi } 897d8a5ba45SMiklos Szeredi 898d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 899d8a5ba45SMiklos Szeredi { 900d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 901d8a5ba45SMiklos Szeredi } 902d8a5ba45SMiklos Szeredi 903d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 904d8a5ba45SMiklos Szeredi { 905d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 906d8a5ba45SMiklos Szeredi } 907d8a5ba45SMiklos Szeredi 908d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 909d123d8e1SMiklos Szeredi { 910d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 911d123d8e1SMiklos Szeredi } 912d123d8e1SMiklos Szeredi 9134510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 9144510d86fSKirill Tkhai { 9154510d86fSKirill Tkhai return atomic64_read(&fc->attr_version); 9164510d86fSKirill Tkhai } 9174510d86fSKirill Tkhai 91815db1683SAmir Goldstein static inline bool fuse_stale_inode(const struct inode *inode, int generation, 91915db1683SAmir Goldstein struct fuse_attr *attr) 92015db1683SAmir Goldstein { 92115db1683SAmir Goldstein return inode->i_generation != generation || 92215db1683SAmir Goldstein inode_wrong_type(inode, attr->mode); 92315db1683SAmir Goldstein } 92415db1683SAmir Goldstein 9255d069dbeSMiklos Szeredi static inline void fuse_make_bad(struct inode *inode) 9265d069dbeSMiklos Szeredi { 927775c5033SAmir Goldstein remove_inode_hash(inode); 9285d069dbeSMiklos Szeredi set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state); 9295d069dbeSMiklos Szeredi } 9305d069dbeSMiklos Szeredi 9315d069dbeSMiklos Szeredi static inline bool fuse_is_bad(struct inode *inode) 9325d069dbeSMiklos Szeredi { 9335d069dbeSMiklos Szeredi return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state)); 9345d069dbeSMiklos Szeredi } 9355d069dbeSMiklos Szeredi 9369ac29fd3SMiklos Szeredi static inline struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags, 9379ac29fd3SMiklos Szeredi struct fuse_page_desc **desc) 9389ac29fd3SMiklos Szeredi { 9399ac29fd3SMiklos Szeredi struct page **pages; 9409ac29fd3SMiklos Szeredi 9419ac29fd3SMiklos Szeredi pages = kzalloc(npages * (sizeof(struct page *) + 9429ac29fd3SMiklos Szeredi sizeof(struct fuse_page_desc)), flags); 9439ac29fd3SMiklos Szeredi *desc = (void *) (pages + npages); 9449ac29fd3SMiklos Szeredi 9459ac29fd3SMiklos Szeredi return pages; 9469ac29fd3SMiklos Szeredi } 9479ac29fd3SMiklos Szeredi 9489ac29fd3SMiklos Szeredi static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs, 9499ac29fd3SMiklos Szeredi unsigned int index, 9509ac29fd3SMiklos Szeredi unsigned int nr_pages) 9519ac29fd3SMiklos Szeredi { 9529ac29fd3SMiklos Szeredi int i; 9539ac29fd3SMiklos Szeredi 9549ac29fd3SMiklos Szeredi for (i = index; i < index + nr_pages; i++) 9559ac29fd3SMiklos Szeredi descs[i].length = PAGE_SIZE - descs[i].offset; 9569ac29fd3SMiklos Szeredi } 9579ac29fd3SMiklos Szeredi 958660585b5SMiklos Szeredi static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket) 959660585b5SMiklos Szeredi { 960660585b5SMiklos Szeredi /* Need RCU protection to prevent use after free after the decrement */ 961660585b5SMiklos Szeredi rcu_read_lock(); 962660585b5SMiklos Szeredi if (atomic_dec_and_test(&bucket->count)) 963660585b5SMiklos Szeredi wake_up(&bucket->waitq); 964660585b5SMiklos Szeredi rcu_read_unlock(); 965660585b5SMiklos Szeredi } 966660585b5SMiklos Szeredi 967334f485dSMiklos Szeredi /** Device operations */ 9684b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 969334f485dSMiklos Szeredi 9704269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 9710ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 972dbd561d2SMiklos Szeredi 973d8a5ba45SMiklos Szeredi /** 974e5e5558eSMiklos Szeredi * Get a filled in inode 975e5e5558eSMiklos Szeredi */ 976b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 9771fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 9781fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 979e5e5558eSMiklos Szeredi 98013983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 98133670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 98233670fa2SMiklos Szeredi 983e5e5558eSMiklos Szeredi /** 984e5e5558eSMiklos Szeredi * Send FORGET command 985e5e5558eSMiklos Szeredi */ 98607e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 987b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 988e5e5558eSMiklos Szeredi 98907e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 99007e77dcaSMiklos Szeredi 9914388c5aaSVivek Goyal struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq, 9924388c5aaSVivek Goyal unsigned int max, 9934388c5aaSVivek Goyal unsigned int *countp); 9944388c5aaSVivek Goyal 99543f5098eSMiklos Szeredi /* 996361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 99704730fefSMiklos Szeredi */ 99843f5098eSMiklos Szeredi struct fuse_io_args { 99943f5098eSMiklos Szeredi union { 100043f5098eSMiklos Szeredi struct { 100143f5098eSMiklos Szeredi struct fuse_read_in in; 100243f5098eSMiklos Szeredi u64 attr_ver; 100343f5098eSMiklos Szeredi } read; 100443f5098eSMiklos Szeredi struct { 100543f5098eSMiklos Szeredi struct fuse_write_in in; 100643f5098eSMiklos Szeredi struct fuse_write_out out; 10074f06dd92SVivek Goyal bool page_locked; 100843f5098eSMiklos Szeredi } write; 100943f5098eSMiklos Szeredi }; 101043f5098eSMiklos Szeredi struct fuse_args_pages ap; 101143f5098eSMiklos Szeredi struct fuse_io_priv *io; 101243f5098eSMiklos Szeredi struct fuse_file *ff; 101343f5098eSMiklos Szeredi }; 101443f5098eSMiklos Szeredi 101543f5098eSMiklos Szeredi void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos, 101643f5098eSMiklos Szeredi size_t count, int opcode); 101743f5098eSMiklos Szeredi 101804730fefSMiklos Szeredi 101904730fefSMiklos Szeredi /** 102004730fefSMiklos Szeredi * Send OPEN or OPENDIR request 102104730fefSMiklos Szeredi */ 102291fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 102304730fefSMiklos Szeredi 1024fcee216bSMax Reitz struct fuse_file *fuse_file_alloc(struct fuse_mount *fm); 1025fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 1026c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 1027fd72faacSMiklos Szeredi 102854d601cbSMiklos Szeredi void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, 102954d601cbSMiklos Szeredi unsigned int flags); 1030c756e0a4SMiklos Szeredi 103104730fefSMiklos Szeredi /** 103204730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 103304730fefSMiklos Szeredi */ 10342e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir); 103504730fefSMiklos Szeredi 103604730fefSMiklos Szeredi /** 103782547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 103882547981SMiklos Szeredi */ 103902c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 1040a9c2d1e8SMiklos Szeredi int datasync, int opcode); 104182547981SMiklos Szeredi 104282547981SMiklos Szeredi /** 104395668a69STejun Heo * Notify poll wakeup 104495668a69STejun Heo */ 104595668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 104695668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 104795668a69STejun Heo 104895668a69STejun Heo /** 10491779381dSMiklos Szeredi * Initialize file operations on a regular file 1050b6aeadedSMiklos Szeredi */ 105193a497b9SJeffle Xu void fuse_init_file_inode(struct inode *inode, unsigned int flags); 1052b6aeadedSMiklos Szeredi 1053b6aeadedSMiklos Szeredi /** 10541779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 1055e5e5558eSMiklos Szeredi */ 1056e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 1057e5e5558eSMiklos Szeredi 1058e5e5558eSMiklos Szeredi /** 10591779381dSMiklos Szeredi * Initialize inode and file operations on a directory 1060e5e5558eSMiklos Szeredi */ 1061e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 1062e5e5558eSMiklos Szeredi 1063e5e5558eSMiklos Szeredi /** 10641779381dSMiklos Szeredi * Initialize inode operations on a symlink 1065e5e5558eSMiklos Szeredi */ 1066e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 1067e5e5558eSMiklos Szeredi 1068e5e5558eSMiklos Szeredi /** 1069e5e5558eSMiklos Szeredi * Change attributes of an inode 1070e5e5558eSMiklos Szeredi */ 10711fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 1072*972f4c46SMiklos Szeredi struct fuse_statx *sx, 10731fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 1074e5e5558eSMiklos Szeredi 10753be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 1076*972f4c46SMiklos Szeredi struct fuse_statx *sx, 10774b52f059SMiklos Szeredi u64 attr_valid, u32 cache_mask); 10784b52f059SMiklos Szeredi 10794b52f059SMiklos Szeredi u32 fuse_get_cache_mask(struct inode *inode); 10803be5a52bSMiklos Szeredi 1081e5e5558eSMiklos Szeredi /** 1082334f485dSMiklos Szeredi * Initialize the client device 1083334f485dSMiklos Szeredi */ 1084334f485dSMiklos Szeredi int fuse_dev_init(void); 1085334f485dSMiklos Szeredi 1086334f485dSMiklos Szeredi /** 1087334f485dSMiklos Szeredi * Cleanup the client device 1088334f485dSMiklos Szeredi */ 1089334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 1090334f485dSMiklos Szeredi 1091bafa9654SMiklos Szeredi int fuse_ctl_init(void); 10927736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 1093bafa9654SMiklos Szeredi 1094334f485dSMiklos Szeredi /** 10957078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 10967078187aSMiklos Szeredi */ 1097fcee216bSMax Reitz ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args); 1098fcee216bSMax Reitz int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, 109912597287SMiklos Szeredi gfp_t gfp_flags); 11007078187aSMiklos Szeredi 110104ec5af0SStefan Hajnoczi /** 110204ec5af0SStefan Hajnoczi * End a finished request 110304ec5af0SStefan Hajnoczi */ 11048f622e94SMax Reitz void fuse_request_end(struct fuse_req *req); 110504ec5af0SStefan Hajnoczi 11065a5fb1eaSMiklos Szeredi /* Abort all requests */ 1107eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 1108b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 110969a53bf2SMiklos Szeredi 11101e9a4ed9SMiklos Szeredi /** 1111e5e5558eSMiklos Szeredi * Invalidate inode attributes 1112e5e5558eSMiklos Szeredi */ 1113fa5eee57SMiklos Szeredi 1114fa5eee57SMiklos Szeredi /* Attributes possibly changed on data modification */ 1115fa5eee57SMiklos Szeredi #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS) 1116fa5eee57SMiklos Szeredi 1117fa5eee57SMiklos Szeredi /* Attributes possibly changed on data and/or size modification */ 1118fa5eee57SMiklos Szeredi #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE) 1119fa5eee57SMiklos Szeredi 1120e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 1121fa5eee57SMiklos Szeredi void fuse_invalidate_attr_mask(struct inode *inode, u32 mask); 1122bafa9654SMiklos Szeredi 1123dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 1124dbd561d2SMiklos Szeredi 1125451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 1126451418fcSAndrew Gallagher 11279dc10a54SMiklos Szeredi u64 fuse_time_to_jiffies(u64 sec, u32 nsec); 11289dc10a54SMiklos Szeredi #define ATTR_TIMEOUT(o) \ 11299dc10a54SMiklos Szeredi fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec) 11309dc10a54SMiklos Szeredi 1131d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 1132d123d8e1SMiklos Szeredi 1133bafa9654SMiklos Szeredi /** 1134bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 1135bafa9654SMiklos Szeredi */ 1136bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 1137bafa9654SMiklos Szeredi 1138bafa9654SMiklos Szeredi /** 11390d179aa5STejun Heo * Initialize fuse_conn 11400d179aa5STejun Heo */ 1141fcee216bSMax Reitz void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, 1142fcee216bSMax Reitz struct user_namespace *user_ns, 1143ae3aad77SStefan Hajnoczi const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv); 11440d179aa5STejun Heo 11450d179aa5STejun Heo /** 1146bafa9654SMiklos Szeredi * Release reference to fuse_conn 1147bafa9654SMiklos Szeredi */ 1148bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 1149bafa9654SMiklos Szeredi 11500cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc); 11510cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc(void); 11520cd1eb9aSVivek Goyal void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc); 1153cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 1154fcee216bSMax Reitz void fuse_send_init(struct fuse_mount *fm); 1155cc080e9eSMiklos Szeredi 1156bafa9654SMiklos Szeredi /** 11570cc2656cSStefan Hajnoczi * Fill in superblock and initialize fuse connection 11580cc2656cSStefan Hajnoczi * @sb: partially-initialized superblock to fill in 11590cc2656cSStefan Hajnoczi * @ctx: mount context 11600cc2656cSStefan Hajnoczi */ 11610cc2656cSStefan Hajnoczi int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx); 11620cc2656cSStefan Hajnoczi 11631866d779SMax Reitz /* 1164fcee216bSMax Reitz * Remove the mount from the connection 1165783863d6SMiklos Szeredi * 1166fcee216bSMax Reitz * Returns whether this was the last mount 1167783863d6SMiklos Szeredi */ 1168fcee216bSMax Reitz bool fuse_mount_remove(struct fuse_mount *fm); 1169fcee216bSMax Reitz 1170fcee216bSMax Reitz /* 1171fe0a7bd8SGreg Kurz * Setup context ops for submounts 1172fe0a7bd8SGreg Kurz */ 1173fe0a7bd8SGreg Kurz int fuse_init_fs_context_submount(struct fs_context *fsc); 1174fe0a7bd8SGreg Kurz 1175fe0a7bd8SGreg Kurz /* 1176fcee216bSMax Reitz * Shut down the connection (possibly sending DESTROY request). 1177fcee216bSMax Reitz */ 1178fcee216bSMax Reitz void fuse_conn_destroy(struct fuse_mount *fm); 1179783863d6SMiklos Szeredi 1180a27c061aSMiklos Szeredi /* Drop the connection and free the fuse mount */ 1181a27c061aSMiklos Szeredi void fuse_mount_destroy(struct fuse_mount *fm); 1182a27c061aSMiklos Szeredi 1183783863d6SMiklos Szeredi /** 1184bafa9654SMiklos Szeredi * Add connection to control filesystem 1185bafa9654SMiklos Szeredi */ 1186bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 1187bafa9654SMiklos Szeredi 1188bafa9654SMiklos Szeredi /** 1189bafa9654SMiklos Szeredi * Remove connection from control filesystem 1190bafa9654SMiklos Szeredi */ 1191bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 1192a5bfffacSTimo Savola 1193a5bfffacSTimo Savola /** 1194a5bfffacSTimo Savola * Is file type valid? 1195a5bfffacSTimo Savola */ 1196a5bfffacSTimo Savola int fuse_valid_type(int m); 1197e57ac683SMiklos Szeredi 1198eb59bd17SMiklos Szeredi bool fuse_invalid_attr(struct fuse_attr *attr); 1199eb59bd17SMiklos Szeredi 1200e57ac683SMiklos Szeredi /** 1201c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 1202e57ac683SMiklos Szeredi */ 1203b1387777SDave Marchevsky bool fuse_allow_current_process(struct fuse_conn *fc); 1204f3332114SMiklos Szeredi 1205f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 1206bcb4be80SMiklos Szeredi 12075c791fe1SMiklos Szeredi void fuse_flush_time_update(struct inode *inode); 1208703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 1209703c7362SSeth Forshee 1210c6c745b8SMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask); 12113be5a52bSMiklos Szeredi 12123be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 12133be5a52bSMiklos Szeredi 12143be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 12153be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 12165c5c5e51SMiklos Szeredi 12173b463ae0SJohn Muir /** 1218fcee216bSMax Reitz * Scan all fuse_mounts belonging to fc to find the first where 1219fcee216bSMax Reitz * ilookup5() returns a result. Return that result and the 1220fcee216bSMax Reitz * respective fuse_mount in *fm (unless fm is NULL). 1221fcee216bSMax Reitz * 1222fcee216bSMax Reitz * The caller must hold fc->killsb. 1223fcee216bSMax Reitz */ 1224fcee216bSMax Reitz struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid, 1225fcee216bSMax Reitz struct fuse_mount **fm); 1226fcee216bSMax Reitz 1227fcee216bSMax Reitz /** 12283b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 12293b463ae0SJohn Muir */ 1230fcee216bSMax Reitz int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid, 12313b463ae0SJohn Muir loff_t offset, loff_t len); 12323b463ae0SJohn Muir 12333b463ae0SJohn Muir /** 12343b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 12353b463ae0SJohn Muir * the dentry matching parent/name. 1236451d0f59SJohn Muir * 1237451d0f59SJohn Muir * If the child_nodeid is non-zero and: 1238451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 1239451d0f59SJohn Muir * - is not a mount point 1240451d0f59SJohn Muir * - is a file or oan empty directory 1241451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 12423b463ae0SJohn Muir */ 1243fcee216bSMax Reitz int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid, 12444f8d3702SMiklos Szeredi u64 child_nodeid, struct qstr *name, u32 flags); 12453b463ae0SJohn Muir 1246fcee216bSMax Reitz int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file, 124708cbf542STejun Heo bool isdir); 1248ea8cd333SPavel Emelyanov 1249ea8cd333SPavel Emelyanov /** 1250ea8cd333SPavel Emelyanov * fuse_direct_io() flags 1251ea8cd333SPavel Emelyanov */ 1252ea8cd333SPavel Emelyanov 1253ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 1254ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 1255ea8cd333SPavel Emelyanov 1256ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1257ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 1258ea8cd333SPavel Emelyanov 1259d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1260d22a943fSAl Viro loff_t *ppos, int flags); 126108cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 126208cbf542STejun Heo unsigned int flags); 1263b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 1264b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 1265076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 126608cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 126708cbf542STejun Heo 1268d347739aSMiklos Szeredi bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written); 1269b0aa7606SMaxim Patlasov 1270ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 12711e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1272a1d75f25SMiklos Szeredi 127362490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1274efb9fa9eSMaxim Patlasov struct file *file); 1275efb9fa9eSMaxim Patlasov 12769759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 12779759bd51SMiklos Szeredi 127863576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 127963576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 12805c672ab3SMiklos Szeredi 128160bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 128252a4c95fSVivek Goyal size_t size, int flags, unsigned int extra_flags); 128360bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 128460bcc88aSSeth Forshee size_t size); 1285703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 128660bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 1287703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 128860bcc88aSSeth Forshee 128960bcc88aSSeth Forshee struct posix_acl; 1290facd6105SChristian Brauner struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu); 129105e6295fSLinus Torvalds struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap, 1292facd6105SChristian Brauner struct dentry *dentry, int type); 129305e6295fSLinus Torvalds int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry, 1294549c7297SChristian Brauner struct posix_acl *acl, int type); 1295d123d8e1SMiklos Szeredi 1296d123d8e1SMiklos Szeredi /* readdir.c */ 1297d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 1298d123d8e1SMiklos Szeredi 129914d46d7aSStefan Hajnoczi /** 130014d46d7aSStefan Hajnoczi * Return the number of bytes in an arguments list 130114d46d7aSStefan Hajnoczi */ 130214d46d7aSStefan Hajnoczi unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args); 130314d46d7aSStefan Hajnoczi 130479d96effSStefan Hajnoczi /** 130579d96effSStefan Hajnoczi * Get the next unique ID for a request 130679d96effSStefan Hajnoczi */ 130779d96effSStefan Hajnoczi u64 fuse_get_unique(struct fuse_iqueue *fiq); 1308783863d6SMiklos Szeredi void fuse_free_conn(struct fuse_conn *fc); 130979d96effSStefan Hajnoczi 13101dd53957SVivek Goyal /* dax.c */ 13111dd53957SVivek Goyal 1312c2d0ad00SVivek Goyal #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode)) 1313c2d0ad00SVivek Goyal 1314c2d0ad00SVivek Goyal ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to); 1315c2d0ad00SVivek Goyal ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from); 1316c2d0ad00SVivek Goyal int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma); 13176ae330caSVivek Goyal int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end); 1318780b1b95SJeffle Xu int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode, 1319780b1b95SJeffle Xu struct dax_device *dax_dev); 13201dd53957SVivek Goyal void fuse_dax_conn_free(struct fuse_conn *fc); 1321c2d0ad00SVivek Goyal bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi); 132293a497b9SJeffle Xu void fuse_dax_inode_init(struct inode *inode, unsigned int flags); 1323c2d0ad00SVivek Goyal void fuse_dax_inode_cleanup(struct inode *inode); 1324c3cb6f93SJeffle Xu void fuse_dax_dontcache(struct inode *inode, unsigned int flags); 1325fd1a1dc6SStefan Hajnoczi bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment); 13269a752d18SVivek Goyal void fuse_dax_cancel_work(struct fuse_conn *fc); 13271dd53957SVivek Goyal 13289ac29fd3SMiklos Szeredi /* ioctl.c */ 13299ac29fd3SMiklos Szeredi long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 13309ac29fd3SMiklos Szeredi long fuse_file_compat_ioctl(struct file *file, unsigned int cmd, 13319ac29fd3SMiklos Szeredi unsigned long arg); 133272227eacSMiklos Szeredi int fuse_fileattr_get(struct dentry *dentry, struct fileattr *fa); 13338782a9aeSChristian Brauner int fuse_fileattr_set(struct mnt_idmap *idmap, 133472227eacSMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 13359ac29fd3SMiklos Szeredi 1336b9d54c6fSMiklos Szeredi /* file.c */ 1337b9d54c6fSMiklos Szeredi 1338b9d54c6fSMiklos Szeredi struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, 1339b9d54c6fSMiklos Szeredi unsigned int open_flags, bool isdir); 1340b9d54c6fSMiklos Szeredi void fuse_file_release(struct inode *inode, struct fuse_file *ff, 1341b9d54c6fSMiklos Szeredi unsigned int open_flags, fl_owner_t id, bool isdir); 1342b9d54c6fSMiklos Szeredi 134329d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 1344