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