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> 29d8a5ba45SMiklos Szeredi 30334f485dSMiklos Szeredi /** Max number of pages that can be used in a single read request */ 31334f485dSMiklos Szeredi #define FUSE_MAX_PAGES_PER_REQ 32 32334f485dSMiklos Szeredi 333be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 343be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 353be5a52bSMiklos Szeredi 361d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 371d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 381d3d752bSMiklos Szeredi 39bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4079a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 41bafa9654SMiklos Szeredi 424250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */ 434250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1 444250c066SMaxim Patlasov 45bafa9654SMiklos Szeredi /** List of active connections */ 46bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 47bafa9654SMiklos Szeredi 48bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 49bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 50413ef8cbSMiklos Szeredi 5179a9d994SCsaba Henk /** Module parameters */ 5279a9d994SCsaba Henk extern unsigned max_user_bgreq; 5379a9d994SCsaba Henk extern unsigned max_user_congthresh; 5479a9d994SCsaba Henk 5507e77dcaSMiklos Szeredi /* One forget request */ 5607e77dcaSMiklos Szeredi struct fuse_forget_link { 5702c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 5807e77dcaSMiklos Szeredi struct fuse_forget_link *next; 5907e77dcaSMiklos Szeredi }; 6007e77dcaSMiklos Szeredi 61d8a5ba45SMiklos Szeredi /** FUSE inode */ 62d8a5ba45SMiklos Szeredi struct fuse_inode { 63d8a5ba45SMiklos Szeredi /** Inode data */ 64d8a5ba45SMiklos Szeredi struct inode inode; 65d8a5ba45SMiklos Szeredi 66d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 67d8a5ba45SMiklos Szeredi * and kernel */ 68d8a5ba45SMiklos Szeredi u64 nodeid; 69d8a5ba45SMiklos Szeredi 709e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 719e6268dbSMiklos Szeredi u64 nlookup; 729e6268dbSMiklos Szeredi 73e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7407e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 75e5e5558eSMiklos Szeredi 76d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 770a0898cfSMiklos Szeredi u64 i_time; 78ebc14c4dSMiklos Szeredi 79ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 80ebc14c4dSMiklos Szeredi preserve the original mode */ 81541af6a0SAl Viro umode_t orig_i_mode; 821fb69e78SMiklos Szeredi 8345c72cd7SPavel Shilovsky /** 64 bit inode number */ 8445c72cd7SPavel Shilovsky u64 orig_ino; 8545c72cd7SPavel Shilovsky 861fb69e78SMiklos Szeredi /** Version of last attribute change */ 871fb69e78SMiklos Szeredi u64 attr_version; 8893a8c3cdSMiklos Szeredi 8993a8c3cdSMiklos Szeredi /** Files usable in writepage. Protected by fc->lock */ 9093a8c3cdSMiklos Szeredi struct list_head write_files; 913be5a52bSMiklos Szeredi 923be5a52bSMiklos Szeredi /** Writepages pending on truncate or fsync */ 933be5a52bSMiklos Szeredi struct list_head queued_writes; 943be5a52bSMiklos Szeredi 953be5a52bSMiklos Szeredi /** Number of sent writes, a negative bias (FUSE_NOWRITE) 963be5a52bSMiklos Szeredi * means more writes are blocked */ 973be5a52bSMiklos Szeredi int writectr; 983be5a52bSMiklos Szeredi 993be5a52bSMiklos Szeredi /** Waitq for writepage completion */ 1003be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1013be5a52bSMiklos Szeredi 1023be5a52bSMiklos Szeredi /** List of writepage requestst (pending or sent) */ 1033be5a52bSMiklos Szeredi struct list_head writepages; 1044582a4abSFeng Shuo 1054582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1064582a4abSFeng Shuo unsigned long state; 1075c672ab3SMiklos Szeredi 1085c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1095c672ab3SMiklos Szeredi struct mutex mutex; 1104582a4abSFeng Shuo }; 1114582a4abSFeng Shuo 1124582a4abSFeng Shuo /** FUSE inode state bits */ 1134582a4abSFeng Shuo enum { 1144582a4abSFeng Shuo /** Advise readdirplus */ 1154582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1166314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1176314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 11806a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 11906a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 120d8a5ba45SMiklos Szeredi }; 121d8a5ba45SMiklos Szeredi 122da5e4714SMiklos Szeredi struct fuse_conn; 123da5e4714SMiklos Szeredi 124b6aeadedSMiklos Szeredi /** FUSE specific file data */ 125b6aeadedSMiklos Szeredi struct fuse_file { 126da5e4714SMiklos Szeredi /** Fuse connection for this file */ 127da5e4714SMiklos Szeredi struct fuse_conn *fc; 128da5e4714SMiklos Szeredi 129b6aeadedSMiklos Szeredi /** Request reserved for flush and release */ 13033649c91SMiklos Szeredi struct fuse_req *reserved_req; 131b6aeadedSMiklos Szeredi 132acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 133acf99433STejun Heo u64 kh; 134acf99433STejun Heo 135b6aeadedSMiklos Szeredi /** File handle used by userspace */ 136b6aeadedSMiklos Szeredi u64 fh; 137c756e0a4SMiklos Szeredi 138da5e4714SMiklos Szeredi /** Node id of this file */ 139da5e4714SMiklos Szeredi u64 nodeid; 140da5e4714SMiklos Szeredi 141c756e0a4SMiklos Szeredi /** Refcount */ 1424e8c2eb5SElena Reshetova refcount_t count; 14393a8c3cdSMiklos Szeredi 144c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 145c7b7143cSMiklos Szeredi u32 open_flags; 146c7b7143cSMiklos Szeredi 14793a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 14893a8c3cdSMiklos Szeredi struct list_head write_entry; 14995668a69STejun Heo 15095668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 15195668a69STejun Heo struct rb_node polled_node; 15295668a69STejun Heo 15395668a69STejun Heo /** Wait queue head for poll */ 15495668a69STejun Heo wait_queue_head_t poll_wait; 15537fb3a30SMiklos Szeredi 15637fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 15737fb3a30SMiklos Szeredi bool flock:1; 158b6aeadedSMiklos Szeredi }; 159b6aeadedSMiklos Szeredi 160334f485dSMiklos Szeredi /** One input argument of a request */ 161334f485dSMiklos Szeredi struct fuse_in_arg { 162334f485dSMiklos Szeredi unsigned size; 163334f485dSMiklos Szeredi const void *value; 164334f485dSMiklos Szeredi }; 165334f485dSMiklos Szeredi 166334f485dSMiklos Szeredi /** The request input */ 167334f485dSMiklos Szeredi struct fuse_in { 168334f485dSMiklos Szeredi /** The request header */ 169334f485dSMiklos Szeredi struct fuse_in_header h; 170334f485dSMiklos Szeredi 171334f485dSMiklos Szeredi /** True if the data for the last argument is in req->pages */ 172334f485dSMiklos Szeredi unsigned argpages:1; 173334f485dSMiklos Szeredi 174334f485dSMiklos Szeredi /** Number of arguments */ 175334f485dSMiklos Szeredi unsigned numargs; 176334f485dSMiklos Szeredi 177334f485dSMiklos Szeredi /** Array of arguments */ 178334f485dSMiklos Szeredi struct fuse_in_arg args[3]; 179334f485dSMiklos Szeredi }; 180334f485dSMiklos Szeredi 181334f485dSMiklos Szeredi /** One output argument of a request */ 182334f485dSMiklos Szeredi struct fuse_arg { 183334f485dSMiklos Szeredi unsigned size; 184334f485dSMiklos Szeredi void *value; 185334f485dSMiklos Szeredi }; 186334f485dSMiklos Szeredi 187334f485dSMiklos Szeredi /** The request output */ 188334f485dSMiklos Szeredi struct fuse_out { 189334f485dSMiklos Szeredi /** Header returned from userspace */ 190334f485dSMiklos Szeredi struct fuse_out_header h; 191334f485dSMiklos Szeredi 192095da6cbSMiklos Szeredi /* 193095da6cbSMiklos Szeredi * The following bitfields are not changed during the request 194095da6cbSMiklos Szeredi * processing 195095da6cbSMiklos Szeredi */ 196095da6cbSMiklos Szeredi 197334f485dSMiklos Szeredi /** Last argument is variable length (can be shorter than 198334f485dSMiklos Szeredi arg->size) */ 199334f485dSMiklos Szeredi unsigned argvar:1; 200334f485dSMiklos Szeredi 201334f485dSMiklos Szeredi /** Last argument is a list of pages to copy data to */ 202334f485dSMiklos Szeredi unsigned argpages:1; 203334f485dSMiklos Szeredi 204334f485dSMiklos Szeredi /** Zero partially or not copied pages */ 205334f485dSMiklos Szeredi unsigned page_zeroing:1; 206334f485dSMiklos Szeredi 207ce534fb0SMiklos Szeredi /** Pages may be replaced with new ones */ 208ce534fb0SMiklos Szeredi unsigned page_replace:1; 209ce534fb0SMiklos Szeredi 210334f485dSMiklos Szeredi /** Number or arguments */ 211334f485dSMiklos Szeredi unsigned numargs; 212334f485dSMiklos Szeredi 213334f485dSMiklos Szeredi /** Array of arguments */ 214f704dcb5SMiklos Szeredi struct fuse_arg args[2]; 215334f485dSMiklos Szeredi }; 216334f485dSMiklos Szeredi 217b2430d75SMaxim Patlasov /** FUSE page descriptor */ 218b2430d75SMaxim Patlasov struct fuse_page_desc { 219b2430d75SMaxim Patlasov unsigned int length; 220b2430d75SMaxim Patlasov unsigned int offset; 221b2430d75SMaxim Patlasov }; 222b2430d75SMaxim Patlasov 2237078187aSMiklos Szeredi struct fuse_args { 2247078187aSMiklos Szeredi struct { 2257078187aSMiklos Szeredi struct { 2267078187aSMiklos Szeredi uint32_t opcode; 2277078187aSMiklos Szeredi uint64_t nodeid; 2287078187aSMiklos Szeredi } h; 2297078187aSMiklos Szeredi unsigned numargs; 2307078187aSMiklos Szeredi struct fuse_in_arg args[3]; 2317078187aSMiklos Szeredi 2327078187aSMiklos Szeredi } in; 2337078187aSMiklos Szeredi struct { 2347078187aSMiklos Szeredi unsigned argvar:1; 2357078187aSMiklos Szeredi unsigned numargs; 2367078187aSMiklos Szeredi struct fuse_arg args[2]; 2377078187aSMiklos Szeredi } out; 2387078187aSMiklos Szeredi }; 2397078187aSMiklos Szeredi 2407078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2417078187aSMiklos Szeredi 24201e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 24301e9d11aSMaxim Patlasov struct fuse_io_priv { 244744742d6SSeth Forshee struct kref refcnt; 24501e9d11aSMaxim Patlasov int async; 24601e9d11aSMaxim Patlasov spinlock_t lock; 24701e9d11aSMaxim Patlasov unsigned reqs; 24801e9d11aSMaxim Patlasov ssize_t bytes; 24901e9d11aSMaxim Patlasov size_t size; 25001e9d11aSMaxim Patlasov __u64 offset; 25101e9d11aSMaxim Patlasov bool write; 252*61c12b49SAshish Samant bool should_dirty; 25301e9d11aSMaxim Patlasov int err; 25401e9d11aSMaxim Patlasov struct kiocb *iocb; 25501e9d11aSMaxim Patlasov struct file *file; 2569d5722b7SChristoph Hellwig struct completion *done; 2577879c4e5SAshish Sangwan bool blocking; 25801e9d11aSMaxim Patlasov }; 25901e9d11aSMaxim Patlasov 260744742d6SSeth Forshee #define FUSE_IO_PRIV_SYNC(f) \ 261744742d6SSeth Forshee { \ 2621e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 263744742d6SSeth Forshee .async = 0, \ 264744742d6SSeth Forshee .file = f, \ 265744742d6SSeth Forshee } 266744742d6SSeth Forshee 267334f485dSMiklos Szeredi /** 268825d6d33SMiklos Szeredi * Request flags 269825d6d33SMiklos Szeredi * 270825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 271825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 272825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 273825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 274825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 275825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 276825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 27733e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 27833e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 27933e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 28077cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 281825d6d33SMiklos Szeredi */ 282825d6d33SMiklos Szeredi enum fuse_req_flag { 283825d6d33SMiklos Szeredi FR_ISREPLY, 284825d6d33SMiklos Szeredi FR_FORCE, 285825d6d33SMiklos Szeredi FR_BACKGROUND, 286825d6d33SMiklos Szeredi FR_WAITING, 287825d6d33SMiklos Szeredi FR_ABORTED, 288825d6d33SMiklos Szeredi FR_INTERRUPTED, 289825d6d33SMiklos Szeredi FR_LOCKED, 29033e14b4dSMiklos Szeredi FR_PENDING, 29133e14b4dSMiklos Szeredi FR_SENT, 29233e14b4dSMiklos Szeredi FR_FINISHED, 29377cd9d48SMiklos Szeredi FR_PRIVATE, 294825d6d33SMiklos Szeredi }; 295825d6d33SMiklos Szeredi 296825d6d33SMiklos Szeredi /** 297334f485dSMiklos Szeredi * A request to the client 298dc00809aSMiklos Szeredi * 299dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 300dc00809aSMiklos Szeredi * - FR_ABORTED 301dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 302334f485dSMiklos Szeredi */ 303334f485dSMiklos Szeredi struct fuse_req { 304ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 305ce1d5a49SMiklos Szeredi fuse_conn */ 306334f485dSMiklos Szeredi struct list_head list; 307334f485dSMiklos Szeredi 308a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 309a4d27e75SMiklos Szeredi struct list_head intr_entry; 310a4d27e75SMiklos Szeredi 311334f485dSMiklos Szeredi /** refcount */ 312ec99f6d3SElena Reshetova refcount_t count; 313334f485dSMiklos Szeredi 314a4d27e75SMiklos Szeredi /** Unique ID for the interrupt request */ 315a4d27e75SMiklos Szeredi u64 intr_unique; 316a4d27e75SMiklos Szeredi 317825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 318825d6d33SMiklos Szeredi unsigned long flags; 3199bc5dddaSMiklos Szeredi 320334f485dSMiklos Szeredi /** The request input */ 321334f485dSMiklos Szeredi struct fuse_in in; 322334f485dSMiklos Szeredi 323334f485dSMiklos Szeredi /** The request output */ 324334f485dSMiklos Szeredi struct fuse_out out; 325334f485dSMiklos Szeredi 326334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 327334f485dSMiklos Szeredi wait_queue_head_t waitq; 328334f485dSMiklos Szeredi 329334f485dSMiklos Szeredi /** Data for asynchronous requests */ 330334f485dSMiklos Szeredi union { 331b57d4264SMiklos Szeredi struct { 332b57d4264SMiklos Szeredi struct fuse_release_in in; 333baebccbeSMiklos Szeredi struct inode *inode; 334b57d4264SMiklos Szeredi } release; 3353ec870d5SMiklos Szeredi struct fuse_init_in init_in; 3363ec870d5SMiklos Szeredi struct fuse_init_out init_out; 33708cbf542STejun Heo struct cuse_init_in cuse_init_in; 3385c5c5e51SMiklos Szeredi struct { 3395c5c5e51SMiklos Szeredi struct fuse_read_in in; 3405c5c5e51SMiklos Szeredi u64 attr_ver; 3415c5c5e51SMiklos Szeredi } read; 342b25e82e5SMiklos Szeredi struct { 343b25e82e5SMiklos Szeredi struct fuse_write_in in; 344b25e82e5SMiklos Szeredi struct fuse_write_out out; 3458b284dc4SMiklos Szeredi struct fuse_req *next; 346b25e82e5SMiklos Szeredi } write; 3472d45ba38SMiklos Szeredi struct fuse_notify_retrieve_in retrieve_in; 348334f485dSMiklos Szeredi } misc; 349334f485dSMiklos Szeredi 350334f485dSMiklos Szeredi /** page vector */ 3514250c066SMaxim Patlasov struct page **pages; 3524250c066SMaxim Patlasov 353b2430d75SMaxim Patlasov /** page-descriptor vector */ 354b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 355b2430d75SMaxim Patlasov 3564250c066SMaxim Patlasov /** size of the 'pages' array */ 3574250c066SMaxim Patlasov unsigned max_pages; 3584250c066SMaxim Patlasov 3594250c066SMaxim Patlasov /** inline page vector */ 3604250c066SMaxim Patlasov struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 361334f485dSMiklos Szeredi 362b2430d75SMaxim Patlasov /** inline page-descriptor vector */ 363b2430d75SMaxim Patlasov struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 364b2430d75SMaxim Patlasov 365334f485dSMiklos Szeredi /** number of pages in vector */ 366334f485dSMiklos Szeredi unsigned num_pages; 367334f485dSMiklos Szeredi 368334f485dSMiklos Szeredi /** File used in the request (or NULL) */ 369c756e0a4SMiklos Szeredi struct fuse_file *ff; 37064c6d8edSMiklos Szeredi 3713be5a52bSMiklos Szeredi /** Inode used in the request or NULL */ 3723be5a52bSMiklos Szeredi struct inode *inode; 3733be5a52bSMiklos Szeredi 37401e9d11aSMaxim Patlasov /** AIO control block */ 37501e9d11aSMaxim Patlasov struct fuse_io_priv *io; 37601e9d11aSMaxim Patlasov 3773be5a52bSMiklos Szeredi /** Link on fi->writepages */ 3783be5a52bSMiklos Szeredi struct list_head writepages_entry; 3793be5a52bSMiklos Szeredi 38064c6d8edSMiklos Szeredi /** Request completion callback */ 38164c6d8edSMiklos Szeredi void (*end)(struct fuse_conn *, struct fuse_req *); 38233649c91SMiklos Szeredi 38333649c91SMiklos Szeredi /** Request is stolen from fuse_file->reserved_req */ 38433649c91SMiklos Szeredi struct file *stolen_file; 385334f485dSMiklos Szeredi }; 386334f485dSMiklos Szeredi 387f88996a9SMiklos Szeredi struct fuse_iqueue { 388e16714d8SMiklos Szeredi /** Connection established */ 389e16714d8SMiklos Szeredi unsigned connected; 390e16714d8SMiklos Szeredi 391f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 392f88996a9SMiklos Szeredi wait_queue_head_t waitq; 393f88996a9SMiklos Szeredi 394f88996a9SMiklos Szeredi /** The next unique request id */ 395f88996a9SMiklos Szeredi u64 reqctr; 396f88996a9SMiklos Szeredi 397f88996a9SMiklos Szeredi /** The list of pending requests */ 398f88996a9SMiklos Szeredi struct list_head pending; 399f88996a9SMiklos Szeredi 400f88996a9SMiklos Szeredi /** Pending interrupts */ 401f88996a9SMiklos Szeredi struct list_head interrupts; 402f88996a9SMiklos Szeredi 403f88996a9SMiklos Szeredi /** Queue of pending forgets */ 404f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 405f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 406f88996a9SMiklos Szeredi 407f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 408f88996a9SMiklos Szeredi int forget_batch; 409f88996a9SMiklos Szeredi 410f88996a9SMiklos Szeredi /** O_ASYNC requests */ 411f88996a9SMiklos Szeredi struct fasync_struct *fasync; 412f88996a9SMiklos Szeredi }; 413f88996a9SMiklos Szeredi 4143a2b5b9cSMiklos Szeredi struct fuse_pqueue { 415e96edd94SMiklos Szeredi /** Connection established */ 416e96edd94SMiklos Szeredi unsigned connected; 417e96edd94SMiklos Szeredi 41845a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 41945a91cb1SMiklos Szeredi spinlock_t lock; 42045a91cb1SMiklos Szeredi 4213a2b5b9cSMiklos Szeredi /** The list of requests being processed */ 4223a2b5b9cSMiklos Szeredi struct list_head processing; 4233a2b5b9cSMiklos Szeredi 4243a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4253a2b5b9cSMiklos Szeredi struct list_head io; 4263a2b5b9cSMiklos Szeredi }; 4273a2b5b9cSMiklos Szeredi 428d8a5ba45SMiklos Szeredi /** 429cc080e9eSMiklos Szeredi * Fuse device instance 430cc080e9eSMiklos Szeredi */ 431cc080e9eSMiklos Szeredi struct fuse_dev { 432cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 433cc080e9eSMiklos Szeredi struct fuse_conn *fc; 434cc080e9eSMiklos Szeredi 435c3696046SMiklos Szeredi /** Processing queue */ 436c3696046SMiklos Szeredi struct fuse_pqueue pq; 437c3696046SMiklos Szeredi 438cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 439cc080e9eSMiklos Szeredi struct list_head entry; 440cc080e9eSMiklos Szeredi }; 441cc080e9eSMiklos Szeredi 442cc080e9eSMiklos Szeredi /** 443d8a5ba45SMiklos Szeredi * A Fuse connection. 444d8a5ba45SMiklos Szeredi * 445d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 446d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 447d8a5ba45SMiklos Szeredi * unmounted. 448d8a5ba45SMiklos Szeredi */ 449d8a5ba45SMiklos Szeredi struct fuse_conn { 450d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 451d7133114SMiklos Szeredi spinlock_t lock; 452d7133114SMiklos Szeredi 453bafa9654SMiklos Szeredi /** Refcount */ 454095fc40aSElena Reshetova refcount_t count; 455bafa9654SMiklos Szeredi 456c3696046SMiklos Szeredi /** Number of fuse_dev's */ 457c3696046SMiklos Szeredi atomic_t dev_count; 458c3696046SMiklos Szeredi 459dd3e2c55SAl Viro struct rcu_head rcu; 460dd3e2c55SAl Viro 461d8a5ba45SMiklos Szeredi /** The user id for this mount */ 462499dcf20SEric W. Biederman kuid_t user_id; 463d8a5ba45SMiklos Szeredi 46487729a55SMiklos Szeredi /** The group id for this mount */ 465499dcf20SEric W. Biederman kgid_t group_id; 46687729a55SMiklos Szeredi 4670b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 4680b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 4690b6e9ea0SSeth Forshee 470db50b96cSMiklos Szeredi /** Maximum read size */ 471db50b96cSMiklos Szeredi unsigned max_read; 472db50b96cSMiklos Szeredi 473413ef8cbSMiklos Szeredi /** Maximum write size */ 474413ef8cbSMiklos Szeredi unsigned max_write; 475413ef8cbSMiklos Szeredi 476f88996a9SMiklos Szeredi /** Input queue */ 477f88996a9SMiklos Szeredi struct fuse_iqueue iq; 478334f485dSMiklos Szeredi 479acf99433STejun Heo /** The next unique kernel file handle */ 480acf99433STejun Heo u64 khctr; 481acf99433STejun Heo 48295668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 48395668a69STejun Heo struct rb_root polled_files; 48495668a69STejun Heo 4857a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 4867a6d3c8bSCsaba Henk unsigned max_background; 4877a6d3c8bSCsaba Henk 4887a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 4897a6d3c8bSCsaba Henk unsigned congestion_threshold; 4907a6d3c8bSCsaba Henk 49108a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 49208a53cdcSMiklos Szeredi unsigned num_background; 49308a53cdcSMiklos Szeredi 494d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 495d12def1bSMiklos Szeredi unsigned active_background; 496d12def1bSMiklos Szeredi 497d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 498d12def1bSMiklos Szeredi struct list_head bg_queue; 499d12def1bSMiklos Szeredi 500796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 501796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 502796523fbSMaxim Patlasov int initialized; 503796523fbSMaxim Patlasov 50408a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 50508a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 50608a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 50708a53cdcSMiklos Szeredi int blocked; 50808a53cdcSMiklos Szeredi 50908a53cdcSMiklos Szeredi /** waitq for blocked connection */ 51008a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 51108a53cdcSMiklos Szeredi 512de5e3decSMiklos Szeredi /** waitq for reserved requests */ 513de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 514de5e3decSMiklos Szeredi 51569a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 51669a53bf2SMiklos Szeredi abort and device release */ 517095da6cbSMiklos Szeredi unsigned connected; 5181e9a4ed9SMiklos Szeredi 519095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 520095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 521095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 522334f485dSMiklos Szeredi unsigned conn_error:1; 523334f485dSMiklos Szeredi 5240ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5250ec7ca41SMiklos Szeredi unsigned conn_init:1; 5260ec7ca41SMiklos Szeredi 5279cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5289cd68455SMiklos Szeredi unsigned async_read:1; 5299cd68455SMiklos Szeredi 5306ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5316ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5326ff958edSMiklos Szeredi 53333670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 53433670fa2SMiklos Szeredi unsigned export_support:1; 53533670fa2SMiklos Szeredi 536d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 537d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 538d5cd66c5SPavel Emelyanov 5395c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5405c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5415c672ab3SMiklos Szeredi 5425e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5435e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5445e940c1dSMiklos Szeredi 545095da6cbSMiklos Szeredi /* 546095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 547095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 548095da6cbSMiklos Szeredi */ 549095da6cbSMiklos Szeredi 5507678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 5517678ac50SAndrew Gallagher unsigned no_open:1; 5527678ac50SAndrew Gallagher 553b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 554b6aeadedSMiklos Szeredi unsigned no_fsync:1; 555b6aeadedSMiklos Szeredi 55682547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 55782547981SMiklos Szeredi unsigned no_fsyncdir:1; 55882547981SMiklos Szeredi 559b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 560b6aeadedSMiklos Szeredi unsigned no_flush:1; 561b6aeadedSMiklos Szeredi 56292a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 56392a8780eSMiklos Szeredi unsigned no_setxattr:1; 56492a8780eSMiklos Szeredi 56592a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 56692a8780eSMiklos Szeredi unsigned no_getxattr:1; 56792a8780eSMiklos Szeredi 56892a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 56992a8780eSMiklos Szeredi unsigned no_listxattr:1; 57092a8780eSMiklos Szeredi 57192a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 57292a8780eSMiklos Szeredi unsigned no_removexattr:1; 57392a8780eSMiklos Szeredi 57437fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 57571421259SMiklos Szeredi unsigned no_lock:1; 57671421259SMiklos Szeredi 57731d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 57831d40d74SMiklos Szeredi unsigned no_access:1; 57931d40d74SMiklos Szeredi 580fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 581fd72faacSMiklos Szeredi unsigned no_create:1; 582fd72faacSMiklos Szeredi 583a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 584a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 585a4d27e75SMiklos Szeredi 586b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 587b2d2272fSMiklos Szeredi unsigned no_bmap:1; 588b2d2272fSMiklos Szeredi 58995668a69STejun Heo /** Is poll not implemented by fs? */ 59095668a69STejun Heo unsigned no_poll:1; 59195668a69STejun Heo 59278bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 59378bb6cb9SMiklos Szeredi unsigned big_writes:1; 59478bb6cb9SMiklos Szeredi 595e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 596e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 597e0a43ddcSMiklos Szeredi 59837fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 59937fb3a30SMiklos Szeredi unsigned no_flock:1; 60037fb3a30SMiklos Szeredi 601519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 602519c6040SMiklos Szeredi unsigned no_fallocate:1; 603519c6040SMiklos Szeredi 6041560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6051560c974SMiklos Szeredi unsigned no_rename2:1; 6061560c974SMiklos Szeredi 60772d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 60872d0d248SBrian Foster unsigned auto_inval_data:1; 60972d0d248SBrian Foster 610634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6110b05b183SAnand V. Avati unsigned do_readdirplus:1; 6120b05b183SAnand V. Avati 613634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 614634734b6SEric Wong unsigned readdirplus_auto:1; 615634734b6SEric Wong 61660b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 61760b9df7aSMiklos Szeredi unsigned async_dio:1; 61860b9df7aSMiklos Szeredi 6190b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6200b5da8dbSRavishankar N unsigned no_lseek:1; 6210b5da8dbSRavishankar N 62260bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 62360bcc88aSSeth Forshee unsigned posix_acl:1; 62460bcc88aSSeth Forshee 62529433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 62629433a29SMiklos Szeredi unsigned default_permissions:1; 62729433a29SMiklos Szeredi 62829433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 62929433a29SMiklos Szeredi unsigned allow_other:1; 63029433a29SMiklos Szeredi 6310cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6320cd5b885SMiklos Szeredi atomic_t num_waiting; 6330cd5b885SMiklos Szeredi 63445714d65SMiklos Szeredi /** Negotiated minor version */ 63545714d65SMiklos Szeredi unsigned minor; 63645714d65SMiklos Szeredi 637bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 638bafa9654SMiklos Szeredi struct list_head entry; 639bafa9654SMiklos Szeredi 640b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 641b6f2fcbcSMiklos Szeredi dev_t dev; 642bafa9654SMiklos Szeredi 643bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 644bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 645bafa9654SMiklos Szeredi 646bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 647bafa9654SMiklos Szeredi int ctl_ndents; 648385a17bfSJeff Dike 6499c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 6509c8ef561SMiklos Szeredi u32 scramble_key[4]; 6510ec7ca41SMiklos Szeredi 6520ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 6530ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 6541fb69e78SMiklos Szeredi 6551fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 6561fb69e78SMiklos Szeredi u64 attr_version; 65743901aabSTejun Heo 65843901aabSTejun Heo /** Called on final put */ 65943901aabSTejun Heo void (*release)(struct fuse_conn *); 6603b463ae0SJohn Muir 6613b463ae0SJohn Muir /** Super block for this connection. */ 6623b463ae0SJohn Muir struct super_block *sb; 6633b463ae0SJohn Muir 6643b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 6653b463ae0SJohn Muir struct rw_semaphore killsb; 666cc080e9eSMiklos Szeredi 667cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 668cc080e9eSMiklos Szeredi struct list_head devices; 669d8a5ba45SMiklos Szeredi }; 670d8a5ba45SMiklos Szeredi 671d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 672d8a5ba45SMiklos Szeredi { 6736383bdaaSMiklos Szeredi return sb->s_fs_info; 674d8a5ba45SMiklos Szeredi } 675d8a5ba45SMiklos Szeredi 676d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 677d8a5ba45SMiklos Szeredi { 678d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 679d8a5ba45SMiklos Szeredi } 680d8a5ba45SMiklos Szeredi 681d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 682d8a5ba45SMiklos Szeredi { 683d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 684d8a5ba45SMiklos Szeredi } 685d8a5ba45SMiklos Szeredi 686d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 687d8a5ba45SMiklos Szeredi { 688d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 689d8a5ba45SMiklos Szeredi } 690d8a5ba45SMiklos Szeredi 691334f485dSMiklos Szeredi /** Device operations */ 6924b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 693334f485dSMiklos Szeredi 6944269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 6950ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 696dbd561d2SMiklos Szeredi 697d8a5ba45SMiklos Szeredi /** 6983b463ae0SJohn Muir * Inode to nodeid comparison. 6993b463ae0SJohn Muir */ 7003b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7013b463ae0SJohn Muir 7023b463ae0SJohn Muir /** 703e5e5558eSMiklos Szeredi * Get a filled in inode 704e5e5558eSMiklos Szeredi */ 705b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7061fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7071fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 708e5e5558eSMiklos Szeredi 70913983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 71033670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 71133670fa2SMiklos Szeredi 712e5e5558eSMiklos Szeredi /** 713e5e5558eSMiklos Szeredi * Send FORGET command 714e5e5558eSMiklos Szeredi */ 71507e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 716b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 717e5e5558eSMiklos Szeredi 71807e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 71907e77dcaSMiklos Szeredi 7200b05b183SAnand V. Avati /* Used by READDIRPLUS */ 7210b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 7220b05b183SAnand V. Avati 723e5e5558eSMiklos Szeredi /** 724361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 72504730fefSMiklos Szeredi */ 726a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 7272106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 72804730fefSMiklos Szeredi 72904730fefSMiklos Szeredi /** 73004730fefSMiklos Szeredi * Send OPEN or OPENDIR request 73104730fefSMiklos Szeredi */ 73291fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 73304730fefSMiklos Szeredi 734acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 735fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 736c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 737fd72faacSMiklos Szeredi 7388b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags); 739c756e0a4SMiklos Szeredi 74004730fefSMiklos Szeredi /** 74104730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 74204730fefSMiklos Szeredi */ 7438b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode); 74404730fefSMiklos Szeredi 74504730fefSMiklos Szeredi /** 74682547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 74782547981SMiklos Szeredi */ 74802c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 74902c24a82SJosef Bacik int datasync, int isdir); 75082547981SMiklos Szeredi 75182547981SMiklos Szeredi /** 75295668a69STejun Heo * Notify poll wakeup 75395668a69STejun Heo */ 75495668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 75595668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 75695668a69STejun Heo 75795668a69STejun Heo /** 7581779381dSMiklos Szeredi * Initialize file operations on a regular file 759b6aeadedSMiklos Szeredi */ 760b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 761b6aeadedSMiklos Szeredi 762b6aeadedSMiklos Szeredi /** 7631779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 764e5e5558eSMiklos Szeredi */ 765e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 766e5e5558eSMiklos Szeredi 767e5e5558eSMiklos Szeredi /** 7681779381dSMiklos Szeredi * Initialize inode and file operations on a directory 769e5e5558eSMiklos Szeredi */ 770e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 771e5e5558eSMiklos Szeredi 772e5e5558eSMiklos Szeredi /** 7731779381dSMiklos Szeredi * Initialize inode operations on a symlink 774e5e5558eSMiklos Szeredi */ 775e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 776e5e5558eSMiklos Szeredi 777e5e5558eSMiklos Szeredi /** 778e5e5558eSMiklos Szeredi * Change attributes of an inode 779e5e5558eSMiklos Szeredi */ 7801fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 7811fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 782e5e5558eSMiklos Szeredi 7833be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 7843be5a52bSMiklos Szeredi u64 attr_valid); 7853be5a52bSMiklos Szeredi 786e5e5558eSMiklos Szeredi /** 787334f485dSMiklos Szeredi * Initialize the client device 788334f485dSMiklos Szeredi */ 789334f485dSMiklos Szeredi int fuse_dev_init(void); 790334f485dSMiklos Szeredi 791334f485dSMiklos Szeredi /** 792334f485dSMiklos Szeredi * Cleanup the client device 793334f485dSMiklos Szeredi */ 794334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 795334f485dSMiklos Szeredi 796bafa9654SMiklos Szeredi int fuse_ctl_init(void); 7977736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 798bafa9654SMiklos Szeredi 799334f485dSMiklos Szeredi /** 800334f485dSMiklos Szeredi * Allocate a request 801334f485dSMiklos Szeredi */ 8024250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 803334f485dSMiklos Szeredi 8044250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8053be5a52bSMiklos Szeredi 806334f485dSMiklos Szeredi /** 807334f485dSMiklos Szeredi * Free a request 808334f485dSMiklos Szeredi */ 809334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 810334f485dSMiklos Szeredi 811334f485dSMiklos Szeredi /** 812b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 813b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 814334f485dSMiklos Szeredi */ 815b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 8168b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 8178b41e671SMaxim Patlasov unsigned npages); 818b111c8c0SMaxim Patlasov 81936cf66edSMaxim Patlasov /* 82036cf66edSMaxim Patlasov * Increment reference count on request 82136cf66edSMaxim Patlasov */ 82236cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 82336cf66edSMaxim Patlasov 824b111c8c0SMaxim Patlasov /** 82533649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 82633649c91SMiklos Szeredi */ 827b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 828b111c8c0SMaxim Patlasov struct file *file); 82933649c91SMiklos Szeredi 83033649c91SMiklos Szeredi /** 831ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 832ce1d5a49SMiklos Szeredi * the request. 833334f485dSMiklos Szeredi */ 834334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 835334f485dSMiklos Szeredi 836334f485dSMiklos Szeredi /** 8377c352bdfSMiklos Szeredi * Send a request (synchronous) 838334f485dSMiklos Szeredi */ 839b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 840334f485dSMiklos Szeredi 841334f485dSMiklos Szeredi /** 8427078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 8437078187aSMiklos Szeredi */ 8447078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 8457078187aSMiklos Szeredi 8467078187aSMiklos Szeredi /** 847334f485dSMiklos Szeredi * Send a request in the background 848334f485dSMiklos Szeredi */ 849b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 850334f485dSMiklos Szeredi 851b93f858aSTejun Heo void fuse_request_send_background_locked(struct fuse_conn *fc, 852b93f858aSTejun Heo struct fuse_req *req); 8533be5a52bSMiklos Szeredi 8545a5fb1eaSMiklos Szeredi /* Abort all requests */ 85569a53bf2SMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 85669a53bf2SMiklos Szeredi 8571e9a4ed9SMiklos Szeredi /** 858e5e5558eSMiklos Szeredi * Invalidate inode attributes 859e5e5558eSMiklos Szeredi */ 860e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 861bafa9654SMiklos Szeredi 862dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 863dbd561d2SMiklos Szeredi 864451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 865451418fcSAndrew Gallagher 866bafa9654SMiklos Szeredi /** 867bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 868bafa9654SMiklos Szeredi */ 869bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 870bafa9654SMiklos Szeredi 871bafa9654SMiklos Szeredi /** 8720d179aa5STejun Heo * Initialize fuse_conn 8730d179aa5STejun Heo */ 874a325f9b9STejun Heo void fuse_conn_init(struct fuse_conn *fc); 8750d179aa5STejun Heo 8760d179aa5STejun Heo /** 877bafa9654SMiklos Szeredi * Release reference to fuse_conn 878bafa9654SMiklos Szeredi */ 879bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 880bafa9654SMiklos Szeredi 881cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 882cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 883cc080e9eSMiklos Szeredi 884bafa9654SMiklos Szeredi /** 885bafa9654SMiklos Szeredi * Add connection to control filesystem 886bafa9654SMiklos Szeredi */ 887bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 888bafa9654SMiklos Szeredi 889bafa9654SMiklos Szeredi /** 890bafa9654SMiklos Szeredi * Remove connection from control filesystem 891bafa9654SMiklos Szeredi */ 892bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 893a5bfffacSTimo Savola 894a5bfffacSTimo Savola /** 895a5bfffacSTimo Savola * Is file type valid? 896a5bfffacSTimo Savola */ 897a5bfffacSTimo Savola int fuse_valid_type(int m); 898e57ac683SMiklos Szeredi 899e57ac683SMiklos Szeredi /** 900c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 901e57ac683SMiklos Szeredi */ 902c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 903f3332114SMiklos Szeredi 904f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 905bcb4be80SMiklos Szeredi 906703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 907703c7362SSeth Forshee 908bcb4be80SMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct kstat *stat, 909bcb4be80SMiklos Szeredi struct file *file, bool *refreshed); 9103be5a52bSMiklos Szeredi 9113be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9123be5a52bSMiklos Szeredi 9133be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9143be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9155c5c5e51SMiklos Szeredi 9165c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc); 91729d434b3STejun Heo 9183b463ae0SJohn Muir /** 9193b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9203b463ae0SJohn Muir */ 9213b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9223b463ae0SJohn Muir loff_t offset, loff_t len); 9233b463ae0SJohn Muir 9243b463ae0SJohn Muir /** 9253b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9263b463ae0SJohn Muir * the dentry matching parent/name. 927451d0f59SJohn Muir * 928451d0f59SJohn Muir * If the child_nodeid is non-zero and: 929451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 930451d0f59SJohn Muir * - is not a mount point 931451d0f59SJohn Muir * - is a file or oan empty directory 932451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 9333b463ae0SJohn Muir */ 9343b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 935451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 9363b463ae0SJohn Muir 93708cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 93808cbf542STejun Heo bool isdir); 939ea8cd333SPavel Emelyanov 940ea8cd333SPavel Emelyanov /** 941ea8cd333SPavel Emelyanov * fuse_direct_io() flags 942ea8cd333SPavel Emelyanov */ 943ea8cd333SPavel Emelyanov 944ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 945ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 946ea8cd333SPavel Emelyanov 947ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 948ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 949ea8cd333SPavel Emelyanov 950d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 951d22a943fSAl Viro loff_t *ppos, int flags); 95208cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 95308cbf542STejun Heo unsigned int flags); 954b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 955b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 95608cbf542STejun Heo unsigned fuse_file_poll(struct file *file, poll_table *wait); 95708cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 95808cbf542STejun Heo 959b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 960b0aa7606SMaxim Patlasov 961ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 9621e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 963a1d75f25SMiklos Szeredi 96462490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 965efb9fa9eSMaxim Patlasov struct file *file); 966efb9fa9eSMaxim Patlasov 9679759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 9689759bd51SMiklos Szeredi 9695c672ab3SMiklos Szeredi void fuse_unlock_inode(struct inode *inode); 9705c672ab3SMiklos Szeredi void fuse_lock_inode(struct inode *inode); 9715c672ab3SMiklos Szeredi 97260bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 97360bcc88aSSeth Forshee size_t size, int flags); 97460bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 97560bcc88aSSeth Forshee size_t size); 976703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 97760bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 978703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 97960bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 98060bcc88aSSeth Forshee 98160bcc88aSSeth Forshee struct posix_acl; 98260bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 98360bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 984703c7362SSeth Forshee 98529d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 986