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 12f2294482SKirill Smelkov #ifndef pr_fmt 13f2294482SKirill Smelkov # define pr_fmt(fmt) "fuse: " fmt 14f2294482SKirill Smelkov #endif 15f2294482SKirill Smelkov 16d8a5ba45SMiklos Szeredi #include <linux/fuse.h> 17d8a5ba45SMiklos Szeredi #include <linux/fs.h> 1851eb01e7SMiklos Szeredi #include <linux/mount.h> 19d8a5ba45SMiklos Szeredi #include <linux/wait.h> 20d8a5ba45SMiklos Szeredi #include <linux/list.h> 21d8a5ba45SMiklos Szeredi #include <linux/spinlock.h> 22d8a5ba45SMiklos Szeredi #include <linux/mm.h> 23d8a5ba45SMiklos Szeredi #include <linux/backing-dev.h> 24bafa9654SMiklos Szeredi #include <linux/mutex.h> 253be5a52bSMiklos Szeredi #include <linux/rwsem.h> 2695668a69STejun Heo #include <linux/rbtree.h> 2795668a69STejun Heo #include <linux/poll.h> 285a18ec17SMiklos Szeredi #include <linux/workqueue.h> 29744742d6SSeth Forshee #include <linux/kref.h> 3060bcc88aSSeth Forshee #include <linux/xattr.h> 310b6e9ea0SSeth Forshee #include <linux/pid_namespace.h> 324e8c2eb5SElena Reshetova #include <linux/refcount.h> 338cb08329SEric W. Biederman #include <linux/user_namespace.h> 34d8a5ba45SMiklos Szeredi 355da784ccSConstantine Shulyupin /** Default max number of pages that can be used in a single read request */ 365da784ccSConstantine Shulyupin #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 375da784ccSConstantine Shulyupin 385da784ccSConstantine Shulyupin /** Maximum of max_pages received in init_out */ 395da784ccSConstantine Shulyupin #define FUSE_MAX_MAX_PAGES 256 40334f485dSMiklos Szeredi 413be5a52bSMiklos Szeredi /** Bias for fi->writectr, meaning new writepages must not be sent */ 423be5a52bSMiklos Szeredi #define FUSE_NOWRITE INT_MIN 433be5a52bSMiklos Szeredi 441d3d752bSMiklos Szeredi /** It could be as large as PATH_MAX, but would that have any uses? */ 451d3d752bSMiklos Szeredi #define FUSE_NAME_MAX 1024 461d3d752bSMiklos Szeredi 47bafa9654SMiklos Szeredi /** Number of dentries for each connection in the control filesystem */ 4879a9d994SCsaba Henk #define FUSE_CTL_NUM_DENTRIES 5 49bafa9654SMiklos Szeredi 50bafa9654SMiklos Szeredi /** List of active connections */ 51bafa9654SMiklos Szeredi extern struct list_head fuse_conn_list; 52bafa9654SMiklos Szeredi 53bafa9654SMiklos Szeredi /** Global mutex protecting fuse_conn_list and the control filesystem */ 54bafa9654SMiklos Szeredi extern struct mutex fuse_mutex; 55413ef8cbSMiklos Szeredi 5679a9d994SCsaba Henk /** Module parameters */ 5779a9d994SCsaba Henk extern unsigned max_user_bgreq; 5879a9d994SCsaba Henk extern unsigned max_user_congthresh; 5979a9d994SCsaba Henk 6007e77dcaSMiklos Szeredi /* One forget request */ 6107e77dcaSMiklos Szeredi struct fuse_forget_link { 6202c048b9SMiklos Szeredi struct fuse_forget_one forget_one; 6307e77dcaSMiklos Szeredi struct fuse_forget_link *next; 6407e77dcaSMiklos Szeredi }; 6507e77dcaSMiklos Szeredi 66d8a5ba45SMiklos Szeredi /** FUSE inode */ 67d8a5ba45SMiklos Szeredi struct fuse_inode { 68d8a5ba45SMiklos Szeredi /** Inode data */ 69d8a5ba45SMiklos Szeredi struct inode inode; 70d8a5ba45SMiklos Szeredi 71d8a5ba45SMiklos Szeredi /** Unique ID, which identifies the inode between userspace 72d8a5ba45SMiklos Szeredi * and kernel */ 73d8a5ba45SMiklos Szeredi u64 nodeid; 74d8a5ba45SMiklos Szeredi 759e6268dbSMiklos Szeredi /** Number of lookups on this inode */ 769e6268dbSMiklos Szeredi u64 nlookup; 779e6268dbSMiklos Szeredi 78e5e5558eSMiklos Szeredi /** The request used for sending the FORGET message */ 7907e77dcaSMiklos Szeredi struct fuse_forget_link *forget; 80e5e5558eSMiklos Szeredi 81d8a5ba45SMiklos Szeredi /** Time in jiffies until the file attributes are valid */ 820a0898cfSMiklos Szeredi u64 i_time; 83ebc14c4dSMiklos Szeredi 842f1e8196SMiklos Szeredi /* Which attributes are invalid */ 852f1e8196SMiklos Szeredi u32 inval_mask; 862f1e8196SMiklos Szeredi 87ebc14c4dSMiklos Szeredi /** The sticky bit in inode->i_mode may have been removed, so 88ebc14c4dSMiklos Szeredi preserve the original mode */ 89541af6a0SAl Viro umode_t orig_i_mode; 901fb69e78SMiklos Szeredi 9145c72cd7SPavel Shilovsky /** 64 bit inode number */ 9245c72cd7SPavel Shilovsky u64 orig_ino; 9345c72cd7SPavel Shilovsky 941fb69e78SMiklos Szeredi /** Version of last attribute change */ 951fb69e78SMiklos Szeredi u64 attr_version; 9693a8c3cdSMiklos Szeredi 97ab2257e9SMiklos Szeredi union { 98ab2257e9SMiklos Szeredi /* Write related fields (regular file only) */ 99ab2257e9SMiklos Szeredi struct { 100f15ecfefSKirill Tkhai /* Files usable in writepage. Protected by fi->lock */ 10193a8c3cdSMiklos Szeredi struct list_head write_files; 1023be5a52bSMiklos Szeredi 103ab2257e9SMiklos Szeredi /* Writepages pending on truncate or fsync */ 1043be5a52bSMiklos Szeredi struct list_head queued_writes; 1053be5a52bSMiklos Szeredi 106ab2257e9SMiklos Szeredi /* Number of sent writes, a negative bias 107ab2257e9SMiklos Szeredi * (FUSE_NOWRITE) means more writes are blocked */ 1083be5a52bSMiklos Szeredi int writectr; 1093be5a52bSMiklos Szeredi 110ab2257e9SMiklos Szeredi /* Waitq for writepage completion */ 1113be5a52bSMiklos Szeredi wait_queue_head_t page_waitq; 1123be5a52bSMiklos Szeredi 113ab2257e9SMiklos Szeredi /* List of writepage requestst (pending or sent) */ 1143be5a52bSMiklos Szeredi struct list_head writepages; 115ab2257e9SMiklos Szeredi }; 1164582a4abSFeng Shuo 117ab2257e9SMiklos Szeredi /* readdir cache (directory only) */ 11869e34551SMiklos Szeredi struct { 11969e34551SMiklos Szeredi /* true if fully cached */ 12069e34551SMiklos Szeredi bool cached; 12169e34551SMiklos Szeredi 12269e34551SMiklos Szeredi /* size of cache */ 12369e34551SMiklos Szeredi loff_t size; 12469e34551SMiklos Szeredi 12569e34551SMiklos Szeredi /* position at end of cache (position of next entry) */ 12669e34551SMiklos Szeredi loff_t pos; 12769e34551SMiklos Szeredi 1283494927eSMiklos Szeredi /* version of the cache */ 1293494927eSMiklos Szeredi u64 version; 1303494927eSMiklos Szeredi 131ab2257e9SMiklos Szeredi /* modification time of directory when cache was 132ab2257e9SMiklos Szeredi * started */ 1337118883bSMiklos Szeredi struct timespec64 mtime; 1347118883bSMiklos Szeredi 135261aaba7SMiklos Szeredi /* iversion of directory when cache was started */ 136261aaba7SMiklos Szeredi u64 iversion; 137261aaba7SMiklos Szeredi 13869e34551SMiklos Szeredi /* protects above fields */ 13969e34551SMiklos Szeredi spinlock_t lock; 14069e34551SMiklos Szeredi } rdc; 141ab2257e9SMiklos Szeredi }; 14269e34551SMiklos Szeredi 1434582a4abSFeng Shuo /** Miscellaneous bits describing inode state */ 1444582a4abSFeng Shuo unsigned long state; 1455c672ab3SMiklos Szeredi 1465c672ab3SMiklos Szeredi /** Lock for serializing lookup and readdir for back compatibility*/ 1475c672ab3SMiklos Szeredi struct mutex mutex; 148f15ecfefSKirill Tkhai 149f15ecfefSKirill Tkhai /** Lock to protect write related fields */ 150f15ecfefSKirill Tkhai spinlock_t lock; 1514582a4abSFeng Shuo }; 1524582a4abSFeng Shuo 1534582a4abSFeng Shuo /** FUSE inode state bits */ 1544582a4abSFeng Shuo enum { 1554582a4abSFeng Shuo /** Advise readdirplus */ 1564582a4abSFeng Shuo FUSE_I_ADVISE_RDPLUS, 1576314efeeSMiklos Szeredi /** Initialized with readdirplus */ 1586314efeeSMiklos Szeredi FUSE_I_INIT_RDPLUS, 15906a7c3c2SMaxim Patlasov /** An operation changing file size is in progress */ 16006a7c3c2SMaxim Patlasov FUSE_I_SIZE_UNSTABLE, 161d8a5ba45SMiklos Szeredi }; 162d8a5ba45SMiklos Szeredi 163da5e4714SMiklos Szeredi struct fuse_conn; 1644cb54866SMiklos Szeredi struct fuse_release_args; 165da5e4714SMiklos Szeredi 166b6aeadedSMiklos Szeredi /** FUSE specific file data */ 167b6aeadedSMiklos Szeredi struct fuse_file { 168da5e4714SMiklos Szeredi /** Fuse connection for this file */ 169da5e4714SMiklos Szeredi struct fuse_conn *fc; 170da5e4714SMiklos Szeredi 1714cb54866SMiklos Szeredi /* Argument space reserved for release */ 1724cb54866SMiklos Szeredi struct fuse_release_args *release_args; 173b6aeadedSMiklos Szeredi 174acf99433STejun Heo /** Kernel file handle guaranteed to be unique */ 175acf99433STejun Heo u64 kh; 176acf99433STejun Heo 177b6aeadedSMiklos Szeredi /** File handle used by userspace */ 178b6aeadedSMiklos Szeredi u64 fh; 179c756e0a4SMiklos Szeredi 180da5e4714SMiklos Szeredi /** Node id of this file */ 181da5e4714SMiklos Szeredi u64 nodeid; 182da5e4714SMiklos Szeredi 183c756e0a4SMiklos Szeredi /** Refcount */ 1844e8c2eb5SElena Reshetova refcount_t count; 18593a8c3cdSMiklos Szeredi 186c7b7143cSMiklos Szeredi /** FOPEN_* flags returned by open */ 187c7b7143cSMiklos Szeredi u32 open_flags; 188c7b7143cSMiklos Szeredi 18993a8c3cdSMiklos Szeredi /** Entry on inode's write_files list */ 19093a8c3cdSMiklos Szeredi struct list_head write_entry; 19195668a69STejun Heo 1925d7bc7e8SMiklos Szeredi /* Readdir related */ 1935d7bc7e8SMiklos Szeredi struct { 1945d7bc7e8SMiklos Szeredi /* 1955d7bc7e8SMiklos Szeredi * Protects below fields against (crazy) parallel readdir on 1965d7bc7e8SMiklos Szeredi * same open file. Uncontended in the normal case. 1975d7bc7e8SMiklos Szeredi */ 1985d7bc7e8SMiklos Szeredi struct mutex lock; 1995d7bc7e8SMiklos Szeredi 2005d7bc7e8SMiklos Szeredi /* Dir stream position */ 2015d7bc7e8SMiklos Szeredi loff_t pos; 2025d7bc7e8SMiklos Szeredi 2035d7bc7e8SMiklos Szeredi /* Offset in cache */ 2045d7bc7e8SMiklos Szeredi loff_t cache_off; 2053494927eSMiklos Szeredi 2063494927eSMiklos Szeredi /* Version of cache we are reading */ 2073494927eSMiklos Szeredi u64 version; 2083494927eSMiklos Szeredi 2095d7bc7e8SMiklos Szeredi } readdir; 2105d7bc7e8SMiklos Szeredi 21195668a69STejun Heo /** RB node to be linked on fuse_conn->polled_files */ 21295668a69STejun Heo struct rb_node polled_node; 21395668a69STejun Heo 21495668a69STejun Heo /** Wait queue head for poll */ 21595668a69STejun Heo wait_queue_head_t poll_wait; 21637fb3a30SMiklos Szeredi 21737fb3a30SMiklos Szeredi /** Has flock been performed on this file? */ 21837fb3a30SMiklos Szeredi bool flock:1; 219b6aeadedSMiklos Szeredi }; 220b6aeadedSMiklos Szeredi 221334f485dSMiklos Szeredi /** One input argument of a request */ 222334f485dSMiklos Szeredi struct fuse_in_arg { 223334f485dSMiklos Szeredi unsigned size; 224334f485dSMiklos Szeredi const void *value; 225334f485dSMiklos Szeredi }; 226334f485dSMiklos Szeredi 227334f485dSMiklos Szeredi /** One output argument of a request */ 228334f485dSMiklos Szeredi struct fuse_arg { 229334f485dSMiklos Szeredi unsigned size; 230334f485dSMiklos Szeredi void *value; 231334f485dSMiklos Szeredi }; 232334f485dSMiklos Szeredi 233b2430d75SMaxim Patlasov /** FUSE page descriptor */ 234b2430d75SMaxim Patlasov struct fuse_page_desc { 235b2430d75SMaxim Patlasov unsigned int length; 236b2430d75SMaxim Patlasov unsigned int offset; 237b2430d75SMaxim Patlasov }; 238b2430d75SMaxim Patlasov 2397078187aSMiklos Szeredi struct fuse_args { 2407078187aSMiklos Szeredi uint64_t nodeid; 2411f4e9d03SMiklos Szeredi uint32_t opcode; 2421f4e9d03SMiklos Szeredi unsigned short in_numargs; 2431f4e9d03SMiklos Szeredi unsigned short out_numargs; 244c500ebaaSMiklos Szeredi bool force:1; 245454a7613SMiklos Szeredi bool noreply:1; 246e413754bSMiklos Szeredi bool nocreds:1; 24768583165SMiklos Szeredi bool in_pages:1; 24868583165SMiklos Szeredi bool out_pages:1; 2491f4e9d03SMiklos Szeredi bool out_argvar:1; 25068583165SMiklos Szeredi bool page_zeroing:1; 25168583165SMiklos Szeredi bool page_replace:1; 252d5b48543SMiklos Szeredi struct fuse_in_arg in_args[3]; 253d5b48543SMiklos Szeredi struct fuse_arg out_args[2]; 25412597287SMiklos Szeredi void (*end)(struct fuse_conn *fc, struct fuse_args *args, int error); 2557078187aSMiklos Szeredi }; 2567078187aSMiklos Szeredi 25768583165SMiklos Szeredi struct fuse_args_pages { 25868583165SMiklos Szeredi struct fuse_args args; 25968583165SMiklos Szeredi struct page **pages; 26068583165SMiklos Szeredi struct fuse_page_desc *descs; 26168583165SMiklos Szeredi unsigned int num_pages; 26268583165SMiklos Szeredi }; 26368583165SMiklos Szeredi 2647078187aSMiklos Szeredi #define FUSE_ARGS(args) struct fuse_args args = {} 2657078187aSMiklos Szeredi 26601e9d11aSMaxim Patlasov /** The request IO state (for asynchronous processing) */ 26701e9d11aSMaxim Patlasov struct fuse_io_priv { 268744742d6SSeth Forshee struct kref refcnt; 26901e9d11aSMaxim Patlasov int async; 27001e9d11aSMaxim Patlasov spinlock_t lock; 27101e9d11aSMaxim Patlasov unsigned reqs; 27201e9d11aSMaxim Patlasov ssize_t bytes; 27301e9d11aSMaxim Patlasov size_t size; 27401e9d11aSMaxim Patlasov __u64 offset; 27501e9d11aSMaxim Patlasov bool write; 27661c12b49SAshish Samant bool should_dirty; 27701e9d11aSMaxim Patlasov int err; 27801e9d11aSMaxim Patlasov struct kiocb *iocb; 2799d5722b7SChristoph Hellwig struct completion *done; 2807879c4e5SAshish Sangwan bool blocking; 28101e9d11aSMaxim Patlasov }; 28201e9d11aSMaxim Patlasov 283e1c0eecbSMiklos Szeredi #define FUSE_IO_PRIV_SYNC(i) \ 284744742d6SSeth Forshee { \ 2851e24edcaSPeter Zijlstra .refcnt = KREF_INIT(1), \ 286744742d6SSeth Forshee .async = 0, \ 287e1c0eecbSMiklos Szeredi .iocb = i, \ 288744742d6SSeth Forshee } 289744742d6SSeth Forshee 290334f485dSMiklos Szeredi /** 291825d6d33SMiklos Szeredi * Request flags 292825d6d33SMiklos Szeredi * 293825d6d33SMiklos Szeredi * FR_ISREPLY: set if the request has reply 294825d6d33SMiklos Szeredi * FR_FORCE: force sending of the request even if interrupted 295825d6d33SMiklos Szeredi * FR_BACKGROUND: request is sent in the background 296825d6d33SMiklos Szeredi * FR_WAITING: request is counted as "waiting" 297825d6d33SMiklos Szeredi * FR_ABORTED: the request was aborted 298825d6d33SMiklos Szeredi * FR_INTERRUPTED: the request has been interrupted 299825d6d33SMiklos Szeredi * FR_LOCKED: data is being copied to/from the request 30033e14b4dSMiklos Szeredi * FR_PENDING: request is not yet in userspace 30133e14b4dSMiklos Szeredi * FR_SENT: request is in userspace, waiting for an answer 30233e14b4dSMiklos Szeredi * FR_FINISHED: request is finished 30377cd9d48SMiklos Szeredi * FR_PRIVATE: request is on private list 304825d6d33SMiklos Szeredi */ 305825d6d33SMiklos Szeredi enum fuse_req_flag { 306825d6d33SMiklos Szeredi FR_ISREPLY, 307825d6d33SMiklos Szeredi FR_FORCE, 308825d6d33SMiklos Szeredi FR_BACKGROUND, 309825d6d33SMiklos Szeredi FR_WAITING, 310825d6d33SMiklos Szeredi FR_ABORTED, 311825d6d33SMiklos Szeredi FR_INTERRUPTED, 312825d6d33SMiklos Szeredi FR_LOCKED, 31333e14b4dSMiklos Szeredi FR_PENDING, 31433e14b4dSMiklos Szeredi FR_SENT, 31533e14b4dSMiklos Szeredi FR_FINISHED, 31677cd9d48SMiklos Szeredi FR_PRIVATE, 317825d6d33SMiklos Szeredi }; 318825d6d33SMiklos Szeredi 319825d6d33SMiklos Szeredi /** 320334f485dSMiklos Szeredi * A request to the client 321dc00809aSMiklos Szeredi * 322dc00809aSMiklos Szeredi * .waitq.lock protects the following fields: 323dc00809aSMiklos Szeredi * - FR_ABORTED 324dc00809aSMiklos Szeredi * - FR_LOCKED (may also be modified under fc->lock, tested under both) 325334f485dSMiklos Szeredi */ 326334f485dSMiklos Szeredi struct fuse_req { 327ce1d5a49SMiklos Szeredi /** This can be on either pending processing or io lists in 328ce1d5a49SMiklos Szeredi fuse_conn */ 329334f485dSMiklos Szeredi struct list_head list; 330334f485dSMiklos Szeredi 331a4d27e75SMiklos Szeredi /** Entry on the interrupts list */ 332a4d27e75SMiklos Szeredi struct list_head intr_entry; 333a4d27e75SMiklos Szeredi 33412597287SMiklos Szeredi /* Input/output arguments */ 33512597287SMiklos Szeredi struct fuse_args *args; 33612597287SMiklos Szeredi 337334f485dSMiklos Szeredi /** refcount */ 338ec99f6d3SElena Reshetova refcount_t count; 339334f485dSMiklos Szeredi 340825d6d33SMiklos Szeredi /* Request flags, updated with test/set/clear_bit() */ 341825d6d33SMiklos Szeredi unsigned long flags; 3429bc5dddaSMiklos Szeredi 343*d4993774SMiklos Szeredi /* The request input header */ 344*d4993774SMiklos Szeredi struct { 345*d4993774SMiklos Szeredi struct fuse_in_header h; 346*d4993774SMiklos Szeredi } in; 347334f485dSMiklos Szeredi 348*d4993774SMiklos Szeredi /* The request output header */ 349*d4993774SMiklos Szeredi struct { 350*d4993774SMiklos Szeredi struct fuse_out_header h; 351*d4993774SMiklos Szeredi } out; 352334f485dSMiklos Szeredi 353334f485dSMiklos Szeredi /** Used to wake up the task waiting for completion of request*/ 354334f485dSMiklos Szeredi wait_queue_head_t waitq; 355334f485dSMiklos Szeredi 356334f485dSMiklos Szeredi /** page vector */ 3574250c066SMaxim Patlasov struct page **pages; 3584250c066SMaxim Patlasov 359b2430d75SMaxim Patlasov /** page-descriptor vector */ 360b2430d75SMaxim Patlasov struct fuse_page_desc *page_descs; 361b2430d75SMaxim Patlasov 362334f485dSMiklos Szeredi /** number of pages in vector */ 363334f485dSMiklos Szeredi unsigned num_pages; 364334f485dSMiklos Szeredi 365334f485dSMiklos Szeredi }; 366334f485dSMiklos Szeredi 367f88996a9SMiklos Szeredi struct fuse_iqueue { 368e16714d8SMiklos Szeredi /** Connection established */ 369e16714d8SMiklos Szeredi unsigned connected; 370e16714d8SMiklos Szeredi 37176e43c8cSEric Biggers /** Lock protecting accesses to members of this structure */ 37276e43c8cSEric Biggers spinlock_t lock; 37376e43c8cSEric Biggers 374f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 375f88996a9SMiklos Szeredi wait_queue_head_t waitq; 376f88996a9SMiklos Szeredi 377f88996a9SMiklos Szeredi /** The next unique request id */ 378f88996a9SMiklos Szeredi u64 reqctr; 379f88996a9SMiklos Szeredi 380f88996a9SMiklos Szeredi /** The list of pending requests */ 381f88996a9SMiklos Szeredi struct list_head pending; 382f88996a9SMiklos Szeredi 383f88996a9SMiklos Szeredi /** Pending interrupts */ 384f88996a9SMiklos Szeredi struct list_head interrupts; 385f88996a9SMiklos Szeredi 386f88996a9SMiklos Szeredi /** Queue of pending forgets */ 387f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 388f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 389f88996a9SMiklos Szeredi 390f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 391f88996a9SMiklos Szeredi int forget_batch; 392f88996a9SMiklos Szeredi 393f88996a9SMiklos Szeredi /** O_ASYNC requests */ 394f88996a9SMiklos Szeredi struct fasync_struct *fasync; 395f88996a9SMiklos Szeredi }; 396f88996a9SMiklos Szeredi 397be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 398be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 399be2ff42cSKirill Tkhai 4003a2b5b9cSMiklos Szeredi struct fuse_pqueue { 401e96edd94SMiklos Szeredi /** Connection established */ 402e96edd94SMiklos Szeredi unsigned connected; 403e96edd94SMiklos Szeredi 40445a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 40545a91cb1SMiklos Szeredi spinlock_t lock; 40645a91cb1SMiklos Szeredi 407be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 408be2ff42cSKirill Tkhai struct list_head *processing; 4093a2b5b9cSMiklos Szeredi 4103a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4113a2b5b9cSMiklos Szeredi struct list_head io; 4123a2b5b9cSMiklos Szeredi }; 4133a2b5b9cSMiklos Szeredi 414d8a5ba45SMiklos Szeredi /** 415cc080e9eSMiklos Szeredi * Fuse device instance 416cc080e9eSMiklos Szeredi */ 417cc080e9eSMiklos Szeredi struct fuse_dev { 418cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 419cc080e9eSMiklos Szeredi struct fuse_conn *fc; 420cc080e9eSMiklos Szeredi 421c3696046SMiklos Szeredi /** Processing queue */ 422c3696046SMiklos Szeredi struct fuse_pqueue pq; 423c3696046SMiklos Szeredi 424cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 425cc080e9eSMiklos Szeredi struct list_head entry; 426cc080e9eSMiklos Szeredi }; 427cc080e9eSMiklos Szeredi 428cc080e9eSMiklos Szeredi /** 429d8a5ba45SMiklos Szeredi * A Fuse connection. 430d8a5ba45SMiklos Szeredi * 431d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 432d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 433d8a5ba45SMiklos Szeredi * unmounted. 434d8a5ba45SMiklos Szeredi */ 435d8a5ba45SMiklos Szeredi struct fuse_conn { 436d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 437d7133114SMiklos Szeredi spinlock_t lock; 438d7133114SMiklos Szeredi 439bafa9654SMiklos Szeredi /** Refcount */ 440095fc40aSElena Reshetova refcount_t count; 441bafa9654SMiklos Szeredi 442c3696046SMiklos Szeredi /** Number of fuse_dev's */ 443c3696046SMiklos Szeredi atomic_t dev_count; 444c3696046SMiklos Szeredi 445dd3e2c55SAl Viro struct rcu_head rcu; 446dd3e2c55SAl Viro 447d8a5ba45SMiklos Szeredi /** The user id for this mount */ 448499dcf20SEric W. Biederman kuid_t user_id; 449d8a5ba45SMiklos Szeredi 45087729a55SMiklos Szeredi /** The group id for this mount */ 451499dcf20SEric W. Biederman kgid_t group_id; 45287729a55SMiklos Szeredi 4530b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 4540b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 4550b6e9ea0SSeth Forshee 4568cb08329SEric W. Biederman /** The user namespace for this mount */ 4578cb08329SEric W. Biederman struct user_namespace *user_ns; 4588cb08329SEric W. Biederman 459db50b96cSMiklos Szeredi /** Maximum read size */ 460db50b96cSMiklos Szeredi unsigned max_read; 461db50b96cSMiklos Szeredi 462413ef8cbSMiklos Szeredi /** Maximum write size */ 463413ef8cbSMiklos Szeredi unsigned max_write; 464413ef8cbSMiklos Szeredi 4655da784ccSConstantine Shulyupin /** Maxmum number of pages that can be used in a single request */ 4665da784ccSConstantine Shulyupin unsigned int max_pages; 4675da784ccSConstantine Shulyupin 468f88996a9SMiklos Szeredi /** Input queue */ 469f88996a9SMiklos Szeredi struct fuse_iqueue iq; 470334f485dSMiklos Szeredi 471acf99433STejun Heo /** The next unique kernel file handle */ 47275126f55SMiklos Szeredi atomic64_t khctr; 473acf99433STejun Heo 47495668a69STejun Heo /** rbtree of fuse_files waiting for poll events indexed by ph */ 47595668a69STejun Heo struct rb_root polled_files; 47695668a69STejun Heo 4777a6d3c8bSCsaba Henk /** Maximum number of outstanding background requests */ 4787a6d3c8bSCsaba Henk unsigned max_background; 4797a6d3c8bSCsaba Henk 4807a6d3c8bSCsaba Henk /** Number of background requests at which congestion starts */ 4817a6d3c8bSCsaba Henk unsigned congestion_threshold; 4827a6d3c8bSCsaba Henk 48308a53cdcSMiklos Szeredi /** Number of requests currently in the background */ 48408a53cdcSMiklos Szeredi unsigned num_background; 48508a53cdcSMiklos Szeredi 486d12def1bSMiklos Szeredi /** Number of background requests currently queued for userspace */ 487d12def1bSMiklos Szeredi unsigned active_background; 488d12def1bSMiklos Szeredi 489d12def1bSMiklos Szeredi /** The list of background requests set aside for later queuing */ 490d12def1bSMiklos Szeredi struct list_head bg_queue; 491d12def1bSMiklos Szeredi 492ae2dffa3SKirill Tkhai /** Protects: max_background, congestion_threshold, num_background, 493ae2dffa3SKirill Tkhai * active_background, bg_queue, blocked */ 494ae2dffa3SKirill Tkhai spinlock_t bg_lock; 495ae2dffa3SKirill Tkhai 496796523fbSMaxim Patlasov /** Flag indicating that INIT reply has been received. Allocating 497796523fbSMaxim Patlasov * any fuse request will be suspended until the flag is set */ 498796523fbSMaxim Patlasov int initialized; 499796523fbSMaxim Patlasov 50008a53cdcSMiklos Szeredi /** Flag indicating if connection is blocked. This will be 50108a53cdcSMiklos Szeredi the case before the INIT reply is received, and if there 50208a53cdcSMiklos Szeredi are too many outstading backgrounds requests */ 50308a53cdcSMiklos Szeredi int blocked; 50408a53cdcSMiklos Szeredi 50508a53cdcSMiklos Szeredi /** waitq for blocked connection */ 50608a53cdcSMiklos Szeredi wait_queue_head_t blocked_waitq; 50708a53cdcSMiklos Szeredi 50869a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 50969a53bf2SMiklos Szeredi abort and device release */ 510095da6cbSMiklos Szeredi unsigned connected; 5111e9a4ed9SMiklos Szeredi 5123b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 5133b7008b2SSzymon Lukasz bool aborted; 5143b7008b2SSzymon Lukasz 515095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 516095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 517095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 518334f485dSMiklos Szeredi unsigned conn_error:1; 519334f485dSMiklos Szeredi 5200ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5210ec7ca41SMiklos Szeredi unsigned conn_init:1; 5220ec7ca41SMiklos Szeredi 5239cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5249cd68455SMiklos Szeredi unsigned async_read:1; 5259cd68455SMiklos Szeredi 5263b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 5273b7008b2SSzymon Lukasz unsigned abort_err:1; 5283b7008b2SSzymon Lukasz 5296ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5306ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5316ff958edSMiklos Szeredi 53233670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 53333670fa2SMiklos Szeredi unsigned export_support:1; 53433670fa2SMiklos Szeredi 535d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 536d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 537d5cd66c5SPavel Emelyanov 5385c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5395c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5405c672ab3SMiklos Szeredi 5415e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5425e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5435e940c1dSMiklos Szeredi 5445571f1e6SDan Schatzberg /** cache READLINK responses in page cache */ 5455571f1e6SDan Schatzberg unsigned cache_symlinks:1; 5465571f1e6SDan Schatzberg 547095da6cbSMiklos Szeredi /* 548095da6cbSMiklos Szeredi * The following bitfields are only for optimization purposes 549095da6cbSMiklos Szeredi * and hence races in setting them will not cause malfunction 550095da6cbSMiklos Szeredi */ 551095da6cbSMiklos Szeredi 5527678ac50SAndrew Gallagher /** Is open/release not implemented by fs? */ 5537678ac50SAndrew Gallagher unsigned no_open:1; 5547678ac50SAndrew Gallagher 555d9a9ea94SChad Austin /** Is opendir/releasedir not implemented by fs? */ 556d9a9ea94SChad Austin unsigned no_opendir:1; 557d9a9ea94SChad Austin 558b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 559b6aeadedSMiklos Szeredi unsigned no_fsync:1; 560b6aeadedSMiklos Szeredi 56182547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 56282547981SMiklos Szeredi unsigned no_fsyncdir:1; 56382547981SMiklos Szeredi 564b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 565b6aeadedSMiklos Szeredi unsigned no_flush:1; 566b6aeadedSMiklos Szeredi 56792a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 56892a8780eSMiklos Szeredi unsigned no_setxattr:1; 56992a8780eSMiklos Szeredi 57092a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 57192a8780eSMiklos Szeredi unsigned no_getxattr:1; 57292a8780eSMiklos Szeredi 57392a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 57492a8780eSMiklos Szeredi unsigned no_listxattr:1; 57592a8780eSMiklos Szeredi 57692a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 57792a8780eSMiklos Szeredi unsigned no_removexattr:1; 57892a8780eSMiklos Szeredi 57937fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 58071421259SMiklos Szeredi unsigned no_lock:1; 58171421259SMiklos Szeredi 58231d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 58331d40d74SMiklos Szeredi unsigned no_access:1; 58431d40d74SMiklos Szeredi 585fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 586fd72faacSMiklos Szeredi unsigned no_create:1; 587fd72faacSMiklos Szeredi 588a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 589a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 590a4d27e75SMiklos Szeredi 591b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 592b2d2272fSMiklos Szeredi unsigned no_bmap:1; 593b2d2272fSMiklos Szeredi 59495668a69STejun Heo /** Is poll not implemented by fs? */ 59595668a69STejun Heo unsigned no_poll:1; 59695668a69STejun Heo 59778bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 59878bb6cb9SMiklos Szeredi unsigned big_writes:1; 59978bb6cb9SMiklos Szeredi 600e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 601e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 602e0a43ddcSMiklos Szeredi 60337fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 60437fb3a30SMiklos Szeredi unsigned no_flock:1; 60537fb3a30SMiklos Szeredi 606519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 607519c6040SMiklos Szeredi unsigned no_fallocate:1; 608519c6040SMiklos Szeredi 6091560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6101560c974SMiklos Szeredi unsigned no_rename2:1; 6111560c974SMiklos Szeredi 61272d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 61372d0d248SBrian Foster unsigned auto_inval_data:1; 61472d0d248SBrian Foster 615ad2ba64dSKirill Smelkov /** Filesystem is fully reponsible for page cache invalidation. */ 616ad2ba64dSKirill Smelkov unsigned explicit_inval_data:1; 617ad2ba64dSKirill Smelkov 618634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6190b05b183SAnand V. Avati unsigned do_readdirplus:1; 6200b05b183SAnand V. Avati 621634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 622634734b6SEric Wong unsigned readdirplus_auto:1; 623634734b6SEric Wong 62460b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 62560b9df7aSMiklos Szeredi unsigned async_dio:1; 62660b9df7aSMiklos Szeredi 6270b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6280b5da8dbSRavishankar N unsigned no_lseek:1; 6290b5da8dbSRavishankar N 63060bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 63160bcc88aSSeth Forshee unsigned posix_acl:1; 63260bcc88aSSeth Forshee 63329433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 63429433a29SMiklos Szeredi unsigned default_permissions:1; 63529433a29SMiklos Szeredi 63629433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 63729433a29SMiklos Szeredi unsigned allow_other:1; 63829433a29SMiklos Szeredi 63988bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 64088bc7d50SNiels de Vos unsigned no_copy_file_range:1; 64188bc7d50SNiels de Vos 6421ccd1ea2SMiklos Szeredi /* Send DESTROY request */ 6431ccd1ea2SMiklos Szeredi unsigned int destroy:1; 6441ccd1ea2SMiklos Szeredi 6450cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 6460cd5b885SMiklos Szeredi atomic_t num_waiting; 6470cd5b885SMiklos Szeredi 64845714d65SMiklos Szeredi /** Negotiated minor version */ 64945714d65SMiklos Szeredi unsigned minor; 65045714d65SMiklos Szeredi 651bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 652bafa9654SMiklos Szeredi struct list_head entry; 653bafa9654SMiklos Szeredi 654b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 655b6f2fcbcSMiklos Szeredi dev_t dev; 656bafa9654SMiklos Szeredi 657bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 658bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 659bafa9654SMiklos Szeredi 660bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 661bafa9654SMiklos Szeredi int ctl_ndents; 662385a17bfSJeff Dike 6639c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 6649c8ef561SMiklos Szeredi u32 scramble_key[4]; 6650ec7ca41SMiklos Szeredi 6661fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 6674510d86fSKirill Tkhai atomic64_t attr_version; 66843901aabSTejun Heo 66943901aabSTejun Heo /** Called on final put */ 67043901aabSTejun Heo void (*release)(struct fuse_conn *); 6713b463ae0SJohn Muir 6723b463ae0SJohn Muir /** Super block for this connection. */ 6733b463ae0SJohn Muir struct super_block *sb; 6743b463ae0SJohn Muir 6753b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 6763b463ae0SJohn Muir struct rw_semaphore killsb; 677cc080e9eSMiklos Szeredi 678cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 679cc080e9eSMiklos Szeredi struct list_head devices; 680d8a5ba45SMiklos Szeredi }; 681d8a5ba45SMiklos Szeredi 682d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 683d8a5ba45SMiklos Szeredi { 6846383bdaaSMiklos Szeredi return sb->s_fs_info; 685d8a5ba45SMiklos Szeredi } 686d8a5ba45SMiklos Szeredi 687d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 688d8a5ba45SMiklos Szeredi { 689d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 690d8a5ba45SMiklos Szeredi } 691d8a5ba45SMiklos Szeredi 692d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 693d8a5ba45SMiklos Szeredi { 694d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 695d8a5ba45SMiklos Szeredi } 696d8a5ba45SMiklos Szeredi 697d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 698d8a5ba45SMiklos Szeredi { 699d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 700d8a5ba45SMiklos Szeredi } 701d8a5ba45SMiklos Szeredi 702d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 703d123d8e1SMiklos Szeredi { 704d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 705d123d8e1SMiklos Szeredi } 706d123d8e1SMiklos Szeredi 7074510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 7084510d86fSKirill Tkhai { 7094510d86fSKirill Tkhai return atomic64_read(&fc->attr_version); 7104510d86fSKirill Tkhai } 7114510d86fSKirill Tkhai 712334f485dSMiklos Szeredi /** Device operations */ 7134b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 714334f485dSMiklos Szeredi 7154269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 7160ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 717dbd561d2SMiklos Szeredi 718d8a5ba45SMiklos Szeredi /** 7193b463ae0SJohn Muir * Inode to nodeid comparison. 7203b463ae0SJohn Muir */ 7213b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7223b463ae0SJohn Muir 7233b463ae0SJohn Muir /** 724e5e5558eSMiklos Szeredi * Get a filled in inode 725e5e5558eSMiklos Szeredi */ 726b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7271fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7281fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 729e5e5558eSMiklos Szeredi 73013983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 73133670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 73233670fa2SMiklos Szeredi 733e5e5558eSMiklos Szeredi /** 734e5e5558eSMiklos Szeredi * Send FORGET command 735e5e5558eSMiklos Szeredi */ 73607e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 737b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 738e5e5558eSMiklos Szeredi 73907e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 74007e77dcaSMiklos Szeredi 74143f5098eSMiklos Szeredi /* 742361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 74304730fefSMiklos Szeredi */ 74443f5098eSMiklos Szeredi struct fuse_io_args { 74543f5098eSMiklos Szeredi union { 74643f5098eSMiklos Szeredi struct { 74743f5098eSMiklos Szeredi struct fuse_read_in in; 74843f5098eSMiklos Szeredi u64 attr_ver; 74943f5098eSMiklos Szeredi } read; 75043f5098eSMiklos Szeredi struct { 75143f5098eSMiklos Szeredi struct fuse_write_in in; 75243f5098eSMiklos Szeredi struct fuse_write_out out; 75343f5098eSMiklos Szeredi } write; 75443f5098eSMiklos Szeredi }; 75543f5098eSMiklos Szeredi struct fuse_args_pages ap; 75643f5098eSMiklos Szeredi struct fuse_io_priv *io; 75743f5098eSMiklos Szeredi struct fuse_file *ff; 75843f5098eSMiklos Szeredi }; 75943f5098eSMiklos Szeredi 76043f5098eSMiklos Szeredi void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos, 76143f5098eSMiklos Szeredi size_t count, int opcode); 76243f5098eSMiklos Szeredi 76304730fefSMiklos Szeredi 76404730fefSMiklos Szeredi /** 76504730fefSMiklos Szeredi * Send OPEN or OPENDIR request 76604730fefSMiklos Szeredi */ 76791fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 76804730fefSMiklos Szeredi 769acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 770fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 771c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 772fd72faacSMiklos Szeredi 773ebf84d0cSKirill Tkhai void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags); 774c756e0a4SMiklos Szeredi 77504730fefSMiklos Szeredi /** 77604730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 77704730fefSMiklos Szeredi */ 7782e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir); 77904730fefSMiklos Szeredi 78004730fefSMiklos Szeredi /** 78182547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 78282547981SMiklos Szeredi */ 78302c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 784a9c2d1e8SMiklos Szeredi int datasync, int opcode); 78582547981SMiklos Szeredi 78682547981SMiklos Szeredi /** 78795668a69STejun Heo * Notify poll wakeup 78895668a69STejun Heo */ 78995668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 79095668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 79195668a69STejun Heo 79295668a69STejun Heo /** 7931779381dSMiklos Szeredi * Initialize file operations on a regular file 794b6aeadedSMiklos Szeredi */ 795b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 796b6aeadedSMiklos Szeredi 797b6aeadedSMiklos Szeredi /** 7981779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 799e5e5558eSMiklos Szeredi */ 800e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 801e5e5558eSMiklos Szeredi 802e5e5558eSMiklos Szeredi /** 8031779381dSMiklos Szeredi * Initialize inode and file operations on a directory 804e5e5558eSMiklos Szeredi */ 805e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 806e5e5558eSMiklos Szeredi 807e5e5558eSMiklos Szeredi /** 8081779381dSMiklos Szeredi * Initialize inode operations on a symlink 809e5e5558eSMiklos Szeredi */ 810e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 811e5e5558eSMiklos Szeredi 812e5e5558eSMiklos Szeredi /** 813e5e5558eSMiklos Szeredi * Change attributes of an inode 814e5e5558eSMiklos Szeredi */ 8151fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 8161fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 817e5e5558eSMiklos Szeredi 8183be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 8193be5a52bSMiklos Szeredi u64 attr_valid); 8203be5a52bSMiklos Szeredi 821e5e5558eSMiklos Szeredi /** 822334f485dSMiklos Szeredi * Initialize the client device 823334f485dSMiklos Szeredi */ 824334f485dSMiklos Szeredi int fuse_dev_init(void); 825334f485dSMiklos Szeredi 826334f485dSMiklos Szeredi /** 827334f485dSMiklos Szeredi * Cleanup the client device 828334f485dSMiklos Szeredi */ 829334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 830334f485dSMiklos Szeredi 831bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8327736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 833bafa9654SMiklos Szeredi 834334f485dSMiklos Szeredi /** 8357078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 8367078187aSMiklos Szeredi */ 8377078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 83812597287SMiklos Szeredi int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args, 83912597287SMiklos Szeredi gfp_t gfp_flags); 8407078187aSMiklos Szeredi 8415a5fb1eaSMiklos Szeredi /* Abort all requests */ 842eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 843b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 84469a53bf2SMiklos Szeredi 8451e9a4ed9SMiklos Szeredi /** 846e5e5558eSMiklos Szeredi * Invalidate inode attributes 847e5e5558eSMiklos Szeredi */ 848e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 849bafa9654SMiklos Szeredi 850dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 851dbd561d2SMiklos Szeredi 852451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 853451418fcSAndrew Gallagher 854d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o); 855d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 856d123d8e1SMiklos Szeredi 857bafa9654SMiklos Szeredi /** 858bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 859bafa9654SMiklos Szeredi */ 860bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 861bafa9654SMiklos Szeredi 862bafa9654SMiklos Szeredi /** 8630d179aa5STejun Heo * Initialize fuse_conn 8640d179aa5STejun Heo */ 8658cb08329SEric W. Biederman void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); 8660d179aa5STejun Heo 8670d179aa5STejun Heo /** 868bafa9654SMiklos Szeredi * Release reference to fuse_conn 869bafa9654SMiklos Szeredi */ 870bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 871bafa9654SMiklos Szeredi 872cc080e9eSMiklos Szeredi struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 873cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 874cc080e9eSMiklos Szeredi 875bafa9654SMiklos Szeredi /** 876bafa9654SMiklos Szeredi * Add connection to control filesystem 877bafa9654SMiklos Szeredi */ 878bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 879bafa9654SMiklos Szeredi 880bafa9654SMiklos Szeredi /** 881bafa9654SMiklos Szeredi * Remove connection from control filesystem 882bafa9654SMiklos Szeredi */ 883bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 884a5bfffacSTimo Savola 885a5bfffacSTimo Savola /** 886a5bfffacSTimo Savola * Is file type valid? 887a5bfffacSTimo Savola */ 888a5bfffacSTimo Savola int fuse_valid_type(int m); 889e57ac683SMiklos Szeredi 890e57ac683SMiklos Szeredi /** 891c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 892e57ac683SMiklos Szeredi */ 893c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 894f3332114SMiklos Szeredi 895f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 896bcb4be80SMiklos Szeredi 897703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 898703c7362SSeth Forshee 8995b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 9003be5a52bSMiklos Szeredi 9013be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9023be5a52bSMiklos Szeredi 9033be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9043be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9055c5c5e51SMiklos Szeredi 9063b463ae0SJohn Muir /** 9073b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9083b463ae0SJohn Muir */ 9093b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9103b463ae0SJohn Muir loff_t offset, loff_t len); 9113b463ae0SJohn Muir 9123b463ae0SJohn Muir /** 9133b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9143b463ae0SJohn Muir * the dentry matching parent/name. 915451d0f59SJohn Muir * 916451d0f59SJohn Muir * If the child_nodeid is non-zero and: 917451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 918451d0f59SJohn Muir * - is not a mount point 919451d0f59SJohn Muir * - is a file or oan empty directory 920451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 9213b463ae0SJohn Muir */ 9223b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 923451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 9243b463ae0SJohn Muir 92508cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 92608cbf542STejun Heo bool isdir); 927ea8cd333SPavel Emelyanov 928ea8cd333SPavel Emelyanov /** 929ea8cd333SPavel Emelyanov * fuse_direct_io() flags 930ea8cd333SPavel Emelyanov */ 931ea8cd333SPavel Emelyanov 932ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 933ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 934ea8cd333SPavel Emelyanov 935ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 936ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 937ea8cd333SPavel Emelyanov 938d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 939d22a943fSAl Viro loff_t *ppos, int flags); 94008cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 94108cbf542STejun Heo unsigned int flags); 942b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 943b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 944076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 94508cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 94608cbf542STejun Heo 947b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 948b0aa7606SMaxim Patlasov 949ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 9501e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 951a1d75f25SMiklos Szeredi 95262490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 953efb9fa9eSMaxim Patlasov struct file *file); 954efb9fa9eSMaxim Patlasov 9559759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 9569759bd51SMiklos Szeredi 95763576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 95863576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 9595c672ab3SMiklos Szeredi 96060bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 96160bcc88aSSeth Forshee size_t size, int flags); 96260bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 96360bcc88aSSeth Forshee size_t size); 964703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 96560bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 966703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 96760bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 968e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 96960bcc88aSSeth Forshee 97060bcc88aSSeth Forshee struct posix_acl; 97160bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 97260bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 973703c7362SSeth Forshee 974d123d8e1SMiklos Szeredi 975d123d8e1SMiklos Szeredi /* readdir.c */ 976d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 977d123d8e1SMiklos Szeredi 97829d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 979