]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/quota.h
Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into...
[bcachefs-tools-debian] / libbcachefs / quota.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_QUOTA_H
3 #define _BCACHEFS_QUOTA_H
4
5 #include "inode.h"
6 #include "quota_types.h"
7
8 extern const struct bch_sb_field_ops bch_sb_field_ops_quota;
9
10 int bch2_quota_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
11 void bch2_quota_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
12
13 #define bch2_bkey_ops_quota ((struct bkey_ops) {        \
14         .key_invalid    = bch2_quota_invalid,           \
15         .val_to_text    = bch2_quota_to_text,           \
16         .min_val_size   = 32,                           \
17 })
18
19 static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
20 {
21         return (struct bch_qid) {
22                 .q[QTYP_USR] = u->bi_uid,
23                 .q[QTYP_GRP] = u->bi_gid,
24                 .q[QTYP_PRJ] = u->bi_project ? u->bi_project - 1 : 0,
25         };
26 }
27
28 static inline unsigned enabled_qtypes(struct bch_fs *c)
29 {
30         return ((c->opts.usrquota << QTYP_USR)|
31                 (c->opts.grpquota << QTYP_GRP)|
32                 (c->opts.prjquota << QTYP_PRJ));
33 }
34
35 #ifdef CONFIG_BCACHEFS_QUOTA
36
37 int bch2_quota_acct(struct bch_fs *, struct bch_qid, enum quota_counters,
38                     s64, enum quota_acct_mode);
39
40 int bch2_quota_transfer(struct bch_fs *, unsigned, struct bch_qid,
41                         struct bch_qid, u64, enum quota_acct_mode);
42
43 void bch2_fs_quota_exit(struct bch_fs *);
44 void bch2_fs_quota_init(struct bch_fs *);
45 int bch2_fs_quota_read(struct bch_fs *);
46
47 extern const struct quotactl_ops bch2_quotactl_operations;
48
49 #else
50
51 static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
52                                   enum quota_counters counter, s64 v,
53                                   enum quota_acct_mode mode)
54 {
55         return 0;
56 }
57
58 static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
59                                       struct bch_qid dst,
60                                       struct bch_qid src, u64 space,
61                                       enum quota_acct_mode mode)
62 {
63         return 0;
64 }
65
66 static inline void bch2_fs_quota_exit(struct bch_fs *c) {}
67 static inline void bch2_fs_quota_init(struct bch_fs *c) {}
68 static inline int bch2_fs_quota_read(struct bch_fs *c) { return 0; }
69
70 #endif
71
72 #endif /* _BCACHEFS_QUOTA_H */