fuse_i.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  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. /** Bias for fi->writectr, meaning new writepages must not be sent */
  33. #define FUSE_NOWRITE INT_MIN
  34. /** Maximum length of a filename, not including terminating null */
  35. /* maximum, small enough for FUSE_MIN_READ_BUFFER*/
  36. #define FUSE_NAME_LOW_MAX 1024
  37. /* maximum, but needs a request buffer > FUSE_MIN_READ_BUFFER */
  38. #define FUSE_NAME_MAX (PATH_MAX - 1)
  39. /** Number of dentries for each connection in the control filesystem */
  40. #define FUSE_CTL_NUM_DENTRIES 5
  41. /* Frequency (in seconds) of request timeout checks, if opted into */
  42. #define FUSE_TIMEOUT_TIMER_FREQ 15
  43. /** Frequency (in jiffies) of request timeout checks, if opted into */
  44. extern const unsigned long fuse_timeout_timer_freq;
  45. /*
  46. * Dentries invalidation workqueue period, in seconds. The value of this
  47. * parameter shall be >= FUSE_DENTRY_INVAL_FREQ_MIN seconds, or 0 (zero), in
  48. * which case no workqueue will be created.
  49. */
  50. extern unsigned inval_wq __read_mostly;
  51. /** Maximum of max_pages received in init_out */
  52. extern unsigned int fuse_max_pages_limit;
  53. /*
  54. * Default timeout (in seconds) for the server to reply to a request
  55. * before the connection is aborted, if no timeout was specified on mount.
  56. */
  57. extern unsigned int fuse_default_req_timeout;
  58. /*
  59. * Max timeout (in seconds) for the server to reply to a request before
  60. * the connection is aborted.
  61. */
  62. extern unsigned int fuse_max_req_timeout;
  63. /** List of active connections */
  64. extern struct list_head fuse_conn_list;
  65. /** Global mutex protecting fuse_conn_list and the control filesystem */
  66. extern struct mutex fuse_mutex;
  67. /** Module parameters */
  68. extern unsigned int max_user_bgreq;
  69. extern unsigned int max_user_congthresh;
  70. /* One forget request */
  71. struct fuse_forget_link {
  72. struct fuse_forget_one forget_one;
  73. struct fuse_forget_link *next;
  74. };
  75. /* Submount lookup tracking */
  76. struct fuse_submount_lookup {
  77. /** Refcount */
  78. refcount_t count;
  79. /** Unique ID, which identifies the inode between userspace
  80. * and kernel */
  81. u64 nodeid;
  82. /** The request used for sending the FORGET message */
  83. struct fuse_forget_link *forget;
  84. };
  85. /** Container for data related to mapping to backing file */
  86. struct fuse_backing {
  87. struct file *file;
  88. struct cred *cred;
  89. /** refcount */
  90. refcount_t count;
  91. struct rcu_head rcu;
  92. };
  93. /** FUSE inode */
  94. struct fuse_inode {
  95. /** Inode data */
  96. struct inode inode;
  97. /** Unique ID, which identifies the inode between userspace
  98. * and kernel */
  99. u64 nodeid;
  100. /** Number of lookups on this inode */
  101. u64 nlookup;
  102. /** The request used for sending the FORGET message */
  103. struct fuse_forget_link *forget;
  104. /** Time in jiffies until the file attributes are valid */
  105. u64 i_time;
  106. /* Which attributes are invalid */
  107. u32 inval_mask;
  108. /** The sticky bit in inode->i_mode may have been removed, so
  109. preserve the original mode */
  110. umode_t orig_i_mode;
  111. /* Cache birthtime */
  112. struct timespec64 i_btime;
  113. /** 64 bit inode number */
  114. u64 orig_ino;
  115. /** Version of last attribute change */
  116. u64 attr_version;
  117. union {
  118. /* read/write io cache (regular file only) */
  119. struct {
  120. /* Files usable in writepage. Protected by fi->lock */
  121. struct list_head write_files;
  122. /* Writepages pending on truncate or fsync */
  123. struct list_head queued_writes;
  124. /* Number of sent writes, a negative bias
  125. * (FUSE_NOWRITE) means more writes are blocked */
  126. int writectr;
  127. /** Number of files/maps using page cache */
  128. int iocachectr;
  129. /* Waitq for writepage completion */
  130. wait_queue_head_t page_waitq;
  131. /* waitq for direct-io completion */
  132. wait_queue_head_t direct_io_waitq;
  133. };
  134. /* readdir cache (directory only) */
  135. struct {
  136. /* true if fully cached */
  137. bool cached;
  138. /* size of cache */
  139. loff_t size;
  140. /* position at end of cache (position of next entry) */
  141. loff_t pos;
  142. /* version of the cache */
  143. u64 version;
  144. /* modification time of directory when cache was
  145. * started */
  146. struct timespec64 mtime;
  147. /* iversion of directory when cache was started */
  148. u64 iversion;
  149. /* protects above fields */
  150. spinlock_t lock;
  151. } rdc;
  152. };
  153. /** Miscellaneous bits describing inode state */
  154. unsigned long state;
  155. /** Lock for serializing lookup and readdir for back compatibility*/
  156. struct mutex mutex;
  157. /** Lock to protect write related fields */
  158. spinlock_t lock;
  159. #ifdef CONFIG_FUSE_DAX
  160. /*
  161. * Dax specific inode data
  162. */
  163. struct fuse_inode_dax *dax;
  164. #endif
  165. /** Submount specific lookup tracking */
  166. struct fuse_submount_lookup *submount_lookup;
  167. #ifdef CONFIG_FUSE_PASSTHROUGH
  168. /** Reference to backing file in passthrough mode */
  169. struct fuse_backing *fb;
  170. #endif
  171. /*
  172. * The underlying inode->i_blkbits value will not be modified,
  173. * so preserve the blocksize specified by the server.
  174. */
  175. u8 cached_i_blkbits;
  176. };
  177. /** FUSE inode state bits */
  178. enum {
  179. /** Advise readdirplus */
  180. FUSE_I_ADVISE_RDPLUS,
  181. /** Initialized with readdirplus */
  182. FUSE_I_INIT_RDPLUS,
  183. /** An operation changing file size is in progress */
  184. FUSE_I_SIZE_UNSTABLE,
  185. /* Bad inode */
  186. FUSE_I_BAD,
  187. /* Has btime */
  188. FUSE_I_BTIME,
  189. /* Wants or already has page cache IO */
  190. FUSE_I_CACHE_IO_MODE,
  191. /*
  192. * Client has exclusive access to the inode, either because fs is local
  193. * or the fuse server has an exclusive "lease" on distributed fs
  194. */
  195. FUSE_I_EXCLUSIVE,
  196. };
  197. struct fuse_conn;
  198. struct fuse_mount;
  199. union fuse_file_args;
  200. /** FUSE specific file data */
  201. struct fuse_file {
  202. /** Fuse connection for this file */
  203. struct fuse_mount *fm;
  204. /* Argument space reserved for open/release */
  205. union fuse_file_args *args;
  206. /** Kernel file handle guaranteed to be unique */
  207. u64 kh;
  208. /** File handle used by userspace */
  209. u64 fh;
  210. /** Node id of this file */
  211. u64 nodeid;
  212. /** Refcount */
  213. refcount_t count;
  214. /** FOPEN_* flags returned by open */
  215. u32 open_flags;
  216. /** Entry on inode's write_files list */
  217. struct list_head write_entry;
  218. /* Readdir related */
  219. struct {
  220. /* Dir stream position */
  221. loff_t pos;
  222. /* Offset in cache */
  223. loff_t cache_off;
  224. /* Version of cache we are reading */
  225. u64 version;
  226. } readdir;
  227. /** RB node to be linked on fuse_conn->polled_files */
  228. struct rb_node polled_node;
  229. /** Wait queue head for poll */
  230. wait_queue_head_t poll_wait;
  231. /** Does file hold a fi->iocachectr refcount? */
  232. enum { IOM_NONE, IOM_CACHED, IOM_UNCACHED } iomode;
  233. #ifdef CONFIG_FUSE_PASSTHROUGH
  234. /** Reference to backing file in passthrough mode */
  235. struct file *passthrough;
  236. const struct cred *cred;
  237. #endif
  238. /** Has flock been performed on this file? */
  239. bool flock:1;
  240. };
  241. /** One input argument of a request */
  242. struct fuse_in_arg {
  243. unsigned size;
  244. const void *value;
  245. };
  246. /** One output argument of a request */
  247. struct fuse_arg {
  248. unsigned size;
  249. void *value;
  250. };
  251. /** FUSE folio descriptor */
  252. struct fuse_folio_desc {
  253. unsigned int length;
  254. unsigned int offset;
  255. };
  256. struct fuse_args {
  257. uint64_t nodeid;
  258. uint32_t opcode;
  259. uint8_t in_numargs;
  260. uint8_t out_numargs;
  261. uint8_t ext_idx;
  262. bool force:1;
  263. bool noreply:1;
  264. bool nocreds:1;
  265. bool in_pages:1;
  266. bool out_pages:1;
  267. bool user_pages:1;
  268. bool out_argvar:1;
  269. bool page_zeroing:1;
  270. bool page_replace:1;
  271. bool may_block:1;
  272. bool is_ext:1;
  273. bool is_pinned:1;
  274. bool invalidate_vmap:1;
  275. struct fuse_in_arg in_args[4];
  276. struct fuse_arg out_args[2];
  277. void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error);
  278. /* Used for kvec iter backed by vmalloc address */
  279. void *vmap_base;
  280. };
  281. struct fuse_args_pages {
  282. struct fuse_args args;
  283. struct folio **folios;
  284. struct fuse_folio_desc *descs;
  285. unsigned int num_folios;
  286. };
  287. struct fuse_release_args {
  288. struct fuse_args args;
  289. struct fuse_release_in inarg;
  290. struct inode *inode;
  291. };
  292. union fuse_file_args {
  293. /* Used during open() */
  294. struct fuse_open_out open_outarg;
  295. /* Used during release() */
  296. struct fuse_release_args release_args;
  297. };
  298. #define FUSE_ARGS(args) struct fuse_args args = {}
  299. /** The request IO state (for asynchronous processing) */
  300. struct fuse_io_priv {
  301. struct kref refcnt;
  302. int async;
  303. spinlock_t lock;
  304. unsigned reqs;
  305. ssize_t bytes;
  306. size_t size;
  307. __u64 offset;
  308. bool write;
  309. bool should_dirty;
  310. int err;
  311. struct kiocb *iocb;
  312. struct completion *done;
  313. bool blocking;
  314. };
  315. #define FUSE_IO_PRIV_SYNC(i) \
  316. { \
  317. .refcnt = KREF_INIT(1), \
  318. .async = 0, \
  319. .iocb = i, \
  320. }
  321. /**
  322. * Request flags
  323. *
  324. * FR_ISREPLY: set if the request has reply
  325. * FR_FORCE: force sending of the request even if interrupted
  326. * FR_BACKGROUND: request is sent in the background
  327. * FR_WAITING: request is counted as "waiting"
  328. * FR_ABORTED: the request was aborted
  329. * FR_INTERRUPTED: the request has been interrupted
  330. * FR_LOCKED: data is being copied to/from the request
  331. * FR_PENDING: request is not yet in userspace
  332. * FR_SENT: request is in userspace, waiting for an answer
  333. * FR_FINISHED: request is finished
  334. * FR_PRIVATE: request is on private list
  335. * FR_ASYNC: request is asynchronous
  336. * FR_URING: request is handled through fuse-io-uring
  337. */
  338. enum fuse_req_flag {
  339. FR_ISREPLY,
  340. FR_FORCE,
  341. FR_BACKGROUND,
  342. FR_WAITING,
  343. FR_ABORTED,
  344. FR_INTERRUPTED,
  345. FR_LOCKED,
  346. FR_PENDING,
  347. FR_SENT,
  348. FR_FINISHED,
  349. FR_PRIVATE,
  350. FR_ASYNC,
  351. FR_URING,
  352. };
  353. /**
  354. * A request to the client
  355. *
  356. * .waitq.lock protects the following fields:
  357. * - FR_ABORTED
  358. * - FR_LOCKED (may also be modified under fc->lock, tested under both)
  359. */
  360. struct fuse_req {
  361. /** This can be on either pending processing or io lists in
  362. fuse_conn */
  363. struct list_head list;
  364. /** Entry on the interrupts list */
  365. struct list_head intr_entry;
  366. /* Input/output arguments */
  367. struct fuse_args *args;
  368. /** refcount */
  369. refcount_t count;
  370. /* Request flags, updated with test/set/clear_bit() */
  371. unsigned long flags;
  372. /* The request input header */
  373. struct {
  374. struct fuse_in_header h;
  375. } in;
  376. /* The request output header */
  377. struct {
  378. struct fuse_out_header h;
  379. } out;
  380. /** Used to wake up the task waiting for completion of request*/
  381. wait_queue_head_t waitq;
  382. #if IS_ENABLED(CONFIG_VIRTIO_FS)
  383. /** virtio-fs's physically contiguous buffer for in and out args */
  384. void *argbuf;
  385. #endif
  386. /** fuse_mount this request belongs to */
  387. struct fuse_mount *fm;
  388. #ifdef CONFIG_FUSE_IO_URING
  389. void *ring_entry;
  390. void *ring_queue;
  391. #endif
  392. /** When (in jiffies) the request was created */
  393. unsigned long create_time;
  394. };
  395. struct fuse_iqueue;
  396. /**
  397. * Input queue callbacks
  398. *
  399. * Input queue signalling is device-specific. For example, the /dev/fuse file
  400. * uses fiq->waitq and fasync to wake processes that are waiting on queue
  401. * readiness. These callbacks allow other device types to respond to input
  402. * queue activity.
  403. */
  404. struct fuse_iqueue_ops {
  405. /**
  406. * Send one forget
  407. */
  408. void (*send_forget)(struct fuse_iqueue *fiq, struct fuse_forget_link *link);
  409. /**
  410. * Send interrupt for request
  411. */
  412. void (*send_interrupt)(struct fuse_iqueue *fiq, struct fuse_req *req);
  413. /**
  414. * Send one request
  415. */
  416. void (*send_req)(struct fuse_iqueue *fiq, struct fuse_req *req);
  417. /**
  418. * Clean up when fuse_iqueue is destroyed
  419. */
  420. void (*release)(struct fuse_iqueue *fiq);
  421. };
  422. /** /dev/fuse input queue operations */
  423. extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
  424. struct fuse_iqueue {
  425. /** Connection established */
  426. unsigned connected;
  427. /** Lock protecting accesses to members of this structure */
  428. spinlock_t lock;
  429. /** Readers of the connection are waiting on this */
  430. wait_queue_head_t waitq;
  431. /** The next unique request id */
  432. u64 reqctr;
  433. /** The list of pending requests */
  434. struct list_head pending;
  435. /** Pending interrupts */
  436. struct list_head interrupts;
  437. /** Queue of pending forgets */
  438. struct fuse_forget_link forget_list_head;
  439. struct fuse_forget_link *forget_list_tail;
  440. /** Batching of FORGET requests (positive indicates FORGET batch) */
  441. int forget_batch;
  442. /** O_ASYNC requests */
  443. struct fasync_struct *fasync;
  444. /** Device-specific callbacks */
  445. const struct fuse_iqueue_ops *ops;
  446. /** Device-specific state */
  447. void *priv;
  448. };
  449. #define FUSE_PQ_HASH_BITS 8
  450. #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
  451. struct fuse_pqueue {
  452. /** Connection established */
  453. unsigned connected;
  454. /** Lock protecting accessess to members of this structure */
  455. spinlock_t lock;
  456. /** Hash table of requests being processed */
  457. struct list_head *processing;
  458. /** The list of requests under I/O */
  459. struct list_head io;
  460. };
  461. /**
  462. * Fuse device instance
  463. */
  464. struct fuse_dev {
  465. /** Fuse connection for this device */
  466. struct fuse_conn *fc;
  467. /** Processing queue */
  468. struct fuse_pqueue pq;
  469. /** list entry on fc->devices */
  470. struct list_head entry;
  471. };
  472. enum fuse_dax_mode {
  473. FUSE_DAX_INODE_DEFAULT, /* default */
  474. FUSE_DAX_ALWAYS, /* "-o dax=always" */
  475. FUSE_DAX_NEVER, /* "-o dax=never" */
  476. FUSE_DAX_INODE_USER, /* "-o dax=inode" */
  477. };
  478. static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode)
  479. {
  480. return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER;
  481. }
  482. struct fuse_fs_context {
  483. int fd;
  484. struct file *file;
  485. unsigned int rootmode;
  486. kuid_t user_id;
  487. kgid_t group_id;
  488. bool is_bdev:1;
  489. bool fd_present:1;
  490. bool rootmode_present:1;
  491. bool user_id_present:1;
  492. bool group_id_present:1;
  493. bool default_permissions:1;
  494. bool allow_other:1;
  495. bool destroy:1;
  496. bool no_control:1;
  497. bool no_force_umount:1;
  498. bool legacy_opts_show:1;
  499. enum fuse_dax_mode dax_mode;
  500. unsigned int max_read;
  501. unsigned int blksize;
  502. const char *subtype;
  503. /* DAX device, may be NULL */
  504. struct dax_device *dax_dev;
  505. /* fuse_dev pointer to fill in, should contain NULL on entry */
  506. void **fudptr;
  507. };
  508. struct fuse_sync_bucket {
  509. /* count is a possible scalability bottleneck */
  510. atomic_t count;
  511. wait_queue_head_t waitq;
  512. struct rcu_head rcu;
  513. };
  514. /**
  515. * A Fuse connection.
  516. *
  517. * This structure is created, when the root filesystem is mounted, and
  518. * is destroyed, when the client device is closed and the last
  519. * fuse_mount is destroyed.
  520. */
  521. struct fuse_conn {
  522. /** Lock protecting accessess to members of this structure */
  523. spinlock_t lock;
  524. /** Refcount */
  525. refcount_t count;
  526. /** Number of fuse_dev's */
  527. atomic_t dev_count;
  528. /** Current epoch for up-to-date dentries */
  529. atomic_t epoch;
  530. struct work_struct epoch_work;
  531. struct rcu_head rcu;
  532. /** The user id for this mount */
  533. kuid_t user_id;
  534. /** The group id for this mount */
  535. kgid_t group_id;
  536. /** The pid namespace for this mount */
  537. struct pid_namespace *pid_ns;
  538. /** The user namespace for this mount */
  539. struct user_namespace *user_ns;
  540. /** Maximum read size */
  541. unsigned max_read;
  542. /** Maximum write size */
  543. unsigned max_write;
  544. /** Maximum number of pages that can be used in a single request */
  545. unsigned int max_pages;
  546. /** Constrain ->max_pages to this value during feature negotiation */
  547. unsigned int max_pages_limit;
  548. /** Input queue */
  549. struct fuse_iqueue iq;
  550. /** The next unique kernel file handle */
  551. atomic64_t khctr;
  552. /** rbtree of fuse_files waiting for poll events indexed by ph */
  553. struct rb_root polled_files;
  554. /** Maximum number of outstanding background requests */
  555. unsigned max_background;
  556. /** Number of background requests at which congestion starts */
  557. unsigned congestion_threshold;
  558. /** Number of requests currently in the background */
  559. unsigned num_background;
  560. /** Number of background requests currently queued for userspace */
  561. unsigned active_background;
  562. /** The list of background requests set aside for later queuing */
  563. struct list_head bg_queue;
  564. /** Protects: max_background, congestion_threshold, num_background,
  565. * active_background, bg_queue, blocked */
  566. spinlock_t bg_lock;
  567. /** Flag indicating that INIT reply has been received. Allocating
  568. * any fuse request will be suspended until the flag is set */
  569. int initialized;
  570. /** Flag indicating if connection is blocked. This will be
  571. the case before the INIT reply is received, and if there
  572. are too many outstading backgrounds requests */
  573. int blocked;
  574. /** waitq for blocked connection */
  575. wait_queue_head_t blocked_waitq;
  576. /** Connection established, cleared on umount, connection
  577. abort and device release */
  578. unsigned connected;
  579. /** Connection aborted via sysfs */
  580. bool aborted;
  581. /** Connection failed (version mismatch). Cannot race with
  582. setting other bitfields since it is only set once in INIT
  583. reply, before any other request, and never cleared */
  584. unsigned conn_error:1;
  585. /** Connection successful. Only set in INIT */
  586. unsigned conn_init:1;
  587. /** Do readahead asynchronously? Only set in INIT */
  588. unsigned async_read:1;
  589. /** Return an unique read error after abort. Only set in INIT */
  590. unsigned abort_err:1;
  591. /** Do not send separate SETATTR request before open(O_TRUNC) */
  592. unsigned atomic_o_trunc:1;
  593. /** Filesystem supports NFS exporting. Only set in INIT */
  594. unsigned export_support:1;
  595. /** write-back cache policy (default is write-through) */
  596. unsigned writeback_cache:1;
  597. /** allow parallel lookups and readdir (default is serialized) */
  598. unsigned parallel_dirops:1;
  599. /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
  600. unsigned handle_killpriv:1;
  601. /** cache READLINK responses in page cache */
  602. unsigned cache_symlinks:1;
  603. /* show legacy mount options */
  604. unsigned int legacy_opts_show:1;
  605. /*
  606. * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
  607. * write/trunc only if caller did not have CAP_FSETID. sgid is killed
  608. * on write/truncate only if caller did not have CAP_FSETID as well as
  609. * file has group execute permission.
  610. */
  611. unsigned handle_killpriv_v2:1;
  612. /*
  613. * The following bitfields are only for optimization purposes
  614. * and hence races in setting them will not cause malfunction
  615. */
  616. /** Is open/release not implemented by fs? */
  617. unsigned no_open:1;
  618. /** Is opendir/releasedir not implemented by fs? */
  619. unsigned no_opendir:1;
  620. /** Is fsync not implemented by fs? */
  621. unsigned no_fsync:1;
  622. /** Is fsyncdir not implemented by fs? */
  623. unsigned no_fsyncdir:1;
  624. /** Is flush not implemented by fs? */
  625. unsigned no_flush:1;
  626. /** Is setxattr not implemented by fs? */
  627. unsigned no_setxattr:1;
  628. /** Does file server support extended setxattr */
  629. unsigned setxattr_ext:1;
  630. /** Is getxattr not implemented by fs? */
  631. unsigned no_getxattr:1;
  632. /** Is listxattr not implemented by fs? */
  633. unsigned no_listxattr:1;
  634. /** Is removexattr not implemented by fs? */
  635. unsigned no_removexattr:1;
  636. /** Are posix file locking primitives not implemented by fs? */
  637. unsigned no_lock:1;
  638. /** Is access not implemented by fs? */
  639. unsigned no_access:1;
  640. /** Is create not implemented by fs? */
  641. unsigned no_create:1;
  642. /** Is interrupt not implemented by fs? */
  643. unsigned no_interrupt:1;
  644. /** Is bmap not implemented by fs? */
  645. unsigned no_bmap:1;
  646. /** Is poll not implemented by fs? */
  647. unsigned no_poll:1;
  648. /** Do multi-page cached writes */
  649. unsigned big_writes:1;
  650. /** Don't apply umask to creation modes */
  651. unsigned dont_mask:1;
  652. /** Are BSD file locking primitives not implemented by fs? */
  653. unsigned no_flock:1;
  654. /** Is fallocate not implemented by fs? */
  655. unsigned no_fallocate:1;
  656. /** Is rename with flags implemented by fs? */
  657. unsigned no_rename2:1;
  658. /** Use enhanced/automatic page cache invalidation. */
  659. unsigned auto_inval_data:1;
  660. /** Filesystem is fully responsible for page cache invalidation. */
  661. unsigned explicit_inval_data:1;
  662. /** Does the filesystem support readdirplus? */
  663. unsigned do_readdirplus:1;
  664. /** Does the filesystem want adaptive readdirplus? */
  665. unsigned readdirplus_auto:1;
  666. /** Does the filesystem support asynchronous direct-IO submission? */
  667. unsigned async_dio:1;
  668. /** Is lseek not implemented by fs? */
  669. unsigned no_lseek:1;
  670. /** Does the filesystem support posix acls? */
  671. unsigned posix_acl:1;
  672. /** Check permissions based on the file mode or not? */
  673. unsigned default_permissions:1;
  674. /** Allow other than the mounter user to access the filesystem ? */
  675. unsigned allow_other:1;
  676. /** Does the filesystem support copy_file_range? */
  677. unsigned no_copy_file_range:1;
  678. /** Does the filesystem support copy_file_range_64? */
  679. unsigned no_copy_file_range_64:1;
  680. /* Send DESTROY request */
  681. unsigned int destroy:1;
  682. /* Delete dentries that have gone stale */
  683. unsigned int delete_stale:1;
  684. /** Do not create entry in fusectl fs */
  685. unsigned int no_control:1;
  686. /** Do not allow MNT_FORCE umount */
  687. unsigned int no_force_umount:1;
  688. /* Auto-mount submounts announced by the server */
  689. unsigned int auto_submounts:1;
  690. /* Propagate syncfs() to server */
  691. unsigned int sync_fs:1;
  692. /* Initialize security xattrs when creating a new inode */
  693. unsigned int init_security:1;
  694. /* Add supplementary group info when creating a new inode */
  695. unsigned int create_supp_group:1;
  696. /* Does the filesystem support per inode DAX? */
  697. unsigned int inode_dax:1;
  698. /* Is tmpfile not implemented by fs? */
  699. unsigned int no_tmpfile:1;
  700. /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
  701. unsigned int direct_io_allow_mmap:1;
  702. /* Is statx not implemented by fs? */
  703. unsigned int no_statx:1;
  704. /** Passthrough support for read/write IO */
  705. unsigned int passthrough:1;
  706. /* Use pages instead of pointer for kernel I/O */
  707. unsigned int use_pages_for_kvec_io:1;
  708. /* Is link not implemented by fs? */
  709. unsigned int no_link:1;
  710. /* Is synchronous FUSE_INIT allowed? */
  711. unsigned int sync_init:1;
  712. /* Use io_uring for communication */
  713. unsigned int io_uring;
  714. /** Maximum stack depth for passthrough backing files */
  715. int max_stack_depth;
  716. /** The number of requests waiting for completion */
  717. atomic_t num_waiting;
  718. /** Negotiated minor version */
  719. unsigned minor;
  720. /** Entry on the fuse_conn_list */
  721. struct list_head entry;
  722. /** Device ID from the root super block */
  723. dev_t dev;
  724. /** Key for lock owner ID scrambling */
  725. u32 scramble_key[4];
  726. /** Version counter for attribute changes */
  727. atomic64_t attr_version;
  728. /** Version counter for evict inode */
  729. atomic64_t evict_ctr;
  730. /* maximum file name length */
  731. u32 name_max;
  732. /** Called on final put */
  733. void (*release)(struct fuse_conn *);
  734. /**
  735. * Read/write semaphore to hold when accessing the sb of any
  736. * fuse_mount belonging to this connection
  737. */
  738. struct rw_semaphore killsb;
  739. /** List of device instances belonging to this connection */
  740. struct list_head devices;
  741. #ifdef CONFIG_FUSE_DAX
  742. /* Dax mode */
  743. enum fuse_dax_mode dax_mode;
  744. /* Dax specific conn data, non-NULL if DAX is enabled */
  745. struct fuse_conn_dax *dax;
  746. #endif
  747. /** List of filesystems using this connection */
  748. struct list_head mounts;
  749. /* New writepages go into this bucket */
  750. struct fuse_sync_bucket __rcu *curr_bucket;
  751. #ifdef CONFIG_FUSE_PASSTHROUGH
  752. /** IDR for backing files ids */
  753. struct idr backing_files_map;
  754. #endif
  755. #ifdef CONFIG_FUSE_IO_URING
  756. /** uring connection information*/
  757. struct fuse_ring *ring;
  758. #endif
  759. /** Only used if the connection opts into request timeouts */
  760. struct {
  761. /* Worker for checking if any requests have timed out */
  762. struct delayed_work work;
  763. /* Request timeout (in jiffies). 0 = no timeout */
  764. unsigned int req_timeout;
  765. } timeout;
  766. };
  767. /*
  768. * Represents a mounted filesystem, potentially a submount.
  769. *
  770. * This object allows sharing a fuse_conn between separate mounts to
  771. * allow submounts with dedicated superblocks and thus separate device
  772. * IDs.
  773. */
  774. struct fuse_mount {
  775. /* Underlying (potentially shared) connection to the FUSE server */
  776. struct fuse_conn *fc;
  777. /*
  778. * Super block for this connection (fc->killsb must be held when
  779. * accessing this).
  780. */
  781. struct super_block *sb;
  782. /* Entry on fc->mounts */
  783. struct list_head fc_entry;
  784. struct rcu_head rcu;
  785. };
  786. /*
  787. * Empty header for FUSE opcodes without specific header needs.
  788. * Used as a placeholder in args->in_args[0] for consistency
  789. * across all FUSE operations, simplifying request handling.
  790. */
  791. struct fuse_zero_header {};
  792. static inline void fuse_set_zero_arg0(struct fuse_args *args)
  793. {
  794. args->in_args[0].size = sizeof(struct fuse_zero_header);
  795. args->in_args[0].value = NULL;
  796. }
  797. static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb)
  798. {
  799. return sb->s_fs_info;
  800. }
  801. static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
  802. {
  803. return get_fuse_mount_super(sb)->fc;
  804. }
  805. static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
  806. {
  807. return get_fuse_mount_super(inode->i_sb);
  808. }
  809. static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
  810. {
  811. return get_fuse_mount_super(inode->i_sb)->fc;
  812. }
  813. static inline struct fuse_inode *get_fuse_inode(const struct inode *inode)
  814. {
  815. return container_of(inode, struct fuse_inode, inode);
  816. }
  817. static inline u64 get_node_id(struct inode *inode)
  818. {
  819. return get_fuse_inode(inode)->nodeid;
  820. }
  821. static inline int invalid_nodeid(u64 nodeid)
  822. {
  823. return !nodeid || nodeid == FUSE_ROOT_ID;
  824. }
  825. static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
  826. {
  827. return atomic64_read(&fc->attr_version);
  828. }
  829. static inline u64 fuse_get_evict_ctr(struct fuse_conn *fc)
  830. {
  831. return atomic64_read(&fc->evict_ctr);
  832. }
  833. static inline bool fuse_stale_inode(const struct inode *inode, int generation,
  834. struct fuse_attr *attr)
  835. {
  836. return inode->i_generation != generation ||
  837. inode_wrong_type(inode, attr->mode);
  838. }
  839. static inline void fuse_make_bad(struct inode *inode)
  840. {
  841. set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state);
  842. }
  843. static inline bool fuse_is_bad(struct inode *inode)
  844. {
  845. return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
  846. }
  847. static inline bool fuse_inode_is_exclusive(const struct inode *inode)
  848. {
  849. const struct fuse_inode *fi = get_fuse_inode(inode);
  850. return test_bit(FUSE_I_EXCLUSIVE, &fi->state);
  851. }
  852. static inline struct folio **fuse_folios_alloc(unsigned int nfolios, gfp_t flags,
  853. struct fuse_folio_desc **desc)
  854. {
  855. struct folio **folios;
  856. folios = kzalloc(nfolios * (sizeof(struct folio *) +
  857. sizeof(struct fuse_folio_desc)), flags);
  858. *desc = (void *) (folios + nfolios);
  859. return folios;
  860. }
  861. static inline void fuse_folio_descs_length_init(struct fuse_folio_desc *descs,
  862. unsigned int index,
  863. unsigned int nr_folios)
  864. {
  865. int i;
  866. for (i = index; i < index + nr_folios; i++)
  867. descs[i].length = PAGE_SIZE - descs[i].offset;
  868. }
  869. static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket)
  870. {
  871. /* Need RCU protection to prevent use after free after the decrement */
  872. rcu_read_lock();
  873. if (atomic_dec_and_test(&bucket->count))
  874. wake_up(&bucket->waitq);
  875. rcu_read_unlock();
  876. }
  877. /** Device operations */
  878. extern const struct file_operations fuse_dev_operations;
  879. extern const struct dentry_operations fuse_dentry_operations;
  880. /**
  881. * Get a filled in inode
  882. */
  883. struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
  884. int generation, struct fuse_attr *attr,
  885. u64 attr_valid, u64 attr_version,
  886. u64 evict_ctr);
  887. int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
  888. struct fuse_entry_out *outarg, struct inode **inode);
  889. /**
  890. * Send FORGET command
  891. */
  892. void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
  893. u64 nodeid, u64 nlookup);
  894. struct fuse_forget_link *fuse_alloc_forget(void);
  895. /*
  896. * Initialize READ or READDIR request
  897. */
  898. struct fuse_io_args {
  899. union {
  900. struct {
  901. struct fuse_read_in in;
  902. u64 attr_ver;
  903. } read;
  904. struct {
  905. struct fuse_write_in in;
  906. struct fuse_write_out out;
  907. bool folio_locked;
  908. } write;
  909. };
  910. struct fuse_args_pages ap;
  911. struct fuse_io_priv *io;
  912. struct fuse_file *ff;
  913. };
  914. void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
  915. size_t count, int opcode);
  916. struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release);
  917. void fuse_file_free(struct fuse_file *ff);
  918. int fuse_finish_open(struct inode *inode, struct file *file);
  919. void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff,
  920. unsigned int flags);
  921. /**
  922. * Send RELEASE or RELEASEDIR request
  923. */
  924. void fuse_release_common(struct file *file, bool isdir);
  925. /**
  926. * Send FSYNC or FSYNCDIR request
  927. */
  928. int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
  929. int datasync, int opcode);
  930. /**
  931. * Notify poll wakeup
  932. */
  933. int fuse_notify_poll_wakeup(struct fuse_conn *fc,
  934. struct fuse_notify_poll_wakeup_out *outarg);
  935. /**
  936. * Initialize file operations on a regular file
  937. */
  938. void fuse_init_file_inode(struct inode *inode, unsigned int flags);
  939. /**
  940. * Initialize inode operations on regular files and special files
  941. */
  942. void fuse_init_common(struct inode *inode);
  943. /**
  944. * Initialize inode and file operations on a directory
  945. */
  946. void fuse_init_dir(struct inode *inode);
  947. /**
  948. * Initialize inode operations on a symlink
  949. */
  950. void fuse_init_symlink(struct inode *inode);
  951. /**
  952. * Change attributes of an inode
  953. */
  954. void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
  955. struct fuse_statx *sx,
  956. u64 attr_valid, u64 attr_version);
  957. void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
  958. struct fuse_statx *sx,
  959. u64 attr_valid, u32 cache_mask,
  960. u64 evict_ctr);
  961. u32 fuse_get_cache_mask(struct inode *inode);
  962. /**
  963. * Initialize the client device
  964. */
  965. int fuse_dev_init(void);
  966. /**
  967. * Cleanup the client device
  968. */
  969. void fuse_dev_cleanup(void);
  970. int fuse_ctl_init(void);
  971. void __exit fuse_ctl_cleanup(void);
  972. /**
  973. * Simple request sending that does request allocation and freeing
  974. */
  975. ssize_t __fuse_simple_request(struct mnt_idmap *idmap,
  976. struct fuse_mount *fm,
  977. struct fuse_args *args);
  978. static inline ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args)
  979. {
  980. return __fuse_simple_request(&invalid_mnt_idmap, fm, args);
  981. }
  982. static inline ssize_t fuse_simple_idmap_request(struct mnt_idmap *idmap,
  983. struct fuse_mount *fm,
  984. struct fuse_args *args)
  985. {
  986. return __fuse_simple_request(idmap, fm, args);
  987. }
  988. int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
  989. gfp_t gfp_flags);
  990. /**
  991. * Assign a unique id to a fuse request
  992. */
  993. void fuse_request_assign_unique(struct fuse_iqueue *fiq, struct fuse_req *req);
  994. /**
  995. * End a finished request
  996. */
  997. void fuse_request_end(struct fuse_req *req);
  998. /* Abort all requests */
  999. void fuse_abort_conn(struct fuse_conn *fc);
  1000. void fuse_wait_aborted(struct fuse_conn *fc);
  1001. /* Check if any requests timed out */
  1002. void fuse_check_timeout(struct work_struct *work);
  1003. void fuse_dentry_tree_init(void);
  1004. void fuse_dentry_tree_cleanup(void);
  1005. void fuse_epoch_work(struct work_struct *work);
  1006. /**
  1007. * Invalidate inode attributes
  1008. */
  1009. /* Attributes possibly changed on data modification */
  1010. #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
  1011. /* Attributes possibly changed on data and/or size modification */
  1012. #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
  1013. void fuse_invalidate_attr(struct inode *inode);
  1014. void fuse_invalidate_attr_mask(struct inode *inode, u32 mask);
  1015. void fuse_invalidate_entry_cache(struct dentry *entry);
  1016. void fuse_invalidate_atime(struct inode *inode);
  1017. u64 fuse_time_to_jiffies(u64 sec, u32 nsec);
  1018. #define ATTR_TIMEOUT(o) \
  1019. fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
  1020. void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
  1021. /**
  1022. * Acquire reference to fuse_conn
  1023. */
  1024. struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
  1025. /**
  1026. * Initialize the fuse processing queue
  1027. */
  1028. void fuse_pqueue_init(struct fuse_pqueue *fpq);
  1029. /**
  1030. * Initialize fuse_conn
  1031. */
  1032. void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
  1033. struct user_namespace *user_ns,
  1034. const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
  1035. /**
  1036. * Release reference to fuse_conn
  1037. */
  1038. void fuse_conn_put(struct fuse_conn *fc);
  1039. struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
  1040. struct fuse_dev *fuse_dev_alloc(void);
  1041. void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
  1042. void fuse_dev_free(struct fuse_dev *fud);
  1043. int fuse_send_init(struct fuse_mount *fm);
  1044. /**
  1045. * Fill in superblock and initialize fuse connection
  1046. * @sb: partially-initialized superblock to fill in
  1047. * @ctx: mount context
  1048. */
  1049. int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
  1050. /*
  1051. * Remove the mount from the connection
  1052. *
  1053. * Returns whether this was the last mount
  1054. */
  1055. bool fuse_mount_remove(struct fuse_mount *fm);
  1056. /*
  1057. * Setup context ops for submounts
  1058. */
  1059. int fuse_init_fs_context_submount(struct fs_context *fsc);
  1060. /*
  1061. * Shut down the connection (possibly sending DESTROY request).
  1062. */
  1063. void fuse_conn_destroy(struct fuse_mount *fm);
  1064. /* Drop the connection and free the fuse mount */
  1065. void fuse_mount_destroy(struct fuse_mount *fm);
  1066. /**
  1067. * Add connection to control filesystem
  1068. */
  1069. int fuse_ctl_add_conn(struct fuse_conn *fc);
  1070. /**
  1071. * Remove connection from control filesystem
  1072. */
  1073. void fuse_ctl_remove_conn(struct fuse_conn *fc);
  1074. /**
  1075. * Is file type valid?
  1076. */
  1077. int fuse_valid_type(int m);
  1078. bool fuse_invalid_attr(struct fuse_attr *attr);
  1079. /**
  1080. * Is current process allowed to perform filesystem operation?
  1081. */
  1082. bool fuse_allow_current_process(struct fuse_conn *fc);
  1083. u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
  1084. void fuse_flush_time_update(struct inode *inode);
  1085. void fuse_update_ctime(struct inode *inode);
  1086. int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask);
  1087. void fuse_flush_writepages(struct inode *inode);
  1088. void fuse_set_nowrite(struct inode *inode);
  1089. void fuse_release_nowrite(struct inode *inode);
  1090. /**
  1091. * Scan all fuse_mounts belonging to fc to find the first where
  1092. * ilookup5() returns a result. Return that result and the
  1093. * respective fuse_mount in *fm (unless fm is NULL).
  1094. *
  1095. * The caller must hold fc->killsb.
  1096. */
  1097. struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
  1098. struct fuse_mount **fm);
  1099. /**
  1100. * File-system tells the kernel to invalidate cache for the given node id.
  1101. */
  1102. int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
  1103. loff_t offset, loff_t len);
  1104. /**
  1105. * File-system tells the kernel to invalidate parent attributes and
  1106. * the dentry matching parent/name.
  1107. *
  1108. * If the child_nodeid is non-zero and:
  1109. * - matches the inode number for the dentry matching parent/name,
  1110. * - is not a mount point
  1111. * - is a file or oan empty directory
  1112. * then the dentry is unhashed (d_delete()).
  1113. */
  1114. int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
  1115. u64 child_nodeid, struct qstr *name, u32 flags);
  1116. /*
  1117. * Try to prune this inode. If neither the inode itself nor dentries associated
  1118. * with this inode have any external reference, then the inode can be freed.
  1119. */
  1120. void fuse_try_prune_one_inode(struct fuse_conn *fc, u64 nodeid);
  1121. int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
  1122. bool isdir);
  1123. /**
  1124. * fuse_direct_io() flags
  1125. */
  1126. /** If set, it is WRITE; otherwise - READ */
  1127. #define FUSE_DIO_WRITE (1 << 0)
  1128. /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
  1129. #define FUSE_DIO_CUSE (1 << 1)
  1130. ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  1131. loff_t *ppos, int flags);
  1132. long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
  1133. unsigned int flags);
  1134. long fuse_ioctl_common(struct file *file, unsigned int cmd,
  1135. unsigned long arg, unsigned int flags);
  1136. __poll_t fuse_file_poll(struct file *file, poll_table *wait);
  1137. int fuse_dev_release(struct inode *inode, struct file *file);
  1138. bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written);
  1139. int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
  1140. int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
  1141. int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
  1142. struct iattr *attr, struct file *file);
  1143. void fuse_set_initialized(struct fuse_conn *fc);
  1144. void fuse_unlock_inode(struct inode *inode, bool locked);
  1145. bool fuse_lock_inode(struct inode *inode);
  1146. int fuse_setxattr(struct inode *inode, const char *name, const void *value,
  1147. size_t size, int flags, unsigned int extra_flags);
  1148. ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
  1149. size_t size);
  1150. ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
  1151. int fuse_removexattr(struct inode *inode, const char *name);
  1152. extern const struct xattr_handler * const fuse_xattr_handlers[];
  1153. struct posix_acl;
  1154. struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu);
  1155. struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap,
  1156. struct dentry *dentry, int type);
  1157. int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry,
  1158. struct posix_acl *acl, int type);
  1159. /* readdir.c */
  1160. int fuse_readdir(struct file *file, struct dir_context *ctx);
  1161. /**
  1162. * Return the number of bytes in an arguments list
  1163. */
  1164. unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
  1165. /**
  1166. * Get the next unique ID for a request
  1167. */
  1168. u64 fuse_get_unique(struct fuse_iqueue *fiq);
  1169. void fuse_free_conn(struct fuse_conn *fc);
  1170. /* dax.c */
  1171. #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
  1172. ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
  1173. ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
  1174. int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
  1175. int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
  1176. int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode,
  1177. struct dax_device *dax_dev);
  1178. void fuse_dax_conn_free(struct fuse_conn *fc);
  1179. bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
  1180. void fuse_dax_inode_init(struct inode *inode, unsigned int flags);
  1181. void fuse_dax_inode_cleanup(struct inode *inode);
  1182. void fuse_dax_dontcache(struct inode *inode, unsigned int flags);
  1183. bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
  1184. void fuse_dax_cancel_work(struct fuse_conn *fc);
  1185. /* ioctl.c */
  1186. long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1187. long fuse_file_compat_ioctl(struct file *file, unsigned int cmd,
  1188. unsigned long arg);
  1189. int fuse_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
  1190. int fuse_fileattr_set(struct mnt_idmap *idmap,
  1191. struct dentry *dentry, struct file_kattr *fa);
  1192. /* iomode.c */
  1193. int fuse_file_cached_io_open(struct inode *inode, struct fuse_file *ff);
  1194. int fuse_inode_uncached_io_start(struct fuse_inode *fi,
  1195. struct fuse_backing *fb);
  1196. void fuse_inode_uncached_io_end(struct fuse_inode *fi);
  1197. int fuse_file_io_open(struct file *file, struct inode *inode);
  1198. void fuse_file_io_release(struct fuse_file *ff, struct inode *inode);
  1199. /* file.c */
  1200. struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,
  1201. unsigned int open_flags, bool isdir);
  1202. void fuse_file_release(struct inode *inode, struct fuse_file *ff,
  1203. unsigned int open_flags, fl_owner_t id, bool isdir);
  1204. /* backing.c */
  1205. #ifdef CONFIG_FUSE_PASSTHROUGH
  1206. struct fuse_backing *fuse_backing_get(struct fuse_backing *fb);
  1207. void fuse_backing_put(struct fuse_backing *fb);
  1208. struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id);
  1209. #else
  1210. static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
  1211. {
  1212. return NULL;
  1213. }
  1214. static inline void fuse_backing_put(struct fuse_backing *fb)
  1215. {
  1216. }
  1217. static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
  1218. int backing_id)
  1219. {
  1220. return NULL;
  1221. }
  1222. #endif
  1223. void fuse_backing_files_init(struct fuse_conn *fc);
  1224. void fuse_backing_files_free(struct fuse_conn *fc);
  1225. int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map);
  1226. int fuse_backing_close(struct fuse_conn *fc, int backing_id);
  1227. /* passthrough.c */
  1228. static inline struct fuse_backing *fuse_inode_backing(struct fuse_inode *fi)
  1229. {
  1230. #ifdef CONFIG_FUSE_PASSTHROUGH
  1231. return READ_ONCE(fi->fb);
  1232. #else
  1233. return NULL;
  1234. #endif
  1235. }
  1236. static inline struct fuse_backing *fuse_inode_backing_set(struct fuse_inode *fi,
  1237. struct fuse_backing *fb)
  1238. {
  1239. #ifdef CONFIG_FUSE_PASSTHROUGH
  1240. return xchg(&fi->fb, fb);
  1241. #else
  1242. return NULL;
  1243. #endif
  1244. }
  1245. struct fuse_backing *fuse_passthrough_open(struct file *file, int backing_id);
  1246. void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb);
  1247. static inline struct file *fuse_file_passthrough(struct fuse_file *ff)
  1248. {
  1249. #ifdef CONFIG_FUSE_PASSTHROUGH
  1250. return ff->passthrough;
  1251. #else
  1252. return NULL;
  1253. #endif
  1254. }
  1255. ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter);
  1256. ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *iter);
  1257. ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos,
  1258. struct pipe_inode_info *pipe,
  1259. size_t len, unsigned int flags);
  1260. ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
  1261. struct file *out, loff_t *ppos,
  1262. size_t len, unsigned int flags);
  1263. ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
  1264. #ifdef CONFIG_SYSCTL
  1265. extern int fuse_sysctl_register(void);
  1266. extern void fuse_sysctl_unregister(void);
  1267. #else
  1268. #define fuse_sysctl_register() (0)
  1269. #define fuse_sysctl_unregister() do { } while (0)
  1270. #endif /* CONFIG_SYSCTL */
  1271. #endif /* _FS_FUSE_I_H */