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 343d4993774SMiklos Szeredi /* The request input header */ 344d4993774SMiklos Szeredi struct { 345d4993774SMiklos Szeredi struct fuse_in_header h; 346d4993774SMiklos Szeredi } in; 347334f485dSMiklos Szeredi 348d4993774SMiklos Szeredi /* The request output header */ 349d4993774SMiklos Szeredi struct { 350d4993774SMiklos Szeredi struct fuse_out_header h; 351d4993774SMiklos 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 }; 357334f485dSMiklos Szeredi 358ae3aad77SStefan Hajnoczi struct fuse_iqueue; 359ae3aad77SStefan Hajnoczi 360ae3aad77SStefan Hajnoczi /** 361ae3aad77SStefan Hajnoczi * Input queue callbacks 362ae3aad77SStefan Hajnoczi * 363ae3aad77SStefan Hajnoczi * Input queue signalling is device-specific. For example, the /dev/fuse file 364ae3aad77SStefan Hajnoczi * uses fiq->waitq and fasync to wake processes that are waiting on queue 365ae3aad77SStefan Hajnoczi * readiness. These callbacks allow other device types to respond to input 366ae3aad77SStefan Hajnoczi * queue activity. 367ae3aad77SStefan Hajnoczi */ 368ae3aad77SStefan Hajnoczi struct fuse_iqueue_ops { 369ae3aad77SStefan Hajnoczi /** 370ae3aad77SStefan Hajnoczi * Signal that a forget has been queued 371ae3aad77SStefan Hajnoczi */ 372ae3aad77SStefan Hajnoczi void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq) 373ae3aad77SStefan Hajnoczi __releases(fiq->lock); 374ae3aad77SStefan Hajnoczi 375ae3aad77SStefan Hajnoczi /** 376ae3aad77SStefan Hajnoczi * Signal that an INTERRUPT request has been queued 377ae3aad77SStefan Hajnoczi */ 378ae3aad77SStefan Hajnoczi void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq) 379ae3aad77SStefan Hajnoczi __releases(fiq->lock); 380ae3aad77SStefan Hajnoczi 381ae3aad77SStefan Hajnoczi /** 382ae3aad77SStefan Hajnoczi * Signal that a request has been queued 383ae3aad77SStefan Hajnoczi */ 384ae3aad77SStefan Hajnoczi void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq) 385ae3aad77SStefan Hajnoczi __releases(fiq->lock); 386ae3aad77SStefan Hajnoczi }; 387ae3aad77SStefan Hajnoczi 388ae3aad77SStefan Hajnoczi /** /dev/fuse input queue operations */ 389ae3aad77SStefan Hajnoczi extern const struct fuse_iqueue_ops fuse_dev_fiq_ops; 390ae3aad77SStefan Hajnoczi 391f88996a9SMiklos Szeredi struct fuse_iqueue { 392e16714d8SMiklos Szeredi /** Connection established */ 393e16714d8SMiklos Szeredi unsigned connected; 394e16714d8SMiklos Szeredi 39576e43c8cSEric Biggers /** Lock protecting accesses to members of this structure */ 39676e43c8cSEric Biggers spinlock_t lock; 39776e43c8cSEric Biggers 398f88996a9SMiklos Szeredi /** Readers of the connection are waiting on this */ 399f88996a9SMiklos Szeredi wait_queue_head_t waitq; 400f88996a9SMiklos Szeredi 401f88996a9SMiklos Szeredi /** The next unique request id */ 402f88996a9SMiklos Szeredi u64 reqctr; 403f88996a9SMiklos Szeredi 404f88996a9SMiklos Szeredi /** The list of pending requests */ 405f88996a9SMiklos Szeredi struct list_head pending; 406f88996a9SMiklos Szeredi 407f88996a9SMiklos Szeredi /** Pending interrupts */ 408f88996a9SMiklos Szeredi struct list_head interrupts; 409f88996a9SMiklos Szeredi 410f88996a9SMiklos Szeredi /** Queue of pending forgets */ 411f88996a9SMiklos Szeredi struct fuse_forget_link forget_list_head; 412f88996a9SMiklos Szeredi struct fuse_forget_link *forget_list_tail; 413f88996a9SMiklos Szeredi 414f88996a9SMiklos Szeredi /** Batching of FORGET requests (positive indicates FORGET batch) */ 415f88996a9SMiklos Szeredi int forget_batch; 416f88996a9SMiklos Szeredi 417f88996a9SMiklos Szeredi /** O_ASYNC requests */ 418f88996a9SMiklos Szeredi struct fasync_struct *fasync; 419ae3aad77SStefan Hajnoczi 420ae3aad77SStefan Hajnoczi /** Device-specific callbacks */ 421ae3aad77SStefan Hajnoczi const struct fuse_iqueue_ops *ops; 422ae3aad77SStefan Hajnoczi 423ae3aad77SStefan Hajnoczi /** Device-specific state */ 424ae3aad77SStefan Hajnoczi void *priv; 425f88996a9SMiklos Szeredi }; 426f88996a9SMiklos Szeredi 427be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_BITS 8 428be2ff42cSKirill Tkhai #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 429be2ff42cSKirill Tkhai 4303a2b5b9cSMiklos Szeredi struct fuse_pqueue { 431e96edd94SMiklos Szeredi /** Connection established */ 432e96edd94SMiklos Szeredi unsigned connected; 433e96edd94SMiklos Szeredi 43445a91cb1SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 43545a91cb1SMiklos Szeredi spinlock_t lock; 43645a91cb1SMiklos Szeredi 437be2ff42cSKirill Tkhai /** Hash table of requests being processed */ 438be2ff42cSKirill Tkhai struct list_head *processing; 4393a2b5b9cSMiklos Szeredi 4403a2b5b9cSMiklos Szeredi /** The list of requests under I/O */ 4413a2b5b9cSMiklos Szeredi struct list_head io; 4423a2b5b9cSMiklos Szeredi }; 4433a2b5b9cSMiklos Szeredi 444d8a5ba45SMiklos Szeredi /** 445cc080e9eSMiklos Szeredi * Fuse device instance 446cc080e9eSMiklos Szeredi */ 447cc080e9eSMiklos Szeredi struct fuse_dev { 448cc080e9eSMiklos Szeredi /** Fuse connection for this device */ 449cc080e9eSMiklos Szeredi struct fuse_conn *fc; 450cc080e9eSMiklos Szeredi 451c3696046SMiklos Szeredi /** Processing queue */ 452c3696046SMiklos Szeredi struct fuse_pqueue pq; 453c3696046SMiklos Szeredi 454cc080e9eSMiklos Szeredi /** list entry on fc->devices */ 455cc080e9eSMiklos Szeredi struct list_head entry; 456cc080e9eSMiklos Szeredi }; 457cc080e9eSMiklos Szeredi 4580cc2656cSStefan Hajnoczi struct fuse_fs_context { 4590cc2656cSStefan Hajnoczi int fd; 4600cc2656cSStefan Hajnoczi unsigned int rootmode; 4610cc2656cSStefan Hajnoczi kuid_t user_id; 4620cc2656cSStefan Hajnoczi kgid_t group_id; 4630cc2656cSStefan Hajnoczi bool is_bdev:1; 4640cc2656cSStefan Hajnoczi bool fd_present:1; 4650cc2656cSStefan Hajnoczi bool rootmode_present:1; 4660cc2656cSStefan Hajnoczi bool user_id_present:1; 4670cc2656cSStefan Hajnoczi bool group_id_present:1; 4680cc2656cSStefan Hajnoczi bool default_permissions:1; 4690cc2656cSStefan Hajnoczi bool allow_other:1; 470*783863d6SMiklos Szeredi bool destroy:1; 4710cc2656cSStefan Hajnoczi unsigned int max_read; 4720cc2656cSStefan Hajnoczi unsigned int blksize; 4730cc2656cSStefan Hajnoczi const char *subtype; 4740cc2656cSStefan Hajnoczi 4750cc2656cSStefan Hajnoczi /* fuse_dev pointer to fill in, should contain NULL on entry */ 4760cc2656cSStefan Hajnoczi void **fudptr; 4770cc2656cSStefan Hajnoczi }; 4780cc2656cSStefan Hajnoczi 479cc080e9eSMiklos Szeredi /** 480d8a5ba45SMiklos Szeredi * A Fuse connection. 481d8a5ba45SMiklos Szeredi * 482d8a5ba45SMiklos Szeredi * This structure is created, when the filesystem is mounted, and is 483d8a5ba45SMiklos Szeredi * destroyed, when the client device is closed and the filesystem is 484d8a5ba45SMiklos Szeredi * unmounted. 485d8a5ba45SMiklos Szeredi */ 486d8a5ba45SMiklos Szeredi struct fuse_conn { 487d7133114SMiklos Szeredi /** Lock protecting accessess to members of this structure */ 488d7133114SMiklos Szeredi spinlock_t lock; 489d7133114SMiklos Szeredi 490bafa9654SMiklos Szeredi /** Refcount */ 491095fc40aSElena Reshetova refcount_t count; 492bafa9654SMiklos Szeredi 493c3696046SMiklos Szeredi /** Number of fuse_dev's */ 494c3696046SMiklos Szeredi atomic_t dev_count; 495c3696046SMiklos Szeredi 496dd3e2c55SAl Viro struct rcu_head rcu; 497dd3e2c55SAl Viro 498d8a5ba45SMiklos Szeredi /** The user id for this mount */ 499499dcf20SEric W. Biederman kuid_t user_id; 500d8a5ba45SMiklos Szeredi 50187729a55SMiklos Szeredi /** The group id for this mount */ 502499dcf20SEric W. Biederman kgid_t group_id; 50387729a55SMiklos Szeredi 5040b6e9ea0SSeth Forshee /** The pid namespace for this mount */ 5050b6e9ea0SSeth Forshee struct pid_namespace *pid_ns; 5060b6e9ea0SSeth Forshee 5078cb08329SEric W. Biederman /** The user namespace for this mount */ 5088cb08329SEric W. Biederman struct user_namespace *user_ns; 5098cb08329SEric W. Biederman 510db50b96cSMiklos Szeredi /** Maximum read size */ 511db50b96cSMiklos Szeredi unsigned max_read; 512db50b96cSMiklos Szeredi 513413ef8cbSMiklos Szeredi /** Maximum write size */ 514413ef8cbSMiklos Szeredi unsigned max_write; 515413ef8cbSMiklos Szeredi 5165da784ccSConstantine Shulyupin /** Maxmum number of pages that can be used in a single request */ 5175da784ccSConstantine Shulyupin unsigned int max_pages; 5185da784ccSConstantine Shulyupin 519f88996a9SMiklos Szeredi /** Input queue */ 520f88996a9SMiklos Szeredi struct fuse_iqueue iq; 521334f485dSMiklos Szeredi 522acf99433STejun Heo /** The next unique kernel file handle */ 52375126f55SMiklos Szeredi atomic64_t 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 55969a53bf2SMiklos Szeredi /** Connection established, cleared on umount, connection 56069a53bf2SMiklos Szeredi abort and device release */ 561095da6cbSMiklos Szeredi unsigned connected; 5621e9a4ed9SMiklos Szeredi 5633b7008b2SSzymon Lukasz /** Connection aborted via sysfs */ 5643b7008b2SSzymon Lukasz bool aborted; 5653b7008b2SSzymon Lukasz 566095da6cbSMiklos Szeredi /** Connection failed (version mismatch). Cannot race with 567095da6cbSMiklos Szeredi setting other bitfields since it is only set once in INIT 568095da6cbSMiklos Szeredi reply, before any other request, and never cleared */ 569334f485dSMiklos Szeredi unsigned conn_error:1; 570334f485dSMiklos Szeredi 5710ec7ca41SMiklos Szeredi /** Connection successful. Only set in INIT */ 5720ec7ca41SMiklos Szeredi unsigned conn_init:1; 5730ec7ca41SMiklos Szeredi 5749cd68455SMiklos Szeredi /** Do readpages asynchronously? Only set in INIT */ 5759cd68455SMiklos Szeredi unsigned async_read:1; 5769cd68455SMiklos Szeredi 5773b7008b2SSzymon Lukasz /** Return an unique read error after abort. Only set in INIT */ 5783b7008b2SSzymon Lukasz unsigned abort_err:1; 5793b7008b2SSzymon Lukasz 5806ff958edSMiklos Szeredi /** Do not send separate SETATTR request before open(O_TRUNC) */ 5816ff958edSMiklos Szeredi unsigned atomic_o_trunc:1; 5826ff958edSMiklos Szeredi 58333670fa2SMiklos Szeredi /** Filesystem supports NFS exporting. Only set in INIT */ 58433670fa2SMiklos Szeredi unsigned export_support:1; 58533670fa2SMiklos Szeredi 586d5cd66c5SPavel Emelyanov /** write-back cache policy (default is write-through) */ 587d5cd66c5SPavel Emelyanov unsigned writeback_cache:1; 588d5cd66c5SPavel Emelyanov 5895c672ab3SMiklos Szeredi /** allow parallel lookups and readdir (default is serialized) */ 5905c672ab3SMiklos Szeredi unsigned parallel_dirops:1; 5915c672ab3SMiklos Szeredi 5925e940c1dSMiklos Szeredi /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 5935e940c1dSMiklos Szeredi unsigned handle_killpriv:1; 5945e940c1dSMiklos Szeredi 5955571f1e6SDan Schatzberg /** cache READLINK responses in page cache */ 5965571f1e6SDan Schatzberg unsigned cache_symlinks:1; 5975571f1e6SDan Schatzberg 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 606d9a9ea94SChad Austin /** Is opendir/releasedir not implemented by fs? */ 607d9a9ea94SChad Austin unsigned no_opendir:1; 608d9a9ea94SChad Austin 609b6aeadedSMiklos Szeredi /** Is fsync not implemented by fs? */ 610b6aeadedSMiklos Szeredi unsigned no_fsync:1; 611b6aeadedSMiklos Szeredi 61282547981SMiklos Szeredi /** Is fsyncdir not implemented by fs? */ 61382547981SMiklos Szeredi unsigned no_fsyncdir:1; 61482547981SMiklos Szeredi 615b6aeadedSMiklos Szeredi /** Is flush not implemented by fs? */ 616b6aeadedSMiklos Szeredi unsigned no_flush:1; 617b6aeadedSMiklos Szeredi 61892a8780eSMiklos Szeredi /** Is setxattr not implemented by fs? */ 61992a8780eSMiklos Szeredi unsigned no_setxattr:1; 62092a8780eSMiklos Szeredi 62192a8780eSMiklos Szeredi /** Is getxattr not implemented by fs? */ 62292a8780eSMiklos Szeredi unsigned no_getxattr:1; 62392a8780eSMiklos Szeredi 62492a8780eSMiklos Szeredi /** Is listxattr not implemented by fs? */ 62592a8780eSMiklos Szeredi unsigned no_listxattr:1; 62692a8780eSMiklos Szeredi 62792a8780eSMiklos Szeredi /** Is removexattr not implemented by fs? */ 62892a8780eSMiklos Szeredi unsigned no_removexattr:1; 62992a8780eSMiklos Szeredi 63037fb3a30SMiklos Szeredi /** Are posix file locking primitives not implemented by fs? */ 63171421259SMiklos Szeredi unsigned no_lock:1; 63271421259SMiklos Szeredi 63331d40d74SMiklos Szeredi /** Is access not implemented by fs? */ 63431d40d74SMiklos Szeredi unsigned no_access:1; 63531d40d74SMiklos Szeredi 636fd72faacSMiklos Szeredi /** Is create not implemented by fs? */ 637fd72faacSMiklos Szeredi unsigned no_create:1; 638fd72faacSMiklos Szeredi 639a4d27e75SMiklos Szeredi /** Is interrupt not implemented by fs? */ 640a4d27e75SMiklos Szeredi unsigned no_interrupt:1; 641a4d27e75SMiklos Szeredi 642b2d2272fSMiklos Szeredi /** Is bmap not implemented by fs? */ 643b2d2272fSMiklos Szeredi unsigned no_bmap:1; 644b2d2272fSMiklos Szeredi 64595668a69STejun Heo /** Is poll not implemented by fs? */ 64695668a69STejun Heo unsigned no_poll:1; 64795668a69STejun Heo 64878bb6cb9SMiklos Szeredi /** Do multi-page cached writes */ 64978bb6cb9SMiklos Szeredi unsigned big_writes:1; 65078bb6cb9SMiklos Szeredi 651e0a43ddcSMiklos Szeredi /** Don't apply umask to creation modes */ 652e0a43ddcSMiklos Szeredi unsigned dont_mask:1; 653e0a43ddcSMiklos Szeredi 65437fb3a30SMiklos Szeredi /** Are BSD file locking primitives not implemented by fs? */ 65537fb3a30SMiklos Szeredi unsigned no_flock:1; 65637fb3a30SMiklos Szeredi 657519c6040SMiklos Szeredi /** Is fallocate not implemented by fs? */ 658519c6040SMiklos Szeredi unsigned no_fallocate:1; 659519c6040SMiklos Szeredi 6601560c974SMiklos Szeredi /** Is rename with flags implemented by fs? */ 6611560c974SMiklos Szeredi unsigned no_rename2:1; 6621560c974SMiklos Szeredi 66372d0d248SBrian Foster /** Use enhanced/automatic page cache invalidation. */ 66472d0d248SBrian Foster unsigned auto_inval_data:1; 66572d0d248SBrian Foster 666ad2ba64dSKirill Smelkov /** Filesystem is fully reponsible for page cache invalidation. */ 667ad2ba64dSKirill Smelkov unsigned explicit_inval_data:1; 668ad2ba64dSKirill Smelkov 669634734b6SEric Wong /** Does the filesystem support readdirplus? */ 6700b05b183SAnand V. Avati unsigned do_readdirplus:1; 6710b05b183SAnand V. Avati 672634734b6SEric Wong /** Does the filesystem want adaptive readdirplus? */ 673634734b6SEric Wong unsigned readdirplus_auto:1; 674634734b6SEric Wong 67560b9df7aSMiklos Szeredi /** Does the filesystem support asynchronous direct-IO submission? */ 67660b9df7aSMiklos Szeredi unsigned async_dio:1; 67760b9df7aSMiklos Szeredi 6780b5da8dbSRavishankar N /** Is lseek not implemented by fs? */ 6790b5da8dbSRavishankar N unsigned no_lseek:1; 6800b5da8dbSRavishankar N 68160bcc88aSSeth Forshee /** Does the filesystem support posix acls? */ 68260bcc88aSSeth Forshee unsigned posix_acl:1; 68360bcc88aSSeth Forshee 68429433a29SMiklos Szeredi /** Check permissions based on the file mode or not? */ 68529433a29SMiklos Szeredi unsigned default_permissions:1; 68629433a29SMiklos Szeredi 68729433a29SMiklos Szeredi /** Allow other than the mounter user to access the filesystem ? */ 68829433a29SMiklos Szeredi unsigned allow_other:1; 68929433a29SMiklos Szeredi 69088bc7d50SNiels de Vos /** Does the filesystem support copy_file_range? */ 69188bc7d50SNiels de Vos unsigned no_copy_file_range:1; 69288bc7d50SNiels de Vos 6931ccd1ea2SMiklos Szeredi /* Send DESTROY request */ 6941ccd1ea2SMiklos Szeredi unsigned int destroy:1; 6951ccd1ea2SMiklos Szeredi 6968fab0106SMiklos Szeredi /* Delete dentries that have gone stale */ 6978fab0106SMiklos Szeredi unsigned int delete_stale:1; 6988fab0106SMiklos Szeredi 6990cd5b885SMiklos Szeredi /** The number of requests waiting for completion */ 7000cd5b885SMiklos Szeredi atomic_t num_waiting; 7010cd5b885SMiklos Szeredi 70245714d65SMiklos Szeredi /** Negotiated minor version */ 70345714d65SMiklos Szeredi unsigned minor; 70445714d65SMiklos Szeredi 705bafa9654SMiklos Szeredi /** Entry on the fuse_conn_list */ 706bafa9654SMiklos Szeredi struct list_head entry; 707bafa9654SMiklos Szeredi 708b6f2fcbcSMiklos Szeredi /** Device ID from super block */ 709b6f2fcbcSMiklos Szeredi dev_t dev; 710bafa9654SMiklos Szeredi 711bafa9654SMiklos Szeredi /** Dentries in the control filesystem */ 712bafa9654SMiklos Szeredi struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 713bafa9654SMiklos Szeredi 714bafa9654SMiklos Szeredi /** number of dentries used in the above array */ 715bafa9654SMiklos Szeredi int ctl_ndents; 716385a17bfSJeff Dike 7179c8ef561SMiklos Szeredi /** Key for lock owner ID scrambling */ 7189c8ef561SMiklos Szeredi u32 scramble_key[4]; 7190ec7ca41SMiklos Szeredi 7201fb69e78SMiklos Szeredi /** Version counter for attribute changes */ 7214510d86fSKirill Tkhai atomic64_t attr_version; 72243901aabSTejun Heo 72343901aabSTejun Heo /** Called on final put */ 72443901aabSTejun Heo void (*release)(struct fuse_conn *); 7253b463ae0SJohn Muir 7263b463ae0SJohn Muir /** Super block for this connection. */ 7273b463ae0SJohn Muir struct super_block *sb; 7283b463ae0SJohn Muir 7293b463ae0SJohn Muir /** Read/write semaphore to hold when accessing sb. */ 7303b463ae0SJohn Muir struct rw_semaphore killsb; 731cc080e9eSMiklos Szeredi 732cc080e9eSMiklos Szeredi /** List of device instances belonging to this connection */ 733cc080e9eSMiklos Szeredi struct list_head devices; 734d8a5ba45SMiklos Szeredi }; 735d8a5ba45SMiklos Szeredi 736d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 737d8a5ba45SMiklos Szeredi { 7386383bdaaSMiklos Szeredi return sb->s_fs_info; 739d8a5ba45SMiklos Szeredi } 740d8a5ba45SMiklos Szeredi 741d8a5ba45SMiklos Szeredi static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 742d8a5ba45SMiklos Szeredi { 743d8a5ba45SMiklos Szeredi return get_fuse_conn_super(inode->i_sb); 744d8a5ba45SMiklos Szeredi } 745d8a5ba45SMiklos Szeredi 746d8a5ba45SMiklos Szeredi static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 747d8a5ba45SMiklos Szeredi { 748d8a5ba45SMiklos Szeredi return container_of(inode, struct fuse_inode, inode); 749d8a5ba45SMiklos Szeredi } 750d8a5ba45SMiklos Szeredi 751d8a5ba45SMiklos Szeredi static inline u64 get_node_id(struct inode *inode) 752d8a5ba45SMiklos Szeredi { 753d8a5ba45SMiklos Szeredi return get_fuse_inode(inode)->nodeid; 754d8a5ba45SMiklos Szeredi } 755d8a5ba45SMiklos Szeredi 756d123d8e1SMiklos Szeredi static inline int invalid_nodeid(u64 nodeid) 757d123d8e1SMiklos Szeredi { 758d123d8e1SMiklos Szeredi return !nodeid || nodeid == FUSE_ROOT_ID; 759d123d8e1SMiklos Szeredi } 760d123d8e1SMiklos Szeredi 7614510d86fSKirill Tkhai static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 7624510d86fSKirill Tkhai { 7634510d86fSKirill Tkhai return atomic64_read(&fc->attr_version); 7644510d86fSKirill Tkhai } 7654510d86fSKirill Tkhai 766334f485dSMiklos Szeredi /** Device operations */ 7674b6f5d20SArjan van de Ven extern const struct file_operations fuse_dev_operations; 768334f485dSMiklos Szeredi 7694269590aSAl Viro extern const struct dentry_operations fuse_dentry_operations; 7700ce267ffSMiklos Szeredi extern const struct dentry_operations fuse_root_dentry_operations; 771dbd561d2SMiklos Szeredi 772d8a5ba45SMiklos Szeredi /** 7733b463ae0SJohn Muir * Inode to nodeid comparison. 7743b463ae0SJohn Muir */ 7753b463ae0SJohn Muir int fuse_inode_eq(struct inode *inode, void *_nodeidp); 7763b463ae0SJohn Muir 7773b463ae0SJohn Muir /** 778e5e5558eSMiklos Szeredi * Get a filled in inode 779e5e5558eSMiklos Szeredi */ 780b48badf0SMiklos Szeredi struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 7811fb69e78SMiklos Szeredi int generation, struct fuse_attr *attr, 7821fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 783e5e5558eSMiklos Szeredi 78413983d06SAl Viro int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 78533670fa2SMiklos Szeredi struct fuse_entry_out *outarg, struct inode **inode); 78633670fa2SMiklos Szeredi 787e5e5558eSMiklos Szeredi /** 788e5e5558eSMiklos Szeredi * Send FORGET command 789e5e5558eSMiklos Szeredi */ 79007e77dcaSMiklos Szeredi void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 791b48badf0SMiklos Szeredi u64 nodeid, u64 nlookup); 792e5e5558eSMiklos Szeredi 79307e77dcaSMiklos Szeredi struct fuse_forget_link *fuse_alloc_forget(void); 79407e77dcaSMiklos Szeredi 7954388c5aaSVivek Goyal struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq, 7964388c5aaSVivek Goyal unsigned int max, 7974388c5aaSVivek Goyal unsigned int *countp); 7984388c5aaSVivek Goyal 79943f5098eSMiklos Szeredi /* 800361b1eb5SMiklos Szeredi * Initialize READ or READDIR request 80104730fefSMiklos Szeredi */ 80243f5098eSMiklos Szeredi struct fuse_io_args { 80343f5098eSMiklos Szeredi union { 80443f5098eSMiklos Szeredi struct { 80543f5098eSMiklos Szeredi struct fuse_read_in in; 80643f5098eSMiklos Szeredi u64 attr_ver; 80743f5098eSMiklos Szeredi } read; 80843f5098eSMiklos Szeredi struct { 80943f5098eSMiklos Szeredi struct fuse_write_in in; 81043f5098eSMiklos Szeredi struct fuse_write_out out; 81143f5098eSMiklos Szeredi } write; 81243f5098eSMiklos Szeredi }; 81343f5098eSMiklos Szeredi struct fuse_args_pages ap; 81443f5098eSMiklos Szeredi struct fuse_io_priv *io; 81543f5098eSMiklos Szeredi struct fuse_file *ff; 81643f5098eSMiklos Szeredi }; 81743f5098eSMiklos Szeredi 81843f5098eSMiklos Szeredi void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos, 81943f5098eSMiklos Szeredi size_t count, int opcode); 82043f5098eSMiklos Szeredi 82104730fefSMiklos Szeredi 82204730fefSMiklos Szeredi /** 82304730fefSMiklos Szeredi * Send OPEN or OPENDIR request 82404730fefSMiklos Szeredi */ 82591fe96b4SMiklos Szeredi int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 82604730fefSMiklos Szeredi 827acf99433STejun Heo struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 828fd72faacSMiklos Szeredi void fuse_file_free(struct fuse_file *ff); 829c7b7143cSMiklos Szeredi void fuse_finish_open(struct inode *inode, struct file *file); 830fd72faacSMiklos Szeredi 831ebf84d0cSKirill Tkhai void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags); 832c756e0a4SMiklos Szeredi 83304730fefSMiklos Szeredi /** 83404730fefSMiklos Szeredi * Send RELEASE or RELEASEDIR request 83504730fefSMiklos Szeredi */ 8362e64ff15SChad Austin void fuse_release_common(struct file *file, bool isdir); 83704730fefSMiklos Szeredi 83804730fefSMiklos Szeredi /** 83982547981SMiklos Szeredi * Send FSYNC or FSYNCDIR request 84082547981SMiklos Szeredi */ 84102c24a82SJosef Bacik int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 842a9c2d1e8SMiklos Szeredi int datasync, int opcode); 84382547981SMiklos Szeredi 84482547981SMiklos Szeredi /** 84595668a69STejun Heo * Notify poll wakeup 84695668a69STejun Heo */ 84795668a69STejun Heo int fuse_notify_poll_wakeup(struct fuse_conn *fc, 84895668a69STejun Heo struct fuse_notify_poll_wakeup_out *outarg); 84995668a69STejun Heo 85095668a69STejun Heo /** 8511779381dSMiklos Szeredi * Initialize file operations on a regular file 852b6aeadedSMiklos Szeredi */ 853b6aeadedSMiklos Szeredi void fuse_init_file_inode(struct inode *inode); 854b6aeadedSMiklos Szeredi 855b6aeadedSMiklos Szeredi /** 8561779381dSMiklos Szeredi * Initialize inode operations on regular files and special files 857e5e5558eSMiklos Szeredi */ 858e5e5558eSMiklos Szeredi void fuse_init_common(struct inode *inode); 859e5e5558eSMiklos Szeredi 860e5e5558eSMiklos Szeredi /** 8611779381dSMiklos Szeredi * Initialize inode and file operations on a directory 862e5e5558eSMiklos Szeredi */ 863e5e5558eSMiklos Szeredi void fuse_init_dir(struct inode *inode); 864e5e5558eSMiklos Szeredi 865e5e5558eSMiklos Szeredi /** 8661779381dSMiklos Szeredi * Initialize inode operations on a symlink 867e5e5558eSMiklos Szeredi */ 868e5e5558eSMiklos Szeredi void fuse_init_symlink(struct inode *inode); 869e5e5558eSMiklos Szeredi 870e5e5558eSMiklos Szeredi /** 871e5e5558eSMiklos Szeredi * Change attributes of an inode 872e5e5558eSMiklos Szeredi */ 8731fb69e78SMiklos Szeredi void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 8741fb69e78SMiklos Szeredi u64 attr_valid, u64 attr_version); 875e5e5558eSMiklos Szeredi 8763be5a52bSMiklos Szeredi void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 8773be5a52bSMiklos Szeredi u64 attr_valid); 8783be5a52bSMiklos Szeredi 879e5e5558eSMiklos Szeredi /** 880334f485dSMiklos Szeredi * Initialize the client device 881334f485dSMiklos Szeredi */ 882334f485dSMiklos Szeredi int fuse_dev_init(void); 883334f485dSMiklos Szeredi 884334f485dSMiklos Szeredi /** 885334f485dSMiklos Szeredi * Cleanup the client device 886334f485dSMiklos Szeredi */ 887334f485dSMiklos Szeredi void fuse_dev_cleanup(void); 888334f485dSMiklos Szeredi 889bafa9654SMiklos Szeredi int fuse_ctl_init(void); 8907736e8ccSFabian Frederick void __exit fuse_ctl_cleanup(void); 891bafa9654SMiklos Szeredi 892334f485dSMiklos Szeredi /** 8937078187aSMiklos Szeredi * Simple request sending that does request allocation and freeing 8947078187aSMiklos Szeredi */ 8957078187aSMiklos Szeredi ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 89612597287SMiklos Szeredi int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args, 89712597287SMiklos Szeredi gfp_t gfp_flags); 8987078187aSMiklos Szeredi 89904ec5af0SStefan Hajnoczi /** 90004ec5af0SStefan Hajnoczi * End a finished request 90104ec5af0SStefan Hajnoczi */ 90204ec5af0SStefan Hajnoczi void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req); 90304ec5af0SStefan Hajnoczi 9045a5fb1eaSMiklos Szeredi /* Abort all requests */ 905eb98e3bdSMiklos Szeredi void fuse_abort_conn(struct fuse_conn *fc); 906b8f95e5dSMiklos Szeredi void fuse_wait_aborted(struct fuse_conn *fc); 90769a53bf2SMiklos Szeredi 9081e9a4ed9SMiklos Szeredi /** 909e5e5558eSMiklos Szeredi * Invalidate inode attributes 910e5e5558eSMiklos Szeredi */ 911e5e5558eSMiklos Szeredi void fuse_invalidate_attr(struct inode *inode); 912bafa9654SMiklos Szeredi 913dbd561d2SMiklos Szeredi void fuse_invalidate_entry_cache(struct dentry *entry); 914dbd561d2SMiklos Szeredi 915451418fcSAndrew Gallagher void fuse_invalidate_atime(struct inode *inode); 916451418fcSAndrew Gallagher 917d123d8e1SMiklos Szeredi u64 entry_attr_timeout(struct fuse_entry_out *o); 918d123d8e1SMiklos Szeredi void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 919d123d8e1SMiklos Szeredi 920bafa9654SMiklos Szeredi /** 921bafa9654SMiklos Szeredi * Acquire reference to fuse_conn 922bafa9654SMiklos Szeredi */ 923bafa9654SMiklos Szeredi struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 924bafa9654SMiklos Szeredi 925bafa9654SMiklos Szeredi /** 9260d179aa5STejun Heo * Initialize fuse_conn 9270d179aa5STejun Heo */ 928ae3aad77SStefan Hajnoczi void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns, 929ae3aad77SStefan Hajnoczi const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv); 9300d179aa5STejun Heo 9310d179aa5STejun Heo /** 932bafa9654SMiklos Szeredi * Release reference to fuse_conn 933bafa9654SMiklos Szeredi */ 934bafa9654SMiklos Szeredi void fuse_conn_put(struct fuse_conn *fc); 935bafa9654SMiklos Szeredi 9360cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc); 9370cd1eb9aSVivek Goyal struct fuse_dev *fuse_dev_alloc(void); 9380cd1eb9aSVivek Goyal void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc); 939cc080e9eSMiklos Szeredi void fuse_dev_free(struct fuse_dev *fud); 94095a84cdbSVivek Goyal void fuse_send_init(struct fuse_conn *fc); 941cc080e9eSMiklos Szeredi 942bafa9654SMiklos Szeredi /** 9430cc2656cSStefan Hajnoczi * Fill in superblock and initialize fuse connection 9440cc2656cSStefan Hajnoczi * @sb: partially-initialized superblock to fill in 9450cc2656cSStefan Hajnoczi * @ctx: mount context 9460cc2656cSStefan Hajnoczi */ 9470cc2656cSStefan Hajnoczi int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx); 9480cc2656cSStefan Hajnoczi 9490cc2656cSStefan Hajnoczi /** 950*783863d6SMiklos Szeredi * Disassociate fuse connection from superblock and kill the superblock 951*783863d6SMiklos Szeredi * 952*783863d6SMiklos Szeredi * Calls kill_anon_super(), do not use with bdev mounts. 953*783863d6SMiklos Szeredi */ 954*783863d6SMiklos Szeredi void fuse_kill_sb_anon(struct super_block *sb); 955*783863d6SMiklos Szeredi 956*783863d6SMiklos Szeredi /** 957bafa9654SMiklos Szeredi * Add connection to control filesystem 958bafa9654SMiklos Szeredi */ 959bafa9654SMiklos Szeredi int fuse_ctl_add_conn(struct fuse_conn *fc); 960bafa9654SMiklos Szeredi 961bafa9654SMiklos Szeredi /** 962bafa9654SMiklos Szeredi * Remove connection from control filesystem 963bafa9654SMiklos Szeredi */ 964bafa9654SMiklos Szeredi void fuse_ctl_remove_conn(struct fuse_conn *fc); 965a5bfffacSTimo Savola 966a5bfffacSTimo Savola /** 967a5bfffacSTimo Savola * Is file type valid? 968a5bfffacSTimo Savola */ 969a5bfffacSTimo Savola int fuse_valid_type(int m); 970e57ac683SMiklos Szeredi 971e57ac683SMiklos Szeredi /** 972c2132c1bSAnatol Pomozov * Is current process allowed to perform filesystem operation? 973e57ac683SMiklos Szeredi */ 974c2132c1bSAnatol Pomozov int fuse_allow_current_process(struct fuse_conn *fc); 975f3332114SMiklos Szeredi 976f3332114SMiklos Szeredi u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 977bcb4be80SMiklos Szeredi 978703c7362SSeth Forshee void fuse_update_ctime(struct inode *inode); 979703c7362SSeth Forshee 9805b97eeacSMiklos Szeredi int fuse_update_attributes(struct inode *inode, struct file *file); 9813be5a52bSMiklos Szeredi 9823be5a52bSMiklos Szeredi void fuse_flush_writepages(struct inode *inode); 9833be5a52bSMiklos Szeredi 9843be5a52bSMiklos Szeredi void fuse_set_nowrite(struct inode *inode); 9853be5a52bSMiklos Szeredi void fuse_release_nowrite(struct inode *inode); 9865c5c5e51SMiklos Szeredi 9873b463ae0SJohn Muir /** 9883b463ae0SJohn Muir * File-system tells the kernel to invalidate cache for the given node id. 9893b463ae0SJohn Muir */ 9903b463ae0SJohn Muir int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 9913b463ae0SJohn Muir loff_t offset, loff_t len); 9923b463ae0SJohn Muir 9933b463ae0SJohn Muir /** 9943b463ae0SJohn Muir * File-system tells the kernel to invalidate parent attributes and 9953b463ae0SJohn Muir * the dentry matching parent/name. 996451d0f59SJohn Muir * 997451d0f59SJohn Muir * If the child_nodeid is non-zero and: 998451d0f59SJohn Muir * - matches the inode number for the dentry matching parent/name, 999451d0f59SJohn Muir * - is not a mount point 1000451d0f59SJohn Muir * - is a file or oan empty directory 1001451d0f59SJohn Muir * then the dentry is unhashed (d_delete()). 10023b463ae0SJohn Muir */ 10033b463ae0SJohn Muir int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 1004451d0f59SJohn Muir u64 child_nodeid, struct qstr *name); 10053b463ae0SJohn Muir 100608cbf542STejun Heo int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 100708cbf542STejun Heo bool isdir); 1008ea8cd333SPavel Emelyanov 1009ea8cd333SPavel Emelyanov /** 1010ea8cd333SPavel Emelyanov * fuse_direct_io() flags 1011ea8cd333SPavel Emelyanov */ 1012ea8cd333SPavel Emelyanov 1013ea8cd333SPavel Emelyanov /** If set, it is WRITE; otherwise - READ */ 1014ea8cd333SPavel Emelyanov #define FUSE_DIO_WRITE (1 << 0) 1015ea8cd333SPavel Emelyanov 1016ea8cd333SPavel Emelyanov /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1017ea8cd333SPavel Emelyanov #define FUSE_DIO_CUSE (1 << 1) 1018ea8cd333SPavel Emelyanov 1019d22a943fSAl Viro ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1020d22a943fSAl Viro loff_t *ppos, int flags); 102108cbf542STejun Heo long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 102208cbf542STejun Heo unsigned int flags); 1023b18da0c5SMiklos Szeredi long fuse_ioctl_common(struct file *file, unsigned int cmd, 1024b18da0c5SMiklos Szeredi unsigned long arg, unsigned int flags); 1025076ccb76SAl Viro __poll_t fuse_file_poll(struct file *file, poll_table *wait); 102608cbf542STejun Heo int fuse_dev_release(struct inode *inode, struct file *file); 102708cbf542STejun Heo 1028b0aa7606SMaxim Patlasov bool fuse_write_update_size(struct inode *inode, loff_t pos); 1029b0aa7606SMaxim Patlasov 1030ab9e13f7SMaxim Patlasov int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 10311e18bda8SMiklos Szeredi int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1032a1d75f25SMiklos Szeredi 103362490330SJan Kara int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1034efb9fa9eSMaxim Patlasov struct file *file); 1035efb9fa9eSMaxim Patlasov 10369759bd51SMiklos Szeredi void fuse_set_initialized(struct fuse_conn *fc); 10379759bd51SMiklos Szeredi 103863576c13SMiklos Szeredi void fuse_unlock_inode(struct inode *inode, bool locked); 103963576c13SMiklos Szeredi bool fuse_lock_inode(struct inode *inode); 10405c672ab3SMiklos Szeredi 104160bcc88aSSeth Forshee int fuse_setxattr(struct inode *inode, const char *name, const void *value, 104260bcc88aSSeth Forshee size_t size, int flags); 104360bcc88aSSeth Forshee ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 104460bcc88aSSeth Forshee size_t size); 1045703c7362SSeth Forshee ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 104660bcc88aSSeth Forshee int fuse_removexattr(struct inode *inode, const char *name); 1047703c7362SSeth Forshee extern const struct xattr_handler *fuse_xattr_handlers[]; 104860bcc88aSSeth Forshee extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 1049e45b2546SEric W. Biederman extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 105060bcc88aSSeth Forshee 105160bcc88aSSeth Forshee struct posix_acl; 105260bcc88aSSeth Forshee struct posix_acl *fuse_get_acl(struct inode *inode, int type); 105360bcc88aSSeth Forshee int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 1054703c7362SSeth Forshee 1055d123d8e1SMiklos Szeredi 1056d123d8e1SMiklos Szeredi /* readdir.c */ 1057d123d8e1SMiklos Szeredi int fuse_readdir(struct file *file, struct dir_context *ctx); 1058d123d8e1SMiklos Szeredi 105914d46d7aSStefan Hajnoczi /** 106014d46d7aSStefan Hajnoczi * Return the number of bytes in an arguments list 106114d46d7aSStefan Hajnoczi */ 106214d46d7aSStefan Hajnoczi unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args); 106314d46d7aSStefan Hajnoczi 106479d96effSStefan Hajnoczi /** 106579d96effSStefan Hajnoczi * Get the next unique ID for a request 106679d96effSStefan Hajnoczi */ 106779d96effSStefan Hajnoczi u64 fuse_get_unique(struct fuse_iqueue *fiq); 1068*783863d6SMiklos Szeredi void fuse_free_conn(struct fuse_conn *fc); 106979d96effSStefan Hajnoczi 107029d434b3STejun Heo #endif /* _FS_FUSE_I_H */ 1071