fuse_i.h 23 KB

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