]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/fs.h
Update bcachefs sources to 15f6e66e86 bcachefs: pass around bset_tree less
[bcachefs-tools-debian] / libbcachefs / fs.h
1 #ifndef _BCACHEFS_FS_H
2 #define _BCACHEFS_FS_H
3
4 #include "inode.h"
5 #include "opts.h"
6 #include "str_hash.h"
7 #include "quota_types.h"
8
9 #include <linux/seqlock.h>
10 #include <linux/stat.h>
11
12 struct bch_inode_info {
13         struct inode            v;
14
15         struct mutex            ei_update_lock;
16         u64                     ei_journal_seq;
17         u64                     ei_quota_reserved;
18         unsigned long           ei_last_dirtied;
19
20         struct mutex            ei_quota_lock;
21         struct bch_qid          ei_qid;
22
23         struct bch_hash_info    ei_str_hash;
24
25         /* copy of inode in btree: */
26         struct bch_inode_unpacked ei_inode;
27 };
28
29 #define to_bch_ei(_inode)                                       \
30         container_of_or_null(_inode, struct bch_inode_info, v)
31
32 static inline struct bch_inode_info *file_bch_inode(struct file *file)
33 {
34         return to_bch_ei(file_inode(file));
35 }
36
37 static inline u8 mode_to_type(umode_t mode)
38 {
39         return (mode >> 12) & 15;
40 }
41
42 static inline unsigned nlink_bias(umode_t mode)
43 {
44         return S_ISDIR(mode) ? 2 : 1;
45 }
46
47 static inline u64 bch2_current_time(struct bch_fs *c)
48 {
49         return timespec_to_bch2_time(c, current_kernel_time64());
50 }
51
52 struct bch_inode_unpacked;
53
54 #ifndef NO_BCACHEFS_FS
55
56 /* returns 0 if we want to do the update, or error is passed up */
57 typedef int (*inode_set_fn)(struct bch_inode_info *,
58                             struct bch_inode_unpacked *, void *);
59
60 void bch2_inode_update_after_write(struct bch_fs *,
61                                    struct bch_inode_info *,
62                                    struct bch_inode_unpacked *,
63                                    unsigned);
64 int __must_check bch2_write_inode_trans(struct btree_trans *,
65                                 struct bch_inode_info *,
66                                 struct bch_inode_unpacked *,
67                                 inode_set_fn, void *);
68 int __must_check bch2_write_inode(struct bch_fs *, struct bch_inode_info *,
69                                   inode_set_fn, void *, unsigned);
70
71 void bch2_vfs_exit(void);
72 int bch2_vfs_init(void);
73
74 #else
75
76 static inline void bch2_vfs_exit(void) {}
77 static inline int bch2_vfs_init(void) { return 0; }
78
79 #endif /* NO_BCACHEFS_FS */
80
81 #endif /* _BCACHEFS_FS_H */