]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - fs/fuse/fuse_i.h
fuse: store fuse_conn in fuse_req
[thirdparty/kernel/linux.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
d8a5ba45
MS
66/** FUSE inode */
67struct fuse_inode {
68 /** Inode data */
69 struct inode inode;
70
71 /** Unique ID, which identifies the inode between userspace
72 * and kernel */
73 u64 nodeid;
74
9e6268db
MS
75 /** Number of lookups on this inode */
76 u64 nlookup;
77
e5e5558e 78 /** The request used for sending the FORGET message */
07e77dca 79 struct fuse_forget_link *forget;
e5e5558e 80
d8a5ba45 81 /** Time in jiffies until the file attributes are valid */
0a0898cf 82 u64 i_time;
ebc14c4d 83
2f1e8196
MS
84 /* Which attributes are invalid */
85 u32 inval_mask;
86
ebc14c4d
MS
87 /** The sticky bit in inode->i_mode may have been removed, so
88 preserve the original mode */
541af6a0 89 umode_t orig_i_mode;
1fb69e78 90
45c72cd7
PS
91 /** 64 bit inode number */
92 u64 orig_ino;
93
1fb69e78
MS
94 /** Version of last attribute change */
95 u64 attr_version;
93a8c3cd 96
ab2257e9
MS
97 union {
98 /* Write related fields (regular file only) */
99 struct {
f15ecfef 100 /* Files usable in writepage. Protected by fi->lock */
ab2257e9 101 struct list_head write_files;
3be5a52b 102
ab2257e9
MS
103 /* Writepages pending on truncate or fsync */
104 struct list_head queued_writes;
3be5a52b 105
ab2257e9
MS
106 /* Number of sent writes, a negative bias
107 * (FUSE_NOWRITE) means more writes are blocked */
108 int writectr;
3be5a52b 109
ab2257e9
MS
110 /* Waitq for writepage completion */
111 wait_queue_head_t page_waitq;
3be5a52b 112
ab2257e9 113 /* List of writepage requestst (pending or sent) */
6b2fb799 114 struct rb_root writepages;
ab2257e9 115 };
4582a4ab 116
ab2257e9
MS
117 /* readdir cache (directory only) */
118 struct {
119 /* true if fully cached */
120 bool cached;
69e34551 121
ab2257e9
MS
122 /* size of cache */
123 loff_t size;
69e34551 124
ab2257e9
MS
125 /* position at end of cache (position of next entry) */
126 loff_t pos;
69e34551 127
ab2257e9
MS
128 /* version of the cache */
129 u64 version;
3494927e 130
ab2257e9
MS
131 /* modification time of directory when cache was
132 * started */
133 struct timespec64 mtime;
7118883b 134
ab2257e9
MS
135 /* iversion of directory when cache was started */
136 u64 iversion;
261aaba7 137
ab2257e9
MS
138 /* protects above fields */
139 spinlock_t lock;
140 } rdc;
141 };
69e34551 142
4582a4ab
FS
143 /** Miscellaneous bits describing inode state */
144 unsigned long state;
5c672ab3
MS
145
146 /** Lock for serializing lookup and readdir for back compatibility*/
147 struct mutex mutex;
f15ecfef
KT
148
149 /** Lock to protect write related fields */
150 spinlock_t lock;
c2d0ad00 151
6ae330ca
VG
152 /**
153 * Can't take inode lock in fault path (leads to circular dependency).
154 * Introduce another semaphore which can be taken in fault path and
155 * then other filesystem paths can take this to block faults.
156 */
157 struct rw_semaphore i_mmap_sem;
158
c2d0ad00
VG
159#ifdef CONFIG_FUSE_DAX
160 /*
161 * Dax specific inode data
162 */
163 struct fuse_inode_dax *dax;
164#endif
4582a4ab
FS
165};
166
167/** FUSE inode state bits */
168enum {
169 /** Advise readdirplus */
170 FUSE_I_ADVISE_RDPLUS,
6314efee
MS
171 /** Initialized with readdirplus */
172 FUSE_I_INIT_RDPLUS,
06a7c3c2
MP
173 /** An operation changing file size is in progress */
174 FUSE_I_SIZE_UNSTABLE,
d8a5ba45
MS
175};
176
da5e4714 177struct fuse_conn;
4cb54866 178struct fuse_release_args;
da5e4714 179
b6aeaded
MS
180/** FUSE specific file data */
181struct fuse_file {
da5e4714
MS
182 /** Fuse connection for this file */
183 struct fuse_conn *fc;
184
4cb54866
MS
185 /* Argument space reserved for release */
186 struct fuse_release_args *release_args;
b6aeaded 187
acf99433
TH
188 /** Kernel file handle guaranteed to be unique */
189 u64 kh;
190
b6aeaded
MS
191 /** File handle used by userspace */
192 u64 fh;
c756e0a4 193
da5e4714
MS
194 /** Node id of this file */
195 u64 nodeid;
196
c756e0a4 197 /** Refcount */
4e8c2eb5 198 refcount_t count;
93a8c3cd 199
c7b7143c
MS
200 /** FOPEN_* flags returned by open */
201 u32 open_flags;
202
93a8c3cd
MS
203 /** Entry on inode's write_files list */
204 struct list_head write_entry;
95668a69 205
5d7bc7e8
MS
206 /* Readdir related */
207 struct {
208 /*
209 * Protects below fields against (crazy) parallel readdir on
210 * same open file. Uncontended in the normal case.
211 */
212 struct mutex lock;
213
214 /* Dir stream position */
215 loff_t pos;
216
217 /* Offset in cache */
218 loff_t cache_off;
3494927e
MS
219
220 /* Version of cache we are reading */
221 u64 version;
222
5d7bc7e8
MS
223 } readdir;
224
95668a69
TH
225 /** RB node to be linked on fuse_conn->polled_files */
226 struct rb_node polled_node;
227
228 /** Wait queue head for poll */
229 wait_queue_head_t poll_wait;
37fb3a30
MS
230
231 /** Has flock been performed on this file? */
232 bool flock:1;
b6aeaded
MS
233};
234
334f485d
MS
235/** One input argument of a request */
236struct fuse_in_arg {
237 unsigned size;
238 const void *value;
239};
240
334f485d
MS
241/** One output argument of a request */
242struct fuse_arg {
243 unsigned size;
244 void *value;
245};
246
b2430d75
MP
247/** FUSE page descriptor */
248struct fuse_page_desc {
249 unsigned int length;
250 unsigned int offset;
251};
252
7078187a 253struct fuse_args {
d5b48543 254 uint64_t nodeid;
1f4e9d03
MS
255 uint32_t opcode;
256 unsigned short in_numargs;
257 unsigned short out_numargs;
c500ebaa 258 bool force:1;
454a7613 259 bool noreply:1;
e413754b 260 bool nocreds:1;
68583165
MS
261 bool in_pages:1;
262 bool out_pages:1;
1f4e9d03 263 bool out_argvar:1;
68583165
MS
264 bool page_zeroing:1;
265 bool page_replace:1;
bb737bbe 266 bool may_block:1;
d5b48543 267 struct fuse_in_arg in_args[3];
d5b48543 268 struct fuse_arg out_args[2];
12597287 269 void (*end)(struct fuse_conn *fc, struct fuse_args *args, int error);
7078187a
MS
270};
271
68583165
MS
272struct fuse_args_pages {
273 struct fuse_args args;
274 struct page **pages;
275 struct fuse_page_desc *descs;
276 unsigned int num_pages;
277};
278
7078187a
MS
279#define FUSE_ARGS(args) struct fuse_args args = {}
280
01e9d11a
MP
281/** The request IO state (for asynchronous processing) */
282struct fuse_io_priv {
744742d6 283 struct kref refcnt;
01e9d11a
MP
284 int async;
285 spinlock_t lock;
286 unsigned reqs;
287 ssize_t bytes;
288 size_t size;
289 __u64 offset;
290 bool write;
61c12b49 291 bool should_dirty;
01e9d11a
MP
292 int err;
293 struct kiocb *iocb;
9d5722b7 294 struct completion *done;
7879c4e5 295 bool blocking;
01e9d11a
MP
296};
297
e1c0eecb 298#define FUSE_IO_PRIV_SYNC(i) \
744742d6 299{ \
1e24edca 300 .refcnt = KREF_INIT(1), \
744742d6 301 .async = 0, \
e1c0eecb 302 .iocb = i, \
744742d6
SF
303}
304
825d6d33
MS
305/**
306 * Request flags
307 *
308 * FR_ISREPLY: set if the request has reply
309 * FR_FORCE: force sending of the request even if interrupted
310 * FR_BACKGROUND: request is sent in the background
311 * FR_WAITING: request is counted as "waiting"
312 * FR_ABORTED: the request was aborted
313 * FR_INTERRUPTED: the request has been interrupted
314 * FR_LOCKED: data is being copied to/from the request
33e14b4d
MS
315 * FR_PENDING: request is not yet in userspace
316 * FR_SENT: request is in userspace, waiting for an answer
317 * FR_FINISHED: request is finished
77cd9d48 318 * FR_PRIVATE: request is on private list
3e8cb8b2 319 * FR_ASYNC: request is asynchronous
825d6d33
MS
320 */
321enum fuse_req_flag {
322 FR_ISREPLY,
323 FR_FORCE,
324 FR_BACKGROUND,
325 FR_WAITING,
326 FR_ABORTED,
327 FR_INTERRUPTED,
328 FR_LOCKED,
33e14b4d
MS
329 FR_PENDING,
330 FR_SENT,
331 FR_FINISHED,
77cd9d48 332 FR_PRIVATE,
3e8cb8b2 333 FR_ASYNC,
825d6d33
MS
334};
335
334f485d
MS
336/**
337 * A request to the client
dc00809a
MS
338 *
339 * .waitq.lock protects the following fields:
340 * - FR_ABORTED
341 * - FR_LOCKED (may also be modified under fc->lock, tested under both)
334f485d
MS
342 */
343struct fuse_req {
ce1d5a49
MS
344 /** This can be on either pending processing or io lists in
345 fuse_conn */
334f485d
MS
346 struct list_head list;
347
a4d27e75
MS
348 /** Entry on the interrupts list */
349 struct list_head intr_entry;
350
12597287
MS
351 /* Input/output arguments */
352 struct fuse_args *args;
353
334f485d 354 /** refcount */
ec99f6d3 355 refcount_t count;
334f485d 356
825d6d33
MS
357 /* Request flags, updated with test/set/clear_bit() */
358 unsigned long flags;
9bc5ddda 359
d4993774
MS
360 /* The request input header */
361 struct {
362 struct fuse_in_header h;
363 } in;
334f485d 364
d4993774
MS
365 /* The request output header */
366 struct {
367 struct fuse_out_header h;
368 } out;
334f485d
MS
369
370 /** Used to wake up the task waiting for completion of request*/
371 wait_queue_head_t waitq;
372
a62a8ef9
SH
373#if IS_ENABLED(CONFIG_VIRTIO_FS)
374 /** virtio-fs's physically contiguous buffer for in and out args */
375 void *argbuf;
376#endif
24754db2
MR
377
378 /** fuse_conn this request belongs to */
379 struct fuse_conn *fc;
334f485d
MS
380};
381
ae3aad77
SH
382struct fuse_iqueue;
383
384/**
385 * Input queue callbacks
386 *
387 * Input queue signalling is device-specific. For example, the /dev/fuse file
388 * uses fiq->waitq and fasync to wake processes that are waiting on queue
389 * readiness. These callbacks allow other device types to respond to input
390 * queue activity.
391 */
392struct fuse_iqueue_ops {
393 /**
394 * Signal that a forget has been queued
395 */
396 void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
397 __releases(fiq->lock);
398
399 /**
400 * Signal that an INTERRUPT request has been queued
401 */
402 void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
403 __releases(fiq->lock);
404
405 /**
406 * Signal that a request has been queued
407 */
408 void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
409 __releases(fiq->lock);
a62a8ef9
SH
410
411 /**
412 * Clean up when fuse_iqueue is destroyed
413 */
414 void (*release)(struct fuse_iqueue *fiq);
ae3aad77
SH
415};
416
417/** /dev/fuse input queue operations */
418extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
419
f88996a9 420struct fuse_iqueue {
e16714d8
MS
421 /** Connection established */
422 unsigned connected;
423
76e43c8c
EB
424 /** Lock protecting accesses to members of this structure */
425 spinlock_t lock;
426
f88996a9
MS
427 /** Readers of the connection are waiting on this */
428 wait_queue_head_t waitq;
429
430 /** The next unique request id */
431 u64 reqctr;
432
433 /** The list of pending requests */
434 struct list_head pending;
435
436 /** Pending interrupts */
437 struct list_head interrupts;
438
439 /** Queue of pending forgets */
440 struct fuse_forget_link forget_list_head;
441 struct fuse_forget_link *forget_list_tail;
442
443 /** Batching of FORGET requests (positive indicates FORGET batch) */
444 int forget_batch;
445
446 /** O_ASYNC requests */
447 struct fasync_struct *fasync;
ae3aad77
SH
448
449 /** Device-specific callbacks */
450 const struct fuse_iqueue_ops *ops;
451
452 /** Device-specific state */
453 void *priv;
f88996a9
MS
454};
455
be2ff42c
KT
456#define FUSE_PQ_HASH_BITS 8
457#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
458
3a2b5b9c 459struct fuse_pqueue {
e96edd94
MS
460 /** Connection established */
461 unsigned connected;
462
45a91cb1
MS
463 /** Lock protecting accessess to members of this structure */
464 spinlock_t lock;
465
be2ff42c
KT
466 /** Hash table of requests being processed */
467 struct list_head *processing;
3a2b5b9c
MS
468
469 /** The list of requests under I/O */
470 struct list_head io;
471};
472
cc080e9e
MS
473/**
474 * Fuse device instance
475 */
476struct fuse_dev {
477 /** Fuse connection for this device */
478 struct fuse_conn *fc;
479
c3696046
MS
480 /** Processing queue */
481 struct fuse_pqueue pq;
482
cc080e9e
MS
483 /** list entry on fc->devices */
484 struct list_head entry;
485};
486
0cc2656c
SH
487struct fuse_fs_context {
488 int fd;
489 unsigned int rootmode;
490 kuid_t user_id;
491 kgid_t group_id;
492 bool is_bdev:1;
493 bool fd_present:1;
494 bool rootmode_present:1;
495 bool user_id_present:1;
496 bool group_id_present:1;
497 bool default_permissions:1;
498 bool allow_other:1;
783863d6 499 bool destroy:1;
15c8e72e
VG
500 bool no_control:1;
501 bool no_force_umount:1;
f4fd4ae3 502 bool legacy_opts_show:1;
1dd53957 503 bool dax:1;
0cc2656c
SH
504 unsigned int max_read;
505 unsigned int blksize;
506 const char *subtype;
507
1dd53957
VG
508 /* DAX device, may be NULL */
509 struct dax_device *dax_dev;
510
0cc2656c
SH
511 /* fuse_dev pointer to fill in, should contain NULL on entry */
512 void **fudptr;
513};
514
d8a5ba45
MS
515/**
516 * A Fuse connection.
517 *
518 * This structure is created, when the filesystem is mounted, and is
519 * destroyed, when the client device is closed and the filesystem is
520 * unmounted.
521 */
522struct fuse_conn {
d7133114
MS
523 /** Lock protecting accessess to members of this structure */
524 spinlock_t lock;
525
bafa9654 526 /** Refcount */
095fc40a 527 refcount_t count;
bafa9654 528
c3696046
MS
529 /** Number of fuse_dev's */
530 atomic_t dev_count;
531
dd3e2c55
AV
532 struct rcu_head rcu;
533
d8a5ba45 534 /** The user id for this mount */
499dcf20 535 kuid_t user_id;
d8a5ba45 536
87729a55 537 /** The group id for this mount */
499dcf20 538 kgid_t group_id;
87729a55 539
0b6e9ea0
SF
540 /** The pid namespace for this mount */
541 struct pid_namespace *pid_ns;
542
8cb08329
EB
543 /** The user namespace for this mount */
544 struct user_namespace *user_ns;
545
db50b96c
MS
546 /** Maximum read size */
547 unsigned max_read;
548
413ef8cb
MS
549 /** Maximum write size */
550 unsigned max_write;
551
5da784cc
CS
552 /** Maxmum number of pages that can be used in a single request */
553 unsigned int max_pages;
554
f88996a9
MS
555 /** Input queue */
556 struct fuse_iqueue iq;
334f485d 557
acf99433 558 /** The next unique kernel file handle */
75126f55 559 atomic64_t khctr;
acf99433 560
95668a69
TH
561 /** rbtree of fuse_files waiting for poll events indexed by ph */
562 struct rb_root polled_files;
563
7a6d3c8b
CH
564 /** Maximum number of outstanding background requests */
565 unsigned max_background;
566
567 /** Number of background requests at which congestion starts */
568 unsigned congestion_threshold;
569
08a53cdc
MS
570 /** Number of requests currently in the background */
571 unsigned num_background;
572
d12def1b
MS
573 /** Number of background requests currently queued for userspace */
574 unsigned active_background;
575
576 /** The list of background requests set aside for later queuing */
577 struct list_head bg_queue;
578
ae2dffa3
KT
579 /** Protects: max_background, congestion_threshold, num_background,
580 * active_background, bg_queue, blocked */
581 spinlock_t bg_lock;
582
796523fb
MP
583 /** Flag indicating that INIT reply has been received. Allocating
584 * any fuse request will be suspended until the flag is set */
585 int initialized;
586
08a53cdc
MS
587 /** Flag indicating if connection is blocked. This will be
588 the case before the INIT reply is received, and if there
589 are too many outstading backgrounds requests */
590 int blocked;
591
592 /** waitq for blocked connection */
593 wait_queue_head_t blocked_waitq;
de5e3dec 594
69a53bf2
MS
595 /** Connection established, cleared on umount, connection
596 abort and device release */
095da6cb 597 unsigned connected;
1e9a4ed9 598
3b7008b2
SL
599 /** Connection aborted via sysfs */
600 bool aborted;
601
095da6cb
MS
602 /** Connection failed (version mismatch). Cannot race with
603 setting other bitfields since it is only set once in INIT
604 reply, before any other request, and never cleared */
1729a16c 605 unsigned conn_error:1;
334f485d 606
0ec7ca41 607 /** Connection successful. Only set in INIT */
1729a16c 608 unsigned conn_init:1;
0ec7ca41 609
9cd68455 610 /** Do readpages asynchronously? Only set in INIT */
1729a16c 611 unsigned async_read:1;
9cd68455 612
3b7008b2
SL
613 /** Return an unique read error after abort. Only set in INIT */
614 unsigned abort_err:1;
615
6ff958ed 616 /** Do not send separate SETATTR request before open(O_TRUNC) */
1729a16c 617 unsigned atomic_o_trunc:1;
6ff958ed 618
33670fa2 619 /** Filesystem supports NFS exporting. Only set in INIT */
1729a16c 620 unsigned export_support:1;
33670fa2 621
d5cd66c5
PE
622 /** write-back cache policy (default is write-through) */
623 unsigned writeback_cache:1;
624
5c672ab3
MS
625 /** allow parallel lookups and readdir (default is serialized) */
626 unsigned parallel_dirops:1;
627
5e940c1d
MS
628 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
629 unsigned handle_killpriv:1;
630
5571f1e6
DS
631 /** cache READLINK responses in page cache */
632 unsigned cache_symlinks:1;
633
f4fd4ae3
VG
634 /* show legacy mount options */
635 unsigned int legacy_opts_show:1;
636
095da6cb
MS
637 /*
638 * The following bitfields are only for optimization purposes
639 * and hence races in setting them will not cause malfunction
640 */
641
7678ac50
AG
642 /** Is open/release not implemented by fs? */
643 unsigned no_open:1;
644
d9a9ea94
CA
645 /** Is opendir/releasedir not implemented by fs? */
646 unsigned no_opendir:1;
647
b6aeaded 648 /** Is fsync not implemented by fs? */
1729a16c 649 unsigned no_fsync:1;
b6aeaded 650
82547981 651 /** Is fsyncdir not implemented by fs? */
1729a16c 652 unsigned no_fsyncdir:1;
82547981 653
b6aeaded 654 /** Is flush not implemented by fs? */
1729a16c 655 unsigned no_flush:1;
b6aeaded 656
92a8780e 657 /** Is setxattr not implemented by fs? */
1729a16c 658 unsigned no_setxattr:1;
92a8780e
MS
659
660 /** Is getxattr not implemented by fs? */
1729a16c 661 unsigned no_getxattr:1;
92a8780e
MS
662
663 /** Is listxattr not implemented by fs? */
1729a16c 664 unsigned no_listxattr:1;
92a8780e
MS
665
666 /** Is removexattr not implemented by fs? */
1729a16c 667 unsigned no_removexattr:1;
92a8780e 668
37fb3a30 669 /** Are posix file locking primitives not implemented by fs? */
1729a16c 670 unsigned no_lock:1;
71421259 671
31d40d74 672 /** Is access not implemented by fs? */
1729a16c 673 unsigned no_access:1;
31d40d74 674
fd72faac 675 /** Is create not implemented by fs? */
1729a16c 676 unsigned no_create:1;
fd72faac 677
a4d27e75 678 /** Is interrupt not implemented by fs? */
1729a16c 679 unsigned no_interrupt:1;
a4d27e75 680
b2d2272f 681 /** Is bmap not implemented by fs? */
1729a16c 682 unsigned no_bmap:1;
b2d2272f 683
95668a69
TH
684 /** Is poll not implemented by fs? */
685 unsigned no_poll:1;
686
78bb6cb9 687 /** Do multi-page cached writes */
1729a16c 688 unsigned big_writes:1;
78bb6cb9 689
e0a43ddc
MS
690 /** Don't apply umask to creation modes */
691 unsigned dont_mask:1;
692
37fb3a30
MS
693 /** Are BSD file locking primitives not implemented by fs? */
694 unsigned no_flock:1;
695
519c6040
MS
696 /** Is fallocate not implemented by fs? */
697 unsigned no_fallocate:1;
698
1560c974
MS
699 /** Is rename with flags implemented by fs? */
700 unsigned no_rename2:1;
701
72d0d248
BF
702 /** Use enhanced/automatic page cache invalidation. */
703 unsigned auto_inval_data:1;
704
ad2ba64d
KS
705 /** Filesystem is fully reponsible for page cache invalidation. */
706 unsigned explicit_inval_data:1;
707
634734b6 708 /** Does the filesystem support readdirplus? */
0b05b183
AA
709 unsigned do_readdirplus:1;
710
634734b6
EW
711 /** Does the filesystem want adaptive readdirplus? */
712 unsigned readdirplus_auto:1;
713
60b9df7a
MS
714 /** Does the filesystem support asynchronous direct-IO submission? */
715 unsigned async_dio:1;
716
0b5da8db
R
717 /** Is lseek not implemented by fs? */
718 unsigned no_lseek:1;
719
60bcc88a
SF
720 /** Does the filesystem support posix acls? */
721 unsigned posix_acl:1;
722
29433a29
MS
723 /** Check permissions based on the file mode or not? */
724 unsigned default_permissions:1;
725
726 /** Allow other than the mounter user to access the filesystem ? */
727 unsigned allow_other:1;
728
88bc7d50
NV
729 /** Does the filesystem support copy_file_range? */
730 unsigned no_copy_file_range:1;
731
1ccd1ea2
MS
732 /* Send DESTROY request */
733 unsigned int destroy:1;
734
8fab0106
MS
735 /* Delete dentries that have gone stale */
736 unsigned int delete_stale:1;
737
15c8e72e
VG
738 /** Do not create entry in fusectl fs */
739 unsigned int no_control:1;
740
741 /** Do not allow MNT_FORCE umount */
742 unsigned int no_force_umount:1;
743
0cd5b885
MS
744 /** The number of requests waiting for completion */
745 atomic_t num_waiting;
746
45714d65
MS
747 /** Negotiated minor version */
748 unsigned minor;
749
bafa9654
MS
750 /** Entry on the fuse_conn_list */
751 struct list_head entry;
752
b6f2fcbc
MS
753 /** Device ID from super block */
754 dev_t dev;
bafa9654
MS
755
756 /** Dentries in the control filesystem */
757 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
758
759 /** number of dentries used in the above array */
760 int ctl_ndents;
385a17bf 761
9c8ef561
MS
762 /** Key for lock owner ID scrambling */
763 u32 scramble_key[4];
0ec7ca41 764
1fb69e78 765 /** Version counter for attribute changes */
4510d86f 766 atomic64_t attr_version;
43901aab
TH
767
768 /** Called on final put */
769 void (*release)(struct fuse_conn *);
3b463ae0
JM
770
771 /** Super block for this connection. */
772 struct super_block *sb;
773
774 /** Read/write semaphore to hold when accessing sb. */
775 struct rw_semaphore killsb;
cc080e9e
MS
776
777 /** List of device instances belonging to this connection */
778 struct list_head devices;
1dd53957
VG
779
780#ifdef CONFIG_FUSE_DAX
781 /* Dax specific conn data, non-NULL if DAX is enabled */
782 struct fuse_conn_dax *dax;
783#endif
d8a5ba45
MS
784};
785
d8a5ba45
MS
786static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
787{
6383bdaa 788 return sb->s_fs_info;
d8a5ba45
MS
789}
790
791static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
792{
793 return get_fuse_conn_super(inode->i_sb);
794}
795
796static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
797{
798 return container_of(inode, struct fuse_inode, inode);
799}
800
801static inline u64 get_node_id(struct inode *inode)
802{
803 return get_fuse_inode(inode)->nodeid;
804}
805
d123d8e1
MS
806static inline int invalid_nodeid(u64 nodeid)
807{
808 return !nodeid || nodeid == FUSE_ROOT_ID;
809}
810
4510d86f
KT
811static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
812{
813 return atomic64_read(&fc->attr_version);
814}
815
334f485d 816/** Device operations */
4b6f5d20 817extern const struct file_operations fuse_dev_operations;
334f485d 818
4269590a 819extern const struct dentry_operations fuse_dentry_operations;
0ce267ff 820extern const struct dentry_operations fuse_root_dentry_operations;
dbd561d2 821
3b463ae0
JM
822/**
823 * Inode to nodeid comparison.
824 */
825int fuse_inode_eq(struct inode *inode, void *_nodeidp);
826
e5e5558e
MS
827/**
828 * Get a filled in inode
829 */
b48badf0 830struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
1fb69e78
MS
831 int generation, struct fuse_attr *attr,
832 u64 attr_valid, u64 attr_version);
e5e5558e 833
13983d06 834int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
33670fa2
MS
835 struct fuse_entry_out *outarg, struct inode **inode);
836
e5e5558e
MS
837/**
838 * Send FORGET command
839 */
07e77dca
MS
840void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
841 u64 nodeid, u64 nlookup);
842
843struct fuse_forget_link *fuse_alloc_forget(void);
e5e5558e 844
4388c5aa
VG
845struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq,
846 unsigned int max,
847 unsigned int *countp);
848
43f5098e 849/*
361b1eb5 850 * Initialize READ or READDIR request
04730fef 851 */
43f5098e
MS
852struct fuse_io_args {
853 union {
854 struct {
855 struct fuse_read_in in;
856 u64 attr_ver;
857 } read;
858 struct {
859 struct fuse_write_in in;
860 struct fuse_write_out out;
861 } write;
862 };
863 struct fuse_args_pages ap;
864 struct fuse_io_priv *io;
865 struct fuse_file *ff;
866};
867
868void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
869 size_t count, int opcode);
870
04730fef
MS
871
872/**
873 * Send OPEN or OPENDIR request
874 */
91fe96b4 875int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
04730fef 876
acf99433 877struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
fd72faac 878void fuse_file_free(struct fuse_file *ff);
c7b7143c 879void fuse_finish_open(struct inode *inode, struct file *file);
fd72faac 880
ebf84d0c 881void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
c756e0a4 882
04730fef
MS
883/**
884 * Send RELEASE or RELEASEDIR request
885 */
2e64ff15 886void fuse_release_common(struct file *file, bool isdir);
04730fef 887
82547981
MS
888/**
889 * Send FSYNC or FSYNCDIR request
890 */
02c24a82 891int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
a9c2d1e8 892 int datasync, int opcode);
82547981 893
95668a69
TH
894/**
895 * Notify poll wakeup
896 */
897int fuse_notify_poll_wakeup(struct fuse_conn *fc,
898 struct fuse_notify_poll_wakeup_out *outarg);
899
b6aeaded 900/**
1779381d 901 * Initialize file operations on a regular file
b6aeaded
MS
902 */
903void fuse_init_file_inode(struct inode *inode);
904
e5e5558e 905/**
1779381d 906 * Initialize inode operations on regular files and special files
e5e5558e
MS
907 */
908void fuse_init_common(struct inode *inode);
909
910/**
1779381d 911 * Initialize inode and file operations on a directory
e5e5558e
MS
912 */
913void fuse_init_dir(struct inode *inode);
914
915/**
1779381d 916 * Initialize inode operations on a symlink
e5e5558e
MS
917 */
918void fuse_init_symlink(struct inode *inode);
919
920/**
921 * Change attributes of an inode
922 */
1fb69e78
MS
923void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
924 u64 attr_valid, u64 attr_version);
e5e5558e 925
3be5a52b
MS
926void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
927 u64 attr_valid);
928
334f485d
MS
929/**
930 * Initialize the client device
931 */
932int fuse_dev_init(void);
933
934/**
935 * Cleanup the client device
936 */
937void fuse_dev_cleanup(void);
938
bafa9654 939int fuse_ctl_init(void);
7736e8cc 940void __exit fuse_ctl_cleanup(void);
bafa9654 941
7078187a
MS
942/**
943 * Simple request sending that does request allocation and freeing
944 */
945ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
12597287
MS
946int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,
947 gfp_t gfp_flags);
7078187a 948
04ec5af0
SH
949/**
950 * End a finished request
951 */
952void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req);
953
5a5fb1ea 954/* Abort all requests */
eb98e3bd 955void fuse_abort_conn(struct fuse_conn *fc);
b8f95e5d 956void fuse_wait_aborted(struct fuse_conn *fc);
69a53bf2 957
e5e5558e
MS
958/**
959 * Invalidate inode attributes
960 */
961void fuse_invalidate_attr(struct inode *inode);
bafa9654 962
dbd561d2
MS
963void fuse_invalidate_entry_cache(struct dentry *entry);
964
451418fc
AG
965void fuse_invalidate_atime(struct inode *inode);
966
d123d8e1
MS
967u64 entry_attr_timeout(struct fuse_entry_out *o);
968void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
969
bafa9654
MS
970/**
971 * Acquire reference to fuse_conn
972 */
973struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
974
0d179aa5
TH
975/**
976 * Initialize fuse_conn
977 */
ae3aad77
SH
978void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
979 const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
0d179aa5 980
bafa9654
MS
981/**
982 * Release reference to fuse_conn
983 */
984void fuse_conn_put(struct fuse_conn *fc);
985
0cd1eb9a
VG
986struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
987struct fuse_dev *fuse_dev_alloc(void);
988void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
cc080e9e 989void fuse_dev_free(struct fuse_dev *fud);
95a84cdb 990void fuse_send_init(struct fuse_conn *fc);
cc080e9e 991
0cc2656c
SH
992/**
993 * Fill in superblock and initialize fuse connection
994 * @sb: partially-initialized superblock to fill in
995 * @ctx: mount context
996 */
997int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
998
783863d6
MS
999/**
1000 * Disassociate fuse connection from superblock and kill the superblock
1001 *
1002 * Calls kill_anon_super(), do not use with bdev mounts.
1003 */
1004void fuse_kill_sb_anon(struct super_block *sb);
1005
bafa9654
MS
1006/**
1007 * Add connection to control filesystem
1008 */
1009int fuse_ctl_add_conn(struct fuse_conn *fc);
1010
1011/**
1012 * Remove connection from control filesystem
1013 */
1014void fuse_ctl_remove_conn(struct fuse_conn *fc);
a5bfffac
TS
1015
1016/**
1017 * Is file type valid?
1018 */
1019int fuse_valid_type(int m);
e57ac683 1020
eb59bd17
MS
1021bool fuse_invalid_attr(struct fuse_attr *attr);
1022
e57ac683 1023/**
c2132c1b 1024 * Is current process allowed to perform filesystem operation?
e57ac683 1025 */
c2132c1b 1026int fuse_allow_current_process(struct fuse_conn *fc);
f3332114
MS
1027
1028u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
bcb4be80 1029
703c7362
SF
1030void fuse_update_ctime(struct inode *inode);
1031
5b97eeac 1032int fuse_update_attributes(struct inode *inode, struct file *file);
3be5a52b
MS
1033
1034void fuse_flush_writepages(struct inode *inode);
1035
1036void fuse_set_nowrite(struct inode *inode);
1037void fuse_release_nowrite(struct inode *inode);
5c5c5e51 1038
3b463ae0
JM
1039/**
1040 * File-system tells the kernel to invalidate cache for the given node id.
1041 */
1042int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
1043 loff_t offset, loff_t len);
1044
1045/**
1046 * File-system tells the kernel to invalidate parent attributes and
1047 * the dentry matching parent/name.
451d0f59
JM
1048 *
1049 * If the child_nodeid is non-zero and:
1050 * - matches the inode number for the dentry matching parent/name,
1051 * - is not a mount point
1052 * - is a file or oan empty directory
1053 * then the dentry is unhashed (d_delete()).
3b463ae0
JM
1054 */
1055int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
451d0f59 1056 u64 child_nodeid, struct qstr *name);
3b463ae0 1057
08cbf542
TH
1058int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
1059 bool isdir);
ea8cd333
PE
1060
1061/**
1062 * fuse_direct_io() flags
1063 */
1064
1065/** If set, it is WRITE; otherwise - READ */
1066#define FUSE_DIO_WRITE (1 << 0)
1067
1068/** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1069#define FUSE_DIO_CUSE (1 << 1)
1070
d22a943f
AV
1071ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1072 loff_t *ppos, int flags);
08cbf542
TH
1073long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1074 unsigned int flags);
b18da0c5
MS
1075long fuse_ioctl_common(struct file *file, unsigned int cmd,
1076 unsigned long arg, unsigned int flags);
076ccb76 1077__poll_t fuse_file_poll(struct file *file, poll_table *wait);
08cbf542
TH
1078int fuse_dev_release(struct inode *inode, struct file *file);
1079
b0aa7606
MP
1080bool fuse_write_update_size(struct inode *inode, loff_t pos);
1081
ab9e13f7 1082int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
1e18bda8 1083int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
a1d75f25 1084
62490330 1085int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
efb9fa9e
MP
1086 struct file *file);
1087
9759bd51
MS
1088void fuse_set_initialized(struct fuse_conn *fc);
1089
63576c13
MS
1090void fuse_unlock_inode(struct inode *inode, bool locked);
1091bool fuse_lock_inode(struct inode *inode);
5c672ab3 1092
60bcc88a
SF
1093int fuse_setxattr(struct inode *inode, const char *name, const void *value,
1094 size_t size, int flags);
1095ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
1096 size_t size);
703c7362 1097ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
60bcc88a 1098int fuse_removexattr(struct inode *inode, const char *name);
703c7362 1099extern const struct xattr_handler *fuse_xattr_handlers[];
60bcc88a 1100extern const struct xattr_handler *fuse_acl_xattr_handlers[];
e45b2546 1101extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
60bcc88a
SF
1102
1103struct posix_acl;
1104struct posix_acl *fuse_get_acl(struct inode *inode, int type);
1105int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
703c7362 1106
d123d8e1
MS
1107
1108/* readdir.c */
1109int fuse_readdir(struct file *file, struct dir_context *ctx);
1110
14d46d7a
SH
1111/**
1112 * Return the number of bytes in an arguments list
1113 */
1114unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
1115
79d96eff
SH
1116/**
1117 * Get the next unique ID for a request
1118 */
1119u64 fuse_get_unique(struct fuse_iqueue *fiq);
783863d6 1120void fuse_free_conn(struct fuse_conn *fc);
79d96eff 1121
1dd53957
VG
1122/* dax.c */
1123
c2d0ad00
VG
1124#define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1125
1126ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
1127ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
1128int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
6ae330ca 1129int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
1dd53957
VG
1130int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev);
1131void fuse_dax_conn_free(struct fuse_conn *fc);
c2d0ad00
VG
1132bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
1133void fuse_dax_inode_init(struct inode *inode);
1134void fuse_dax_inode_cleanup(struct inode *inode);
fd1a1dc6 1135bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
9a752d18 1136void fuse_dax_cancel_work(struct fuse_conn *fc);
1dd53957 1137
29d434b3 1138#endif /* _FS_FUSE_I_H */