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 9145c72cd7SPavel Shilovsky /** 64 bit inode number */ 9245c72cd7SPavel Shilovsky u64 orig_ino; 9345c72cd7SPavel Shilovsky 941fb69e78SMiklos Szeredi /** Version of last attribute change */ 951fb69e78SMiklos Szeredi u64 attr_version; 9693a8c3cdSMiklos Szeredi 97ab2257e9SMiklos Szeredi union { 98ab2257e9SMiklos Szeredi /* Write related fields (regular file only) */ 99ab2257e9SMiklos Szeredi struct { 100f15ecfefSKirill Tkhai /* Files usable in writepage. Protected by fi->lock */ 10193a8c3cdSMiklos Szeredi struct list_head write_files; 1023be5a52bSMiklos Szeredi 103ab2257e9SMiklos Szeredi /* Writepages pending on truncate or fsync */ 1043be5a52bSMiklos Szeredi struct list_head queued_writes; 1053be5a52bSMiklos Szeredi 106ab2257e9SMiklos Szeredi /* Number of sent writes, a negative bias 107ab2257e9SMiklos Szeredi * (FUSE_NOWRITE) means more writes are blocked */ 1083be5a52bSMiklos Szeredi int writectr; 1093be5a52bSMiklos Szeredi 110ab2257e9SMiklos Szeredi /* Waitq for writepage completion */ 1113be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1123be5a52bSMiklos Szeredi 113ab2257e9SMiklos Szeredi /* List of writepage requestst (pending or sent) */ 1146b2fb799SMaxim Patlasov struct rb_root writepages; 115ab2257e9SMiklos Szeredi }; 1164582a4abSFeng Shuo 117ab2257e9SMiklos Szeredi /* readdir cache (directory only) */ 11869e34551SMiklos Szeredi struct { 11969e34551SMiklos Szeredi /* true if fully cached */ 12069e34551SMiklos Szeredi bool cached; 12169e34551SMiklos Szeredi 12269e34551SMiklos Szeredi /* size of cache */ 12369e34551SMiklos Szeredi loff_t size; 12469e34551SMiklos Szeredi 12569e34551SMiklos Szeredi /* position at end of cache (position of next entry) */ 12669e34551SMiklos Szeredi loff_t pos; 12769e34551SMiklos Szeredi 1283494927eSMiklos Szeredi /* version of the cache */ 1293494927eSMiklos Szeredi u64 version; 1303494927eSMiklos Szeredi 131ab2257e9SMiklos Szeredi /* modification time of directory when cache was 132ab2257e9SMiklos Szeredi * started */ 1337118883bSMiklos Szeredi struct timespec64 mtime; 1347118883bSMiklos Szeredi 135261aaba7SMiklos Szeredi /* iversion of directory when cache was started */ 136261aaba7SMiklos Szeredi u64 iversion; 137261aaba7SMiklos Szeredi 13869e34551SMiklos Szeredi /* protects above fields */ 13969e34551SMiklos Szeredi spinlock_t lock; 14069e34551SMiklos Szeredi } rdc; 141ab2257e9SMiklos Szeredi }; 14269e34551SMiklos Szeredi 1434582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1444582a4abSFeng Shuo unsigned long state; 1455c672ab3SMiklos Szeredi 1465c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1475c672ab3SMiklos Szeredi struct mutex mutex; 148f15ecfefSKirill Tkhai 149f15ecfefSKirill Tkhai /** Lock to protect write related fields */ 150f15ecfefSKirill Tkhai spinlock_t lock; 151c2d0ad00SVivek Goyal 152c2d0ad00SVivek Goyal #ifdef CONFIG_FUSE_DAX 153c2d0ad00SVivek Goyal /* 154c2d0ad00SVivek Goyal * Dax specific inode data 155c2d0ad00SVivek Goyal */ 156c2d0ad00SVivek Goyal struct fuse_inode_dax *dax; 157c2d0ad00SVivek Goyal #endif 1584582a4abSFeng Shuo }; 1594582a4abSFeng Shuo 1604582a4abSFeng Shuo /** FUSE inode state bits */ 1614582a4abSFeng Shuo enum { 1624582a4abSFeng Shuo /** Advise readdirplus */ 1634582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1646314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1656314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 16606a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 16706a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 1685d069dbeSMiklos Szeredi /* Bad inode */ 1695d069dbeSMiklos Szeredi FUSE_I_BAD, 170d8a5ba45SMiklos Szeredi }; 171d8a5ba45SMiklos Szeredi 172da5e4714SMiklos Szeredi struct fuse_conn; 173fcee216bSMax Reitz struct fuse_mount; 1744cb54866SMiklos Szeredi struct fuse_release_args; 175da5e4714SMiklos Szeredi 176b6aeadedSMiklos Szeredi /** FUSE specific file data */ 177b6aeadedSMiklos Szeredi struct fuse_file { 178da5e4714SMiklos Szeredi /** Fuse connection for this file */ 179fcee216bSMax Reitz struct fuse_mount *fm; 180da5e4714SMiklos Szeredi 1814cb54866SMiklos Szeredi /* Argument space reserved for release */ 1824cb54866SMiklos Szeredi struct fuse_release_args *release_args; 183b6aeadedSMiklos Szeredi 184acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 185acf99433STejun Heo u64 kh; 186acf99433STejun Heo 187b6aeadedSMiklos Szeredi /** File handle used by userspace */ 188b6aeadedSMiklos Szeredi u64 fh; 189c756e0a4SMiklos Szeredi 190da5e4714SMiklos Szeredi /** Node id of this file */ 191da5e4714SMiklos Szeredi u64 nodeid; 192da5e4714SMiklos Szeredi 193c756e0a4SMiklos Szeredi /** Refcount */ 1944e8c2eb5SElena Reshetova refcount_t count; 19593a8c3cdSMiklos Szeredi 196c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 197c7b7143cSMiklos Szeredi u32 open_flags; 198c7b7143cSMiklos Szeredi 19993a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 20093a8c3cdSMiklos Szeredi struct list_head write_entry; 20195668a69STejun Heo 2025d7bc7e8SMiklos Szeredi /* Readdir related */ 2035d7bc7e8SMiklos Szeredi struct { 2045d7bc7e8SMiklos Szeredi /* 2055d7bc7e8SMiklos Szeredi * Protects below fields against (crazy) parallel readdir on 2065d7bc7e8SMiklos Szeredi * same open file. Uncontended in the normal case. 2075d7bc7e8SMiklos Szeredi */ 2085d7bc7e8SMiklos Szeredi struct mutex lock; 2095d7bc7e8SMiklos Szeredi 2105d7bc7e8SMiklos Szeredi /* Dir stream position */ 2115d7bc7e8SMiklos Szeredi loff_t pos; 2125d7bc7e8SMiklos Szeredi 2135d7bc7e8SMiklos Szeredi /* Offset in cache */ 2145d7bc7e8SMiklos Szeredi loff_t cache_off; 2153494927eSMiklos Szeredi 2163494927eSMiklos Szeredi /* Version of cache we are reading */ 2173494927eSMiklos Szeredi u64 version; 2183494927eSMiklos Szeredi 2195d7bc7e8SMiklos Szeredi } readdir; 2205d7bc7e8SMiklos Szeredi 22195668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 22295668a69STejun Heo struct rb_node polled_node; 22395668a69STejun Heo 22495668a69STejun Heo /** Wait queue head for poll */ 22595668a69STejun Heo wait_queue_head_t poll_wait; 22637fb3a30SMiklos Szeredi 22737fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 22837fb3a30SMiklos Szeredi bool flock:1; 229b6aeadedSMiklos Szeredi }; 230b6aeadedSMiklos Szeredi 231334f485dSMiklos Szeredi /** One input argument of a request */ 232334f485dSMiklos Szeredi struct fuse_in_arg { 233334f485dSMiklos Szeredi unsigned size; 234334f485dSMiklos Szeredi const void *value; 235334f485dSMiklos Szeredi }; 236334f485dSMiklos Szeredi 237334f485dSMiklos Szeredi /** One output argument of a request */ 238334f485dSMiklos Szeredi struct fuse_arg { 239334f485dSMiklos Szeredi unsigned size; 240334f485dSMiklos Szeredi void *value; 241334f485dSMiklos Szeredi }; 242334f485dSMiklos Szeredi 243b2430d75SMaxim Patlasov /** FUSE page descriptor */ 244b2430d75SMaxim Patlasov struct fuse_page_desc { 245b2430d75SMaxim Patlasov unsigned int length; 246b2430d75SMaxim Patlasov unsigned int offset; 247b2430d75SMaxim Patlasov }; 248b2430d75SMaxim Patlasov 2497078187aSMiklos Szeredi struct fuse_args { 2507078187aSMiklos Szeredi uint64_t nodeid; 2511f4e9d03SMiklos Szeredi uint32_t opcode; 25215d937d7SMiklos Szeredi uint8_t in_numargs; 25315d937d7SMiklos Szeredi uint8_t out_numargs; 25415d937d7SMiklos Szeredi uint8_t ext_idx; 255c500ebaaSMiklos Szeredi bool force:1; 256454a7613SMiklos Szeredi bool noreply:1; 257e413754bSMiklos Szeredi bool nocreds:1; 25868583165SMiklos Szeredi bool in_pages:1; 25968583165SMiklos Szeredi bool out_pages:1; 2600c4bcfdeSMiklos Szeredi bool user_pages:1; 2611f4e9d03SMiklos Szeredi bool out_argvar:1; 26268583165SMiklos Szeredi bool page_zeroing:1; 26368583165SMiklos Szeredi bool page_replace:1; 264bb737bbeSVivek Goyal bool may_block:1; 26515d937d7SMiklos Szeredi bool is_ext:1; 266d5b48543SMiklos Szeredi struct fuse_in_arg in_args[3]; 267d5b48543SMiklos Szeredi struct fuse_arg out_args[2]; 268fcee216bSMax Reitz void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error); 2697078187aSMiklos Szeredi }; 2707078187aSMiklos Szeredi 27168583165SMiklos Szeredi struct fuse_args_pages { 27268583165SMiklos Szeredi struct fuse_args args; 27368583165SMiklos Szeredi struct page **pages; 27468583165SMiklos Szeredi struct fuse_page_desc *descs; 27568583165SMiklos Szeredi unsigned int num_pages; 27668583165SMiklos Szeredi }; 27768583165SMiklos Szeredi 2787078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2797078187aSMiklos Szeredi 28001e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 28101e9d11aSMaxim Patlasov struct fuse_io_priv { 282744742d6SSeth Forshee struct kref refcnt; 28301e9d11aSMaxim Patlasov int async; 28401e9d11aSMaxim Patlasov spinlock_t lock; 28501e9d11aSMaxim Patlasov unsigned reqs; 28601e9d11aSMaxim Patlasov ssize_t bytes; 28701e9d11aSMaxim Patlasov size_t size; 28801e9d11aSMaxim Patlasov __u64 offset; 28901e9d11aSMaxim Patlasov bool write; 29061c12b49SAshish Samant bool should_dirty; 29101e9d11aSMaxim Patlasov int err; 29201e9d11aSMaxim Patlasov struct kiocb *iocb; 2939d5722b7SChristoph Hellwig struct completion *done; 2947879c4e5SAshish Sangwan bool blocking; 29501e9d11aSMaxim Patlasov }; 29601e9d11aSMaxim Patlasov 297e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 298744742d6SSeth Forshee { \ 2991e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 300744742d6SSeth Forshee .async = 0, \ 301e1c0eecbSMiklos Szeredi .iocb = i, \ 302744742d6SSeth Forshee } 303744742d6SSeth Forshee 304334f485dSMiklos Szeredi /** 305825d6d33SMiklos Szeredi * Request flags 306825d6d33SMiklos Szeredi * 307825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 308825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 309825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 310825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 311825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 312825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 313825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 31433e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 31533e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 31633e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 31777cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 3183e8cb8b2SMiklos Szeredi * FR_ASYNC: request is asynchronous 319825d6d33SMiklos Szeredi */ 320825d6d33SMiklos Szeredi enum fuse_req_flag { 321825d6d33SMiklos Szeredi FR_ISREPLY, 322825d6d33SMiklos Szeredi FR_FORCE, 323825d6d33SMiklos Szeredi FR_BACKGROUND, 324825d6d33SMiklos Szeredi FR_WAITING, 325825d6d33SMiklos Szeredi FR_ABORTED, 326825d6d33SMiklos Szeredi FR_INTERRUPTED, 327825d6d33SMiklos Szeredi FR_LOCKED, 32833e14b4dSMiklos Szeredi FR_PENDING, 32933e14b4dSMiklos Szeredi FR_SENT, 33033e14b4dSMiklos Szeredi FR_FINISHED, 33177cd9d48SMiklos Szeredi FR_PRIVATE, 3323e8cb8b2SMiklos Szeredi FR_ASYNC, 333825d6d33SMiklos Szeredi }; 334825d6d33SMiklos Szeredi 335825d6d33SMiklos Szeredi /** 336334f485dSMiklos Szeredi * A request to the client 337dc00809aSMiklos Szeredi * 338dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 339dc00809aSMiklos Szeredi * - FR_ABORTED 340dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 341334f485dSMiklos Szeredi */ 342334f485dSMiklos Szeredi struct fuse_req { 343ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 344ce1d5a49SMiklos Szeredi fuse_conn */ 345334f485dSMiklos Szeredi struct list_head list; 346334f485dSMiklos Szeredi 347a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 348a4d27e75SMiklos Szeredi struct list_head intr_entry; 349a4d27e75SMiklos Szeredi 35012597287SMiklos Szeredi /* Input/output arguments */ 35112597287SMiklos Szeredi struct fuse_args *args; 35212597287SMiklos Szeredi 353334f485dSMiklos Szeredi /** refcount */ 354ec99f6d3SElena Reshetova refcount_t count; 355334f485dSMiklos Szeredi 356825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 357825d6d33SMiklos Szeredi unsigned long flags; 3589bc5dddaSMiklos Szeredi 359d4993774SMiklos Szeredi /* The request input header */ 360d4993774SMiklos Szeredi struct { 361d4993774SMiklos Szeredi struct fuse_in_header h; 362d4993774SMiklos Szeredi } in; 363334f485dSMiklos Szeredi 364d4993774SMiklos Szeredi /* The request output header */ 365d4993774SMiklos Szeredi struct { 366d4993774SMiklos Szeredi struct fuse_out_header h; 367d4993774SMiklos Szeredi } out; 368334f485dSMiklos Szeredi 369334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 370334f485dSMiklos Szeredi wait_queue_head_t waitq; 371334f485dSMiklos Szeredi 372a62a8ef9SStefan Hajnoczi #if IS_ENABLED(CONFIG_VIRTIO_FS) 373a62a8ef9SStefan Hajnoczi /** virtio-fs's physically contiguous buffer for in and out args */ 374a62a8ef9SStefan Hajnoczi void *argbuf; 375a62a8ef9SStefan Hajnoczi #endif 37624754db2SMax Reitz 377fcee216bSMax Reitz /** fuse_mount this request belongs to */ 378fcee216bSMax Reitz struct fuse_mount *fm; 379334f485dSMiklos Szeredi }; 380334f485dSMiklos Szeredi 381ae3aad77SStefan Hajnoczi struct fuse_iqueue; 382ae3aad77SStefan Hajnoczi 383ae3aad77SStefan Hajnoczi /** 384ae3aad77SStefan Hajnoczi * Input queue callbacks 385ae3aad77SStefan Hajnoczi * 386ae3aad77SStefan Hajnoczi * Input queue signalling is device-specific. For example, the /dev/fuse file 387ae3aad77SStefan Hajnoczi * uses fiq->waitq and fasync to wake processes that are waiting on queue 388ae3aad77SStefan Hajnoczi * readiness. These callbacks allow other device types to respond to input 389ae3aad77SStefan Hajnoczi * queue activity. 390ae3aad77SStefan Hajnoczi */ 391ae3aad77SStefan Hajnoczi struct fuse_iqueue_ops { 392ae3aad77SStefan Hajnoczi /** 393ae3aad77SStefan Hajnoczi * Signal that a forget has been queued 394ae3aad77SStefan Hajnoczi */ 395ae3aad77SStefan Hajnoczi void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq) 396ae3aad77SStefan Hajnoczi __releases(fiq->lock); 397ae3aad77SStefan Hajnoczi 398ae3aad77SStefan Hajnoczi /** 399ae3aad77SStefan Hajnoczi * Signal that an INTERRUPT request has been queued 400ae3aad77SStefan Hajnoczi */ 401ae3aad77SStefan Hajnoczi void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq) 402ae3aad77SStefan Hajnoczi __releases(fiq->lock); 403ae3aad77SStefan Hajnoczi 404ae3aad77SStefan Hajnoczi /** 405ae3aad77SStefan Hajnoczi * Signal that a request has been queued 406ae3aad77SStefan Hajnoczi */ 407ae3aad77SStefan Hajnoczi void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq) 408ae3aad77SStefan Hajnoczi __releases(fiq->lock); 409a62a8ef9SStefan Hajnoczi 410a62a8ef9SStefan Hajnoczi /** 411a62a8ef9SStefan Hajnoczi * Clean up when fuse_iqueue is destroyed 412a62a8ef9SStefan Hajnoczi */ 413a62a8ef9SStefan Hajnoczi void (*release)(struct fuse_iqueue *fiq); 414ae3aad77SStefan Hajnoczi }; 415ae3aad77SStefan Hajnoczi 416ae3aad77SStefan Hajnoczi /** /dev/fuse input queue operations */ 417ae3aad77SStefan Hajnoczi extern const struct fuse_iqueue_ops fuse_dev_fiq_ops; 418ae3aad77SStefan Hajnoczi 419f88996a9SMiklos Szeredi struct fuse_iqueue { 420e16714d8SMiklos Szeredi /** Connection established */ 421e16714d8SMiklos Szeredi unsigned connected; 422e16714d8SMiklos Szeredi 42376e43c8cSEric Biggers /** Lock protecting accesses to members of this structure */ 42476e43c8cSEric Biggers spinlock_t lock; 42576e43c8cSEric Biggers 426f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 427f88996a9SMiklos Szeredi wait_queue_head_t waitq; 428f88996a9SMiklos Szeredi 429f88996a9SMiklos Szeredi /** The next unique request id */ 430f88996a9SMiklos Szeredi u64 reqctr; 431f88996a9SMiklos Szeredi 432f88996a9SMiklos Szeredi /** The list of pending requests */ 433f88996a9SMiklos Szeredi struct list_head pending; 434f88996a9SMiklos Szeredi 435f88996a9SMiklos Szeredi /** Pending interrupts */ 436f88996a9SMiklos Szeredi struct list_head interrupts; 437f88996a9SMiklos Szeredi 438f88996a9SMiklos Szeredi /** Queue of pending forgets */ 439f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 440f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 441f88996a9SMiklos Szeredi 442f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 443f88996a9SMiklos Szeredi int forget_batch; 444f88996a9SMiklos Szeredi 445f88996a9SMiklos Szeredi /** O_ASYNC requests */ 446f88996a9SMiklos Szeredi struct fasync_struct *fasync; 447ae3aad77SStefan Hajnoczi 448ae3aad77SStefan Hajnoczi /** Device-specific callbacks */ 449ae3aad77SStefan Hajnoczi const struct fuse_iqueue_ops *ops; 450ae3aad77SStefan Hajnoczi 451ae3aad77SStefan Hajnoczi /** Device-specific state */ 452ae3aad77SStefan Hajnoczi void *priv; 453f88996a9SMiklos Szeredi }; 454f88996a9SMiklos Szeredi 455be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 456be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 457be2ff42cSKirill Tkhai 4583a2b5b9cSMiklos Szeredi struct fuse_pqueue { 459e96edd94SMiklos Szeredi /** Connection established */ 460e96edd94SMiklos Szeredi unsigned connected; 461e96edd94SMiklos Szeredi 46245a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 46345a91cb1SMiklos Szeredi spinlock_t lock; 46445a91cb1SMiklos Szeredi 465be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 466be2ff42cSKirill Tkhai struct list_head *processing; 4673a2b5b9cSMiklos Szeredi 4683a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4693a2b5b9cSMiklos Szeredi struct list_head io; 4703a2b5b9cSMiklos Szeredi }; 4713a2b5b9cSMiklos Szeredi 472d8a5ba45SMiklos Szeredi /** 473cc080e9eSMiklos Szeredi * Fuse device instance 474cc080e9eSMiklos Szeredi */ 475cc080e9eSMiklos Szeredi struct fuse_dev { 476cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 477cc080e9eSMiklos Szeredi struct fuse_conn *fc; 478cc080e9eSMiklos Szeredi 479c3696046SMiklos Szeredi /** Processing queue */ 480c3696046SMiklos Szeredi struct fuse_pqueue pq; 481c3696046SMiklos Szeredi 482cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 483cc080e9eSMiklos Szeredi struct list_head entry; 484cc080e9eSMiklos Szeredi }; 485cc080e9eSMiklos Szeredi 486780b1b95SJeffle Xu enum fuse_dax_mode { 487780b1b95SJeffle Xu FUSE_DAX_INODE_DEFAULT, /* default */ 488780b1b95SJeffle Xu FUSE_DAX_ALWAYS, /* "-o dax=always" */ 489780b1b95SJeffle Xu FUSE_DAX_NEVER, /* "-o dax=never" */ 490780b1b95SJeffle Xu FUSE_DAX_INODE_USER, /* "-o dax=inode" */ 491780b1b95SJeffle Xu }; 492780b1b95SJeffle Xu 493780b1b95SJeffle Xu static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode) 494780b1b95SJeffle Xu { 495780b1b95SJeffle Xu return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER; 496780b1b95SJeffle Xu } 497780b1b95SJeffle Xu 4980cc2656cSStefan Hajnoczi struct fuse_fs_context { 4990cc2656cSStefan Hajnoczi int fd; 50062dd1fc8SMiklos Szeredi struct file *file; 5010cc2656cSStefan Hajnoczi unsigned int rootmode; 5020cc2656cSStefan Hajnoczi kuid_t user_id; 5030cc2656cSStefan Hajnoczi kgid_t group_id; 5040cc2656cSStefan Hajnoczi bool is_bdev:1; 5050cc2656cSStefan Hajnoczi bool fd_present:1; 5060cc2656cSStefan Hajnoczi bool rootmode_present:1; 5070cc2656cSStefan Hajnoczi bool user_id_present:1; 5080cc2656cSStefan Hajnoczi bool group_id_present:1; 5090cc2656cSStefan Hajnoczi bool default_permissions:1; 5100cc2656cSStefan Hajnoczi bool allow_other:1; 511783863d6SMiklos Szeredi bool destroy:1; 51215c8e72eSVivek Goyal bool no_control:1; 51315c8e72eSVivek Goyal bool no_force_umount:1; 514f4fd4ae3SVivek Goyal bool legacy_opts_show:1; 515780b1b95SJeffle Xu enum fuse_dax_mode dax_mode; 5160cc2656cSStefan Hajnoczi unsigned int max_read; 5170cc2656cSStefan Hajnoczi unsigned int blksize; 5180cc2656cSStefan Hajnoczi const char *subtype; 5190cc2656cSStefan Hajnoczi 5201dd53957SVivek Goyal /* DAX device, may be NULL */ 5211dd53957SVivek Goyal struct dax_device *dax_dev; 5221dd53957SVivek Goyal 5230cc2656cSStefan Hajnoczi /* fuse_dev pointer to fill in, should contain NULL on entry */ 5240cc2656cSStefan Hajnoczi void **fudptr; 5250cc2656cSStefan Hajnoczi }; 5260cc2656cSStefan Hajnoczi 527660585b5SMiklos Szeredi struct fuse_sync_bucket { 528660585b5SMiklos Szeredi /* count is a possible scalability bottleneck */ 529660585b5SMiklos Szeredi atomic_t count; 530660585b5SMiklos Szeredi wait_queue_head_t waitq; 531660585b5SMiklos Szeredi struct rcu_head rcu; 532660585b5SMiklos Szeredi }; 533660585b5SMiklos Szeredi 534cc080e9eSMiklos Szeredi /** 535d8a5ba45SMiklos Szeredi * A Fuse connection. 536d8a5ba45SMiklos Szeredi * 537fcee216bSMax Reitz * This structure is created, when the root filesystem is mounted, and 538fcee216bSMax Reitz * is destroyed, when the client device is closed and the last 539fcee216bSMax Reitz * fuse_mount is destroyed. 540d8a5ba45SMiklos Szeredi */ 541d8a5ba45SMiklos Szeredi struct fuse_conn { 542d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 543d7133114SMiklos Szeredi spinlock_t lock; 544d7133114SMiklos Szeredi 545bafa9654SMiklos Szeredi /** Refcount */ 546095fc40aSElena Reshetova refcount_t count; 547bafa9654SMiklos Szeredi 548c3696046SMiklos Szeredi /** Number of fuse_dev's */ 549c3696046SMiklos Szeredi atomic_t dev_count; 550c3696046SMiklos Szeredi 551dd3e2c55SAl Viro struct rcu_head rcu; 552dd3e2c55SAl Viro 553d8a5ba45SMiklos Szeredi /** The user id for this mount */ 554499dcf20SEric W. Biederman kuid_t user_id; 555d8a5ba45SMiklos Szeredi 55687729a55SMiklos Szeredi /** The group id for this mount */ 557499dcf20SEric W. Biederman kgid_t group_id; 55887729a55SMiklos Szeredi 5590b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 5600b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 5610b6e9ea0SSeth Forshee 5628cb08329SEric W. Biederman /** The user namespace for this mount */ 5638cb08329SEric W. Biederman struct user_namespace *user_ns; 5648cb08329SEric W. Biederman 565db50b96cSMiklos Szeredi /** Maximum read size */ 566db50b96cSMiklos Szeredi unsigned max_read; 567db50b96cSMiklos Szeredi 568413ef8cbSMiklos Szeredi /** Maximum write size */ 569413ef8cbSMiklos Szeredi unsigned max_write; 570413ef8cbSMiklos Szeredi 5714b91459aSConnor Kuehl /** Maximum number of pages that can be used in a single request */ 5725da784ccSConstantine Shulyupin unsigned int max_pages; 5735da784ccSConstantine Shulyupin 574a7f0d7aaSConnor Kuehl /** Constrain ->max_pages to this value during feature negotiation */ 575a7f0d7aaSConnor Kuehl unsigned int max_pages_limit; 576a7f0d7aaSConnor Kuehl 577f88996a9SMiklos Szeredi /** Input queue */ 578f88996a9SMiklos Szeredi struct fuse_iqueue iq; 579334f485dSMiklos Szeredi 580acf99433STejun Heo /** The next unique kernel file handle */ 58175126f55SMiklos Szeredi atomic64_t khctr; 582acf99433STejun Heo 58395668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 58495668a69STejun Heo struct rb_root polled_files; 58595668a69STejun Heo 5867a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 5877a6d3c8bSCsaba Henk unsigned max_background; 5887a6d3c8bSCsaba Henk 5897a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 5907a6d3c8bSCsaba Henk unsigned congestion_threshold; 5917a6d3c8bSCsaba Henk 59208a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 59308a53cdcSMiklos Szeredi unsigned num_background; 59408a53cdcSMiklos Szeredi 595d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 596d12def1bSMiklos Szeredi unsigned active_background; 597d12def1bSMiklos Szeredi 598d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 599d12def1bSMiklos Szeredi struct list_head bg_queue; 600d12def1bSMiklos Szeredi 601ae2dffa3SKirill Tkhai /** Protects: max_background, congestion_threshold, num_background, 602ae2dffa3SKirill Tkhai * active_background, bg_queue, blocked */ 603ae2dffa3SKirill Tkhai spinlock_t bg_lock; 604ae2dffa3SKirill Tkhai 605796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 606796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 607796523fbSMaxim Patlasov int initialized; 608796523fbSMaxim Patlasov 60908a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 61008a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 61108a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 61208a53cdcSMiklos Szeredi int blocked; 61308a53cdcSMiklos Szeredi 61408a53cdcSMiklos Szeredi /** waitq for blocked connection */ 61508a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 61608a53cdcSMiklos Szeredi 61769a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 61869a53bf2SMiklos Szeredi abort and device release */ 619095da6cbSMiklos Szeredi unsigned connected; 6201e9a4ed9SMiklos Szeredi 6213b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 6223b7008b2SSzymon Lukasz bool aborted; 6233b7008b2SSzymon Lukasz 624095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 625095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 626095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 627334f485dSMiklos Szeredi unsigned conn_error:1; 628334f485dSMiklos Szeredi 6290ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 6300ec7ca41SMiklos Szeredi unsigned conn_init:1; 6310ec7ca41SMiklos Szeredi 632704528d8SMatthew Wilcox (Oracle) /** Do readahead asynchronously? Only set in INIT */ 6339cd68455SMiklos Szeredi unsigned async_read:1; 6349cd68455SMiklos Szeredi 6353b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 6363b7008b2SSzymon Lukasz unsigned abort_err:1; 6373b7008b2SSzymon Lukasz 6386ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 6396ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 6406ff958edSMiklos Szeredi 64133670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 64233670fa2SMiklos Szeredi unsigned export_support:1; 64333670fa2SMiklos Szeredi 644d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 645d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 646d5cd66c5SPavel Emelyanov 6475c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 6485c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 6495c672ab3SMiklos Szeredi 6505e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 6515e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 6525e940c1dSMiklos Szeredi 6535571f1e6SDan Schatzberg /** cache READLINK responses in page cache */ 6545571f1e6SDan Schatzberg unsigned cache_symlinks:1; 6555571f1e6SDan Schatzberg 656f4fd4ae3SVivek Goyal /* show legacy mount options */ 657f4fd4ae3SVivek Goyal unsigned int legacy_opts_show:1; 658f4fd4ae3SVivek Goyal 659095da6cbSMiklos Szeredi /* 66063f9909fSVivek Goyal * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on 66163f9909fSVivek Goyal * write/trunc only if caller did not have CAP_FSETID. sgid is killed 66263f9909fSVivek Goyal * on write/truncate only if caller did not have CAP_FSETID as well as 66363f9909fSVivek Goyal * file has group execute permission. 66463f9909fSVivek Goyal */ 66563f9909fSVivek Goyal unsigned handle_killpriv_v2:1; 66663f9909fSVivek Goyal 66763f9909fSVivek Goyal /* 668095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 669095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 670095da6cbSMiklos Szeredi */ 671095da6cbSMiklos Szeredi 6727678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 6737678ac50SAndrew Gallagher unsigned no_open:1; 6747678ac50SAndrew Gallagher 675d9a9ea94SChad Austin /** Is opendir/releasedir not implemented by fs? */ 676d9a9ea94SChad Austin unsigned no_opendir:1; 677d9a9ea94SChad Austin 678b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 679b6aeadedSMiklos Szeredi unsigned no_fsync:1; 680b6aeadedSMiklos Szeredi 68182547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 68282547981SMiklos Szeredi unsigned no_fsyncdir:1; 68382547981SMiklos Szeredi 684b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 685b6aeadedSMiklos Szeredi unsigned no_flush:1; 686b6aeadedSMiklos Szeredi 68792a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 68892a8780eSMiklos Szeredi unsigned no_setxattr:1; 68992a8780eSMiklos Szeredi 69052a4c95fSVivek Goyal /** Does file server support extended setxattr */ 69152a4c95fSVivek Goyal unsigned setxattr_ext:1; 69252a4c95fSVivek Goyal 69392a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 69492a8780eSMiklos Szeredi unsigned no_getxattr:1; 69592a8780eSMiklos Szeredi 69692a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 69792a8780eSMiklos Szeredi unsigned no_listxattr:1; 69892a8780eSMiklos Szeredi 69992a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 70092a8780eSMiklos Szeredi unsigned no_removexattr:1; 70192a8780eSMiklos Szeredi 70237fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 70371421259SMiklos Szeredi unsigned no_lock:1; 70471421259SMiklos Szeredi 70531d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 70631d40d74SMiklos Szeredi unsigned no_access:1; 70731d40d74SMiklos Szeredi 708fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 709fd72faacSMiklos Szeredi unsigned no_create:1; 710fd72faacSMiklos Szeredi 711a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 712a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 713a4d27e75SMiklos Szeredi 714b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 715b2d2272fSMiklos Szeredi unsigned no_bmap:1; 716b2d2272fSMiklos Szeredi 71795668a69STejun Heo /** Is poll not implemented by fs? */ 71895668a69STejun Heo unsigned no_poll:1; 71995668a69STejun Heo 72078bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 72178bb6cb9SMiklos Szeredi unsigned big_writes:1; 72278bb6cb9SMiklos Szeredi 723e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 724e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 725e0a43ddcSMiklos Szeredi 72637fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 72737fb3a30SMiklos Szeredi unsigned no_flock:1; 72837fb3a30SMiklos Szeredi 729519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 730519c6040SMiklos Szeredi unsigned no_fallocate:1; 731519c6040SMiklos Szeredi 7321560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 7331560c974SMiklos Szeredi unsigned no_rename2:1; 7341560c974SMiklos Szeredi 73572d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 73672d0d248SBrian Foster unsigned auto_inval_data:1; 73772d0d248SBrian Foster 738aa6ff555SBhaskar Chowdhury /** Filesystem is fully responsible for page cache invalidation. */ 739ad2ba64dSKirill Smelkov unsigned explicit_inval_data:1; 740ad2ba64dSKirill Smelkov 741634734b6SEric Wong /** Does the filesystem support readdirplus? */ 7420b05b183SAnand V. Avati unsigned do_readdirplus:1; 7430b05b183SAnand V. Avati 744634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 745634734b6SEric Wong unsigned readdirplus_auto:1; 746634734b6SEric Wong 74760b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 74860b9df7aSMiklos Szeredi unsigned async_dio:1; 74960b9df7aSMiklos Szeredi 7500b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 7510b5da8dbSRavishankar N unsigned no_lseek:1; 7520b5da8dbSRavishankar N 75360bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 75460bcc88aSSeth Forshee unsigned posix_acl:1; 75560bcc88aSSeth Forshee 75629433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 75729433a29SMiklos Szeredi unsigned default_permissions:1; 75829433a29SMiklos Szeredi 75929433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 76029433a29SMiklos Szeredi unsigned allow_other:1; 76129433a29SMiklos Szeredi 76288bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 76388bc7d50SNiels de Vos unsigned no_copy_file_range:1; 76488bc7d50SNiels de Vos 7651ccd1ea2SMiklos Szeredi /* Send DESTROY request */ 7661ccd1ea2SMiklos Szeredi unsigned int destroy:1; 7671ccd1ea2SMiklos Szeredi 7688fab0106SMiklos Szeredi /* Delete dentries that have gone stale */ 7698fab0106SMiklos Szeredi unsigned int delete_stale:1; 7708fab0106SMiklos Szeredi 77115c8e72eSVivek Goyal /** Do not create entry in fusectl fs */ 77215c8e72eSVivek Goyal unsigned int no_control:1; 77315c8e72eSVivek Goyal 77415c8e72eSVivek Goyal /** Do not allow MNT_FORCE umount */ 77515c8e72eSVivek Goyal unsigned int no_force_umount:1; 77615c8e72eSVivek Goyal 777bf109c64SMax Reitz /* Auto-mount submounts announced by the server */ 778bf109c64SMax Reitz unsigned int auto_submounts:1; 779bf109c64SMax Reitz 7802d82ab25SGreg Kurz /* Propagate syncfs() to server */ 7812d82ab25SGreg Kurz unsigned int sync_fs:1; 7822d82ab25SGreg Kurz 7833e2b6fdbSVivek Goyal /* Initialize security xattrs when creating a new inode */ 7843e2b6fdbSVivek Goyal unsigned int init_security:1; 7853e2b6fdbSVivek Goyal 786*8ed7cb3fSMiklos Szeredi /* Add supplementary group info when creating a new inode */ 787*8ed7cb3fSMiklos Szeredi unsigned int create_supp_group:1; 788*8ed7cb3fSMiklos Szeredi 7892ee019faSJeffle Xu /* Does the filesystem support per inode DAX? */ 7902ee019faSJeffle Xu unsigned int inode_dax:1; 7912ee019faSJeffle Xu 7927d375390SMiklos Szeredi /* Is tmpfile not implemented by fs? */ 7937d375390SMiklos Szeredi unsigned int no_tmpfile:1; 7947d375390SMiklos Szeredi 7950cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 7960cd5b885SMiklos Szeredi atomic_t num_waiting; 7970cd5b885SMiklos Szeredi 79845714d65SMiklos Szeredi /** Negotiated minor version */ 79945714d65SMiklos Szeredi unsigned minor; 80045714d65SMiklos Szeredi 801fcee216bSMax Reitz /** Entry on the fuse_mount_list */ 802bafa9654SMiklos Szeredi struct list_head entry; 803bafa9654SMiklos Szeredi 804fcee216bSMax Reitz /** Device ID from the root super block */ 805b6f2fcbcSMiklos Szeredi dev_t dev; 806bafa9654SMiklos Szeredi 807bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 808bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 809bafa9654SMiklos Szeredi 810bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 811bafa9654SMiklos Szeredi int ctl_ndents; 812385a17bfSJeff Dike 8139c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 8149c8ef561SMiklos Szeredi u32 scramble_key[4]; 8150ec7ca41SMiklos Szeredi 8161fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 8174510d86fSKirill Tkhai atomic64_t attr_version; 81843901aabSTejun Heo 81943901aabSTejun Heo /** Called on final put */ 82043901aabSTejun Heo void (*release)(struct fuse_conn *); 8213b463ae0SJohn Muir 822fcee216bSMax Reitz /** 823fcee216bSMax Reitz * Read/write semaphore to hold when accessing the sb of any 824fcee216bSMax Reitz * fuse_mount belonging to this connection 825fcee216bSMax Reitz */ 8263b463ae0SJohn Muir struct rw_semaphore killsb; 827cc080e9eSMiklos Szeredi 828cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 829cc080e9eSMiklos Szeredi struct list_head devices; 8301dd53957SVivek Goyal 8311dd53957SVivek Goyal #ifdef CONFIG_FUSE_DAX 832780b1b95SJeffle Xu /* Dax mode */ 833780b1b95SJeffle Xu enum fuse_dax_mode dax_mode; 834780b1b95SJeffle Xu 8351dd53957SVivek Goyal /* Dax specific conn data, non-NULL if DAX is enabled */ 8361dd53957SVivek Goyal struct fuse_conn_dax *dax; 8371dd53957SVivek Goyal #endif 838fcee216bSMax Reitz 839fcee216bSMax Reitz /** List of filesystems using this connection */ 840fcee216bSMax Reitz struct list_head mounts; 841660585b5SMiklos Szeredi 842660585b5SMiklos Szeredi /* New writepages go into this bucket */ 843660585b5SMiklos Szeredi struct fuse_sync_bucket __rcu *curr_bucket; 844d8a5ba45SMiklos Szeredi }; 845d8a5ba45SMiklos Szeredi 846fcee216bSMax Reitz /* 847fcee216bSMax Reitz * Represents a mounted filesystem, potentially a submount. 848fcee216bSMax Reitz * 849fcee216bSMax Reitz * This object allows sharing a fuse_conn between separate mounts to 850fcee216bSMax Reitz * allow submounts with dedicated superblocks and thus separate device 851fcee216bSMax Reitz * IDs. 852fcee216bSMax Reitz */ 853fcee216bSMax Reitz struct fuse_mount { 854fcee216bSMax Reitz /* Underlying (potentially shared) connection to the FUSE server */ 855fcee216bSMax Reitz struct fuse_conn *fc; 856fcee216bSMax Reitz 857fcee216bSMax Reitz /* 858fcee216bSMax Reitz * Super block for this connection (fc->killsb must be held when 859fcee216bSMax Reitz * accessing this). 860fcee216bSMax Reitz */ 861fcee216bSMax Reitz struct super_block *sb; 862fcee216bSMax Reitz 863fcee216bSMax Reitz /* Entry on fc->mounts */ 864fcee216bSMax Reitz struct list_head fc_entry; 865fcee216bSMax Reitz }; 866fcee216bSMax Reitz 867fcee216bSMax Reitz static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb) 868d8a5ba45SMiklos Szeredi { 8696383bdaaSMiklos Szeredi return sb->s_fs_info; 870d8a5ba45SMiklos Szeredi } 871d8a5ba45SMiklos Szeredi 872fcee216bSMax Reitz static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 873fcee216bSMax Reitz { 874bd3bf1e8SMiklos Szeredi return get_fuse_mount_super(sb)->fc; 875fcee216bSMax Reitz } 876fcee216bSMax Reitz 877fcee216bSMax Reitz static inline struct fuse_mount *get_fuse_mount(struct inode *inode) 878fcee216bSMax Reitz { 879fcee216bSMax Reitz return get_fuse_mount_super(inode->i_sb); 880fcee216bSMax Reitz } 881fcee216bSMax Reitz 882d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 883d8a5ba45SMiklos Szeredi { 884bd3bf1e8SMiklos Szeredi return get_fuse_mount_super(inode->i_sb)->fc; 885d8a5ba45SMiklos Szeredi } 886d8a5ba45SMiklos Szeredi 887d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 888d8a5ba45SMiklos Szeredi { 889d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 890d8a5ba45SMiklos Szeredi } 891d8a5ba45SMiklos Szeredi 892d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 893d8a5ba45SMiklos Szeredi { 894d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 895d8a5ba45SMiklos Szeredi } 896d8a5ba45SMiklos Szeredi 897d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 898d123d8e1SMiklos Szeredi { 899d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 900d123d8e1SMiklos Szeredi } 901d123d8e1SMiklos Szeredi 9024510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 9034510d86fSKirill Tkhai { 9044510d86fSKirill Tkhai return atomic64_read(&fc->attr_version); 9054510d86fSKirill Tkhai } 9064510d86fSKirill Tkhai 90715db1683SAmir Goldstein static inline bool fuse_stale_inode(const struct inode *inode, int generation, 90815db1683SAmir Goldstein struct fuse_attr *attr) 90915db1683SAmir Goldstein { 91015db1683SAmir Goldstein return inode->i_generation != generation || 91115db1683SAmir Goldstein inode_wrong_type(inode, attr->mode); 91215db1683SAmir Goldstein } 91315db1683SAmir Goldstein 9145d069dbeSMiklos Szeredi static inline void fuse_make_bad(struct inode *inode) 9155d069dbeSMiklos Szeredi { 916775c5033SAmir Goldstein remove_inode_hash(inode); 9175d069dbeSMiklos Szeredi set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state); 9185d069dbeSMiklos Szeredi } 9195d069dbeSMiklos Szeredi 9205d069dbeSMiklos Szeredi static inline bool fuse_is_bad(struct inode *inode) 9215d069dbeSMiklos Szeredi { 9225d069dbeSMiklos Szeredi return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state)); 9235d069dbeSMiklos Szeredi } 9245d069dbeSMiklos Szeredi 9259ac29fd3SMiklos Szeredi static inline struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags, 9269ac29fd3SMiklos Szeredi struct fuse_page_desc **desc) 9279ac29fd3SMiklos Szeredi { 9289ac29fd3SMiklos Szeredi struct page **pages; 9299ac29fd3SMiklos Szeredi 9309ac29fd3SMiklos Szeredi pages = kzalloc(npages * (sizeof(struct page *) + 9319ac29fd3SMiklos Szeredi sizeof(struct fuse_page_desc)), flags); 9329ac29fd3SMiklos Szeredi *desc = (void *) (pages + npages); 9339ac29fd3SMiklos Szeredi 9349ac29fd3SMiklos Szeredi return pages; 9359ac29fd3SMiklos Szeredi } 9369ac29fd3SMiklos Szeredi 9379ac29fd3SMiklos Szeredi static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs, 9389ac29fd3SMiklos Szeredi unsigned int index, 9399ac29fd3SMiklos Szeredi unsigned int nr_pages) 9409ac29fd3SMiklos Szeredi { 9419ac29fd3SMiklos Szeredi int i; 9429ac29fd3SMiklos Szeredi 9439ac29fd3SMiklos Szeredi for (i = index; i < index + nr_pages; i++) 9449ac29fd3SMiklos Szeredi descs[i].length = PAGE_SIZE - descs[i].offset; 9459ac29fd3SMiklos Szeredi } 9469ac29fd3SMiklos Szeredi 947660585b5SMiklos Szeredi static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket) 948660585b5SMiklos Szeredi { 949660585b5SMiklos Szeredi /* Need RCU protection to prevent use after free after the decrement */ 950660585b5SMiklos Szeredi rcu_read_lock(); 951660585b5SMiklos Szeredi if (atomic_dec_and_test(&bucket->count)) 952660585b5SMiklos Szeredi wake_up(&bucket->waitq); 953660585b5SMiklos Szeredi rcu_read_unlock(); 954660585b5SMiklos Szeredi } 955660585b5SMiklos Szeredi 956334f485dSMiklos Szeredi /** Device operations */ 9574b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 958334f485dSMiklos Szeredi 9594269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 9600ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 961dbd561d2SMiklos Szeredi 962d8a5ba45SMiklos Szeredi /** 963e5e5558eSMiklos Szeredi * Get a filled in inode 964e5e5558eSMiklos Szeredi */ 965b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 9661fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 9671fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 968e5e5558eSMiklos Szeredi 96913983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 97033670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 97133670fa2SMiklos Szeredi 972e5e5558eSMiklos Szeredi /** 973e5e5558eSMiklos Szeredi * Send FORGET command 974e5e5558eSMiklos Szeredi */ 97507e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 976b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 977e5e5558eSMiklos Szeredi 97807e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 97907e77dcaSMiklos Szeredi 9804388c5aaSVivek Goyal struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq, 9814388c5aaSVivek Goyal unsigned int max, 9824388c5aaSVivek Goyal unsigned int *countp); 9834388c5aaSVivek Goyal 98443f5098eSMiklos Szeredi /* 985361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 98604730fefSMiklos Szeredi */ 98743f5098eSMiklos Szeredi struct fuse_io_args { 98843f5098eSMiklos Szeredi union { 98943f5098eSMiklos Szeredi struct { 99043f5098eSMiklos Szeredi struct fuse_read_in in; 99143f5098eSMiklos Szeredi u64 attr_ver; 99243f5098eSMiklos Szeredi } read; 99343f5098eSMiklos Szeredi struct { 99443f5098eSMiklos Szeredi struct fuse_write_in in; 99543f5098eSMiklos Szeredi struct fuse_write_out out; 9964f06dd92SVivek Goyal bool page_locked; 99743f5098eSMiklos Szeredi } write; 99843f5098eSMiklos Szeredi }; 99943f5098eSMiklos Szeredi struct fuse_args_pages ap; 100043f5098eSMiklos Szeredi struct fuse_io_priv *io; 100143f5098eSMiklos Szeredi struct fuse_file *ff; 100243f5098eSMiklos Szeredi }; 100343f5098eSMiklos Szeredi 100443f5098eSMiklos Szeredi void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos, 100543f5098eSMiklos Szeredi size_t count, int opcode); 100643f5098eSMiklos Szeredi 100704730fefSMiklos Szeredi 100804730fefSMiklos Szeredi /** 100904730fefSMiklos Szeredi * Send OPEN or OPENDIR request 101004730fefSMiklos Szeredi */ 101191fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 101204730fefSMiklos Szeredi 1013fcee216bSMax Reitz struct fuse_file *fuse_file_alloc(struct fuse_mount *fm); 1014fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 1015c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 1016fd72faacSMiklos Szeredi 101754d601cbSMiklos Szeredi void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, 101854d601cbSMiklos Szeredi unsigned int flags); 1019c756e0a4SMiklos Szeredi 102004730fefSMiklos Szeredi /** 102104730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 102204730fefSMiklos Szeredi */ 10232e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir); 102404730fefSMiklos Szeredi 102504730fefSMiklos Szeredi /** 102682547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 102782547981SMiklos Szeredi */ 102802c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 1029a9c2d1e8SMiklos Szeredi int datasync, int opcode); 103082547981SMiklos Szeredi 103182547981SMiklos Szeredi /** 103295668a69STejun Heo * Notify poll wakeup 103395668a69STejun Heo */ 103495668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 103595668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 103695668a69STejun Heo 103795668a69STejun Heo /** 10381779381dSMiklos Szeredi * Initialize file operations on a regular file 1039b6aeadedSMiklos Szeredi */ 104093a497b9SJeffle Xu void fuse_init_file_inode(struct inode *inode, unsigned int flags); 1041b6aeadedSMiklos Szeredi 1042b6aeadedSMiklos Szeredi /** 10431779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 1044e5e5558eSMiklos Szeredi */ 1045e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 1046e5e5558eSMiklos Szeredi 1047e5e5558eSMiklos Szeredi /** 10481779381dSMiklos Szeredi * Initialize inode and file operations on a directory 1049e5e5558eSMiklos Szeredi */ 1050e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 1051e5e5558eSMiklos Szeredi 1052e5e5558eSMiklos Szeredi /** 10531779381dSMiklos Szeredi * Initialize inode operations on a symlink 1054e5e5558eSMiklos Szeredi */ 1055e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 1056e5e5558eSMiklos Szeredi 1057e5e5558eSMiklos Szeredi /** 1058e5e5558eSMiklos Szeredi * Change attributes of an inode 1059e5e5558eSMiklos Szeredi */ 10601fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 10611fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 1062e5e5558eSMiklos Szeredi 10633be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 10644b52f059SMiklos Szeredi u64 attr_valid, u32 cache_mask); 10654b52f059SMiklos Szeredi 10664b52f059SMiklos Szeredi u32 fuse_get_cache_mask(struct inode *inode); 10673be5a52bSMiklos Szeredi 1068e5e5558eSMiklos Szeredi /** 1069334f485dSMiklos Szeredi * Initialize the client device 1070334f485dSMiklos Szeredi */ 1071334f485dSMiklos Szeredi int fuse_dev_init(void); 1072334f485dSMiklos Szeredi 1073334f485dSMiklos Szeredi /** 1074334f485dSMiklos Szeredi * Cleanup the client device 1075334f485dSMiklos Szeredi */ 1076334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 1077334f485dSMiklos Szeredi 1078bafa9654SMiklos Szeredi int fuse_ctl_init(void); 10797736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 1080bafa9654SMiklos Szeredi 1081334f485dSMiklos Szeredi /** 10827078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 10837078187aSMiklos Szeredi */ 1084fcee216bSMax Reitz ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args); 1085fcee216bSMax Reitz int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, 108612597287SMiklos Szeredi gfp_t gfp_flags); 10877078187aSMiklos Szeredi 108804ec5af0SStefan Hajnoczi /** 108904ec5af0SStefan Hajnoczi * End a finished request 109004ec5af0SStefan Hajnoczi */ 10918f622e94SMax Reitz void fuse_request_end(struct fuse_req *req); 109204ec5af0SStefan Hajnoczi 10935a5fb1eaSMiklos Szeredi /* Abort all requests */ 1094eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 1095b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 109669a53bf2SMiklos Szeredi 10971e9a4ed9SMiklos Szeredi /** 1098e5e5558eSMiklos Szeredi * Invalidate inode attributes 1099e5e5558eSMiklos Szeredi */ 1100fa5eee57SMiklos Szeredi 1101fa5eee57SMiklos Szeredi /* Attributes possibly changed on data modification */ 1102fa5eee57SMiklos Szeredi #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS) 1103fa5eee57SMiklos Szeredi 1104fa5eee57SMiklos Szeredi /* Attributes possibly changed on data and/or size modification */ 1105fa5eee57SMiklos Szeredi #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE) 1106fa5eee57SMiklos Szeredi 1107e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 1108fa5eee57SMiklos Szeredi void fuse_invalidate_attr_mask(struct inode *inode, u32 mask); 1109bafa9654SMiklos Szeredi 1110dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 1111dbd561d2SMiklos Szeredi 1112451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 1113451418fcSAndrew Gallagher 1114d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o); 1115d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 1116d123d8e1SMiklos Szeredi 1117bafa9654SMiklos Szeredi /** 1118bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 1119bafa9654SMiklos Szeredi */ 1120bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 1121bafa9654SMiklos Szeredi 1122bafa9654SMiklos Szeredi /** 11230d179aa5STejun Heo * Initialize fuse_conn 11240d179aa5STejun Heo */ 1125fcee216bSMax Reitz void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, 1126fcee216bSMax Reitz struct user_namespace *user_ns, 1127ae3aad77SStefan Hajnoczi const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv); 11280d179aa5STejun Heo 11290d179aa5STejun Heo /** 1130bafa9654SMiklos Szeredi * Release reference to fuse_conn 1131bafa9654SMiklos Szeredi */ 1132bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 1133bafa9654SMiklos Szeredi 11340cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc); 11350cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc(void); 11360cd1eb9aSVivek Goyal void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc); 1137cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 1138fcee216bSMax Reitz void fuse_send_init(struct fuse_mount *fm); 1139cc080e9eSMiklos Szeredi 1140bafa9654SMiklos Szeredi /** 11410cc2656cSStefan Hajnoczi * Fill in superblock and initialize fuse connection 11420cc2656cSStefan Hajnoczi * @sb: partially-initialized superblock to fill in 11430cc2656cSStefan Hajnoczi * @ctx: mount context 11440cc2656cSStefan Hajnoczi */ 11450cc2656cSStefan Hajnoczi int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx); 11460cc2656cSStefan Hajnoczi 11471866d779SMax Reitz /* 1148fcee216bSMax Reitz * Remove the mount from the connection 1149783863d6SMiklos Szeredi * 1150fcee216bSMax Reitz * Returns whether this was the last mount 1151783863d6SMiklos Szeredi */ 1152fcee216bSMax Reitz bool fuse_mount_remove(struct fuse_mount *fm); 1153fcee216bSMax Reitz 1154fcee216bSMax Reitz /* 1155fe0a7bd8SGreg Kurz * Setup context ops for submounts 1156fe0a7bd8SGreg Kurz */ 1157fe0a7bd8SGreg Kurz int fuse_init_fs_context_submount(struct fs_context *fsc); 1158fe0a7bd8SGreg Kurz 1159fe0a7bd8SGreg Kurz /* 1160fcee216bSMax Reitz * Shut down the connection (possibly sending DESTROY request). 1161fcee216bSMax Reitz */ 1162fcee216bSMax Reitz void fuse_conn_destroy(struct fuse_mount *fm); 1163783863d6SMiklos Szeredi 1164a27c061aSMiklos Szeredi /* Drop the connection and free the fuse mount */ 1165a27c061aSMiklos Szeredi void fuse_mount_destroy(struct fuse_mount *fm); 1166a27c061aSMiklos Szeredi 1167783863d6SMiklos Szeredi /** 1168bafa9654SMiklos Szeredi * Add connection to control filesystem 1169bafa9654SMiklos Szeredi */ 1170bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 1171bafa9654SMiklos Szeredi 1172bafa9654SMiklos Szeredi /** 1173bafa9654SMiklos Szeredi * Remove connection from control filesystem 1174bafa9654SMiklos Szeredi */ 1175bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 1176a5bfffacSTimo Savola 1177a5bfffacSTimo Savola /** 1178a5bfffacSTimo Savola * Is file type valid? 1179a5bfffacSTimo Savola */ 1180a5bfffacSTimo Savola int fuse_valid_type(int m); 1181e57ac683SMiklos Szeredi 1182eb59bd17SMiklos Szeredi bool fuse_invalid_attr(struct fuse_attr *attr); 1183eb59bd17SMiklos Szeredi 1184e57ac683SMiklos Szeredi /** 1185c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 1186e57ac683SMiklos Szeredi */ 1187b1387777SDave Marchevsky bool fuse_allow_current_process(struct fuse_conn *fc); 1188f3332114SMiklos Szeredi 1189f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 1190bcb4be80SMiklos Szeredi 11915c791fe1SMiklos Szeredi void fuse_flush_time_update(struct inode *inode); 1192703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 1193703c7362SSeth Forshee 1194c6c745b8SMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask); 11953be5a52bSMiklos Szeredi 11963be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 11973be5a52bSMiklos Szeredi 11983be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 11993be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 12005c5c5e51SMiklos Szeredi 12013b463ae0SJohn Muir /** 1202fcee216bSMax Reitz * Scan all fuse_mounts belonging to fc to find the first where 1203fcee216bSMax Reitz * ilookup5() returns a result. Return that result and the 1204fcee216bSMax Reitz * respective fuse_mount in *fm (unless fm is NULL). 1205fcee216bSMax Reitz * 1206fcee216bSMax Reitz * The caller must hold fc->killsb. 1207fcee216bSMax Reitz */ 1208fcee216bSMax Reitz struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid, 1209fcee216bSMax Reitz struct fuse_mount **fm); 1210fcee216bSMax Reitz 1211fcee216bSMax Reitz /** 12123b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 12133b463ae0SJohn Muir */ 1214fcee216bSMax Reitz int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid, 12153b463ae0SJohn Muir loff_t offset, loff_t len); 12163b463ae0SJohn Muir 12173b463ae0SJohn Muir /** 12183b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 12193b463ae0SJohn Muir * the dentry matching parent/name. 1220451d0f59SJohn Muir * 1221451d0f59SJohn Muir * If the child_nodeid is non-zero and: 1222451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 1223451d0f59SJohn Muir * - is not a mount point 1224451d0f59SJohn Muir * - is a file or oan empty directory 1225451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 12263b463ae0SJohn Muir */ 1227fcee216bSMax Reitz int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid, 12284f8d3702SMiklos Szeredi u64 child_nodeid, struct qstr *name, u32 flags); 12293b463ae0SJohn Muir 1230fcee216bSMax Reitz int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file, 123108cbf542STejun Heo bool isdir); 1232ea8cd333SPavel Emelyanov 1233ea8cd333SPavel Emelyanov /** 1234ea8cd333SPavel Emelyanov * fuse_direct_io() flags 1235ea8cd333SPavel Emelyanov */ 1236ea8cd333SPavel Emelyanov 1237ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 1238ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 1239ea8cd333SPavel Emelyanov 1240ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1241ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 1242ea8cd333SPavel Emelyanov 1243d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1244d22a943fSAl Viro loff_t *ppos, int flags); 124508cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 124608cbf542STejun Heo unsigned int flags); 1247b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 1248b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 1249076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 125008cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 125108cbf542STejun Heo 1252d347739aSMiklos Szeredi bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written); 1253b0aa7606SMaxim Patlasov 1254ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 12551e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1256a1d75f25SMiklos Szeredi 125762490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1258efb9fa9eSMaxim Patlasov struct file *file); 1259efb9fa9eSMaxim Patlasov 12609759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 12619759bd51SMiklos Szeredi 126263576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 126363576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 12645c672ab3SMiklos Szeredi 126560bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 126652a4c95fSVivek Goyal size_t size, int flags, unsigned int extra_flags); 126760bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 126860bcc88aSSeth Forshee size_t size); 1269703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 127060bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 1271703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 127260bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 1273e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 127460bcc88aSSeth Forshee 127560bcc88aSSeth Forshee struct posix_acl; 12760cad6246SMiklos Szeredi struct posix_acl *fuse_get_acl(struct inode *inode, int type, bool rcu); 1277138060baSChristian Brauner int fuse_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, 1278549c7297SChristian Brauner struct posix_acl *acl, int type); 1279d123d8e1SMiklos Szeredi 1280d123d8e1SMiklos Szeredi /* readdir.c */ 1281d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 1282d123d8e1SMiklos Szeredi 128314d46d7aSStefan Hajnoczi /** 128414d46d7aSStefan Hajnoczi * Return the number of bytes in an arguments list 128514d46d7aSStefan Hajnoczi */ 128614d46d7aSStefan Hajnoczi unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args); 128714d46d7aSStefan Hajnoczi 128879d96effSStefan Hajnoczi /** 128979d96effSStefan Hajnoczi * Get the next unique ID for a request 129079d96effSStefan Hajnoczi */ 129179d96effSStefan Hajnoczi u64 fuse_get_unique(struct fuse_iqueue *fiq); 1292783863d6SMiklos Szeredi void fuse_free_conn(struct fuse_conn *fc); 129379d96effSStefan Hajnoczi 12941dd53957SVivek Goyal /* dax.c */ 12951dd53957SVivek Goyal 1296c2d0ad00SVivek Goyal #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode)) 1297c2d0ad00SVivek Goyal 1298c2d0ad00SVivek Goyal ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to); 1299c2d0ad00SVivek Goyal ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from); 1300c2d0ad00SVivek Goyal int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma); 13016ae330caSVivek Goyal int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end); 1302780b1b95SJeffle Xu int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode, 1303780b1b95SJeffle Xu struct dax_device *dax_dev); 13041dd53957SVivek Goyal void fuse_dax_conn_free(struct fuse_conn *fc); 1305c2d0ad00SVivek Goyal bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi); 130693a497b9SJeffle Xu void fuse_dax_inode_init(struct inode *inode, unsigned int flags); 1307c2d0ad00SVivek Goyal void fuse_dax_inode_cleanup(struct inode *inode); 1308c3cb6f93SJeffle Xu void fuse_dax_dontcache(struct inode *inode, unsigned int flags); 1309fd1a1dc6SStefan Hajnoczi bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment); 13109a752d18SVivek Goyal void fuse_dax_cancel_work(struct fuse_conn *fc); 13111dd53957SVivek Goyal 13129ac29fd3SMiklos Szeredi /* ioctl.c */ 13139ac29fd3SMiklos Szeredi long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 13149ac29fd3SMiklos Szeredi long fuse_file_compat_ioctl(struct file *file, unsigned int cmd, 13159ac29fd3SMiklos Szeredi unsigned long arg); 131672227eacSMiklos Szeredi int fuse_fileattr_get(struct dentry *dentry, struct fileattr *fa); 131772227eacSMiklos Szeredi int fuse_fileattr_set(struct user_namespace *mnt_userns, 131872227eacSMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 13199ac29fd3SMiklos Szeredi 1320b9d54c6fSMiklos Szeredi /* file.c */ 1321b9d54c6fSMiklos Szeredi 1322b9d54c6fSMiklos Szeredi struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, 1323b9d54c6fSMiklos Szeredi unsigned int open_flags, bool isdir); 1324b9d54c6fSMiklos Szeredi void fuse_file_release(struct inode *inode, struct fuse_file *ff, 1325b9d54c6fSMiklos Szeredi unsigned int open_flags, fl_owner_t id, bool isdir); 1326b9d54c6fSMiklos Szeredi 132729d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 1328