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;
17 struct deferred_update *ei_inode_update;
19 u64 ei_quota_reserved;
20 unsigned long ei_last_dirtied;
22 struct mutex ei_quota_lock;
23 struct bch_qid ei_qid;
25 struct bch_hash_info ei_str_hash;
27 /* copy of inode in btree: */
28 struct bch_inode_unpacked ei_inode;
31 #define to_bch_ei(_inode) \
32 container_of_or_null(_inode, struct bch_inode_info, v)
34 static inline int ptrcmp(void *l, void *r)
39 enum bch_inode_lock_op {
40 INODE_LOCK = (1U << 0),
41 INODE_UPDATE_LOCK = (1U << 1),
44 #define bch2_lock_inodes(_locks, ...) \
46 struct bch_inode_info *a[] = { NULL, __VA_ARGS__ }; \
49 bubble_sort(&a[1], ARRAY_SIZE(a) - 1, ptrcmp); \
51 for (i = 1; i < ARRAY_SIZE(a); i++) \
52 if (a[i] != a[i - 1]) { \
53 if (_locks & INODE_LOCK) \
54 down_write_nested(&a[i]->v.i_rwsem, i); \
55 if (_locks & INODE_UPDATE_LOCK) \
56 mutex_lock_nested(&a[i]->ei_update_lock, i);\
60 #define bch2_unlock_inodes(_locks, ...) \
62 struct bch_inode_info *a[] = { NULL, __VA_ARGS__ }; \
65 bubble_sort(&a[1], ARRAY_SIZE(a) - 1, ptrcmp); \
67 for (i = 1; i < ARRAY_SIZE(a); i++) \
68 if (a[i] != a[i - 1]) { \
69 if (_locks & INODE_LOCK) \
70 up_write(&a[i]->v.i_rwsem); \
71 if (_locks & INODE_UPDATE_LOCK) \
72 mutex_unlock(&a[i]->ei_update_lock); \
76 static inline struct bch_inode_info *file_bch_inode(struct file *file)
78 return to_bch_ei(file_inode(file));
81 static inline u8 mode_to_type(umode_t mode)
83 return (mode >> 12) & 15;
86 static inline unsigned nlink_bias(umode_t mode)
88 return S_ISDIR(mode) ? 2 : 1;
91 static inline bool inode_attr_changing(struct bch_inode_info *dir,
92 struct bch_inode_info *inode,
95 return !(inode->ei_inode.bi_fields_set & (1 << id)) &&
96 bch2_inode_opt_get(&dir->ei_inode, id) !=
97 bch2_inode_opt_get(&inode->ei_inode, id);
100 static inline bool inode_attrs_changing(struct bch_inode_info *dir,
101 struct bch_inode_info *inode)
105 for (id = 0; id < Inode_opt_nr; id++)
106 if (inode_attr_changing(dir, inode, id))
112 struct bch_inode_unpacked;
114 #ifndef NO_BCACHEFS_FS
116 int bch2_fs_quota_transfer(struct bch_fs *,
117 struct bch_inode_info *,
120 enum quota_acct_mode);
122 static inline int bch2_set_projid(struct bch_fs *c,
123 struct bch_inode_info *inode,
126 struct bch_qid qid = inode->ei_qid;
128 qid.q[QTYP_PRJ] = projid;
130 return bch2_fs_quota_transfer(c, inode, qid,
132 KEY_TYPE_QUOTA_PREALLOC);
135 struct inode *bch2_vfs_inode_get(struct bch_fs *, u64);
137 /* returns 0 if we want to do the update, or error is passed up */
138 typedef int (*inode_set_fn)(struct bch_inode_info *,
139 struct bch_inode_unpacked *, void *);
141 void bch2_inode_update_after_write(struct bch_fs *,
142 struct bch_inode_info *,
143 struct bch_inode_unpacked *,
145 int __must_check bch2_write_inode_trans(struct btree_trans *,
146 struct bch_inode_info *,
147 struct bch_inode_unpacked *,
148 inode_set_fn, void *);
149 int __must_check bch2_write_inode(struct bch_fs *, struct bch_inode_info *,
150 inode_set_fn, void *, unsigned);
152 int bch2_reinherit_attrs_fn(struct bch_inode_info *,
153 struct bch_inode_unpacked *,
156 void bch2_vfs_exit(void);
157 int bch2_vfs_init(void);
161 static inline void bch2_vfs_exit(void) {}
162 static inline int bch2_vfs_init(void) { return 0; }
164 #endif /* NO_BCACHEFS_FS */
166 #endif /* _BCACHEFS_FS_H */