summaryrefslogtreecommitdiff
path: root/fs/bcachefs/quota.h
blob: 9650e518cd644b30155be5c77f61b1539453b531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_QUOTA_H
#define _BCACHEFS_QUOTA_H

#include "inode.h"
#include "quota_types.h"

extern const struct bch_sb_field_ops bch_sb_field_ops_quota;

const char *bch2_quota_invalid(const struct bch_fs *, struct bkey_s_c);
int bch2_quota_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);

#define bch2_bkey_quota_ops (struct bkey_ops) {		\
	.key_invalid	= bch2_quota_invalid,		\
	.val_to_text	= bch2_quota_to_text,		\
}

enum quota_acct_mode {
	BCH_QUOTA_PREALLOC,
	BCH_QUOTA_WARN,
	BCH_QUOTA_NOCHECK,
};

static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
{
	return (struct bch_qid) {
		.q[QTYP_USR] = u->bi_uid,
		.q[QTYP_GRP] = u->bi_gid,
		.q[QTYP_PRJ] = u->bi_project,
	};
}

static inline unsigned enabled_qtypes(struct bch_fs *c)
{
	return ((c->opts.usrquota << QTYP_USR)|
		(c->opts.grpquota << QTYP_GRP)|
		(c->opts.prjquota << QTYP_PRJ));
}

#ifdef CONFIG_BCACHEFS_QUOTA

int bch2_quota_acct(struct bch_fs *, struct bch_qid, enum quota_counters,
		    s64, enum quota_acct_mode);

int bch2_quota_transfer(struct bch_fs *, unsigned, struct bch_qid,
			struct bch_qid, u64);

void bch2_fs_quota_exit(struct bch_fs *);
void bch2_fs_quota_init(struct bch_fs *);
int bch2_fs_quota_read(struct bch_fs *);

extern const struct quotactl_ops bch2_quotactl_operations;

#else

static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
				  enum quota_counters counter, s64 v,
				  enum quota_acct_mode mode)
{
	return 0;
}

static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
				      struct bch_qid dst,
				      struct bch_qid src, u64 space)
{
	return 0;
}

static inline void bch2_fs_quota_exit(struct bch_fs *c) {}
static inline void bch2_fs_quota_init(struct bch_fs *c) {}
static inline int bch2_fs_quota_read(struct bch_fs *c) { return 0; }

#endif

#endif /* _BCACHEFS_QUOTA_H */