1d8a5ba45SMiklos Szeredi /* 2d8a5ba45SMiklos Szeredi FUSE: Filesystem in Userspace 31729a16cSMiklos Szeredi Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu> 4d8a5ba45SMiklos Szeredi 5d8a5ba45SMiklos Szeredi This program can be distributed under the terms of the GNU GPL. 6d8a5ba45SMiklos Szeredi See the file COPYING. 7d8a5ba45SMiklos Szeredi */ 8d8a5ba45SMiklos Szeredi 929d434b3STejun Heo #ifndef _FS_FUSE_I_H 1029d434b3STejun Heo #define _FS_FUSE_I_H 1129d434b3STejun Heo 12d8a5ba45SMiklos Szeredi #include <linux/fuse.h> 13d8a5ba45SMiklos Szeredi #include <linux/fs.h> 1451eb01e7SMiklos Szeredi #include <linux/mount.h> 15d8a5ba45SMiklos Szeredi #include <linux/wait.h> 16d8a5ba45SMiklos Szeredi #include <linux/list.h> 17d8a5ba45SMiklos Szeredi #include <linux/spinlock.h> 18d8a5ba45SMiklos Szeredi #include <linux/mm.h> 19d8a5ba45SMiklos Szeredi #include <linux/backing-dev.h> 20bafa9654SMiklos Szeredi #include <linux/mutex.h> 213be5a52bSMiklos Szeredi #include <linux/rwsem.h> 2295668a69STejun Heo #include <linux/rbtree.h> 2395668a69STejun Heo #include <linux/poll.h> 245a18ec17SMiklos Szeredi #include <linux/workqueue.h> 25744742d6SSeth Forshee #include <linux/kref.h> 2660bcc88aSSeth Forshee #include <linux/xattr.h> 270b6e9ea0SSeth Forshee #include <linux/pid_namespace.h> 284e8c2eb5SElena Reshetova #include <linux/refcount.h> 298cb08329SEric W. Biederman #include <linux/user_namespace.h> 30d8a5ba45SMiklos Szeredi 31334f485dSMiklos Szeredi /** Max number of pages that can be used in a single read request */ 32334f485dSMiklos Szeredi #define FUSE_MAX_PAGES_PER_REQ 32 33334f485dSMiklos Szeredi 343be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 353be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 363be5a52bSMiklos Szeredi 371d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 381d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 391d3d752bSMiklos Szeredi 40bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4179a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 42bafa9654SMiklos Szeredi 434250c066SMaxim Patlasov /** Number of page pointers embedded in fuse_req */ 444250c066SMaxim Patlasov #define FUSE_REQ_INLINE_PAGES 1 454250c066SMaxim Patlasov 46bafa9654SMiklos Szeredi /** List of active connections */ 47bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 48bafa9654SMiklos Szeredi 49bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 50bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 51413ef8cbSMiklos Szeredi 5279a9d994SCsaba Henk /** Module parameters */ 5379a9d994SCsaba Henk extern unsigned max_user_bgreq; 5479a9d994SCsaba Henk extern unsigned max_user_congthresh; 5579a9d994SCsaba Henk 5607e77dcaSMiklos Szeredi /* One forget request */ 5707e77dcaSMiklos Szeredi struct fuse_forget_link { 5802c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 5907e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6007e77dcaSMiklos Szeredi }; 6107e77dcaSMiklos Szeredi 62d8a5ba45SMiklos Szeredi /** FUSE inode */ 63d8a5ba45SMiklos Szeredi struct fuse_inode { 64d8a5ba45SMiklos Szeredi /** Inode data */ 65d8a5ba45SMiklos Szeredi struct inode inode; 66d8a5ba45SMiklos Szeredi 67d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 68d8a5ba45SMiklos Szeredi * and kernel */ 69d8a5ba45SMiklos Szeredi u64 nodeid; 70d8a5ba45SMiklos Szeredi 719e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 729e6268dbSMiklos Szeredi u64 nlookup; 739e6268dbSMiklos Szeredi 74e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7507e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 76e5e5558eSMiklos Szeredi 77d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 780a0898cfSMiklos Szeredi u64 i_time; 79ebc14c4dSMiklos Szeredi 80ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 81ebc14c4dSMiklos Szeredi preserve the original mode */ 82541af6a0SAl Viro umode_t orig_i_mode; 831fb69e78SMiklos Szeredi 8445c72cd7SPavel Shilovsky /** 64 bit inode number */ 8545c72cd7SPavel Shilovsky u64 orig_ino; 8645c72cd7SPavel Shilovsky 871fb69e78SMiklos Szeredi /** Version of last attribute change */ 881fb69e78SMiklos Szeredi u64 attr_version; 8993a8c3cdSMiklos Szeredi 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 10669e34551SMiklos Szeredi /* readdir cache */ 10769e34551SMiklos Szeredi struct { 10869e34551SMiklos Szeredi /* true if fully cached */ 10969e34551SMiklos Szeredi bool cached; 11069e34551SMiklos Szeredi 11169e34551SMiklos Szeredi /* size of cache */ 11269e34551SMiklos Szeredi loff_t size; 11369e34551SMiklos Szeredi 11469e34551SMiklos Szeredi /* position at end of cache (position of next entry) */ 11569e34551SMiklos Szeredi loff_t pos; 11669e34551SMiklos Szeredi 1173494927eSMiklos Szeredi /* version of the cache */ 1183494927eSMiklos Szeredi u64 version; 1193494927eSMiklos Szeredi 120*7118883bSMiklos Szeredi /* modification time of directory when cache was started */ 121*7118883bSMiklos Szeredi struct timespec64 mtime; 122*7118883bSMiklos Szeredi 12369e34551SMiklos Szeredi /* protects above fields */ 12469e34551SMiklos Szeredi spinlock_t lock; 12569e34551SMiklos Szeredi } rdc; 12669e34551SMiklos Szeredi 1274582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1284582a4abSFeng Shuo unsigned long state; 1295c672ab3SMiklos Szeredi 1305c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1315c672ab3SMiklos Szeredi struct mutex mutex; 1324582a4abSFeng Shuo }; 1334582a4abSFeng Shuo 1344582a4abSFeng Shuo /** FUSE inode state bits */ 1354582a4abSFeng Shuo enum { 1364582a4abSFeng Shuo /** Advise readdirplus */ 1374582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1386314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1396314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 14006a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 14106a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 142d8a5ba45SMiklos Szeredi }; 143d8a5ba45SMiklos Szeredi 144da5e4714SMiklos Szeredi struct fuse_conn; 145da5e4714SMiklos Szeredi 146b6aeadedSMiklos Szeredi /** FUSE specific file data */ 147b6aeadedSMiklos Szeredi struct fuse_file { 148da5e4714SMiklos Szeredi /** Fuse connection for this file */ 149da5e4714SMiklos Szeredi struct fuse_conn *fc; 150da5e4714SMiklos Szeredi 151b6aeadedSMiklos Szeredi /** Request reserved for flush and release */ 15233649c91SMiklos Szeredi struct fuse_req *reserved_req; 153b6aeadedSMiklos Szeredi 154acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 155acf99433STejun Heo u64 kh; 156acf99433STejun Heo 157b6aeadedSMiklos Szeredi /** File handle used by userspace */ 158b6aeadedSMiklos Szeredi u64 fh; 159c756e0a4SMiklos Szeredi 160da5e4714SMiklos Szeredi /** Node id of this file */ 161da5e4714SMiklos Szeredi u64 nodeid; 162da5e4714SMiklos Szeredi 163c756e0a4SMiklos Szeredi /** Refcount */ 1644e8c2eb5SElena Reshetova refcount_t count; 16593a8c3cdSMiklos Szeredi 166c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 167c7b7143cSMiklos Szeredi u32 open_flags; 168c7b7143cSMiklos Szeredi 16993a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 17093a8c3cdSMiklos Szeredi struct list_head write_entry; 17195668a69STejun Heo 1725d7bc7e8SMiklos Szeredi /* Readdir related */ 1735d7bc7e8SMiklos Szeredi struct { 1745d7bc7e8SMiklos Szeredi /* 1755d7bc7e8SMiklos Szeredi * Protects below fields against (crazy) parallel readdir on 1765d7bc7e8SMiklos Szeredi * same open file. Uncontended in the normal case. 1775d7bc7e8SMiklos Szeredi */ 1785d7bc7e8SMiklos Szeredi struct mutex lock; 1795d7bc7e8SMiklos Szeredi 1805d7bc7e8SMiklos Szeredi /* Dir stream position */ 1815d7bc7e8SMiklos Szeredi loff_t pos; 1825d7bc7e8SMiklos Szeredi 1835d7bc7e8SMiklos Szeredi /* Offset in cache */ 1845d7bc7e8SMiklos Szeredi loff_t cache_off; 1853494927eSMiklos Szeredi 1863494927eSMiklos Szeredi /* Version of cache we are reading */ 1873494927eSMiklos Szeredi u64 version; 1883494927eSMiklos Szeredi 1895d7bc7e8SMiklos Szeredi } readdir; 1905d7bc7e8SMiklos Szeredi 19195668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 19295668a69STejun Heo struct rb_node polled_node; 19395668a69STejun Heo 19495668a69STejun Heo /** Wait queue head for poll */ 19595668a69STejun Heo wait_queue_head_t poll_wait; 19637fb3a30SMiklos Szeredi 19737fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 19837fb3a30SMiklos Szeredi bool flock:1; 199b6aeadedSMiklos Szeredi }; 200b6aeadedSMiklos Szeredi 201334f485dSMiklos Szeredi /** One input argument of a request */ 202334f485dSMiklos Szeredi struct fuse_in_arg { 203334f485dSMiklos Szeredi unsigned size; 204334f485dSMiklos Szeredi const void *value; 205334f485dSMiklos Szeredi }; 206334f485dSMiklos Szeredi 207334f485dSMiklos Szeredi /** The request input */ 208334f485dSMiklos Szeredi struct fuse_in { 209334f485dSMiklos Szeredi /** The request header */ 210334f485dSMiklos Szeredi struct fuse_in_header h; 211334f485dSMiklos Szeredi 212334f485dSMiklos Szeredi /** True if the data for the last argument is in req->pages */ 213334f485dSMiklos Szeredi unsigned argpages:1; 214334f485dSMiklos Szeredi 215334f485dSMiklos Szeredi /** Number of arguments */ 216334f485dSMiklos Szeredi unsigned numargs; 217334f485dSMiklos Szeredi 218334f485dSMiklos Szeredi /** Array of arguments */ 219334f485dSMiklos Szeredi struct fuse_in_arg args[3]; 220334f485dSMiklos Szeredi }; 221334f485dSMiklos Szeredi 222334f485dSMiklos Szeredi /** One output argument of a request */ 223334f485dSMiklos Szeredi struct fuse_arg { 224334f485dSMiklos Szeredi unsigned size; 225334f485dSMiklos Szeredi void *value; 226334f485dSMiklos Szeredi }; 227334f485dSMiklos Szeredi 228334f485dSMiklos Szeredi /** The request output */ 229334f485dSMiklos Szeredi struct fuse_out { 230334f485dSMiklos Szeredi /** Header returned from userspace */ 231334f485dSMiklos Szeredi struct fuse_out_header h; 232334f485dSMiklos Szeredi 233095da6cbSMiklos Szeredi /* 234095da6cbSMiklos Szeredi * The following bitfields are not changed during the request 235095da6cbSMiklos Szeredi * processing 236095da6cbSMiklos Szeredi */ 237095da6cbSMiklos Szeredi 238334f485dSMiklos Szeredi /** Last argument is variable length (can be shorter than 239334f485dSMiklos Szeredi arg->size) */ 240334f485dSMiklos Szeredi unsigned argvar:1; 241334f485dSMiklos Szeredi 242334f485dSMiklos Szeredi /** Last argument is a list of pages to copy data to */ 243334f485dSMiklos Szeredi unsigned argpages:1; 244334f485dSMiklos Szeredi 245334f485dSMiklos Szeredi /** Zero partially or not copied pages */ 246334f485dSMiklos Szeredi unsigned page_zeroing:1; 247334f485dSMiklos Szeredi 248ce534fb0SMiklos Szeredi /** Pages may be replaced with new ones */ 249ce534fb0SMiklos Szeredi unsigned page_replace:1; 250ce534fb0SMiklos Szeredi 251334f485dSMiklos Szeredi /** Number or arguments */ 252334f485dSMiklos Szeredi unsigned numargs; 253334f485dSMiklos Szeredi 254334f485dSMiklos Szeredi /** Array of arguments */ 255f704dcb5SMiklos Szeredi struct fuse_arg args[2]; 256334f485dSMiklos Szeredi }; 257334f485dSMiklos Szeredi 258b2430d75SMaxim Patlasov /** FUSE page descriptor */ 259b2430d75SMaxim Patlasov struct fuse_page_desc { 260b2430d75SMaxim Patlasov unsigned int length; 261b2430d75SMaxim Patlasov unsigned int offset; 262b2430d75SMaxim Patlasov }; 263b2430d75SMaxim Patlasov 2647078187aSMiklos Szeredi struct fuse_args { 2657078187aSMiklos Szeredi struct { 2667078187aSMiklos Szeredi struct { 2677078187aSMiklos Szeredi uint32_t opcode; 2687078187aSMiklos Szeredi uint64_t nodeid; 2697078187aSMiklos Szeredi } h; 2707078187aSMiklos Szeredi unsigned numargs; 2717078187aSMiklos Szeredi struct fuse_in_arg args[3]; 2727078187aSMiklos Szeredi 2737078187aSMiklos Szeredi } in; 2747078187aSMiklos Szeredi struct { 2757078187aSMiklos Szeredi unsigned argvar:1; 2767078187aSMiklos Szeredi unsigned numargs; 2777078187aSMiklos Szeredi struct fuse_arg args[2]; 2787078187aSMiklos Szeredi } out; 2797078187aSMiklos Szeredi }; 2807078187aSMiklos Szeredi 2817078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2827078187aSMiklos Szeredi 28301e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 28401e9d11aSMaxim Patlasov struct fuse_io_priv { 285744742d6SSeth Forshee struct kref refcnt; 28601e9d11aSMaxim Patlasov int async; 28701e9d11aSMaxim Patlasov spinlock_t lock; 28801e9d11aSMaxim Patlasov unsigned reqs; 28901e9d11aSMaxim Patlasov ssize_t bytes; 29001e9d11aSMaxim Patlasov size_t size; 29101e9d11aSMaxim Patlasov __u64 offset; 29201e9d11aSMaxim Patlasov bool write; 29361c12b49SAshish Samant bool should_dirty; 29401e9d11aSMaxim Patlasov int err; 29501e9d11aSMaxim Patlasov struct kiocb *iocb; 2969d5722b7SChristoph Hellwig struct completion *done; 2977879c4e5SAshish Sangwan bool blocking; 29801e9d11aSMaxim Patlasov }; 29901e9d11aSMaxim Patlasov 300e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 301744742d6SSeth Forshee { \ 3021e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 303744742d6SSeth Forshee .async = 0, \ 304e1c0eecbSMiklos Szeredi .iocb = i, \ 305744742d6SSeth Forshee } 306744742d6SSeth Forshee 307334f485dSMiklos Szeredi /** 308825d6d33SMiklos Szeredi * Request flags 309825d6d33SMiklos Szeredi * 310825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 311825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 312825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 313825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 314825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 315825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 316825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 31733e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 31833e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 31933e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 32077cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 321825d6d33SMiklos Szeredi */ 322825d6d33SMiklos Szeredi enum fuse_req_flag { 323825d6d33SMiklos Szeredi FR_ISREPLY, 324825d6d33SMiklos Szeredi FR_FORCE, 325825d6d33SMiklos Szeredi FR_BACKGROUND, 326825d6d33SMiklos Szeredi FR_WAITING, 327825d6d33SMiklos Szeredi FR_ABORTED, 328825d6d33SMiklos Szeredi FR_INTERRUPTED, 329825d6d33SMiklos Szeredi FR_LOCKED, 33033e14b4dSMiklos Szeredi FR_PENDING, 33133e14b4dSMiklos Szeredi FR_SENT, 33233e14b4dSMiklos Szeredi FR_FINISHED, 33377cd9d48SMiklos Szeredi FR_PRIVATE, 334825d6d33SMiklos Szeredi }; 335825d6d33SMiklos Szeredi 336825d6d33SMiklos Szeredi /** 337334f485dSMiklos Szeredi * A request to the client 338dc00809aSMiklos Szeredi * 339dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 340dc00809aSMiklos Szeredi * - FR_ABORTED 341dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 342334f485dSMiklos Szeredi */ 343334f485dSMiklos Szeredi struct fuse_req { 344ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 345ce1d5a49SMiklos Szeredi fuse_conn */ 346334f485dSMiklos Szeredi struct list_head list; 347334f485dSMiklos Szeredi 348a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 349a4d27e75SMiklos Szeredi struct list_head intr_entry; 350a4d27e75SMiklos Szeredi 351334f485dSMiklos Szeredi /** refcount */ 352ec99f6d3SElena Reshetova refcount_t count; 353334f485dSMiklos Szeredi 354825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 355825d6d33SMiklos Szeredi unsigned long flags; 3569bc5dddaSMiklos Szeredi 357334f485dSMiklos Szeredi /** The request input */ 358334f485dSMiklos Szeredi struct fuse_in in; 359334f485dSMiklos Szeredi 360334f485dSMiklos Szeredi /** The request output */ 361334f485dSMiklos Szeredi struct fuse_out out; 362334f485dSMiklos Szeredi 363334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 364334f485dSMiklos Szeredi wait_queue_head_t waitq; 365334f485dSMiklos Szeredi 366334f485dSMiklos Szeredi /** Data for asynchronous requests */ 367334f485dSMiklos Szeredi union { 368b57d4264SMiklos Szeredi struct { 369b57d4264SMiklos Szeredi struct fuse_release_in in; 370baebccbeSMiklos Szeredi struct inode *inode; 371b57d4264SMiklos Szeredi } release; 3723ec870d5SMiklos Szeredi struct fuse_init_in init_in; 3733ec870d5SMiklos Szeredi struct fuse_init_out init_out; 37408cbf542STejun Heo struct cuse_init_in cuse_init_in; 3755c5c5e51SMiklos Szeredi struct { 3765c5c5e51SMiklos Szeredi struct fuse_read_in in; 3775c5c5e51SMiklos Szeredi u64 attr_ver; 3785c5c5e51SMiklos Szeredi } read; 379b25e82e5SMiklos Szeredi struct { 380b25e82e5SMiklos Szeredi struct fuse_write_in in; 381b25e82e5SMiklos Szeredi struct fuse_write_out out; 3828b284dc4SMiklos Szeredi struct fuse_req *next; 383b25e82e5SMiklos Szeredi } write; 3842d45ba38SMiklos Szeredi struct fuse_notify_retrieve_in retrieve_in; 385334f485dSMiklos Szeredi } misc; 386334f485dSMiklos Szeredi 387334f485dSMiklos Szeredi /** page vector */ 3884250c066SMaxim Patlasov struct page **pages; 3894250c066SMaxim Patlasov 390b2430d75SMaxim Patlasov /** page-descriptor vector */ 391b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 392b2430d75SMaxim Patlasov 3934250c066SMaxim Patlasov /** size of the 'pages' array */ 3944250c066SMaxim Patlasov unsigned max_pages; 3954250c066SMaxim Patlasov 3964250c066SMaxim Patlasov /** inline page vector */ 3974250c066SMaxim Patlasov struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 398334f485dSMiklos Szeredi 399b2430d75SMaxim Patlasov /** inline page-descriptor vector */ 400b2430d75SMaxim Patlasov struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 401b2430d75SMaxim Patlasov 402334f485dSMiklos Szeredi /** number of pages in vector */ 403334f485dSMiklos Szeredi unsigned num_pages; 404334f485dSMiklos Szeredi 405334f485dSMiklos Szeredi /** File used in the request (or NULL) */ 406c756e0a4SMiklos Szeredi struct fuse_file *ff; 40764c6d8edSMiklos Szeredi 4083be5a52bSMiklos Szeredi /** Inode used in the request or NULL */ 4093be5a52bSMiklos Szeredi struct inode *inode; 4103be5a52bSMiklos Szeredi 41101e9d11aSMaxim Patlasov /** AIO control block */ 41201e9d11aSMaxim Patlasov struct fuse_io_priv *io; 41301e9d11aSMaxim Patlasov 4143be5a52bSMiklos Szeredi /** Link on fi->writepages */ 4153be5a52bSMiklos Szeredi struct list_head writepages_entry; 4163be5a52bSMiklos Szeredi 41764c6d8edSMiklos Szeredi /** Request completion callback */ 41864c6d8edSMiklos Szeredi void (*end)(struct fuse_conn *, struct fuse_req *); 41933649c91SMiklos Szeredi 42033649c91SMiklos Szeredi /** Request is stolen from fuse_file->reserved_req */ 42133649c91SMiklos Szeredi struct file *stolen_file; 422334f485dSMiklos Szeredi }; 423334f485dSMiklos Szeredi 424f88996a9SMiklos Szeredi struct fuse_iqueue { 425e16714d8SMiklos Szeredi /** Connection established */ 426e16714d8SMiklos Szeredi unsigned connected; 427e16714d8SMiklos Szeredi 428f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 429f88996a9SMiklos Szeredi wait_queue_head_t waitq; 430f88996a9SMiklos Szeredi 431f88996a9SMiklos Szeredi /** The next unique request id */ 432f88996a9SMiklos Szeredi u64 reqctr; 433f88996a9SMiklos Szeredi 434f88996a9SMiklos Szeredi /** The list of pending requests */ 435f88996a9SMiklos Szeredi struct list_head pending; 436f88996a9SMiklos Szeredi 437f88996a9SMiklos Szeredi /** Pending interrupts */ 438f88996a9SMiklos Szeredi struct list_head interrupts; 439f88996a9SMiklos Szeredi 440f88996a9SMiklos Szeredi /** Queue of pending forgets */ 441f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 442f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 443f88996a9SMiklos Szeredi 444f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 445f88996a9SMiklos Szeredi int forget_batch; 446f88996a9SMiklos Szeredi 447f88996a9SMiklos Szeredi /** O_ASYNC requests */ 448f88996a9SMiklos Szeredi struct fasync_struct *fasync; 449f88996a9SMiklos Szeredi }; 450f88996a9SMiklos Szeredi 451be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 452be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 453be2ff42cSKirill Tkhai 4543a2b5b9cSMiklos Szeredi struct fuse_pqueue { 455e96edd94SMiklos Szeredi /** Connection established */ 456e96edd94SMiklos Szeredi unsigned connected; 457e96edd94SMiklos Szeredi 45845a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 45945a91cb1SMiklos Szeredi spinlock_t lock; 46045a91cb1SMiklos Szeredi 461be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 462be2ff42cSKirill Tkhai struct list_head *processing; 4633a2b5b9cSMiklos Szeredi 4643a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4653a2b5b9cSMiklos Szeredi struct list_head io; 4663a2b5b9cSMiklos Szeredi }; 4673a2b5b9cSMiklos Szeredi 468d8a5ba45SMiklos Szeredi /** 469cc080e9eSMiklos Szeredi * Fuse device instance 470cc080e9eSMiklos Szeredi */ 471cc080e9eSMiklos Szeredi struct fuse_dev { 472cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 473cc080e9eSMiklos Szeredi struct fuse_conn *fc; 474cc080e9eSMiklos Szeredi 475c3696046SMiklos Szeredi /** Processing queue */ 476c3696046SMiklos Szeredi struct fuse_pqueue pq; 477c3696046SMiklos Szeredi 478cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 479cc080e9eSMiklos Szeredi struct list_head entry; 480cc080e9eSMiklos Szeredi }; 481cc080e9eSMiklos Szeredi 482cc080e9eSMiklos Szeredi /** 483d8a5ba45SMiklos Szeredi * A Fuse connection. 484d8a5ba45SMiklos Szeredi * 485d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 486d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 487d8a5ba45SMiklos Szeredi * unmounted. 488d8a5ba45SMiklos Szeredi */ 489d8a5ba45SMiklos Szeredi struct fuse_conn { 490d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 491d7133114SMiklos Szeredi spinlock_t lock; 492d7133114SMiklos Szeredi 493bafa9654SMiklos Szeredi /** Refcount */ 494095fc40aSElena Reshetova refcount_t count; 495bafa9654SMiklos Szeredi 496c3696046SMiklos Szeredi /** Number of fuse_dev's */ 497c3696046SMiklos Szeredi atomic_t dev_count; 498c3696046SMiklos Szeredi 499dd3e2c55SAl Viro struct rcu_head rcu; 500dd3e2c55SAl Viro 501d8a5ba45SMiklos Szeredi /** The user id for this mount */ 502499dcf20SEric W. Biederman kuid_t user_id; 503d8a5ba45SMiklos Szeredi 50487729a55SMiklos Szeredi /** The group id for this mount */ 505499dcf20SEric W. Biederman kgid_t group_id; 50687729a55SMiklos Szeredi 5070b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 5080b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 5090b6e9ea0SSeth Forshee 5108cb08329SEric W. Biederman /** The user namespace for this mount */ 5118cb08329SEric W. Biederman struct user_namespace *user_ns; 5128cb08329SEric W. Biederman 513db50b96cSMiklos Szeredi /** Maximum read size */ 514db50b96cSMiklos Szeredi unsigned max_read; 515db50b96cSMiklos Szeredi 516413ef8cbSMiklos Szeredi /** Maximum write size */ 517413ef8cbSMiklos Szeredi unsigned max_write; 518413ef8cbSMiklos Szeredi 519f88996a9SMiklos Szeredi /** Input queue */ 520f88996a9SMiklos Szeredi struct fuse_iqueue iq; 521334f485dSMiklos Szeredi 522acf99433STejun Heo /** The next unique kernel file handle */ 523acf99433STejun Heo u64 khctr; 524acf99433STejun Heo 52595668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 52695668a69STejun Heo struct rb_root polled_files; 52795668a69STejun Heo 5287a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 5297a6d3c8bSCsaba Henk unsigned max_background; 5307a6d3c8bSCsaba Henk 5317a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 5327a6d3c8bSCsaba Henk unsigned congestion_threshold; 5337a6d3c8bSCsaba Henk 53408a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 53508a53cdcSMiklos Szeredi unsigned num_background; 53608a53cdcSMiklos Szeredi 537d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 538d12def1bSMiklos Szeredi unsigned active_background; 539d12def1bSMiklos Szeredi 540d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 541d12def1bSMiklos Szeredi struct list_head bg_queue; 542d12def1bSMiklos Szeredi 543ae2dffa3SKirill Tkhai /** Protects: max_background, congestion_threshold, num_background, 544ae2dffa3SKirill Tkhai * active_background, bg_queue, blocked */ 545ae2dffa3SKirill Tkhai spinlock_t bg_lock; 546ae2dffa3SKirill Tkhai 547796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 548796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 549796523fbSMaxim Patlasov int initialized; 550796523fbSMaxim Patlasov 55108a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 55208a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 55308a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 55408a53cdcSMiklos Szeredi int blocked; 55508a53cdcSMiklos Szeredi 55608a53cdcSMiklos Szeredi /** waitq for blocked connection */ 55708a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 55808a53cdcSMiklos Szeredi 559de5e3decSMiklos Szeredi /** waitq for reserved requests */ 560de5e3decSMiklos Szeredi wait_queue_head_t reserved_req_waitq; 561de5e3decSMiklos Szeredi 56269a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 56369a53bf2SMiklos Szeredi abort and device release */ 564095da6cbSMiklos Szeredi unsigned connected; 5651e9a4ed9SMiklos Szeredi 5663b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 5673b7008b2SSzymon Lukasz bool aborted; 5683b7008b2SSzymon Lukasz 569095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 570095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 571095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 572334f485dSMiklos Szeredi unsigned conn_error:1; 573334f485dSMiklos Szeredi 5740ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5750ec7ca41SMiklos Szeredi unsigned conn_init:1; 5760ec7ca41SMiklos Szeredi 5779cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5789cd68455SMiklos Szeredi unsigned async_read:1; 5799cd68455SMiklos Szeredi 5803b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 5813b7008b2SSzymon Lukasz unsigned abort_err:1; 5823b7008b2SSzymon Lukasz 5836ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5846ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5856ff958edSMiklos Szeredi 58633670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 58733670fa2SMiklos Szeredi unsigned export_support:1; 58833670fa2SMiklos Szeredi 589d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 590d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 591d5cd66c5SPavel Emelyanov 5925c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5935c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5945c672ab3SMiklos Szeredi 5955e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5965e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5975e940c1dSMiklos Szeredi 598095da6cbSMiklos Szeredi /* 599095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 600095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 601095da6cbSMiklos Szeredi */ 602095da6cbSMiklos Szeredi 6037678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 6047678ac50SAndrew Gallagher unsigned no_open:1; 6057678ac50SAndrew Gallagher 606b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 607b6aeadedSMiklos Szeredi unsigned no_fsync:1; 608b6aeadedSMiklos Szeredi 60982547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 61082547981SMiklos Szeredi unsigned no_fsyncdir:1; 61182547981SMiklos Szeredi 612b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 613b6aeadedSMiklos Szeredi unsigned no_flush:1; 614b6aeadedSMiklos Szeredi 61592a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 61692a8780eSMiklos Szeredi unsigned no_setxattr:1; 61792a8780eSMiklos Szeredi 61892a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 61992a8780eSMiklos Szeredi unsigned no_getxattr:1; 62092a8780eSMiklos Szeredi 62192a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 62292a8780eSMiklos Szeredi unsigned no_listxattr:1; 62392a8780eSMiklos Szeredi 62492a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 62592a8780eSMiklos Szeredi unsigned no_removexattr:1; 62692a8780eSMiklos Szeredi 62737fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 62871421259SMiklos Szeredi unsigned no_lock:1; 62971421259SMiklos Szeredi 63031d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 63131d40d74SMiklos Szeredi unsigned no_access:1; 63231d40d74SMiklos Szeredi 633fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 634fd72faacSMiklos Szeredi unsigned no_create:1; 635fd72faacSMiklos Szeredi 636a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 637a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 638a4d27e75SMiklos Szeredi 639b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 640b2d2272fSMiklos Szeredi unsigned no_bmap:1; 641b2d2272fSMiklos Szeredi 64295668a69STejun Heo /** Is poll not implemented by fs? */ 64395668a69STejun Heo unsigned no_poll:1; 64495668a69STejun Heo 64578bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 64678bb6cb9SMiklos Szeredi unsigned big_writes:1; 64778bb6cb9SMiklos Szeredi 648e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 649e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 650e0a43ddcSMiklos Szeredi 65137fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 65237fb3a30SMiklos Szeredi unsigned no_flock:1; 65337fb3a30SMiklos Szeredi 654519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 655519c6040SMiklos Szeredi unsigned no_fallocate:1; 656519c6040SMiklos Szeredi 6571560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6581560c974SMiklos Szeredi unsigned no_rename2:1; 6591560c974SMiklos Szeredi 66072d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 66172d0d248SBrian Foster unsigned auto_inval_data:1; 66272d0d248SBrian Foster 663634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6640b05b183SAnand V. Avati unsigned do_readdirplus:1; 6650b05b183SAnand V. Avati 666634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 667634734b6SEric Wong unsigned readdirplus_auto:1; 668634734b6SEric Wong 66960b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 67060b9df7aSMiklos Szeredi unsigned async_dio:1; 67160b9df7aSMiklos Szeredi 6720b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6730b5da8dbSRavishankar N unsigned no_lseek:1; 6740b5da8dbSRavishankar N 67560bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 67660bcc88aSSeth Forshee unsigned posix_acl:1; 67760bcc88aSSeth Forshee 67829433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 67929433a29SMiklos Szeredi unsigned default_permissions:1; 68029433a29SMiklos Szeredi 68129433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 68229433a29SMiklos Szeredi unsigned allow_other:1; 68329433a29SMiklos Szeredi 68488bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 68588bc7d50SNiels de Vos unsigned no_copy_file_range:1; 68688bc7d50SNiels de Vos 6870cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6880cd5b885SMiklos Szeredi atomic_t num_waiting; 6890cd5b885SMiklos Szeredi 69045714d65SMiklos Szeredi /** Negotiated minor version */ 69145714d65SMiklos Szeredi unsigned minor; 69245714d65SMiklos Szeredi 693bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 694bafa9654SMiklos Szeredi struct list_head entry; 695bafa9654SMiklos Szeredi 696b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 697b6f2fcbcSMiklos Szeredi dev_t dev; 698bafa9654SMiklos Szeredi 699bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 700bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 701bafa9654SMiklos Szeredi 702bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 703bafa9654SMiklos Szeredi int ctl_ndents; 704385a17bfSJeff Dike 7059c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 7069c8ef561SMiklos Szeredi u32 scramble_key[4]; 7070ec7ca41SMiklos Szeredi 7080ec7ca41SMiklos Szeredi /** Reserved request for the DESTROY message */ 7090ec7ca41SMiklos Szeredi struct fuse_req *destroy_req; 7101fb69e78SMiklos Szeredi 7111fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 7121fb69e78SMiklos Szeredi u64 attr_version; 71343901aabSTejun Heo 71443901aabSTejun Heo /** Called on final put */ 71543901aabSTejun Heo void (*release)(struct fuse_conn *); 7163b463ae0SJohn Muir 7173b463ae0SJohn Muir /** Super block for this connection. */ 7183b463ae0SJohn Muir struct super_block *sb; 7193b463ae0SJohn Muir 7203b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 7213b463ae0SJohn Muir struct rw_semaphore killsb; 722cc080e9eSMiklos Szeredi 723cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 724cc080e9eSMiklos Szeredi struct list_head devices; 725d8a5ba45SMiklos Szeredi }; 726d8a5ba45SMiklos Szeredi 727d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 728d8a5ba45SMiklos Szeredi { 7296383bdaaSMiklos Szeredi return sb->s_fs_info; 730d8a5ba45SMiklos Szeredi } 731d8a5ba45SMiklos Szeredi 732d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 733d8a5ba45SMiklos Szeredi { 734d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 735d8a5ba45SMiklos Szeredi } 736d8a5ba45SMiklos Szeredi 737d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 738d8a5ba45SMiklos Szeredi { 739d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 740d8a5ba45SMiklos Szeredi } 741d8a5ba45SMiklos Szeredi 742d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 743d8a5ba45SMiklos Szeredi { 744d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 745d8a5ba45SMiklos Szeredi } 746d8a5ba45SMiklos Szeredi 747d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 748d123d8e1SMiklos Szeredi { 749d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 750d123d8e1SMiklos Szeredi } 751d123d8e1SMiklos Szeredi 752334f485dSMiklos Szeredi /** Device operations */ 7534b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 754334f485dSMiklos Szeredi 7554269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 7560ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 757dbd561d2SMiklos Szeredi 758d8a5ba45SMiklos Szeredi /** 7593b463ae0SJohn Muir * Inode to nodeid comparison. 7603b463ae0SJohn Muir */ 7613b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7623b463ae0SJohn Muir 7633b463ae0SJohn Muir /** 764e5e5558eSMiklos Szeredi * Get a filled in inode 765e5e5558eSMiklos Szeredi */ 766b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7671fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7681fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 769e5e5558eSMiklos Szeredi 77013983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 77133670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 77233670fa2SMiklos Szeredi 773e5e5558eSMiklos Szeredi /** 774e5e5558eSMiklos Szeredi * Send FORGET command 775e5e5558eSMiklos Szeredi */ 77607e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 777b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 778e5e5558eSMiklos Szeredi 77907e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 78007e77dcaSMiklos Szeredi 7810b05b183SAnand V. Avati /* Used by READDIRPLUS */ 7820b05b183SAnand V. Avati void fuse_force_forget(struct file *file, u64 nodeid); 7830b05b183SAnand V. Avati 784e5e5558eSMiklos Szeredi /** 785361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 78604730fefSMiklos Szeredi */ 787a6643094SMiklos Szeredi void fuse_read_fill(struct fuse_req *req, struct file *file, 7882106cb18SMiklos Szeredi loff_t pos, size_t count, int opcode); 78904730fefSMiklos Szeredi 79004730fefSMiklos Szeredi /** 79104730fefSMiklos Szeredi * Send OPEN or OPENDIR request 79204730fefSMiklos Szeredi */ 79391fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 79404730fefSMiklos Szeredi 795acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 796fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 797c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 798fd72faacSMiklos Szeredi 7998b0797a4SMiklos Szeredi void fuse_sync_release(struct fuse_file *ff, int flags); 800c756e0a4SMiklos Szeredi 80104730fefSMiklos Szeredi /** 80204730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 80304730fefSMiklos Szeredi */ 8048b0797a4SMiklos Szeredi void fuse_release_common(struct file *file, int opcode); 80504730fefSMiklos Szeredi 80604730fefSMiklos Szeredi /** 80782547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 80882547981SMiklos Szeredi */ 80902c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 81002c24a82SJosef Bacik int datasync, int isdir); 81182547981SMiklos Szeredi 81282547981SMiklos Szeredi /** 81395668a69STejun Heo * Notify poll wakeup 81495668a69STejun Heo */ 81595668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 81695668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 81795668a69STejun Heo 81895668a69STejun Heo /** 8191779381dSMiklos Szeredi * Initialize file operations on a regular file 820b6aeadedSMiklos Szeredi */ 821b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 822b6aeadedSMiklos Szeredi 823b6aeadedSMiklos Szeredi /** 8241779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 825e5e5558eSMiklos Szeredi */ 826e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 827e5e5558eSMiklos Szeredi 828e5e5558eSMiklos Szeredi /** 8291779381dSMiklos Szeredi * Initialize inode and file operations on a directory 830e5e5558eSMiklos Szeredi */ 831e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 832e5e5558eSMiklos Szeredi 833e5e5558eSMiklos Szeredi /** 8341779381dSMiklos Szeredi * Initialize inode operations on a symlink 835e5e5558eSMiklos Szeredi */ 836e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 837e5e5558eSMiklos Szeredi 838e5e5558eSMiklos Szeredi /** 839e5e5558eSMiklos Szeredi * Change attributes of an inode 840e5e5558eSMiklos Szeredi */ 8411fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 8421fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 843e5e5558eSMiklos Szeredi 8443be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 8453be5a52bSMiklos Szeredi u64 attr_valid); 8463be5a52bSMiklos Szeredi 847e5e5558eSMiklos Szeredi /** 848334f485dSMiklos Szeredi * Initialize the client device 849334f485dSMiklos Szeredi */ 850334f485dSMiklos Szeredi int fuse_dev_init(void); 851334f485dSMiklos Szeredi 852334f485dSMiklos Szeredi /** 853334f485dSMiklos Szeredi * Cleanup the client device 854334f485dSMiklos Szeredi */ 855334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 856334f485dSMiklos Szeredi 857bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8587736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 859bafa9654SMiklos Szeredi 860334f485dSMiklos Szeredi /** 861334f485dSMiklos Szeredi * Allocate a request 862334f485dSMiklos Szeredi */ 8634250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc(unsigned npages); 864334f485dSMiklos Szeredi 8654250c066SMaxim Patlasov struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 8663be5a52bSMiklos Szeredi 867334f485dSMiklos Szeredi /** 868334f485dSMiklos Szeredi * Free a request 869334f485dSMiklos Szeredi */ 870334f485dSMiklos Szeredi void fuse_request_free(struct fuse_req *req); 871334f485dSMiklos Szeredi 872334f485dSMiklos Szeredi /** 873b111c8c0SMaxim Patlasov * Get a request, may fail with -ENOMEM, 874b111c8c0SMaxim Patlasov * caller should specify # elements in req->pages[] explicitly 875334f485dSMiklos Szeredi */ 876b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 8778b41e671SMaxim Patlasov struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 8788b41e671SMaxim Patlasov unsigned npages); 879b111c8c0SMaxim Patlasov 88036cf66edSMaxim Patlasov /* 88136cf66edSMaxim Patlasov * Increment reference count on request 88236cf66edSMaxim Patlasov */ 88336cf66edSMaxim Patlasov void __fuse_get_request(struct fuse_req *req); 88436cf66edSMaxim Patlasov 885b111c8c0SMaxim Patlasov /** 88633649c91SMiklos Szeredi * Gets a requests for a file operation, always succeeds 88733649c91SMiklos Szeredi */ 888b111c8c0SMaxim Patlasov struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 889b111c8c0SMaxim Patlasov struct file *file); 89033649c91SMiklos Szeredi 89133649c91SMiklos Szeredi /** 892ce1d5a49SMiklos Szeredi * Decrement reference count of a request. If count goes to zero free 893ce1d5a49SMiklos Szeredi * the request. 894334f485dSMiklos Szeredi */ 895334f485dSMiklos Szeredi void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 896334f485dSMiklos Szeredi 897334f485dSMiklos Szeredi /** 8987c352bdfSMiklos Szeredi * Send a request (synchronous) 899334f485dSMiklos Szeredi */ 900b93f858aSTejun Heo void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 901334f485dSMiklos Szeredi 902334f485dSMiklos Szeredi /** 9037078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 9047078187aSMiklos Szeredi */ 9057078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 9067078187aSMiklos Szeredi 9077078187aSMiklos Szeredi /** 908334f485dSMiklos Szeredi * Send a request in the background 909334f485dSMiklos Szeredi */ 910b93f858aSTejun Heo void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 91163825b4eSKirill Tkhai bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); 9123be5a52bSMiklos Szeredi 9135a5fb1eaSMiklos Szeredi /* Abort all requests */ 9143b7008b2SSzymon Lukasz void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); 915b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 91669a53bf2SMiklos Szeredi 9171e9a4ed9SMiklos Szeredi /** 918e5e5558eSMiklos Szeredi * Invalidate inode attributes 919e5e5558eSMiklos Szeredi */ 920e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 921bafa9654SMiklos Szeredi 922dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 923dbd561d2SMiklos Szeredi 924451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 925451418fcSAndrew Gallagher 926d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o); 927d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 928d123d8e1SMiklos Szeredi 929bafa9654SMiklos Szeredi /** 930bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 931bafa9654SMiklos Szeredi */ 932bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 933bafa9654SMiklos Szeredi 934bafa9654SMiklos Szeredi /** 9350d179aa5STejun Heo * Initialize fuse_conn 9360d179aa5STejun Heo */ 9378cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); 9380d179aa5STejun Heo 9390d179aa5STejun Heo /** 940bafa9654SMiklos Szeredi * Release reference to fuse_conn 941bafa9654SMiklos Szeredi */ 942bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 943bafa9654SMiklos Szeredi 944cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 945cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 946cc080e9eSMiklos Szeredi 947bafa9654SMiklos Szeredi /** 948bafa9654SMiklos Szeredi * Add connection to control filesystem 949bafa9654SMiklos Szeredi */ 950bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 951bafa9654SMiklos Szeredi 952bafa9654SMiklos Szeredi /** 953bafa9654SMiklos Szeredi * Remove connection from control filesystem 954bafa9654SMiklos Szeredi */ 955bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 956a5bfffacSTimo Savola 957a5bfffacSTimo Savola /** 958a5bfffacSTimo Savola * Is file type valid? 959a5bfffacSTimo Savola */ 960a5bfffacSTimo Savola int fuse_valid_type(int m); 961e57ac683SMiklos Szeredi 962e57ac683SMiklos Szeredi /** 963c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 964e57ac683SMiklos Szeredi */ 965c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 966f3332114SMiklos Szeredi 967f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 968bcb4be80SMiklos Szeredi 969703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 970703c7362SSeth Forshee 9715b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 9723be5a52bSMiklos Szeredi 9733be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9743be5a52bSMiklos Szeredi 9753be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9763be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9775c5c5e51SMiklos Szeredi 9785c5c5e51SMiklos Szeredi u64 fuse_get_attr_version(struct fuse_conn *fc); 97929d434b3STejun Heo 9803b463ae0SJohn Muir /** 9813b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9823b463ae0SJohn Muir */ 9833b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9843b463ae0SJohn Muir loff_t offset, loff_t len); 9853b463ae0SJohn Muir 9863b463ae0SJohn Muir /** 9873b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9883b463ae0SJohn Muir * the dentry matching parent/name. 989451d0f59SJohn Muir * 990451d0f59SJohn Muir * If the child_nodeid is non-zero and: 991451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 992451d0f59SJohn Muir * - is not a mount point 993451d0f59SJohn Muir * - is a file or oan empty directory 994451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 9953b463ae0SJohn Muir */ 9963b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 997451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 9983b463ae0SJohn Muir 99908cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 100008cbf542STejun Heo bool isdir); 1001ea8cd333SPavel Emelyanov 1002ea8cd333SPavel Emelyanov /** 1003ea8cd333SPavel Emelyanov * fuse_direct_io() flags 1004ea8cd333SPavel Emelyanov */ 1005ea8cd333SPavel Emelyanov 1006ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 1007ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 1008ea8cd333SPavel Emelyanov 1009ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1010ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 1011ea8cd333SPavel Emelyanov 1012d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1013d22a943fSAl Viro loff_t *ppos, int flags); 101408cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 101508cbf542STejun Heo unsigned int flags); 1016b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 1017b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 1018076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 101908cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 102008cbf542STejun Heo 1021b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 1022b0aa7606SMaxim Patlasov 1023ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 10241e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1025a1d75f25SMiklos Szeredi 102662490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1027efb9fa9eSMaxim Patlasov struct file *file); 1028efb9fa9eSMaxim Patlasov 10299759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 10309759bd51SMiklos Szeredi 103163576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 103263576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 10335c672ab3SMiklos Szeredi 103460bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 103560bcc88aSSeth Forshee size_t size, int flags); 103660bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 103760bcc88aSSeth Forshee size_t size); 1038703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 103960bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 1040703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 104160bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 1042e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 104360bcc88aSSeth Forshee 104460bcc88aSSeth Forshee struct posix_acl; 104560bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 104660bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 1047703c7362SSeth Forshee 1048d123d8e1SMiklos Szeredi 1049d123d8e1SMiklos Szeredi /* readdir.c */ 1050d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 1051d123d8e1SMiklos Szeredi 105229d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 1053