1
2
3
4
5
6
7
8
9#ifndef _FS_FUSE_I_H
10#define _FS_FUSE_I_H
11
12#include <linux/fuse.h>
13#include <linux/fs.h>
14#include <linux/mount.h>
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>
20#include <linux/mutex.h>
21#include <linux/rwsem.h>
22#include <linux/rbtree.h>
23#include <linux/poll.h>
24
25
26#define FUSE_MAX_PAGES_PER_REQ 32
27
28
29#define FUSE_NOWRITE INT_MIN
30
31
32#define FUSE_NAME_MAX 1024
33
34
35#define FUSE_CTL_NUM_DENTRIES 5
36
37
38
39
40#define FUSE_DEFAULT_PERMISSIONS (1 << 0)
41
42
43
44#define FUSE_ALLOW_OTHER (1 << 1)
45
46
47extern struct list_head fuse_conn_list;
48
49
50extern struct mutex fuse_mutex;
51
52
53extern unsigned max_user_bgreq;
54extern unsigned max_user_congthresh;
55
56
57struct fuse_inode {
58
59 struct inode inode;
60
61
62
63 u64 nodeid;
64
65
66 u64 nlookup;
67
68
69 struct fuse_req *forget_req;
70
71
72 u64 i_time;
73
74
75
76 mode_t orig_i_mode;
77
78
79 u64 attr_version;
80
81
82 struct list_head write_files;
83
84
85 struct list_head queued_writes;
86
87
88
89 int writectr;
90
91
92 wait_queue_head_t page_waitq;
93
94
95 struct list_head writepages;
96};
97
98struct fuse_conn;
99
100
101struct fuse_file {
102
103 struct fuse_conn *fc;
104
105
106 struct fuse_req *reserved_req;
107
108
109 u64 kh;
110
111
112 u64 fh;
113
114
115 u64 nodeid;
116
117
118 atomic_t count;
119
120
121 u32 open_flags;
122
123
124 struct list_head write_entry;
125
126
127 struct rb_node polled_node;
128
129
130 wait_queue_head_t poll_wait;
131};
132
133
134struct fuse_in_arg {
135 unsigned size;
136 const void *value;
137};
138
139
140struct fuse_in {
141
142 struct fuse_in_header h;
143
144
145 unsigned argpages:1;
146
147
148 unsigned numargs;
149
150
151 struct fuse_in_arg args[3];
152};
153
154
155struct fuse_arg {
156 unsigned size;
157 void *value;
158};
159
160
161struct fuse_out {
162
163 struct fuse_out_header h;
164
165
166
167
168
169
170
171
172 unsigned argvar:1;
173
174
175 unsigned argpages:1;
176
177
178 unsigned page_zeroing:1;
179
180
181 unsigned page_replace:1;
182
183
184 unsigned numargs;
185
186
187 struct fuse_arg args[3];
188};
189
190
191enum fuse_req_state {
192 FUSE_REQ_INIT = 0,
193 FUSE_REQ_PENDING,
194 FUSE_REQ_READING,
195 FUSE_REQ_SENT,
196 FUSE_REQ_WRITING,
197 FUSE_REQ_FINISHED
198};
199
200
201
202
203struct fuse_req {
204
205
206 struct list_head list;
207
208
209 struct list_head intr_entry;
210
211
212 atomic_t count;
213
214
215 u64 intr_unique;
216
217
218
219
220
221
222
223
224 unsigned isreply:1;
225
226
227 unsigned force:1;
228
229
230 unsigned aborted:1;
231
232
233 unsigned background:1;
234
235
236 unsigned interrupted:1;
237
238
239 unsigned locked:1;
240
241
242 unsigned waiting:1;
243
244
245 enum fuse_req_state state;
246
247
248 struct fuse_in in;
249
250
251 struct fuse_out out;
252
253
254 wait_queue_head_t waitq;
255
256
257 union {
258 struct fuse_forget_in forget_in;
259 struct {
260 struct fuse_release_in in;
261 struct path path;
262 } release;
263 struct fuse_init_in init_in;
264 struct fuse_init_out init_out;
265 struct cuse_init_in cuse_init_in;
266 struct cuse_init_out cuse_init_out;
267 struct {
268 struct fuse_read_in in;
269 u64 attr_ver;
270 } read;
271 struct {
272 struct fuse_write_in in;
273 struct fuse_write_out out;
274 } write;
275 struct fuse_lk_in lk_in;
276 } misc;
277
278
279 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
280
281
282 unsigned num_pages;
283
284
285 unsigned page_offset;
286
287
288 struct fuse_file *ff;
289
290
291 struct inode *inode;
292
293
294 struct list_head writepages_entry;
295
296
297 void (*end)(struct fuse_conn *, struct fuse_req *);
298
299
300 struct file *stolen_file;
301};
302
303
304
305
306
307
308
309
310struct fuse_conn {
311
312 spinlock_t lock;
313
314
315 struct mutex inst_mutex;
316
317
318 atomic_t count;
319
320
321 uid_t user_id;
322
323
324 gid_t group_id;
325
326
327 unsigned flags;
328
329
330 unsigned max_read;
331
332
333 unsigned max_write;
334
335
336 wait_queue_head_t waitq;
337
338
339 struct list_head pending;
340
341
342 struct list_head processing;
343
344
345 struct list_head io;
346
347
348 u64 khctr;
349
350
351 struct rb_root polled_files;
352
353
354 unsigned max_background;
355
356
357 unsigned congestion_threshold;
358
359
360 unsigned num_background;
361
362
363 unsigned active_background;
364
365
366 struct list_head bg_queue;
367
368
369 struct list_head interrupts;
370
371
372
373
374 int blocked;
375
376
377 wait_queue_head_t blocked_waitq;
378
379
380 wait_queue_head_t reserved_req_waitq;
381
382
383 u64 reqctr;
384
385
386
387 unsigned connected;
388
389
390
391
392 unsigned conn_error:1;
393
394
395 unsigned conn_init:1;
396
397
398 unsigned async_read:1;
399
400
401 unsigned atomic_o_trunc:1;
402
403
404 unsigned export_support:1;
405
406
407 unsigned bdi_initialized:1;
408
409
410
411
412
413
414
415 unsigned no_fsync:1;
416
417
418 unsigned no_fsyncdir:1;
419
420
421 unsigned no_flush:1;
422
423
424 unsigned no_setxattr:1;
425
426
427 unsigned no_getxattr:1;
428
429
430 unsigned no_listxattr:1;
431
432
433 unsigned no_removexattr:1;
434
435
436 unsigned no_lock:1;
437
438
439 unsigned no_access:1;
440
441
442 unsigned no_create:1;
443
444
445 unsigned no_interrupt:1;
446
447
448 unsigned no_bmap:1;
449
450
451 unsigned no_poll:1;
452
453
454 unsigned big_writes:1;
455
456
457 unsigned dont_mask:1;
458
459
460 atomic_t num_waiting;
461
462
463 unsigned minor;
464
465
466 struct backing_dev_info bdi;
467
468
469 struct list_head entry;
470
471
472 dev_t dev;
473
474
475 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
476
477
478 int ctl_ndents;
479
480
481 struct fasync_struct *fasync;
482
483
484 u32 scramble_key[4];
485
486
487 struct fuse_req *destroy_req;
488
489
490 u64 attr_version;
491
492
493 void (*release)(struct fuse_conn *);
494
495
496 struct super_block *sb;
497
498
499 struct rw_semaphore killsb;
500};
501
502static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
503{
504 return sb->s_fs_info;
505}
506
507static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
508{
509 return get_fuse_conn_super(inode->i_sb);
510}
511
512static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
513{
514 return container_of(inode, struct fuse_inode, inode);
515}
516
517static inline u64 get_node_id(struct inode *inode)
518{
519 return get_fuse_inode(inode)->nodeid;
520}
521
522
523extern const struct file_operations fuse_dev_operations;
524
525extern const struct dentry_operations fuse_dentry_operations;
526
527
528
529
530int fuse_inode_eq(struct inode *inode, void *_nodeidp);
531
532
533
534
535struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
536 int generation, struct fuse_attr *attr,
537 u64 attr_valid, u64 attr_version);
538
539int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
540 struct fuse_entry_out *outarg, struct inode **inode);
541
542
543
544
545void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
546 u64 nodeid, u64 nlookup);
547
548
549
550
551void fuse_read_fill(struct fuse_req *req, struct file *file,
552 loff_t pos, size_t count, int opcode);
553
554
555
556
557int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
558
559struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
560struct fuse_file *fuse_file_get(struct fuse_file *ff);
561void fuse_file_free(struct fuse_file *ff);
562void fuse_finish_open(struct inode *inode, struct file *file);
563
564void fuse_sync_release(struct fuse_file *ff, int flags);
565
566
567
568
569void fuse_release_common(struct file *file, int opcode);
570
571
572
573
574int fuse_fsync_common(struct file *file, int datasync, int isdir);
575
576
577
578
579int fuse_notify_poll_wakeup(struct fuse_conn *fc,
580 struct fuse_notify_poll_wakeup_out *outarg);
581
582
583
584
585void fuse_init_file_inode(struct inode *inode);
586
587
588
589
590void fuse_init_common(struct inode *inode);
591
592
593
594
595void fuse_init_dir(struct inode *inode);
596
597
598
599
600void fuse_init_symlink(struct inode *inode);
601
602
603
604
605void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
606 u64 attr_valid, u64 attr_version);
607
608void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
609 u64 attr_valid);
610
611
612
613
614int fuse_dev_init(void);
615
616
617
618
619void fuse_dev_cleanup(void);
620
621int fuse_ctl_init(void);
622void fuse_ctl_cleanup(void);
623
624
625
626
627struct fuse_req *fuse_request_alloc(void);
628
629struct fuse_req *fuse_request_alloc_nofs(void);
630
631
632
633
634void fuse_request_free(struct fuse_req *req);
635
636
637
638
639struct fuse_req *fuse_get_req(struct fuse_conn *fc);
640
641
642
643
644struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file);
645
646
647
648
649
650void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
651
652
653
654
655void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
656
657
658
659
660void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
661
662
663
664
665void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
666
667void fuse_request_send_background_locked(struct fuse_conn *fc,
668 struct fuse_req *req);
669
670
671void fuse_abort_conn(struct fuse_conn *fc);
672
673
674
675
676void fuse_invalidate_attr(struct inode *inode);
677
678void fuse_invalidate_entry_cache(struct dentry *entry);
679
680
681
682
683struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
684
685void fuse_conn_kill(struct fuse_conn *fc);
686
687
688
689
690void fuse_conn_init(struct fuse_conn *fc);
691
692
693
694
695void fuse_conn_put(struct fuse_conn *fc);
696
697
698
699
700int fuse_ctl_add_conn(struct fuse_conn *fc);
701
702
703
704
705void fuse_ctl_remove_conn(struct fuse_conn *fc);
706
707
708
709
710int fuse_valid_type(int m);
711
712
713
714
715int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task);
716
717u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
718
719int fuse_update_attributes(struct inode *inode, struct kstat *stat,
720 struct file *file, bool *refreshed);
721
722void fuse_flush_writepages(struct inode *inode);
723
724void fuse_set_nowrite(struct inode *inode);
725void fuse_release_nowrite(struct inode *inode);
726
727u64 fuse_get_attr_version(struct fuse_conn *fc);
728
729
730
731
732int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
733 loff_t offset, loff_t len);
734
735
736
737
738
739int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
740 struct qstr *name);
741
742int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
743 bool isdir);
744ssize_t fuse_direct_io(struct file *file, const char __user *buf,
745 size_t count, loff_t *ppos, int write);
746long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
747 unsigned int flags);
748unsigned fuse_file_poll(struct file *file, poll_table *wait);
749int fuse_dev_release(struct inode *inode, struct file *file);
750
751#endif
752