fuse_i.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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. #ifndef pr_fmt
  10. # define pr_fmt(fmt) "fuse: " fmt
  11. #endif
  12. #include <linux/fuse.h>
  13. #include <linux/fs.h>
  14. #include <linux/mount.h>
  15. #include <linux/wait.h>
  16. #include <linux/list.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/mm.h>
  19. #include <linux/backing-dev.h>
  20. #include <linux/mutex.h>
  21. #include <linux/rwsem.h>
  22. #include <linux/rbtree.h>
  23. #include <linux/poll.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/kref.h>
  26. #include <linux/xattr.h>
  27. #include <linux/pid_namespace.h>
  28. #include <linux/refcount.h>
  29. #include <linux/user_namespace.h>
  30. /** Default max number of pages that can be used in a single read request */
  31. #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
  32. /** Maximum of max_pages received in init_out */
  33. #define FUSE_MAX_MAX_PAGES 256
  34. /** Bias for fi->writectr, meaning new writepages must not be sent */
  35. #define FUSE_NOWRITE INT_MIN
  36. /** It could be as large as PATH_MAX, but would that have any uses? */
  37. #define FUSE_NAME_MAX 1024
  38. /** Number of dentries for each connection in the control filesystem */
  39. #define FUSE_CTL_NUM_DENTRIES 5
  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. /* Which attributes are invalid */
  66. u32 inval_mask;
  67. /** The sticky bit in inode->i_mode may have been removed, so
  68. preserve the original mode */
  69. umode_t orig_i_mode;
  70. /** 64 bit inode number */
  71. u64 orig_ino;
  72. /** Version of last attribute change */
  73. u64 attr_version;
  74. union {
  75. /* Write related fields (regular file only) */
  76. struct {
  77. /* Files usable in writepage. Protected by fi->lock */
  78. struct list_head write_files;
  79. /* Writepages pending on truncate or fsync */
  80. struct list_head queued_writes;
  81. /* Number of sent writes, a negative bias
  82. * (FUSE_NOWRITE) means more writes are blocked */
  83. int writectr;
  84. /* Waitq for writepage completion */
  85. wait_queue_head_t page_waitq;
  86. /* List of writepage requestst (pending or sent) */
  87. struct rb_root writepages;
  88. };
  89. /* readdir cache (directory only) */
  90. struct {
  91. /* true if fully cached */
  92. bool cached;
  93. /* size of cache */
  94. loff_t size;
  95. /* position at end of cache (position of next entry) */
  96. loff_t pos;
  97. /* version of the cache */
  98. u64 version;
  99. /* modification time of directory when cache was
  100. * started */
  101. struct timespec64 mtime;
  102. /* iversion of directory when cache was started */
  103. u64 iversion;
  104. /* protects above fields */
  105. spinlock_t lock;
  106. } rdc;
  107. };
  108. /** Miscellaneous bits describing inode state */
  109. unsigned long state;
  110. /** Lock for serializing lookup and readdir for back compatibility*/
  111. struct mutex mutex;
  112. /** Lock to protect write related fields */
  113. spinlock_t lock;
  114. /**
  115. * Can't take inode lock in fault path (leads to circular dependency).
  116. * Introduce another semaphore which can be taken in fault path and
  117. * then other filesystem paths can take this to block faults.
  118. */
  119. struct rw_semaphore i_mmap_sem;
  120. #ifdef CONFIG_FUSE_DAX
  121. /*
  122. * Dax specific inode data
  123. */
  124. struct fuse_inode_dax *dax;
  125. #endif
  126. };
  127. /** FUSE inode state bits */
  128. enum {
  129. /** Advise readdirplus */
  130. FUSE_I_ADVISE_RDPLUS,
  131. /** Initialized with readdirplus */
  132. FUSE_I_INIT_RDPLUS,
  133. /** An operation changing file size is in progress */
  134. FUSE_I_SIZE_UNSTABLE,
  135. /* Bad inode */
  136. FUSE_I_BAD,
  137. };
  138. struct fuse_conn;
  139. struct fuse_mount;
  140. struct fuse_release_args;
  141. /**
  142. * Reference to lower filesystem file for read/write operations handled in
  143. * passthrough mode.
  144. * This struct also tracks the credentials to be used for handling read/write
  145. * operations.
  146. */
  147. struct fuse_passthrough {
  148. struct file *filp;
  149. struct cred *cred;
  150. };
  151. /** FUSE specific file data */
  152. struct fuse_file {
  153. /** Fuse connection for this file */
  154. struct fuse_mount *fm;
  155. /* Argument space reserved for release */
  156. struct fuse_release_args *release_args;
  157. /** Kernel file handle guaranteed to be unique */
  158. u64 kh;
  159. /** File handle used by userspace */
  160. u64 fh;
  161. /** Node id of this file */
  162. u64 nodeid;
  163. /** Refcount */
  164. refcount_t count;
  165. /** FOPEN_* flags returned by open */
  166. u32 open_flags;
  167. /** Entry on inode's write_files list */
  168. struct list_head write_entry;
  169. /* Readdir related */
  170. struct {
  171. /*
  172. * Protects below fields against (crazy) parallel readdir on
  173. * same open file. Uncontended in the normal case.
  174. */
  175. struct mutex lock;
  176. /* Dir stream position */
  177. loff_t pos;
  178. /* Offset in cache */
  179. loff_t cache_off;
  180. /* Version of cache we are reading */
  181. u64 version;
  182. } readdir;
  183. /** Container for data related to the passthrough functionality */
  184. struct fuse_passthrough passthrough;
  185. /** RB node to be linked on fuse_conn->polled_files */
  186. struct rb_node polled_node;
  187. /** Wait queue head for poll */
  188. wait_queue_head_t poll_wait;
  189. /** Has flock been performed on this file? */
  190. bool flock:1;
  191. };
  192. /** One input argument of a request */
  193. struct fuse_in_arg {
  194. unsigned size;
  195. const void *value;
  196. };
  197. /** One output argument of a request */
  198. struct fuse_arg {
  199. unsigned size;
  200. void *value;
  201. };
  202. /** FUSE page descriptor */
  203. struct fuse_page_desc {
  204. unsigned int length;
  205. unsigned int offset;
  206. };
  207. struct fuse_args {
  208. uint64_t nodeid;
  209. uint32_t opcode;
  210. unsigned short in_numargs;
  211. unsigned short out_numargs;
  212. bool force:1;
  213. bool noreply:1;
  214. bool nocreds:1;
  215. bool in_pages:1;
  216. bool out_pages:1;
  217. bool user_pages:1;
  218. bool out_argvar:1;
  219. bool page_zeroing:1;
  220. bool page_replace:1;
  221. bool may_block:1;
  222. struct fuse_in_arg in_args[3];
  223. struct fuse_arg out_args[2];
  224. void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error);
  225. /* Path used for completing d_canonical_path */
  226. struct path *canonical_path;
  227. };
  228. struct fuse_args_pages {
  229. struct fuse_args args;
  230. struct page **pages;
  231. struct fuse_page_desc *descs;
  232. unsigned int num_pages;
  233. };
  234. #define FUSE_ARGS(args) struct fuse_args args = {}
  235. /** The request IO state (for asynchronous processing) */
  236. struct fuse_io_priv {
  237. struct kref refcnt;
  238. int async;
  239. spinlock_t lock;
  240. unsigned reqs;
  241. ssize_t bytes;
  242. size_t size;
  243. __u64 offset;
  244. bool write;
  245. bool should_dirty;
  246. int err;
  247. struct kiocb *iocb;
  248. struct completion *done;
  249. bool blocking;
  250. };
  251. #define FUSE_IO_PRIV_SYNC(i) \
  252. { \
  253. .refcnt = KREF_INIT(1), \
  254. .async = 0, \
  255. .iocb = i, \
  256. }
  257. /**
  258. * Request flags
  259. *
  260. * FR_ISREPLY: set if the request has reply
  261. * FR_FORCE: force sending of the request even if interrupted
  262. * FR_BACKGROUND: request is sent in the background
  263. * FR_WAITING: request is counted as "waiting"
  264. * FR_ABORTED: the request was aborted
  265. * FR_INTERRUPTED: the request has been interrupted
  266. * FR_LOCKED: data is being copied to/from the request
  267. * FR_PENDING: request is not yet in userspace
  268. * FR_SENT: request is in userspace, waiting for an answer
  269. * FR_FINISHED: request is finished
  270. * FR_PRIVATE: request is on private list
  271. * FR_ASYNC: request is asynchronous
  272. */
  273. enum fuse_req_flag {
  274. FR_ISREPLY,
  275. FR_FORCE,
  276. FR_BACKGROUND,
  277. FR_WAITING,
  278. FR_ABORTED,
  279. FR_INTERRUPTED,
  280. FR_LOCKED,
  281. FR_PENDING,
  282. FR_SENT,
  283. FR_FINISHED,
  284. FR_PRIVATE,
  285. FR_ASYNC,
  286. };
  287. /**
  288. * A request to the client
  289. *
  290. * .waitq.lock protects the following fields:
  291. * - FR_ABORTED
  292. * - FR_LOCKED (may also be modified under fc->lock, tested under both)
  293. */
  294. struct fuse_req {
  295. /** This can be on either pending processing or io lists in
  296. fuse_conn */
  297. struct list_head list;
  298. /** Entry on the interrupts list */
  299. struct list_head intr_entry;
  300. /* Input/output arguments */
  301. struct fuse_args *args;
  302. /** refcount */
  303. refcount_t count;
  304. /* Request flags, updated with test/set/clear_bit() */
  305. unsigned long flags;
  306. /* The request input header */
  307. struct {
  308. struct fuse_in_header h;
  309. } in;
  310. /* The request output header */
  311. struct {
  312. struct fuse_out_header h;
  313. } out;
  314. /** Used to wake up the task waiting for completion of request*/
  315. wait_queue_head_t waitq;
  316. /** virtio-fs's physically contiguous buffer for in and out args */
  317. void *argbuf;
  318. /** fuse_mount this request belongs to */
  319. struct fuse_mount *fm;
  320. };
  321. struct fuse_iqueue;
  322. /**
  323. * Input queue callbacks
  324. *
  325. * Input queue signalling is device-specific. For example, the /dev/fuse file
  326. * uses fiq->waitq and fasync to wake processes that are waiting on queue
  327. * readiness. These callbacks allow other device types to respond to input
  328. * queue activity.
  329. */
  330. struct fuse_iqueue_ops {
  331. /**
  332. * Signal that a forget has been queued
  333. */
  334. void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
  335. __releases(fiq->lock);
  336. /**
  337. * Signal that an INTERRUPT request has been queued
  338. */
  339. void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
  340. __releases(fiq->lock);
  341. /**
  342. * Signal that a request has been queued
  343. */
  344. void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
  345. __releases(fiq->lock);
  346. /**
  347. * Clean up when fuse_iqueue is destroyed
  348. */
  349. void (*release)(struct fuse_iqueue *fiq);
  350. };
  351. /** /dev/fuse input queue operations */
  352. extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
  353. struct fuse_iqueue {
  354. /** Connection established */
  355. unsigned connected;
  356. /** Lock protecting accesses to members of this structure */
  357. spinlock_t lock;
  358. /** Readers of the connection are waiting on this */
  359. wait_queue_head_t waitq;
  360. /** The next unique request id */
  361. u64 reqctr;
  362. /** The list of pending requests */
  363. struct list_head pending;
  364. /** Pending interrupts */
  365. struct list_head interrupts;
  366. /** Queue of pending forgets */
  367. struct fuse_forget_link forget_list_head;
  368. struct fuse_forget_link *forget_list_tail;
  369. /** Batching of FORGET requests (positive indicates FORGET batch) */
  370. int forget_batch;
  371. /** O_ASYNC requests */
  372. struct fasync_struct *fasync;
  373. /** Device-specific callbacks */
  374. const struct fuse_iqueue_ops *ops;
  375. /** Device-specific state */
  376. void *priv;
  377. };
  378. #define FUSE_PQ_HASH_BITS 8
  379. #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
  380. struct fuse_pqueue {
  381. /** Connection established */
  382. unsigned connected;
  383. /** Lock protecting accessess to members of this structure */
  384. spinlock_t lock;
  385. /** Hash table of requests being processed */
  386. struct list_head *processing;
  387. /** The list of requests under I/O */
  388. struct list_head io;
  389. };
  390. /**
  391. * Fuse device instance
  392. */
  393. struct fuse_dev {
  394. /** Fuse connection for this device */
  395. struct fuse_conn *fc;
  396. /** Processing queue */
  397. struct fuse_pqueue pq;
  398. /** list entry on fc->devices */
  399. struct list_head entry;
  400. };
  401. struct fuse_fs_context {
  402. int fd;
  403. unsigned int rootmode;
  404. kuid_t user_id;
  405. kgid_t group_id;
  406. bool is_bdev:1;
  407. bool fd_present:1;
  408. bool rootmode_present:1;
  409. bool user_id_present:1;
  410. bool group_id_present:1;
  411. bool default_permissions:1;
  412. bool allow_other:1;
  413. bool destroy:1;
  414. bool no_control:1;
  415. bool no_force_umount:1;
  416. bool legacy_opts_show:1;
  417. bool dax:1;
  418. unsigned int max_read;
  419. unsigned int blksize;
  420. const char *subtype;
  421. /* DAX device, may be NULL */
  422. struct dax_device *dax_dev;
  423. /* fuse_dev pointer to fill in, should contain NULL on entry */
  424. void **fudptr;
  425. };
  426. /**
  427. * A Fuse connection.
  428. *
  429. * This structure is created, when the root filesystem is mounted, and
  430. * is destroyed, when the client device is closed and the last
  431. * fuse_mount is destroyed.
  432. */
  433. struct fuse_conn {
  434. /** Lock protecting accessess to members of this structure */
  435. spinlock_t lock;
  436. /** Refcount */
  437. refcount_t count;
  438. /** Number of fuse_dev's */
  439. atomic_t dev_count;
  440. struct rcu_head rcu;
  441. /** The user id for this mount */
  442. kuid_t user_id;
  443. /** The group id for this mount */
  444. kgid_t group_id;
  445. /** The pid namespace for this mount */
  446. struct pid_namespace *pid_ns;
  447. /** The user namespace for this mount */
  448. struct user_namespace *user_ns;
  449. /** Maximum read size */
  450. unsigned max_read;
  451. /** Maximum write size */
  452. unsigned max_write;
  453. /** Maxmum number of pages that can be used in a single request */
  454. unsigned int max_pages;
  455. /** Input queue */
  456. struct fuse_iqueue iq;
  457. /** The next unique kernel file handle */
  458. atomic64_t khctr;
  459. /** rbtree of fuse_files waiting for poll events indexed by ph */
  460. struct rb_root polled_files;
  461. /** Maximum number of outstanding background requests */
  462. unsigned max_background;
  463. /** Number of background requests at which congestion starts */
  464. unsigned congestion_threshold;
  465. /** Number of requests currently in the background */
  466. unsigned num_background;
  467. /** Number of background requests currently queued for userspace */
  468. unsigned active_background;
  469. /** The list of background requests set aside for later queuing */
  470. struct list_head bg_queue;
  471. /** Protects: max_background, congestion_threshold, num_background,
  472. * active_background, bg_queue, blocked */
  473. spinlock_t bg_lock;
  474. /** Flag indicating that INIT reply has been received. Allocating
  475. * any fuse request will be suspended until the flag is set */
  476. int initialized;
  477. /** Flag indicating if connection is blocked. This will be
  478. the case before the INIT reply is received, and if there
  479. are too many outstading backgrounds requests */
  480. int blocked;
  481. /** waitq for blocked connection */
  482. wait_queue_head_t blocked_waitq;
  483. /** Connection established, cleared on umount, connection
  484. abort and device release */
  485. unsigned connected;
  486. /** Connection aborted via sysfs */
  487. bool aborted;
  488. /** Connection failed (version mismatch). Cannot race with
  489. setting other bitfields since it is only set once in INIT
  490. reply, before any other request, and never cleared */
  491. unsigned conn_error:1;
  492. /** Connection successful. Only set in INIT */
  493. unsigned conn_init:1;
  494. /** Do readpages asynchronously? Only set in INIT */
  495. unsigned async_read:1;
  496. /** Return an unique read error after abort. Only set in INIT */
  497. unsigned abort_err:1;
  498. /** Do not send separate SETATTR request before open(O_TRUNC) */
  499. unsigned atomic_o_trunc:1;
  500. /** Filesystem supports NFS exporting. Only set in INIT */
  501. unsigned export_support:1;
  502. /** write-back cache policy (default is write-through) */
  503. unsigned writeback_cache:1;
  504. /** allow parallel lookups and readdir (default is serialized) */
  505. unsigned parallel_dirops:1;
  506. /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
  507. unsigned handle_killpriv:1;
  508. /** cache READLINK responses in page cache */
  509. unsigned cache_symlinks:1;
  510. /* show legacy mount options */
  511. unsigned int legacy_opts_show:1;
  512. /*
  513. * The following bitfields are only for optimization purposes
  514. * and hence races in setting them will not cause malfunction
  515. */
  516. /** Is open/release not implemented by fs? */
  517. unsigned no_open:1;
  518. /** Is opendir/releasedir not implemented by fs? */
  519. unsigned no_opendir:1;
  520. /** Is fsync not implemented by fs? */
  521. unsigned no_fsync:1;
  522. /** Is fsyncdir not implemented by fs? */
  523. unsigned no_fsyncdir:1;
  524. /** Is flush not implemented by fs? */
  525. unsigned no_flush:1;
  526. /** Is setxattr not implemented by fs? */
  527. unsigned no_setxattr:1;
  528. /** Is getxattr not implemented by fs? */
  529. unsigned no_getxattr:1;
  530. /** Is listxattr not implemented by fs? */
  531. unsigned no_listxattr:1;
  532. /** Is removexattr not implemented by fs? */
  533. unsigned no_removexattr:1;
  534. /** Are posix file locking primitives not implemented by fs? */
  535. unsigned no_lock:1;
  536. /** Is access not implemented by fs? */
  537. unsigned no_access:1;
  538. /** Is create not implemented by fs? */
  539. unsigned no_create:1;
  540. /** Is interrupt not implemented by fs? */
  541. unsigned no_interrupt:1;
  542. /** Is bmap not implemented by fs? */
  543. unsigned no_bmap:1;
  544. /** Is poll not implemented by fs? */
  545. unsigned no_poll:1;
  546. /** Do multi-page cached writes */
  547. unsigned big_writes:1;
  548. /** Don't apply umask to creation modes */
  549. unsigned dont_mask:1;
  550. /** Are BSD file locking primitives not implemented by fs? */
  551. unsigned no_flock:1;
  552. /** Is fallocate not implemented by fs? */
  553. unsigned no_fallocate:1;
  554. /** Is rename with flags implemented by fs? */
  555. unsigned no_rename2:1;
  556. /** Use enhanced/automatic page cache invalidation. */
  557. unsigned auto_inval_data:1;
  558. /** Filesystem is fully reponsible for page cache invalidation. */
  559. unsigned explicit_inval_data:1;
  560. /** Does the filesystem support readdirplus? */
  561. unsigned do_readdirplus:1;
  562. /** Does the filesystem want adaptive readdirplus? */
  563. unsigned readdirplus_auto:1;
  564. /** Does the filesystem support asynchronous direct-IO submission? */
  565. unsigned async_dio:1;
  566. /** Is lseek not implemented by fs? */
  567. unsigned no_lseek:1;
  568. /** Does the filesystem support posix acls? */
  569. unsigned posix_acl:1;
  570. /** Check permissions based on the file mode or not? */
  571. unsigned default_permissions:1;
  572. /** Allow other than the mounter user to access the filesystem ? */
  573. unsigned allow_other:1;
  574. /** Does the filesystem support copy_file_range? */
  575. unsigned no_copy_file_range:1;
  576. /* Send DESTROY request */
  577. unsigned int destroy:1;
  578. /* Delete dentries that have gone stale */
  579. unsigned int delete_stale:1;
  580. /** Do not create entry in fusectl fs */
  581. unsigned int no_control:1;
  582. /** Do not allow MNT_FORCE umount */
  583. unsigned int no_force_umount:1;
  584. /* Auto-mount submounts announced by the server */
  585. unsigned int auto_submounts:1;
  586. /** Passthrough mode for read/write IO */
  587. unsigned int passthrough:1;
  588. /** The number of requests waiting for completion */
  589. atomic_t num_waiting;
  590. /** Negotiated minor version */
  591. unsigned minor;
  592. /** Entry on the fuse_mount_list */
  593. struct list_head entry;
  594. /** Device ID from the root super block */
  595. dev_t dev;
  596. /** Dentries in the control filesystem */
  597. struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
  598. /** number of dentries used in the above array */
  599. int ctl_ndents;
  600. /** Key for lock owner ID scrambling */
  601. u32 scramble_key[4];
  602. /** Version counter for attribute changes */
  603. atomic64_t attr_version;
  604. /** Called on final put */
  605. void (*release)(struct fuse_conn *);
  606. /**
  607. * Read/write semaphore to hold when accessing the sb of any
  608. * fuse_mount belonging to this connection
  609. */
  610. struct rw_semaphore killsb;
  611. /** List of device instances belonging to this connection */
  612. struct list_head devices;
  613. #ifdef CONFIG_FUSE_DAX
  614. /* Dax specific conn data, non-NULL if DAX is enabled */
  615. struct fuse_conn_dax *dax;
  616. #endif
  617. /** List of filesystems using this connection */
  618. struct list_head mounts;
  619. /** IDR for passthrough requests */
  620. struct idr passthrough_req;
  621. /** Protects passthrough_req */
  622. spinlock_t passthrough_req_lock;
  623. };
  624. /*
  625. * Represents a mounted filesystem, potentially a submount.
  626. *
  627. * This object allows sharing a fuse_conn between separate mounts to
  628. * allow submounts with dedicated superblocks and thus separate device
  629. * IDs.
  630. */
  631. struct fuse_mount {
  632. /* Underlying (potentially shared) connection to the FUSE server */
  633. struct fuse_conn *fc;
  634. /* Refcount */
  635. refcount_t count;
  636. /*
  637. * Super block for this connection (fc->killsb must be held when
  638. * accessing this).
  639. */
  640. struct super_block *sb;
  641. /* Entry on fc->mounts */
  642. struct list_head fc_entry;
  643. };
  644. static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb)
  645. {
  646. return sb->s_fs_info;
  647. }
  648. static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
  649. {
  650. struct fuse_mount *fm = get_fuse_mount_super(sb);
  651. return fm ? fm->fc : NULL;
  652. }
  653. static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
  654. {
  655. return get_fuse_mount_super(inode->i_sb);
  656. }
  657. static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
  658. {
  659. struct fuse_mount *fm = get_fuse_mount(inode);
  660. return fm ? fm->fc : NULL;
  661. }
  662. static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
  663. {
  664. return container_of(inode, struct fuse_inode, inode);
  665. }
  666. static inline u64 get_node_id(struct inode *inode)
  667. {
  668. return get_fuse_inode(inode)->nodeid;
  669. }
  670. static inline int invalid_nodeid(u64 nodeid)
  671. {
  672. return !nodeid || nodeid == FUSE_ROOT_ID;
  673. }
  674. static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
  675. {
  676. return atomic64_read(&fc->attr_version);
  677. }
  678. static inline bool fuse_stale_inode(const struct inode *inode, int generation,
  679. struct fuse_attr *attr)
  680. {
  681. return inode->i_generation != generation ||
  682. inode_wrong_type(inode, attr->mode);
  683. }
  684. static inline void fuse_make_bad(struct inode *inode)
  685. {
  686. remove_inode_hash(inode);
  687. set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state);
  688. }
  689. static inline bool fuse_is_bad(struct inode *inode)
  690. {
  691. return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
  692. }
  693. /** Device operations */
  694. extern const struct file_operations fuse_dev_operations;
  695. extern const struct dentry_operations fuse_dentry_operations;
  696. extern const struct dentry_operations fuse_root_dentry_operations;
  697. /**
  698. * Get a filled in inode
  699. */
  700. struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
  701. int generation, struct fuse_attr *attr,
  702. u64 attr_valid, u64 attr_version);
  703. int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
  704. struct fuse_entry_out *outarg, struct inode **inode);
  705. /**
  706. * Send FORGET command
  707. */
  708. void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
  709. u64 nodeid, u64 nlookup);
  710. struct fuse_forget_link *fuse_alloc_forget(void);
  711. struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq,
  712. unsigned int max,
  713. unsigned int *countp);
  714. /*
  715. * Initialize READ or READDIR request
  716. */
  717. struct fuse_io_args {
  718. union {
  719. struct {
  720. struct fuse_read_in in;
  721. u64 attr_ver;
  722. } read;
  723. struct {
  724. struct fuse_write_in in;
  725. struct fuse_write_out out;
  726. bool page_locked;
  727. } write;
  728. };
  729. struct fuse_args_pages ap;
  730. struct fuse_io_priv *io;
  731. struct fuse_file *ff;
  732. };
  733. void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
  734. size_t count, int opcode);
  735. /**
  736. * Send OPEN or OPENDIR request
  737. */
  738. int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
  739. struct fuse_file *fuse_file_alloc(struct fuse_mount *fm);
  740. void fuse_file_free(struct fuse_file *ff);
  741. void fuse_finish_open(struct inode *inode, struct file *file);
  742. void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
  743. /**
  744. * Send RELEASE or RELEASEDIR request
  745. */
  746. void fuse_release_common(struct file *file, bool isdir);
  747. /**
  748. * Send FSYNC or FSYNCDIR request
  749. */
  750. int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
  751. int datasync, int opcode);
  752. /**
  753. * Notify poll wakeup
  754. */
  755. int fuse_notify_poll_wakeup(struct fuse_conn *fc,
  756. struct fuse_notify_poll_wakeup_out *outarg);
  757. /**
  758. * Initialize file operations on a regular file
  759. */
  760. void fuse_init_file_inode(struct inode *inode);
  761. /**
  762. * Initialize inode operations on regular files and special files
  763. */
  764. void fuse_init_common(struct inode *inode);
  765. /**
  766. * Initialize inode and file operations on a directory
  767. */
  768. void fuse_init_dir(struct inode *inode);
  769. /**
  770. * Initialize inode operations on a symlink
  771. */
  772. void fuse_init_symlink(struct inode *inode);
  773. /**
  774. * Change attributes of an inode
  775. */
  776. void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
  777. u64 attr_valid, u64 attr_version);
  778. void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
  779. u64 attr_valid);
  780. /**
  781. * Initialize the client device
  782. */
  783. int fuse_dev_init(void);
  784. /**
  785. * Cleanup the client device
  786. */
  787. void fuse_dev_cleanup(void);
  788. int fuse_ctl_init(void);
  789. void __exit fuse_ctl_cleanup(void);
  790. /**
  791. * Simple request sending that does request allocation and freeing
  792. */
  793. ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args);
  794. int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
  795. gfp_t gfp_flags);
  796. /**
  797. * End a finished request
  798. */
  799. void fuse_request_end(struct fuse_req *req);
  800. /* Abort all requests */
  801. void fuse_abort_conn(struct fuse_conn *fc);
  802. void fuse_wait_aborted(struct fuse_conn *fc);
  803. /**
  804. * Invalidate inode attributes
  805. */
  806. void fuse_invalidate_attr(struct inode *inode);
  807. void fuse_invalidate_entry_cache(struct dentry *entry);
  808. void fuse_invalidate_atime(struct inode *inode);
  809. u64 entry_attr_timeout(struct fuse_entry_out *o);
  810. void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
  811. /**
  812. * Acquire reference to fuse_conn
  813. */
  814. struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
  815. /**
  816. * Initialize fuse_conn
  817. */
  818. void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
  819. struct user_namespace *user_ns,
  820. const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
  821. /**
  822. * Release reference to fuse_conn
  823. */
  824. void fuse_conn_put(struct fuse_conn *fc);
  825. /**
  826. * Acquire reference to fuse_mount
  827. */
  828. struct fuse_mount *fuse_mount_get(struct fuse_mount *fm);
  829. /**
  830. * Release reference to fuse_mount
  831. */
  832. void fuse_mount_put(struct fuse_mount *fm);
  833. struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
  834. struct fuse_dev *fuse_dev_alloc(void);
  835. void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
  836. void fuse_dev_free(struct fuse_dev *fud);
  837. void fuse_send_init(struct fuse_mount *fm);
  838. /**
  839. * Fill in superblock and initialize fuse connection
  840. * @sb: partially-initialized superblock to fill in
  841. * @ctx: mount context
  842. */
  843. int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
  844. /*
  845. * Fill in superblock for submounts
  846. * @sb: partially-initialized superblock to fill in
  847. * @parent_fi: The fuse_inode of the parent filesystem where this submount is
  848. * mounted
  849. */
  850. int fuse_fill_super_submount(struct super_block *sb,
  851. struct fuse_inode *parent_fi);
  852. /*
  853. * Remove the mount from the connection
  854. *
  855. * Returns whether this was the last mount
  856. */
  857. bool fuse_mount_remove(struct fuse_mount *fm);
  858. /*
  859. * Shut down the connection (possibly sending DESTROY request).
  860. */
  861. void fuse_conn_destroy(struct fuse_mount *fm);
  862. /**
  863. * Add connection to control filesystem
  864. */
  865. int fuse_ctl_add_conn(struct fuse_conn *fc);
  866. /**
  867. * Remove connection from control filesystem
  868. */
  869. void fuse_ctl_remove_conn(struct fuse_conn *fc);
  870. /**
  871. * Is file type valid?
  872. */
  873. int fuse_valid_type(int m);
  874. bool fuse_invalid_attr(struct fuse_attr *attr);
  875. /**
  876. * Is current process allowed to perform filesystem operation?
  877. */
  878. int fuse_allow_current_process(struct fuse_conn *fc);
  879. u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
  880. void fuse_flush_time_update(struct inode *inode);
  881. void fuse_update_ctime(struct inode *inode);
  882. int fuse_update_attributes(struct inode *inode, struct file *file);
  883. void fuse_flush_writepages(struct inode *inode);
  884. void fuse_set_nowrite(struct inode *inode);
  885. void fuse_release_nowrite(struct inode *inode);
  886. /**
  887. * Scan all fuse_mounts belonging to fc to find the first where
  888. * ilookup5() returns a result. Return that result and the
  889. * respective fuse_mount in *fm (unless fm is NULL).
  890. *
  891. * The caller must hold fc->killsb.
  892. */
  893. struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
  894. struct fuse_mount **fm);
  895. /**
  896. * File-system tells the kernel to invalidate cache for the given node id.
  897. */
  898. int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
  899. loff_t offset, loff_t len);
  900. /**
  901. * File-system tells the kernel to invalidate parent attributes and
  902. * the dentry matching parent/name.
  903. *
  904. * If the child_nodeid is non-zero and:
  905. * - matches the inode number for the dentry matching parent/name,
  906. * - is not a mount point
  907. * - is a file or oan empty directory
  908. * then the dentry is unhashed (d_delete()).
  909. */
  910. int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
  911. u64 child_nodeid, struct qstr *name);
  912. int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
  913. bool isdir);
  914. /**
  915. * fuse_direct_io() flags
  916. */
  917. /** If set, it is WRITE; otherwise - READ */
  918. #define FUSE_DIO_WRITE (1 << 0)
  919. /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
  920. #define FUSE_DIO_CUSE (1 << 1)
  921. ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  922. loff_t *ppos, int flags);
  923. long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
  924. unsigned int flags);
  925. long fuse_ioctl_common(struct file *file, unsigned int cmd,
  926. unsigned long arg, unsigned int flags);
  927. __poll_t fuse_file_poll(struct file *file, poll_table *wait);
  928. int fuse_dev_release(struct inode *inode, struct file *file);
  929. bool fuse_write_update_size(struct inode *inode, loff_t pos);
  930. int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
  931. int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
  932. int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
  933. struct file *file);
  934. void fuse_set_initialized(struct fuse_conn *fc);
  935. void fuse_unlock_inode(struct inode *inode, bool locked);
  936. bool fuse_lock_inode(struct inode *inode);
  937. int fuse_setxattr(struct inode *inode, const char *name, const void *value,
  938. size_t size, int flags);
  939. ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
  940. size_t size);
  941. ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
  942. int fuse_removexattr(struct inode *inode, const char *name);
  943. extern const struct xattr_handler *fuse_xattr_handlers[];
  944. extern const struct xattr_handler *fuse_acl_xattr_handlers[];
  945. extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
  946. struct posix_acl;
  947. struct posix_acl *fuse_get_acl(struct inode *inode, int type);
  948. int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
  949. /* readdir.c */
  950. int fuse_readdir(struct file *file, struct dir_context *ctx);
  951. /**
  952. * Return the number of bytes in an arguments list
  953. */
  954. unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
  955. /**
  956. * Get the next unique ID for a request
  957. */
  958. u64 fuse_get_unique(struct fuse_iqueue *fiq);
  959. void fuse_free_conn(struct fuse_conn *fc);
  960. /* dax.c */
  961. #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
  962. ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
  963. ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
  964. int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
  965. int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
  966. int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev);
  967. void fuse_dax_conn_free(struct fuse_conn *fc);
  968. bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
  969. void fuse_dax_inode_init(struct inode *inode);
  970. void fuse_dax_inode_cleanup(struct inode *inode);
  971. bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
  972. void fuse_dax_cancel_work(struct fuse_conn *fc);
  973. /* passthrough.c */
  974. int fuse_passthrough_open(struct fuse_dev *fud, u32 lower_fd);
  975. int fuse_passthrough_setup(struct fuse_conn *fc, struct fuse_file *ff,
  976. struct fuse_open_out *openarg);
  977. void fuse_passthrough_release(struct fuse_passthrough *passthrough);
  978. ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *to);
  979. ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *from);
  980. ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
  981. #endif /* _FS_FUSE_I_H */