]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/fuse/fuse_i.h
virtiofs: add logic to free up a memory range
[mirror_ubuntu-hirsute-kernel.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
334f485d
MS
377};
378
ae3aad77
SH
379struct fuse_iqueue;
380
381/**
382 * Input queue callbacks
383 *
384 * Input queue signalling is device-specific. For example, the /dev/fuse file
385 * uses fiq->waitq and fasync to wake processes that are waiting on queue
386 * readiness. These callbacks allow other device types to respond to input
387 * queue activity.
388 */
389struct fuse_iqueue_ops {
390 /**
391 * Signal that a forget has been queued
392 */
393 void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
394 __releases(fiq->lock);
395
396 /**
397 * Signal that an INTERRUPT request has been queued
398 */
399 void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
400 __releases(fiq->lock);
401
402 /**
403 * Signal that a request has been queued
404 */
405 void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
406 __releases(fiq->lock);
a62a8ef9
SH
407
408 /**
409 * Clean up when fuse_iqueue is destroyed
410 */
411 void (*release)(struct fuse_iqueue *fiq);
ae3aad77
SH
412};
413
414/** /dev/fuse input queue operations */
415extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
416
f88996a9 417struct fuse_iqueue {
e16714d8
MS
418 /** Connection established */
419 unsigned connected;
420
76e43c8c
EB
421 /** Lock protecting accesses to members of this structure */
422 spinlock_t lock;
423
f88996a9
MS
424 /** Readers of the connection are waiting on this */
425 wait_queue_head_t waitq;
426
427 /** The next unique request id */
428 u64 reqctr;
429
430 /** The list of pending requests */
431 struct list_head pending;
432
433 /** Pending interrupts */
434 struct list_head interrupts;
435
436 /** Queue of pending forgets */
437 struct fuse_forget_link forget_list_head;
438 struct fuse_forget_link *forget_list_tail;
439
440 /** Batching of FORGET requests (positive indicates FORGET batch) */
441 int forget_batch;
442
443 /** O_ASYNC requests */
444 struct fasync_struct *fasync;
ae3aad77
SH
445
446 /** Device-specific callbacks */
447 const struct fuse_iqueue_ops *ops;
448
449 /** Device-specific state */
450 void *priv;
f88996a9
MS
451};
452
be2ff42c
KT
453#define FUSE_PQ_HASH_BITS 8
454#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
455
3a2b5b9c 456struct fuse_pqueue {
e96edd94
MS
457 /** Connection established */
458 unsigned connected;
459
45a91cb1
MS
460 /** Lock protecting accessess to members of this structure */
461 spinlock_t lock;
462
be2ff42c
KT
463 /** Hash table of requests being processed */
464 struct list_head *processing;
3a2b5b9c
MS
465
466 /** The list of requests under I/O */
467 struct list_head io;
468};
469
cc080e9e
MS
470/**
471 * Fuse device instance
472 */
473struct fuse_dev {
474 /** Fuse connection for this device */
475 struct fuse_conn *fc;
476
c3696046
MS
477 /** Processing queue */
478 struct fuse_pqueue pq;
479
cc080e9e
MS
480 /** list entry on fc->devices */
481 struct list_head entry;
482};
483
0cc2656c
SH
484struct fuse_fs_context {
485 int fd;
486 unsigned int rootmode;
487 kuid_t user_id;
488 kgid_t group_id;
489 bool is_bdev:1;
490 bool fd_present:1;
491 bool rootmode_present:1;
492 bool user_id_present:1;
493 bool group_id_present:1;
494 bool default_permissions:1;
495 bool allow_other:1;
783863d6 496 bool destroy:1;
15c8e72e
VG
497 bool no_control:1;
498 bool no_force_umount:1;
f4fd4ae3 499 bool legacy_opts_show:1;
1dd53957 500 bool dax:1;
0cc2656c
SH
501 unsigned int max_read;
502 unsigned int blksize;
503 const char *subtype;
504
1dd53957
VG
505 /* DAX device, may be NULL */
506 struct dax_device *dax_dev;
507
0cc2656c
SH
508 /* fuse_dev pointer to fill in, should contain NULL on entry */
509 void **fudptr;
510};
511
d8a5ba45
MS
512/**
513 * A Fuse connection.
514 *
515 * This structure is created, when the filesystem is mounted, and is
516 * destroyed, when the client device is closed and the filesystem is
517 * unmounted.
518 */
519struct fuse_conn {
d7133114
MS
520 /** Lock protecting accessess to members of this structure */
521 spinlock_t lock;
522
bafa9654 523 /** Refcount */
095fc40a 524 refcount_t count;
bafa9654 525
c3696046
MS
526 /** Number of fuse_dev's */
527 atomic_t dev_count;
528
dd3e2c55
AV
529 struct rcu_head rcu;
530
d8a5ba45 531 /** The user id for this mount */
499dcf20 532 kuid_t user_id;
d8a5ba45 533
87729a55 534 /** The group id for this mount */
499dcf20 535 kgid_t group_id;
87729a55 536
0b6e9ea0
SF
537 /** The pid namespace for this mount */
538 struct pid_namespace *pid_ns;
539
8cb08329
EB
540 /** The user namespace for this mount */
541 struct user_namespace *user_ns;
542
db50b96c
MS
543 /** Maximum read size */
544 unsigned max_read;
545
413ef8cb
MS
546 /** Maximum write size */
547 unsigned max_write;
548
5da784cc
CS
549 /** Maxmum number of pages that can be used in a single request */
550 unsigned int max_pages;
551
f88996a9
MS
552 /** Input queue */
553 struct fuse_iqueue iq;
334f485d 554
acf99433 555 /** The next unique kernel file handle */
75126f55 556 atomic64_t khctr;
acf99433 557
95668a69
TH
558 /** rbtree of fuse_files waiting for poll events indexed by ph */
559 struct rb_root polled_files;
560
7a6d3c8b
CH
561 /** Maximum number of outstanding background requests */
562 unsigned max_background;
563
564 /** Number of background requests at which congestion starts */
565 unsigned congestion_threshold;
566
08a53cdc
MS
567 /** Number of requests currently in the background */
568 unsigned num_background;
569
d12def1b
MS
570 /** Number of background requests currently queued for userspace */
571 unsigned active_background;
572
573 /** The list of background requests set aside for later queuing */
574 struct list_head bg_queue;
575
ae2dffa3
KT
576 /** Protects: max_background, congestion_threshold, num_background,
577 * active_background, bg_queue, blocked */
578 spinlock_t bg_lock;
579
796523fb
MP
580 /** Flag indicating that INIT reply has been received. Allocating
581 * any fuse request will be suspended until the flag is set */
582 int initialized;
583
08a53cdc
MS
584 /** Flag indicating if connection is blocked. This will be
585 the case before the INIT reply is received, and if there
586 are too many outstading backgrounds requests */
587 int blocked;
588
589 /** waitq for blocked connection */
590 wait_queue_head_t blocked_waitq;
de5e3dec 591
69a53bf2
MS
592 /** Connection established, cleared on umount, connection
593 abort and device release */
095da6cb 594 unsigned connected;
1e9a4ed9 595
3b7008b2
SL
596 /** Connection aborted via sysfs */
597 bool aborted;
598
095da6cb
MS
599 /** Connection failed (version mismatch). Cannot race with
600 setting other bitfields since it is only set once in INIT
601 reply, before any other request, and never cleared */
1729a16c 602 unsigned conn_error:1;
334f485d 603
0ec7ca41 604 /** Connection successful. Only set in INIT */
1729a16c 605 unsigned conn_init:1;
0ec7ca41 606
9cd68455 607 /** Do readpages asynchronously? Only set in INIT */
1729a16c 608 unsigned async_read:1;
9cd68455 609
3b7008b2
SL
610 /** Return an unique read error after abort. Only set in INIT */
611 unsigned abort_err:1;
612
6ff958ed 613 /** Do not send separate SETATTR request before open(O_TRUNC) */
1729a16c 614 unsigned atomic_o_trunc:1;
6ff958ed 615
33670fa2 616 /** Filesystem supports NFS exporting. Only set in INIT */
1729a16c 617 unsigned export_support:1;
33670fa2 618
d5cd66c5
PE
619 /** write-back cache policy (default is write-through) */
620 unsigned writeback_cache:1;
621
5c672ab3
MS
622 /** allow parallel lookups and readdir (default is serialized) */
623 unsigned parallel_dirops:1;
624
5e940c1d
MS
625 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
626 unsigned handle_killpriv:1;
627
5571f1e6
DS
628 /** cache READLINK responses in page cache */
629 unsigned cache_symlinks:1;
630
f4fd4ae3
VG
631 /* show legacy mount options */
632 unsigned int legacy_opts_show:1;
633
095da6cb
MS
634 /*
635 * The following bitfields are only for optimization purposes
636 * and hence races in setting them will not cause malfunction
637 */
638
7678ac50
AG
639 /** Is open/release not implemented by fs? */
640 unsigned no_open:1;
641
d9a9ea94
CA
642 /** Is opendir/releasedir not implemented by fs? */
643 unsigned no_opendir:1;
644
b6aeaded 645 /** Is fsync not implemented by fs? */
1729a16c 646 unsigned no_fsync:1;
b6aeaded 647
82547981 648 /** Is fsyncdir not implemented by fs? */
1729a16c 649 unsigned no_fsyncdir:1;
82547981 650
b6aeaded 651 /** Is flush not implemented by fs? */
1729a16c 652 unsigned no_flush:1;
b6aeaded 653
92a8780e 654 /** Is setxattr not implemented by fs? */
1729a16c 655 unsigned no_setxattr:1;
92a8780e
MS
656
657 /** Is getxattr not implemented by fs? */
1729a16c 658 unsigned no_getxattr:1;
92a8780e
MS
659
660 /** Is listxattr not implemented by fs? */
1729a16c 661 unsigned no_listxattr:1;
92a8780e
MS
662
663 /** Is removexattr not implemented by fs? */
1729a16c 664 unsigned no_removexattr:1;
92a8780e 665
37fb3a30 666 /** Are posix file locking primitives not implemented by fs? */
1729a16c 667 unsigned no_lock:1;
71421259 668
31d40d74 669 /** Is access not implemented by fs? */
1729a16c 670 unsigned no_access:1;
31d40d74 671
fd72faac 672 /** Is create not implemented by fs? */
1729a16c 673 unsigned no_create:1;
fd72faac 674
a4d27e75 675 /** Is interrupt not implemented by fs? */
1729a16c 676 unsigned no_interrupt:1;
a4d27e75 677
b2d2272f 678 /** Is bmap not implemented by fs? */
1729a16c 679 unsigned no_bmap:1;
b2d2272f 680
95668a69
TH
681 /** Is poll not implemented by fs? */
682 unsigned no_poll:1;
683
78bb6cb9 684 /** Do multi-page cached writes */
1729a16c 685 unsigned big_writes:1;
78bb6cb9 686
e0a43ddc
MS
687 /** Don't apply umask to creation modes */
688 unsigned dont_mask:1;
689
37fb3a30
MS
690 /** Are BSD file locking primitives not implemented by fs? */
691 unsigned no_flock:1;
692
519c6040
MS
693 /** Is fallocate not implemented by fs? */
694 unsigned no_fallocate:1;
695
1560c974
MS
696 /** Is rename with flags implemented by fs? */
697 unsigned no_rename2:1;
698
72d0d248
BF
699 /** Use enhanced/automatic page cache invalidation. */
700 unsigned auto_inval_data:1;
701
ad2ba64d
KS
702 /** Filesystem is fully reponsible for page cache invalidation. */
703 unsigned explicit_inval_data:1;
704
634734b6 705 /** Does the filesystem support readdirplus? */
0b05b183
AA
706 unsigned do_readdirplus:1;
707
634734b6
EW
708 /** Does the filesystem want adaptive readdirplus? */
709 unsigned readdirplus_auto:1;
710
60b9df7a
MS
711 /** Does the filesystem support asynchronous direct-IO submission? */
712 unsigned async_dio:1;
713
0b5da8db
R
714 /** Is lseek not implemented by fs? */
715 unsigned no_lseek:1;
716
60bcc88a
SF
717 /** Does the filesystem support posix acls? */
718 unsigned posix_acl:1;
719
29433a29
MS
720 /** Check permissions based on the file mode or not? */
721 unsigned default_permissions:1;
722
723 /** Allow other than the mounter user to access the filesystem ? */
724 unsigned allow_other:1;
725
88bc7d50
NV
726 /** Does the filesystem support copy_file_range? */
727 unsigned no_copy_file_range:1;
728
1ccd1ea2
MS
729 /* Send DESTROY request */
730 unsigned int destroy:1;
731
8fab0106
MS
732 /* Delete dentries that have gone stale */
733 unsigned int delete_stale:1;
734
15c8e72e
VG
735 /** Do not create entry in fusectl fs */
736 unsigned int no_control:1;
737
738 /** Do not allow MNT_FORCE umount */
739 unsigned int no_force_umount:1;
740
0cd5b885
MS
741 /** The number of requests waiting for completion */
742 atomic_t num_waiting;
743
45714d65
MS
744 /** Negotiated minor version */
745 unsigned minor;
746
bafa9654
MS
747 /** Entry on the fuse_conn_list */
748 struct list_head entry;
749
b6f2fcbc
MS
750 /** Device ID from super block */
751 dev_t dev;
bafa9654
MS
752
753 /** Dentries in the control filesystem */
754 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
755
756 /** number of dentries used in the above array */
757 int ctl_ndents;
385a17bf 758
9c8ef561
MS
759 /** Key for lock owner ID scrambling */
760 u32 scramble_key[4];
0ec7ca41 761
1fb69e78 762 /** Version counter for attribute changes */
4510d86f 763 atomic64_t attr_version;
43901aab
TH
764
765 /** Called on final put */
766 void (*release)(struct fuse_conn *);
3b463ae0
JM
767
768 /** Super block for this connection. */
769 struct super_block *sb;
770
771 /** Read/write semaphore to hold when accessing sb. */
772 struct rw_semaphore killsb;
cc080e9e
MS
773
774 /** List of device instances belonging to this connection */
775 struct list_head devices;
1dd53957
VG
776
777#ifdef CONFIG_FUSE_DAX
778 /* Dax specific conn data, non-NULL if DAX is enabled */
779 struct fuse_conn_dax *dax;
780#endif
d8a5ba45
MS
781};
782
d8a5ba45
MS
783static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
784{
6383bdaa 785 return sb->s_fs_info;
d8a5ba45
MS
786}
787
788static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
789{
790 return get_fuse_conn_super(inode->i_sb);
791}
792
793static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
794{
795 return container_of(inode, struct fuse_inode, inode);
796}
797
798static inline u64 get_node_id(struct inode *inode)
799{
800 return get_fuse_inode(inode)->nodeid;
801}
802
d123d8e1
MS
803static inline int invalid_nodeid(u64 nodeid)
804{
805 return !nodeid || nodeid == FUSE_ROOT_ID;
806}
807
4510d86f
KT
808static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
809{
810 return atomic64_read(&fc->attr_version);
811}
812
334f485d 813/** Device operations */
4b6f5d20 814extern const struct file_operations fuse_dev_operations;
334f485d 815
4269590a 816extern const struct dentry_operations fuse_dentry_operations;
0ce267ff 817extern const struct dentry_operations fuse_root_dentry_operations;
dbd561d2 818
3b463ae0
JM
819/**
820 * Inode to nodeid comparison.
821 */
822int fuse_inode_eq(struct inode *inode, void *_nodeidp);
823
e5e5558e
MS
824/**
825 * Get a filled in inode
826 */
b48badf0 827struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
1fb69e78
MS
828 int generation, struct fuse_attr *attr,
829 u64 attr_valid, u64 attr_version);
e5e5558e 830
13983d06 831int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
33670fa2
MS
832 struct fuse_entry_out *outarg, struct inode **inode);
833
e5e5558e
MS
834/**
835 * Send FORGET command
836 */
07e77dca
MS
837void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
838 u64 nodeid, u64 nlookup);
839
840struct fuse_forget_link *fuse_alloc_forget(void);
e5e5558e 841
4388c5aa
VG
842struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq,
843 unsigned int max,
844 unsigned int *countp);
845
43f5098e 846/*
361b1eb5 847 * Initialize READ or READDIR request
04730fef 848 */
43f5098e
MS
849struct fuse_io_args {
850 union {
851 struct {
852 struct fuse_read_in in;
853 u64 attr_ver;
854 } read;
855 struct {
856 struct fuse_write_in in;
857 struct fuse_write_out out;
858 } write;
859 };
860 struct fuse_args_pages ap;
861 struct fuse_io_priv *io;
862 struct fuse_file *ff;
863};
864
865void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
866 size_t count, int opcode);
867
04730fef
MS
868
869/**
870 * Send OPEN or OPENDIR request
871 */
91fe96b4 872int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
04730fef 873
acf99433 874struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
fd72faac 875void fuse_file_free(struct fuse_file *ff);
c7b7143c 876void fuse_finish_open(struct inode *inode, struct file *file);
fd72faac 877
ebf84d0c 878void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
c756e0a4 879
04730fef
MS
880/**
881 * Send RELEASE or RELEASEDIR request
882 */
2e64ff15 883void fuse_release_common(struct file *file, bool isdir);
04730fef 884
82547981
MS
885/**
886 * Send FSYNC or FSYNCDIR request
887 */
02c24a82 888int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
a9c2d1e8 889 int datasync, int opcode);
82547981 890
95668a69
TH
891/**
892 * Notify poll wakeup
893 */
894int fuse_notify_poll_wakeup(struct fuse_conn *fc,
895 struct fuse_notify_poll_wakeup_out *outarg);
896
b6aeaded 897/**
1779381d 898 * Initialize file operations on a regular file
b6aeaded
MS
899 */
900void fuse_init_file_inode(struct inode *inode);
901
e5e5558e 902/**
1779381d 903 * Initialize inode operations on regular files and special files
e5e5558e
MS
904 */
905void fuse_init_common(struct inode *inode);
906
907/**
1779381d 908 * Initialize inode and file operations on a directory
e5e5558e
MS
909 */
910void fuse_init_dir(struct inode *inode);
911
912/**
1779381d 913 * Initialize inode operations on a symlink
e5e5558e
MS
914 */
915void fuse_init_symlink(struct inode *inode);
916
917/**
918 * Change attributes of an inode
919 */
1fb69e78
MS
920void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
921 u64 attr_valid, u64 attr_version);
e5e5558e 922
3be5a52b
MS
923void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
924 u64 attr_valid);
925
334f485d
MS
926/**
927 * Initialize the client device
928 */
929int fuse_dev_init(void);
930
931/**
932 * Cleanup the client device
933 */
934void fuse_dev_cleanup(void);
935
bafa9654 936int fuse_ctl_init(void);
7736e8cc 937void __exit fuse_ctl_cleanup(void);
bafa9654 938
7078187a
MS
939/**
940 * Simple request sending that does request allocation and freeing
941 */
942ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
12597287
MS
943int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,
944 gfp_t gfp_flags);
7078187a 945
04ec5af0
SH
946/**
947 * End a finished request
948 */
949void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req);
950
5a5fb1ea 951/* Abort all requests */
eb98e3bd 952void fuse_abort_conn(struct fuse_conn *fc);
b8f95e5d 953void fuse_wait_aborted(struct fuse_conn *fc);
69a53bf2 954
e5e5558e
MS
955/**
956 * Invalidate inode attributes
957 */
958void fuse_invalidate_attr(struct inode *inode);
bafa9654 959
dbd561d2
MS
960void fuse_invalidate_entry_cache(struct dentry *entry);
961
451418fc
AG
962void fuse_invalidate_atime(struct inode *inode);
963
d123d8e1
MS
964u64 entry_attr_timeout(struct fuse_entry_out *o);
965void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
966
bafa9654
MS
967/**
968 * Acquire reference to fuse_conn
969 */
970struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
971
0d179aa5
TH
972/**
973 * Initialize fuse_conn
974 */
ae3aad77
SH
975void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
976 const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
0d179aa5 977
bafa9654
MS
978/**
979 * Release reference to fuse_conn
980 */
981void fuse_conn_put(struct fuse_conn *fc);
982
0cd1eb9a
VG
983struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
984struct fuse_dev *fuse_dev_alloc(void);
985void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
cc080e9e 986void fuse_dev_free(struct fuse_dev *fud);
95a84cdb 987void fuse_send_init(struct fuse_conn *fc);
cc080e9e 988
0cc2656c
SH
989/**
990 * Fill in superblock and initialize fuse connection
991 * @sb: partially-initialized superblock to fill in
992 * @ctx: mount context
993 */
994int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx);
995
783863d6
MS
996/**
997 * Disassociate fuse connection from superblock and kill the superblock
998 *
999 * Calls kill_anon_super(), do not use with bdev mounts.
1000 */
1001void fuse_kill_sb_anon(struct super_block *sb);
1002
bafa9654
MS
1003/**
1004 * Add connection to control filesystem
1005 */
1006int fuse_ctl_add_conn(struct fuse_conn *fc);
1007
1008/**
1009 * Remove connection from control filesystem
1010 */
1011void fuse_ctl_remove_conn(struct fuse_conn *fc);
a5bfffac
TS
1012
1013/**
1014 * Is file type valid?
1015 */
1016int fuse_valid_type(int m);
e57ac683 1017
eb59bd17
MS
1018bool fuse_invalid_attr(struct fuse_attr *attr);
1019
e57ac683 1020/**
c2132c1b 1021 * Is current process allowed to perform filesystem operation?
e57ac683 1022 */
c2132c1b 1023int fuse_allow_current_process(struct fuse_conn *fc);
f3332114
MS
1024
1025u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
bcb4be80 1026
703c7362
SF
1027void fuse_update_ctime(struct inode *inode);
1028
5b97eeac 1029int fuse_update_attributes(struct inode *inode, struct file *file);
3be5a52b
MS
1030
1031void fuse_flush_writepages(struct inode *inode);
1032
1033void fuse_set_nowrite(struct inode *inode);
1034void fuse_release_nowrite(struct inode *inode);
5c5c5e51 1035
3b463ae0
JM
1036/**
1037 * File-system tells the kernel to invalidate cache for the given node id.
1038 */
1039int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
1040 loff_t offset, loff_t len);
1041
1042/**
1043 * File-system tells the kernel to invalidate parent attributes and
1044 * the dentry matching parent/name.
451d0f59
JM
1045 *
1046 * If the child_nodeid is non-zero and:
1047 * - matches the inode number for the dentry matching parent/name,
1048 * - is not a mount point
1049 * - is a file or oan empty directory
1050 * then the dentry is unhashed (d_delete()).
3b463ae0
JM
1051 */
1052int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
451d0f59 1053 u64 child_nodeid, struct qstr *name);
3b463ae0 1054
08cbf542
TH
1055int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
1056 bool isdir);
ea8cd333
PE
1057
1058/**
1059 * fuse_direct_io() flags
1060 */
1061
1062/** If set, it is WRITE; otherwise - READ */
1063#define FUSE_DIO_WRITE (1 << 0)
1064
1065/** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1066#define FUSE_DIO_CUSE (1 << 1)
1067
d22a943f
AV
1068ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1069 loff_t *ppos, int flags);
08cbf542
TH
1070long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1071 unsigned int flags);
b18da0c5
MS
1072long fuse_ioctl_common(struct file *file, unsigned int cmd,
1073 unsigned long arg, unsigned int flags);
076ccb76 1074__poll_t fuse_file_poll(struct file *file, poll_table *wait);
08cbf542
TH
1075int fuse_dev_release(struct inode *inode, struct file *file);
1076
b0aa7606
MP
1077bool fuse_write_update_size(struct inode *inode, loff_t pos);
1078
ab9e13f7 1079int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
1e18bda8 1080int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
a1d75f25 1081
62490330 1082int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
efb9fa9e
MP
1083 struct file *file);
1084
9759bd51
MS
1085void fuse_set_initialized(struct fuse_conn *fc);
1086
63576c13
MS
1087void fuse_unlock_inode(struct inode *inode, bool locked);
1088bool fuse_lock_inode(struct inode *inode);
5c672ab3 1089
60bcc88a
SF
1090int fuse_setxattr(struct inode *inode, const char *name, const void *value,
1091 size_t size, int flags);
1092ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
1093 size_t size);
703c7362 1094ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
60bcc88a 1095int fuse_removexattr(struct inode *inode, const char *name);
703c7362 1096extern const struct xattr_handler *fuse_xattr_handlers[];
60bcc88a 1097extern const struct xattr_handler *fuse_acl_xattr_handlers[];
e45b2546 1098extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
60bcc88a
SF
1099
1100struct posix_acl;
1101struct posix_acl *fuse_get_acl(struct inode *inode, int type);
1102int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
703c7362 1103
d123d8e1
MS
1104
1105/* readdir.c */
1106int fuse_readdir(struct file *file, struct dir_context *ctx);
1107
14d46d7a
SH
1108/**
1109 * Return the number of bytes in an arguments list
1110 */
1111unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
1112
79d96eff
SH
1113/**
1114 * Get the next unique ID for a request
1115 */
1116u64 fuse_get_unique(struct fuse_iqueue *fiq);
783863d6 1117void fuse_free_conn(struct fuse_conn *fc);
79d96eff 1118
1dd53957
VG
1119/* dax.c */
1120
c2d0ad00
VG
1121#define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode))
1122
1123ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
1124ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
1125int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
6ae330ca 1126int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
1dd53957
VG
1127int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev);
1128void fuse_dax_conn_free(struct fuse_conn *fc);
c2d0ad00
VG
1129bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
1130void fuse_dax_inode_init(struct inode *inode);
1131void fuse_dax_inode_cleanup(struct inode *inode);
fd1a1dc6 1132bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
9a752d18 1133void fuse_dax_cancel_work(struct fuse_conn *fc);
1dd53957 1134
29d434b3 1135#endif /* _FS_FUSE_I_H */