xref: /linux/fs/bcachefs/quota.h (revision b71817585383d96ddc51ebd126f6253fdb9a8568)
11c6fdbd8SKent Overstreet /* SPDX-License-Identifier: GPL-2.0 */
21c6fdbd8SKent Overstreet #ifndef _BCACHEFS_QUOTA_H
31c6fdbd8SKent Overstreet #define _BCACHEFS_QUOTA_H
41c6fdbd8SKent Overstreet 
51c6fdbd8SKent Overstreet #include "inode.h"
61c6fdbd8SKent Overstreet #include "quota_types.h"
71c6fdbd8SKent Overstreet 
865eaf4e2SKent Overstreet enum bch_validate_flags;
91c6fdbd8SKent Overstreet extern const struct bch_sb_field_ops bch_sb_field_ops_quota;
101c6fdbd8SKent Overstreet 
11*d97de0d0SKent Overstreet int bch2_quota_validate(struct bch_fs *, struct bkey_s_c, enum bch_validate_flags);
12319f9ac3SKent Overstreet void bch2_quota_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
131c6fdbd8SKent Overstreet 
14a1019576SKent Overstreet #define bch2_bkey_ops_quota ((struct bkey_ops) {	\
15*d97de0d0SKent Overstreet 	.key_validate	= bch2_quota_validate,		\
161c6fdbd8SKent Overstreet 	.val_to_text	= bch2_quota_to_text,		\
17174f930bSKent Overstreet 	.min_val_size	= 32,				\
18a1019576SKent Overstreet })
191c6fdbd8SKent Overstreet 
bch_qid(struct bch_inode_unpacked * u)201c6fdbd8SKent Overstreet static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
211c6fdbd8SKent Overstreet {
221c6fdbd8SKent Overstreet 	return (struct bch_qid) {
231c6fdbd8SKent Overstreet 		.q[QTYP_USR] = u->bi_uid,
241c6fdbd8SKent Overstreet 		.q[QTYP_GRP] = u->bi_gid,
252fab25cdSKent Overstreet 		.q[QTYP_PRJ] = u->bi_project ? u->bi_project - 1 : 0,
261c6fdbd8SKent Overstreet 	};
271c6fdbd8SKent Overstreet }
281c6fdbd8SKent Overstreet 
enabled_qtypes(struct bch_fs * c)291c6fdbd8SKent Overstreet static inline unsigned enabled_qtypes(struct bch_fs *c)
301c6fdbd8SKent Overstreet {
311c6fdbd8SKent Overstreet 	return ((c->opts.usrquota << QTYP_USR)|
321c6fdbd8SKent Overstreet 		(c->opts.grpquota << QTYP_GRP)|
331c6fdbd8SKent Overstreet 		(c->opts.prjquota << QTYP_PRJ));
341c6fdbd8SKent Overstreet }
351c6fdbd8SKent Overstreet 
361c6fdbd8SKent Overstreet #ifdef CONFIG_BCACHEFS_QUOTA
371c6fdbd8SKent Overstreet 
381c6fdbd8SKent Overstreet int bch2_quota_acct(struct bch_fs *, struct bch_qid, enum quota_counters,
391c6fdbd8SKent Overstreet 		    s64, enum quota_acct_mode);
401c6fdbd8SKent Overstreet 
411c6fdbd8SKent Overstreet int bch2_quota_transfer(struct bch_fs *, unsigned, struct bch_qid,
420f5254aaSKent Overstreet 			struct bch_qid, u64, enum quota_acct_mode);
431c6fdbd8SKent Overstreet 
441c6fdbd8SKent Overstreet void bch2_fs_quota_exit(struct bch_fs *);
451c6fdbd8SKent Overstreet void bch2_fs_quota_init(struct bch_fs *);
461c6fdbd8SKent Overstreet int bch2_fs_quota_read(struct bch_fs *);
471c6fdbd8SKent Overstreet 
481c6fdbd8SKent Overstreet extern const struct quotactl_ops bch2_quotactl_operations;
491c6fdbd8SKent Overstreet 
501c6fdbd8SKent Overstreet #else
511c6fdbd8SKent Overstreet 
bch2_quota_acct(struct bch_fs * c,struct bch_qid qid,enum quota_counters counter,s64 v,enum quota_acct_mode mode)521c6fdbd8SKent Overstreet static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
531c6fdbd8SKent Overstreet 				  enum quota_counters counter, s64 v,
541c6fdbd8SKent Overstreet 				  enum quota_acct_mode mode)
551c6fdbd8SKent Overstreet {
561c6fdbd8SKent Overstreet 	return 0;
571c6fdbd8SKent Overstreet }
581c6fdbd8SKent Overstreet 
bch2_quota_transfer(struct bch_fs * c,unsigned qtypes,struct bch_qid dst,struct bch_qid src,u64 space,enum quota_acct_mode mode)591c6fdbd8SKent Overstreet static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
601c6fdbd8SKent Overstreet 				      struct bch_qid dst,
610f5254aaSKent Overstreet 				      struct bch_qid src, u64 space,
620f5254aaSKent Overstreet 				      enum quota_acct_mode mode)
631c6fdbd8SKent Overstreet {
641c6fdbd8SKent Overstreet 	return 0;
651c6fdbd8SKent Overstreet }
661c6fdbd8SKent Overstreet 
bch2_fs_quota_exit(struct bch_fs * c)671c6fdbd8SKent Overstreet static inline void bch2_fs_quota_exit(struct bch_fs *c) {}
bch2_fs_quota_init(struct bch_fs * c)681c6fdbd8SKent Overstreet static inline void bch2_fs_quota_init(struct bch_fs *c) {}
bch2_fs_quota_read(struct bch_fs * c)691c6fdbd8SKent Overstreet static inline int bch2_fs_quota_read(struct bch_fs *c) { return 0; }
701c6fdbd8SKent Overstreet 
711c6fdbd8SKent Overstreet #endif
721c6fdbd8SKent Overstreet 
731c6fdbd8SKent Overstreet #endif /* _BCACHEFS_QUOTA_H */
74