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 31334f485dSMiklos Szeredi /** Max number of pages that can be used in a single read request */ 32334f485dSMiklos Szeredi #define FUSE_MAX_PAGES_PER_REQ 32 33334f485dSMiklos Szeredi 343be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 353be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 363be5a52bSMiklos Szeredi 371d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 381d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 391d3d752bSMiklos Szeredi 40bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4179a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 42bafa9654SMiklos Szeredi 434250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */ 444250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1 454250c066SMaxim Patlasov 46bafa9654SMiklos Szeredi /** List of active connections */ 47bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 48bafa9654SMiklos Szeredi 49bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 50bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 51413ef8cbSMiklos Szeredi 5279a9d994SCsaba Henk /** Module parameters */ 5379a9d994SCsaba Henk extern unsigned max_user_bgreq; 5479a9d994SCsaba Henk extern unsigned max_user_congthresh; 5579a9d994SCsaba Henk 5607e77dcaSMiklos Szeredi /* One forget request */ 5707e77dcaSMiklos Szeredi struct fuse_forget_link { 5802c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 5907e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6007e77dcaSMiklos Szeredi }; 6107e77dcaSMiklos Szeredi 62d8a5ba45SMiklos Szeredi /** FUSE inode */ 63d8a5ba45SMiklos Szeredi struct fuse_inode { 64d8a5ba45SMiklos Szeredi /** Inode data */ 65d8a5ba45SMiklos Szeredi struct inode inode; 66d8a5ba45SMiklos Szeredi 67d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 68d8a5ba45SMiklos Szeredi * and kernel */ 69d8a5ba45SMiklos Szeredi u64 nodeid; 70d8a5ba45SMiklos Szeredi 719e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 729e6268dbSMiklos Szeredi u64 nlookup; 739e6268dbSMiklos Szeredi 74e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7507e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 76e5e5558eSMiklos Szeredi 77d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 780a0898cfSMiklos Szeredi u64 i_time; 79ebc14c4dSMiklos Szeredi 80ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 81ebc14c4dSMiklos Szeredi preserve the original mode */ 82541af6a0SAl Viro umode_t orig_i_mode; 831fb69e78SMiklos Szeredi 8445c72cd7SPavel Shilovsky /** 64 bit inode number */ 8545c72cd7SPavel Shilovsky u64 orig_ino; 8645c72cd7SPavel Shilovsky 871fb69e78SMiklos Szeredi /** Version of last attribute change */ 881fb69e78SMiklos Szeredi u64 attr_version; 8993a8c3cdSMiklos Szeredi 90*ab2257e9SMiklos Szeredi union { 91*ab2257e9SMiklos Szeredi /* Write related fields (regular file only) */ 92*ab2257e9SMiklos Szeredi struct { 93*ab2257e9SMiklos Szeredi /* Files usable in writepage. Protected by fc->lock */ 9493a8c3cdSMiklos Szeredi struct list_head write_files; 953be5a52bSMiklos Szeredi 96*ab2257e9SMiklos Szeredi /* Writepages pending on truncate or fsync */ 973be5a52bSMiklos Szeredi struct list_head queued_writes; 983be5a52bSMiklos Szeredi 99*ab2257e9SMiklos Szeredi /* Number of sent writes, a negative bias 100*ab2257e9SMiklos Szeredi * (FUSE_NOWRITE) means more writes are blocked */ 1013be5a52bSMiklos Szeredi int writectr; 1023be5a52bSMiklos Szeredi 103*ab2257e9SMiklos Szeredi /* Waitq for writepage completion */ 1043be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1053be5a52bSMiklos Szeredi 106*ab2257e9SMiklos Szeredi /* List of writepage requestst (pending or sent) */ 1073be5a52bSMiklos Szeredi struct list_head writepages; 108*ab2257e9SMiklos Szeredi }; 1094582a4abSFeng Shuo 110*ab2257e9SMiklos Szeredi /* readdir cache (directory only) */ 11169e34551SMiklos Szeredi struct { 11269e34551SMiklos Szeredi /* true if fully cached */ 11369e34551SMiklos Szeredi bool cached; 11469e34551SMiklos Szeredi 11569e34551SMiklos Szeredi /* size of cache */ 11669e34551SMiklos Szeredi loff_t size; 11769e34551SMiklos Szeredi 11869e34551SMiklos Szeredi /* position at end of cache (position of next entry) */ 11969e34551SMiklos Szeredi loff_t pos; 12069e34551SMiklos Szeredi 1213494927eSMiklos Szeredi /* version of the cache */ 1223494927eSMiklos Szeredi u64 version; 1233494927eSMiklos Szeredi 124*ab2257e9SMiklos Szeredi /* modification time of directory when cache was 125*ab2257e9SMiklos Szeredi * started */ 1267118883bSMiklos Szeredi struct timespec64 mtime; 1277118883bSMiklos Szeredi 128261aaba7SMiklos Szeredi /* iversion of directory when cache was started */ 129261aaba7SMiklos Szeredi u64 iversion; 130261aaba7SMiklos Szeredi 13169e34551SMiklos Szeredi /* protects above fields */ 13269e34551SMiklos Szeredi spinlock_t lock; 13369e34551SMiklos Szeredi } rdc; 134*ab2257e9SMiklos Szeredi }; 13569e34551SMiklos Szeredi 1364582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1374582a4abSFeng Shuo unsigned long state; 1385c672ab3SMiklos Szeredi 1395c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1405c672ab3SMiklos Szeredi struct mutex mutex; 1414582a4abSFeng Shuo }; 1424582a4abSFeng Shuo 1434582a4abSFeng Shuo /** FUSE inode state bits */ 1444582a4abSFeng Shuo enum { 1454582a4abSFeng Shuo /** Advise readdirplus */ 1464582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1476314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1486314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 14906a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 15006a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 151d8a5ba45SMiklos Szeredi }; 152d8a5ba45SMiklos Szeredi 153da5e4714SMiklos Szeredi struct fuse_conn; 154da5e4714SMiklos Szeredi 155b6aeadedSMiklos Szeredi /** FUSE specific file data */ 156b6aeadedSMiklos Szeredi struct fuse_file { 157da5e4714SMiklos Szeredi /** Fuse connection for this file */ 158da5e4714SMiklos Szeredi struct fuse_conn *fc; 159da5e4714SMiklos Szeredi 160b6aeadedSMiklos Szeredi /** Request reserved for flush and release */ 16133649c91SMiklos Szeredi struct fuse_req *reserved_req; 162b6aeadedSMiklos Szeredi 163acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 164acf99433STejun Heo u64 kh; 165acf99433STejun Heo 166b6aeadedSMiklos Szeredi /** File handle used by userspace */ 167b6aeadedSMiklos Szeredi u64 fh; 168c756e0a4SMiklos Szeredi 169da5e4714SMiklos Szeredi /** Node id of this file */ 170da5e4714SMiklos Szeredi u64 nodeid; 171da5e4714SMiklos Szeredi 172c756e0a4SMiklos Szeredi /** Refcount */ 1734e8c2eb5SElena Reshetova refcount_t count; 17493a8c3cdSMiklos Szeredi 175c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 176c7b7143cSMiklos Szeredi u32 open_flags; 177c7b7143cSMiklos Szeredi 17893a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 17993a8c3cdSMiklos Szeredi struct list_head write_entry; 18095668a69STejun Heo 1815d7bc7e8SMiklos Szeredi /* Readdir related */ 1825d7bc7e8SMiklos Szeredi struct { 1835d7bc7e8SMiklos Szeredi /* 1845d7bc7e8SMiklos Szeredi * Protects below fields against (crazy) parallel readdir on 1855d7bc7e8SMiklos Szeredi * same open file. Uncontended in the normal case. 1865d7bc7e8SMiklos Szeredi */ 1875d7bc7e8SMiklos Szeredi struct mutex lock; 1885d7bc7e8SMiklos Szeredi 1895d7bc7e8SMiklos Szeredi /* Dir stream position */ 1905d7bc7e8SMiklos Szeredi loff_t pos; 1915d7bc7e8SMiklos Szeredi 1925d7bc7e8SMiklos Szeredi /* Offset in cache */ 1935d7bc7e8SMiklos Szeredi loff_t cache_off; 1943494927eSMiklos Szeredi 1953494927eSMiklos Szeredi /* Version of cache we are reading */ 1963494927eSMiklos Szeredi u64 version; 1973494927eSMiklos Szeredi 1985d7bc7e8SMiklos Szeredi } readdir; 1995d7bc7e8SMiklos Szeredi 20095668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 20195668a69STejun Heo struct rb_node polled_node; 20295668a69STejun Heo 20395668a69STejun Heo /** Wait queue head for poll */ 20495668a69STejun Heo wait_queue_head_t poll_wait; 20537fb3a30SMiklos Szeredi 20637fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 20737fb3a30SMiklos Szeredi bool flock:1; 208b6aeadedSMiklos Szeredi }; 209b6aeadedSMiklos Szeredi 210334f485dSMiklos Szeredi /** One input argument of a request */ 211334f485dSMiklos Szeredi struct fuse_in_arg { 212334f485dSMiklos Szeredi unsigned size; 213334f485dSMiklos Szeredi const void *value; 214334f485dSMiklos Szeredi }; 215334f485dSMiklos Szeredi 216334f485dSMiklos Szeredi /** The request input */ 217334f485dSMiklos Szeredi struct fuse_in { 218334f485dSMiklos Szeredi /** The request header */ 219334f485dSMiklos Szeredi struct fuse_in_header h; 220334f485dSMiklos Szeredi 221334f485dSMiklos Szeredi /** True if the data for the last argument is in req->pages */ 222334f485dSMiklos Szeredi unsigned argpages:1; 223334f485dSMiklos Szeredi 224334f485dSMiklos Szeredi /** Number of arguments */ 225334f485dSMiklos Szeredi unsigned numargs; 226334f485dSMiklos Szeredi 227334f485dSMiklos Szeredi /** Array of arguments */ 228334f485dSMiklos Szeredi struct fuse_in_arg args[3]; 229334f485dSMiklos Szeredi }; 230334f485dSMiklos Szeredi 231334f485dSMiklos Szeredi /** One output argument of a request */ 232334f485dSMiklos Szeredi struct fuse_arg { 233334f485dSMiklos Szeredi unsigned size; 234334f485dSMiklos Szeredi void *value; 235334f485dSMiklos Szeredi }; 236334f485dSMiklos Szeredi 237334f485dSMiklos Szeredi /** The request output */ 238334f485dSMiklos Szeredi struct fuse_out { 239334f485dSMiklos Szeredi /** Header returned from userspace */ 240334f485dSMiklos Szeredi struct fuse_out_header h; 241334f485dSMiklos Szeredi 242095da6cbSMiklos Szeredi /* 243095da6cbSMiklos Szeredi * The following bitfields are not changed during the request 244095da6cbSMiklos Szeredi * processing 245095da6cbSMiklos Szeredi */ 246095da6cbSMiklos Szeredi 247334f485dSMiklos Szeredi /** Last argument is variable length (can be shorter than 248334f485dSMiklos Szeredi arg->size) */ 249334f485dSMiklos Szeredi unsigned argvar:1; 250334f485dSMiklos Szeredi 251334f485dSMiklos Szeredi /** Last argument is a list of pages to copy data to */ 252334f485dSMiklos Szeredi unsigned argpages:1; 253334f485dSMiklos Szeredi 254334f485dSMiklos Szeredi /** Zero partially or not copied pages */ 255334f485dSMiklos Szeredi unsigned page_zeroing:1; 256334f485dSMiklos Szeredi 257ce534fb0SMiklos Szeredi /** Pages may be replaced with new ones */ 258ce534fb0SMiklos Szeredi unsigned page_replace:1; 259ce534fb0SMiklos Szeredi 260334f485dSMiklos Szeredi /** Number or arguments */ 261334f485dSMiklos Szeredi unsigned numargs; 262334f485dSMiklos Szeredi 263334f485dSMiklos Szeredi /** Array of arguments */ 264f704dcb5SMiklos Szeredi struct fuse_arg args[2]; 265334f485dSMiklos Szeredi }; 266334f485dSMiklos Szeredi 267b2430d75SMaxim Patlasov /** FUSE page descriptor */ 268b2430d75SMaxim Patlasov struct fuse_page_desc { 269b2430d75SMaxim Patlasov unsigned int length; 270b2430d75SMaxim Patlasov unsigned int offset; 271b2430d75SMaxim Patlasov }; 272b2430d75SMaxim Patlasov 2737078187aSMiklos Szeredi struct fuse_args { 2747078187aSMiklos Szeredi struct { 2757078187aSMiklos Szeredi struct { 2767078187aSMiklos Szeredi uint32_t opcode; 2777078187aSMiklos Szeredi uint64_t nodeid; 2787078187aSMiklos Szeredi } h; 2797078187aSMiklos Szeredi unsigned numargs; 2807078187aSMiklos Szeredi struct fuse_in_arg args[3]; 2817078187aSMiklos Szeredi 2827078187aSMiklos Szeredi } in; 2837078187aSMiklos Szeredi struct { 2847078187aSMiklos Szeredi unsigned argvar:1; 2857078187aSMiklos Szeredi unsigned numargs; 2867078187aSMiklos Szeredi struct fuse_arg args[2]; 2877078187aSMiklos Szeredi } out; 2887078187aSMiklos Szeredi }; 2897078187aSMiklos Szeredi 2907078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2917078187aSMiklos Szeredi 29201e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 29301e9d11aSMaxim Patlasov struct fuse_io_priv { 294744742d6SSeth Forshee struct kref refcnt; 29501e9d11aSMaxim Patlasov int async; 29601e9d11aSMaxim Patlasov spinlock_t lock; 29701e9d11aSMaxim Patlasov unsigned reqs; 29801e9d11aSMaxim Patlasov ssize_t bytes; 29901e9d11aSMaxim Patlasov size_t size; 30001e9d11aSMaxim Patlasov __u64 offset; 30101e9d11aSMaxim Patlasov bool write; 30261c12b49SAshish Samant bool should_dirty; 30301e9d11aSMaxim Patlasov int err; 30401e9d11aSMaxim Patlasov struct kiocb *iocb; 3059d5722b7SChristoph Hellwig struct completion *done; 3067879c4e5SAshish Sangwan bool blocking; 30701e9d11aSMaxim Patlasov }; 30801e9d11aSMaxim Patlasov 309e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 310744742d6SSeth Forshee { \ 3111e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 312744742d6SSeth Forshee .async = 0, \ 313e1c0eecbSMiklos Szeredi .iocb = i, \ 314744742d6SSeth Forshee } 315744742d6SSeth Forshee 316334f485dSMiklos Szeredi /** 317825d6d33SMiklos Szeredi * Request flags 318825d6d33SMiklos Szeredi * 319825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 320825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 321825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 322825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 323825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 324825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 325825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 32633e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 32733e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 32833e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 32977cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 330825d6d33SMiklos Szeredi */ 331825d6d33SMiklos Szeredi enum fuse_req_flag { 332825d6d33SMiklos Szeredi FR_ISREPLY, 333825d6d33SMiklos Szeredi FR_FORCE, 334825d6d33SMiklos Szeredi FR_BACKGROUND, 335825d6d33SMiklos Szeredi FR_WAITING, 336825d6d33SMiklos Szeredi FR_ABORTED, 337825d6d33SMiklos Szeredi FR_INTERRUPTED, 338825d6d33SMiklos Szeredi FR_LOCKED, 33933e14b4dSMiklos Szeredi FR_PENDING, 34033e14b4dSMiklos Szeredi FR_SENT, 34133e14b4dSMiklos Szeredi FR_FINISHED, 34277cd9d48SMiklos Szeredi FR_PRIVATE, 343825d6d33SMiklos Szeredi }; 344825d6d33SMiklos Szeredi 345825d6d33SMiklos Szeredi /** 346334f485dSMiklos Szeredi * A request to the client 347dc00809aSMiklos Szeredi * 348dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 349dc00809aSMiklos Szeredi * - FR_ABORTED 350dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 351334f485dSMiklos Szeredi */ 352334f485dSMiklos Szeredi struct fuse_req { 353ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 354ce1d5a49SMiklos Szeredi fuse_conn */ 355334f485dSMiklos Szeredi struct list_head list; 356334f485dSMiklos Szeredi 357a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 358a4d27e75SMiklos Szeredi struct list_head intr_entry; 359a4d27e75SMiklos Szeredi 360334f485dSMiklos Szeredi /** refcount */ 361ec99f6d3SElena Reshetova refcount_t count; 362334f485dSMiklos Szeredi 363825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 364825d6d33SMiklos Szeredi unsigned long flags; 3659bc5dddaSMiklos Szeredi 366334f485dSMiklos Szeredi /** The request input */ 367334f485dSMiklos Szeredi struct fuse_in in; 368334f485dSMiklos Szeredi 369334f485dSMiklos Szeredi /** The request output */ 370334f485dSMiklos Szeredi struct fuse_out out; 371334f485dSMiklos Szeredi 372334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 373334f485dSMiklos Szeredi wait_queue_head_t waitq; 374334f485dSMiklos Szeredi 375334f485dSMiklos Szeredi /** Data for asynchronous requests */ 376334f485dSMiklos Szeredi union { 377b57d4264SMiklos Szeredi struct { 378b57d4264SMiklos Szeredi struct fuse_release_in in; 379baebccbeSMiklos Szeredi struct inode *inode; 380b57d4264SMiklos Szeredi } release; 3813ec870d5SMiklos Szeredi struct fuse_init_in init_in; 3823ec870d5SMiklos Szeredi struct fuse_init_out init_out; 38308cbf542STejun Heo struct cuse_init_in cuse_init_in; 3845c5c5e51SMiklos Szeredi struct { 3855c5c5e51SMiklos Szeredi struct fuse_read_in in; 3865c5c5e51SMiklos Szeredi u64 attr_ver; 3875c5c5e51SMiklos Szeredi } read; 388b25e82e5SMiklos Szeredi struct { 389b25e82e5SMiklos Szeredi struct fuse_write_in in; 390b25e82e5SMiklos Szeredi struct fuse_write_out out; 3918b284dc4SMiklos Szeredi struct fuse_req *next; 392b25e82e5SMiklos Szeredi } write; 3932d45ba38SMiklos Szeredi struct fuse_notify_retrieve_in retrieve_in; 394334f485dSMiklos Szeredi } misc; 395334f485dSMiklos Szeredi 396334f485dSMiklos Szeredi /** page vector */ 3974250c066SMaxim Patlasov struct page **pages; 3984250c066SMaxim Patlasov 399b2430d75SMaxim Patlasov /** page-descriptor vector */ 400b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 401b2430d75SMaxim Patlasov 4024250c066SMaxim Patlasov /** size of the 'pages' array */ 4034250c066SMaxim Patlasov unsigned max_pages; 4044250c066SMaxim Patlasov 4054250c066SMaxim Patlasov /** inline page vector */ 4064250c066SMaxim Patlasov struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 407334f485dSMiklos Szeredi 408b2430d75SMaxim Patlasov /** inline page-descriptor vector */ 409b2430d75SMaxim Patlasov struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 410b2430d75SMaxim Patlasov 411334f485dSMiklos Szeredi /** number of pages in vector */ 412334f485dSMiklos Szeredi unsigned num_pages; 413334f485dSMiklos Szeredi 414334f485dSMiklos Szeredi /** File used in the request (or NULL) */ 415c756e0a4SMiklos Szeredi struct fuse_file *ff; 41664c6d8edSMiklos Szeredi 4173be5a52bSMiklos Szeredi /** Inode used in the request or NULL */ 4183be5a52bSMiklos Szeredi struct inode *inode; 4193be5a52bSMiklos Szeredi 42001e9d11aSMaxim Patlasov /** AIO control block */ 42101e9d11aSMaxim Patlasov struct fuse_io_priv *io; 42201e9d11aSMaxim Patlasov 4233be5a52bSMiklos Szeredi /** Link on fi->writepages */ 4243be5a52bSMiklos Szeredi struct list_head writepages_entry; 4253be5a52bSMiklos Szeredi 42664c6d8edSMiklos Szeredi /** Request completion callback */ 42764c6d8edSMiklos Szeredi void (*end)(struct fuse_conn *, struct fuse_req *); 42833649c91SMiklos Szeredi 42933649c91SMiklos Szeredi /** Request is stolen from fuse_file->reserved_req */ 43033649c91SMiklos Szeredi struct file *stolen_file; 431334f485dSMiklos Szeredi }; 432334f485dSMiklos Szeredi 433f88996a9SMiklos Szeredi struct fuse_iqueue { 434e16714d8SMiklos Szeredi /** Connection established */ 435e16714d8SMiklos Szeredi unsigned connected; 436e16714d8SMiklos Szeredi 437f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 438f88996a9SMiklos Szeredi wait_queue_head_t waitq; 439f88996a9SMiklos Szeredi 440f88996a9SMiklos Szeredi /** The next unique request id */ 441f88996a9SMiklos Szeredi u64 reqctr; 442f88996a9SMiklos Szeredi 443f88996a9SMiklos Szeredi /** The list of pending requests */ 444f88996a9SMiklos Szeredi struct list_head pending; 445f88996a9SMiklos Szeredi 446f88996a9SMiklos Szeredi /** Pending interrupts */ 447f88996a9SMiklos Szeredi struct list_head interrupts; 448f88996a9SMiklos Szeredi 449f88996a9SMiklos Szeredi /** Queue of pending forgets */ 450f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 451f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 452f88996a9SMiklos Szeredi 453f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 454f88996a9SMiklos Szeredi int forget_batch; 455f88996a9SMiklos Szeredi 456f88996a9SMiklos Szeredi /** O_ASYNC requests */ 457f88996a9SMiklos Szeredi struct fasync_struct *fasync; 458f88996a9SMiklos Szeredi }; 459f88996a9SMiklos Szeredi 460be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 461be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 462be2ff42cSKirill Tkhai 4633a2b5b9cSMiklos Szeredi struct fuse_pqueue { 464e96edd94SMiklos Szeredi /** Connection established */ 465e96edd94SMiklos Szeredi unsigned connected; 466e96edd94SMiklos Szeredi 46745a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 46845a91cb1SMiklos Szeredi spinlock_t lock; 46945a91cb1SMiklos Szeredi 470be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 471be2ff42cSKirill Tkhai struct list_head *processing; 4723a2b5b9cSMiklos Szeredi 4733a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4743a2b5b9cSMiklos Szeredi struct list_head io; 4753a2b5b9cSMiklos Szeredi }; 4763a2b5b9cSMiklos Szeredi 477d8a5ba45SMiklos Szeredi /** 478cc080e9eSMiklos Szeredi * Fuse device instance 479cc080e9eSMiklos Szeredi */ 480cc080e9eSMiklos Szeredi struct fuse_dev { 481cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 482cc080e9eSMiklos Szeredi struct fuse_conn *fc; 483cc080e9eSMiklos Szeredi 484c3696046SMiklos Szeredi /** Processing queue */ 485c3696046SMiklos Szeredi struct fuse_pqueue pq; 486c3696046SMiklos Szeredi 487cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 488cc080e9eSMiklos Szeredi struct list_head entry; 489cc080e9eSMiklos Szeredi }; 490cc080e9eSMiklos Szeredi 491cc080e9eSMiklos Szeredi /** 492d8a5ba45SMiklos Szeredi * A Fuse connection. 493d8a5ba45SMiklos Szeredi * 494d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 495d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 496d8a5ba45SMiklos Szeredi * unmounted. 497d8a5ba45SMiklos Szeredi */ 498d8a5ba45SMiklos Szeredi struct fuse_conn { 499d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 500d7133114SMiklos Szeredi spinlock_t lock; 501d7133114SMiklos Szeredi 502bafa9654SMiklos Szeredi /** Refcount */ 503095fc40aSElena Reshetova refcount_t count; 504bafa9654SMiklos Szeredi 505c3696046SMiklos Szeredi /** Number of fuse_dev's */ 506c3696046SMiklos Szeredi atomic_t dev_count; 507c3696046SMiklos Szeredi 508dd3e2c55SAl Viro struct rcu_head rcu; 509dd3e2c55SAl Viro 510d8a5ba45SMiklos Szeredi /** The user id for this mount */ 511499dcf20SEric W. Biederman kuid_t user_id; 512d8a5ba45SMiklos Szeredi 51387729a55SMiklos Szeredi /** The group id for this mount */ 514499dcf20SEric W. Biederman kgid_t group_id; 51587729a55SMiklos Szeredi 5160b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 5170b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 5180b6e9ea0SSeth Forshee 5198cb08329SEric W. Biederman /** The user namespace for this mount */ 5208cb08329SEric W. Biederman struct user_namespace *user_ns; 5218cb08329SEric W. Biederman 522db50b96cSMiklos Szeredi /** Maximum read size */ 523db50b96cSMiklos Szeredi unsigned max_read; 524db50b96cSMiklos Szeredi 525413ef8cbSMiklos Szeredi /** Maximum write size */ 526413ef8cbSMiklos Szeredi unsigned max_write; 527413ef8cbSMiklos Szeredi 528f88996a9SMiklos Szeredi /** Input queue */ 529f88996a9SMiklos Szeredi struct fuse_iqueue iq; 530334f485dSMiklos Szeredi 531acf99433STejun Heo /** The next unique kernel file handle */ 532acf99433STejun Heo u64 khctr; 533acf99433STejun Heo 53495668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 53595668a69STejun Heo struct rb_root polled_files; 53695668a69STejun Heo 5377a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 5387a6d3c8bSCsaba Henk unsigned max_background; 5397a6d3c8bSCsaba Henk 5407a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 5417a6d3c8bSCsaba Henk unsigned congestion_threshold; 5427a6d3c8bSCsaba Henk 54308a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 54408a53cdcSMiklos Szeredi unsigned num_background; 54508a53cdcSMiklos Szeredi 546d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 547d12def1bSMiklos Szeredi unsigned active_background; 548d12def1bSMiklos Szeredi 549d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 550d12def1bSMiklos Szeredi struct list_head bg_queue; 551d12def1bSMiklos Szeredi 552ae2dffa3SKirill Tkhai /** Protects: max_background, congestion_threshold, num_background, 553ae2dffa3SKirill Tkhai * active_background, bg_queue, blocked */ 554ae2dffa3SKirill Tkhai spinlock_t bg_lock; 555ae2dffa3SKirill Tkhai 556796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 557796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 558796523fbSMaxim Patlasov int initialized; 559796523fbSMaxim Patlasov 56008a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 56108a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 56208a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 56308a53cdcSMiklos Szeredi int blocked; 56408a53cdcSMiklos Szeredi 56508a53cdcSMiklos Szeredi /** waitq for blocked connection */ 56608a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 56708a53cdcSMiklos Szeredi 568de5e3decSMiklos Szeredi /** waitq for reserved requests */ 569de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 570de5e3decSMiklos Szeredi 57169a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 57269a53bf2SMiklos Szeredi abort and device release */ 573095da6cbSMiklos Szeredi unsigned connected; 5741e9a4ed9SMiklos Szeredi 5753b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 5763b7008b2SSzymon Lukasz bool aborted; 5773b7008b2SSzymon Lukasz 578095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 579095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 580095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 581334f485dSMiklos Szeredi unsigned conn_error:1; 582334f485dSMiklos Szeredi 5830ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5840ec7ca41SMiklos Szeredi unsigned conn_init:1; 5850ec7ca41SMiklos Szeredi 5869cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5879cd68455SMiklos Szeredi unsigned async_read:1; 5889cd68455SMiklos Szeredi 5893b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 5903b7008b2SSzymon Lukasz unsigned abort_err:1; 5913b7008b2SSzymon Lukasz 5926ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5936ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5946ff958edSMiklos Szeredi 59533670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 59633670fa2SMiklos Szeredi unsigned export_support:1; 59733670fa2SMiklos Szeredi 598d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 599d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 600d5cd66c5SPavel Emelyanov 6015c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 6025c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 6035c672ab3SMiklos Szeredi 6045e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 6055e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 6065e940c1dSMiklos Szeredi 607095da6cbSMiklos Szeredi /* 608095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 609095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 610095da6cbSMiklos Szeredi */ 611095da6cbSMiklos Szeredi 6127678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 6137678ac50SAndrew Gallagher unsigned no_open:1; 6147678ac50SAndrew Gallagher 615b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 616b6aeadedSMiklos Szeredi unsigned no_fsync:1; 617b6aeadedSMiklos Szeredi 61882547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 61982547981SMiklos Szeredi unsigned no_fsyncdir:1; 62082547981SMiklos Szeredi 621b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 622b6aeadedSMiklos Szeredi unsigned no_flush:1; 623b6aeadedSMiklos Szeredi 62492a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 62592a8780eSMiklos Szeredi unsigned no_setxattr:1; 62692a8780eSMiklos Szeredi 62792a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 62892a8780eSMiklos Szeredi unsigned no_getxattr:1; 62992a8780eSMiklos Szeredi 63092a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 63192a8780eSMiklos Szeredi unsigned no_listxattr:1; 63292a8780eSMiklos Szeredi 63392a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 63492a8780eSMiklos Szeredi unsigned no_removexattr:1; 63592a8780eSMiklos Szeredi 63637fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 63771421259SMiklos Szeredi unsigned no_lock:1; 63871421259SMiklos Szeredi 63931d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 64031d40d74SMiklos Szeredi unsigned no_access:1; 64131d40d74SMiklos Szeredi 642fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 643fd72faacSMiklos Szeredi unsigned no_create:1; 644fd72faacSMiklos Szeredi 645a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 646a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 647a4d27e75SMiklos Szeredi 648b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 649b2d2272fSMiklos Szeredi unsigned no_bmap:1; 650b2d2272fSMiklos Szeredi 65195668a69STejun Heo /** Is poll not implemented by fs? */ 65295668a69STejun Heo unsigned no_poll:1; 65395668a69STejun Heo 65478bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 65578bb6cb9SMiklos Szeredi unsigned big_writes:1; 65678bb6cb9SMiklos Szeredi 657e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 658e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 659e0a43ddcSMiklos Szeredi 66037fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 66137fb3a30SMiklos Szeredi unsigned no_flock:1; 66237fb3a30SMiklos Szeredi 663519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 664519c6040SMiklos Szeredi unsigned no_fallocate:1; 665519c6040SMiklos Szeredi 6661560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6671560c974SMiklos Szeredi unsigned no_rename2:1; 6681560c974SMiklos Szeredi 66972d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 67072d0d248SBrian Foster unsigned auto_inval_data:1; 67172d0d248SBrian Foster 672634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6730b05b183SAnand V. Avati unsigned do_readdirplus:1; 6740b05b183SAnand V. Avati 675634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 676634734b6SEric Wong unsigned readdirplus_auto:1; 677634734b6SEric Wong 67860b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 67960b9df7aSMiklos Szeredi unsigned async_dio:1; 68060b9df7aSMiklos Szeredi 6810b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6820b5da8dbSRavishankar N unsigned no_lseek:1; 6830b5da8dbSRavishankar N 68460bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 68560bcc88aSSeth Forshee unsigned posix_acl:1; 68660bcc88aSSeth Forshee 68729433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 68829433a29SMiklos Szeredi unsigned default_permissions:1; 68929433a29SMiklos Szeredi 69029433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 69129433a29SMiklos Szeredi unsigned allow_other:1; 69229433a29SMiklos Szeredi 69388bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 69488bc7d50SNiels de Vos unsigned no_copy_file_range:1; 69588bc7d50SNiels de Vos 6960cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6970cd5b885SMiklos Szeredi atomic_t num_waiting; 6980cd5b885SMiklos Szeredi 69945714d65SMiklos Szeredi /** Negotiated minor version */ 70045714d65SMiklos Szeredi unsigned minor; 70145714d65SMiklos Szeredi 702bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 703bafa9654SMiklos Szeredi struct list_head entry; 704bafa9654SMiklos Szeredi 705b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 706b6f2fcbcSMiklos Szeredi dev_t dev; 707bafa9654SMiklos Szeredi 708bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 709bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 710bafa9654SMiklos Szeredi 711bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 712bafa9654SMiklos Szeredi int ctl_ndents; 713385a17bfSJeff Dike 7149c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 7159c8ef561SMiklos Szeredi u32 scramble_key[4]; 7160ec7ca41SMiklos Szeredi 7170ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 7180ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 7191fb69e78SMiklos Szeredi 7201fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 7211fb69e78SMiklos Szeredi u64 attr_version; 72243901aabSTejun Heo 72343901aabSTejun Heo /** Called on final put */ 72443901aabSTejun Heo void (*release)(struct fuse_conn *); 7253b463ae0SJohn Muir 7263b463ae0SJohn Muir /** Super block for this connection. */ 7273b463ae0SJohn Muir struct super_block *sb; 7283b463ae0SJohn Muir 7293b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 7303b463ae0SJohn Muir struct rw_semaphore killsb; 731cc080e9eSMiklos Szeredi 732cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 733cc080e9eSMiklos Szeredi struct list_head devices; 734d8a5ba45SMiklos Szeredi }; 735d8a5ba45SMiklos Szeredi 736d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 737d8a5ba45SMiklos Szeredi { 7386383bdaaSMiklos Szeredi return sb->s_fs_info; 739d8a5ba45SMiklos Szeredi } 740d8a5ba45SMiklos Szeredi 741d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 742d8a5ba45SMiklos Szeredi { 743d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 744d8a5ba45SMiklos Szeredi } 745d8a5ba45SMiklos Szeredi 746d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 747d8a5ba45SMiklos Szeredi { 748d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 749d8a5ba45SMiklos Szeredi } 750d8a5ba45SMiklos Szeredi 751d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 752d8a5ba45SMiklos Szeredi { 753d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 754d8a5ba45SMiklos Szeredi } 755d8a5ba45SMiklos Szeredi 756d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 757d123d8e1SMiklos Szeredi { 758d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 759d123d8e1SMiklos Szeredi } 760d123d8e1SMiklos Szeredi 761334f485dSMiklos Szeredi /** Device operations */ 7624b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 763334f485dSMiklos Szeredi 7644269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 7650ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 766dbd561d2SMiklos Szeredi 767d8a5ba45SMiklos Szeredi /** 7683b463ae0SJohn Muir * Inode to nodeid comparison. 7693b463ae0SJohn Muir */ 7703b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7713b463ae0SJohn Muir 7723b463ae0SJohn Muir /** 773e5e5558eSMiklos Szeredi * Get a filled in inode 774e5e5558eSMiklos Szeredi */ 775b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7761fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7771fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 778e5e5558eSMiklos Szeredi 77913983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 78033670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 78133670fa2SMiklos Szeredi 782e5e5558eSMiklos Szeredi /** 783e5e5558eSMiklos Szeredi * Send FORGET command 784e5e5558eSMiklos Szeredi */ 78507e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 786b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 787e5e5558eSMiklos Szeredi 78807e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 78907e77dcaSMiklos Szeredi 7900b05b183SAnand V. Avati /* Used by READDIRPLUS */ 7910b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 7920b05b183SAnand V. Avati 793e5e5558eSMiklos Szeredi /** 794361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 79504730fefSMiklos Szeredi */ 796a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 7972106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 79804730fefSMiklos Szeredi 79904730fefSMiklos Szeredi /** 80004730fefSMiklos Szeredi * Send OPEN or OPENDIR request 80104730fefSMiklos Szeredi */ 80291fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 80304730fefSMiklos Szeredi 804acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 805fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 806c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 807fd72faacSMiklos Szeredi 8088b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags); 809c756e0a4SMiklos Szeredi 81004730fefSMiklos Szeredi /** 81104730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 81204730fefSMiklos Szeredi */ 8138b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode); 81404730fefSMiklos Szeredi 81504730fefSMiklos Szeredi /** 81682547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 81782547981SMiklos Szeredi */ 81802c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 81902c24a82SJosef Bacik int datasync, int isdir); 82082547981SMiklos Szeredi 82182547981SMiklos Szeredi /** 82295668a69STejun Heo * Notify poll wakeup 82395668a69STejun Heo */ 82495668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 82595668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 82695668a69STejun Heo 82795668a69STejun Heo /** 8281779381dSMiklos Szeredi * Initialize file operations on a regular file 829b6aeadedSMiklos Szeredi */ 830b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 831b6aeadedSMiklos Szeredi 832b6aeadedSMiklos Szeredi /** 8331779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 834e5e5558eSMiklos Szeredi */ 835e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 836e5e5558eSMiklos Szeredi 837e5e5558eSMiklos Szeredi /** 8381779381dSMiklos Szeredi * Initialize inode and file operations on a directory 839e5e5558eSMiklos Szeredi */ 840e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 841e5e5558eSMiklos Szeredi 842e5e5558eSMiklos Szeredi /** 8431779381dSMiklos Szeredi * Initialize inode operations on a symlink 844e5e5558eSMiklos Szeredi */ 845e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 846e5e5558eSMiklos Szeredi 847e5e5558eSMiklos Szeredi /** 848e5e5558eSMiklos Szeredi * Change attributes of an inode 849e5e5558eSMiklos Szeredi */ 8501fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 8511fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 852e5e5558eSMiklos Szeredi 8533be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 8543be5a52bSMiklos Szeredi u64 attr_valid); 8553be5a52bSMiklos Szeredi 856e5e5558eSMiklos Szeredi /** 857334f485dSMiklos Szeredi * Initialize the client device 858334f485dSMiklos Szeredi */ 859334f485dSMiklos Szeredi int fuse_dev_init(void); 860334f485dSMiklos Szeredi 861334f485dSMiklos Szeredi /** 862334f485dSMiklos Szeredi * Cleanup the client device 863334f485dSMiklos Szeredi */ 864334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 865334f485dSMiklos Szeredi 866bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8677736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 868bafa9654SMiklos Szeredi 869334f485dSMiklos Szeredi /** 870334f485dSMiklos Szeredi * Allocate a request 871334f485dSMiklos Szeredi */ 8724250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 873334f485dSMiklos Szeredi 8744250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8753be5a52bSMiklos Szeredi 876334f485dSMiklos Szeredi /** 877334f485dSMiklos Szeredi * Free a request 878334f485dSMiklos Szeredi */ 879334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 880334f485dSMiklos Szeredi 881334f485dSMiklos Szeredi /** 882b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 883b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 884334f485dSMiklos Szeredi */ 885b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 8868b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 8878b41e671SMaxim Patlasov unsigned npages); 888b111c8c0SMaxim Patlasov 88936cf66edSMaxim Patlasov /* 89036cf66edSMaxim Patlasov * Increment reference count on request 89136cf66edSMaxim Patlasov */ 89236cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 89336cf66edSMaxim Patlasov 894b111c8c0SMaxim Patlasov /** 89533649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 89633649c91SMiklos Szeredi */ 897b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 898b111c8c0SMaxim Patlasov struct file *file); 89933649c91SMiklos Szeredi 90033649c91SMiklos Szeredi /** 901ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 902ce1d5a49SMiklos Szeredi * the request. 903334f485dSMiklos Szeredi */ 904334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 905334f485dSMiklos Szeredi 906334f485dSMiklos Szeredi /** 9077c352bdfSMiklos Szeredi * Send a request (synchronous) 908334f485dSMiklos Szeredi */ 909b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 910334f485dSMiklos Szeredi 911334f485dSMiklos Szeredi /** 9127078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 9137078187aSMiklos Szeredi */ 9147078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 9157078187aSMiklos Szeredi 9167078187aSMiklos Szeredi /** 917334f485dSMiklos Szeredi * Send a request in the background 918334f485dSMiklos Szeredi */ 919b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 92063825b4eSKirill Tkhai bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); 9213be5a52bSMiklos Szeredi 9225a5fb1eaSMiklos Szeredi /* Abort all requests */ 9233b7008b2SSzymon Lukasz void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); 924b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 92569a53bf2SMiklos Szeredi 9261e9a4ed9SMiklos Szeredi /** 927e5e5558eSMiklos Szeredi * Invalidate inode attributes 928e5e5558eSMiklos Szeredi */ 929e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 930bafa9654SMiklos Szeredi 931dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 932dbd561d2SMiklos Szeredi 933451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 934451418fcSAndrew Gallagher 935d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o); 936d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 937d123d8e1SMiklos Szeredi 938bafa9654SMiklos Szeredi /** 939bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 940bafa9654SMiklos Szeredi */ 941bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 942bafa9654SMiklos Szeredi 943bafa9654SMiklos Szeredi /** 9440d179aa5STejun Heo * Initialize fuse_conn 9450d179aa5STejun Heo */ 9468cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); 9470d179aa5STejun Heo 9480d179aa5STejun Heo /** 949bafa9654SMiklos Szeredi * Release reference to fuse_conn 950bafa9654SMiklos Szeredi */ 951bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 952bafa9654SMiklos Szeredi 953cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 954cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 955cc080e9eSMiklos Szeredi 956bafa9654SMiklos Szeredi /** 957bafa9654SMiklos Szeredi * Add connection to control filesystem 958bafa9654SMiklos Szeredi */ 959bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 960bafa9654SMiklos Szeredi 961bafa9654SMiklos Szeredi /** 962bafa9654SMiklos Szeredi * Remove connection from control filesystem 963bafa9654SMiklos Szeredi */ 964bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 965a5bfffacSTimo Savola 966a5bfffacSTimo Savola /** 967a5bfffacSTimo Savola * Is file type valid? 968a5bfffacSTimo Savola */ 969a5bfffacSTimo Savola int fuse_valid_type(int m); 970e57ac683SMiklos Szeredi 971e57ac683SMiklos Szeredi /** 972c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 973e57ac683SMiklos Szeredi */ 974c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 975f3332114SMiklos Szeredi 976f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 977bcb4be80SMiklos Szeredi 978703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 979703c7362SSeth Forshee 9805b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 9813be5a52bSMiklos Szeredi 9823be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9833be5a52bSMiklos Szeredi 9843be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9853be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9865c5c5e51SMiklos Szeredi 9875c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc); 98829d434b3STejun Heo 9893b463ae0SJohn Muir /** 9903b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9913b463ae0SJohn Muir */ 9923b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9933b463ae0SJohn Muir loff_t offset, loff_t len); 9943b463ae0SJohn Muir 9953b463ae0SJohn Muir /** 9963b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9973b463ae0SJohn Muir * the dentry matching parent/name. 998451d0f59SJohn Muir * 999451d0f59SJohn Muir * If the child_nodeid is non-zero and: 1000451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 1001451d0f59SJohn Muir * - is not a mount point 1002451d0f59SJohn Muir * - is a file or oan empty directory 1003451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 10043b463ae0SJohn Muir */ 10053b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 1006451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 10073b463ae0SJohn Muir 100808cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 100908cbf542STejun Heo bool isdir); 1010ea8cd333SPavel Emelyanov 1011ea8cd333SPavel Emelyanov /** 1012ea8cd333SPavel Emelyanov * fuse_direct_io() flags 1013ea8cd333SPavel Emelyanov */ 1014ea8cd333SPavel Emelyanov 1015ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 1016ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 1017ea8cd333SPavel Emelyanov 1018ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1019ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 1020ea8cd333SPavel Emelyanov 1021d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1022d22a943fSAl Viro loff_t *ppos, int flags); 102308cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 102408cbf542STejun Heo unsigned int flags); 1025b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 1026b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 1027076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 102808cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 102908cbf542STejun Heo 1030b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 1031b0aa7606SMaxim Patlasov 1032ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 10331e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1034a1d75f25SMiklos Szeredi 103562490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1036efb9fa9eSMaxim Patlasov struct file *file); 1037efb9fa9eSMaxim Patlasov 10389759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 10399759bd51SMiklos Szeredi 104063576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 104163576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 10425c672ab3SMiklos Szeredi 104360bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 104460bcc88aSSeth Forshee size_t size, int flags); 104560bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 104660bcc88aSSeth Forshee size_t size); 1047703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 104860bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 1049703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 105060bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 1051e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 105260bcc88aSSeth Forshee 105360bcc88aSSeth Forshee struct posix_acl; 105460bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 105560bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 1056703c7362SSeth Forshee 1057d123d8e1SMiklos Szeredi 1058d123d8e1SMiklos Szeredi /* readdir.c */ 1059d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 1060d123d8e1SMiklos Szeredi 106129d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 1062