xref: /linux/fs/bcachefs/quota.h (revision 409c38d4f156740bf3165fd6ceae4fa6425eebf4)
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 enum bkey_invalid_flags;
9 extern const struct bch_sb_field_ops bch_sb_field_ops_quota;
10 
11 int bch2_quota_invalid(struct bch_fs *, struct bkey_s_c,
12 		       enum bkey_invalid_flags, struct printbuf *);
13 void bch2_quota_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
14 
15 #define bch2_bkey_ops_quota ((struct bkey_ops) {	\
16 	.key_invalid	= bch2_quota_invalid,		\
17 	.val_to_text	= bch2_quota_to_text,		\
18 	.min_val_size	= 32,				\
19 })
20 
21 static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
22 {
23 	return (struct bch_qid) {
24 		.q[QTYP_USR] = u->bi_uid,
25 		.q[QTYP_GRP] = u->bi_gid,
26 		.q[QTYP_PRJ] = u->bi_project ? u->bi_project - 1 : 0,
27 	};
28 }
29 
30 static inline unsigned enabled_qtypes(struct bch_fs *c)
31 {
32 	return ((c->opts.usrquota << QTYP_USR)|
33 		(c->opts.grpquota << QTYP_GRP)|
34 		(c->opts.prjquota << QTYP_PRJ));
35 }
36 
37 #ifdef CONFIG_BCACHEFS_QUOTA
38 
39 int bch2_quota_acct(struct bch_fs *, struct bch_qid, enum quota_counters,
40 		    s64, enum quota_acct_mode);
41 
42 int bch2_quota_transfer(struct bch_fs *, unsigned, struct bch_qid,
43 			struct bch_qid, u64, enum quota_acct_mode);
44 
45 void bch2_fs_quota_exit(struct bch_fs *);
46 void bch2_fs_quota_init(struct bch_fs *);
47 int bch2_fs_quota_read(struct bch_fs *);
48 
49 extern const struct quotactl_ops bch2_quotactl_operations;
50 
51 #else
52 
53 static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
54 				  enum quota_counters counter, s64 v,
55 				  enum quota_acct_mode mode)
56 {
57 	return 0;
58 }
59 
60 static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
61 				      struct bch_qid dst,
62 				      struct bch_qid src, u64 space,
63 				      enum quota_acct_mode mode)
64 {
65 	return 0;
66 }
67 
68 static inline void bch2_fs_quota_exit(struct bch_fs *c) {}
69 static inline void bch2_fs_quota_init(struct bch_fs *c) {}
70 static inline int bch2_fs_quota_read(struct bch_fs *c) { return 0; }
71 
72 #endif
73 
74 #endif /* _BCACHEFS_QUOTA_H */
75