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 12d8a5ba45SMiklos Szeredi #include <linux/fuse.h> 13d8a5ba45SMiklos Szeredi #include <linux/fs.h> 1451eb01e7SMiklos Szeredi #include <linux/mount.h> 15d8a5ba45SMiklos Szeredi #include <linux/wait.h> 16d8a5ba45SMiklos Szeredi #include <linux/list.h> 17d8a5ba45SMiklos Szeredi #include <linux/spinlock.h> 18d8a5ba45SMiklos Szeredi #include <linux/mm.h> 19d8a5ba45SMiklos Szeredi #include <linux/backing-dev.h> 20bafa9654SMiklos Szeredi #include <linux/mutex.h> 213be5a52bSMiklos Szeredi #include <linux/rwsem.h> 2295668a69STejun Heo #include <linux/rbtree.h> 2395668a69STejun Heo #include <linux/poll.h> 245a18ec17SMiklos Szeredi #include <linux/workqueue.h> 25744742d6SSeth Forshee #include <linux/kref.h> 2660bcc88aSSeth Forshee #include <linux/xattr.h> 270b6e9ea0SSeth Forshee #include <linux/pid_namespace.h> 284e8c2eb5SElena Reshetova #include <linux/refcount.h> 298cb08329SEric W. Biederman #include <linux/user_namespace.h> 30d8a5ba45SMiklos Szeredi 315da784ccSConstantine Shulyupin /** Default max number of pages that can be used in a single read request */ 325da784ccSConstantine Shulyupin #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 335da784ccSConstantine Shulyupin 345da784ccSConstantine Shulyupin /** Maximum of max_pages received in init_out */ 355da784ccSConstantine Shulyupin #define FUSE_MAX_MAX_PAGES 256 36334f485dSMiklos Szeredi 373be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 383be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 393be5a52bSMiklos Szeredi 401d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 411d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 421d3d752bSMiklos Szeredi 43bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4479a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 45bafa9654SMiklos Szeredi 464250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */ 474250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1 484250c066SMaxim Patlasov 49bafa9654SMiklos Szeredi /** List of active connections */ 50bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 51bafa9654SMiklos Szeredi 52bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 53bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 54413ef8cbSMiklos Szeredi 5579a9d994SCsaba Henk /** Module parameters */ 5679a9d994SCsaba Henk extern unsigned max_user_bgreq; 5779a9d994SCsaba Henk extern unsigned max_user_congthresh; 5879a9d994SCsaba Henk 5907e77dcaSMiklos Szeredi /* One forget request */ 6007e77dcaSMiklos Szeredi struct fuse_forget_link { 6102c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 6207e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6307e77dcaSMiklos Szeredi }; 6407e77dcaSMiklos Szeredi 65d8a5ba45SMiklos Szeredi /** FUSE inode */ 66d8a5ba45SMiklos Szeredi struct fuse_inode { 67d8a5ba45SMiklos Szeredi /** Inode data */ 68d8a5ba45SMiklos Szeredi struct inode inode; 69d8a5ba45SMiklos Szeredi 70d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 71d8a5ba45SMiklos Szeredi * and kernel */ 72d8a5ba45SMiklos Szeredi u64 nodeid; 73d8a5ba45SMiklos Szeredi 749e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 759e6268dbSMiklos Szeredi u64 nlookup; 769e6268dbSMiklos Szeredi 77e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7807e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 79e5e5558eSMiklos Szeredi 80d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 810a0898cfSMiklos Szeredi u64 i_time; 82ebc14c4dSMiklos Szeredi 832f1e8196SMiklos Szeredi /* Which attributes are invalid */ 842f1e8196SMiklos Szeredi u32 inval_mask; 852f1e8196SMiklos Szeredi 86ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 87ebc14c4dSMiklos Szeredi preserve the original mode */ 88541af6a0SAl Viro umode_t orig_i_mode; 891fb69e78SMiklos Szeredi 9045c72cd7SPavel Shilovsky /** 64 bit inode number */ 9145c72cd7SPavel Shilovsky u64 orig_ino; 9245c72cd7SPavel Shilovsky 931fb69e78SMiklos Szeredi /** Version of last attribute change */ 941fb69e78SMiklos Szeredi u64 attr_version; 9593a8c3cdSMiklos Szeredi 96ab2257e9SMiklos Szeredi union { 97ab2257e9SMiklos Szeredi /* Write related fields (regular file only) */ 98ab2257e9SMiklos Szeredi struct { 99f15ecfefSKirill Tkhai /* Files usable in writepage. Protected by fi->lock */ 10093a8c3cdSMiklos Szeredi struct list_head write_files; 1013be5a52bSMiklos Szeredi 102ab2257e9SMiklos Szeredi /* Writepages pending on truncate or fsync */ 1033be5a52bSMiklos Szeredi struct list_head queued_writes; 1043be5a52bSMiklos Szeredi 105ab2257e9SMiklos Szeredi /* Number of sent writes, a negative bias 106ab2257e9SMiklos Szeredi * (FUSE_NOWRITE) means more writes are blocked */ 1073be5a52bSMiklos Szeredi int writectr; 1083be5a52bSMiklos Szeredi 109ab2257e9SMiklos Szeredi /* Waitq for writepage completion */ 1103be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1113be5a52bSMiklos Szeredi 112ab2257e9SMiklos Szeredi /* List of writepage requestst (pending or sent) */ 1133be5a52bSMiklos Szeredi struct list_head writepages; 114ab2257e9SMiklos Szeredi }; 1154582a4abSFeng Shuo 116ab2257e9SMiklos Szeredi /* readdir cache (directory only) */ 11769e34551SMiklos Szeredi struct { 11869e34551SMiklos Szeredi /* true if fully cached */ 11969e34551SMiklos Szeredi bool cached; 12069e34551SMiklos Szeredi 12169e34551SMiklos Szeredi /* size of cache */ 12269e34551SMiklos Szeredi loff_t size; 12369e34551SMiklos Szeredi 12469e34551SMiklos Szeredi /* position at end of cache (position of next entry) */ 12569e34551SMiklos Szeredi loff_t pos; 12669e34551SMiklos Szeredi 1273494927eSMiklos Szeredi /* version of the cache */ 1283494927eSMiklos Szeredi u64 version; 1293494927eSMiklos Szeredi 130ab2257e9SMiklos Szeredi /* modification time of directory when cache was 131ab2257e9SMiklos Szeredi * started */ 1327118883bSMiklos Szeredi struct timespec64 mtime; 1337118883bSMiklos Szeredi 134261aaba7SMiklos Szeredi /* iversion of directory when cache was started */ 135261aaba7SMiklos Szeredi u64 iversion; 136261aaba7SMiklos Szeredi 13769e34551SMiklos Szeredi /* protects above fields */ 13869e34551SMiklos Szeredi spinlock_t lock; 13969e34551SMiklos Szeredi } rdc; 140ab2257e9SMiklos Szeredi }; 14169e34551SMiklos Szeredi 1424582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1434582a4abSFeng Shuo unsigned long state; 1445c672ab3SMiklos Szeredi 1455c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1465c672ab3SMiklos Szeredi struct mutex mutex; 147f15ecfefSKirill Tkhai 148f15ecfefSKirill Tkhai /** Lock to protect write related fields */ 149f15ecfefSKirill Tkhai spinlock_t lock; 1504582a4abSFeng Shuo }; 1514582a4abSFeng Shuo 1524582a4abSFeng Shuo /** FUSE inode state bits */ 1534582a4abSFeng Shuo enum { 1544582a4abSFeng Shuo /** Advise readdirplus */ 1554582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1566314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1576314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 15806a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 15906a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 160d8a5ba45SMiklos Szeredi }; 161d8a5ba45SMiklos Szeredi 162da5e4714SMiklos Szeredi struct fuse_conn; 163da5e4714SMiklos Szeredi 164b6aeadedSMiklos Szeredi /** FUSE specific file data */ 165b6aeadedSMiklos Szeredi struct fuse_file { 166da5e4714SMiklos Szeredi /** Fuse connection for this file */ 167da5e4714SMiklos Szeredi struct fuse_conn *fc; 168da5e4714SMiklos Szeredi 1696b675738SKirill Tkhai /* 1706b675738SKirill Tkhai * Request reserved for flush and release. 1716b675738SKirill Tkhai * Modified under relative fuse_inode::lock. 1726b675738SKirill Tkhai */ 17333649c91SMiklos Szeredi struct fuse_req *reserved_req; 174b6aeadedSMiklos Szeredi 175acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 176acf99433STejun Heo u64 kh; 177acf99433STejun Heo 178b6aeadedSMiklos Szeredi /** File handle used by userspace */ 179b6aeadedSMiklos Szeredi u64 fh; 180c756e0a4SMiklos Szeredi 181da5e4714SMiklos Szeredi /** Node id of this file */ 182da5e4714SMiklos Szeredi u64 nodeid; 183da5e4714SMiklos Szeredi 184c756e0a4SMiklos Szeredi /** Refcount */ 1854e8c2eb5SElena Reshetova refcount_t count; 18693a8c3cdSMiklos Szeredi 187c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 188c7b7143cSMiklos Szeredi u32 open_flags; 189c7b7143cSMiklos Szeredi 19093a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 19193a8c3cdSMiklos Szeredi struct list_head write_entry; 19295668a69STejun Heo 1935d7bc7e8SMiklos Szeredi /* Readdir related */ 1945d7bc7e8SMiklos Szeredi struct { 1955d7bc7e8SMiklos Szeredi /* 1965d7bc7e8SMiklos Szeredi * Protects below fields against (crazy) parallel readdir on 1975d7bc7e8SMiklos Szeredi * same open file. Uncontended in the normal case. 1985d7bc7e8SMiklos Szeredi */ 1995d7bc7e8SMiklos Szeredi struct mutex lock; 2005d7bc7e8SMiklos Szeredi 2015d7bc7e8SMiklos Szeredi /* Dir stream position */ 2025d7bc7e8SMiklos Szeredi loff_t pos; 2035d7bc7e8SMiklos Szeredi 2045d7bc7e8SMiklos Szeredi /* Offset in cache */ 2055d7bc7e8SMiklos Szeredi loff_t cache_off; 2063494927eSMiklos Szeredi 2073494927eSMiklos Szeredi /* Version of cache we are reading */ 2083494927eSMiklos Szeredi u64 version; 2093494927eSMiklos Szeredi 2105d7bc7e8SMiklos Szeredi } readdir; 2115d7bc7e8SMiklos Szeredi 21295668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 21395668a69STejun Heo struct rb_node polled_node; 21495668a69STejun Heo 21595668a69STejun Heo /** Wait queue head for poll */ 21695668a69STejun Heo wait_queue_head_t poll_wait; 21737fb3a30SMiklos Szeredi 21837fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 21937fb3a30SMiklos Szeredi bool flock:1; 220b6aeadedSMiklos Szeredi }; 221b6aeadedSMiklos Szeredi 222334f485dSMiklos Szeredi /** One input argument of a request */ 223334f485dSMiklos Szeredi struct fuse_in_arg { 224334f485dSMiklos Szeredi unsigned size; 225334f485dSMiklos Szeredi const void *value; 226334f485dSMiklos Szeredi }; 227334f485dSMiklos Szeredi 228334f485dSMiklos Szeredi /** The request input */ 229334f485dSMiklos Szeredi struct fuse_in { 230334f485dSMiklos Szeredi /** The request header */ 231334f485dSMiklos Szeredi struct fuse_in_header h; 232334f485dSMiklos Szeredi 233334f485dSMiklos Szeredi /** True if the data for the last argument is in req->pages */ 234334f485dSMiklos Szeredi unsigned argpages:1; 235334f485dSMiklos Szeredi 236334f485dSMiklos Szeredi /** Number of arguments */ 237334f485dSMiklos Szeredi unsigned numargs; 238334f485dSMiklos Szeredi 239334f485dSMiklos Szeredi /** Array of arguments */ 240334f485dSMiklos Szeredi struct fuse_in_arg args[3]; 241334f485dSMiklos Szeredi }; 242334f485dSMiklos Szeredi 243334f485dSMiklos Szeredi /** One output argument of a request */ 244334f485dSMiklos Szeredi struct fuse_arg { 245334f485dSMiklos Szeredi unsigned size; 246334f485dSMiklos Szeredi void *value; 247334f485dSMiklos Szeredi }; 248334f485dSMiklos Szeredi 249334f485dSMiklos Szeredi /** The request output */ 250334f485dSMiklos Szeredi struct fuse_out { 251334f485dSMiklos Szeredi /** Header returned from userspace */ 252334f485dSMiklos Szeredi struct fuse_out_header h; 253334f485dSMiklos Szeredi 254095da6cbSMiklos Szeredi /* 255095da6cbSMiklos Szeredi * The following bitfields are not changed during the request 256095da6cbSMiklos Szeredi * processing 257095da6cbSMiklos Szeredi */ 258095da6cbSMiklos Szeredi 259334f485dSMiklos Szeredi /** Last argument is variable length (can be shorter than 260334f485dSMiklos Szeredi arg->size) */ 261334f485dSMiklos Szeredi unsigned argvar:1; 262334f485dSMiklos Szeredi 263334f485dSMiklos Szeredi /** Last argument is a list of pages to copy data to */ 264334f485dSMiklos Szeredi unsigned argpages:1; 265334f485dSMiklos Szeredi 266334f485dSMiklos Szeredi /** Zero partially or not copied pages */ 267334f485dSMiklos Szeredi unsigned page_zeroing:1; 268334f485dSMiklos Szeredi 269ce534fb0SMiklos Szeredi /** Pages may be replaced with new ones */ 270ce534fb0SMiklos Szeredi unsigned page_replace:1; 271ce534fb0SMiklos Szeredi 272334f485dSMiklos Szeredi /** Number or arguments */ 273334f485dSMiklos Szeredi unsigned numargs; 274334f485dSMiklos Szeredi 275334f485dSMiklos Szeredi /** Array of arguments */ 276f704dcb5SMiklos Szeredi struct fuse_arg args[2]; 277334f485dSMiklos Szeredi }; 278334f485dSMiklos Szeredi 279b2430d75SMaxim Patlasov /** FUSE page descriptor */ 280b2430d75SMaxim Patlasov struct fuse_page_desc { 281b2430d75SMaxim Patlasov unsigned int length; 282b2430d75SMaxim Patlasov unsigned int offset; 283b2430d75SMaxim Patlasov }; 284b2430d75SMaxim Patlasov 2857078187aSMiklos Szeredi struct fuse_args { 2867078187aSMiklos Szeredi struct { 2877078187aSMiklos Szeredi struct { 2887078187aSMiklos Szeredi uint32_t opcode; 2897078187aSMiklos Szeredi uint64_t nodeid; 2907078187aSMiklos Szeredi } h; 2917078187aSMiklos Szeredi unsigned numargs; 2927078187aSMiklos Szeredi struct fuse_in_arg args[3]; 2937078187aSMiklos Szeredi 2947078187aSMiklos Szeredi } in; 2957078187aSMiklos Szeredi struct { 2967078187aSMiklos Szeredi unsigned argvar:1; 2977078187aSMiklos Szeredi unsigned numargs; 2987078187aSMiklos Szeredi struct fuse_arg args[2]; 2997078187aSMiklos Szeredi } out; 3007078187aSMiklos Szeredi }; 3017078187aSMiklos Szeredi 3027078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 3037078187aSMiklos Szeredi 30401e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 30501e9d11aSMaxim Patlasov struct fuse_io_priv { 306744742d6SSeth Forshee struct kref refcnt; 30701e9d11aSMaxim Patlasov int async; 30801e9d11aSMaxim Patlasov spinlock_t lock; 30901e9d11aSMaxim Patlasov unsigned reqs; 31001e9d11aSMaxim Patlasov ssize_t bytes; 31101e9d11aSMaxim Patlasov size_t size; 31201e9d11aSMaxim Patlasov __u64 offset; 31301e9d11aSMaxim Patlasov bool write; 31461c12b49SAshish Samant bool should_dirty; 31501e9d11aSMaxim Patlasov int err; 31601e9d11aSMaxim Patlasov struct kiocb *iocb; 3179d5722b7SChristoph Hellwig struct completion *done; 3187879c4e5SAshish Sangwan bool blocking; 31901e9d11aSMaxim Patlasov }; 32001e9d11aSMaxim Patlasov 321e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 322744742d6SSeth Forshee { \ 3231e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 324744742d6SSeth Forshee .async = 0, \ 325e1c0eecbSMiklos Szeredi .iocb = i, \ 326744742d6SSeth Forshee } 327744742d6SSeth Forshee 328334f485dSMiklos Szeredi /** 329825d6d33SMiklos Szeredi * Request flags 330825d6d33SMiklos Szeredi * 331825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 332825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 333825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 334825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 335825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 336825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 337825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 33833e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 33933e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 34033e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 34177cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 342825d6d33SMiklos Szeredi */ 343825d6d33SMiklos Szeredi enum fuse_req_flag { 344825d6d33SMiklos Szeredi FR_ISREPLY, 345825d6d33SMiklos Szeredi FR_FORCE, 346825d6d33SMiklos Szeredi FR_BACKGROUND, 347825d6d33SMiklos Szeredi FR_WAITING, 348825d6d33SMiklos Szeredi FR_ABORTED, 349825d6d33SMiklos Szeredi FR_INTERRUPTED, 350825d6d33SMiklos Szeredi FR_LOCKED, 35133e14b4dSMiklos Szeredi FR_PENDING, 35233e14b4dSMiklos Szeredi FR_SENT, 35333e14b4dSMiklos Szeredi FR_FINISHED, 35477cd9d48SMiklos Szeredi FR_PRIVATE, 355825d6d33SMiklos Szeredi }; 356825d6d33SMiklos Szeredi 357825d6d33SMiklos Szeredi /** 358334f485dSMiklos Szeredi * A request to the client 359dc00809aSMiklos Szeredi * 360dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 361dc00809aSMiklos Szeredi * - FR_ABORTED 362dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 363334f485dSMiklos Szeredi */ 364334f485dSMiklos Szeredi struct fuse_req { 365ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 366ce1d5a49SMiklos Szeredi fuse_conn */ 367334f485dSMiklos Szeredi struct list_head list; 368334f485dSMiklos Szeredi 369a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 370a4d27e75SMiklos Szeredi struct list_head intr_entry; 371a4d27e75SMiklos Szeredi 372334f485dSMiklos Szeredi /** refcount */ 373ec99f6d3SElena Reshetova refcount_t count; 374334f485dSMiklos Szeredi 375825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 376825d6d33SMiklos Szeredi unsigned long flags; 3779bc5dddaSMiklos Szeredi 378334f485dSMiklos Szeredi /** The request input */ 379334f485dSMiklos Szeredi struct fuse_in in; 380334f485dSMiklos Szeredi 381334f485dSMiklos Szeredi /** The request output */ 382334f485dSMiklos Szeredi struct fuse_out out; 383334f485dSMiklos Szeredi 384334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 385334f485dSMiklos Szeredi wait_queue_head_t waitq; 386334f485dSMiklos Szeredi 387334f485dSMiklos Szeredi /** Data for asynchronous requests */ 388334f485dSMiklos Szeredi union { 389b57d4264SMiklos Szeredi struct { 390b57d4264SMiklos Szeredi struct fuse_release_in in; 391baebccbeSMiklos Szeredi struct inode *inode; 392b57d4264SMiklos Szeredi } release; 3933ec870d5SMiklos Szeredi struct fuse_init_in init_in; 3943ec870d5SMiklos Szeredi struct fuse_init_out init_out; 39508cbf542STejun Heo struct cuse_init_in cuse_init_in; 3965c5c5e51SMiklos Szeredi struct { 3975c5c5e51SMiklos Szeredi struct fuse_read_in in; 3985c5c5e51SMiklos Szeredi u64 attr_ver; 3995c5c5e51SMiklos Szeredi } read; 400b25e82e5SMiklos Szeredi struct { 401b25e82e5SMiklos Szeredi struct fuse_write_in in; 402b25e82e5SMiklos Szeredi struct fuse_write_out out; 4038b284dc4SMiklos Szeredi struct fuse_req *next; 404b25e82e5SMiklos Szeredi } write; 4052d45ba38SMiklos Szeredi struct fuse_notify_retrieve_in retrieve_in; 406334f485dSMiklos Szeredi } misc; 407334f485dSMiklos Szeredi 408334f485dSMiklos Szeredi /** page vector */ 4094250c066SMaxim Patlasov struct page **pages; 4104250c066SMaxim Patlasov 411b2430d75SMaxim Patlasov /** page-descriptor vector */ 412b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 413b2430d75SMaxim Patlasov 4144250c066SMaxim Patlasov /** size of the 'pages' array */ 4154250c066SMaxim Patlasov unsigned max_pages; 4164250c066SMaxim Patlasov 4174250c066SMaxim Patlasov /** inline page vector */ 4184250c066SMaxim Patlasov struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 419334f485dSMiklos Szeredi 420b2430d75SMaxim Patlasov /** inline page-descriptor vector */ 421b2430d75SMaxim Patlasov struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 422b2430d75SMaxim Patlasov 423334f485dSMiklos Szeredi /** number of pages in vector */ 424334f485dSMiklos Szeredi unsigned num_pages; 425334f485dSMiklos Szeredi 426334f485dSMiklos Szeredi /** File used in the request (or NULL) */ 427c756e0a4SMiklos Szeredi struct fuse_file *ff; 42864c6d8edSMiklos Szeredi 4293be5a52bSMiklos Szeredi /** Inode used in the request or NULL */ 4303be5a52bSMiklos Szeredi struct inode *inode; 4313be5a52bSMiklos Szeredi 43201e9d11aSMaxim Patlasov /** AIO control block */ 43301e9d11aSMaxim Patlasov struct fuse_io_priv *io; 43401e9d11aSMaxim Patlasov 4353be5a52bSMiklos Szeredi /** Link on fi->writepages */ 4363be5a52bSMiklos Szeredi struct list_head writepages_entry; 4373be5a52bSMiklos Szeredi 43864c6d8edSMiklos Szeredi /** Request completion callback */ 43964c6d8edSMiklos Szeredi void (*end)(struct fuse_conn *, struct fuse_req *); 44033649c91SMiklos Szeredi 44133649c91SMiklos Szeredi /** Request is stolen from fuse_file->reserved_req */ 44233649c91SMiklos Szeredi struct file *stolen_file; 443334f485dSMiklos Szeredi }; 444334f485dSMiklos Szeredi 445f88996a9SMiklos Szeredi struct fuse_iqueue { 446e16714d8SMiklos Szeredi /** Connection established */ 447e16714d8SMiklos Szeredi unsigned connected; 448e16714d8SMiklos Szeredi 449f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 450f88996a9SMiklos Szeredi wait_queue_head_t waitq; 451f88996a9SMiklos Szeredi 452f88996a9SMiklos Szeredi /** The next unique request id */ 453f88996a9SMiklos Szeredi u64 reqctr; 454f88996a9SMiklos Szeredi 455f88996a9SMiklos Szeredi /** The list of pending requests */ 456f88996a9SMiklos Szeredi struct list_head pending; 457f88996a9SMiklos Szeredi 458f88996a9SMiklos Szeredi /** Pending interrupts */ 459f88996a9SMiklos Szeredi struct list_head interrupts; 460f88996a9SMiklos Szeredi 461f88996a9SMiklos Szeredi /** Queue of pending forgets */ 462f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 463f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 464f88996a9SMiklos Szeredi 465f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 466f88996a9SMiklos Szeredi int forget_batch; 467f88996a9SMiklos Szeredi 468f88996a9SMiklos Szeredi /** O_ASYNC requests */ 469f88996a9SMiklos Szeredi struct fasync_struct *fasync; 470f88996a9SMiklos Szeredi }; 471f88996a9SMiklos Szeredi 472be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 473be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 474be2ff42cSKirill Tkhai 4753a2b5b9cSMiklos Szeredi struct fuse_pqueue { 476e96edd94SMiklos Szeredi /** Connection established */ 477e96edd94SMiklos Szeredi unsigned connected; 478e96edd94SMiklos Szeredi 47945a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 48045a91cb1SMiklos Szeredi spinlock_t lock; 48145a91cb1SMiklos Szeredi 482be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 483be2ff42cSKirill Tkhai struct list_head *processing; 4843a2b5b9cSMiklos Szeredi 4853a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4863a2b5b9cSMiklos Szeredi struct list_head io; 4873a2b5b9cSMiklos Szeredi }; 4883a2b5b9cSMiklos Szeredi 489d8a5ba45SMiklos Szeredi /** 490cc080e9eSMiklos Szeredi * Fuse device instance 491cc080e9eSMiklos Szeredi */ 492cc080e9eSMiklos Szeredi struct fuse_dev { 493cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 494cc080e9eSMiklos Szeredi struct fuse_conn *fc; 495cc080e9eSMiklos Szeredi 496c3696046SMiklos Szeredi /** Processing queue */ 497c3696046SMiklos Szeredi struct fuse_pqueue pq; 498c3696046SMiklos Szeredi 499cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 500cc080e9eSMiklos Szeredi struct list_head entry; 501cc080e9eSMiklos Szeredi }; 502cc080e9eSMiklos Szeredi 503cc080e9eSMiklos Szeredi /** 504d8a5ba45SMiklos Szeredi * A Fuse connection. 505d8a5ba45SMiklos Szeredi * 506d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 507d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 508d8a5ba45SMiklos Szeredi * unmounted. 509d8a5ba45SMiklos Szeredi */ 510d8a5ba45SMiklos Szeredi struct fuse_conn { 511d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 512d7133114SMiklos Szeredi spinlock_t lock; 513d7133114SMiklos Szeredi 514bafa9654SMiklos Szeredi /** Refcount */ 515095fc40aSElena Reshetova refcount_t count; 516bafa9654SMiklos Szeredi 517c3696046SMiklos Szeredi /** Number of fuse_dev's */ 518c3696046SMiklos Szeredi atomic_t dev_count; 519c3696046SMiklos Szeredi 520dd3e2c55SAl Viro struct rcu_head rcu; 521dd3e2c55SAl Viro 522d8a5ba45SMiklos Szeredi /** The user id for this mount */ 523499dcf20SEric W. Biederman kuid_t user_id; 524d8a5ba45SMiklos Szeredi 52587729a55SMiklos Szeredi /** The group id for this mount */ 526499dcf20SEric W. Biederman kgid_t group_id; 52787729a55SMiklos Szeredi 5280b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 5290b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 5300b6e9ea0SSeth Forshee 5318cb08329SEric W. Biederman /** The user namespace for this mount */ 5328cb08329SEric W. Biederman struct user_namespace *user_ns; 5338cb08329SEric W. Biederman 534db50b96cSMiklos Szeredi /** Maximum read size */ 535db50b96cSMiklos Szeredi unsigned max_read; 536db50b96cSMiklos Szeredi 537413ef8cbSMiklos Szeredi /** Maximum write size */ 538413ef8cbSMiklos Szeredi unsigned max_write; 539413ef8cbSMiklos Szeredi 5405da784ccSConstantine Shulyupin /** Maxmum number of pages that can be used in a single request */ 5415da784ccSConstantine Shulyupin unsigned int max_pages; 5425da784ccSConstantine Shulyupin 543f88996a9SMiklos Szeredi /** Input queue */ 544f88996a9SMiklos Szeredi struct fuse_iqueue iq; 545334f485dSMiklos Szeredi 546acf99433STejun Heo /** The next unique kernel file handle */ 547*75126f55SMiklos Szeredi atomic64_t khctr; 548acf99433STejun Heo 54995668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 55095668a69STejun Heo struct rb_root polled_files; 55195668a69STejun Heo 5527a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 5537a6d3c8bSCsaba Henk unsigned max_background; 5547a6d3c8bSCsaba Henk 5557a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 5567a6d3c8bSCsaba Henk unsigned congestion_threshold; 5577a6d3c8bSCsaba Henk 55808a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 55908a53cdcSMiklos Szeredi unsigned num_background; 56008a53cdcSMiklos Szeredi 561d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 562d12def1bSMiklos Szeredi unsigned active_background; 563d12def1bSMiklos Szeredi 564d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 565d12def1bSMiklos Szeredi struct list_head bg_queue; 566d12def1bSMiklos Szeredi 567ae2dffa3SKirill Tkhai /** Protects: max_background, congestion_threshold, num_background, 568ae2dffa3SKirill Tkhai * active_background, bg_queue, blocked */ 569ae2dffa3SKirill Tkhai spinlock_t bg_lock; 570ae2dffa3SKirill Tkhai 571796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 572796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 573796523fbSMaxim Patlasov int initialized; 574796523fbSMaxim Patlasov 57508a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 57608a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 57708a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 57808a53cdcSMiklos Szeredi int blocked; 57908a53cdcSMiklos Szeredi 58008a53cdcSMiklos Szeredi /** waitq for blocked connection */ 58108a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 58208a53cdcSMiklos Szeredi 583de5e3decSMiklos Szeredi /** waitq for reserved requests */ 584de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 585de5e3decSMiklos Szeredi 58669a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 58769a53bf2SMiklos Szeredi abort and device release */ 588095da6cbSMiklos Szeredi unsigned connected; 5891e9a4ed9SMiklos Szeredi 5903b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 5913b7008b2SSzymon Lukasz bool aborted; 5923b7008b2SSzymon Lukasz 593095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 594095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 595095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 596334f485dSMiklos Szeredi unsigned conn_error:1; 597334f485dSMiklos Szeredi 5980ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5990ec7ca41SMiklos Szeredi unsigned conn_init:1; 6000ec7ca41SMiklos Szeredi 6019cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 6029cd68455SMiklos Szeredi unsigned async_read:1; 6039cd68455SMiklos Szeredi 6043b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 6053b7008b2SSzymon Lukasz unsigned abort_err:1; 6063b7008b2SSzymon Lukasz 6076ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 6086ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 6096ff958edSMiklos Szeredi 61033670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 61133670fa2SMiklos Szeredi unsigned export_support:1; 61233670fa2SMiklos Szeredi 613d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 614d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 615d5cd66c5SPavel Emelyanov 6165c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 6175c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 6185c672ab3SMiklos Szeredi 6195e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 6205e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 6215e940c1dSMiklos Szeredi 6225571f1e6SDan Schatzberg /** cache READLINK responses in page cache */ 6235571f1e6SDan Schatzberg unsigned cache_symlinks:1; 6245571f1e6SDan Schatzberg 625095da6cbSMiklos Szeredi /* 626095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 627095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 628095da6cbSMiklos Szeredi */ 629095da6cbSMiklos Szeredi 6307678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 6317678ac50SAndrew Gallagher unsigned no_open:1; 6327678ac50SAndrew Gallagher 633b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 634b6aeadedSMiklos Szeredi unsigned no_fsync:1; 635b6aeadedSMiklos Szeredi 63682547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 63782547981SMiklos Szeredi unsigned no_fsyncdir:1; 63882547981SMiklos Szeredi 639b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 640b6aeadedSMiklos Szeredi unsigned no_flush:1; 641b6aeadedSMiklos Szeredi 64292a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 64392a8780eSMiklos Szeredi unsigned no_setxattr:1; 64492a8780eSMiklos Szeredi 64592a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 64692a8780eSMiklos Szeredi unsigned no_getxattr:1; 64792a8780eSMiklos Szeredi 64892a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 64992a8780eSMiklos Szeredi unsigned no_listxattr:1; 65092a8780eSMiklos Szeredi 65192a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 65292a8780eSMiklos Szeredi unsigned no_removexattr:1; 65392a8780eSMiklos Szeredi 65437fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 65571421259SMiklos Szeredi unsigned no_lock:1; 65671421259SMiklos Szeredi 65731d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 65831d40d74SMiklos Szeredi unsigned no_access:1; 65931d40d74SMiklos Szeredi 660fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 661fd72faacSMiklos Szeredi unsigned no_create:1; 662fd72faacSMiklos Szeredi 663a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 664a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 665a4d27e75SMiklos Szeredi 666b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 667b2d2272fSMiklos Szeredi unsigned no_bmap:1; 668b2d2272fSMiklos Szeredi 66995668a69STejun Heo /** Is poll not implemented by fs? */ 67095668a69STejun Heo unsigned no_poll:1; 67195668a69STejun Heo 67278bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 67378bb6cb9SMiklos Szeredi unsigned big_writes:1; 67478bb6cb9SMiklos Szeredi 675e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 676e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 677e0a43ddcSMiklos Szeredi 67837fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 67937fb3a30SMiklos Szeredi unsigned no_flock:1; 68037fb3a30SMiklos Szeredi 681519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 682519c6040SMiklos Szeredi unsigned no_fallocate:1; 683519c6040SMiklos Szeredi 6841560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6851560c974SMiklos Szeredi unsigned no_rename2:1; 6861560c974SMiklos Szeredi 68772d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 68872d0d248SBrian Foster unsigned auto_inval_data:1; 68972d0d248SBrian Foster 690634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6910b05b183SAnand V. Avati unsigned do_readdirplus:1; 6920b05b183SAnand V. Avati 693634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 694634734b6SEric Wong unsigned readdirplus_auto:1; 695634734b6SEric Wong 69660b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 69760b9df7aSMiklos Szeredi unsigned async_dio:1; 69860b9df7aSMiklos Szeredi 6990b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 7000b5da8dbSRavishankar N unsigned no_lseek:1; 7010b5da8dbSRavishankar N 70260bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 70360bcc88aSSeth Forshee unsigned posix_acl:1; 70460bcc88aSSeth Forshee 70529433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 70629433a29SMiklos Szeredi unsigned default_permissions:1; 70729433a29SMiklos Szeredi 70829433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 70929433a29SMiklos Szeredi unsigned allow_other:1; 71029433a29SMiklos Szeredi 71188bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 71288bc7d50SNiels de Vos unsigned no_copy_file_range:1; 71388bc7d50SNiels de Vos 7140cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 7150cd5b885SMiklos Szeredi atomic_t num_waiting; 7160cd5b885SMiklos Szeredi 71745714d65SMiklos Szeredi /** Negotiated minor version */ 71845714d65SMiklos Szeredi unsigned minor; 71945714d65SMiklos Szeredi 720bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 721bafa9654SMiklos Szeredi struct list_head entry; 722bafa9654SMiklos Szeredi 723b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 724b6f2fcbcSMiklos Szeredi dev_t dev; 725bafa9654SMiklos Szeredi 726bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 727bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 728bafa9654SMiklos Szeredi 729bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 730bafa9654SMiklos Szeredi int ctl_ndents; 731385a17bfSJeff Dike 7329c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 7339c8ef561SMiklos Szeredi u32 scramble_key[4]; 7340ec7ca41SMiklos Szeredi 7350ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 7360ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 7371fb69e78SMiklos Szeredi 7381fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 7394510d86fSKirill Tkhai atomic64_t attr_version; 74043901aabSTejun Heo 74143901aabSTejun Heo /** Called on final put */ 74243901aabSTejun Heo void (*release)(struct fuse_conn *); 7433b463ae0SJohn Muir 7443b463ae0SJohn Muir /** Super block for this connection. */ 7453b463ae0SJohn Muir struct super_block *sb; 7463b463ae0SJohn Muir 7473b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 7483b463ae0SJohn Muir struct rw_semaphore killsb; 749cc080e9eSMiklos Szeredi 750cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 751cc080e9eSMiklos Szeredi struct list_head devices; 752d8a5ba45SMiklos Szeredi }; 753d8a5ba45SMiklos Szeredi 754d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 755d8a5ba45SMiklos Szeredi { 7566383bdaaSMiklos Szeredi return sb->s_fs_info; 757d8a5ba45SMiklos Szeredi } 758d8a5ba45SMiklos Szeredi 759d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 760d8a5ba45SMiklos Szeredi { 761d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 762d8a5ba45SMiklos Szeredi } 763d8a5ba45SMiklos Szeredi 764d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 765d8a5ba45SMiklos Szeredi { 766d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 767d8a5ba45SMiklos Szeredi } 768d8a5ba45SMiklos Szeredi 769d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 770d8a5ba45SMiklos Szeredi { 771d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 772d8a5ba45SMiklos Szeredi } 773d8a5ba45SMiklos Szeredi 774d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 775d123d8e1SMiklos Szeredi { 776d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 777d123d8e1SMiklos Szeredi } 778d123d8e1SMiklos Szeredi 7794510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 7804510d86fSKirill Tkhai { 7814510d86fSKirill Tkhai return atomic64_read(&fc->attr_version); 7824510d86fSKirill Tkhai } 7834510d86fSKirill Tkhai 784334f485dSMiklos Szeredi /** Device operations */ 7854b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 786334f485dSMiklos Szeredi 7874269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 7880ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 789dbd561d2SMiklos Szeredi 790d8a5ba45SMiklos Szeredi /** 7913b463ae0SJohn Muir * Inode to nodeid comparison. 7923b463ae0SJohn Muir */ 7933b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7943b463ae0SJohn Muir 7953b463ae0SJohn Muir /** 796e5e5558eSMiklos Szeredi * Get a filled in inode 797e5e5558eSMiklos Szeredi */ 798b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7991fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 8001fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 801e5e5558eSMiklos Szeredi 80213983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 80333670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 80433670fa2SMiklos Szeredi 805e5e5558eSMiklos Szeredi /** 806e5e5558eSMiklos Szeredi * Send FORGET command 807e5e5558eSMiklos Szeredi */ 80807e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 809b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 810e5e5558eSMiklos Szeredi 81107e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 81207e77dcaSMiklos Szeredi 8130b05b183SAnand V. Avati /* Used by READDIRPLUS */ 8140b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 8150b05b183SAnand V. Avati 816e5e5558eSMiklos Szeredi /** 817361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 81804730fefSMiklos Szeredi */ 819a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 8202106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 82104730fefSMiklos Szeredi 82204730fefSMiklos Szeredi /** 82304730fefSMiklos Szeredi * Send OPEN or OPENDIR request 82404730fefSMiklos Szeredi */ 82591fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 82604730fefSMiklos Szeredi 827acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 828fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 829c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 830fd72faacSMiklos Szeredi 831ebf84d0cSKirill Tkhai void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags); 832c756e0a4SMiklos Szeredi 83304730fefSMiklos Szeredi /** 83404730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 83504730fefSMiklos Szeredi */ 8362e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir); 83704730fefSMiklos Szeredi 83804730fefSMiklos Szeredi /** 83982547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 84082547981SMiklos Szeredi */ 84102c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 842a9c2d1e8SMiklos Szeredi int datasync, int opcode); 84382547981SMiklos Szeredi 84482547981SMiklos Szeredi /** 84595668a69STejun Heo * Notify poll wakeup 84695668a69STejun Heo */ 84795668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 84895668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 84995668a69STejun Heo 85095668a69STejun Heo /** 8511779381dSMiklos Szeredi * Initialize file operations on a regular file 852b6aeadedSMiklos Szeredi */ 853b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 854b6aeadedSMiklos Szeredi 855b6aeadedSMiklos Szeredi /** 8561779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 857e5e5558eSMiklos Szeredi */ 858e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 859e5e5558eSMiklos Szeredi 860e5e5558eSMiklos Szeredi /** 8611779381dSMiklos Szeredi * Initialize inode and file operations on a directory 862e5e5558eSMiklos Szeredi */ 863e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 864e5e5558eSMiklos Szeredi 865e5e5558eSMiklos Szeredi /** 8661779381dSMiklos Szeredi * Initialize inode operations on a symlink 867e5e5558eSMiklos Szeredi */ 868e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 869e5e5558eSMiklos Szeredi 870e5e5558eSMiklos Szeredi /** 871e5e5558eSMiklos Szeredi * Change attributes of an inode 872e5e5558eSMiklos Szeredi */ 8731fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 8741fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 875e5e5558eSMiklos Szeredi 8763be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 8773be5a52bSMiklos Szeredi u64 attr_valid); 8783be5a52bSMiklos Szeredi 879e5e5558eSMiklos Szeredi /** 880334f485dSMiklos Szeredi * Initialize the client device 881334f485dSMiklos Szeredi */ 882334f485dSMiklos Szeredi int fuse_dev_init(void); 883334f485dSMiklos Szeredi 884334f485dSMiklos Szeredi /** 885334f485dSMiklos Szeredi * Cleanup the client device 886334f485dSMiklos Szeredi */ 887334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 888334f485dSMiklos Szeredi 889bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8907736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 891bafa9654SMiklos Szeredi 892334f485dSMiklos Szeredi /** 893334f485dSMiklos Szeredi * Allocate a request 894334f485dSMiklos Szeredi */ 8954250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 896334f485dSMiklos Szeredi 8974250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8983be5a52bSMiklos Szeredi 899e52a8250SMiklos Szeredi bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req, 900e52a8250SMiklos Szeredi gfp_t flags); 901e52a8250SMiklos Szeredi 902e52a8250SMiklos Szeredi 903334f485dSMiklos Szeredi /** 904334f485dSMiklos Szeredi * Free a request 905334f485dSMiklos Szeredi */ 906334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 907334f485dSMiklos Szeredi 908334f485dSMiklos Szeredi /** 909b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 910b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 911334f485dSMiklos Szeredi */ 912b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 9138b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 9148b41e671SMaxim Patlasov unsigned npages); 915b111c8c0SMaxim Patlasov 91636cf66edSMaxim Patlasov /* 91736cf66edSMaxim Patlasov * Increment reference count on request 91836cf66edSMaxim Patlasov */ 91936cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 92036cf66edSMaxim Patlasov 921b111c8c0SMaxim Patlasov /** 92233649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 92333649c91SMiklos Szeredi */ 924b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 925b111c8c0SMaxim Patlasov struct file *file); 92633649c91SMiklos Szeredi 92733649c91SMiklos Szeredi /** 928ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 929ce1d5a49SMiklos Szeredi * the request. 930334f485dSMiklos Szeredi */ 931334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 932334f485dSMiklos Szeredi 933334f485dSMiklos Szeredi /** 9347c352bdfSMiklos Szeredi * Send a request (synchronous) 935334f485dSMiklos Szeredi */ 936b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 937334f485dSMiklos Szeredi 938334f485dSMiklos Szeredi /** 9397078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 9407078187aSMiklos Szeredi */ 9417078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 9427078187aSMiklos Szeredi 9437078187aSMiklos Szeredi /** 944334f485dSMiklos Szeredi * Send a request in the background 945334f485dSMiklos Szeredi */ 946b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 94763825b4eSKirill Tkhai bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); 9483be5a52bSMiklos Szeredi 9495a5fb1eaSMiklos Szeredi /* Abort all requests */ 950eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 951b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 95269a53bf2SMiklos Szeredi 9531e9a4ed9SMiklos Szeredi /** 954e5e5558eSMiklos Szeredi * Invalidate inode attributes 955e5e5558eSMiklos Szeredi */ 956e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 957bafa9654SMiklos Szeredi 958dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 959dbd561d2SMiklos Szeredi 960451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 961451418fcSAndrew Gallagher 962d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o); 963d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 964d123d8e1SMiklos Szeredi 965bafa9654SMiklos Szeredi /** 966bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 967bafa9654SMiklos Szeredi */ 968bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 969bafa9654SMiklos Szeredi 970bafa9654SMiklos Szeredi /** 9710d179aa5STejun Heo * Initialize fuse_conn 9720d179aa5STejun Heo */ 9738cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); 9740d179aa5STejun Heo 9750d179aa5STejun Heo /** 976bafa9654SMiklos Szeredi * Release reference to fuse_conn 977bafa9654SMiklos Szeredi */ 978bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 979bafa9654SMiklos Szeredi 980cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 981cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 982cc080e9eSMiklos Szeredi 983bafa9654SMiklos Szeredi /** 984bafa9654SMiklos Szeredi * Add connection to control filesystem 985bafa9654SMiklos Szeredi */ 986bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 987bafa9654SMiklos Szeredi 988bafa9654SMiklos Szeredi /** 989bafa9654SMiklos Szeredi * Remove connection from control filesystem 990bafa9654SMiklos Szeredi */ 991bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 992a5bfffacSTimo Savola 993a5bfffacSTimo Savola /** 994a5bfffacSTimo Savola * Is file type valid? 995a5bfffacSTimo Savola */ 996a5bfffacSTimo Savola int fuse_valid_type(int m); 997e57ac683SMiklos Szeredi 998e57ac683SMiklos Szeredi /** 999c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 1000e57ac683SMiklos Szeredi */ 1001c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 1002f3332114SMiklos Szeredi 1003f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 1004bcb4be80SMiklos Szeredi 1005703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 1006703c7362SSeth Forshee 10075b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 10083be5a52bSMiklos Szeredi 10093be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 10103be5a52bSMiklos Szeredi 10113be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 10123be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 10135c5c5e51SMiklos Szeredi 10143b463ae0SJohn Muir /** 10153b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 10163b463ae0SJohn Muir */ 10173b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 10183b463ae0SJohn Muir loff_t offset, loff_t len); 10193b463ae0SJohn Muir 10203b463ae0SJohn Muir /** 10213b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 10223b463ae0SJohn Muir * the dentry matching parent/name. 1023451d0f59SJohn Muir * 1024451d0f59SJohn Muir * If the child_nodeid is non-zero and: 1025451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 1026451d0f59SJohn Muir * - is not a mount point 1027451d0f59SJohn Muir * - is a file or oan empty directory 1028451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 10293b463ae0SJohn Muir */ 10303b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 1031451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 10323b463ae0SJohn Muir 103308cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 103408cbf542STejun Heo bool isdir); 1035ea8cd333SPavel Emelyanov 1036ea8cd333SPavel Emelyanov /** 1037ea8cd333SPavel Emelyanov * fuse_direct_io() flags 1038ea8cd333SPavel Emelyanov */ 1039ea8cd333SPavel Emelyanov 1040ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 1041ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 1042ea8cd333SPavel Emelyanov 1043ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1044ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 1045ea8cd333SPavel Emelyanov 1046d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1047d22a943fSAl Viro loff_t *ppos, int flags); 104808cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 104908cbf542STejun Heo unsigned int flags); 1050b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 1051b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 1052076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 105308cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 105408cbf542STejun Heo 1055b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 1056b0aa7606SMaxim Patlasov 1057ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 10581e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1059a1d75f25SMiklos Szeredi 106062490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1061efb9fa9eSMaxim Patlasov struct file *file); 1062efb9fa9eSMaxim Patlasov 10639759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 10649759bd51SMiklos Szeredi 106563576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 106663576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 10675c672ab3SMiklos Szeredi 106860bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 106960bcc88aSSeth Forshee size_t size, int flags); 107060bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 107160bcc88aSSeth Forshee size_t size); 1072703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 107360bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 1074703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 107560bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 1076e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 107760bcc88aSSeth Forshee 107860bcc88aSSeth Forshee struct posix_acl; 107960bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 108060bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 1081703c7362SSeth Forshee 1082d123d8e1SMiklos Szeredi 1083d123d8e1SMiklos Szeredi /* readdir.c */ 1084d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 1085d123d8e1SMiklos Szeredi 108629d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 1087