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; 25261c12b49SAshish Samant bool should_dirty; 25301e9d11aSMaxim Patlasov int err; 25401e9d11aSMaxim Patlasov struct kiocb *iocb; 2559d5722b7SChristoph Hellwig struct completion *done; 2567879c4e5SAshish Sangwan bool blocking; 25701e9d11aSMaxim Patlasov }; 25801e9d11aSMaxim Patlasov 259e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 260744742d6SSeth Forshee { \ 2611e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 262744742d6SSeth Forshee .async = 0, \ 263e1c0eecbSMiklos Szeredi .iocb = i, \ 264744742d6SSeth Forshee } 265744742d6SSeth Forshee 266334f485dSMiklos Szeredi /** 267825d6d33SMiklos Szeredi * Request flags 268825d6d33SMiklos Szeredi * 269825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 270825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 271825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 272825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 273825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 274825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 275825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 27633e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 27733e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 27833e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 27977cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 280825d6d33SMiklos Szeredi */ 281825d6d33SMiklos Szeredi enum fuse_req_flag { 282825d6d33SMiklos Szeredi FR_ISREPLY, 283825d6d33SMiklos Szeredi FR_FORCE, 284825d6d33SMiklos Szeredi FR_BACKGROUND, 285825d6d33SMiklos Szeredi FR_WAITING, 286825d6d33SMiklos Szeredi FR_ABORTED, 287825d6d33SMiklos Szeredi FR_INTERRUPTED, 288825d6d33SMiklos Szeredi FR_LOCKED, 28933e14b4dSMiklos Szeredi FR_PENDING, 29033e14b4dSMiklos Szeredi FR_SENT, 29133e14b4dSMiklos Szeredi FR_FINISHED, 29277cd9d48SMiklos Szeredi FR_PRIVATE, 293825d6d33SMiklos Szeredi }; 294825d6d33SMiklos Szeredi 295825d6d33SMiklos Szeredi /** 296334f485dSMiklos Szeredi * A request to the client 297dc00809aSMiklos Szeredi * 298dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 299dc00809aSMiklos Szeredi * - FR_ABORTED 300dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 301334f485dSMiklos Szeredi */ 302334f485dSMiklos Szeredi struct fuse_req { 303ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 304ce1d5a49SMiklos Szeredi fuse_conn */ 305334f485dSMiklos Szeredi struct list_head list; 306334f485dSMiklos Szeredi 307a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 308a4d27e75SMiklos Szeredi struct list_head intr_entry; 309a4d27e75SMiklos Szeredi 310334f485dSMiklos Szeredi /** refcount */ 311ec99f6d3SElena Reshetova refcount_t count; 312334f485dSMiklos Szeredi 313a4d27e75SMiklos Szeredi /** Unique ID for the interrupt request */ 314a4d27e75SMiklos Szeredi u64 intr_unique; 315a4d27e75SMiklos Szeredi 316825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 317825d6d33SMiklos Szeredi unsigned long flags; 3189bc5dddaSMiklos Szeredi 319334f485dSMiklos Szeredi /** The request input */ 320334f485dSMiklos Szeredi struct fuse_in in; 321334f485dSMiklos Szeredi 322334f485dSMiklos Szeredi /** The request output */ 323334f485dSMiklos Szeredi struct fuse_out out; 324334f485dSMiklos Szeredi 325334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 326334f485dSMiklos Szeredi wait_queue_head_t waitq; 327334f485dSMiklos Szeredi 328334f485dSMiklos Szeredi /** Data for asynchronous requests */ 329334f485dSMiklos Szeredi union { 330b57d4264SMiklos Szeredi struct { 331b57d4264SMiklos Szeredi struct fuse_release_in in; 332baebccbeSMiklos Szeredi struct inode *inode; 333b57d4264SMiklos Szeredi } release; 3343ec870d5SMiklos Szeredi struct fuse_init_in init_in; 3353ec870d5SMiklos Szeredi struct fuse_init_out init_out; 33608cbf542STejun Heo struct cuse_init_in cuse_init_in; 3375c5c5e51SMiklos Szeredi struct { 3385c5c5e51SMiklos Szeredi struct fuse_read_in in; 3395c5c5e51SMiklos Szeredi u64 attr_ver; 3405c5c5e51SMiklos Szeredi } read; 341b25e82e5SMiklos Szeredi struct { 342b25e82e5SMiklos Szeredi struct fuse_write_in in; 343b25e82e5SMiklos Szeredi struct fuse_write_out out; 3448b284dc4SMiklos Szeredi struct fuse_req *next; 345b25e82e5SMiklos Szeredi } write; 3462d45ba38SMiklos Szeredi struct fuse_notify_retrieve_in retrieve_in; 347334f485dSMiklos Szeredi } misc; 348334f485dSMiklos Szeredi 349334f485dSMiklos Szeredi /** page vector */ 3504250c066SMaxim Patlasov struct page **pages; 3514250c066SMaxim Patlasov 352b2430d75SMaxim Patlasov /** page-descriptor vector */ 353b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 354b2430d75SMaxim Patlasov 3554250c066SMaxim Patlasov /** size of the 'pages' array */ 3564250c066SMaxim Patlasov unsigned max_pages; 3574250c066SMaxim Patlasov 3584250c066SMaxim Patlasov /** inline page vector */ 3594250c066SMaxim Patlasov struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 360334f485dSMiklos Szeredi 361b2430d75SMaxim Patlasov /** inline page-descriptor vector */ 362b2430d75SMaxim Patlasov struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 363b2430d75SMaxim Patlasov 364334f485dSMiklos Szeredi /** number of pages in vector */ 365334f485dSMiklos Szeredi unsigned num_pages; 366334f485dSMiklos Szeredi 367334f485dSMiklos Szeredi /** File used in the request (or NULL) */ 368c756e0a4SMiklos Szeredi struct fuse_file *ff; 36964c6d8edSMiklos Szeredi 3703be5a52bSMiklos Szeredi /** Inode used in the request or NULL */ 3713be5a52bSMiklos Szeredi struct inode *inode; 3723be5a52bSMiklos Szeredi 37301e9d11aSMaxim Patlasov /** AIO control block */ 37401e9d11aSMaxim Patlasov struct fuse_io_priv *io; 37501e9d11aSMaxim Patlasov 3763be5a52bSMiklos Szeredi /** Link on fi->writepages */ 3773be5a52bSMiklos Szeredi struct list_head writepages_entry; 3783be5a52bSMiklos Szeredi 37964c6d8edSMiklos Szeredi /** Request completion callback */ 38064c6d8edSMiklos Szeredi void (*end)(struct fuse_conn *, struct fuse_req *); 38133649c91SMiklos Szeredi 38233649c91SMiklos Szeredi /** Request is stolen from fuse_file->reserved_req */ 38333649c91SMiklos Szeredi struct file *stolen_file; 384334f485dSMiklos Szeredi }; 385334f485dSMiklos Szeredi 386f88996a9SMiklos Szeredi struct fuse_iqueue { 387e16714d8SMiklos Szeredi /** Connection established */ 388e16714d8SMiklos Szeredi unsigned connected; 389e16714d8SMiklos Szeredi 390f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 391f88996a9SMiklos Szeredi wait_queue_head_t waitq; 392f88996a9SMiklos Szeredi 393f88996a9SMiklos Szeredi /** The next unique request id */ 394f88996a9SMiklos Szeredi u64 reqctr; 395f88996a9SMiklos Szeredi 396f88996a9SMiklos Szeredi /** The list of pending requests */ 397f88996a9SMiklos Szeredi struct list_head pending; 398f88996a9SMiklos Szeredi 399f88996a9SMiklos Szeredi /** Pending interrupts */ 400f88996a9SMiklos Szeredi struct list_head interrupts; 401f88996a9SMiklos Szeredi 402f88996a9SMiklos Szeredi /** Queue of pending forgets */ 403f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 404f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 405f88996a9SMiklos Szeredi 406f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 407f88996a9SMiklos Szeredi int forget_batch; 408f88996a9SMiklos Szeredi 409f88996a9SMiklos Szeredi /** O_ASYNC requests */ 410f88996a9SMiklos Szeredi struct fasync_struct *fasync; 411f88996a9SMiklos Szeredi }; 412f88996a9SMiklos Szeredi 4133a2b5b9cSMiklos Szeredi struct fuse_pqueue { 414e96edd94SMiklos Szeredi /** Connection established */ 415e96edd94SMiklos Szeredi unsigned connected; 416e96edd94SMiklos Szeredi 41745a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 41845a91cb1SMiklos Szeredi spinlock_t lock; 41945a91cb1SMiklos Szeredi 4203a2b5b9cSMiklos Szeredi /** The list of requests being processed */ 4213a2b5b9cSMiklos Szeredi struct list_head processing; 4223a2b5b9cSMiklos Szeredi 4233a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4243a2b5b9cSMiklos Szeredi struct list_head io; 4253a2b5b9cSMiklos Szeredi }; 4263a2b5b9cSMiklos Szeredi 427d8a5ba45SMiklos Szeredi /** 428cc080e9eSMiklos Szeredi * Fuse device instance 429cc080e9eSMiklos Szeredi */ 430cc080e9eSMiklos Szeredi struct fuse_dev { 431cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 432cc080e9eSMiklos Szeredi struct fuse_conn *fc; 433cc080e9eSMiklos Szeredi 434c3696046SMiklos Szeredi /** Processing queue */ 435c3696046SMiklos Szeredi struct fuse_pqueue pq; 436c3696046SMiklos Szeredi 437cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 438cc080e9eSMiklos Szeredi struct list_head entry; 439cc080e9eSMiklos Szeredi }; 440cc080e9eSMiklos Szeredi 441cc080e9eSMiklos Szeredi /** 442d8a5ba45SMiklos Szeredi * A Fuse connection. 443d8a5ba45SMiklos Szeredi * 444d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 445d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 446d8a5ba45SMiklos Szeredi * unmounted. 447d8a5ba45SMiklos Szeredi */ 448d8a5ba45SMiklos Szeredi struct fuse_conn { 449d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 450d7133114SMiklos Szeredi spinlock_t lock; 451d7133114SMiklos Szeredi 452bafa9654SMiklos Szeredi /** Refcount */ 453095fc40aSElena Reshetova refcount_t count; 454bafa9654SMiklos Szeredi 455c3696046SMiklos Szeredi /** Number of fuse_dev's */ 456c3696046SMiklos Szeredi atomic_t dev_count; 457c3696046SMiklos Szeredi 458dd3e2c55SAl Viro struct rcu_head rcu; 459dd3e2c55SAl Viro 460d8a5ba45SMiklos Szeredi /** The user id for this mount */ 461499dcf20SEric W. Biederman kuid_t user_id; 462d8a5ba45SMiklos Szeredi 46387729a55SMiklos Szeredi /** The group id for this mount */ 464499dcf20SEric W. Biederman kgid_t group_id; 46587729a55SMiklos Szeredi 4660b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 4670b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 4680b6e9ea0SSeth Forshee 469db50b96cSMiklos Szeredi /** Maximum read size */ 470db50b96cSMiklos Szeredi unsigned max_read; 471db50b96cSMiklos Szeredi 472413ef8cbSMiklos Szeredi /** Maximum write size */ 473413ef8cbSMiklos Szeredi unsigned max_write; 474413ef8cbSMiklos Szeredi 475f88996a9SMiklos Szeredi /** Input queue */ 476f88996a9SMiklos Szeredi struct fuse_iqueue iq; 477334f485dSMiklos Szeredi 478acf99433STejun Heo /** The next unique kernel file handle */ 479acf99433STejun Heo u64 khctr; 480acf99433STejun Heo 48195668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 48295668a69STejun Heo struct rb_root polled_files; 48395668a69STejun Heo 4847a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 4857a6d3c8bSCsaba Henk unsigned max_background; 4867a6d3c8bSCsaba Henk 4877a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 4887a6d3c8bSCsaba Henk unsigned congestion_threshold; 4897a6d3c8bSCsaba Henk 49008a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 49108a53cdcSMiklos Szeredi unsigned num_background; 49208a53cdcSMiklos Szeredi 493d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 494d12def1bSMiklos Szeredi unsigned active_background; 495d12def1bSMiklos Szeredi 496d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 497d12def1bSMiklos Szeredi struct list_head bg_queue; 498d12def1bSMiklos Szeredi 499796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 500796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 501796523fbSMaxim Patlasov int initialized; 502796523fbSMaxim Patlasov 50308a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 50408a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 50508a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 50608a53cdcSMiklos Szeredi int blocked; 50708a53cdcSMiklos Szeredi 50808a53cdcSMiklos Szeredi /** waitq for blocked connection */ 50908a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 51008a53cdcSMiklos Szeredi 511de5e3decSMiklos Szeredi /** waitq for reserved requests */ 512de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 513de5e3decSMiklos Szeredi 51469a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 51569a53bf2SMiklos Szeredi abort and device release */ 516095da6cbSMiklos Szeredi unsigned connected; 5171e9a4ed9SMiklos Szeredi 518095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 519095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 520095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 521334f485dSMiklos Szeredi unsigned conn_error:1; 522334f485dSMiklos Szeredi 5230ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5240ec7ca41SMiklos Szeredi unsigned conn_init:1; 5250ec7ca41SMiklos Szeredi 5269cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5279cd68455SMiklos Szeredi unsigned async_read:1; 5289cd68455SMiklos Szeredi 5296ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5306ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5316ff958edSMiklos Szeredi 53233670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 53333670fa2SMiklos Szeredi unsigned export_support:1; 53433670fa2SMiklos Szeredi 535d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 536d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 537d5cd66c5SPavel Emelyanov 5385c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5395c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5405c672ab3SMiklos Szeredi 5415e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5425e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5435e940c1dSMiklos Szeredi 544095da6cbSMiklos Szeredi /* 545095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 546095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 547095da6cbSMiklos Szeredi */ 548095da6cbSMiklos Szeredi 5497678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 5507678ac50SAndrew Gallagher unsigned no_open:1; 5517678ac50SAndrew Gallagher 552b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 553b6aeadedSMiklos Szeredi unsigned no_fsync:1; 554b6aeadedSMiklos Szeredi 55582547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 55682547981SMiklos Szeredi unsigned no_fsyncdir:1; 55782547981SMiklos Szeredi 558b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 559b6aeadedSMiklos Szeredi unsigned no_flush:1; 560b6aeadedSMiklos Szeredi 56192a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 56292a8780eSMiklos Szeredi unsigned no_setxattr:1; 56392a8780eSMiklos Szeredi 56492a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 56592a8780eSMiklos Szeredi unsigned no_getxattr:1; 56692a8780eSMiklos Szeredi 56792a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 56892a8780eSMiklos Szeredi unsigned no_listxattr:1; 56992a8780eSMiklos Szeredi 57092a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 57192a8780eSMiklos Szeredi unsigned no_removexattr:1; 57292a8780eSMiklos Szeredi 57337fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 57471421259SMiklos Szeredi unsigned no_lock:1; 57571421259SMiklos Szeredi 57631d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 57731d40d74SMiklos Szeredi unsigned no_access:1; 57831d40d74SMiklos Szeredi 579fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 580fd72faacSMiklos Szeredi unsigned no_create:1; 581fd72faacSMiklos Szeredi 582a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 583a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 584a4d27e75SMiklos Szeredi 585b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 586b2d2272fSMiklos Szeredi unsigned no_bmap:1; 587b2d2272fSMiklos Szeredi 58895668a69STejun Heo /** Is poll not implemented by fs? */ 58995668a69STejun Heo unsigned no_poll:1; 59095668a69STejun Heo 59178bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 59278bb6cb9SMiklos Szeredi unsigned big_writes:1; 59378bb6cb9SMiklos Szeredi 594e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 595e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 596e0a43ddcSMiklos Szeredi 59737fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 59837fb3a30SMiklos Szeredi unsigned no_flock:1; 59937fb3a30SMiklos Szeredi 600519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 601519c6040SMiklos Szeredi unsigned no_fallocate:1; 602519c6040SMiklos Szeredi 6031560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6041560c974SMiklos Szeredi unsigned no_rename2:1; 6051560c974SMiklos Szeredi 60672d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 60772d0d248SBrian Foster unsigned auto_inval_data:1; 60872d0d248SBrian Foster 609634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6100b05b183SAnand V. Avati unsigned do_readdirplus:1; 6110b05b183SAnand V. Avati 612634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 613634734b6SEric Wong unsigned readdirplus_auto:1; 614634734b6SEric Wong 61560b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 61660b9df7aSMiklos Szeredi unsigned async_dio:1; 61760b9df7aSMiklos Szeredi 6180b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6190b5da8dbSRavishankar N unsigned no_lseek:1; 6200b5da8dbSRavishankar N 62160bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 62260bcc88aSSeth Forshee unsigned posix_acl:1; 62360bcc88aSSeth Forshee 62429433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 62529433a29SMiklos Szeredi unsigned default_permissions:1; 62629433a29SMiklos Szeredi 62729433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 62829433a29SMiklos Szeredi unsigned allow_other:1; 62929433a29SMiklos Szeredi 6300cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6310cd5b885SMiklos Szeredi atomic_t num_waiting; 6320cd5b885SMiklos Szeredi 63345714d65SMiklos Szeredi /** Negotiated minor version */ 63445714d65SMiklos Szeredi unsigned minor; 63545714d65SMiklos Szeredi 636bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 637bafa9654SMiklos Szeredi struct list_head entry; 638bafa9654SMiklos Szeredi 639b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 640b6f2fcbcSMiklos Szeredi dev_t dev; 641bafa9654SMiklos Szeredi 642bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 643bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 644bafa9654SMiklos Szeredi 645bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 646bafa9654SMiklos Szeredi int ctl_ndents; 647385a17bfSJeff Dike 6489c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 6499c8ef561SMiklos Szeredi u32 scramble_key[4]; 6500ec7ca41SMiklos Szeredi 6510ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 6520ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 6531fb69e78SMiklos Szeredi 6541fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 6551fb69e78SMiklos Szeredi u64 attr_version; 65643901aabSTejun Heo 65743901aabSTejun Heo /** Called on final put */ 65843901aabSTejun Heo void (*release)(struct fuse_conn *); 6593b463ae0SJohn Muir 6603b463ae0SJohn Muir /** Super block for this connection. */ 6613b463ae0SJohn Muir struct super_block *sb; 6623b463ae0SJohn Muir 6633b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 6643b463ae0SJohn Muir struct rw_semaphore killsb; 665cc080e9eSMiklos Szeredi 666cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 667cc080e9eSMiklos Szeredi struct list_head devices; 668d8a5ba45SMiklos Szeredi }; 669d8a5ba45SMiklos Szeredi 670d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 671d8a5ba45SMiklos Szeredi { 6726383bdaaSMiklos Szeredi return sb->s_fs_info; 673d8a5ba45SMiklos Szeredi } 674d8a5ba45SMiklos Szeredi 675d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 676d8a5ba45SMiklos Szeredi { 677d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 678d8a5ba45SMiklos Szeredi } 679d8a5ba45SMiklos Szeredi 680d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 681d8a5ba45SMiklos Szeredi { 682d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 683d8a5ba45SMiklos Szeredi } 684d8a5ba45SMiklos Szeredi 685d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 686d8a5ba45SMiklos Szeredi { 687d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 688d8a5ba45SMiklos Szeredi } 689d8a5ba45SMiklos Szeredi 690334f485dSMiklos Szeredi /** Device operations */ 6914b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 692334f485dSMiklos Szeredi 6934269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 6940ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 695dbd561d2SMiklos Szeredi 696d8a5ba45SMiklos Szeredi /** 6973b463ae0SJohn Muir * Inode to nodeid comparison. 6983b463ae0SJohn Muir */ 6993b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7003b463ae0SJohn Muir 7013b463ae0SJohn Muir /** 702e5e5558eSMiklos Szeredi * Get a filled in inode 703e5e5558eSMiklos Szeredi */ 704b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7051fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7061fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 707e5e5558eSMiklos Szeredi 70813983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 70933670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 71033670fa2SMiklos Szeredi 711e5e5558eSMiklos Szeredi /** 712e5e5558eSMiklos Szeredi * Send FORGET command 713e5e5558eSMiklos Szeredi */ 71407e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 715b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 716e5e5558eSMiklos Szeredi 71707e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 71807e77dcaSMiklos Szeredi 7190b05b183SAnand V. Avati /* Used by READDIRPLUS */ 7200b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 7210b05b183SAnand V. Avati 722e5e5558eSMiklos Szeredi /** 723361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 72404730fefSMiklos Szeredi */ 725a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 7262106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 72704730fefSMiklos Szeredi 72804730fefSMiklos Szeredi /** 72904730fefSMiklos Szeredi * Send OPEN or OPENDIR request 73004730fefSMiklos Szeredi */ 73191fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 73204730fefSMiklos Szeredi 733acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 734fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 735c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 736fd72faacSMiklos Szeredi 7378b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags); 738c756e0a4SMiklos Szeredi 73904730fefSMiklos Szeredi /** 74004730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 74104730fefSMiklos Szeredi */ 7428b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode); 74304730fefSMiklos Szeredi 74404730fefSMiklos Szeredi /** 74582547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 74682547981SMiklos Szeredi */ 74702c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 74802c24a82SJosef Bacik int datasync, int isdir); 74982547981SMiklos Szeredi 75082547981SMiklos Szeredi /** 75195668a69STejun Heo * Notify poll wakeup 75295668a69STejun Heo */ 75395668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 75495668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 75595668a69STejun Heo 75695668a69STejun Heo /** 7571779381dSMiklos Szeredi * Initialize file operations on a regular file 758b6aeadedSMiklos Szeredi */ 759b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 760b6aeadedSMiklos Szeredi 761b6aeadedSMiklos Szeredi /** 7621779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 763e5e5558eSMiklos Szeredi */ 764e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 765e5e5558eSMiklos Szeredi 766e5e5558eSMiklos Szeredi /** 7671779381dSMiklos Szeredi * Initialize inode and file operations on a directory 768e5e5558eSMiklos Szeredi */ 769e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 770e5e5558eSMiklos Szeredi 771e5e5558eSMiklos Szeredi /** 7721779381dSMiklos Szeredi * Initialize inode operations on a symlink 773e5e5558eSMiklos Szeredi */ 774e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 775e5e5558eSMiklos Szeredi 776e5e5558eSMiklos Szeredi /** 777e5e5558eSMiklos Szeredi * Change attributes of an inode 778e5e5558eSMiklos Szeredi */ 7791fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 7801fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 781e5e5558eSMiklos Szeredi 7823be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 7833be5a52bSMiklos Szeredi u64 attr_valid); 7843be5a52bSMiklos Szeredi 785e5e5558eSMiklos Szeredi /** 786334f485dSMiklos Szeredi * Initialize the client device 787334f485dSMiklos Szeredi */ 788334f485dSMiklos Szeredi int fuse_dev_init(void); 789334f485dSMiklos Szeredi 790334f485dSMiklos Szeredi /** 791334f485dSMiklos Szeredi * Cleanup the client device 792334f485dSMiklos Szeredi */ 793334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 794334f485dSMiklos Szeredi 795bafa9654SMiklos Szeredi int fuse_ctl_init(void); 7967736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 797bafa9654SMiklos Szeredi 798334f485dSMiklos Szeredi /** 799334f485dSMiklos Szeredi * Allocate a request 800334f485dSMiklos Szeredi */ 8014250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 802334f485dSMiklos Szeredi 8034250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8043be5a52bSMiklos Szeredi 805334f485dSMiklos Szeredi /** 806334f485dSMiklos Szeredi * Free a request 807334f485dSMiklos Szeredi */ 808334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 809334f485dSMiklos Szeredi 810334f485dSMiklos Szeredi /** 811b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 812b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 813334f485dSMiklos Szeredi */ 814b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 8158b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 8168b41e671SMaxim Patlasov unsigned npages); 817b111c8c0SMaxim Patlasov 81836cf66edSMaxim Patlasov /* 81936cf66edSMaxim Patlasov * Increment reference count on request 82036cf66edSMaxim Patlasov */ 82136cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 82236cf66edSMaxim Patlasov 823b111c8c0SMaxim Patlasov /** 82433649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 82533649c91SMiklos Szeredi */ 826b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 827b111c8c0SMaxim Patlasov struct file *file); 82833649c91SMiklos Szeredi 82933649c91SMiklos Szeredi /** 830ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 831ce1d5a49SMiklos Szeredi * the request. 832334f485dSMiklos Szeredi */ 833334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 834334f485dSMiklos Szeredi 835334f485dSMiklos Szeredi /** 8367c352bdfSMiklos Szeredi * Send a request (synchronous) 837334f485dSMiklos Szeredi */ 838b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 839334f485dSMiklos Szeredi 840334f485dSMiklos Szeredi /** 8417078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 8427078187aSMiklos Szeredi */ 8437078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 8447078187aSMiklos Szeredi 8457078187aSMiklos Szeredi /** 846334f485dSMiklos Szeredi * Send a request in the background 847334f485dSMiklos Szeredi */ 848b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 849334f485dSMiklos Szeredi 850b93f858aSTejun Heo void fuse_request_send_background_locked(struct fuse_conn *fc, 851b93f858aSTejun Heo struct fuse_req *req); 8523be5a52bSMiklos Szeredi 8535a5fb1eaSMiklos Szeredi /* Abort all requests */ 85469a53bf2SMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 85569a53bf2SMiklos Szeredi 8561e9a4ed9SMiklos Szeredi /** 857e5e5558eSMiklos Szeredi * Invalidate inode attributes 858e5e5558eSMiklos Szeredi */ 859e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 860bafa9654SMiklos Szeredi 861dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 862dbd561d2SMiklos Szeredi 863451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 864451418fcSAndrew Gallagher 865bafa9654SMiklos Szeredi /** 866bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 867bafa9654SMiklos Szeredi */ 868bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 869bafa9654SMiklos Szeredi 870bafa9654SMiklos Szeredi /** 8710d179aa5STejun Heo * Initialize fuse_conn 8720d179aa5STejun Heo */ 873a325f9b9STejun Heo void fuse_conn_init(struct fuse_conn *fc); 8740d179aa5STejun Heo 8750d179aa5STejun Heo /** 876bafa9654SMiklos Szeredi * Release reference to fuse_conn 877bafa9654SMiklos Szeredi */ 878bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 879bafa9654SMiklos Szeredi 880cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 881cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 882cc080e9eSMiklos Szeredi 883bafa9654SMiklos Szeredi /** 884bafa9654SMiklos Szeredi * Add connection to control filesystem 885bafa9654SMiklos Szeredi */ 886bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 887bafa9654SMiklos Szeredi 888bafa9654SMiklos Szeredi /** 889bafa9654SMiklos Szeredi * Remove connection from control filesystem 890bafa9654SMiklos Szeredi */ 891bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 892a5bfffacSTimo Savola 893a5bfffacSTimo Savola /** 894a5bfffacSTimo Savola * Is file type valid? 895a5bfffacSTimo Savola */ 896a5bfffacSTimo Savola int fuse_valid_type(int m); 897e57ac683SMiklos Szeredi 898e57ac683SMiklos Szeredi /** 899c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 900e57ac683SMiklos Szeredi */ 901c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 902f3332114SMiklos Szeredi 903f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 904bcb4be80SMiklos Szeredi 905703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 906703c7362SSeth Forshee 9075b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 9083be5a52bSMiklos Szeredi 9093be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9103be5a52bSMiklos Szeredi 9113be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9123be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9135c5c5e51SMiklos Szeredi 9145c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc); 91529d434b3STejun Heo 9163b463ae0SJohn Muir /** 9173b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9183b463ae0SJohn Muir */ 9193b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9203b463ae0SJohn Muir loff_t offset, loff_t len); 9213b463ae0SJohn Muir 9223b463ae0SJohn Muir /** 9233b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9243b463ae0SJohn Muir * the dentry matching parent/name. 925451d0f59SJohn Muir * 926451d0f59SJohn Muir * If the child_nodeid is non-zero and: 927451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 928451d0f59SJohn Muir * - is not a mount point 929451d0f59SJohn Muir * - is a file or oan empty directory 930451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 9313b463ae0SJohn Muir */ 9323b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 933451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 9343b463ae0SJohn Muir 93508cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 93608cbf542STejun Heo bool isdir); 937ea8cd333SPavel Emelyanov 938ea8cd333SPavel Emelyanov /** 939ea8cd333SPavel Emelyanov * fuse_direct_io() flags 940ea8cd333SPavel Emelyanov */ 941ea8cd333SPavel Emelyanov 942ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 943ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 944ea8cd333SPavel Emelyanov 945ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 946ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 947ea8cd333SPavel Emelyanov 948d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 949d22a943fSAl Viro loff_t *ppos, int flags); 95008cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 95108cbf542STejun Heo unsigned int flags); 952b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 953b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 954*076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 95508cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 95608cbf542STejun Heo 957b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 958b0aa7606SMaxim Patlasov 959ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 9601e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 961a1d75f25SMiklos Szeredi 96262490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 963efb9fa9eSMaxim Patlasov struct file *file); 964efb9fa9eSMaxim Patlasov 9659759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 9669759bd51SMiklos Szeredi 9675c672ab3SMiklos Szeredi void fuse_unlock_inode(struct inode *inode); 9685c672ab3SMiklos Szeredi void fuse_lock_inode(struct inode *inode); 9695c672ab3SMiklos Szeredi 97060bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 97160bcc88aSSeth Forshee size_t size, int flags); 97260bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 97360bcc88aSSeth Forshee size_t size); 974703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 97560bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 976703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 97760bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 97860bcc88aSSeth Forshee 97960bcc88aSSeth Forshee struct posix_acl; 98060bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 98160bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 982703c7362SSeth Forshee 98329d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 984