1
2
3
4
5
6
7
8
9#ifndef _FS_FUSE_I_H
10#define _FS_FUSE_I_H
11
12#ifndef pr_fmt
13# define pr_fmt(fmt) "fuse: " fmt
14#endif
15
16#include <linux/fuse.h>
17#include <linux/fs.h>
18#include <linux/mount.h>
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>
24#include <linux/mutex.h>
25#include <linux/rwsem.h>
26#include <linux/rbtree.h>
27#include <linux/poll.h>
28#include <linux/workqueue.h>
29#include <linux/kref.h>
30#include <linux/xattr.h>
31#include <linux/pid_namespace.h>
32#include <linux/refcount.h>
33#include <linux/user_namespace.h>
34
35
36#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
37
38
39#define FUSE_MAX_MAX_PAGES 256
40
41
42#define FUSE_NOWRITE INT_MIN
43
44
45#define FUSE_NAME_MAX 1024
46
47
48#define FUSE_CTL_NUM_DENTRIES 5
49
50
51#define FUSE_REQ_INLINE_PAGES 1
52
53
54extern struct list_head fuse_conn_list;
55
56
57extern struct mutex fuse_mutex;
58
59
60extern unsigned max_user_bgreq;
61extern unsigned max_user_congthresh;
62
63
64struct fuse_forget_link {
65 struct fuse_forget_one forget_one;
66 struct fuse_forget_link *next;
67};
68
69
70struct fuse_inode {
71
72 struct inode inode;
73
74
75
76 u64 nodeid;
77
78
79 u64 nlookup;
80
81
82 struct fuse_forget_link *forget;
83
84
85 u64 i_time;
86
87
88 u32 inval_mask;
89
90
91
92 umode_t orig_i_mode;
93
94
95 u64 orig_ino;
96
97
98 u64 attr_version;
99
100 union {
101
102 struct {
103
104 struct list_head write_files;
105
106
107 struct list_head queued_writes;
108
109
110
111 int writectr;
112
113
114 wait_queue_head_t page_waitq;
115
116
117 struct list_head writepages;
118 };
119
120
121 struct {
122
123 bool cached;
124
125
126 loff_t size;
127
128
129 loff_t pos;
130
131
132 u64 version;
133
134
135
136 struct timespec64 mtime;
137
138
139 u64 iversion;
140
141
142 spinlock_t lock;
143 } rdc;
144 };
145
146
147 unsigned long state;
148
149
150 struct mutex mutex;
151
152
153 spinlock_t lock;
154};
155
156
157enum {
158
159 FUSE_I_ADVISE_RDPLUS,
160
161 FUSE_I_INIT_RDPLUS,
162
163 FUSE_I_SIZE_UNSTABLE,
164};
165
166struct fuse_conn;
167
168
169struct fuse_file {
170
171 struct fuse_conn *fc;
172
173
174
175
176
177 struct fuse_req *reserved_req;
178
179
180 u64 kh;
181
182
183 u64 fh;
184
185
186 u64 nodeid;
187
188
189 refcount_t count;
190
191
192 u32 open_flags;
193
194
195 struct list_head write_entry;
196
197
198 struct {
199
200
201
202
203 struct mutex lock;
204
205
206 loff_t pos;
207
208
209 loff_t cache_off;
210
211
212 u64 version;
213
214 } readdir;
215
216
217 struct rb_node polled_node;
218
219
220 wait_queue_head_t poll_wait;
221
222
223 bool flock:1;
224};
225
226
227struct fuse_in_arg {
228 unsigned size;
229 const void *value;
230};
231
232
233struct fuse_in {
234
235 struct fuse_in_header h;
236
237
238 unsigned argpages:1;
239
240
241 unsigned numargs;
242
243
244 struct fuse_in_arg args[3];
245};
246
247
248struct fuse_arg {
249 unsigned size;
250 void *value;
251};
252
253
254struct fuse_out {
255
256 struct fuse_out_header h;
257
258
259
260
261
262
263
264
265 unsigned argvar:1;
266
267
268 unsigned argpages:1;
269
270
271 unsigned page_zeroing:1;
272
273
274 unsigned page_replace:1;
275
276
277 unsigned numargs;
278
279
280 struct fuse_arg args[2];
281};
282
283
284struct fuse_page_desc {
285 unsigned int length;
286 unsigned int offset;
287};
288
289struct fuse_args {
290 struct {
291 struct {
292 uint32_t opcode;
293 uint64_t nodeid;
294 } h;
295 unsigned numargs;
296 struct fuse_in_arg args[3];
297
298 } in;
299 struct {
300 unsigned argvar:1;
301 unsigned numargs;
302 struct fuse_arg args[2];
303 } out;
304};
305
306#define FUSE_ARGS(args) struct fuse_args args = {}
307
308
309struct fuse_io_priv {
310 struct kref refcnt;
311 int async;
312 spinlock_t lock;
313 unsigned reqs;
314 ssize_t bytes;
315 size_t size;
316 __u64 offset;
317 bool write;
318 bool should_dirty;
319 int err;
320 struct kiocb *iocb;
321 struct completion *done;
322 bool blocking;
323};
324
325#define FUSE_IO_PRIV_SYNC(i) \
326{ \
327 .refcnt = KREF_INIT(1), \
328 .async = 0, \
329 .iocb = i, \
330}
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347enum fuse_req_flag {
348 FR_ISREPLY,
349 FR_FORCE,
350 FR_BACKGROUND,
351 FR_WAITING,
352 FR_ABORTED,
353 FR_INTERRUPTED,
354 FR_LOCKED,
355 FR_PENDING,
356 FR_SENT,
357 FR_FINISHED,
358 FR_PRIVATE,
359};
360
361
362
363
364
365
366
367
368struct fuse_req {
369
370
371 struct list_head list;
372
373
374 struct list_head intr_entry;
375
376
377 refcount_t count;
378
379
380 unsigned long flags;
381
382
383 struct fuse_in in;
384
385
386 struct fuse_out out;
387
388
389 wait_queue_head_t waitq;
390
391
392 union {
393 struct {
394 struct fuse_release_in in;
395 struct inode *inode;
396 } release;
397 struct fuse_init_in init_in;
398 struct fuse_init_out init_out;
399 struct cuse_init_in cuse_init_in;
400 struct {
401 struct fuse_read_in in;
402 u64 attr_ver;
403 } read;
404 struct {
405 struct fuse_write_in in;
406 struct fuse_write_out out;
407 struct fuse_req *next;
408 } write;
409 struct fuse_notify_retrieve_in retrieve_in;
410 } misc;
411
412
413 struct page **pages;
414
415
416 struct fuse_page_desc *page_descs;
417
418
419 unsigned max_pages;
420
421
422 struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
423
424
425 struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
426
427
428 unsigned num_pages;
429
430
431 struct fuse_file *ff;
432
433
434 struct inode *inode;
435
436
437 struct fuse_io_priv *io;
438
439
440 struct list_head writepages_entry;
441
442
443 void (*end)(struct fuse_conn *, struct fuse_req *);
444
445
446 struct file *stolen_file;
447};
448
449struct fuse_iqueue {
450
451 unsigned connected;
452
453
454 wait_queue_head_t waitq;
455
456
457 u64 reqctr;
458
459
460 struct list_head pending;
461
462
463 struct list_head interrupts;
464
465
466 struct fuse_forget_link forget_list_head;
467 struct fuse_forget_link *forget_list_tail;
468
469
470 int forget_batch;
471
472
473 struct fasync_struct *fasync;
474};
475
476#define FUSE_PQ_HASH_BITS 8
477#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
478
479struct fuse_pqueue {
480
481 unsigned connected;
482
483
484 spinlock_t lock;
485
486
487 struct list_head *processing;
488
489
490 struct list_head io;
491};
492
493
494
495
496struct fuse_dev {
497
498 struct fuse_conn *fc;
499
500
501 struct fuse_pqueue pq;
502
503
504 struct list_head entry;
505};
506
507
508
509
510
511
512
513
514struct fuse_conn {
515
516 spinlock_t lock;
517
518
519 refcount_t count;
520
521
522 atomic_t dev_count;
523
524 struct rcu_head rcu;
525
526
527 kuid_t user_id;
528
529
530 kgid_t group_id;
531
532
533 struct pid_namespace *pid_ns;
534
535
536 struct user_namespace *user_ns;
537
538
539 unsigned max_read;
540
541
542 unsigned max_write;
543
544
545 unsigned int max_pages;
546
547
548 struct fuse_iqueue iq;
549
550
551 atomic64_t khctr;
552
553
554 struct rb_root polled_files;
555
556
557 unsigned max_background;
558
559
560 unsigned congestion_threshold;
561
562
563 unsigned num_background;
564
565
566 unsigned active_background;
567
568
569 struct list_head bg_queue;
570
571
572
573 spinlock_t bg_lock;
574
575
576
577 int initialized;
578
579
580
581
582 int blocked;
583
584
585 wait_queue_head_t blocked_waitq;
586
587
588 wait_queue_head_t reserved_req_waitq;
589
590
591
592 unsigned connected;
593
594
595 bool aborted;
596
597
598
599
600 unsigned conn_error:1;
601
602
603 unsigned conn_init:1;
604
605
606 unsigned async_read:1;
607
608
609 unsigned abort_err:1;
610
611
612 unsigned atomic_o_trunc:1;
613
614
615 unsigned export_support:1;
616
617
618 unsigned writeback_cache:1;
619
620
621 unsigned parallel_dirops:1;
622
623
624 unsigned handle_killpriv:1;
625
626
627 unsigned cache_symlinks:1;
628
629
630
631
632
633
634
635 unsigned no_open:1;
636
637
638 unsigned no_opendir:1;
639
640
641 unsigned no_fsync:1;
642
643
644 unsigned no_fsyncdir:1;
645
646
647 unsigned no_flush:1;
648
649
650 unsigned no_setxattr:1;
651
652
653 unsigned no_getxattr:1;
654
655
656 unsigned no_listxattr:1;
657
658
659 unsigned no_removexattr:1;
660
661
662 unsigned no_lock:1;
663
664
665 unsigned no_access:1;
666
667
668 unsigned no_create:1;
669
670
671 unsigned no_interrupt:1;
672
673
674 unsigned no_bmap:1;
675
676
677 unsigned no_poll:1;
678
679
680 unsigned big_writes:1;
681
682
683 unsigned dont_mask:1;
684
685
686 unsigned no_flock:1;
687
688
689 unsigned no_fallocate:1;
690
691
692 unsigned no_rename2:1;
693
694
695 unsigned auto_inval_data:1;
696
697
698 unsigned explicit_inval_data:1;
699
700
701 unsigned do_readdirplus:1;
702
703
704 unsigned readdirplus_auto:1;
705
706
707 unsigned async_dio:1;
708
709
710 unsigned no_lseek:1;
711
712
713 unsigned posix_acl:1;
714
715
716 unsigned default_permissions:1;
717
718
719 unsigned allow_other:1;
720
721
722 unsigned no_copy_file_range:1;
723
724
725 atomic_t num_waiting;
726
727
728 unsigned minor;
729
730
731 struct list_head entry;
732
733
734 dev_t dev;
735
736
737 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
738
739
740 int ctl_ndents;
741
742
743 u32 scramble_key[4];
744
745
746 struct fuse_req *destroy_req;
747
748
749 atomic64_t attr_version;
750
751
752 void (*release)(struct fuse_conn *);
753
754
755 struct super_block *sb;
756
757
758 struct rw_semaphore killsb;
759
760
761 struct list_head devices;
762};
763
764static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
765{
766 return sb->s_fs_info;
767}
768
769static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
770{
771 return get_fuse_conn_super(inode->i_sb);
772}
773
774static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
775{
776 return container_of(inode, struct fuse_inode, inode);
777}
778
779static inline u64 get_node_id(struct inode *inode)
780{
781 return get_fuse_inode(inode)->nodeid;
782}
783
784static inline int invalid_nodeid(u64 nodeid)
785{
786 return !nodeid || nodeid == FUSE_ROOT_ID;
787}
788
789static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
790{
791 return atomic64_read(&fc->attr_version);
792}
793
794
795extern const struct file_operations fuse_dev_operations;
796
797extern const struct dentry_operations fuse_dentry_operations;
798extern const struct dentry_operations fuse_root_dentry_operations;
799
800
801
802
803int fuse_inode_eq(struct inode *inode, void *_nodeidp);
804
805
806
807
808struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
809 int generation, struct fuse_attr *attr,
810 u64 attr_valid, u64 attr_version);
811
812int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
813 struct fuse_entry_out *outarg, struct inode **inode);
814
815
816
817
818void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
819 u64 nodeid, u64 nlookup);
820
821struct fuse_forget_link *fuse_alloc_forget(void);
822
823
824void fuse_force_forget(struct file *file, u64 nodeid);
825
826
827
828
829void fuse_read_fill(struct fuse_req *req, struct file *file,
830 loff_t pos, size_t count, int opcode);
831
832
833
834
835int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
836
837struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
838void fuse_file_free(struct fuse_file *ff);
839void fuse_finish_open(struct inode *inode, struct file *file);
840
841void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
842
843
844
845
846void fuse_release_common(struct file *file, bool isdir);
847
848
849
850
851int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
852 int datasync, int opcode);
853
854
855
856
857int fuse_notify_poll_wakeup(struct fuse_conn *fc,
858 struct fuse_notify_poll_wakeup_out *outarg);
859
860
861
862
863void fuse_init_file_inode(struct inode *inode);
864
865
866
867
868void fuse_init_common(struct inode *inode);
869
870
871
872
873void fuse_init_dir(struct inode *inode);
874
875
876
877
878void fuse_init_symlink(struct inode *inode);
879
880
881
882
883void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
884 u64 attr_valid, u64 attr_version);
885
886void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
887 u64 attr_valid);
888
889
890
891
892int fuse_dev_init(void);
893
894
895
896
897void fuse_dev_cleanup(void);
898
899int fuse_ctl_init(void);
900void __exit fuse_ctl_cleanup(void);
901
902
903
904
905struct fuse_req *fuse_request_alloc(unsigned npages);
906
907struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
908
909bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req,
910 gfp_t flags);
911
912
913
914
915
916void fuse_request_free(struct fuse_req *req);
917
918
919
920
921
922struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
923struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
924 unsigned npages);
925
926
927
928
929void __fuse_get_request(struct fuse_req *req);
930
931
932
933
934struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
935 struct file *file);
936
937
938
939
940
941void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
942
943
944
945
946void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
947
948
949
950
951ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
952
953
954
955
956void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
957bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
958
959
960void fuse_abort_conn(struct fuse_conn *fc);
961void fuse_wait_aborted(struct fuse_conn *fc);
962
963
964
965
966void fuse_invalidate_attr(struct inode *inode);
967
968void fuse_invalidate_entry_cache(struct dentry *entry);
969
970void fuse_invalidate_atime(struct inode *inode);
971
972u64 entry_attr_timeout(struct fuse_entry_out *o);
973void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
974
975
976
977
978struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
979
980
981
982
983void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
984
985
986
987
988void fuse_conn_put(struct fuse_conn *fc);
989
990struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
991void fuse_dev_free(struct fuse_dev *fud);
992
993
994
995
996int fuse_ctl_add_conn(struct fuse_conn *fc);
997
998
999
1000
1001void fuse_ctl_remove_conn(struct fuse_conn *fc);
1002
1003
1004
1005
1006int fuse_valid_type(int m);
1007
1008
1009
1010
1011int fuse_allow_current_process(struct fuse_conn *fc);
1012
1013u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
1014
1015void fuse_update_ctime(struct inode *inode);
1016
1017int fuse_update_attributes(struct inode *inode, struct file *file);
1018
1019void fuse_flush_writepages(struct inode *inode);
1020
1021void fuse_set_nowrite(struct inode *inode);
1022void fuse_release_nowrite(struct inode *inode);
1023
1024
1025
1026
1027int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
1028 loff_t offset, loff_t len);
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
1041 u64 child_nodeid, struct qstr *name);
1042
1043int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
1044 bool isdir);
1045
1046
1047
1048
1049
1050
1051#define FUSE_DIO_WRITE (1 << 0)
1052
1053
1054#define FUSE_DIO_CUSE (1 << 1)
1055
1056ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1057 loff_t *ppos, int flags);
1058long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1059 unsigned int flags);
1060long fuse_ioctl_common(struct file *file, unsigned int cmd,
1061 unsigned long arg, unsigned int flags);
1062__poll_t fuse_file_poll(struct file *file, poll_table *wait);
1063int fuse_dev_release(struct inode *inode, struct file *file);
1064
1065bool fuse_write_update_size(struct inode *inode, loff_t pos);
1066
1067int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
1068int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1069
1070int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1071 struct file *file);
1072
1073void fuse_set_initialized(struct fuse_conn *fc);
1074
1075void fuse_unlock_inode(struct inode *inode, bool locked);
1076bool fuse_lock_inode(struct inode *inode);
1077
1078int fuse_setxattr(struct inode *inode, const char *name, const void *value,
1079 size_t size, int flags);
1080ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
1081 size_t size);
1082ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
1083int fuse_removexattr(struct inode *inode, const char *name);
1084extern const struct xattr_handler *fuse_xattr_handlers[];
1085extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1086extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
1087
1088struct posix_acl;
1089struct posix_acl *fuse_get_acl(struct inode *inode, int type);
1090int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
1091
1092
1093
1094int fuse_readdir(struct file *file, struct dir_context *ctx);
1095
1096#endif
1097