1 /* SPDX-License-Identifier: GPL-2.0 */
8 #include "quota_types.h"
10 #include <linux/seqlock.h>
11 #include <linux/stat.h>
13 struct bch_inode_info {
16 struct mutex ei_update_lock;
18 u64 ei_quota_reserved;
19 unsigned long ei_last_dirtied;
21 struct mutex ei_quota_lock;
22 struct bch_qid ei_qid;
24 struct bch_hash_info ei_str_hash;
26 /* copy of inode in btree: */
27 struct bch_inode_unpacked ei_inode;
30 #define to_bch_ei(_inode) \
31 container_of_or_null(_inode, struct bch_inode_info, v)
33 static inline int ptrcmp(void *l, void *r)
38 enum bch_inode_lock_op {
39 INODE_LOCK = (1U << 0),
40 INODE_UPDATE_LOCK = (1U << 1),
43 #define bch2_lock_inodes(_locks, ...) \
45 struct bch_inode_info *a[] = { NULL, __VA_ARGS__ }; \
48 bubble_sort(&a[1], ARRAY_SIZE(a) - 1, ptrcmp); \
50 for (i = 1; i < ARRAY_SIZE(a); i++) \
51 if (a[i] != a[i - 1]) { \
52 if (_locks & INODE_LOCK) \
53 down_write_nested(&a[i]->v.i_rwsem, i); \
54 if (_locks & INODE_UPDATE_LOCK) \
55 mutex_lock_nested(&a[i]->ei_update_lock, i);\
59 #define bch2_unlock_inodes(_locks, ...) \
61 struct bch_inode_info *a[] = { NULL, __VA_ARGS__ }; \
64 bubble_sort(&a[1], ARRAY_SIZE(a) - 1, ptrcmp); \
66 for (i = 1; i < ARRAY_SIZE(a); i++) \
67 if (a[i] != a[i - 1]) { \
68 if (_locks & INODE_LOCK) \
69 up_write(&a[i]->v.i_rwsem); \
70 if (_locks & INODE_UPDATE_LOCK) \
71 mutex_unlock(&a[i]->ei_update_lock); \
75 static inline struct bch_inode_info *file_bch_inode(struct file *file)
77 return to_bch_ei(file_inode(file));
80 static inline u8 mode_to_type(umode_t mode)
82 return (mode >> 12) & 15;
85 static inline bool inode_attr_changing(struct bch_inode_info *dir,
86 struct bch_inode_info *inode,
89 return !(inode->ei_inode.bi_fields_set & (1 << id)) &&
90 bch2_inode_opt_get(&dir->ei_inode, id) !=
91 bch2_inode_opt_get(&inode->ei_inode, id);
94 static inline bool inode_attrs_changing(struct bch_inode_info *dir,
95 struct bch_inode_info *inode)
99 for (id = 0; id < Inode_opt_nr; id++)
100 if (inode_attr_changing(dir, inode, id))
106 struct bch_inode_unpacked;
108 #ifndef NO_BCACHEFS_FS
110 int bch2_fs_quota_transfer(struct bch_fs *,
111 struct bch_inode_info *,
114 enum quota_acct_mode);
116 static inline int bch2_set_projid(struct bch_fs *c,
117 struct bch_inode_info *inode,
120 struct bch_qid qid = inode->ei_qid;
122 qid.q[QTYP_PRJ] = projid;
124 return bch2_fs_quota_transfer(c, inode, qid,
126 KEY_TYPE_QUOTA_PREALLOC);
129 struct inode *bch2_vfs_inode_get(struct bch_fs *, u64);
131 /* returns 0 if we want to do the update, or error is passed up */
132 typedef int (*inode_set_fn)(struct bch_inode_info *,
133 struct bch_inode_unpacked *, void *);
135 void bch2_inode_update_after_write(struct bch_fs *,
136 struct bch_inode_info *,
137 struct bch_inode_unpacked *,
139 int __must_check bch2_write_inode_trans(struct btree_trans *,
140 struct bch_inode_info *,
141 struct bch_inode_unpacked *,
142 inode_set_fn, void *);
143 int __must_check bch2_write_inode(struct bch_fs *, struct bch_inode_info *,
144 inode_set_fn, void *, unsigned);
146 int bch2_reinherit_attrs_fn(struct bch_inode_info *,
147 struct bch_inode_unpacked *,
150 void bch2_vfs_exit(void);
151 int bch2_vfs_init(void);
155 static inline void bch2_vfs_exit(void) {}
156 static inline int bch2_vfs_init(void) { return 0; }
158 #endif /* NO_BCACHEFS_FS */
160 #endif /* _BCACHEFS_FS_H */