xref: /linux/fs/bcachefs/quota.h (revision 174f930b8e1cad3915819a46bb20da214f68f2b5)
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 
81c6fdbd8SKent Overstreet extern const struct bch_sb_field_ops bch_sb_field_ops_quota;
91c6fdbd8SKent Overstreet 
10facafdcbSKent Overstreet int bch2_quota_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
11319f9ac3SKent Overstreet void bch2_quota_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
121c6fdbd8SKent Overstreet 
13a1019576SKent Overstreet #define bch2_bkey_ops_quota ((struct bkey_ops) {	\
141c6fdbd8SKent Overstreet 	.key_invalid	= bch2_quota_invalid,		\
151c6fdbd8SKent Overstreet 	.val_to_text	= bch2_quota_to_text,		\
16*174f930bSKent Overstreet 	.min_val_size	= 32,				\
17a1019576SKent Overstreet })
181c6fdbd8SKent Overstreet 
191c6fdbd8SKent Overstreet static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
201c6fdbd8SKent Overstreet {
211c6fdbd8SKent Overstreet 	return (struct bch_qid) {
221c6fdbd8SKent Overstreet 		.q[QTYP_USR] = u->bi_uid,
231c6fdbd8SKent Overstreet 		.q[QTYP_GRP] = u->bi_gid,
242fab25cdSKent Overstreet 		.q[QTYP_PRJ] = u->bi_project ? u->bi_project - 1 : 0,
251c6fdbd8SKent Overstreet 	};
261c6fdbd8SKent Overstreet }
271c6fdbd8SKent Overstreet 
281c6fdbd8SKent Overstreet static inline unsigned enabled_qtypes(struct bch_fs *c)
291c6fdbd8SKent Overstreet {
301c6fdbd8SKent Overstreet 	return ((c->opts.usrquota << QTYP_USR)|
311c6fdbd8SKent Overstreet 		(c->opts.grpquota << QTYP_GRP)|
321c6fdbd8SKent Overstreet 		(c->opts.prjquota << QTYP_PRJ));
331c6fdbd8SKent Overstreet }
341c6fdbd8SKent Overstreet 
351c6fdbd8SKent Overstreet #ifdef CONFIG_BCACHEFS_QUOTA
361c6fdbd8SKent Overstreet 
371c6fdbd8SKent Overstreet int bch2_quota_acct(struct bch_fs *, struct bch_qid, enum quota_counters,
381c6fdbd8SKent Overstreet 		    s64, enum quota_acct_mode);
391c6fdbd8SKent Overstreet 
401c6fdbd8SKent Overstreet int bch2_quota_transfer(struct bch_fs *, unsigned, struct bch_qid,
410f5254aaSKent Overstreet 			struct bch_qid, u64, enum quota_acct_mode);
421c6fdbd8SKent Overstreet 
431c6fdbd8SKent Overstreet void bch2_fs_quota_exit(struct bch_fs *);
441c6fdbd8SKent Overstreet void bch2_fs_quota_init(struct bch_fs *);
451c6fdbd8SKent Overstreet int bch2_fs_quota_read(struct bch_fs *);
461c6fdbd8SKent Overstreet 
471c6fdbd8SKent Overstreet extern const struct quotactl_ops bch2_quotactl_operations;
481c6fdbd8SKent Overstreet 
491c6fdbd8SKent Overstreet #else
501c6fdbd8SKent Overstreet 
511c6fdbd8SKent Overstreet static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
521c6fdbd8SKent Overstreet 				  enum quota_counters counter, s64 v,
531c6fdbd8SKent Overstreet 				  enum quota_acct_mode mode)
541c6fdbd8SKent Overstreet {
551c6fdbd8SKent Overstreet 	return 0;
561c6fdbd8SKent Overstreet }
571c6fdbd8SKent Overstreet 
581c6fdbd8SKent Overstreet static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
591c6fdbd8SKent Overstreet 				      struct bch_qid dst,
600f5254aaSKent Overstreet 				      struct bch_qid src, u64 space,
610f5254aaSKent Overstreet 				      enum quota_acct_mode mode)
621c6fdbd8SKent Overstreet {
631c6fdbd8SKent Overstreet 	return 0;
641c6fdbd8SKent Overstreet }
651c6fdbd8SKent Overstreet 
661c6fdbd8SKent Overstreet static inline void bch2_fs_quota_exit(struct bch_fs *c) {}
671c6fdbd8SKent Overstreet static inline void bch2_fs_quota_init(struct bch_fs *c) {}
681c6fdbd8SKent Overstreet static inline int bch2_fs_quota_read(struct bch_fs *c) { return 0; }
691c6fdbd8SKent Overstreet 
701c6fdbd8SKent Overstreet #endif
711c6fdbd8SKent Overstreet 
721c6fdbd8SKent Overstreet #endif /* _BCACHEFS_QUOTA_H */
73