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> 29*8cb08329SEric W. Biederman #include <linux/user_namespace.h> 30d8a5ba45SMiklos Szeredi 31334f485dSMiklos Szeredi /** Max number of pages that can be used in a single read request */ 32334f485dSMiklos Szeredi #define FUSE_MAX_PAGES_PER_REQ 32 33334f485dSMiklos Szeredi 343be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 353be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 363be5a52bSMiklos Szeredi 371d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 381d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 391d3d752bSMiklos Szeredi 40bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4179a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 42bafa9654SMiklos Szeredi 434250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */ 444250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1 454250c066SMaxim Patlasov 46bafa9654SMiklos Szeredi /** List of active connections */ 47bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 48bafa9654SMiklos Szeredi 49bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 50bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 51413ef8cbSMiklos Szeredi 5279a9d994SCsaba Henk /** Module parameters */ 5379a9d994SCsaba Henk extern unsigned max_user_bgreq; 5479a9d994SCsaba Henk extern unsigned max_user_congthresh; 5579a9d994SCsaba Henk 5607e77dcaSMiklos Szeredi /* One forget request */ 5707e77dcaSMiklos Szeredi struct fuse_forget_link { 5802c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 5907e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6007e77dcaSMiklos Szeredi }; 6107e77dcaSMiklos Szeredi 62d8a5ba45SMiklos Szeredi /** FUSE inode */ 63d8a5ba45SMiklos Szeredi struct fuse_inode { 64d8a5ba45SMiklos Szeredi /** Inode data */ 65d8a5ba45SMiklos Szeredi struct inode inode; 66d8a5ba45SMiklos Szeredi 67d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 68d8a5ba45SMiklos Szeredi * and kernel */ 69d8a5ba45SMiklos Szeredi u64 nodeid; 70d8a5ba45SMiklos Szeredi 719e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 729e6268dbSMiklos Szeredi u64 nlookup; 739e6268dbSMiklos Szeredi 74e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7507e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 76e5e5558eSMiklos Szeredi 77d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 780a0898cfSMiklos Szeredi u64 i_time; 79ebc14c4dSMiklos Szeredi 80ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 81ebc14c4dSMiklos Szeredi preserve the original mode */ 82541af6a0SAl Viro umode_t orig_i_mode; 831fb69e78SMiklos Szeredi 8445c72cd7SPavel Shilovsky /** 64 bit inode number */ 8545c72cd7SPavel Shilovsky u64 orig_ino; 8645c72cd7SPavel Shilovsky 871fb69e78SMiklos Szeredi /** Version of last attribute change */ 881fb69e78SMiklos Szeredi u64 attr_version; 8993a8c3cdSMiklos Szeredi 9093a8c3cdSMiklos Szeredi /** Files usable in writepage. Protected by fc->lock */ 9193a8c3cdSMiklos Szeredi struct list_head write_files; 923be5a52bSMiklos Szeredi 933be5a52bSMiklos Szeredi /** Writepages pending on truncate or fsync */ 943be5a52bSMiklos Szeredi struct list_head queued_writes; 953be5a52bSMiklos Szeredi 963be5a52bSMiklos Szeredi /** Number of sent writes, a negative bias (FUSE_NOWRITE) 973be5a52bSMiklos Szeredi * means more writes are blocked */ 983be5a52bSMiklos Szeredi int writectr; 993be5a52bSMiklos Szeredi 1003be5a52bSMiklos Szeredi /** Waitq for writepage completion */ 1013be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1023be5a52bSMiklos Szeredi 1033be5a52bSMiklos Szeredi /** List of writepage requestst (pending or sent) */ 1043be5a52bSMiklos Szeredi struct list_head writepages; 1054582a4abSFeng Shuo 1064582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1074582a4abSFeng Shuo unsigned long state; 1085c672ab3SMiklos Szeredi 1095c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1105c672ab3SMiklos Szeredi struct mutex mutex; 1114582a4abSFeng Shuo }; 1124582a4abSFeng Shuo 1134582a4abSFeng Shuo /** FUSE inode state bits */ 1144582a4abSFeng Shuo enum { 1154582a4abSFeng Shuo /** Advise readdirplus */ 1164582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1176314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1186314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 11906a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 12006a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 121d8a5ba45SMiklos Szeredi }; 122d8a5ba45SMiklos Szeredi 123da5e4714SMiklos Szeredi struct fuse_conn; 124da5e4714SMiklos Szeredi 125b6aeadedSMiklos Szeredi /** FUSE specific file data */ 126b6aeadedSMiklos Szeredi struct fuse_file { 127da5e4714SMiklos Szeredi /** Fuse connection for this file */ 128da5e4714SMiklos Szeredi struct fuse_conn *fc; 129da5e4714SMiklos Szeredi 130b6aeadedSMiklos Szeredi /** Request reserved for flush and release */ 13133649c91SMiklos Szeredi struct fuse_req *reserved_req; 132b6aeadedSMiklos Szeredi 133acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 134acf99433STejun Heo u64 kh; 135acf99433STejun Heo 136b6aeadedSMiklos Szeredi /** File handle used by userspace */ 137b6aeadedSMiklos Szeredi u64 fh; 138c756e0a4SMiklos Szeredi 139da5e4714SMiklos Szeredi /** Node id of this file */ 140da5e4714SMiklos Szeredi u64 nodeid; 141da5e4714SMiklos Szeredi 142c756e0a4SMiklos Szeredi /** Refcount */ 1434e8c2eb5SElena Reshetova refcount_t count; 14493a8c3cdSMiklos Szeredi 145c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 146c7b7143cSMiklos Szeredi u32 open_flags; 147c7b7143cSMiklos Szeredi 14893a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 14993a8c3cdSMiklos Szeredi struct list_head write_entry; 15095668a69STejun Heo 15195668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 15295668a69STejun Heo struct rb_node polled_node; 15395668a69STejun Heo 15495668a69STejun Heo /** Wait queue head for poll */ 15595668a69STejun Heo wait_queue_head_t poll_wait; 15637fb3a30SMiklos Szeredi 15737fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 15837fb3a30SMiklos Szeredi bool flock:1; 159b6aeadedSMiklos Szeredi }; 160b6aeadedSMiklos Szeredi 161334f485dSMiklos Szeredi /** One input argument of a request */ 162334f485dSMiklos Szeredi struct fuse_in_arg { 163334f485dSMiklos Szeredi unsigned size; 164334f485dSMiklos Szeredi const void *value; 165334f485dSMiklos Szeredi }; 166334f485dSMiklos Szeredi 167334f485dSMiklos Szeredi /** The request input */ 168334f485dSMiklos Szeredi struct fuse_in { 169334f485dSMiklos Szeredi /** The request header */ 170334f485dSMiklos Szeredi struct fuse_in_header h; 171334f485dSMiklos Szeredi 172334f485dSMiklos Szeredi /** True if the data for the last argument is in req->pages */ 173334f485dSMiklos Szeredi unsigned argpages:1; 174334f485dSMiklos Szeredi 175334f485dSMiklos Szeredi /** Number of arguments */ 176334f485dSMiklos Szeredi unsigned numargs; 177334f485dSMiklos Szeredi 178334f485dSMiklos Szeredi /** Array of arguments */ 179334f485dSMiklos Szeredi struct fuse_in_arg args[3]; 180334f485dSMiklos Szeredi }; 181334f485dSMiklos Szeredi 182334f485dSMiklos Szeredi /** One output argument of a request */ 183334f485dSMiklos Szeredi struct fuse_arg { 184334f485dSMiklos Szeredi unsigned size; 185334f485dSMiklos Szeredi void *value; 186334f485dSMiklos Szeredi }; 187334f485dSMiklos Szeredi 188334f485dSMiklos Szeredi /** The request output */ 189334f485dSMiklos Szeredi struct fuse_out { 190334f485dSMiklos Szeredi /** Header returned from userspace */ 191334f485dSMiklos Szeredi struct fuse_out_header h; 192334f485dSMiklos Szeredi 193095da6cbSMiklos Szeredi /* 194095da6cbSMiklos Szeredi * The following bitfields are not changed during the request 195095da6cbSMiklos Szeredi * processing 196095da6cbSMiklos Szeredi */ 197095da6cbSMiklos Szeredi 198334f485dSMiklos Szeredi /** Last argument is variable length (can be shorter than 199334f485dSMiklos Szeredi arg->size) */ 200334f485dSMiklos Szeredi unsigned argvar:1; 201334f485dSMiklos Szeredi 202334f485dSMiklos Szeredi /** Last argument is a list of pages to copy data to */ 203334f485dSMiklos Szeredi unsigned argpages:1; 204334f485dSMiklos Szeredi 205334f485dSMiklos Szeredi /** Zero partially or not copied pages */ 206334f485dSMiklos Szeredi unsigned page_zeroing:1; 207334f485dSMiklos Szeredi 208ce534fb0SMiklos Szeredi /** Pages may be replaced with new ones */ 209ce534fb0SMiklos Szeredi unsigned page_replace:1; 210ce534fb0SMiklos Szeredi 211334f485dSMiklos Szeredi /** Number or arguments */ 212334f485dSMiklos Szeredi unsigned numargs; 213334f485dSMiklos Szeredi 214334f485dSMiklos Szeredi /** Array of arguments */ 215f704dcb5SMiklos Szeredi struct fuse_arg args[2]; 216334f485dSMiklos Szeredi }; 217334f485dSMiklos Szeredi 218b2430d75SMaxim Patlasov /** FUSE page descriptor */ 219b2430d75SMaxim Patlasov struct fuse_page_desc { 220b2430d75SMaxim Patlasov unsigned int length; 221b2430d75SMaxim Patlasov unsigned int offset; 222b2430d75SMaxim Patlasov }; 223b2430d75SMaxim Patlasov 2247078187aSMiklos Szeredi struct fuse_args { 2257078187aSMiklos Szeredi struct { 2267078187aSMiklos Szeredi struct { 2277078187aSMiklos Szeredi uint32_t opcode; 2287078187aSMiklos Szeredi uint64_t nodeid; 2297078187aSMiklos Szeredi } h; 2307078187aSMiklos Szeredi unsigned numargs; 2317078187aSMiklos Szeredi struct fuse_in_arg args[3]; 2327078187aSMiklos Szeredi 2337078187aSMiklos Szeredi } in; 2347078187aSMiklos Szeredi struct { 2357078187aSMiklos Szeredi unsigned argvar:1; 2367078187aSMiklos Szeredi unsigned numargs; 2377078187aSMiklos Szeredi struct fuse_arg args[2]; 2387078187aSMiklos Szeredi } out; 2397078187aSMiklos Szeredi }; 2407078187aSMiklos Szeredi 2417078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2427078187aSMiklos Szeredi 24301e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 24401e9d11aSMaxim Patlasov struct fuse_io_priv { 245744742d6SSeth Forshee struct kref refcnt; 24601e9d11aSMaxim Patlasov int async; 24701e9d11aSMaxim Patlasov spinlock_t lock; 24801e9d11aSMaxim Patlasov unsigned reqs; 24901e9d11aSMaxim Patlasov ssize_t bytes; 25001e9d11aSMaxim Patlasov size_t size; 25101e9d11aSMaxim Patlasov __u64 offset; 25201e9d11aSMaxim Patlasov bool write; 25361c12b49SAshish Samant bool should_dirty; 25401e9d11aSMaxim Patlasov int err; 25501e9d11aSMaxim Patlasov struct kiocb *iocb; 2569d5722b7SChristoph Hellwig struct completion *done; 2577879c4e5SAshish Sangwan bool blocking; 25801e9d11aSMaxim Patlasov }; 25901e9d11aSMaxim Patlasov 260e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 261744742d6SSeth Forshee { \ 2621e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 263744742d6SSeth Forshee .async = 0, \ 264e1c0eecbSMiklos Szeredi .iocb = i, \ 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 470*8cb08329SEric W. Biederman /** The user namespace for this mount */ 471*8cb08329SEric W. Biederman struct user_namespace *user_ns; 472*8cb08329SEric W. Biederman 473db50b96cSMiklos Szeredi /** Maximum read size */ 474db50b96cSMiklos Szeredi unsigned max_read; 475db50b96cSMiklos Szeredi 476413ef8cbSMiklos Szeredi /** Maximum write size */ 477413ef8cbSMiklos Szeredi unsigned max_write; 478413ef8cbSMiklos Szeredi 479f88996a9SMiklos Szeredi /** Input queue */ 480f88996a9SMiklos Szeredi struct fuse_iqueue iq; 481334f485dSMiklos Szeredi 482acf99433STejun Heo /** The next unique kernel file handle */ 483acf99433STejun Heo u64 khctr; 484acf99433STejun Heo 48595668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 48695668a69STejun Heo struct rb_root polled_files; 48795668a69STejun Heo 4887a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 4897a6d3c8bSCsaba Henk unsigned max_background; 4907a6d3c8bSCsaba Henk 4917a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 4927a6d3c8bSCsaba Henk unsigned congestion_threshold; 4937a6d3c8bSCsaba Henk 49408a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 49508a53cdcSMiklos Szeredi unsigned num_background; 49608a53cdcSMiklos Szeredi 497d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 498d12def1bSMiklos Szeredi unsigned active_background; 499d12def1bSMiklos Szeredi 500d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 501d12def1bSMiklos Szeredi struct list_head bg_queue; 502d12def1bSMiklos Szeredi 503796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 504796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 505796523fbSMaxim Patlasov int initialized; 506796523fbSMaxim Patlasov 50708a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 50808a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 50908a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 51008a53cdcSMiklos Szeredi int blocked; 51108a53cdcSMiklos Szeredi 51208a53cdcSMiklos Szeredi /** waitq for blocked connection */ 51308a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 51408a53cdcSMiklos Szeredi 515de5e3decSMiklos Szeredi /** waitq for reserved requests */ 516de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 517de5e3decSMiklos Szeredi 51869a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 51969a53bf2SMiklos Szeredi abort and device release */ 520095da6cbSMiklos Szeredi unsigned connected; 5211e9a4ed9SMiklos Szeredi 5223b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 5233b7008b2SSzymon Lukasz bool aborted; 5243b7008b2SSzymon Lukasz 525095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 526095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 527095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 528334f485dSMiklos Szeredi unsigned conn_error:1; 529334f485dSMiklos Szeredi 5300ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5310ec7ca41SMiklos Szeredi unsigned conn_init:1; 5320ec7ca41SMiklos Szeredi 5339cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5349cd68455SMiklos Szeredi unsigned async_read:1; 5359cd68455SMiklos Szeredi 5363b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 5373b7008b2SSzymon Lukasz unsigned abort_err:1; 5383b7008b2SSzymon Lukasz 5396ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5406ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5416ff958edSMiklos Szeredi 54233670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 54333670fa2SMiklos Szeredi unsigned export_support:1; 54433670fa2SMiklos Szeredi 545d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 546d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 547d5cd66c5SPavel Emelyanov 5485c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5495c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5505c672ab3SMiklos Szeredi 5515e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5525e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5535e940c1dSMiklos Szeredi 554095da6cbSMiklos Szeredi /* 555095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 556095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 557095da6cbSMiklos Szeredi */ 558095da6cbSMiklos Szeredi 5597678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 5607678ac50SAndrew Gallagher unsigned no_open:1; 5617678ac50SAndrew Gallagher 562b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 563b6aeadedSMiklos Szeredi unsigned no_fsync:1; 564b6aeadedSMiklos Szeredi 56582547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 56682547981SMiklos Szeredi unsigned no_fsyncdir:1; 56782547981SMiklos Szeredi 568b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 569b6aeadedSMiklos Szeredi unsigned no_flush:1; 570b6aeadedSMiklos Szeredi 57192a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 57292a8780eSMiklos Szeredi unsigned no_setxattr:1; 57392a8780eSMiklos Szeredi 57492a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 57592a8780eSMiklos Szeredi unsigned no_getxattr:1; 57692a8780eSMiklos Szeredi 57792a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 57892a8780eSMiklos Szeredi unsigned no_listxattr:1; 57992a8780eSMiklos Szeredi 58092a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 58192a8780eSMiklos Szeredi unsigned no_removexattr:1; 58292a8780eSMiklos Szeredi 58337fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 58471421259SMiklos Szeredi unsigned no_lock:1; 58571421259SMiklos Szeredi 58631d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 58731d40d74SMiklos Szeredi unsigned no_access:1; 58831d40d74SMiklos Szeredi 589fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 590fd72faacSMiklos Szeredi unsigned no_create:1; 591fd72faacSMiklos Szeredi 592a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 593a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 594a4d27e75SMiklos Szeredi 595b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 596b2d2272fSMiklos Szeredi unsigned no_bmap:1; 597b2d2272fSMiklos Szeredi 59895668a69STejun Heo /** Is poll not implemented by fs? */ 59995668a69STejun Heo unsigned no_poll:1; 60095668a69STejun Heo 60178bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 60278bb6cb9SMiklos Szeredi unsigned big_writes:1; 60378bb6cb9SMiklos Szeredi 604e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 605e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 606e0a43ddcSMiklos Szeredi 60737fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 60837fb3a30SMiklos Szeredi unsigned no_flock:1; 60937fb3a30SMiklos Szeredi 610519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 611519c6040SMiklos Szeredi unsigned no_fallocate:1; 612519c6040SMiklos Szeredi 6131560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6141560c974SMiklos Szeredi unsigned no_rename2:1; 6151560c974SMiklos Szeredi 61672d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 61772d0d248SBrian Foster unsigned auto_inval_data:1; 61872d0d248SBrian Foster 619634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6200b05b183SAnand V. Avati unsigned do_readdirplus:1; 6210b05b183SAnand V. Avati 622634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 623634734b6SEric Wong unsigned readdirplus_auto:1; 624634734b6SEric Wong 62560b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 62660b9df7aSMiklos Szeredi unsigned async_dio:1; 62760b9df7aSMiklos Szeredi 6280b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6290b5da8dbSRavishankar N unsigned no_lseek:1; 6300b5da8dbSRavishankar N 63160bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 63260bcc88aSSeth Forshee unsigned posix_acl:1; 63360bcc88aSSeth Forshee 63429433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 63529433a29SMiklos Szeredi unsigned default_permissions:1; 63629433a29SMiklos Szeredi 63729433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 63829433a29SMiklos Szeredi unsigned allow_other:1; 63929433a29SMiklos Szeredi 6400cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6410cd5b885SMiklos Szeredi atomic_t num_waiting; 6420cd5b885SMiklos Szeredi 64345714d65SMiklos Szeredi /** Negotiated minor version */ 64445714d65SMiklos Szeredi unsigned minor; 64545714d65SMiklos Szeredi 646bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 647bafa9654SMiklos Szeredi struct list_head entry; 648bafa9654SMiklos Szeredi 649b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 650b6f2fcbcSMiklos Szeredi dev_t dev; 651bafa9654SMiklos Szeredi 652bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 653bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 654bafa9654SMiklos Szeredi 655bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 656bafa9654SMiklos Szeredi int ctl_ndents; 657385a17bfSJeff Dike 6589c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 6599c8ef561SMiklos Szeredi u32 scramble_key[4]; 6600ec7ca41SMiklos Szeredi 6610ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 6620ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 6631fb69e78SMiklos Szeredi 6641fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 6651fb69e78SMiklos Szeredi u64 attr_version; 66643901aabSTejun Heo 66743901aabSTejun Heo /** Called on final put */ 66843901aabSTejun Heo void (*release)(struct fuse_conn *); 6693b463ae0SJohn Muir 6703b463ae0SJohn Muir /** Super block for this connection. */ 6713b463ae0SJohn Muir struct super_block *sb; 6723b463ae0SJohn Muir 6733b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 6743b463ae0SJohn Muir struct rw_semaphore killsb; 675cc080e9eSMiklos Szeredi 676cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 677cc080e9eSMiklos Szeredi struct list_head devices; 678d8a5ba45SMiklos Szeredi }; 679d8a5ba45SMiklos Szeredi 680d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 681d8a5ba45SMiklos Szeredi { 6826383bdaaSMiklos Szeredi return sb->s_fs_info; 683d8a5ba45SMiklos Szeredi } 684d8a5ba45SMiklos Szeredi 685d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 686d8a5ba45SMiklos Szeredi { 687d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 688d8a5ba45SMiklos Szeredi } 689d8a5ba45SMiklos Szeredi 690d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 691d8a5ba45SMiklos Szeredi { 692d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 693d8a5ba45SMiklos Szeredi } 694d8a5ba45SMiklos Szeredi 695d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 696d8a5ba45SMiklos Szeredi { 697d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 698d8a5ba45SMiklos Szeredi } 699d8a5ba45SMiklos Szeredi 700334f485dSMiklos Szeredi /** Device operations */ 7014b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 702334f485dSMiklos Szeredi 7034269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 7040ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 705dbd561d2SMiklos Szeredi 706d8a5ba45SMiklos Szeredi /** 7073b463ae0SJohn Muir * Inode to nodeid comparison. 7083b463ae0SJohn Muir */ 7093b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7103b463ae0SJohn Muir 7113b463ae0SJohn Muir /** 712e5e5558eSMiklos Szeredi * Get a filled in inode 713e5e5558eSMiklos Szeredi */ 714b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7151fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7161fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 717e5e5558eSMiklos Szeredi 71813983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 71933670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 72033670fa2SMiklos Szeredi 721e5e5558eSMiklos Szeredi /** 722e5e5558eSMiklos Szeredi * Send FORGET command 723e5e5558eSMiklos Szeredi */ 72407e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 725b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 726e5e5558eSMiklos Szeredi 72707e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 72807e77dcaSMiklos Szeredi 7290b05b183SAnand V. Avati /* Used by READDIRPLUS */ 7300b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 7310b05b183SAnand V. Avati 732e5e5558eSMiklos Szeredi /** 733361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 73404730fefSMiklos Szeredi */ 735a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 7362106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 73704730fefSMiklos Szeredi 73804730fefSMiklos Szeredi /** 73904730fefSMiklos Szeredi * Send OPEN or OPENDIR request 74004730fefSMiklos Szeredi */ 74191fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 74204730fefSMiklos Szeredi 743acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 744fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 745c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 746fd72faacSMiklos Szeredi 7478b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags); 748c756e0a4SMiklos Szeredi 74904730fefSMiklos Szeredi /** 75004730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 75104730fefSMiklos Szeredi */ 7528b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode); 75304730fefSMiklos Szeredi 75404730fefSMiklos Szeredi /** 75582547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 75682547981SMiklos Szeredi */ 75702c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 75802c24a82SJosef Bacik int datasync, int isdir); 75982547981SMiklos Szeredi 76082547981SMiklos Szeredi /** 76195668a69STejun Heo * Notify poll wakeup 76295668a69STejun Heo */ 76395668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 76495668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 76595668a69STejun Heo 76695668a69STejun Heo /** 7671779381dSMiklos Szeredi * Initialize file operations on a regular file 768b6aeadedSMiklos Szeredi */ 769b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 770b6aeadedSMiklos Szeredi 771b6aeadedSMiklos Szeredi /** 7721779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 773e5e5558eSMiklos Szeredi */ 774e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 775e5e5558eSMiklos Szeredi 776e5e5558eSMiklos Szeredi /** 7771779381dSMiklos Szeredi * Initialize inode and file operations on a directory 778e5e5558eSMiklos Szeredi */ 779e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 780e5e5558eSMiklos Szeredi 781e5e5558eSMiklos Szeredi /** 7821779381dSMiklos Szeredi * Initialize inode operations on a symlink 783e5e5558eSMiklos Szeredi */ 784e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 785e5e5558eSMiklos Szeredi 786e5e5558eSMiklos Szeredi /** 787e5e5558eSMiklos Szeredi * Change attributes of an inode 788e5e5558eSMiklos Szeredi */ 7891fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 7901fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 791e5e5558eSMiklos Szeredi 7923be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 7933be5a52bSMiklos Szeredi u64 attr_valid); 7943be5a52bSMiklos Szeredi 795e5e5558eSMiklos Szeredi /** 796334f485dSMiklos Szeredi * Initialize the client device 797334f485dSMiklos Szeredi */ 798334f485dSMiklos Szeredi int fuse_dev_init(void); 799334f485dSMiklos Szeredi 800334f485dSMiklos Szeredi /** 801334f485dSMiklos Szeredi * Cleanup the client device 802334f485dSMiklos Szeredi */ 803334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 804334f485dSMiklos Szeredi 805bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8067736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 807bafa9654SMiklos Szeredi 808334f485dSMiklos Szeredi /** 809334f485dSMiklos Szeredi * Allocate a request 810334f485dSMiklos Szeredi */ 8114250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 812334f485dSMiklos Szeredi 8134250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8143be5a52bSMiklos Szeredi 815334f485dSMiklos Szeredi /** 816334f485dSMiklos Szeredi * Free a request 817334f485dSMiklos Szeredi */ 818334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 819334f485dSMiklos Szeredi 820334f485dSMiklos Szeredi /** 821b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 822b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 823334f485dSMiklos Szeredi */ 824b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 8258b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 8268b41e671SMaxim Patlasov unsigned npages); 827b111c8c0SMaxim Patlasov 82836cf66edSMaxim Patlasov /* 82936cf66edSMaxim Patlasov * Increment reference count on request 83036cf66edSMaxim Patlasov */ 83136cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 83236cf66edSMaxim Patlasov 833b111c8c0SMaxim Patlasov /** 83433649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 83533649c91SMiklos Szeredi */ 836b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 837b111c8c0SMaxim Patlasov struct file *file); 83833649c91SMiklos Szeredi 83933649c91SMiklos Szeredi /** 840ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 841ce1d5a49SMiklos Szeredi * the request. 842334f485dSMiklos Szeredi */ 843334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 844334f485dSMiklos Szeredi 845334f485dSMiklos Szeredi /** 8467c352bdfSMiklos Szeredi * Send a request (synchronous) 847334f485dSMiklos Szeredi */ 848b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 849334f485dSMiklos Szeredi 850334f485dSMiklos Szeredi /** 8517078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 8527078187aSMiklos Szeredi */ 8537078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 8547078187aSMiklos Szeredi 8557078187aSMiklos Szeredi /** 856334f485dSMiklos Szeredi * Send a request in the background 857334f485dSMiklos Szeredi */ 858b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 859334f485dSMiklos Szeredi 860b93f858aSTejun Heo void fuse_request_send_background_locked(struct fuse_conn *fc, 861b93f858aSTejun Heo struct fuse_req *req); 8623be5a52bSMiklos Szeredi 8635a5fb1eaSMiklos Szeredi /* Abort all requests */ 8643b7008b2SSzymon Lukasz void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); 86569a53bf2SMiklos Szeredi 8661e9a4ed9SMiklos Szeredi /** 867e5e5558eSMiklos Szeredi * Invalidate inode attributes 868e5e5558eSMiklos Szeredi */ 869e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 870bafa9654SMiklos Szeredi 871dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 872dbd561d2SMiklos Szeredi 873451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 874451418fcSAndrew Gallagher 875bafa9654SMiklos Szeredi /** 876bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 877bafa9654SMiklos Szeredi */ 878bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 879bafa9654SMiklos Szeredi 880bafa9654SMiklos Szeredi /** 8810d179aa5STejun Heo * Initialize fuse_conn 8820d179aa5STejun Heo */ 883*8cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); 8840d179aa5STejun Heo 8850d179aa5STejun Heo /** 886bafa9654SMiklos Szeredi * Release reference to fuse_conn 887bafa9654SMiklos Szeredi */ 888bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 889bafa9654SMiklos Szeredi 890cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 891cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 892cc080e9eSMiklos Szeredi 893bafa9654SMiklos Szeredi /** 894bafa9654SMiklos Szeredi * Add connection to control filesystem 895bafa9654SMiklos Szeredi */ 896bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 897bafa9654SMiklos Szeredi 898bafa9654SMiklos Szeredi /** 899bafa9654SMiklos Szeredi * Remove connection from control filesystem 900bafa9654SMiklos Szeredi */ 901bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 902a5bfffacSTimo Savola 903a5bfffacSTimo Savola /** 904a5bfffacSTimo Savola * Is file type valid? 905a5bfffacSTimo Savola */ 906a5bfffacSTimo Savola int fuse_valid_type(int m); 907e57ac683SMiklos Szeredi 908e57ac683SMiklos Szeredi /** 909c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 910e57ac683SMiklos Szeredi */ 911c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 912f3332114SMiklos Szeredi 913f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 914bcb4be80SMiklos Szeredi 915703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 916703c7362SSeth Forshee 9175b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 9183be5a52bSMiklos Szeredi 9193be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9203be5a52bSMiklos Szeredi 9213be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9223be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9235c5c5e51SMiklos Szeredi 9245c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc); 92529d434b3STejun Heo 9263b463ae0SJohn Muir /** 9273b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9283b463ae0SJohn Muir */ 9293b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9303b463ae0SJohn Muir loff_t offset, loff_t len); 9313b463ae0SJohn Muir 9323b463ae0SJohn Muir /** 9333b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9343b463ae0SJohn Muir * the dentry matching parent/name. 935451d0f59SJohn Muir * 936451d0f59SJohn Muir * If the child_nodeid is non-zero and: 937451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 938451d0f59SJohn Muir * - is not a mount point 939451d0f59SJohn Muir * - is a file or oan empty directory 940451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 9413b463ae0SJohn Muir */ 9423b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 943451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 9443b463ae0SJohn Muir 94508cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 94608cbf542STejun Heo bool isdir); 947ea8cd333SPavel Emelyanov 948ea8cd333SPavel Emelyanov /** 949ea8cd333SPavel Emelyanov * fuse_direct_io() flags 950ea8cd333SPavel Emelyanov */ 951ea8cd333SPavel Emelyanov 952ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 953ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 954ea8cd333SPavel Emelyanov 955ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 956ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 957ea8cd333SPavel Emelyanov 958d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 959d22a943fSAl Viro loff_t *ppos, int flags); 96008cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 96108cbf542STejun Heo unsigned int flags); 962b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 963b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 964076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 96508cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 96608cbf542STejun Heo 967b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 968b0aa7606SMaxim Patlasov 969ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 9701e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 971a1d75f25SMiklos Szeredi 97262490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 973efb9fa9eSMaxim Patlasov struct file *file); 974efb9fa9eSMaxim Patlasov 9759759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 9769759bd51SMiklos Szeredi 9775c672ab3SMiklos Szeredi void fuse_unlock_inode(struct inode *inode); 9785c672ab3SMiklos Szeredi void fuse_lock_inode(struct inode *inode); 9795c672ab3SMiklos Szeredi 98060bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 98160bcc88aSSeth Forshee size_t size, int flags); 98260bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 98360bcc88aSSeth Forshee size_t size); 984703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 98560bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 986703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 98760bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 98860bcc88aSSeth Forshee 98960bcc88aSSeth Forshee struct posix_acl; 99060bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 99160bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 992703c7362SSeth Forshee 99329d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 994