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 | ||
d8a5ba45 MS |
12 | #include <linux/fuse.h> |
13 | #include <linux/fs.h> | |
51eb01e7 | 14 | #include <linux/mount.h> |
d8a5ba45 MS |
15 | #include <linux/wait.h> |
16 | #include <linux/list.h> | |
17 | #include <linux/spinlock.h> | |
18 | #include <linux/mm.h> | |
19 | #include <linux/backing-dev.h> | |
bafa9654 | 20 | #include <linux/mutex.h> |
3be5a52b | 21 | #include <linux/rwsem.h> |
95668a69 TH |
22 | #include <linux/rbtree.h> |
23 | #include <linux/poll.h> | |
5a18ec17 | 24 | #include <linux/workqueue.h> |
744742d6 | 25 | #include <linux/kref.h> |
60bcc88a | 26 | #include <linux/xattr.h> |
0b6e9ea0 | 27 | #include <linux/pid_namespace.h> |
4e8c2eb5 | 28 | #include <linux/refcount.h> |
8cb08329 | 29 | #include <linux/user_namespace.h> |
d8a5ba45 | 30 | |
334f485d MS |
31 | /** Max number of pages that can be used in a single read request */ |
32 | #define FUSE_MAX_PAGES_PER_REQ 32 | |
33 | ||
3be5a52b MS |
34 | /** Bias for fi->writectr, meaning new writepages must not be sent */ |
35 | #define FUSE_NOWRITE INT_MIN | |
36 | ||
1d3d752b MS |
37 | /** It could be as large as PATH_MAX, but would that have any uses? */ |
38 | #define FUSE_NAME_MAX 1024 | |
39 | ||
bafa9654 | 40 | /** Number of dentries for each connection in the control filesystem */ |
79a9d994 | 41 | #define FUSE_CTL_NUM_DENTRIES 5 |
bafa9654 | 42 | |
4250c066 MP |
43 | /** Number of page pointers embedded in fuse_req */ |
44 | #define FUSE_REQ_INLINE_PAGES 1 | |
45 | ||
bafa9654 MS |
46 | /** List of active connections */ |
47 | extern struct list_head fuse_conn_list; | |
48 | ||
49 | /** Global mutex protecting fuse_conn_list and the control filesystem */ | |
50 | extern struct mutex fuse_mutex; | |
413ef8cb | 51 | |
79a9d994 CH |
52 | /** Module parameters */ |
53 | extern unsigned max_user_bgreq; | |
54 | extern unsigned max_user_congthresh; | |
55 | ||
07e77dca MS |
56 | /* One forget request */ |
57 | struct fuse_forget_link { | |
02c048b9 | 58 | struct fuse_forget_one forget_one; |
07e77dca MS |
59 | struct fuse_forget_link *next; |
60 | }; | |
61 | ||
d8a5ba45 MS |
62 | /** FUSE inode */ |
63 | struct fuse_inode { | |
64 | /** Inode data */ | |
65 | struct inode inode; | |
66 | ||
67 | /** Unique ID, which identifies the inode between userspace | |
68 | * and kernel */ | |
69 | u64 nodeid; | |
70 | ||
9e6268db MS |
71 | /** Number of lookups on this inode */ |
72 | u64 nlookup; | |
73 | ||
e5e5558e | 74 | /** The request used for sending the FORGET message */ |
07e77dca | 75 | struct fuse_forget_link *forget; |
e5e5558e | 76 | |
d8a5ba45 | 77 | /** Time in jiffies until the file attributes are valid */ |
0a0898cf | 78 | u64 i_time; |
ebc14c4d MS |
79 | |
80 | /** The sticky bit in inode->i_mode may have been removed, so | |
81 | preserve the original mode */ | |
541af6a0 | 82 | umode_t orig_i_mode; |
1fb69e78 | 83 | |
45c72cd7 PS |
84 | /** 64 bit inode number */ |
85 | u64 orig_ino; | |
86 | ||
1fb69e78 MS |
87 | /** Version of last attribute change */ |
88 | u64 attr_version; | |
93a8c3cd MS |
89 | |
90 | /** Files usable in writepage. Protected by fc->lock */ | |
91 | struct list_head write_files; | |
3be5a52b MS |
92 | |
93 | /** Writepages pending on truncate or fsync */ | |
94 | struct list_head queued_writes; | |
95 | ||
96 | /** Number of sent writes, a negative bias (FUSE_NOWRITE) | |
97 | * means more writes are blocked */ | |
98 | int writectr; | |
99 | ||
100 | /** Waitq for writepage completion */ | |
101 | wait_queue_head_t page_waitq; | |
102 | ||
103 | /** List of writepage requestst (pending or sent) */ | |
104 | struct list_head writepages; | |
4582a4ab | 105 | |
69e34551 MS |
106 | /* readdir cache */ |
107 | struct { | |
108 | /* true if fully cached */ | |
109 | bool cached; | |
110 | ||
111 | /* size of cache */ | |
112 | loff_t size; | |
113 | ||
114 | /* position at end of cache (position of next entry) */ | |
115 | loff_t pos; | |
116 | ||
3494927e MS |
117 | /* version of the cache */ |
118 | u64 version; | |
119 | ||
7118883b MS |
120 | /* modification time of directory when cache was started */ |
121 | struct timespec64 mtime; | |
122 | ||
261aaba7 MS |
123 | /* iversion of directory when cache was started */ |
124 | u64 iversion; | |
125 | ||
69e34551 MS |
126 | /* protects above fields */ |
127 | spinlock_t lock; | |
128 | } rdc; | |
129 | ||
4582a4ab FS |
130 | /** Miscellaneous bits describing inode state */ |
131 | unsigned long state; | |
5c672ab3 MS |
132 | |
133 | /** Lock for serializing lookup and readdir for back compatibility*/ | |
134 | struct mutex mutex; | |
4582a4ab FS |
135 | }; |
136 | ||
137 | /** FUSE inode state bits */ | |
138 | enum { | |
139 | /** Advise readdirplus */ | |
140 | FUSE_I_ADVISE_RDPLUS, | |
6314efee MS |
141 | /** Initialized with readdirplus */ |
142 | FUSE_I_INIT_RDPLUS, | |
06a7c3c2 MP |
143 | /** An operation changing file size is in progress */ |
144 | FUSE_I_SIZE_UNSTABLE, | |
d8a5ba45 MS |
145 | }; |
146 | ||
da5e4714 MS |
147 | struct fuse_conn; |
148 | ||
b6aeaded MS |
149 | /** FUSE specific file data */ |
150 | struct fuse_file { | |
da5e4714 MS |
151 | /** Fuse connection for this file */ |
152 | struct fuse_conn *fc; | |
153 | ||
b6aeaded | 154 | /** Request reserved for flush and release */ |
33649c91 | 155 | struct fuse_req *reserved_req; |
b6aeaded | 156 | |
acf99433 TH |
157 | /** Kernel file handle guaranteed to be unique */ |
158 | u64 kh; | |
159 | ||
b6aeaded MS |
160 | /** File handle used by userspace */ |
161 | u64 fh; | |
c756e0a4 | 162 | |
da5e4714 MS |
163 | /** Node id of this file */ |
164 | u64 nodeid; | |
165 | ||
c756e0a4 | 166 | /** Refcount */ |
4e8c2eb5 | 167 | refcount_t count; |
93a8c3cd | 168 | |
c7b7143c MS |
169 | /** FOPEN_* flags returned by open */ |
170 | u32 open_flags; | |
171 | ||
93a8c3cd MS |
172 | /** Entry on inode's write_files list */ |
173 | struct list_head write_entry; | |
95668a69 | 174 | |
5d7bc7e8 MS |
175 | /* Readdir related */ |
176 | struct { | |
177 | /* | |
178 | * Protects below fields against (crazy) parallel readdir on | |
179 | * same open file. Uncontended in the normal case. | |
180 | */ | |
181 | struct mutex lock; | |
182 | ||
183 | /* Dir stream position */ | |
184 | loff_t pos; | |
185 | ||
186 | /* Offset in cache */ | |
187 | loff_t cache_off; | |
3494927e MS |
188 | |
189 | /* Version of cache we are reading */ | |
190 | u64 version; | |
191 | ||
5d7bc7e8 MS |
192 | } readdir; |
193 | ||
95668a69 TH |
194 | /** RB node to be linked on fuse_conn->polled_files */ |
195 | struct rb_node polled_node; | |
196 | ||
197 | /** Wait queue head for poll */ | |
198 | wait_queue_head_t poll_wait; | |
37fb3a30 MS |
199 | |
200 | /** Has flock been performed on this file? */ | |
201 | bool flock:1; | |
b6aeaded MS |
202 | }; |
203 | ||
334f485d MS |
204 | /** One input argument of a request */ |
205 | struct fuse_in_arg { | |
206 | unsigned size; | |
207 | const void *value; | |
208 | }; | |
209 | ||
210 | /** The request input */ | |
211 | struct fuse_in { | |
212 | /** The request header */ | |
213 | struct fuse_in_header h; | |
214 | ||
215 | /** True if the data for the last argument is in req->pages */ | |
216 | unsigned argpages:1; | |
217 | ||
218 | /** Number of arguments */ | |
219 | unsigned numargs; | |
220 | ||
221 | /** Array of arguments */ | |
222 | struct fuse_in_arg args[3]; | |
223 | }; | |
224 | ||
225 | /** One output argument of a request */ | |
226 | struct fuse_arg { | |
227 | unsigned size; | |
228 | void *value; | |
229 | }; | |
230 | ||
231 | /** The request output */ | |
232 | struct fuse_out { | |
233 | /** Header returned from userspace */ | |
234 | struct fuse_out_header h; | |
235 | ||
095da6cb MS |
236 | /* |
237 | * The following bitfields are not changed during the request | |
238 | * processing | |
239 | */ | |
240 | ||
334f485d MS |
241 | /** Last argument is variable length (can be shorter than |
242 | arg->size) */ | |
243 | unsigned argvar:1; | |
244 | ||
245 | /** Last argument is a list of pages to copy data to */ | |
246 | unsigned argpages:1; | |
247 | ||
248 | /** Zero partially or not copied pages */ | |
249 | unsigned page_zeroing:1; | |
250 | ||
ce534fb0 MS |
251 | /** Pages may be replaced with new ones */ |
252 | unsigned page_replace:1; | |
253 | ||
334f485d MS |
254 | /** Number or arguments */ |
255 | unsigned numargs; | |
256 | ||
257 | /** Array of arguments */ | |
f704dcb5 | 258 | struct fuse_arg args[2]; |
334f485d MS |
259 | }; |
260 | ||
b2430d75 MP |
261 | /** FUSE page descriptor */ |
262 | struct fuse_page_desc { | |
263 | unsigned int length; | |
264 | unsigned int offset; | |
265 | }; | |
266 | ||
7078187a MS |
267 | struct fuse_args { |
268 | struct { | |
269 | struct { | |
270 | uint32_t opcode; | |
271 | uint64_t nodeid; | |
272 | } h; | |
273 | unsigned numargs; | |
274 | struct fuse_in_arg args[3]; | |
275 | ||
276 | } in; | |
277 | struct { | |
278 | unsigned argvar:1; | |
279 | unsigned numargs; | |
280 | struct fuse_arg args[2]; | |
281 | } out; | |
282 | }; | |
283 | ||
284 | #define FUSE_ARGS(args) struct fuse_args args = {} | |
285 | ||
01e9d11a MP |
286 | /** The request IO state (for asynchronous processing) */ |
287 | struct fuse_io_priv { | |
744742d6 | 288 | struct kref refcnt; |
01e9d11a MP |
289 | int async; |
290 | spinlock_t lock; | |
291 | unsigned reqs; | |
292 | ssize_t bytes; | |
293 | size_t size; | |
294 | __u64 offset; | |
295 | bool write; | |
61c12b49 | 296 | bool should_dirty; |
01e9d11a MP |
297 | int err; |
298 | struct kiocb *iocb; | |
9d5722b7 | 299 | struct completion *done; |
7879c4e5 | 300 | bool blocking; |
01e9d11a MP |
301 | }; |
302 | ||
e1c0eecb | 303 | #define FUSE_IO_PRIV_SYNC(i) \ |
744742d6 | 304 | { \ |
1e24edca | 305 | .refcnt = KREF_INIT(1), \ |
744742d6 | 306 | .async = 0, \ |
e1c0eecb | 307 | .iocb = i, \ |
744742d6 SF |
308 | } |
309 | ||
825d6d33 MS |
310 | /** |
311 | * Request flags | |
312 | * | |
313 | * FR_ISREPLY: set if the request has reply | |
314 | * FR_FORCE: force sending of the request even if interrupted | |
315 | * FR_BACKGROUND: request is sent in the background | |
316 | * FR_WAITING: request is counted as "waiting" | |
317 | * FR_ABORTED: the request was aborted | |
318 | * FR_INTERRUPTED: the request has been interrupted | |
319 | * FR_LOCKED: data is being copied to/from the request | |
33e14b4d MS |
320 | * FR_PENDING: request is not yet in userspace |
321 | * FR_SENT: request is in userspace, waiting for an answer | |
322 | * FR_FINISHED: request is finished | |
77cd9d48 | 323 | * FR_PRIVATE: request is on private list |
825d6d33 MS |
324 | */ |
325 | enum fuse_req_flag { | |
326 | FR_ISREPLY, | |
327 | FR_FORCE, | |
328 | FR_BACKGROUND, | |
329 | FR_WAITING, | |
330 | FR_ABORTED, | |
331 | FR_INTERRUPTED, | |
332 | FR_LOCKED, | |
33e14b4d MS |
333 | FR_PENDING, |
334 | FR_SENT, | |
335 | FR_FINISHED, | |
77cd9d48 | 336 | FR_PRIVATE, |
825d6d33 MS |
337 | }; |
338 | ||
334f485d MS |
339 | /** |
340 | * A request to the client | |
dc00809a MS |
341 | * |
342 | * .waitq.lock protects the following fields: | |
343 | * - FR_ABORTED | |
344 | * - FR_LOCKED (may also be modified under fc->lock, tested under both) | |
334f485d MS |
345 | */ |
346 | struct fuse_req { | |
ce1d5a49 MS |
347 | /** This can be on either pending processing or io lists in |
348 | fuse_conn */ | |
334f485d MS |
349 | struct list_head list; |
350 | ||
a4d27e75 MS |
351 | /** Entry on the interrupts list */ |
352 | struct list_head intr_entry; | |
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 | |
334f485d MS |
360 | /** The request input */ |
361 | struct fuse_in in; | |
362 | ||
363 | /** The request output */ | |
364 | struct fuse_out out; | |
365 | ||
366 | /** Used to wake up the task waiting for completion of request*/ | |
367 | wait_queue_head_t waitq; | |
368 | ||
369 | /** Data for asynchronous requests */ | |
370 | union { | |
b57d4264 | 371 | struct { |
baebccbe MS |
372 | struct fuse_release_in in; |
373 | struct inode *inode; | |
b57d4264 | 374 | } release; |
3ec870d5 MS |
375 | struct fuse_init_in init_in; |
376 | struct fuse_init_out init_out; | |
08cbf542 | 377 | struct cuse_init_in cuse_init_in; |
5c5c5e51 MS |
378 | struct { |
379 | struct fuse_read_in in; | |
380 | u64 attr_ver; | |
381 | } read; | |
b25e82e5 MS |
382 | struct { |
383 | struct fuse_write_in in; | |
384 | struct fuse_write_out out; | |
8b284dc4 | 385 | struct fuse_req *next; |
b25e82e5 | 386 | } write; |
2d45ba38 | 387 | struct fuse_notify_retrieve_in retrieve_in; |
334f485d MS |
388 | } misc; |
389 | ||
390 | /** page vector */ | |
4250c066 MP |
391 | struct page **pages; |
392 | ||
b2430d75 MP |
393 | /** page-descriptor vector */ |
394 | struct fuse_page_desc *page_descs; | |
395 | ||
4250c066 MP |
396 | /** size of the 'pages' array */ |
397 | unsigned max_pages; | |
398 | ||
399 | /** inline page vector */ | |
400 | struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; | |
334f485d | 401 | |
b2430d75 MP |
402 | /** inline page-descriptor vector */ |
403 | struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; | |
404 | ||
334f485d MS |
405 | /** number of pages in vector */ |
406 | unsigned num_pages; | |
407 | ||
334f485d | 408 | /** File used in the request (or NULL) */ |
c756e0a4 | 409 | struct fuse_file *ff; |
64c6d8ed | 410 | |
3be5a52b MS |
411 | /** Inode used in the request or NULL */ |
412 | struct inode *inode; | |
413 | ||
01e9d11a MP |
414 | /** AIO control block */ |
415 | struct fuse_io_priv *io; | |
416 | ||
3be5a52b MS |
417 | /** Link on fi->writepages */ |
418 | struct list_head writepages_entry; | |
419 | ||
64c6d8ed MS |
420 | /** Request completion callback */ |
421 | void (*end)(struct fuse_conn *, struct fuse_req *); | |
33649c91 MS |
422 | |
423 | /** Request is stolen from fuse_file->reserved_req */ | |
424 | struct file *stolen_file; | |
334f485d MS |
425 | }; |
426 | ||
f88996a9 | 427 | struct fuse_iqueue { |
e16714d8 MS |
428 | /** Connection established */ |
429 | unsigned connected; | |
430 | ||
f88996a9 MS |
431 | /** Readers of the connection are waiting on this */ |
432 | wait_queue_head_t waitq; | |
433 | ||
434 | /** The next unique request id */ | |
435 | u64 reqctr; | |
436 | ||
437 | /** The list of pending requests */ | |
438 | struct list_head pending; | |
439 | ||
440 | /** Pending interrupts */ | |
441 | struct list_head interrupts; | |
442 | ||
443 | /** Queue of pending forgets */ | |
444 | struct fuse_forget_link forget_list_head; | |
445 | struct fuse_forget_link *forget_list_tail; | |
446 | ||
447 | /** Batching of FORGET requests (positive indicates FORGET batch) */ | |
448 | int forget_batch; | |
449 | ||
450 | /** O_ASYNC requests */ | |
451 | struct fasync_struct *fasync; | |
452 | }; | |
453 | ||
be2ff42c KT |
454 | #define FUSE_PQ_HASH_BITS 8 |
455 | #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) | |
456 | ||
3a2b5b9c | 457 | struct fuse_pqueue { |
e96edd94 MS |
458 | /** Connection established */ |
459 | unsigned connected; | |
460 | ||
45a91cb1 MS |
461 | /** Lock protecting accessess to members of this structure */ |
462 | spinlock_t lock; | |
463 | ||
be2ff42c KT |
464 | /** Hash table of requests being processed */ |
465 | struct list_head *processing; | |
3a2b5b9c MS |
466 | |
467 | /** The list of requests under I/O */ | |
468 | struct list_head io; | |
469 | }; | |
470 | ||
cc080e9e MS |
471 | /** |
472 | * Fuse device instance | |
473 | */ | |
474 | struct fuse_dev { | |
475 | /** Fuse connection for this device */ | |
476 | struct fuse_conn *fc; | |
477 | ||
c3696046 MS |
478 | /** Processing queue */ |
479 | struct fuse_pqueue pq; | |
480 | ||
cc080e9e MS |
481 | /** list entry on fc->devices */ |
482 | struct list_head entry; | |
483 | }; | |
484 | ||
d8a5ba45 MS |
485 | /** |
486 | * A Fuse connection. | |
487 | * | |
488 | * This structure is created, when the filesystem is mounted, and is | |
489 | * destroyed, when the client device is closed and the filesystem is | |
490 | * unmounted. | |
491 | */ | |
492 | struct fuse_conn { | |
d7133114 MS |
493 | /** Lock protecting accessess to members of this structure */ |
494 | spinlock_t lock; | |
495 | ||
bafa9654 | 496 | /** Refcount */ |
095fc40a | 497 | refcount_t count; |
bafa9654 | 498 | |
c3696046 MS |
499 | /** Number of fuse_dev's */ |
500 | atomic_t dev_count; | |
501 | ||
dd3e2c55 AV |
502 | struct rcu_head rcu; |
503 | ||
d8a5ba45 | 504 | /** The user id for this mount */ |
499dcf20 | 505 | kuid_t user_id; |
d8a5ba45 | 506 | |
87729a55 | 507 | /** The group id for this mount */ |
499dcf20 | 508 | kgid_t group_id; |
87729a55 | 509 | |
0b6e9ea0 SF |
510 | /** The pid namespace for this mount */ |
511 | struct pid_namespace *pid_ns; | |
512 | ||
8cb08329 EB |
513 | /** The user namespace for this mount */ |
514 | struct user_namespace *user_ns; | |
515 | ||
db50b96c MS |
516 | /** Maximum read size */ |
517 | unsigned max_read; | |
518 | ||
413ef8cb MS |
519 | /** Maximum write size */ |
520 | unsigned max_write; | |
521 | ||
f88996a9 MS |
522 | /** Input queue */ |
523 | struct fuse_iqueue iq; | |
334f485d | 524 | |
acf99433 TH |
525 | /** The next unique kernel file handle */ |
526 | u64 khctr; | |
527 | ||
95668a69 TH |
528 | /** rbtree of fuse_files waiting for poll events indexed by ph */ |
529 | struct rb_root polled_files; | |
530 | ||
7a6d3c8b CH |
531 | /** Maximum number of outstanding background requests */ |
532 | unsigned max_background; | |
533 | ||
534 | /** Number of background requests at which congestion starts */ | |
535 | unsigned congestion_threshold; | |
536 | ||
08a53cdc MS |
537 | /** Number of requests currently in the background */ |
538 | unsigned num_background; | |
539 | ||
d12def1b MS |
540 | /** Number of background requests currently queued for userspace */ |
541 | unsigned active_background; | |
542 | ||
543 | /** The list of background requests set aside for later queuing */ | |
544 | struct list_head bg_queue; | |
545 | ||
ae2dffa3 KT |
546 | /** Protects: max_background, congestion_threshold, num_background, |
547 | * active_background, bg_queue, blocked */ | |
548 | spinlock_t bg_lock; | |
549 | ||
796523fb MP |
550 | /** Flag indicating that INIT reply has been received. Allocating |
551 | * any fuse request will be suspended until the flag is set */ | |
552 | int initialized; | |
553 | ||
08a53cdc MS |
554 | /** Flag indicating if connection is blocked. This will be |
555 | the case before the INIT reply is received, and if there | |
556 | are too many outstading backgrounds requests */ | |
557 | int blocked; | |
558 | ||
559 | /** waitq for blocked connection */ | |
560 | wait_queue_head_t blocked_waitq; | |
de5e3dec MS |
561 | |
562 | /** waitq for reserved requests */ | |
563 | wait_queue_head_t reserved_req_waitq; | |
08a53cdc | 564 | |
69a53bf2 MS |
565 | /** Connection established, cleared on umount, connection |
566 | abort and device release */ | |
095da6cb | 567 | unsigned connected; |
1e9a4ed9 | 568 | |
3b7008b2 SL |
569 | /** Connection aborted via sysfs */ |
570 | bool aborted; | |
571 | ||
095da6cb MS |
572 | /** Connection failed (version mismatch). Cannot race with |
573 | setting other bitfields since it is only set once in INIT | |
574 | reply, before any other request, and never cleared */ | |
1729a16c | 575 | unsigned conn_error:1; |
334f485d | 576 | |
0ec7ca41 | 577 | /** Connection successful. Only set in INIT */ |
1729a16c | 578 | unsigned conn_init:1; |
0ec7ca41 | 579 | |
9cd68455 | 580 | /** Do readpages asynchronously? Only set in INIT */ |
1729a16c | 581 | unsigned async_read:1; |
9cd68455 | 582 | |
3b7008b2 SL |
583 | /** Return an unique read error after abort. Only set in INIT */ |
584 | unsigned abort_err:1; | |
585 | ||
6ff958ed | 586 | /** Do not send separate SETATTR request before open(O_TRUNC) */ |
1729a16c | 587 | unsigned atomic_o_trunc:1; |
6ff958ed | 588 | |
33670fa2 | 589 | /** Filesystem supports NFS exporting. Only set in INIT */ |
1729a16c | 590 | unsigned export_support:1; |
33670fa2 | 591 | |
d5cd66c5 PE |
592 | /** write-back cache policy (default is write-through) */ |
593 | unsigned writeback_cache:1; | |
594 | ||
5c672ab3 MS |
595 | /** allow parallel lookups and readdir (default is serialized) */ |
596 | unsigned parallel_dirops:1; | |
597 | ||
5e940c1d MS |
598 | /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ |
599 | unsigned handle_killpriv:1; | |
600 | ||
095da6cb MS |
601 | /* |
602 | * The following bitfields are only for optimization purposes | |
603 | * and hence races in setting them will not cause malfunction | |
604 | */ | |
605 | ||
7678ac50 AG |
606 | /** Is open/release not implemented by fs? */ |
607 | unsigned no_open:1; | |
608 | ||
b6aeaded | 609 | /** Is fsync not implemented by fs? */ |
1729a16c | 610 | unsigned no_fsync:1; |
b6aeaded | 611 | |
82547981 | 612 | /** Is fsyncdir not implemented by fs? */ |
1729a16c | 613 | unsigned no_fsyncdir:1; |
82547981 | 614 | |
b6aeaded | 615 | /** Is flush not implemented by fs? */ |
1729a16c | 616 | unsigned no_flush:1; |
b6aeaded | 617 | |
92a8780e | 618 | /** Is setxattr not implemented by fs? */ |
1729a16c | 619 | unsigned no_setxattr:1; |
92a8780e MS |
620 | |
621 | /** Is getxattr not implemented by fs? */ | |
1729a16c | 622 | unsigned no_getxattr:1; |
92a8780e MS |
623 | |
624 | /** Is listxattr not implemented by fs? */ | |
1729a16c | 625 | unsigned no_listxattr:1; |
92a8780e MS |
626 | |
627 | /** Is removexattr not implemented by fs? */ | |
1729a16c | 628 | unsigned no_removexattr:1; |
92a8780e | 629 | |
37fb3a30 | 630 | /** Are posix file locking primitives not implemented by fs? */ |
1729a16c | 631 | unsigned no_lock:1; |
71421259 | 632 | |
31d40d74 | 633 | /** Is access not implemented by fs? */ |
1729a16c | 634 | unsigned no_access:1; |
31d40d74 | 635 | |
fd72faac | 636 | /** Is create not implemented by fs? */ |
1729a16c | 637 | unsigned no_create:1; |
fd72faac | 638 | |
a4d27e75 | 639 | /** Is interrupt not implemented by fs? */ |
1729a16c | 640 | unsigned no_interrupt:1; |
a4d27e75 | 641 | |
b2d2272f | 642 | /** Is bmap not implemented by fs? */ |
1729a16c | 643 | unsigned no_bmap:1; |
b2d2272f | 644 | |
95668a69 TH |
645 | /** Is poll not implemented by fs? */ |
646 | unsigned no_poll:1; | |
647 | ||
78bb6cb9 | 648 | /** Do multi-page cached writes */ |
1729a16c | 649 | unsigned big_writes:1; |
78bb6cb9 | 650 | |
e0a43ddc MS |
651 | /** Don't apply umask to creation modes */ |
652 | unsigned dont_mask:1; | |
653 | ||
37fb3a30 MS |
654 | /** Are BSD file locking primitives not implemented by fs? */ |
655 | unsigned no_flock:1; | |
656 | ||
519c6040 MS |
657 | /** Is fallocate not implemented by fs? */ |
658 | unsigned no_fallocate:1; | |
659 | ||
1560c974 MS |
660 | /** Is rename with flags implemented by fs? */ |
661 | unsigned no_rename2:1; | |
662 | ||
72d0d248 BF |
663 | /** Use enhanced/automatic page cache invalidation. */ |
664 | unsigned auto_inval_data:1; | |
665 | ||
634734b6 | 666 | /** Does the filesystem support readdirplus? */ |
0b05b183 AA |
667 | unsigned do_readdirplus:1; |
668 | ||
634734b6 EW |
669 | /** Does the filesystem want adaptive readdirplus? */ |
670 | unsigned readdirplus_auto:1; | |
671 | ||
60b9df7a MS |
672 | /** Does the filesystem support asynchronous direct-IO submission? */ |
673 | unsigned async_dio:1; | |
674 | ||
0b5da8db R |
675 | /** Is lseek not implemented by fs? */ |
676 | unsigned no_lseek:1; | |
677 | ||
60bcc88a SF |
678 | /** Does the filesystem support posix acls? */ |
679 | unsigned posix_acl:1; | |
680 | ||
29433a29 MS |
681 | /** Check permissions based on the file mode or not? */ |
682 | unsigned default_permissions:1; | |
683 | ||
684 | /** Allow other than the mounter user to access the filesystem ? */ | |
685 | unsigned allow_other:1; | |
686 | ||
88bc7d50 NV |
687 | /** Does the filesystem support copy_file_range? */ |
688 | unsigned no_copy_file_range:1; | |
689 | ||
0cd5b885 MS |
690 | /** The number of requests waiting for completion */ |
691 | atomic_t num_waiting; | |
692 | ||
45714d65 MS |
693 | /** Negotiated minor version */ |
694 | unsigned minor; | |
695 | ||
bafa9654 MS |
696 | /** Entry on the fuse_conn_list */ |
697 | struct list_head entry; | |
698 | ||
b6f2fcbc MS |
699 | /** Device ID from super block */ |
700 | dev_t dev; | |
bafa9654 MS |
701 | |
702 | /** Dentries in the control filesystem */ | |
703 | struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; | |
704 | ||
705 | /** number of dentries used in the above array */ | |
706 | int ctl_ndents; | |
385a17bf | 707 | |
9c8ef561 MS |
708 | /** Key for lock owner ID scrambling */ |
709 | u32 scramble_key[4]; | |
0ec7ca41 MS |
710 | |
711 | /** Reserved request for the DESTROY message */ | |
712 | struct fuse_req *destroy_req; | |
1fb69e78 MS |
713 | |
714 | /** Version counter for attribute changes */ | |
715 | u64 attr_version; | |
43901aab TH |
716 | |
717 | /** Called on final put */ | |
718 | void (*release)(struct fuse_conn *); | |
3b463ae0 JM |
719 | |
720 | /** Super block for this connection. */ | |
721 | struct super_block *sb; | |
722 | ||
723 | /** Read/write semaphore to hold when accessing sb. */ | |
724 | struct rw_semaphore killsb; | |
cc080e9e MS |
725 | |
726 | /** List of device instances belonging to this connection */ | |
727 | struct list_head devices; | |
d8a5ba45 MS |
728 | }; |
729 | ||
d8a5ba45 MS |
730 | static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) |
731 | { | |
6383bdaa | 732 | return sb->s_fs_info; |
d8a5ba45 MS |
733 | } |
734 | ||
735 | static inline struct fuse_conn *get_fuse_conn(struct inode *inode) | |
736 | { | |
737 | return get_fuse_conn_super(inode->i_sb); | |
738 | } | |
739 | ||
740 | static inline struct fuse_inode *get_fuse_inode(struct inode *inode) | |
741 | { | |
742 | return container_of(inode, struct fuse_inode, inode); | |
743 | } | |
744 | ||
745 | static inline u64 get_node_id(struct inode *inode) | |
746 | { | |
747 | return get_fuse_inode(inode)->nodeid; | |
748 | } | |
749 | ||
d123d8e1 MS |
750 | static inline int invalid_nodeid(u64 nodeid) |
751 | { | |
752 | return !nodeid || nodeid == FUSE_ROOT_ID; | |
753 | } | |
754 | ||
334f485d | 755 | /** Device operations */ |
4b6f5d20 | 756 | extern const struct file_operations fuse_dev_operations; |
334f485d | 757 | |
4269590a | 758 | extern const struct dentry_operations fuse_dentry_operations; |
0ce267ff | 759 | extern const struct dentry_operations fuse_root_dentry_operations; |
dbd561d2 | 760 | |
3b463ae0 JM |
761 | /** |
762 | * Inode to nodeid comparison. | |
763 | */ | |
764 | int fuse_inode_eq(struct inode *inode, void *_nodeidp); | |
765 | ||
e5e5558e MS |
766 | /** |
767 | * Get a filled in inode | |
768 | */ | |
b48badf0 | 769 | struct inode *fuse_iget(struct super_block *sb, u64 nodeid, |
1fb69e78 MS |
770 | int generation, struct fuse_attr *attr, |
771 | u64 attr_valid, u64 attr_version); | |
e5e5558e | 772 | |
13983d06 | 773 | int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, |
33670fa2 MS |
774 | struct fuse_entry_out *outarg, struct inode **inode); |
775 | ||
e5e5558e MS |
776 | /** |
777 | * Send FORGET command | |
778 | */ | |
07e77dca MS |
779 | void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, |
780 | u64 nodeid, u64 nlookup); | |
781 | ||
782 | struct fuse_forget_link *fuse_alloc_forget(void); | |
e5e5558e | 783 | |
0b05b183 AA |
784 | /* Used by READDIRPLUS */ |
785 | void fuse_force_forget(struct file *file, u64 nodeid); | |
786 | ||
04730fef | 787 | /** |
361b1eb5 | 788 | * Initialize READ or READDIR request |
04730fef | 789 | */ |
a6643094 | 790 | void fuse_read_fill(struct fuse_req *req, struct file *file, |
2106cb18 | 791 | loff_t pos, size_t count, int opcode); |
04730fef MS |
792 | |
793 | /** | |
794 | * Send OPEN or OPENDIR request | |
795 | */ | |
91fe96b4 | 796 | int fuse_open_common(struct inode *inode, struct file *file, bool isdir); |
04730fef | 797 | |
acf99433 | 798 | struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); |
fd72faac | 799 | void fuse_file_free(struct fuse_file *ff); |
c7b7143c | 800 | void fuse_finish_open(struct inode *inode, struct file *file); |
fd72faac | 801 | |
8b0797a4 | 802 | void fuse_sync_release(struct fuse_file *ff, int flags); |
c756e0a4 | 803 | |
04730fef MS |
804 | /** |
805 | * Send RELEASE or RELEASEDIR request | |
806 | */ | |
8b0797a4 | 807 | void fuse_release_common(struct file *file, int opcode); |
04730fef | 808 | |
82547981 MS |
809 | /** |
810 | * Send FSYNC or FSYNCDIR request | |
811 | */ | |
02c24a82 JB |
812 | int fuse_fsync_common(struct file *file, loff_t start, loff_t end, |
813 | int datasync, int isdir); | |
82547981 | 814 | |
95668a69 TH |
815 | /** |
816 | * Notify poll wakeup | |
817 | */ | |
818 | int fuse_notify_poll_wakeup(struct fuse_conn *fc, | |
819 | struct fuse_notify_poll_wakeup_out *outarg); | |
820 | ||
b6aeaded | 821 | /** |
1779381d | 822 | * Initialize file operations on a regular file |
b6aeaded MS |
823 | */ |
824 | void fuse_init_file_inode(struct inode *inode); | |
825 | ||
e5e5558e | 826 | /** |
1779381d | 827 | * Initialize inode operations on regular files and special files |
e5e5558e MS |
828 | */ |
829 | void fuse_init_common(struct inode *inode); | |
830 | ||
831 | /** | |
1779381d | 832 | * Initialize inode and file operations on a directory |
e5e5558e MS |
833 | */ |
834 | void fuse_init_dir(struct inode *inode); | |
835 | ||
836 | /** | |
1779381d | 837 | * Initialize inode operations on a symlink |
e5e5558e MS |
838 | */ |
839 | void fuse_init_symlink(struct inode *inode); | |
840 | ||
841 | /** | |
842 | * Change attributes of an inode | |
843 | */ | |
1fb69e78 MS |
844 | void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, |
845 | u64 attr_valid, u64 attr_version); | |
e5e5558e | 846 | |
3be5a52b MS |
847 | void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, |
848 | u64 attr_valid); | |
849 | ||
334f485d MS |
850 | /** |
851 | * Initialize the client device | |
852 | */ | |
853 | int fuse_dev_init(void); | |
854 | ||
855 | /** | |
856 | * Cleanup the client device | |
857 | */ | |
858 | void fuse_dev_cleanup(void); | |
859 | ||
bafa9654 | 860 | int fuse_ctl_init(void); |
7736e8cc | 861 | void __exit fuse_ctl_cleanup(void); |
bafa9654 | 862 | |
334f485d MS |
863 | /** |
864 | * Allocate a request | |
865 | */ | |
4250c066 | 866 | struct fuse_req *fuse_request_alloc(unsigned npages); |
334f485d | 867 | |
4250c066 | 868 | struct fuse_req *fuse_request_alloc_nofs(unsigned npages); |
3be5a52b | 869 | |
334f485d MS |
870 | /** |
871 | * Free a request | |
872 | */ | |
873 | void fuse_request_free(struct fuse_req *req); | |
874 | ||
334f485d | 875 | /** |
b111c8c0 MP |
876 | * Get a request, may fail with -ENOMEM, |
877 | * caller should specify # elements in req->pages[] explicitly | |
334f485d | 878 | */ |
b111c8c0 | 879 | struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); |
8b41e671 MP |
880 | struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, |
881 | unsigned npages); | |
b111c8c0 | 882 | |
36cf66ed MP |
883 | /* |
884 | * Increment reference count on request | |
885 | */ | |
886 | void __fuse_get_request(struct fuse_req *req); | |
887 | ||
33649c91 MS |
888 | /** |
889 | * Gets a requests for a file operation, always succeeds | |
890 | */ | |
b111c8c0 MP |
891 | struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, |
892 | struct file *file); | |
33649c91 | 893 | |
334f485d | 894 | /** |
ce1d5a49 MS |
895 | * Decrement reference count of a request. If count goes to zero free |
896 | * the request. | |
334f485d MS |
897 | */ |
898 | void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); | |
899 | ||
900 | /** | |
7c352bdf | 901 | * Send a request (synchronous) |
334f485d | 902 | */ |
b93f858a | 903 | void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); |
334f485d | 904 | |
7078187a MS |
905 | /** |
906 | * Simple request sending that does request allocation and freeing | |
907 | */ | |
908 | ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); | |
909 | ||
334f485d MS |
910 | /** |
911 | * Send a request in the background | |
912 | */ | |
b93f858a | 913 | void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); |
63825b4e | 914 | bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); |
3be5a52b | 915 | |
5a5fb1ea | 916 | /* Abort all requests */ |
3b7008b2 | 917 | void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); |
b8f95e5d | 918 | void fuse_wait_aborted(struct fuse_conn *fc); |
69a53bf2 | 919 | |
e5e5558e MS |
920 | /** |
921 | * Invalidate inode attributes | |
922 | */ | |
923 | void fuse_invalidate_attr(struct inode *inode); | |
bafa9654 | 924 | |
dbd561d2 MS |
925 | void fuse_invalidate_entry_cache(struct dentry *entry); |
926 | ||
451418fc AG |
927 | void fuse_invalidate_atime(struct inode *inode); |
928 | ||
d123d8e1 MS |
929 | u64 entry_attr_timeout(struct fuse_entry_out *o); |
930 | void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); | |
931 | ||
bafa9654 MS |
932 | /** |
933 | * Acquire reference to fuse_conn | |
934 | */ | |
935 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); | |
936 | ||
0d179aa5 TH |
937 | /** |
938 | * Initialize fuse_conn | |
939 | */ | |
8cb08329 | 940 | void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); |
0d179aa5 | 941 | |
bafa9654 MS |
942 | /** |
943 | * Release reference to fuse_conn | |
944 | */ | |
945 | void fuse_conn_put(struct fuse_conn *fc); | |
946 | ||
cc080e9e MS |
947 | struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); |
948 | void fuse_dev_free(struct fuse_dev *fud); | |
949 | ||
bafa9654 MS |
950 | /** |
951 | * Add connection to control filesystem | |
952 | */ | |
953 | int fuse_ctl_add_conn(struct fuse_conn *fc); | |
954 | ||
955 | /** | |
956 | * Remove connection from control filesystem | |
957 | */ | |
958 | void fuse_ctl_remove_conn(struct fuse_conn *fc); | |
a5bfffac TS |
959 | |
960 | /** | |
961 | * Is file type valid? | |
962 | */ | |
963 | int fuse_valid_type(int m); | |
e57ac683 MS |
964 | |
965 | /** | |
c2132c1b | 966 | * Is current process allowed to perform filesystem operation? |
e57ac683 | 967 | */ |
c2132c1b | 968 | int fuse_allow_current_process(struct fuse_conn *fc); |
f3332114 MS |
969 | |
970 | u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); | |
bcb4be80 | 971 | |
703c7362 SF |
972 | void fuse_update_ctime(struct inode *inode); |
973 | ||
5b97eeac | 974 | int fuse_update_attributes(struct inode *inode, struct file *file); |
3be5a52b MS |
975 | |
976 | void fuse_flush_writepages(struct inode *inode); | |
977 | ||
978 | void fuse_set_nowrite(struct inode *inode); | |
979 | void fuse_release_nowrite(struct inode *inode); | |
5c5c5e51 MS |
980 | |
981 | u64 fuse_get_attr_version(struct fuse_conn *fc); | |
29d434b3 | 982 | |
3b463ae0 JM |
983 | /** |
984 | * File-system tells the kernel to invalidate cache for the given node id. | |
985 | */ | |
986 | int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, | |
987 | loff_t offset, loff_t len); | |
988 | ||
989 | /** | |
990 | * File-system tells the kernel to invalidate parent attributes and | |
991 | * the dentry matching parent/name. | |
451d0f59 JM |
992 | * |
993 | * If the child_nodeid is non-zero and: | |
994 | * - matches the inode number for the dentry matching parent/name, | |
995 | * - is not a mount point | |
996 | * - is a file or oan empty directory | |
997 | * then the dentry is unhashed (d_delete()). | |
3b463ae0 JM |
998 | */ |
999 | int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, | |
451d0f59 | 1000 | u64 child_nodeid, struct qstr *name); |
3b463ae0 | 1001 | |
08cbf542 TH |
1002 | int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, |
1003 | bool isdir); | |
ea8cd333 PE |
1004 | |
1005 | /** | |
1006 | * fuse_direct_io() flags | |
1007 | */ | |
1008 | ||
1009 | /** If set, it is WRITE; otherwise - READ */ | |
1010 | #define FUSE_DIO_WRITE (1 << 0) | |
1011 | ||
1012 | /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ | |
1013 | #define FUSE_DIO_CUSE (1 << 1) | |
1014 | ||
d22a943f AV |
1015 | ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, |
1016 | loff_t *ppos, int flags); | |
08cbf542 TH |
1017 | long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, |
1018 | unsigned int flags); | |
b18da0c5 MS |
1019 | long fuse_ioctl_common(struct file *file, unsigned int cmd, |
1020 | unsigned long arg, unsigned int flags); | |
076ccb76 | 1021 | __poll_t fuse_file_poll(struct file *file, poll_table *wait); |
08cbf542 TH |
1022 | int fuse_dev_release(struct inode *inode, struct file *file); |
1023 | ||
b0aa7606 MP |
1024 | bool fuse_write_update_size(struct inode *inode, loff_t pos); |
1025 | ||
ab9e13f7 | 1026 | int fuse_flush_times(struct inode *inode, struct fuse_file *ff); |
1e18bda8 | 1027 | int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); |
a1d75f25 | 1028 | |
62490330 | 1029 | int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, |
efb9fa9e MP |
1030 | struct file *file); |
1031 | ||
9759bd51 MS |
1032 | void fuse_set_initialized(struct fuse_conn *fc); |
1033 | ||
63576c13 MS |
1034 | void fuse_unlock_inode(struct inode *inode, bool locked); |
1035 | bool fuse_lock_inode(struct inode *inode); | |
5c672ab3 | 1036 | |
60bcc88a SF |
1037 | int fuse_setxattr(struct inode *inode, const char *name, const void *value, |
1038 | size_t size, int flags); | |
1039 | ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, | |
1040 | size_t size); | |
703c7362 | 1041 | ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); |
60bcc88a | 1042 | int fuse_removexattr(struct inode *inode, const char *name); |
703c7362 | 1043 | extern const struct xattr_handler *fuse_xattr_handlers[]; |
60bcc88a | 1044 | extern const struct xattr_handler *fuse_acl_xattr_handlers[]; |
e45b2546 | 1045 | extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; |
60bcc88a SF |
1046 | |
1047 | struct posix_acl; | |
1048 | struct posix_acl *fuse_get_acl(struct inode *inode, int type); | |
1049 | int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
703c7362 | 1050 | |
d123d8e1 MS |
1051 | |
1052 | /* readdir.c */ | |
1053 | int fuse_readdir(struct file *file, struct dir_context *ctx); | |
1054 | ||
29d434b3 | 1055 | #endif /* _FS_FUSE_I_H */ |