fuse_i.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. */
  7. #ifndef _FS_FUSE_I_H
  8. #define _FS_FUSE_I_H
  9. #include <linux/fuse.h>
  10. #include <linux/fs.h>
  11. #include <linux/mount.h>
  12. #include <linux/wait.h>
  13. #include <linux/list.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/mm.h>
  16. #include <linux/backing-dev.h>
  17. #include <linux/mutex.h>
  18. #include <linux/rwsem.h>
  19. #include <linux/rbtree.h>
  20. #include <linux/poll.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/kref.h>
  23. #include <linux/xattr.h>
  24. #include <linux/pid_namespace.h>
  25. #include <linux/refcount.h>
  26. #include <linux/user_namespace.h>
  27. /** Default max number of pages that can be used in a single read request */
  28. #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
  29. /** Maximum of max_pages received in init_out */
  30. #define FUSE_MAX_MAX_PAGES 256
  31. /** Bias for fi->writectr, meaning new writepages must not be sent */
  32. #define FUSE_NOWRITE INT_MIN
  33. /** It could be as large as PATH_MAX, but would that have any uses? */
  34. #define FUSE_NAME_MAX 1024
  35. /** Number of dentries for each connection in the control filesystem */
  36. #define FUSE_CTL_NUM_DENTRIES 5
  37. /** Number of page pointers embedded in fuse_req */
  38. #define FUSE_REQ_INLINE_PAGES 1
  39. /** List of active connections */
  40. extern struct list_head fuse_conn_list;
  41. /** Global mutex protecting fuse_conn_list and the control filesystem */
  42. extern struct mutex fuse_mutex;
  43. /** Module parameters */
  44. extern unsigned max_user_bgreq;
  45. extern unsigned max_user_congthresh;
  46. /* One forget request */
  47. struct fuse_forget_link {
  48. struct fuse_forget_one forget_one;
  49. struct fuse_forget_link *next;
  50. };
  51. /** FUSE inode */
  52. struct fuse_inode {
  53. /** Inode data */
  54. struct inode inode;
  55. /** Unique ID, which identifies the inode between userspace
  56. * and kernel */
  57. u64 nodeid;
  58. /** Number of lookups on this inode */
  59. u64 nlookup;
  60. /** The request used for sending the FORGET message */
  61. struct fuse_forget_link *forget;
  62. /** Time in jiffies until the file attributes are valid */
  63. u64 i_time;
  64. /* Which attributes are invalid */
  65. u32 inval_mask;
  66. /** The sticky bit in inode->i_mode may have been removed, so
  67. preserve the original mode */
  68. umode_t orig_i_mode;
  69. /** 64 bit inode number */
  70. u64 orig_ino;
  71. /** Version of last attribute change */
  72. u64 attr_version;
  73. union {
  74. /* Write related fields (regular file only) */
  75. struct {
  76. /* Files usable in writepage. Protected by fc->lock */
  77. struct list_head write_files;
  78. /* Writepages pending on truncate or fsync */
  79. struct list_head queued_writes;
  80. /* Number of sent writes, a negative bias
  81. * (FUSE_NOWRITE) means more writes are blocked */
  82. int writectr;
  83. /* Waitq for writepage completion */
  84. wait_queue_head_t page_waitq;
  85. /* List of writepage requestst (pending or sent) */
  86. struct list_head writepages;
  87. };
  88. /* readdir cache (directory only) */
  89. struct {
  90. /* true if fully cached */
  91. bool cached;
  92. /* size of cache */
  93. loff_t size;
  94. /* position at end of cache (position of next entry) */
  95. loff_t pos;
  96. /* version of the cache */
  97. u64 version;
  98. /* modification time of directory when cache was
  99. * started */
  100. struct timespec64 mtime;
  101. /* iversion of directory when cache was started */
  102. u64 iversion;
  103. /* protects above fields */
  104. spinlock_t lock;
  105. } rdc;
  106. };
  107. /** Miscellaneous bits describing inode state */
  108. unsigned long state;
  109. /** Lock for serializing lookup and readdir for back compatibility*/
  110. struct mutex mutex;
  111. };
  112. /** FUSE inode state bits */
  113. enum {
  114. /** Advise readdirplus */
  115. FUSE_I_ADVISE_RDPLUS,
  116. /** Initialized with readdirplus */
  117. FUSE_I_INIT_RDPLUS,
  118. /** An operation changing file size is in progress */
  119. FUSE_I_SIZE_UNSTABLE,
  120. };
  121. struct fuse_conn;
  122. /** FUSE specific file data */
  123. struct fuse_file {
  124. /** Fuse connection for this file */
  125. struct fuse_conn *fc;
  126. /** Request reserved for flush and release */
  127. struct fuse_req *reserved_req;
  128. /** Kernel file handle guaranteed to be unique */
  129. u64 kh;
  130. /** File handle used by userspace */
  131. u64 fh;
  132. /** Node id of this file */
  133. u64 nodeid;
  134. /** Refcount */
  135. refcount_t count;
  136. /** FOPEN_* flags returned by open */
  137. u32 open_flags;
  138. /** Entry on inode's write_files list */
  139. struct list_head write_entry;
  140. /* Readdir related */
  141. struct {
  142. /*
  143. * Protects below fields against (crazy) parallel readdir on
  144. * same open file. Uncontended in the normal case.
  145. */
  146. struct mutex lock;
  147. /* Dir stream position */
  148. loff_t pos;
  149. /* Offset in cache */
  150. loff_t cache_off;
  151. /* Version of cache we are reading */
  152. u64 version;
  153. } readdir;
  154. /** RB node to be linked on fuse_conn->polled_files */
  155. struct rb_node polled_node;
  156. /** Wait queue head for poll */
  157. wait_queue_head_t poll_wait;
  158. /** Has flock been performed on this file? */
  159. bool flock:1;
  160. };
  161. /** One input argument of a request */
  162. struct fuse_in_arg {
  163. unsigned size;
  164. const void *value;
  165. };
  166. /** The request input */
  167. struct fuse_in {
  168. /** The request header */
  169. struct fuse_in_header h;
  170. /** True if the data for the last argument is in req->pages */
  171. unsigned argpages:1;
  172. /** Number of arguments */
  173. unsigned numargs;
  174. /** Array of arguments */
  175. struct fuse_in_arg args[3];
  176. };
  177. /** One output argument of a request */
  178. struct fuse_arg {
  179. unsigned size;
  180. void *value;
  181. };
  182. /** The request output */
  183. struct fuse_out {
  184. /** Header returned from userspace */
  185. struct fuse_out_header h;
  186. /*
  187. * The following bitfields are not changed during the request
  188. * processing
  189. */
  190. /** Last argument is variable length (can be shorter than
  191. arg->size) */
  192. unsigned argvar:1;
  193. /** Last argument is a list of pages to copy data to */
  194. unsigned argpages:1;
  195. /** Zero partially or not copied pages */
  196. unsigned page_zeroing:1;
  197. /** Pages may be replaced with new ones */
  198. unsigned page_replace:1;
  199. /** Number or arguments */
  200. unsigned numargs;
  201. /** Array of arguments */
  202. struct fuse_arg args[2];
  203. };
  204. /** FUSE page descriptor */
  205. struct fuse_page_desc {
  206. unsigned int length;
  207. unsigned int offset;
  208. };
  209. struct fuse_args {
  210. struct {
  211. struct {
  212. uint32_t opcode;
  213. uint64_t nodeid;
  214. } h;
  215. unsigned numargs;
  216. struct fuse_in_arg args[3];
  217. } in;
  218. struct {
  219. unsigned argvar:1;
  220. unsigned numargs;
  221. struct fuse_arg args[2];
  222. } out;
  223. };
  224. #define FUSE_ARGS(args) struct fuse_args args = {}
  225. /** The request IO state (for asynchronous processing) */
  226. struct fuse_io_priv {
  227. struct kref refcnt;
  228. int async;
  229. spinlock_t lock;
  230. unsigned reqs;
  231. ssize_t bytes;
  232. size_t size;
  233. __u64 offset;
  234. bool write;
  235. bool should_dirty;
  236. int err;
  237. struct kiocb *iocb;
  238. struct completion *done;
  239. bool blocking;
  240. };
  241. #define FUSE_IO_PRIV_SYNC(i) \
  242. { \
  243. .refcnt = KREF_INIT(1), \
  244. .async = 0, \
  245. .iocb = i, \
  246. }
  247. /**
  248. * Request flags
  249. *
  250. * FR_ISREPLY: set if the request has reply
  251. * FR_FORCE: force sending of the request even if interrupted
  252. * FR_BACKGROUND: request is sent in the background
  253. * FR_WAITING: request is counted as "waiting"
  254. * FR_ABORTED: the request was aborted
  255. * FR_INTERRUPTED: the request has been interrupted
  256. * FR_LOCKED: data is being copied to/from the request
  257. * FR_PENDING: request is not yet in userspace
  258. * FR_SENT: request is in userspace, waiting for an answer
  259. * FR_FINISHED: request is finished
  260. * FR_PRIVATE: request is on private list
  261. */
  262. enum fuse_req_flag {
  263. FR_ISREPLY,
  264. FR_FORCE,
  265. FR_BACKGROUND,
  266. FR_WAITING,
  267. FR_ABORTED,
  268. FR_INTERRUPTED,
  269. FR_LOCKED,
  270. FR_PENDING,
  271. FR_SENT,
  272. FR_FINISHED,
  273. FR_PRIVATE,
  274. };
  275. /**
  276. * A request to the client
  277. *
  278. * .waitq.lock protects the following fields:
  279. * - FR_ABORTED
  280. * - FR_LOCKED (may also be modified under fc->lock, tested under both)
  281. */
  282. struct fuse_req {
  283. /** This can be on either pending processing or io lists in
  284. fuse_conn */
  285. struct list_head list;
  286. /** Entry on the interrupts list */
  287. struct list_head intr_entry;
  288. /** refcount */
  289. refcount_t count;
  290. /* Request flags, updated with test/set/clear_bit() */
  291. unsigned long flags;
  292. /** The request input */
  293. struct fuse_in in;
  294. /** The request output */
  295. struct fuse_out out;
  296. /** Used to wake up the task waiting for completion of request*/
  297. wait_queue_head_t waitq;
  298. /** Data for asynchronous requests */
  299. union {
  300. struct {
  301. struct fuse_release_in in;
  302. struct inode *inode;
  303. } release;
  304. struct fuse_init_in init_in;
  305. struct fuse_init_out init_out;
  306. struct cuse_init_in cuse_init_in;
  307. struct {
  308. struct fuse_read_in in;
  309. u64 attr_ver;
  310. } read;
  311. struct {
  312. struct fuse_write_in in;
  313. struct fuse_write_out out;
  314. struct fuse_req *next;
  315. } write;
  316. struct fuse_notify_retrieve_in retrieve_in;
  317. } misc;
  318. /** page vector */
  319. struct page **pages;
  320. /** page-descriptor vector */
  321. struct fuse_page_desc *page_descs;
  322. /** size of the 'pages' array */
  323. unsigned max_pages;
  324. /** inline page vector */
  325. struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
  326. /** inline page-descriptor vector */
  327. struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
  328. /** number of pages in vector */
  329. unsigned num_pages;
  330. /** File used in the request (or NULL) */
  331. struct fuse_file *ff;
  332. /** Inode used in the request or NULL */
  333. struct inode *inode;
  334. /** AIO control block */
  335. struct fuse_io_priv *io;
  336. /** Link on fi->writepages */
  337. struct list_head writepages_entry;
  338. /** Request completion callback */
  339. void (*end)(struct fuse_conn *, struct fuse_req *);
  340. /** Request is stolen from fuse_file->reserved_req */
  341. struct file *stolen_file;
  342. };
  343. struct fuse_iqueue {
  344. /** Connection established */
  345. unsigned connected;
  346. /** Readers of the connection are waiting on this */
  347. wait_queue_head_t waitq;
  348. /** The next unique request id */
  349. u64 reqctr;
  350. /** The list of pending requests */
  351. struct list_head pending;
  352. /** Pending interrupts */
  353. struct list_head interrupts;
  354. /** Queue of pending forgets */
  355. struct fuse_forget_link forget_list_head;
  356. struct fuse_forget_link *forget_list_tail;
  357. /** Batching of FORGET requests (positive indicates FORGET batch) */
  358. int forget_batch;
  359. /** O_ASYNC requests */
  360. struct fasync_struct *fasync;
  361. };
  362. #define FUSE_PQ_HASH_BITS 8
  363. #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
  364. struct fuse_pqueue {
  365. /** Connection established */
  366. unsigned connected;
  367. /** Lock protecting accessess to members of this structure */
  368. spinlock_t lock;
  369. /** Hash table of requests being processed */
  370. struct list_head *processing;
  371. /** The list of requests under I/O */
  372. struct list_head io;
  373. };
  374. /**
  375. * Fuse device instance
  376. */
  377. struct fuse_dev {
  378. /** Fuse connection for this device */
  379. struct fuse_conn *fc;
  380. /** Processing queue */
  381. struct fuse_pqueue pq;
  382. /** list entry on fc->devices */
  383. struct list_head entry;
  384. };
  385. /**
  386. * A Fuse connection.
  387. *
  388. * This structure is created, when the filesystem is mounted, and is
  389. * destroyed, when the client device is closed and the filesystem is
  390. * unmounted.
  391. */
  392. struct fuse_conn {
  393. /** Lock protecting accessess to members of this structure */
  394. spinlock_t lock;
  395. /** Refcount */
  396. refcount_t count;
  397. /** Number of fuse_dev's */
  398. atomic_t dev_count;
  399. struct rcu_head rcu;
  400. /** The user id for this mount */
  401. kuid_t user_id;
  402. /** The group id for this mount */
  403. kgid_t group_id;
  404. /** The pid namespace for this mount */
  405. struct pid_namespace *pid_ns;
  406. /** The user namespace for this mount */
  407. struct user_namespace *user_ns;
  408. /** Maximum read size */
  409. unsigned max_read;
  410. /** Maximum write size */
  411. unsigned max_write;
  412. /** Maxmum number of pages that can be used in a single request */
  413. unsigned int max_pages;
  414. /** Input queue */
  415. struct fuse_iqueue iq;
  416. /** The next unique kernel file handle */
  417. u64 khctr;
  418. /** rbtree of fuse_files waiting for poll events indexed by ph */
  419. struct rb_root polled_files;
  420. /** Maximum number of outstanding background requests */
  421. unsigned max_background;
  422. /** Number of background requests at which congestion starts */
  423. unsigned congestion_threshold;
  424. /** Number of requests currently in the background */
  425. unsigned num_background;
  426. /** Number of background requests currently queued for userspace */
  427. unsigned active_background;
  428. /** The list of background requests set aside for later queuing */
  429. struct list_head bg_queue;
  430. /** Protects: max_background, congestion_threshold, num_background,
  431. * active_background, bg_queue, blocked */
  432. spinlock_t bg_lock;
  433. /** Flag indicating that INIT reply has been received. Allocating
  434. * any fuse request will be suspended until the flag is set */
  435. int initialized;
  436. /** Flag indicating if connection is blocked. This will be
  437. the case before the INIT reply is received, and if there
  438. are too many outstading backgrounds requests */
  439. int blocked;
  440. /** waitq for blocked connection */
  441. wait_queue_head_t blocked_waitq;
  442. /** waitq for reserved requests */
  443. wait_queue_head_t reserved_req_waitq;
  444. /** Connection established, cleared on umount, connection
  445. abort and device release */
  446. unsigned connected;
  447. /** Connection aborted via sysfs */
  448. bool aborted;
  449. /** Connection failed (version mismatch). Cannot race with
  450. setting other bitfields since it is only set once in INIT
  451. reply, before any other request, and never cleared */
  452. unsigned conn_error:1;
  453. /** Connection successful. Only set in INIT */
  454. unsigned conn_init:1;
  455. /** Do readpages asynchronously? Only set in INIT */
  456. unsigned async_read:1;
  457. /** Return an unique read error after abort. Only set in INIT */
  458. unsigned abort_err:1;
  459. /** Do not send separate SETATTR request before open(O_TRUNC) */
  460. unsigned atomic_o_trunc:1;
  461. /** Filesystem supports NFS exporting. Only set in INIT */
  462. unsigned export_support:1;
  463. /** write-back cache policy (default is write-through) */
  464. unsigned writeback_cache:1;
  465. /** allow parallel lookups and readdir (default is serialized) */
  466. unsigned parallel_dirops:1;
  467. /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
  468. unsigned handle_killpriv:1;
  469. /** cache READLINK responses in page cache */
  470. unsigned cache_symlinks:1;
  471. /*
  472. * The following bitfields are only for optimization purposes
  473. * and hence races in setting them will not cause malfunction
  474. */
  475. /** Is open/release not implemented by fs? */
  476. unsigned no_open:1;
  477. /** Is fsync not implemented by fs? */
  478. unsigned no_fsync:1;
  479. /** Is fsyncdir not implemented by fs? */
  480. unsigned no_fsyncdir:1;
  481. /** Is flush not implemented by fs? */
  482. unsigned no_flush:1;
  483. /** Is setxattr not implemented by fs? */
  484. unsigned no_setxattr:1;
  485. /** Is getxattr not implemented by fs? */
  486. unsigned no_getxattr:1;
  487. /** Is listxattr not implemented by fs? */
  488. unsigned no_listxattr:1;
  489. /** Is removexattr not implemented by fs? */
  490. unsigned no_removexattr:1;
  491. /** Are posix file locking primitives not implemented by fs? */
  492. unsigned no_lock:1;
  493. /** Is access not implemented by fs? */
  494. unsigned no_access:1;
  495. /** Is create not implemented by fs? */
  496. unsigned no_create:1;
  497. /** Is interrupt not implemented by fs? */
  498. unsigned no_interrupt:1;
  499. /** Is bmap not implemented by fs? */
  500. unsigned no_bmap:1;
  501. /** Is poll not implemented by fs? */
  502. unsigned no_poll:1;
  503. /** Do multi-page cached writes */
  504. unsigned big_writes:1;
  505. /** Don't apply umask to creation modes */
  506. unsigned dont_mask:1;
  507. /** Are BSD file locking primitives not implemented by fs? */
  508. unsigned no_flock:1;
  509. /** Is fallocate not implemented by fs? */
  510. unsigned no_fallocate:1;
  511. /** Is rename with flags implemented by fs? */
  512. unsigned no_rename2:1;
  513. /** Use enhanced/automatic page cache invalidation. */
  514. unsigned auto_inval_data:1;
  515. /** Does the filesystem support readdirplus? */
  516. unsigned do_readdirplus:1;
  517. /** Does the filesystem want adaptive readdirplus? */
  518. unsigned readdirplus_auto:1;
  519. /** Does the filesystem support asynchronous direct-IO submission? */
  520. unsigned async_dio:1;
  521. /** Is lseek not implemented by fs? */
  522. unsigned no_lseek:1;
  523. /** Does the filesystem support posix acls? */
  524. unsigned posix_acl:1;
  525. /** Check permissions based on the file mode or not? */
  526. unsigned default_permissions:1;
  527. /** Allow other than the mounter user to access the filesystem ? */
  528. unsigned allow_other:1;
  529. /** Does the filesystem support copy_file_range? */
  530. unsigned no_copy_file_range:1;
  531. /** The number of requests waiting for completion */
  532. atomic_t num_waiting;
  533. /** Negotiated minor version */
  534. unsigned minor;
  535. /** Entry on the fuse_conn_list */
  536. struct list_head entry;
  537. /** Device ID from super block */
  538. dev_t dev;
  539. /** Dentries in the control filesystem */
  540. struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
  541. /** number of dentries used in the above array */
  542. int ctl_ndents;
  543. /** Key for lock owner ID scrambling */
  544. u32 scramble_key[4];
  545. /** Reserved request for the DESTROY message */
  546. struct fuse_req *destroy_req;
  547. /** Version counter for attribute changes */
  548. u64 attr_version;
  549. /** Called on final put */
  550. void (*release)(struct fuse_conn *);
  551. /** Super block for this connection. */
  552. struct super_block *sb;
  553. /** Read/write semaphore to hold when accessing sb. */
  554. struct rw_semaphore killsb;
  555. /** List of device instances belonging to this connection */
  556. struct list_head devices;
  557. };
  558. static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
  559. {
  560. return sb->s_fs_info;
  561. }
  562. static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
  563. {
  564. return get_fuse_conn_super(inode->i_sb);
  565. }
  566. static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
  567. {
  568. return container_of(inode, struct fuse_inode, inode);
  569. }
  570. static inline u64 get_node_id(struct inode *inode)
  571. {
  572. return get_fuse_inode(inode)->nodeid;
  573. }
  574. static inline int invalid_nodeid(u64 nodeid)
  575. {
  576. return !nodeid || nodeid == FUSE_ROOT_ID;
  577. }
  578. /** Device operations */
  579. extern const struct file_operations fuse_dev_operations;
  580. extern const struct dentry_operations fuse_dentry_operations;
  581. extern const struct dentry_operations fuse_root_dentry_operations;
  582. /**
  583. * Inode to nodeid comparison.
  584. */
  585. int fuse_inode_eq(struct inode *inode, void *_nodeidp);
  586. /**
  587. * Get a filled in inode
  588. */
  589. struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
  590. int generation, struct fuse_attr *attr,
  591. u64 attr_valid, u64 attr_version);
  592. int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
  593. struct fuse_entry_out *outarg, struct inode **inode);
  594. /**
  595. * Send FORGET command
  596. */
  597. void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
  598. u64 nodeid, u64 nlookup);
  599. struct fuse_forget_link *fuse_alloc_forget(void);
  600. /* Used by READDIRPLUS */
  601. void fuse_force_forget(struct file *file, u64 nodeid);
  602. /**
  603. * Initialize READ or READDIR request
  604. */
  605. void fuse_read_fill(struct fuse_req *req, struct file *file,
  606. loff_t pos, size_t count, int opcode);
  607. /**
  608. * Send OPEN or OPENDIR request
  609. */
  610. int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
  611. struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
  612. void fuse_file_free(struct fuse_file *ff);
  613. void fuse_finish_open(struct inode *inode, struct file *file);
  614. void fuse_sync_release(struct fuse_file *ff, int flags);
  615. /**
  616. * Send RELEASE or RELEASEDIR request
  617. */
  618. void fuse_release_common(struct file *file, bool isdir);
  619. /**
  620. * Send FSYNC or FSYNCDIR request
  621. */
  622. int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
  623. int datasync, int opcode);
  624. /**
  625. * Notify poll wakeup
  626. */
  627. int fuse_notify_poll_wakeup(struct fuse_conn *fc,
  628. struct fuse_notify_poll_wakeup_out *outarg);
  629. /**
  630. * Initialize file operations on a regular file
  631. */
  632. void fuse_init_file_inode(struct inode *inode);
  633. /**
  634. * Initialize inode operations on regular files and special files
  635. */
  636. void fuse_init_common(struct inode *inode);
  637. /**
  638. * Initialize inode and file operations on a directory
  639. */
  640. void fuse_init_dir(struct inode *inode);
  641. /**
  642. * Initialize inode operations on a symlink
  643. */
  644. void fuse_init_symlink(struct inode *inode);
  645. /**
  646. * Change attributes of an inode
  647. */
  648. void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
  649. u64 attr_valid, u64 attr_version);
  650. void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
  651. u64 attr_valid);
  652. /**
  653. * Initialize the client device
  654. */
  655. int fuse_dev_init(void);
  656. /**
  657. * Cleanup the client device
  658. */
  659. void fuse_dev_cleanup(void);
  660. int fuse_ctl_init(void);
  661. void __exit fuse_ctl_cleanup(void);
  662. /**
  663. * Allocate a request
  664. */
  665. struct fuse_req *fuse_request_alloc(unsigned npages);
  666. struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
  667. bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req,
  668. gfp_t flags);
  669. /**
  670. * Free a request
  671. */
  672. void fuse_request_free(struct fuse_req *req);
  673. /**
  674. * Get a request, may fail with -ENOMEM,
  675. * caller should specify # elements in req->pages[] explicitly
  676. */
  677. struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
  678. struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
  679. unsigned npages);
  680. /*
  681. * Increment reference count on request
  682. */
  683. void __fuse_get_request(struct fuse_req *req);
  684. /**
  685. * Gets a requests for a file operation, always succeeds
  686. */
  687. struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
  688. struct file *file);
  689. /**
  690. * Decrement reference count of a request. If count goes to zero free
  691. * the request.
  692. */
  693. void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
  694. /**
  695. * Send a request (synchronous)
  696. */
  697. void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
  698. /**
  699. * Simple request sending that does request allocation and freeing
  700. */
  701. ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
  702. /**
  703. * Send a request in the background
  704. */
  705. void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
  706. bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
  707. /* Abort all requests */
  708. void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);
  709. void fuse_wait_aborted(struct fuse_conn *fc);
  710. /**
  711. * Invalidate inode attributes
  712. */
  713. void fuse_invalidate_attr(struct inode *inode);
  714. void fuse_invalidate_entry_cache(struct dentry *entry);
  715. void fuse_invalidate_atime(struct inode *inode);
  716. u64 entry_attr_timeout(struct fuse_entry_out *o);
  717. void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
  718. /**
  719. * Acquire reference to fuse_conn
  720. */
  721. struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
  722. /**
  723. * Initialize fuse_conn
  724. */
  725. void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
  726. /**
  727. * Release reference to fuse_conn
  728. */
  729. void fuse_conn_put(struct fuse_conn *fc);
  730. struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
  731. void fuse_dev_free(struct fuse_dev *fud);
  732. /**
  733. * Add connection to control filesystem
  734. */
  735. int fuse_ctl_add_conn(struct fuse_conn *fc);
  736. /**
  737. * Remove connection from control filesystem
  738. */
  739. void fuse_ctl_remove_conn(struct fuse_conn *fc);
  740. /**
  741. * Is file type valid?
  742. */
  743. int fuse_valid_type(int m);
  744. /**
  745. * Is current process allowed to perform filesystem operation?
  746. */
  747. int fuse_allow_current_process(struct fuse_conn *fc);
  748. u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
  749. void fuse_update_ctime(struct inode *inode);
  750. int fuse_update_attributes(struct inode *inode, struct file *file);
  751. void fuse_flush_writepages(struct inode *inode);
  752. void fuse_set_nowrite(struct inode *inode);
  753. void fuse_release_nowrite(struct inode *inode);
  754. u64 fuse_get_attr_version(struct fuse_conn *fc);
  755. /**
  756. * File-system tells the kernel to invalidate cache for the given node id.
  757. */
  758. int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
  759. loff_t offset, loff_t len);
  760. /**
  761. * File-system tells the kernel to invalidate parent attributes and
  762. * the dentry matching parent/name.
  763. *
  764. * If the child_nodeid is non-zero and:
  765. * - matches the inode number for the dentry matching parent/name,
  766. * - is not a mount point
  767. * - is a file or oan empty directory
  768. * then the dentry is unhashed (d_delete()).
  769. */
  770. int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
  771. u64 child_nodeid, struct qstr *name);
  772. int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
  773. bool isdir);
  774. /**
  775. * fuse_direct_io() flags
  776. */
  777. /** If set, it is WRITE; otherwise - READ */
  778. #define FUSE_DIO_WRITE (1 << 0)
  779. /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
  780. #define FUSE_DIO_CUSE (1 << 1)
  781. ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  782. loff_t *ppos, int flags);
  783. long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
  784. unsigned int flags);
  785. long fuse_ioctl_common(struct file *file, unsigned int cmd,
  786. unsigned long arg, unsigned int flags);
  787. __poll_t fuse_file_poll(struct file *file, poll_table *wait);
  788. int fuse_dev_release(struct inode *inode, struct file *file);
  789. bool fuse_write_update_size(struct inode *inode, loff_t pos);
  790. int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
  791. int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
  792. int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
  793. struct file *file);
  794. void fuse_set_initialized(struct fuse_conn *fc);
  795. void fuse_unlock_inode(struct inode *inode, bool locked);
  796. bool fuse_lock_inode(struct inode *inode);
  797. int fuse_setxattr(struct inode *inode, const char *name, const void *value,
  798. size_t size, int flags);
  799. ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
  800. size_t size);
  801. ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
  802. int fuse_removexattr(struct inode *inode, const char *name);
  803. extern const struct xattr_handler *fuse_xattr_handlers[];
  804. extern const struct xattr_handler *fuse_acl_xattr_handlers[];
  805. extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
  806. struct posix_acl;
  807. struct posix_acl *fuse_get_acl(struct inode *inode, int type);
  808. int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
  809. /* readdir.c */
  810. int fuse_readdir(struct file *file, struct dir_context *ctx);
  811. #endif /* _FS_FUSE_I_H */