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> 27d8a5ba45SMiklos Szeredi 28334f485dSMiklos Szeredi /** Max number of pages that can be used in a single read request */ 29334f485dSMiklos Szeredi #define FUSE_MAX_PAGES_PER_REQ 32 30334f485dSMiklos Szeredi 313be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 323be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 333be5a52bSMiklos Szeredi 341d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 351d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 361d3d752bSMiklos Szeredi 37bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 3879a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 39bafa9654SMiklos Szeredi 401e9a4ed9SMiklos Szeredi /** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem 411e9a4ed9SMiklos Szeredi module will check permissions based on the file mode. Otherwise no 421e9a4ed9SMiklos Szeredi permission checking is done in the kernel */ 431e9a4ed9SMiklos Szeredi #define FUSE_DEFAULT_PERMISSIONS (1 << 0) 441e9a4ed9SMiklos Szeredi 451e9a4ed9SMiklos Szeredi /** If the FUSE_ALLOW_OTHER flag is given, then not only the user 461e9a4ed9SMiklos Szeredi doing the mount will be allowed to access the filesystem */ 471e9a4ed9SMiklos Szeredi #define FUSE_ALLOW_OTHER (1 << 1) 481e9a4ed9SMiklos Szeredi 494250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */ 504250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1 514250c066SMaxim Patlasov 52bafa9654SMiklos Szeredi /** List of active connections */ 53bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 54bafa9654SMiklos Szeredi 55bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 56bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 57413ef8cbSMiklos Szeredi 5879a9d994SCsaba Henk /** Module parameters */ 5979a9d994SCsaba Henk extern unsigned max_user_bgreq; 6079a9d994SCsaba Henk extern unsigned max_user_congthresh; 6179a9d994SCsaba Henk 6207e77dcaSMiklos Szeredi /* One forget request */ 6307e77dcaSMiklos Szeredi struct fuse_forget_link { 6402c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 6507e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6607e77dcaSMiklos Szeredi }; 6707e77dcaSMiklos Szeredi 68d8a5ba45SMiklos Szeredi /** FUSE inode */ 69d8a5ba45SMiklos Szeredi struct fuse_inode { 70d8a5ba45SMiklos Szeredi /** Inode data */ 71d8a5ba45SMiklos Szeredi struct inode inode; 72d8a5ba45SMiklos Szeredi 73d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 74d8a5ba45SMiklos Szeredi * and kernel */ 75d8a5ba45SMiklos Szeredi u64 nodeid; 76d8a5ba45SMiklos Szeredi 779e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 789e6268dbSMiklos Szeredi u64 nlookup; 799e6268dbSMiklos Szeredi 80e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 8107e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 82e5e5558eSMiklos Szeredi 83d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 840a0898cfSMiklos Szeredi u64 i_time; 85ebc14c4dSMiklos 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 9693a8c3cdSMiklos Szeredi /** Files usable in writepage. Protected by fc->lock */ 9793a8c3cdSMiklos Szeredi struct list_head write_files; 983be5a52bSMiklos Szeredi 993be5a52bSMiklos Szeredi /** Writepages pending on truncate or fsync */ 1003be5a52bSMiklos Szeredi struct list_head queued_writes; 1013be5a52bSMiklos Szeredi 1023be5a52bSMiklos Szeredi /** Number of sent writes, a negative bias (FUSE_NOWRITE) 1033be5a52bSMiklos Szeredi * means more writes are blocked */ 1043be5a52bSMiklos Szeredi int writectr; 1053be5a52bSMiklos Szeredi 1063be5a52bSMiklos Szeredi /** Waitq for writepage completion */ 1073be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1083be5a52bSMiklos Szeredi 1093be5a52bSMiklos Szeredi /** List of writepage requestst (pending or sent) */ 1103be5a52bSMiklos Szeredi struct list_head writepages; 1114582a4abSFeng Shuo 1124582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1134582a4abSFeng Shuo unsigned long state; 1145c672ab3SMiklos Szeredi 1155c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1165c672ab3SMiklos Szeredi struct mutex mutex; 1174582a4abSFeng Shuo }; 1184582a4abSFeng Shuo 1194582a4abSFeng Shuo /** FUSE inode state bits */ 1204582a4abSFeng Shuo enum { 1214582a4abSFeng Shuo /** Advise readdirplus */ 1224582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1236314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1246314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 12506a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 12606a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 127d8a5ba45SMiklos Szeredi }; 128d8a5ba45SMiklos Szeredi 129da5e4714SMiklos Szeredi struct fuse_conn; 130da5e4714SMiklos Szeredi 131b6aeadedSMiklos Szeredi /** FUSE specific file data */ 132b6aeadedSMiklos Szeredi struct fuse_file { 133da5e4714SMiklos Szeredi /** Fuse connection for this file */ 134da5e4714SMiklos Szeredi struct fuse_conn *fc; 135da5e4714SMiklos Szeredi 136b6aeadedSMiklos Szeredi /** Request reserved for flush and release */ 13733649c91SMiklos Szeredi struct fuse_req *reserved_req; 138b6aeadedSMiklos Szeredi 139acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 140acf99433STejun Heo u64 kh; 141acf99433STejun Heo 142b6aeadedSMiklos Szeredi /** File handle used by userspace */ 143b6aeadedSMiklos Szeredi u64 fh; 144c756e0a4SMiklos Szeredi 145da5e4714SMiklos Szeredi /** Node id of this file */ 146da5e4714SMiklos Szeredi u64 nodeid; 147da5e4714SMiklos Szeredi 148c756e0a4SMiklos Szeredi /** Refcount */ 149c756e0a4SMiklos Szeredi atomic_t count; 15093a8c3cdSMiklos Szeredi 151c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 152c7b7143cSMiklos Szeredi u32 open_flags; 153c7b7143cSMiklos Szeredi 15493a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 15593a8c3cdSMiklos Szeredi struct list_head write_entry; 15695668a69STejun Heo 15795668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 15895668a69STejun Heo struct rb_node polled_node; 15995668a69STejun Heo 16095668a69STejun Heo /** Wait queue head for poll */ 16195668a69STejun Heo wait_queue_head_t poll_wait; 16237fb3a30SMiklos Szeredi 16337fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 16437fb3a30SMiklos Szeredi bool flock:1; 165b6aeadedSMiklos Szeredi }; 166b6aeadedSMiklos Szeredi 167334f485dSMiklos Szeredi /** One input argument of a request */ 168334f485dSMiklos Szeredi struct fuse_in_arg { 169334f485dSMiklos Szeredi unsigned size; 170334f485dSMiklos Szeredi const void *value; 171334f485dSMiklos Szeredi }; 172334f485dSMiklos Szeredi 173334f485dSMiklos Szeredi /** The request input */ 174334f485dSMiklos Szeredi struct fuse_in { 175334f485dSMiklos Szeredi /** The request header */ 176334f485dSMiklos Szeredi struct fuse_in_header h; 177334f485dSMiklos Szeredi 178334f485dSMiklos Szeredi /** True if the data for the last argument is in req->pages */ 179334f485dSMiklos Szeredi unsigned argpages:1; 180334f485dSMiklos Szeredi 181334f485dSMiklos Szeredi /** Number of arguments */ 182334f485dSMiklos Szeredi unsigned numargs; 183334f485dSMiklos Szeredi 184334f485dSMiklos Szeredi /** Array of arguments */ 185334f485dSMiklos Szeredi struct fuse_in_arg args[3]; 186334f485dSMiklos Szeredi }; 187334f485dSMiklos Szeredi 188334f485dSMiklos Szeredi /** One output argument of a request */ 189334f485dSMiklos Szeredi struct fuse_arg { 190334f485dSMiklos Szeredi unsigned size; 191334f485dSMiklos Szeredi void *value; 192334f485dSMiklos Szeredi }; 193334f485dSMiklos Szeredi 194334f485dSMiklos Szeredi /** The request output */ 195334f485dSMiklos Szeredi struct fuse_out { 196334f485dSMiklos Szeredi /** Header returned from userspace */ 197334f485dSMiklos Szeredi struct fuse_out_header h; 198334f485dSMiklos Szeredi 199095da6cbSMiklos Szeredi /* 200095da6cbSMiklos Szeredi * The following bitfields are not changed during the request 201095da6cbSMiklos Szeredi * processing 202095da6cbSMiklos Szeredi */ 203095da6cbSMiklos Szeredi 204334f485dSMiklos Szeredi /** Last argument is variable length (can be shorter than 205334f485dSMiklos Szeredi arg->size) */ 206334f485dSMiklos Szeredi unsigned argvar:1; 207334f485dSMiklos Szeredi 208334f485dSMiklos Szeredi /** Last argument is a list of pages to copy data to */ 209334f485dSMiklos Szeredi unsigned argpages:1; 210334f485dSMiklos Szeredi 211334f485dSMiklos Szeredi /** Zero partially or not copied pages */ 212334f485dSMiklos Szeredi unsigned page_zeroing:1; 213334f485dSMiklos Szeredi 214ce534fb0SMiklos Szeredi /** Pages may be replaced with new ones */ 215ce534fb0SMiklos Szeredi unsigned page_replace:1; 216ce534fb0SMiklos Szeredi 217334f485dSMiklos Szeredi /** Number or arguments */ 218334f485dSMiklos Szeredi unsigned numargs; 219334f485dSMiklos Szeredi 220334f485dSMiklos Szeredi /** Array of arguments */ 221f704dcb5SMiklos Szeredi struct fuse_arg args[2]; 222334f485dSMiklos Szeredi }; 223334f485dSMiklos Szeredi 224b2430d75SMaxim Patlasov /** FUSE page descriptor */ 225b2430d75SMaxim Patlasov struct fuse_page_desc { 226b2430d75SMaxim Patlasov unsigned int length; 227b2430d75SMaxim Patlasov unsigned int offset; 228b2430d75SMaxim Patlasov }; 229b2430d75SMaxim Patlasov 2307078187aSMiklos Szeredi struct fuse_args { 2317078187aSMiklos Szeredi struct { 2327078187aSMiklos Szeredi struct { 2337078187aSMiklos Szeredi uint32_t opcode; 2347078187aSMiklos Szeredi uint64_t nodeid; 2357078187aSMiklos Szeredi } h; 2367078187aSMiklos Szeredi unsigned numargs; 2377078187aSMiklos Szeredi struct fuse_in_arg args[3]; 2387078187aSMiklos Szeredi 2397078187aSMiklos Szeredi } in; 2407078187aSMiklos Szeredi struct { 2417078187aSMiklos Szeredi unsigned argvar:1; 2427078187aSMiklos Szeredi unsigned numargs; 2437078187aSMiklos Szeredi struct fuse_arg args[2]; 2447078187aSMiklos Szeredi } out; 2457078187aSMiklos Szeredi }; 2467078187aSMiklos Szeredi 2477078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2487078187aSMiklos Szeredi 24901e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 25001e9d11aSMaxim Patlasov struct fuse_io_priv { 251744742d6SSeth Forshee struct kref refcnt; 25201e9d11aSMaxim Patlasov int async; 25301e9d11aSMaxim Patlasov spinlock_t lock; 25401e9d11aSMaxim Patlasov unsigned reqs; 25501e9d11aSMaxim Patlasov ssize_t bytes; 25601e9d11aSMaxim Patlasov size_t size; 25701e9d11aSMaxim Patlasov __u64 offset; 25801e9d11aSMaxim Patlasov bool write; 25901e9d11aSMaxim Patlasov int err; 26001e9d11aSMaxim Patlasov struct kiocb *iocb; 26101e9d11aSMaxim Patlasov struct file *file; 2629d5722b7SChristoph Hellwig struct completion *done; 2637879c4e5SAshish Sangwan bool blocking; 26401e9d11aSMaxim Patlasov }; 26501e9d11aSMaxim Patlasov 266744742d6SSeth Forshee #define FUSE_IO_PRIV_SYNC(f) \ 267744742d6SSeth Forshee { \ 268744742d6SSeth Forshee .refcnt = { ATOMIC_INIT(1) }, \ 269744742d6SSeth Forshee .async = 0, \ 270744742d6SSeth Forshee .file = f, \ 271744742d6SSeth Forshee } 272744742d6SSeth Forshee 273334f485dSMiklos Szeredi /** 274825d6d33SMiklos Szeredi * Request flags 275825d6d33SMiklos Szeredi * 276825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 277825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 278825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 279825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 280825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 281825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 282825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 28333e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 28433e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 28533e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 28677cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 287825d6d33SMiklos Szeredi */ 288825d6d33SMiklos Szeredi enum fuse_req_flag { 289825d6d33SMiklos Szeredi FR_ISREPLY, 290825d6d33SMiklos Szeredi FR_FORCE, 291825d6d33SMiklos Szeredi FR_BACKGROUND, 292825d6d33SMiklos Szeredi FR_WAITING, 293825d6d33SMiklos Szeredi FR_ABORTED, 294825d6d33SMiklos Szeredi FR_INTERRUPTED, 295825d6d33SMiklos Szeredi FR_LOCKED, 29633e14b4dSMiklos Szeredi FR_PENDING, 29733e14b4dSMiklos Szeredi FR_SENT, 29833e14b4dSMiklos Szeredi FR_FINISHED, 29977cd9d48SMiklos Szeredi FR_PRIVATE, 300825d6d33SMiklos Szeredi }; 301825d6d33SMiklos Szeredi 302825d6d33SMiklos Szeredi /** 303334f485dSMiklos Szeredi * A request to the client 304dc00809aSMiklos Szeredi * 305dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 306dc00809aSMiklos Szeredi * - FR_ABORTED 307dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 308334f485dSMiklos Szeredi */ 309334f485dSMiklos Szeredi struct fuse_req { 310ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 311ce1d5a49SMiklos Szeredi fuse_conn */ 312334f485dSMiklos Szeredi struct list_head list; 313334f485dSMiklos Szeredi 314a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 315a4d27e75SMiklos Szeredi struct list_head intr_entry; 316a4d27e75SMiklos Szeredi 317334f485dSMiklos Szeredi /** refcount */ 318334f485dSMiklos Szeredi atomic_t count; 319334f485dSMiklos Szeredi 320a4d27e75SMiklos Szeredi /** Unique ID for the interrupt request */ 321a4d27e75SMiklos Szeredi u64 intr_unique; 322a4d27e75SMiklos Szeredi 323825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 324825d6d33SMiklos Szeredi unsigned long flags; 3259bc5dddaSMiklos Szeredi 326334f485dSMiklos Szeredi /** The request input */ 327334f485dSMiklos Szeredi struct fuse_in in; 328334f485dSMiklos Szeredi 329334f485dSMiklos Szeredi /** The request output */ 330334f485dSMiklos Szeredi struct fuse_out out; 331334f485dSMiklos Szeredi 332334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 333334f485dSMiklos Szeredi wait_queue_head_t waitq; 334334f485dSMiklos Szeredi 335334f485dSMiklos Szeredi /** Data for asynchronous requests */ 336334f485dSMiklos Szeredi union { 337b57d4264SMiklos Szeredi struct { 338b57d4264SMiklos Szeredi struct fuse_release_in in; 339baebccbeSMiklos Szeredi struct inode *inode; 340b57d4264SMiklos Szeredi } release; 3413ec870d5SMiklos Szeredi struct fuse_init_in init_in; 3423ec870d5SMiklos Szeredi struct fuse_init_out init_out; 34308cbf542STejun Heo struct cuse_init_in cuse_init_in; 3445c5c5e51SMiklos Szeredi struct { 3455c5c5e51SMiklos Szeredi struct fuse_read_in in; 3465c5c5e51SMiklos Szeredi u64 attr_ver; 3475c5c5e51SMiklos Szeredi } read; 348b25e82e5SMiklos Szeredi struct { 349b25e82e5SMiklos Szeredi struct fuse_write_in in; 350b25e82e5SMiklos Szeredi struct fuse_write_out out; 3518b284dc4SMiklos Szeredi struct fuse_req *next; 352b25e82e5SMiklos Szeredi } write; 3532d45ba38SMiklos Szeredi struct fuse_notify_retrieve_in retrieve_in; 354334f485dSMiklos Szeredi } misc; 355334f485dSMiklos Szeredi 356334f485dSMiklos Szeredi /** page vector */ 3574250c066SMaxim Patlasov struct page **pages; 3584250c066SMaxim Patlasov 359b2430d75SMaxim Patlasov /** page-descriptor vector */ 360b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 361b2430d75SMaxim Patlasov 3624250c066SMaxim Patlasov /** size of the 'pages' array */ 3634250c066SMaxim Patlasov unsigned max_pages; 3644250c066SMaxim Patlasov 3654250c066SMaxim Patlasov /** inline page vector */ 3664250c066SMaxim Patlasov struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 367334f485dSMiklos Szeredi 368b2430d75SMaxim Patlasov /** inline page-descriptor vector */ 369b2430d75SMaxim Patlasov struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 370b2430d75SMaxim Patlasov 371334f485dSMiklos Szeredi /** number of pages in vector */ 372334f485dSMiklos Szeredi unsigned num_pages; 373334f485dSMiklos Szeredi 374334f485dSMiklos Szeredi /** File used in the request (or NULL) */ 375c756e0a4SMiklos Szeredi struct fuse_file *ff; 37664c6d8edSMiklos Szeredi 3773be5a52bSMiklos Szeredi /** Inode used in the request or NULL */ 3783be5a52bSMiklos Szeredi struct inode *inode; 3793be5a52bSMiklos Szeredi 38001e9d11aSMaxim Patlasov /** AIO control block */ 38101e9d11aSMaxim Patlasov struct fuse_io_priv *io; 38201e9d11aSMaxim Patlasov 3833be5a52bSMiklos Szeredi /** Link on fi->writepages */ 3843be5a52bSMiklos Szeredi struct list_head writepages_entry; 3853be5a52bSMiklos Szeredi 38664c6d8edSMiklos Szeredi /** Request completion callback */ 38764c6d8edSMiklos Szeredi void (*end)(struct fuse_conn *, struct fuse_req *); 38833649c91SMiklos Szeredi 38933649c91SMiklos Szeredi /** Request is stolen from fuse_file->reserved_req */ 39033649c91SMiklos Szeredi struct file *stolen_file; 391334f485dSMiklos Szeredi }; 392334f485dSMiklos Szeredi 393f88996a9SMiklos Szeredi struct fuse_iqueue { 394e16714d8SMiklos Szeredi /** Connection established */ 395e16714d8SMiklos Szeredi unsigned connected; 396e16714d8SMiklos Szeredi 397f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 398f88996a9SMiklos Szeredi wait_queue_head_t waitq; 399f88996a9SMiklos Szeredi 400f88996a9SMiklos Szeredi /** The next unique request id */ 401f88996a9SMiklos Szeredi u64 reqctr; 402f88996a9SMiklos Szeredi 403f88996a9SMiklos Szeredi /** The list of pending requests */ 404f88996a9SMiklos Szeredi struct list_head pending; 405f88996a9SMiklos Szeredi 406f88996a9SMiklos Szeredi /** Pending interrupts */ 407f88996a9SMiklos Szeredi struct list_head interrupts; 408f88996a9SMiklos Szeredi 409f88996a9SMiklos Szeredi /** Queue of pending forgets */ 410f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 411f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 412f88996a9SMiklos Szeredi 413f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 414f88996a9SMiklos Szeredi int forget_batch; 415f88996a9SMiklos Szeredi 416f88996a9SMiklos Szeredi /** O_ASYNC requests */ 417f88996a9SMiklos Szeredi struct fasync_struct *fasync; 418f88996a9SMiklos Szeredi }; 419f88996a9SMiklos Szeredi 4203a2b5b9cSMiklos Szeredi struct fuse_pqueue { 421e96edd94SMiklos Szeredi /** Connection established */ 422e96edd94SMiklos Szeredi unsigned connected; 423e96edd94SMiklos Szeredi 42445a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 42545a91cb1SMiklos Szeredi spinlock_t lock; 42645a91cb1SMiklos Szeredi 4273a2b5b9cSMiklos Szeredi /** The list of requests being processed */ 4283a2b5b9cSMiklos Szeredi struct list_head processing; 4293a2b5b9cSMiklos Szeredi 4303a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4313a2b5b9cSMiklos Szeredi struct list_head io; 4323a2b5b9cSMiklos Szeredi }; 4333a2b5b9cSMiklos Szeredi 434d8a5ba45SMiklos Szeredi /** 435cc080e9eSMiklos Szeredi * Fuse device instance 436cc080e9eSMiklos Szeredi */ 437cc080e9eSMiklos Szeredi struct fuse_dev { 438cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 439cc080e9eSMiklos Szeredi struct fuse_conn *fc; 440cc080e9eSMiklos Szeredi 441c3696046SMiklos Szeredi /** Processing queue */ 442c3696046SMiklos Szeredi struct fuse_pqueue pq; 443c3696046SMiklos Szeredi 444cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 445cc080e9eSMiklos Szeredi struct list_head entry; 446cc080e9eSMiklos Szeredi }; 447cc080e9eSMiklos Szeredi 448cc080e9eSMiklos Szeredi /** 449d8a5ba45SMiklos Szeredi * A Fuse connection. 450d8a5ba45SMiklos Szeredi * 451d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 452d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 453d8a5ba45SMiklos Szeredi * unmounted. 454d8a5ba45SMiklos Szeredi */ 455d8a5ba45SMiklos Szeredi struct fuse_conn { 456d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 457d7133114SMiklos Szeredi spinlock_t lock; 458d7133114SMiklos Szeredi 459bafa9654SMiklos Szeredi /** Refcount */ 460bafa9654SMiklos Szeredi atomic_t count; 461bafa9654SMiklos Szeredi 462c3696046SMiklos Szeredi /** Number of fuse_dev's */ 463c3696046SMiklos Szeredi atomic_t dev_count; 464c3696046SMiklos Szeredi 465dd3e2c55SAl Viro struct rcu_head rcu; 466dd3e2c55SAl Viro 467d8a5ba45SMiklos Szeredi /** The user id for this mount */ 468499dcf20SEric W. Biederman kuid_t user_id; 469d8a5ba45SMiklos Szeredi 47087729a55SMiklos Szeredi /** The group id for this mount */ 471499dcf20SEric W. Biederman kgid_t group_id; 47287729a55SMiklos Szeredi 4731e9a4ed9SMiklos Szeredi /** The fuse mount flags for this mount */ 4741e9a4ed9SMiklos Szeredi unsigned flags; 4751e9a4ed9SMiklos Szeredi 476db50b96cSMiklos Szeredi /** Maximum read size */ 477db50b96cSMiklos Szeredi unsigned max_read; 478db50b96cSMiklos Szeredi 479413ef8cbSMiklos Szeredi /** Maximum write size */ 480413ef8cbSMiklos Szeredi unsigned max_write; 481413ef8cbSMiklos Szeredi 482f88996a9SMiklos Szeredi /** Input queue */ 483f88996a9SMiklos Szeredi struct fuse_iqueue iq; 484334f485dSMiklos Szeredi 485acf99433STejun Heo /** The next unique kernel file handle */ 486acf99433STejun Heo u64 khctr; 487acf99433STejun Heo 48895668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 48995668a69STejun Heo struct rb_root polled_files; 49095668a69STejun Heo 4917a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 4927a6d3c8bSCsaba Henk unsigned max_background; 4937a6d3c8bSCsaba Henk 4947a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 4957a6d3c8bSCsaba Henk unsigned congestion_threshold; 4967a6d3c8bSCsaba Henk 49708a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 49808a53cdcSMiklos Szeredi unsigned num_background; 49908a53cdcSMiklos Szeredi 500d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 501d12def1bSMiklos Szeredi unsigned active_background; 502d12def1bSMiklos Szeredi 503d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 504d12def1bSMiklos Szeredi struct list_head bg_queue; 505d12def1bSMiklos Szeredi 506796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 507796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 508796523fbSMaxim Patlasov int initialized; 509796523fbSMaxim Patlasov 51008a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 51108a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 51208a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 51308a53cdcSMiklos Szeredi int blocked; 51408a53cdcSMiklos Szeredi 51508a53cdcSMiklos Szeredi /** waitq for blocked connection */ 51608a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 51708a53cdcSMiklos Szeredi 518de5e3decSMiklos Szeredi /** waitq for reserved requests */ 519de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 520de5e3decSMiklos Szeredi 52169a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 52269a53bf2SMiklos Szeredi abort and device release */ 523095da6cbSMiklos Szeredi unsigned connected; 5241e9a4ed9SMiklos Szeredi 525095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 526095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 527095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 528334f485dSMiklos Szeredi unsigned conn_error:1; 529334f485dSMiklos Szeredi 5300ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5310ec7ca41SMiklos Szeredi unsigned conn_init:1; 5320ec7ca41SMiklos Szeredi 5339cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5349cd68455SMiklos Szeredi unsigned async_read:1; 5359cd68455SMiklos Szeredi 5366ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5376ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5386ff958edSMiklos Szeredi 53933670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 54033670fa2SMiklos Szeredi unsigned export_support:1; 54133670fa2SMiklos Szeredi 542a325f9b9STejun Heo /** Set if bdi is valid */ 543a325f9b9STejun Heo unsigned bdi_initialized:1; 544a325f9b9STejun Heo 545d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 546d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 547d5cd66c5SPavel Emelyanov 5485c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5495c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5505c672ab3SMiklos Szeredi 5515e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5525e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5535e940c1dSMiklos Szeredi 554095da6cbSMiklos Szeredi /* 555095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 556095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 557095da6cbSMiklos Szeredi */ 558095da6cbSMiklos Szeredi 5597678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 5607678ac50SAndrew Gallagher unsigned no_open:1; 5617678ac50SAndrew Gallagher 562b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 563b6aeadedSMiklos Szeredi unsigned no_fsync:1; 564b6aeadedSMiklos Szeredi 56582547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 56682547981SMiklos Szeredi unsigned no_fsyncdir:1; 56782547981SMiklos Szeredi 568b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 569b6aeadedSMiklos Szeredi unsigned no_flush:1; 570b6aeadedSMiklos Szeredi 57192a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 57292a8780eSMiklos Szeredi unsigned no_setxattr:1; 57392a8780eSMiklos Szeredi 57492a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 57592a8780eSMiklos Szeredi unsigned no_getxattr:1; 57692a8780eSMiklos Szeredi 57792a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 57892a8780eSMiklos Szeredi unsigned no_listxattr:1; 57992a8780eSMiklos Szeredi 58092a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 58192a8780eSMiklos Szeredi unsigned no_removexattr:1; 58292a8780eSMiklos Szeredi 58337fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 58471421259SMiklos Szeredi unsigned no_lock:1; 58571421259SMiklos Szeredi 58631d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 58731d40d74SMiklos Szeredi unsigned no_access:1; 58831d40d74SMiklos Szeredi 589fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 590fd72faacSMiklos Szeredi unsigned no_create:1; 591fd72faacSMiklos Szeredi 592a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 593a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 594a4d27e75SMiklos Szeredi 595b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 596b2d2272fSMiklos Szeredi unsigned no_bmap:1; 597b2d2272fSMiklos Szeredi 59895668a69STejun Heo /** Is poll not implemented by fs? */ 59995668a69STejun Heo unsigned no_poll:1; 60095668a69STejun Heo 60178bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 60278bb6cb9SMiklos Szeredi unsigned big_writes:1; 60378bb6cb9SMiklos Szeredi 604e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 605e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 606e0a43ddcSMiklos Szeredi 60737fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 60837fb3a30SMiklos Szeredi unsigned no_flock:1; 60937fb3a30SMiklos Szeredi 610519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 611519c6040SMiklos Szeredi unsigned no_fallocate:1; 612519c6040SMiklos Szeredi 6131560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6141560c974SMiklos Szeredi unsigned no_rename2:1; 6151560c974SMiklos Szeredi 61672d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 61772d0d248SBrian Foster unsigned auto_inval_data:1; 61872d0d248SBrian Foster 619634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6200b05b183SAnand V. Avati unsigned do_readdirplus:1; 6210b05b183SAnand V. Avati 622634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 623634734b6SEric Wong unsigned readdirplus_auto:1; 624634734b6SEric Wong 62560b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 62660b9df7aSMiklos Szeredi unsigned async_dio:1; 62760b9df7aSMiklos Szeredi 6280b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6290b5da8dbSRavishankar N unsigned no_lseek:1; 6300b5da8dbSRavishankar N 63160bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 63260bcc88aSSeth Forshee unsigned posix_acl:1; 63360bcc88aSSeth Forshee 6340cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6350cd5b885SMiklos Szeredi atomic_t num_waiting; 6360cd5b885SMiklos Szeredi 63745714d65SMiklos Szeredi /** Negotiated minor version */ 63845714d65SMiklos Szeredi unsigned minor; 63945714d65SMiklos Szeredi 640d8a5ba45SMiklos Szeredi /** Backing dev info */ 641d8a5ba45SMiklos Szeredi struct backing_dev_info bdi; 642f543f253SMiklos Szeredi 643bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 644bafa9654SMiklos Szeredi struct list_head entry; 645bafa9654SMiklos Szeredi 646b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 647b6f2fcbcSMiklos Szeredi dev_t dev; 648bafa9654SMiklos Szeredi 649bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 650bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 651bafa9654SMiklos Szeredi 652bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 653bafa9654SMiklos Szeredi int ctl_ndents; 654385a17bfSJeff Dike 6559c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 6569c8ef561SMiklos Szeredi u32 scramble_key[4]; 6570ec7ca41SMiklos Szeredi 6580ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 6590ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 6601fb69e78SMiklos Szeredi 6611fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 6621fb69e78SMiklos Szeredi u64 attr_version; 66343901aabSTejun Heo 66443901aabSTejun Heo /** Called on final put */ 66543901aabSTejun Heo void (*release)(struct fuse_conn *); 6663b463ae0SJohn Muir 6673b463ae0SJohn Muir /** Super block for this connection. */ 6683b463ae0SJohn Muir struct super_block *sb; 6693b463ae0SJohn Muir 6703b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 6713b463ae0SJohn Muir struct rw_semaphore killsb; 672cc080e9eSMiklos Szeredi 673cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 674cc080e9eSMiklos Szeredi struct list_head devices; 675d8a5ba45SMiklos Szeredi }; 676d8a5ba45SMiklos Szeredi 677d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 678d8a5ba45SMiklos Szeredi { 6796383bdaaSMiklos Szeredi return sb->s_fs_info; 680d8a5ba45SMiklos Szeredi } 681d8a5ba45SMiklos Szeredi 682d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 683d8a5ba45SMiklos Szeredi { 684d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 685d8a5ba45SMiklos Szeredi } 686d8a5ba45SMiklos Szeredi 687d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 688d8a5ba45SMiklos Szeredi { 689d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 690d8a5ba45SMiklos Szeredi } 691d8a5ba45SMiklos Szeredi 692d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 693d8a5ba45SMiklos Szeredi { 694d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 695d8a5ba45SMiklos Szeredi } 696d8a5ba45SMiklos Szeredi 697334f485dSMiklos Szeredi /** Device operations */ 6984b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 699334f485dSMiklos Szeredi 7004269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 701dbd561d2SMiklos Szeredi 702d8a5ba45SMiklos Szeredi /** 7033b463ae0SJohn Muir * Inode to nodeid comparison. 7043b463ae0SJohn Muir */ 7053b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7063b463ae0SJohn Muir 7073b463ae0SJohn Muir /** 708e5e5558eSMiklos Szeredi * Get a filled in inode 709e5e5558eSMiklos Szeredi */ 710b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7111fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7121fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 713e5e5558eSMiklos Szeredi 71413983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 71533670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 71633670fa2SMiklos Szeredi 717e5e5558eSMiklos Szeredi /** 718e5e5558eSMiklos Szeredi * Send FORGET command 719e5e5558eSMiklos Szeredi */ 72007e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 721b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 722e5e5558eSMiklos Szeredi 72307e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 72407e77dcaSMiklos Szeredi 7250b05b183SAnand V. Avati /* Used by READDIRPLUS */ 7260b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 7270b05b183SAnand V. Avati 728e5e5558eSMiklos Szeredi /** 729361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 73004730fefSMiklos Szeredi */ 731a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 7322106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 73304730fefSMiklos Szeredi 73404730fefSMiklos Szeredi /** 73504730fefSMiklos Szeredi * Send OPEN or OPENDIR request 73604730fefSMiklos Szeredi */ 73791fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 73804730fefSMiklos Szeredi 739acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 740c7b7143cSMiklos Szeredi struct fuse_file *fuse_file_get(struct fuse_file *ff); 741fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 742c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 743fd72faacSMiklos Szeredi 7448b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags); 745c756e0a4SMiklos Szeredi 74604730fefSMiklos Szeredi /** 74704730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 74804730fefSMiklos Szeredi */ 7498b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode); 75004730fefSMiklos Szeredi 75104730fefSMiklos Szeredi /** 75282547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 75382547981SMiklos Szeredi */ 75402c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 75502c24a82SJosef Bacik int datasync, int isdir); 75682547981SMiklos Szeredi 75782547981SMiklos Szeredi /** 75895668a69STejun Heo * Notify poll wakeup 75995668a69STejun Heo */ 76095668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 76195668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 76295668a69STejun Heo 76395668a69STejun Heo /** 7641779381dSMiklos Szeredi * Initialize file operations on a regular file 765b6aeadedSMiklos Szeredi */ 766b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 767b6aeadedSMiklos Szeredi 768b6aeadedSMiklos Szeredi /** 7691779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 770e5e5558eSMiklos Szeredi */ 771e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 772e5e5558eSMiklos Szeredi 773e5e5558eSMiklos Szeredi /** 7741779381dSMiklos Szeredi * Initialize inode and file operations on a directory 775e5e5558eSMiklos Szeredi */ 776e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 777e5e5558eSMiklos Szeredi 778e5e5558eSMiklos Szeredi /** 7791779381dSMiklos Szeredi * Initialize inode operations on a symlink 780e5e5558eSMiklos Szeredi */ 781e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 782e5e5558eSMiklos Szeredi 783e5e5558eSMiklos Szeredi /** 784e5e5558eSMiklos Szeredi * Change attributes of an inode 785e5e5558eSMiklos Szeredi */ 7861fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 7871fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 788e5e5558eSMiklos Szeredi 7893be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 7903be5a52bSMiklos Szeredi u64 attr_valid); 7913be5a52bSMiklos Szeredi 792e5e5558eSMiklos Szeredi /** 793334f485dSMiklos Szeredi * Initialize the client device 794334f485dSMiklos Szeredi */ 795334f485dSMiklos Szeredi int fuse_dev_init(void); 796334f485dSMiklos Szeredi 797334f485dSMiklos Szeredi /** 798334f485dSMiklos Szeredi * Cleanup the client device 799334f485dSMiklos Szeredi */ 800334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 801334f485dSMiklos Szeredi 802bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8037736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 804bafa9654SMiklos Szeredi 805334f485dSMiklos Szeredi /** 806334f485dSMiklos Szeredi * Allocate a request 807334f485dSMiklos Szeredi */ 8084250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 809334f485dSMiklos Szeredi 8104250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8113be5a52bSMiklos Szeredi 812334f485dSMiklos Szeredi /** 813334f485dSMiklos Szeredi * Free a request 814334f485dSMiklos Szeredi */ 815334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 816334f485dSMiklos Szeredi 817334f485dSMiklos Szeredi /** 818b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 819b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 820334f485dSMiklos Szeredi */ 821b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 8228b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 8238b41e671SMaxim Patlasov unsigned npages); 824b111c8c0SMaxim Patlasov 82536cf66edSMaxim Patlasov /* 82636cf66edSMaxim Patlasov * Increment reference count on request 82736cf66edSMaxim Patlasov */ 82836cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 82936cf66edSMaxim Patlasov 830b111c8c0SMaxim Patlasov /** 83133649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 83233649c91SMiklos Szeredi */ 833b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 834b111c8c0SMaxim Patlasov struct file *file); 83533649c91SMiklos Szeredi 83633649c91SMiklos Szeredi /** 837ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 838ce1d5a49SMiklos Szeredi * the request. 839334f485dSMiklos Szeredi */ 840334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 841334f485dSMiklos Szeredi 842334f485dSMiklos Szeredi /** 8437c352bdfSMiklos Szeredi * Send a request (synchronous) 844334f485dSMiklos Szeredi */ 845b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 846334f485dSMiklos Szeredi 847334f485dSMiklos Szeredi /** 8487078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 8497078187aSMiklos Szeredi */ 8507078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 8517078187aSMiklos Szeredi 8527078187aSMiklos Szeredi /** 853334f485dSMiklos Szeredi * Send a request in the background 854334f485dSMiklos Szeredi */ 855b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 856334f485dSMiklos Szeredi 857b93f858aSTejun Heo void fuse_request_send_background_locked(struct fuse_conn *fc, 858b93f858aSTejun Heo struct fuse_req *req); 8593be5a52bSMiklos Szeredi 8605a5fb1eaSMiklos Szeredi /* Abort all requests */ 86169a53bf2SMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 86269a53bf2SMiklos Szeredi 8631e9a4ed9SMiklos Szeredi /** 864e5e5558eSMiklos Szeredi * Invalidate inode attributes 865e5e5558eSMiklos Szeredi */ 866e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 867bafa9654SMiklos Szeredi 868dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 869dbd561d2SMiklos Szeredi 870451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 871451418fcSAndrew Gallagher 872bafa9654SMiklos Szeredi /** 873bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 874bafa9654SMiklos Szeredi */ 875bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 876bafa9654SMiklos Szeredi 877bafa9654SMiklos Szeredi /** 8780d179aa5STejun Heo * Initialize fuse_conn 8790d179aa5STejun Heo */ 880a325f9b9STejun Heo void fuse_conn_init(struct fuse_conn *fc); 8810d179aa5STejun Heo 8820d179aa5STejun Heo /** 883bafa9654SMiklos Szeredi * Release reference to fuse_conn 884bafa9654SMiklos Szeredi */ 885bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 886bafa9654SMiklos Szeredi 887cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 888cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 889cc080e9eSMiklos Szeredi 890bafa9654SMiklos Szeredi /** 891bafa9654SMiklos Szeredi * Add connection to control filesystem 892bafa9654SMiklos Szeredi */ 893bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 894bafa9654SMiklos Szeredi 895bafa9654SMiklos Szeredi /** 896bafa9654SMiklos Szeredi * Remove connection from control filesystem 897bafa9654SMiklos Szeredi */ 898bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 899a5bfffacSTimo Savola 900a5bfffacSTimo Savola /** 901a5bfffacSTimo Savola * Is file type valid? 902a5bfffacSTimo Savola */ 903a5bfffacSTimo Savola int fuse_valid_type(int m); 904e57ac683SMiklos Szeredi 905e57ac683SMiklos Szeredi /** 906c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 907e57ac683SMiklos Szeredi */ 908c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 909f3332114SMiklos Szeredi 910f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 911bcb4be80SMiklos Szeredi 912*703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 913*703c7362SSeth Forshee 914bcb4be80SMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct kstat *stat, 915bcb4be80SMiklos Szeredi struct file *file, bool *refreshed); 9163be5a52bSMiklos Szeredi 9173be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9183be5a52bSMiklos Szeredi 9193be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9203be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9215c5c5e51SMiklos Szeredi 9225c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc); 92329d434b3STejun Heo 9243b463ae0SJohn Muir /** 9253b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9263b463ae0SJohn Muir */ 9273b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9283b463ae0SJohn Muir loff_t offset, loff_t len); 9293b463ae0SJohn Muir 9303b463ae0SJohn Muir /** 9313b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9323b463ae0SJohn Muir * the dentry matching parent/name. 933451d0f59SJohn Muir * 934451d0f59SJohn Muir * If the child_nodeid is non-zero and: 935451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 936451d0f59SJohn Muir * - is not a mount point 937451d0f59SJohn Muir * - is a file or oan empty directory 938451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 9393b463ae0SJohn Muir */ 9403b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 941451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 9423b463ae0SJohn Muir 94308cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 94408cbf542STejun Heo bool isdir); 945ea8cd333SPavel Emelyanov 946ea8cd333SPavel Emelyanov /** 947ea8cd333SPavel Emelyanov * fuse_direct_io() flags 948ea8cd333SPavel Emelyanov */ 949ea8cd333SPavel Emelyanov 950ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 951ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 952ea8cd333SPavel Emelyanov 953ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 954ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 955ea8cd333SPavel Emelyanov 956d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 957d22a943fSAl Viro loff_t *ppos, int flags); 95808cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 95908cbf542STejun Heo unsigned int flags); 960b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 961b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 96208cbf542STejun Heo unsigned fuse_file_poll(struct file *file, poll_table *wait); 96308cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 96408cbf542STejun Heo 965b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 966b0aa7606SMaxim Patlasov 967ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 9681e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 969a1d75f25SMiklos Szeredi 970efb9fa9eSMaxim Patlasov int fuse_do_setattr(struct inode *inode, struct iattr *attr, 971efb9fa9eSMaxim Patlasov struct file *file); 972efb9fa9eSMaxim Patlasov 9739759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 9749759bd51SMiklos Szeredi 9755c672ab3SMiklos Szeredi void fuse_unlock_inode(struct inode *inode); 9765c672ab3SMiklos Szeredi void fuse_lock_inode(struct inode *inode); 9775c672ab3SMiklos Szeredi 97860bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 97960bcc88aSSeth Forshee size_t size, int flags); 98060bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 98160bcc88aSSeth Forshee size_t size); 982*703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 98360bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 984*703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 98560bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 98660bcc88aSSeth Forshee 98760bcc88aSSeth Forshee struct posix_acl; 98860bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 98960bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 990*703c7362SSeth Forshee 99129d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 992