1
2
3
4
5
6
7
8
9#include <linux/fuse.h>
10#include <linux/fs.h>
11#include <linux/mount.h>
12#include <linux/wait.h>
13#include <linux/list.h>
14#include <linux/spinlock.h>
15#include <linux/mm.h>
16#include <linux/backing-dev.h>
17#include <linux/mutex.h>
18
19
20#define FUSE_MAX_PAGES_PER_REQ 32
21
22
23#define FUSE_MAX_BACKGROUND 12
24
25
26#define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100)
27
28
29#define FUSE_NAME_MAX 1024
30
31
32#define FUSE_CTL_NUM_DENTRIES 3
33
34
35
36
37#define FUSE_DEFAULT_PERMISSIONS (1 << 0)
38
39
40
41#define FUSE_ALLOW_OTHER (1 << 1)
42
43
44extern struct list_head fuse_conn_list;
45
46
47extern struct mutex fuse_mutex;
48
49
50struct fuse_inode {
51
52 struct inode inode;
53
54
55
56 u64 nodeid;
57
58
59 u64 nlookup;
60
61
62 struct fuse_req *forget_req;
63
64
65 u64 i_time;
66
67
68
69 mode_t orig_i_mode;
70
71
72 u64 attr_version;
73
74
75 struct list_head write_files;
76};
77
78
79struct fuse_file {
80
81 struct fuse_req *reserved_req;
82
83
84 u64 fh;
85
86
87 atomic_t count;
88
89
90 struct list_head write_entry;
91};
92
93
94struct fuse_in_arg {
95 unsigned size;
96 const void *value;
97};
98
99
100struct fuse_in {
101
102 struct fuse_in_header h;
103
104
105 unsigned argpages:1;
106
107
108 unsigned numargs;
109
110
111 struct fuse_in_arg args[3];
112};
113
114
115struct fuse_arg {
116 unsigned size;
117 void *value;
118};
119
120
121struct fuse_out {
122
123 struct fuse_out_header h;
124
125
126
127
128
129
130
131
132 unsigned argvar:1;
133
134
135 unsigned argpages:1;
136
137
138 unsigned page_zeroing:1;
139
140
141 unsigned numargs;
142
143
144 struct fuse_arg args[3];
145};
146
147
148enum fuse_req_state {
149 FUSE_REQ_INIT = 0,
150 FUSE_REQ_PENDING,
151 FUSE_REQ_READING,
152 FUSE_REQ_SENT,
153 FUSE_REQ_WRITING,
154 FUSE_REQ_FINISHED
155};
156
157struct fuse_conn;
158
159
160
161
162struct fuse_req {
163
164
165 struct list_head list;
166
167
168 struct list_head intr_entry;
169
170
171 atomic_t count;
172
173
174 u64 intr_unique;
175
176
177
178
179
180
181
182
183 unsigned isreply:1;
184
185
186 unsigned force:1;
187
188
189 unsigned aborted:1;
190
191
192 unsigned background:1;
193
194
195 unsigned interrupted:1;
196
197
198 unsigned locked:1;
199
200
201 unsigned waiting:1;
202
203
204 enum fuse_req_state state;
205
206
207 struct fuse_in in;
208
209
210 struct fuse_out out;
211
212
213 wait_queue_head_t waitq;
214
215
216 union {
217 struct fuse_forget_in forget_in;
218 struct {
219 struct fuse_release_in in;
220 struct vfsmount *vfsmount;
221 struct dentry *dentry;
222 } release;
223 struct fuse_init_in init_in;
224 struct fuse_init_out init_out;
225 struct fuse_read_in read_in;
226 struct {
227 struct fuse_write_in in;
228 struct fuse_write_out out;
229 } write;
230 struct fuse_lk_in lk_in;
231 } misc;
232
233
234 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
235
236
237 unsigned num_pages;
238
239
240 unsigned page_offset;
241
242
243 struct fuse_file *ff;
244
245
246 void (*end)(struct fuse_conn *, struct fuse_req *);
247
248
249 struct file *stolen_file;
250};
251
252
253
254
255
256
257
258
259struct fuse_conn {
260
261 spinlock_t lock;
262
263
264 struct mutex inst_mutex;
265
266
267 atomic_t count;
268
269
270 uid_t user_id;
271
272
273 gid_t group_id;
274
275
276 unsigned flags;
277
278
279 unsigned max_read;
280
281
282 unsigned max_write;
283
284
285 wait_queue_head_t waitq;
286
287
288 struct list_head pending;
289
290
291 struct list_head processing;
292
293
294 struct list_head io;
295
296
297 unsigned num_background;
298
299
300 unsigned active_background;
301
302
303 struct list_head bg_queue;
304
305
306 struct list_head interrupts;
307
308
309
310
311 int blocked;
312
313
314 wait_queue_head_t blocked_waitq;
315
316
317 wait_queue_head_t reserved_req_waitq;
318
319
320 u64 reqctr;
321
322
323
324 unsigned connected;
325
326
327
328
329 unsigned conn_error : 1;
330
331
332 unsigned conn_init : 1;
333
334
335 unsigned async_read : 1;
336
337
338 unsigned atomic_o_trunc : 1;
339
340
341
342
343
344
345
346 unsigned no_fsync : 1;
347
348
349 unsigned no_fsyncdir : 1;
350
351
352 unsigned no_flush : 1;
353
354
355 unsigned no_setxattr : 1;
356
357
358 unsigned no_getxattr : 1;
359
360
361 unsigned no_listxattr : 1;
362
363
364 unsigned no_removexattr : 1;
365
366
367 unsigned no_lock : 1;
368
369
370 unsigned no_access : 1;
371
372
373 unsigned no_create : 1;
374
375
376 unsigned no_interrupt : 1;
377
378
379 unsigned no_bmap : 1;
380
381
382 atomic_t num_waiting;
383
384
385 unsigned minor;
386
387
388 struct backing_dev_info bdi;
389
390
391 struct list_head entry;
392
393
394 u64 id;
395
396
397 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
398
399
400 int ctl_ndents;
401
402
403 struct fasync_struct *fasync;
404
405
406 u32 scramble_key[4];
407
408
409 struct fuse_req *destroy_req;
410
411
412 u64 attr_version;
413};
414
415static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
416{
417 return sb->s_fs_info;
418}
419
420static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
421{
422 return get_fuse_conn_super(inode->i_sb);
423}
424
425static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
426{
427 return container_of(inode, struct fuse_inode, inode);
428}
429
430static inline u64 get_node_id(struct inode *inode)
431{
432 return get_fuse_inode(inode)->nodeid;
433}
434
435
436extern const struct file_operations fuse_dev_operations;
437
438
439
440
441struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
442 int generation, struct fuse_attr *attr,
443 u64 attr_valid, u64 attr_version);
444
445
446
447
448void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
449 unsigned long nodeid, u64 nlookup);
450
451
452
453
454void fuse_read_fill(struct fuse_req *req, struct file *file,
455 struct inode *inode, loff_t pos, size_t count, int opcode);
456
457
458
459
460int fuse_open_common(struct inode *inode, struct file *file, int isdir);
461
462struct fuse_file *fuse_file_alloc(void);
463void fuse_file_free(struct fuse_file *ff);
464void fuse_finish_open(struct inode *inode, struct file *file,
465 struct fuse_file *ff, struct fuse_open_out *outarg);
466
467
468void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode);
469
470
471
472
473int fuse_release_common(struct inode *inode, struct file *file, int isdir);
474
475
476
477
478int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
479 int isdir);
480
481
482
483
484void fuse_init_file_inode(struct inode *inode);
485
486
487
488
489void fuse_init_common(struct inode *inode);
490
491
492
493
494void fuse_init_dir(struct inode *inode);
495
496
497
498
499void fuse_init_symlink(struct inode *inode);
500
501
502
503
504void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
505 u64 attr_valid, u64 attr_version);
506
507
508
509
510int fuse_dev_init(void);
511
512
513
514
515void fuse_dev_cleanup(void);
516
517int fuse_ctl_init(void);
518void fuse_ctl_cleanup(void);
519
520
521
522
523struct fuse_req *fuse_request_alloc(void);
524
525
526
527
528void fuse_request_free(struct fuse_req *req);
529
530
531
532
533struct fuse_req *fuse_get_req(struct fuse_conn *fc);
534
535
536
537
538struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file);
539
540
541
542
543
544void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
545
546
547
548
549void request_send(struct fuse_conn *fc, struct fuse_req *req);
550
551
552
553
554void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
555
556
557
558
559void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
560
561
562void fuse_abort_conn(struct fuse_conn *fc);
563
564
565
566
567void fuse_invalidate_attr(struct inode *inode);
568
569
570
571
572struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
573
574
575
576
577void fuse_conn_put(struct fuse_conn *fc);
578
579
580
581
582int fuse_ctl_add_conn(struct fuse_conn *fc);
583
584
585
586
587void fuse_ctl_remove_conn(struct fuse_conn *fc);
588
589
590
591
592int fuse_valid_type(int m);
593
594
595
596
597int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task);
598
599u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
600
601int fuse_update_attributes(struct inode *inode, struct kstat *stat,
602 struct file *file, bool *refreshed);
603