]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/quota.h
Update bcachefs sources to 62de7539dc bcachefs: Make bkey types globally unique
[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 enum quota_acct_mode {
18         KEY_TYPE_QUOTA_PREALLOC,
19         KEY_TYPE_QUOTA_WARN,
20         KEY_TYPE_QUOTA_NOCHECK,
21 };
22
23 static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
24 {
25         return (struct bch_qid) {
26                 .q[QTYP_USR] = u->bi_uid,
27                 .q[QTYP_GRP] = u->bi_gid,
28                 .q[QTYP_PRJ] = u->bi_project,
29         };
30 }
31
32 static inline unsigned enabled_qtypes(struct bch_fs *c)
33 {
34         return ((c->opts.usrquota << QTYP_USR)|
35                 (c->opts.grpquota << QTYP_GRP)|
36                 (c->opts.prjquota << QTYP_PRJ));
37 }
38
39 #ifdef CONFIG_BCACHEFS_QUOTA
40
41 int bch2_quota_acct(struct bch_fs *, struct bch_qid, enum quota_counters,
42                     s64, enum quota_acct_mode);
43
44 int bch2_quota_transfer(struct bch_fs *, unsigned, struct bch_qid,
45                         struct bch_qid, u64);
46
47 void bch2_fs_quota_exit(struct bch_fs *);
48 void bch2_fs_quota_init(struct bch_fs *);
49 int bch2_fs_quota_read(struct bch_fs *);
50
51 extern const struct quotactl_ops bch2_quotactl_operations;
52
53 #else
54
55 static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
56                                   enum quota_counters counter, s64 v,
57                                   enum quota_acct_mode mode)
58 {
59         return 0;
60 }
61
62 static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
63                                       struct bch_qid dst,
64                                       struct bch_qid src, u64 space)
65 {
66         return 0;
67 }
68
69 static inline void bch2_fs_quota_exit(struct bch_fs *c) {}
70 static inline void bch2_fs_quota_init(struct bch_fs *c) {}
71 static inline int bch2_fs_quota_read(struct bch_fs *c) { return 0; }
72
73 #endif
74
75 #endif /* _BCACHEFS_QUOTA_H */