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