Merge tag 'fuse-update-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi...
[linux-2.6-block.git] / fs / fuse / fuse_i.h
CommitLineData
d8a5ba45
MS
1/*
2 FUSE: Filesystem in Userspace
1729a16c 3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
d8a5ba45
MS
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
29d434b3
TH
9#ifndef _FS_FUSE_I_H
10#define _FS_FUSE_I_H
11
f2294482
KS
12#ifndef pr_fmt
13# define pr_fmt(fmt) "fuse: " fmt
14#endif
15
d8a5ba45
MS
16#include <linux/fuse.h>
17#include <linux/fs.h>
51eb01e7 18#include <linux/mount.h>
d8a5ba45
MS
19#include <linux/wait.h>
20#include <linux/list.h>
21#include <linux/spinlock.h>
22#include <linux/mm.h>
23#include <linux/backing-dev.h>
bafa9654 24#include <linux/mutex.h>
3be5a52b 25#include <linux/rwsem.h>
95668a69
TH
26#include <linux/rbtree.h>
27#include <linux/poll.h>
5a18ec17 28#include <linux/workqueue.h>
744742d6 29#include <linux/kref.h>
60bcc88a 30#include <linux/xattr.h>
0b6e9ea0 31#include <linux/pid_namespace.h>
4e8c2eb5 32#include <linux/refcount.h>
8cb08329 33#include <linux/user_namespace.h>
d8a5ba45 34
5da784cc
CS
35/** Default max number of pages that can be used in a single read request */
36#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
37
38/** Maximum of max_pages received in init_out */
39#define FUSE_MAX_MAX_PAGES 256
334f485d 40
3be5a52b
MS
41/** Bias for fi->writectr, meaning new writepages must not be sent */
42#define FUSE_NOWRITE INT_MIN
43
1d3d752b
MS
44/** It could be as large as PATH_MAX, but would that have any uses? */
45#define FUSE_NAME_MAX 1024
46
bafa9654 47/** Number of dentries for each connection in the control filesystem */
79a9d994 48#define FUSE_CTL_NUM_DENTRIES 5
bafa9654 49
bafa9654
MS
50/** List of active connections */
51extern struct list_head fuse_conn_list;
52
53/** Global mutex protecting fuse_conn_list and the control filesystem */
54extern struct mutex fuse_mutex;
413ef8cb 55
79a9d994
CH
56/** Module parameters */
57extern unsigned max_user_bgreq;
58extern unsigned max_user_congthresh;
59
07e77dca
MS
60/* One forget request */
61struct fuse_forget_link {
02c048b9 62 struct fuse_forget_one forget_one;
07e77dca
MS
63 struct fuse_forget_link *next;
64};
65
c4d361f6
KJ
66/* Submount lookup tracking */
67struct fuse_submount_lookup {
68 /** Refcount */
69 refcount_t count;
70
71 /** Unique ID, which identifies the inode between userspace
72 * and kernel */
73 u64 nodeid;
74
75 /** The request used for sending the FORGET message */
76 struct fuse_forget_link *forget;
77};
78
7dc4e97a
AG
79/** Container for data related to mapping to backing file */
80struct fuse_backing {
81 struct file *file;
44350256 82 struct cred *cred;
7dc4e97a
AG
83
84 /** refcount */
85 refcount_t count;
86 struct rcu_head rcu;
87};
88
d8a5ba45
MS
89/** FUSE inode */
90struct fuse_inode {
91 /** Inode data */
92 struct inode inode;
93
94 /** Unique ID, which identifies the inode between userspace
95 * and kernel */
96 u64 nodeid;
97
9e6268db
MS
98 /** Number of lookups on this inode */
99 u64 nlookup;
100
e5e5558e 101 /** The request used for sending the FORGET message */
07e77dca 102 struct fuse_forget_link *forget;
e5e5558e 103
d8a5ba45 104 /** Time in jiffies until the file attributes are valid */
0a0898cf 105 u64 i_time;
ebc14c4d 106
2f1e8196
MS
107 /* Which attributes are invalid */
108 u32 inval_mask;
109
ebc14c4d
MS
110 /** The sticky bit in inode->i_mode may have been removed, so
111 preserve the original mode */
541af6a0 112 umode_t orig_i_mode;
1fb69e78 113
972f4c46
MS
114 /* Cache birthtime */
115 struct timespec64 i_btime;
116
45c72cd7
PS
117 /** 64 bit inode number */
118 u64 orig_ino;
119
1fb69e78
MS
120 /** Version of last attribute change */
121 u64 attr_version;
93a8c3cd 122
ab2257e9 123 union {
cb098dd2 124 /* read/write io cache (regular file only) */
ab2257e9 125 struct {
f15ecfef 126 /* Files usable in writepage. Protected by fi->lock */
ab2257e9 127 struct list_head write_files;
3be5a52b 128
ab2257e9
MS
129 /* Writepages pending on truncate or fsync */
130 struct list_head queued_writes;
3be5a52b 131
ab2257e9
MS
132 /* Number of sent writes, a negative bias
133 * (FUSE_NOWRITE) means more writes are blocked */
134 int writectr;
3be5a52b 135
cb098dd2
AG
136 /** Number of files/maps using page cache */
137 int iocachectr;
138
ab2257e9
MS
139 /* Waitq for writepage completion */
140 wait_queue_head_t page_waitq;
3be5a52b 141
205c1d80
AG
142 /* waitq for direct-io completion */
143 wait_queue_head_t direct_io_waitq;
144
ab2257e9 145 /* List of writepage requestst (pending or sent) */
6b2fb799 146 struct rb_root writepages;
ab2257e9 147 };
4582a4ab 148
ab2257e9
MS
149 /* readdir cache (directory only) */
150 struct {
151 /* true if fully cached */
152 bool cached;
69e34551 153
ab2257e9
MS
154 /* size of cache */
155 loff_t size;
69e34551 156
ab2257e9
MS
157 /* position at end of cache (position of next entry) */
158 loff_t pos;
69e34551 159
ab2257e9
MS
160 /* version of the cache */
161 u64 version;
3494927e 162
ab2257e9
MS
163 /* modification time of directory when cache was
164 * started */
165 struct timespec64 mtime;
7118883b 166
ab2257e9
MS
167 /* iversion of directory when cache was started */
168 u64 iversion;
261aaba7 169
ab2257e9
MS
170 /* protects above fields */
171 spinlock_t lock;
172 } rdc;
173 };
69e34551 174
4582a4ab
FS
175 /** Miscellaneous bits describing inode state */
176 unsigned long state;
5c672ab3
MS
177
178 /** Lock for serializing lookup and readdir for back compatibility*/
179 struct mutex mutex;
f15ecfef
KT
180
181 /** Lock to protect write related fields */
182 spinlock_t lock;
c2d0ad00
VG
183
184#ifdef CONFIG_FUSE_DAX
185 /*
186 * Dax specific inode data
187 */
188 struct fuse_inode_dax *dax;
189#endif
c4d361f6
KJ
190 /** Submount specific lookup tracking */
191 struct fuse_submount_lookup *submount_lookup;
7dc4e97a
AG
192#ifdef CONFIG_FUSE_PASSTHROUGH
193 /** Reference to backing file in passthrough mode */
194 struct fuse_backing *fb;
195#endif
4582a4ab
FS
196};
197
198/** FUSE inode state bits */
199enum {
200 /** Advise readdirplus */
201 FUSE_I_ADVISE_RDPLUS,
6314efee
MS
202 /** Initialized with readdirplus */
203 FUSE_I_INIT_RDPLUS,
06a7c3c2
MP
204 /** An operation changing file size is in progress */
205 FUSE_I_SIZE_UNSTABLE,
5d069dbe
MS
206 /* Bad inode */
207 FUSE_I_BAD,
972f4c46
MS
208 /* Has btime */
209 FUSE_I_BTIME,
cb098dd2
AG
210 /* Wants or already has page cache IO */
211 FUSE_I_CACHE_IO_MODE,
d8a5ba45
MS
212};
213
da5e4714 214struct fuse_conn;
fcee216b 215struct fuse_mount;
fc8ff397 216union fuse_file_args;
da5e4714 217
b6aeaded
MS
218/** FUSE specific file data */
219struct fuse_file {
da5e4714 220 /** Fuse connection for this file */
fcee216b 221 struct fuse_mount *fm;
da5e4714 222
fc8ff397
AG
223 /* Argument space reserved for open/release */
224 union fuse_file_args *args;
b6aeaded 225
acf99433
TH
226 /** Kernel file handle guaranteed to be unique */
227 u64 kh;
228
b6aeaded
MS
229 /** File handle used by userspace */
230 u64 fh;
c756e0a4 231
da5e4714
MS
232 /** Node id of this file */
233 u64 nodeid;
234
c756e0a4 235 /** Refcount */
4e8c2eb5 236 refcount_t count;
93a8c3cd 237
c7b7143c
MS
238 /** FOPEN_* flags returned by open */
239 u32 open_flags;
240
93a8c3cd
MS
241 /** Entry on inode's write_files list */
242 struct list_head write_entry;
95668a69 243
5d7bc7e8
MS
244 /* Readdir related */
245 struct {
5d7bc7e8
MS
246 /* Dir stream position */
247 loff_t pos;
248
249 /* Offset in cache */
250 loff_t cache_off;
3494927e
MS
251
252 /* Version of cache we are reading */
253 u64 version;
254
5d7bc7e8
MS
255 } readdir;
256
95668a69
TH
257 /** RB node to be linked on fuse_conn->polled_files */
258 struct rb_node polled_node;
259
260 /** Wait queue head for poll */
261 wait_queue_head_t poll_wait;
37fb3a30 262
cb098dd2
AG
263 /** Does file hold a fi->iocachectr refcount? */
264 enum { IOM_NONE, IOM_CACHED, IOM_UNCACHED } iomode;
265
4a90451b
AG
266#ifdef CONFIG_FUSE_PASSTHROUGH
267 /** Reference to backing file in passthrough mode */
268 struct file *passthrough;
269 const struct cred *cred;
270#endif
271
37fb3a30
MS
272 /** Has flock been performed on this file? */
273 bool flock:1;
b6aeaded
MS
274};
275
334f485d
MS
276/** One input argument of a request */
277struct fuse_in_arg {
278 unsigned size;
279 const void *value;
280};
281
334f485d
MS
282/** One output argument of a request */
283struct fuse_arg {
284 unsigned size;
285 void *value;
286};
287
b2430d75
MP
288/** FUSE page descriptor */
289struct fuse_page_desc {
290 unsigned int length;
291 unsigned int offset;
292};
293
7078187a 294struct fuse_args {
d5b48543 295 uint64_t nodeid;
1f4e9d03 296 uint32_t opcode;
15d937d7
MS
297 uint8_t in_numargs;
298 uint8_t out_numargs;
299 uint8_t ext_idx;
c500ebaa 300 bool force:1;
454a7613 301 bool noreply:1;
e413754b 302 bool nocreds:1;
68583165
MS
303 bool in_pages:1;
304 bool out_pages:1;
0c4bcfde 305 bool user_pages:1;
1f4e9d03 306 bool out_argvar:1;
68583165
MS
307 bool page_zeroing:1;
308 bool page_replace:1;
bb737bbe 309 bool may_block:1;
15d937d7 310 bool is_ext:1;
738adade 311 bool is_pinned:1;
d5b48543 312 struct fuse_in_arg in_args[3];
d5b48543 313 struct fuse_arg out_args[2];
fcee216b 314 void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error);
7078187a
MS
315};
316
68583165
MS
317struct fuse_args_pages {
318 struct fuse_args args;
319 struct page **pages;
320 struct fuse_page_desc *descs;
321 unsigned int num_pages;
322};
323
fc8ff397
AG
324struct fuse_release_args {
325 struct fuse_args args;
326 struct fuse_release_in inarg;
327 struct inode *inode;
328};
329
330union fuse_file_args {
331 /* Used during open() */
332 struct fuse_open_out open_outarg;
333 /* Used during release() */
334 struct fuse_release_args release_args;
335};
336
7078187a
MS
337#define FUSE_ARGS(args) struct fuse_args args = {}
338
01e9d11a
MP
339/** The request IO state (for asynchronous processing) */
340struct fuse_io_priv {
744742d6 341 struct kref refcnt;
01e9d11a
MP
342 int async;
343 spinlock_t lock;
344 unsigned reqs;
345 ssize_t bytes;
346 size_t size;
347 __u64 offset;
348 bool write;
61c12b49 349 bool should_dirty;
01e9d11a
MP
350 int err;
351 struct kiocb *iocb;
9d5722b7 352 struct completion *done;
7879c4e5 353 bool blocking;
01e9d11a
MP
354};
355
e1c0eecb 356#define FUSE_IO_PRIV_SYNC(i) \
744742d6 357{ \
1e24edca 358 .refcnt = KREF_INIT(1), \
744742d6 359 .async = 0, \
e1c0eecb 360 .iocb = i, \
744742d6
SF
361}
362
825d6d33
MS
363/**
364 * Request flags
365 *
366 * FR_ISREPLY: set if the request has reply
367 * FR_FORCE: force sending of the request even if interrupted
368 * FR_BACKGROUND: request is sent in the background
369 * FR_WAITING: request is counted as "waiting"
370 * FR_ABORTED: the request was aborted
371 * FR_INTERRUPTED: the request has been interrupted
372 * FR_LOCKED: data is being copied to/from the request
33e14b4d
MS
373 * FR_PENDING: request is not yet in userspace
374 * FR_SENT: request is in userspace, waiting for an answer
375 * FR_FINISHED: request is finished
77cd9d48 376 * FR_PRIVATE: request is on private list
3e8cb8b2 377 * FR_ASYNC: request is asynchronous
825d6d33
MS
378 */
379enum fuse_req_flag {
380 FR_ISREPLY,
381 FR_FORCE,
382 FR_BACKGROUND,
383 FR_WAITING,
384 FR_ABORTED,
385 FR_INTERRUPTED,
386 FR_LOCKED,
33e14b4d
MS
387 FR_PENDING,
388 FR_SENT,
389 FR_FINISHED,
77cd9d48 390 FR_PRIVATE,
3e8cb8b2 391 FR_ASYNC,
825d6d33
MS
392};
393
334f485d
MS
394/**
395 * A request to the client
dc00809a
MS
396 *
397 * .waitq.lock protects the following fields:
398 * - FR_ABORTED
399 * - FR_LOCKED (may also be modified under fc->lock, tested under both)
334f485d
MS
400 */
401struct fuse_req {
ce1d5a49
MS
402 /** This can be on either pending processing or io lists in
403 fuse_conn */
334f485d
MS
404 struct list_head list;
405
a4d27e75
MS
406 /** Entry on the interrupts list */
407 struct list_head intr_entry;
408
12597287
MS
409 /* Input/output arguments */
410 struct fuse_args *args;
411
334f485d 412 /** refcount */
ec99f6d3 413 refcount_t count;
334f485d 414
825d6d33
MS
415 /* Request flags, updated with test/set/clear_bit() */
416 unsigned long flags;
9bc5ddda 417
d4993774
MS
418 /* The request input header */
419 struct {
420 struct fuse_in_header h;
421 } in;
334f485d 422
d4993774
MS
423 /* The request output header */
424 struct {
425 struct fuse_out_header h;
426 } out;
334f485d
MS
427
428 /** Used to wake up the task waiting for completion of request*/
429 wait_queue_head_t waitq;
430
a62a8ef9
SH
431#if IS_ENABLED(CONFIG_VIRTIO_FS)
432 /** virtio-fs's physically contiguous buffer for in and out args */
433 void *argbuf;
434#endif
24754db2 435
fcee216b
MR
436 /** fuse_mount this request belongs to */
437 struct fuse_mount *fm;
334f485d
MS
438};
439
ae3aad77
SH
440struct fuse_iqueue;
441
442/**
443 * Input queue callbacks
444 *
445 * Input queue signalling is device-specific. For example, the /dev/fuse file
446 * uses fiq->waitq and fasync to wake processes that are waiting on queue
447 * readiness. These callbacks allow other device types to respond to input
448 * queue activity.
449 */
450struct fuse_iqueue_ops {
451 /**
452 * Signal that a forget has been queued
453 */
454 void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
455 __releases(fiq->lock);
456
457 /**
458 * Signal that an INTERRUPT request has been queued
459 */
460 void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
461 __releases(fiq->lock);
462
463 /**
464 * Signal that a request has been queued
465 */
466 void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
467 __releases(fiq->lock);
a62a8ef9
SH
468
469 /**
470 * Clean up when fuse_iqueue is destroyed
471 */
472 void (*release)(struct fuse_iqueue *fiq);
ae3aad77
SH
473};
474
475/** /dev/fuse input queue operations */
476extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
477
f88996a9 478struct fuse_iqueue {
e16714d8
MS
479 /** Connection established */
480 unsigned connected;
481
76e43c8c
EB
482 /** Lock protecting accesses to members of this structure */
483 spinlock_t lock;
484
f88996a9
MS
485 /** Readers of the connection are waiting on this */
486 wait_queue_head_t waitq;
487
488 /** The next unique request id */
489 u64 reqctr;
490
491 /** The list of pending requests */
492 struct list_head pending;
493
494 /** Pending interrupts */
495 struct list_head interrupts;
496
497 /** Queue of pending forgets */
498 struct fuse_forget_link forget_list_head;
499 struct fuse_forget_link *forget_list_tail;
500
501 /** Batching of FORGET requests (positive indicates FORGET batch) */
502 int forget_batch;
503
504 /** O_ASYNC requests */
505 struct fasync_struct *fasync;
ae3aad77
SH
506
507 /** Device-specific callbacks */
508 const struct fuse_iqueue_ops *ops;
509
510 /** Device-specific state */
511 void *priv;
f88996a9
MS
512};
513
be2ff42c
KT
514#define FUSE_PQ_HASH_BITS 8
515#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
516
3a2b5b9c 517struct fuse_pqueue {
e96edd94
MS
518 /** Connection established */
519 unsigned connected;
520
45a91cb1
MS
521 /** Lock protecting accessess to members of this structure */
522 spinlock_t lock;
523
be2ff42c
KT
524 /** Hash table of requests being processed */
525 struct list_head *processing;
3a2b5b9c
MS
526
527 /** The list of requests under I/O */
528 struct list_head io;
529};
530
cc080e9e
MS
531/**
532 * Fuse device instance
533 */
534struct fuse_dev {
535 /** Fuse connection for this device */
536 struct fuse_conn *fc;
537
c3696046
MS
538 /** Processing queue */
539 struct fuse_pqueue pq;
540
cc080e9e
MS
541 /** list entry on fc->devices */
542 struct list_head entry;
543};
544
780b1b95
JX
545enum fuse_dax_mode {
546 FUSE_DAX_INODE_DEFAULT, /* default */
547 FUSE_DAX_ALWAYS, /* "-o dax=always" */
548 FUSE_DAX_NEVER, /* "-o dax=never" */
549 FUSE_DAX_INODE_USER, /* "-o dax=inode" */
550};
551
552static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode)
553{
554 return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER;
555}
556
0cc2656c
SH
557struct fuse_fs_context {
558 int fd;
62dd1fc8 559 struct file *file;
0cc2656c
SH
560 unsigned int rootmode;
561 kuid_t user_id;
562 kgid_t group_id;
563 bool is_bdev:1;
564 bool fd_present:1;
565 bool rootmode_present:1;
566 bool user_id_present:1;
567 bool group_id_present:1;
568 bool default_permissions:1;
569 bool allow_other:1;
783863d6 570 bool destroy:1;
15c8e72e
VG
571 bool no_control:1;
572 bool no_force_umount:1;
f4fd4ae3 573 bool legacy_opts_show:1;
780b1b95 574 enum fuse_dax_mode dax_mode;
0cc2656c
SH
575 unsigned int max_read;
576 unsigned int blksize;
577 const char *subtype;
578
1dd53957
VG
579 /* DAX device, may be NULL */
580 struct dax_device *dax_dev;
581
0cc2656c
SH
582 /* fuse_dev pointer to fill in, should contain NULL on entry */
583 void **fudptr;
584};
585
660585b5
MS
586struct fuse_sync_bucket {
587 /* count is a possible scalability bottleneck */
588 atomic_t count;
589 wait_queue_head_t waitq;
590 struct rcu_head rcu;
591};
592
d8a5ba45
MS
593/**
594 * A Fuse connection.
595 *
fcee216b
MR
596 * This structure is created, when the root filesystem is mounted, and
597 * is destroyed, when the client device is closed and the last
598 * fuse_mount is destroyed.
d8a5ba45
MS
599 */
600struct fuse_conn {
d7133114
MS
601 /** Lock protecting accessess to members of this structure */
602 spinlock_t lock;
603
bafa9654 604 /** Refcount */
095fc40a 605 refcount_t count;
bafa9654 606
c3696046
MS
607 /** Number of fuse_dev's */
608 atomic_t dev_count;
609
dd3e2c55
AV
610 struct rcu_head rcu;
611
d8a5ba45 612 /** The user id for this mount */
499dcf20 613 kuid_t user_id;
d8a5ba45 614
87729a55 615 /** The group id for this mount */
499dcf20 616 kgid_t group_id;
87729a55 617
0b6e9ea0
SF
618 /** The pid namespace for this mount */
619 struct pid_namespace *pid_ns;
620
8cb08329
EB
621 /** The user namespace for this mount */
622 struct user_namespace *user_ns;
623
db50b96c
MS
624 /** Maximum read size */
625 unsigned max_read;
626
413ef8cb
MS
627 /** Maximum write size */
628 unsigned max_write;
629
4b91459a 630 /** Maximum number of pages that can be used in a single request */
5da784cc
CS
631 unsigned int max_pages;
632
a7f0d7aa
CK
633 /** Constrain ->max_pages to this value during feature negotiation */
634 unsigned int max_pages_limit;
635
f88996a9
MS
636 /** Input queue */
637 struct fuse_iqueue iq;
334f485d 638
acf99433 639 /** The next unique kernel file handle */
75126f55 640 atomic64_t khctr;
acf99433 641
95668a69
TH
642 /** rbtree of fuse_files waiting for poll events indexed by ph */
643 struct rb_root polled_files;
644
7a6d3c8b
CH
645 /** Maximum number of outstanding background requests */
646 unsigned max_background;
647
648 /** Number of background requests at which congestion starts */
649 unsigned congestion_threshold;
650
08a53cdc
MS
651 /** Number of requests currently in the background */
652 unsigned num_background;
653
d12def1b
MS
654 /** Number of background requests currently queued for userspace */
655 unsigned active_background;
656
657 /** The list of background requests set aside for later queuing */
658 struct list_head bg_queue;
659
ae2dffa3
KT
660 /** Protects: max_background, congestion_threshold, num_background,
661 * active_background, bg_queue, blocked */
662 spinlock_t bg_lock;
663
796523fb
MP
664 /** Flag indicating that INIT reply has been received. Allocating
665 * any fuse request will be suspended until the flag is set */
666 int initialized;
667
08a53cdc
MS
668 /** Flag indicating if connection is blocked. This will be
669 the case before the INIT reply is received, and if there
670 are too many outstading backgrounds requests */
671 int blocked;
672
673 /** waitq for blocked connection */
674 wait_queue_head_t blocked_waitq;
de5e3dec 675
69a53bf2
MS
676 /** Connection established, cleared on umount, connection
677 abort and device release */
095da6cb 678 unsigned connected;
1e9a4ed9 679
3b7008b2
SL
680 /** Connection aborted via sysfs */
681 bool aborted;
682
095da6cb
MS
683 /** Connection failed (version mismatch). Cannot race with
684 setting other bitfields since it is only set once in INIT
685 reply, before any other request, and never cleared */
1729a16c 686 unsigned conn_error:1;
334f485d 687
0ec7ca41 688 /** Connection successful. Only set in INIT */
1729a16c 689 unsigned conn_init:1;
0ec7ca41 690
704528d8 691 /** Do readahead asynchronously? Only set in INIT */
1729a16c 692 unsigned async_read:1;
9cd68455 693
3b7008b2
SL
694 /** Return an unique read error after abort. Only set in INIT */
695 unsigned abort_err:1;
696
6ff958ed 697 /** Do not send separate SETATTR request before open(O_TRUNC) */
1729a16c 698 unsigned atomic_o_trunc:1;
6ff958ed 699
33670fa2 700 /** Filesystem supports NFS exporting. Only set in INIT */
1729a16c 701 unsigned export_support:1;
33670fa2 702
d5cd66c5
PE
703 /** write-back cache policy (default is write-through) */
704 unsigned writeback_cache:1;
705
5c672ab3
MS
706 /** allow parallel lookups and readdir (default is serialized) */
707 unsigned parallel_dirops:1;
708
5e940c1d
MS
709 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
710 unsigned handle_killpriv:1;
711
5571f1e6
DS
712 /** cache READLINK responses in page cache */
713 unsigned cache_symlinks:1;
714
f4fd4ae3
VG
715 /* show legacy mount options */
716 unsigned int legacy_opts_show:1;
717
63f9909f
VG
718 /*
719 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on
720 * write/trunc only if caller did not have CAP_FSETID. sgid is killed
721 * on write/truncate only if caller did not have CAP_FSETID as well as
722 * file has group execute permission.
723 */
724 unsigned handle_killpriv_v2:1;
725
095da6cb
MS
726 /*
727 * The following bitfields are only for optimization purposes
728 * and hence races in setting them will not cause malfunction
729 */
730
7678ac50
AG
731 /** Is open/release not implemented by fs? */
732 unsigned no_open:1;
733
d9a9ea94
CA
734 /** Is opendir/releasedir not implemented by fs? */
735 unsigned no_opendir:1;
736
b6aeaded 737 /** Is fsync not implemented by fs? */
1729a16c 738 unsigned no_fsync:1;
b6aeaded 739
82547981 740 /** Is fsyncdir not implemented by fs? */
1729a16c 741 unsigned no_fsyncdir:1;
82547981 742
b6aeaded 743 /** Is flush not implemented by fs? */
1729a16c 744 unsigned no_flush:1;
b6aeaded 745
92a8780e 746 /** Is setxattr not implemented by fs? */
1729a16c 747 unsigned no_setxattr:1;
92a8780e 748
52a4c95f
VG
749 /** Does file server support extended setxattr */
750 unsigned setxattr_ext:1;
751
92a8780e 752 /** Is getxattr not implemented by fs? */
1729a16c 753 unsigned no_getxattr:1;
92a8780e
MS
754
755 /** Is listxattr not implemented by fs? */
1729a16c 756 unsigned no_listxattr:1;
92a8780e
MS
757
758 /** Is removexattr not implemented by fs? */
1729a16c 759 unsigned no_removexattr:1;
92a8780e 760
37fb3a30 761 /** Are posix file locking primitives not implemented by fs? */
1729a16c 762 unsigned no_lock:1;
71421259 763
31d40d74 764 /** Is access not implemented by fs? */
1729a16c 765 unsigned no_access:1;
31d40d74 766
fd72faac 767 /** Is create not implemented by fs? */
1729a16c 768 unsigned no_create:1;
fd72faac 769
a4d27e75 770 /** Is interrupt not implemented by fs? */
1729a16c 771 unsigned no_interrupt:1;
a4d27e75 772
b2d2272f 773 /** Is bmap not implemented by fs? */
1729a16c 774 unsigned no_bmap:1;
b2d2272f 775
95668a69
TH
776 /** Is poll not implemented by fs? */
777 unsigned no_poll:1;
778
78bb6cb9 779 /** Do multi-page cached writes */
1729a16c 780 unsigned big_writes:1;
78bb6cb9 781
e0a43ddc
MS
782 /** Don't apply umask to creation modes */
783 unsigned dont_mask:1;
784
37fb3a30
MS
785 /** Are BSD file locking primitives not implemented by fs? */
786 unsigned no_flock:1;
787
519c6040
MS
788 /** Is fallocate not implemented by fs? */
789 unsigned no_fallocate:1;
790
1560c974
MS
791 /** Is rename with flags implemented by fs? */
792 unsigned no_rename2:1;
793
72d0d248
BF
794 /** Use enhanced/automatic page cache invalidation. */
795 unsigned auto_inval_data:1;
796
aa6ff555 797 /** Filesystem is fully responsible for page cache invalidation. */
ad2ba64d
KS
798 unsigned explicit_inval_data:1;
799
634734b6 800 /** Does the filesystem support readdirplus? */
0b05b183
AA
801 unsigned do_readdirplus:1;
802
634734b6
EW
803 /** Does the filesystem want adaptive readdirplus? */
804 unsigned readdirplus_auto:1;
805
60b9df7a
MS
806 /** Does the filesystem support asynchronous direct-IO submission? */
807 unsigned async_dio:1;
808
0b5da8db
R
809 /** Is lseek not implemented by fs? */
810 unsigned no_lseek:1;
811
60bcc88a
SF
812 /** Does the filesystem support posix acls? */
813 unsigned posix_acl:1;
814
29433a29
MS
815 /** Check permissions based on the file mode or not? */
816 unsigned default_permissions:1;
817
818 /** Allow other than the mounter user to access the filesystem ? */
819 unsigned allow_other:1;
820
88bc7d50
NV
821 /** Does the filesystem support copy_file_range? */
822 unsigned no_copy_file_range:1;
823
1ccd1ea2
MS
824 /* Send DESTROY request */
825 unsigned int destroy:1;
826
8fab0106
MS
827 /* Delete dentries that have gone stale */
828 unsigned int delete_stale:1;
829
15c8e72e
VG
830 /** Do not create entry in fusectl fs */
831 unsigned int no_control:1;
832
833 /** Do not allow MNT_FORCE umount */
834 unsigned int no_force_umount:1;
835
bf109c64
MR
836 /* Auto-mount submounts announced by the server */
837 unsigned int auto_submounts:1;
838
2d82ab25
GK
839 /* Propagate syncfs() to server */
840 unsigned int sync_fs:1;
841
3e2b6fdb
VG
842 /* Initialize security xattrs when creating a new inode */
843 unsigned int init_security:1;
844
8ed7cb3f
MS
845 /* Add supplementary group info when creating a new inode */
846 unsigned int create_supp_group:1;
847
2ee019fa
JX
848 /* Does the filesystem support per inode DAX? */
849 unsigned int inode_dax:1;
850
7d375390
MS
851 /* Is tmpfile not implemented by fs? */
852 unsigned int no_tmpfile:1;
853
c55e0a55
TF
854 /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */
855 unsigned int direct_io_allow_mmap:1;
e78662e8 856
d3045530
MS
857 /* Is statx not implemented by fs? */
858 unsigned int no_statx:1;
859
7dc4e97a
AG
860 /** Passthrough support for read/write IO */
861 unsigned int passthrough:1;
862
863 /** Maximum stack depth for passthrough backing files */
864 int max_stack_depth;
865
0cd5b885
MS
866 /** The number of requests waiting for completion */
867 atomic_t num_waiting;
868
45714d65
MS
869 /** Negotiated minor version */
870 unsigned minor;
871
fcee216b 872 /** Entry on the fuse_mount_list */
bafa9654
MS
873 struct list_head entry;
874
fcee216b 875 /** Device ID from the root super block */
b6f2fcbc 876 dev_t dev;
bafa9654
MS
877
878 /** Dentries in the control filesystem */
879 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
880
881 /** number of dentries used in the above array */
882 int ctl_ndents;
385a17bf 883
9c8ef561
MS
884 /** Key for lock owner ID scrambling */
885 u32 scramble_key[4];
0ec7ca41 886
1fb69e78 887 /** Version counter for attribute changes */
4510d86f 888 atomic64_t attr_version;
43901aab
TH
889
890 /** Called on final put */
891 void (*release)(struct fuse_conn *);
3b463ae0 892
fcee216b
MR
893 /**
894 * Read/write semaphore to hold when accessing the sb of any
895 * fuse_mount belonging to this connection
896 */
3b463ae0 897 struct rw_semaphore killsb;
cc080e9e
MS
898
899 /** List of device instances belonging to this connection */
900 struct list_head devices;
1dd53957
VG
901
902#ifdef CONFIG_FUSE_DAX
780b1b95
JX
903 /* Dax mode */
904 enum fuse_dax_mode dax_mode;
905
1dd53957
VG
906 /* Dax specific conn data, non-NULL if DAX is enabled */
907 struct fuse_conn_dax *dax;
908#endif
fcee216b
MR
909
910 /** List of filesystems using this connection */
911 struct list_head mounts;
660585b5
MS
912
913 /* New writepages go into this bucket */
914 struct fuse_sync_bucket __rcu *curr_bucket;
44350256
AG
915
916#ifdef CONFIG_FUSE_PASSTHROUGH
917 /** IDR for backing files ids */
918 struct idr backing_files_map;
919#endif
d8a5ba45
MS
920};
921
fcee216b
MR
922/*
923 * Represents a mounted filesystem, potentially a submount.
924 *
925 * This object allows sharing a fuse_conn between separate mounts to
926 * allow submounts with dedicated superblocks and thus separate device
927 * IDs.
928 */
929struct fuse_mount {
930 /* Underlying (potentially shared) connection to the FUSE server */
931 struct fuse_conn *fc;
932
fcee216b
MR
933 /*
934 * Super block for this connection (fc->killsb must be held when
935 * accessing this).
936 */
937 struct super_block *sb;
938
939 /* Entry on fc->mounts */
940 struct list_head fc_entry;
053fc4f7 941 struct rcu_head rcu;
fcee216b
MR
942};
943
944static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb)
d8a5ba45 945{
6383bdaa 946 return sb->s_fs_info;
d8a5ba45
MS
947}
948
fcee216b
MR
949static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
950{
bd3bf1e8 951 return get_fuse_mount_super(sb)->fc;
fcee216b
MR
952}
953
954static inline struct fuse_mount *get_fuse_mount(struct inode *inode)
955{
956 return get_fuse_mount_super(inode->i_sb);
957}
958
d8a5ba45
MS
959static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
960{
bd3bf1e8 961 return get_fuse_mount_super(inode->i_sb)->fc;
d8a5ba45
MS
962}
963
964static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
965{
966 return container_of(inode, struct fuse_inode, inode);
967}
968
969static inline u64 get_node_id(struct inode *inode)
970{
971 return get_fuse_inode(inode)->nodeid;
972}
973
d123d8e1
MS
974static inline int invalid_nodeid(u64 nodeid)
975{
976 return !nodeid || nodeid == FUSE_ROOT_ID;
977}
978
4510d86f
KT
979static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
980{
981 return atomic64_read(&fc->attr_version);
982}
983
15db1683
AG
984static inline bool fuse_stale_inode(const struct inode *inode, int generation,
985 struct fuse_attr *attr)
986{
987 return inode->i_generation != generation ||
988 inode_wrong_type(inode, attr->mode);
989}
990
5d069dbe
MS
991static inline void fuse_make_bad(struct inode *inode)
992{
993 set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state);
994}
995
996static inline bool fuse_is_bad(struct inode *inode)
997{
998 return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
999}
1000
9ac29fd3
MS
1001static inline struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
1002 struct fuse_page_desc **desc)
1003{
1004 struct page **pages;
1005
1006 pages = kzalloc(npages * (sizeof(struct page *) +
1007 sizeof(struct fuse_page_desc)), flags);
1008 *desc = (void *) (pages + npages);
1009
1010 return pages;
1011}
1012
1013static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs,
1014 unsigned int index,
1015 unsigned int nr_pages)
1016{
1017 int i;
1018
1019 for (i = index; i < index + nr_pages; i++)
1020 descs[i].length = PAGE_SIZE - descs[i].offset;
1021}
1022
660585b5
MS
1023static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket)
1024{
1025 /* Need RCU protection to prevent use after free after the decrement */
1026 rcu_read_lock();
1027 if (atomic_dec_and_test(&bucket->count))
1028 wake_up(&bucket->waitq);
1029 rcu_read_unlock();
1030}
1031
334f485d 1032/** Device operations */
4b6f5d20 1033extern const struct file_operations fuse_dev_operations;
334f485d 1034
4269590a 1035extern const struct dentry_operations fuse_dentry_operations;
0ce267ff 1036extern const struct dentry_operations fuse_root_dentry_operations;
dbd561d2 1037
e5e5558e
MS
1038/**
1039 * Get a filled in inode
1040 */
b48badf0 1041struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
1fb69e78
MS
1042 int generation, struct fuse_attr *attr,
1043 u64 attr_valid, u64 attr_version);
e5e5558e 1044
13983d06 1045int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
33670fa2
MS
1046 struct fuse_entry_out *outarg, struct inode **inode);
1047
e5e5558e
MS
1048/**
1049 * Send FORGET command
1050 */
07e77dca
MS
1051void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
1052 u64 nodeid, u64 nlookup);
1053
1054struct fuse_forget_link *fuse_alloc_forget(void);
e5e5558e 1055
4388c5aa
VG
1056struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq,
1057 unsigned int max,
1058 unsigned int *countp);
1059
43f5098e 1060/*
361b1eb5 1061 * Initialize READ or READDIR request
04730fef 1062 */
43f5098e
MS
1063struct fuse_io_args {
1064 union {
1065 struct {
1066 struct fuse_read_in in;
1067 u64 attr_ver;
1068 } read;
1069 struct {
1070 struct fuse_write_in in;
1071 struct fuse_write_out out;
4f06dd92 1072 bool page_locked;
43f5098e
MS
1073 } write;
1074 };
1075 struct fuse_args_pages ap;
1076 struct fuse_io_priv *io;
1077 struct fuse_file *ff;
1078};
1079
1080void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
1081 size_t count, int opcode);
1082
04730fef 1083
e26ee4ef 1084struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release);
fd72faac 1085void fuse_file_free(struct fuse_file *ff);
d2c487f1 1086int fuse_finish_open(struct inode *inode, struct file *file);
fd72faac 1087
54d601cb
MS
1088void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff,
1089 unsigned int flags);
c756e0a4 1090
04730fef
MS
1091/**
1092 * Send RELEASE or RELEASEDIR request
1093 */
2e64ff15 1094void fuse_release_common(struct file *file, bool isdir);
04730fef 1095
82547981
MS
1096/**
1097 * Send FSYNC or FSYNCDIR request
1098 */
02c24a82 1099int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
a9c2d1e8 1100 int datasync, int opcode);
82547981 1101
95668a69
TH
1102/**
1103 * Notify poll wakeup
1104 */
1105int fuse_notify_poll_wakeup(struct fuse_conn *fc,
1106 struct fuse_notify_poll_wakeup_out *outarg);
1107
b6aeaded 1108/**
1779381d 1109 * Initialize file operations on a regular file
b6aeaded 1110 */
93a497b9 1111void fuse_init_file_inode(struct inode *inode, unsigned int flags);
b6aeaded 1112
e5e5558e 1113/**
1779381d 1114 * Initialize inode operations on regular files and special files
e5e5558e
MS
1115 */
1116void fuse_init_common(struct inode *inode);
1117
1118/**
1779381d 1119 * Initialize inode and file operations on a directory
e5e5558e
MS
1120 */
1121void fuse_init_dir(struct inode *inode);
1122
1123/**
1779381d 1124 * Initialize inode operations on a symlink
e5e5558e
MS
1125 */
1126void fuse_init_symlink(struct inode *inode);
1127
1128/**
1129 * Change attributes of an inode
1130 */
1fb69e78 1131void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
972f4c46 1132 struct fuse_statx *sx,
1fb69e78 1133 u64 attr_valid, u64 attr_version);
e5e5558e 1134
3be5a52b 1135void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
972f4c46 1136 struct fuse_statx *sx,
4b52f059
MS
1137 u64 attr_valid, u32 cache_mask);
1138
1139u32 fuse_get_cache_mask(struct inode *inode);
3be5a52b 1140
334f485d
MS
1141/**
1142 * Initialize the client device
1143 */
1144int fuse_dev_init(void);
1145
1146/**
1147 * Cleanup the client device
1148 */
1149void fuse_dev_cleanup(void);
1150
bafa9654 1151int fuse_ctl_init(void);
7736e8cc 1152void __exit fuse_ctl_cleanup(void);
bafa9654 1153
7078187a
MS
1154/**
1155 * Simple request sending that does request allocation and freeing
1156 */
fcee216b
MR
1157ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args);
1158int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
12597287 1159 gfp_t gfp_flags);
7078187a 1160
04ec5af0
SH
1161/**
1162 * End a finished request
1163 */
8f622e94 1164void fuse_request_end(struct fuse_req *req);
04ec5af0 1165
5a5fb1ea 1166/* Abort all requests */
eb98e3bd 1167void fuse_abort_conn(struct fuse_conn *fc);
b8f95e5d 1168void fuse_wait_aborted(struct fuse_conn *fc);
69a53bf2 1169
e5e5558e
MS
1170/**
1171 * Invalidate inode attributes
1172 */
fa5eee57
MS
1173
1174/* Attributes possibly changed on data modification */
1175#define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1176
1177/* Attributes possibly changed on data and/or size modification */
1178#define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
1179
e5e5558e 1180void fuse_invalidate_attr(struct inode *inode);
fa5eee57 1181void fuse_invalidate_attr_mask(struct inode *inode, u32 mask);
bafa9654 1182
dbd561d2
MS
1183void fuse_invalidate_entry_cache(struct dentry *entry);
1184
451418fc
AG
1185void fuse_invalidate_atime(struct inode *inode);
1186
9dc10a54
MS
1187u64 fuse_time_to_jiffies(u64 sec, u32 nsec);
1188#define ATTR_TIMEOUT(o) \
1189 fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec)
1190
d123d8e1
MS
1191void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
1192
bafa9654
MS
1193/**
1194 * Acquire reference to fuse_conn
1195 */
1196struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
1197
0d179aa5
TH
1198/**
1199 * Initialize fuse_conn
1200 */
fcee216b
MR
1201void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
1202 struct user_namespace *user_ns,
ae3aad77 1203 const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
0d179aa5 1204
bafa9654
MS
1205/**
1206 * Release reference to fuse_conn
1207 */
1208void fuse_conn_put(struct fuse_conn *fc);
1209
0cd1eb9a
VG
1210struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
1211struct fuse_dev *fuse_dev_alloc(void);
1212void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
cc080e9e 1213void fuse_dev_free(struct fuse_dev *fud);
fcee216b 1214void fuse_send_init(struct fuse_mount *fm);
cc080e9e 1215
0cc2656c
SH
1216/**
1217 * Fill in superblock and initialize fuse connection
1218 * @sb: partially-initialized superblock to fill in
1219 * @ctx: mount context
1220 */
1221int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
1222
fcee216b
MR
1223/*
1224 * Remove the mount from the connection
783863d6 1225 *
fcee216b
MR
1226 * Returns whether this was the last mount
1227 */
1228bool fuse_mount_remove(struct fuse_mount *fm);
1229
fe0a7bd8
GK
1230/*
1231 * Setup context ops for submounts
1232 */
1233int fuse_init_fs_context_submount(struct fs_context *fsc);
1234
fcee216b
MR
1235/*
1236 * Shut down the connection (possibly sending DESTROY request).
783863d6 1237 */
fcee216b 1238void fuse_conn_destroy(struct fuse_mount *fm);
783863d6 1239
a27c061a
MS
1240/* Drop the connection and free the fuse mount */
1241void fuse_mount_destroy(struct fuse_mount *fm);
1242
bafa9654
MS
1243/**
1244 * Add connection to control filesystem
1245 */
1246int fuse_ctl_add_conn(struct fuse_conn *fc);
1247
1248/**
1249 * Remove connection from control filesystem
1250 */
1251void fuse_ctl_remove_conn(struct fuse_conn *fc);
a5bfffac
TS
1252
1253/**
1254 * Is file type valid?
1255 */
1256int fuse_valid_type(int m);
e57ac683 1257
eb59bd17
MS
1258bool fuse_invalid_attr(struct fuse_attr *attr);
1259
e57ac683 1260/**
c2132c1b 1261 * Is current process allowed to perform filesystem operation?
e57ac683 1262 */
b1387777 1263bool fuse_allow_current_process(struct fuse_conn *fc);
f3332114
MS
1264
1265u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
bcb4be80 1266
5c791fe1 1267void fuse_flush_time_update(struct inode *inode);
703c7362
SF
1268void fuse_update_ctime(struct inode *inode);
1269
c6c745b8 1270int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask);
3be5a52b
MS
1271
1272void fuse_flush_writepages(struct inode *inode);
1273
1274void fuse_set_nowrite(struct inode *inode);
1275void fuse_release_nowrite(struct inode *inode);
5c5c5e51 1276
fcee216b
MR
1277/**
1278 * Scan all fuse_mounts belonging to fc to find the first where
1279 * ilookup5() returns a result. Return that result and the
1280 * respective fuse_mount in *fm (unless fm is NULL).
1281 *
1282 * The caller must hold fc->killsb.
1283 */
1284struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
1285 struct fuse_mount **fm);
1286
3b463ae0
JM
1287/**
1288 * File-system tells the kernel to invalidate cache for the given node id.
1289 */
fcee216b 1290int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
3b463ae0
JM
1291 loff_t offset, loff_t len);
1292
1293/**
1294 * File-system tells the kernel to invalidate parent attributes and
1295 * the dentry matching parent/name.
451d0f59
JM
1296 *
1297 * If the child_nodeid is non-zero and:
1298 * - matches the inode number for the dentry matching parent/name,
1299 * - is not a mount point
1300 * - is a file or oan empty directory
1301 * then the dentry is unhashed (d_delete()).
3b463ae0 1302 */
fcee216b 1303int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
4f8d3702 1304 u64 child_nodeid, struct qstr *name, u32 flags);
3b463ae0 1305
fcee216b 1306int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
08cbf542 1307 bool isdir);
ea8cd333
PE
1308
1309/**
1310 * fuse_direct_io() flags
1311 */
1312
1313/** If set, it is WRITE; otherwise - READ */
1314#define FUSE_DIO_WRITE (1 << 0)
1315
1316/** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1317#define FUSE_DIO_CUSE (1 << 1)
1318
d22a943f
AV
1319ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1320 loff_t *ppos, int flags);
08cbf542
TH
1321long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1322 unsigned int flags);
b18da0c5
MS
1323long fuse_ioctl_common(struct file *file, unsigned int cmd,
1324 unsigned long arg, unsigned int flags);
076ccb76 1325__poll_t fuse_file_poll(struct file *file, poll_table *wait);
08cbf542
TH
1326int fuse_dev_release(struct inode *inode, struct file *file);
1327
d347739a 1328bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written);
b0aa7606 1329
ab9e13f7 1330int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
1e18bda8 1331int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
a1d75f25 1332
62490330 1333int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
efb9fa9e
MP
1334 struct file *file);
1335
9759bd51
MS
1336void fuse_set_initialized(struct fuse_conn *fc);
1337
63576c13
MS
1338void fuse_unlock_inode(struct inode *inode, bool locked);
1339bool fuse_lock_inode(struct inode *inode);
5c672ab3 1340
60bcc88a 1341int fuse_setxattr(struct inode *inode, const char *name, const void *value,
52a4c95f 1342 size_t size, int flags, unsigned int extra_flags);
60bcc88a
SF
1343ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
1344 size_t size);
703c7362 1345ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
60bcc88a 1346int fuse_removexattr(struct inode *inode, const char *name);
34271edb 1347extern const struct xattr_handler * const fuse_xattr_handlers[];
60bcc88a
SF
1348
1349struct posix_acl;
facd6105 1350struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu);
05e6295f 1351struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap,
facd6105 1352 struct dentry *dentry, int type);
05e6295f 1353int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry,
549c7297 1354 struct posix_acl *acl, int type);
d123d8e1
MS
1355
1356/* readdir.c */
1357int fuse_readdir(struct file *file, struct dir_context *ctx);
1358
14d46d7a
SH
1359/**
1360 * Return the number of bytes in an arguments list
1361 */
1362unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
1363
79d96eff
SH
1364/**
1365 * Get the next unique ID for a request
1366 */
1367u64 fuse_get_unique(struct fuse_iqueue *fiq);
783863d6 1368void fuse_free_conn(struct fuse_conn *fc);
79d96eff 1369
1dd53957
VG
1370/* dax.c */
1371
c2d0ad00
VG
1372#define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1373
1374ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
1375ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
1376int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
6ae330ca 1377int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
780b1b95
JX
1378int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode,
1379 struct dax_device *dax_dev);
1dd53957 1380void fuse_dax_conn_free(struct fuse_conn *fc);
c2d0ad00 1381bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
93a497b9 1382void fuse_dax_inode_init(struct inode *inode, unsigned int flags);
c2d0ad00 1383void fuse_dax_inode_cleanup(struct inode *inode);
c3cb6f93 1384void fuse_dax_dontcache(struct inode *inode, unsigned int flags);
fd1a1dc6 1385bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
9a752d18 1386void fuse_dax_cancel_work(struct fuse_conn *fc);
1dd53957 1387
9ac29fd3
MS
1388/* ioctl.c */
1389long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1390long fuse_file_compat_ioctl(struct file *file, unsigned int cmd,
1391 unsigned long arg);
72227eac 1392int fuse_fileattr_get(struct dentry *dentry, struct fileattr *fa);
8782a9ae 1393int fuse_fileattr_set(struct mnt_idmap *idmap,
72227eac 1394 struct dentry *dentry, struct fileattr *fa);
9ac29fd3 1395
cb098dd2
AG
1396/* iomode.c */
1397int fuse_file_cached_io_start(struct inode *inode, struct fuse_file *ff);
4a90451b 1398int fuse_file_uncached_io_start(struct inode *inode, struct fuse_file *ff, struct fuse_backing *fb);
205c1d80 1399void fuse_file_uncached_io_end(struct inode *inode, struct fuse_file *ff);
b9d54c6f 1400
cb098dd2
AG
1401int fuse_file_io_open(struct file *file, struct inode *inode);
1402void fuse_file_io_release(struct fuse_file *ff, struct inode *inode);
b9d54c6f 1403
cb098dd2 1404/* file.c */
b9d54c6f
MS
1405struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,
1406 unsigned int open_flags, bool isdir);
1407void fuse_file_release(struct inode *inode, struct fuse_file *ff,
1408 unsigned int open_flags, fl_owner_t id, bool isdir);
1409
7dc4e97a
AG
1410/* passthrough.c */
1411static inline struct fuse_backing *fuse_inode_backing(struct fuse_inode *fi)
1412{
1413#ifdef CONFIG_FUSE_PASSTHROUGH
1414 return READ_ONCE(fi->fb);
1415#else
1416 return NULL;
1417#endif
1418}
1419
1420static inline struct fuse_backing *fuse_inode_backing_set(struct fuse_inode *fi,
1421 struct fuse_backing *fb)
1422{
1423#ifdef CONFIG_FUSE_PASSTHROUGH
1424 return xchg(&fi->fb, fb);
1425#else
1426 return NULL;
1427#endif
1428}
1429
4a90451b 1430#ifdef CONFIG_FUSE_PASSTHROUGH
7dc4e97a
AG
1431struct fuse_backing *fuse_backing_get(struct fuse_backing *fb);
1432void fuse_backing_put(struct fuse_backing *fb);
4a90451b
AG
1433#else
1434
1435static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
1436{
1437 return NULL;
1438}
1439
1440static inline void fuse_backing_put(struct fuse_backing *fb)
1441{
1442}
1443#endif
1444
44350256
AG
1445void fuse_backing_files_init(struct fuse_conn *fc);
1446void fuse_backing_files_free(struct fuse_conn *fc);
1447int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map);
1448int fuse_backing_close(struct fuse_conn *fc, int backing_id);
7dc4e97a 1449
4a90451b
AG
1450struct fuse_backing *fuse_passthrough_open(struct file *file,
1451 struct inode *inode,
1452 int backing_id);
1453void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb);
1454
1455static inline struct file *fuse_file_passthrough(struct fuse_file *ff)
1456{
1457#ifdef CONFIG_FUSE_PASSTHROUGH
1458 return ff->passthrough;
1459#else
1460 return NULL;
1461#endif
1462}
1463
57e1176e
AG
1464ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter);
1465ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *iter);
5ca73468
AG
1466ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos,
1467 struct pipe_inode_info *pipe,
1468 size_t len, unsigned int flags);
1469ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
1470 struct file *out, loff_t *ppos,
1471 size_t len, unsigned int flags);
fda0b98e 1472ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
57e1176e 1473
29d434b3 1474#endif /* _FS_FUSE_I_H */