fuse_i.h 22 KB

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