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#ifndef _LINUX_QUOTA_
33#define _LINUX_QUOTA_
34
35#include <linux/list.h>
36#include <linux/mutex.h>
37#include <linux/rwsem.h>
38#include <linux/spinlock.h>
39#include <linux/wait.h>
40#include <linux/percpu_counter.h>
41
42#include <linux/dqblk_xfs.h>
43#include <linux/dqblk_v1.h>
44#include <linux/dqblk_v2.h>
45
46#include <linux/atomic.h>
47#include <linux/uidgid.h>
48#include <linux/projid.h>
49#include <uapi/linux/quota.h>
50
51#undef USRQUOTA
52#undef GRPQUOTA
53enum quota_type {
54 USRQUOTA = 0,
55 GRPQUOTA = 1,
56 PRJQUOTA = 2,
57};
58
59typedef __kernel_uid32_t qid_t;
60typedef long long qsize_t;
61
62struct kqid {
63 union {
64 kuid_t uid;
65 kgid_t gid;
66 kprojid_t projid;
67 };
68 enum quota_type type;
69};
70
71extern bool qid_eq(struct kqid left, struct kqid right);
72extern bool qid_lt(struct kqid left, struct kqid right);
73extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
74extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
75extern bool qid_valid(struct kqid qid);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91static inline struct kqid make_kqid(struct user_namespace *from,
92 enum quota_type type, qid_t qid)
93{
94 struct kqid kqid;
95
96 kqid.type = type;
97 switch (type) {
98 case USRQUOTA:
99 kqid.uid = make_kuid(from, qid);
100 break;
101 case GRPQUOTA:
102 kqid.gid = make_kgid(from, qid);
103 break;
104 case PRJQUOTA:
105 kqid.projid = make_kprojid(from, qid);
106 break;
107 default:
108 BUG();
109 }
110 return kqid;
111}
112
113
114
115
116
117
118
119static inline struct kqid make_kqid_invalid(enum quota_type type)
120{
121 struct kqid kqid;
122
123 kqid.type = type;
124 switch (type) {
125 case USRQUOTA:
126 kqid.uid = INVALID_UID;
127 break;
128 case GRPQUOTA:
129 kqid.gid = INVALID_GID;
130 break;
131 case PRJQUOTA:
132 kqid.projid = INVALID_PROJID;
133 break;
134 default:
135 BUG();
136 }
137 return kqid;
138}
139
140
141
142
143
144static inline struct kqid make_kqid_uid(kuid_t uid)
145{
146 struct kqid kqid;
147 kqid.type = USRQUOTA;
148 kqid.uid = uid;
149 return kqid;
150}
151
152
153
154
155
156static inline struct kqid make_kqid_gid(kgid_t gid)
157{
158 struct kqid kqid;
159 kqid.type = GRPQUOTA;
160 kqid.gid = gid;
161 return kqid;
162}
163
164
165
166
167
168static inline struct kqid make_kqid_projid(kprojid_t projid)
169{
170 struct kqid kqid;
171 kqid.type = PRJQUOTA;
172 kqid.projid = projid;
173 return kqid;
174}
175
176
177extern spinlock_t dq_data_lock;
178
179
180
181#define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
182#define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
183#define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
184#define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
185
186
187
188
189struct mem_dqblk {
190 qsize_t dqb_bhardlimit;
191 qsize_t dqb_bsoftlimit;
192 qsize_t dqb_curspace;
193 qsize_t dqb_rsvspace;
194 qsize_t dqb_ihardlimit;
195 qsize_t dqb_isoftlimit;
196 qsize_t dqb_curinodes;
197 time_t dqb_btime;
198 time_t dqb_itime;
199};
200
201
202
203
204struct quota_format_type;
205
206struct mem_dqinfo {
207 struct quota_format_type *dqi_format;
208 int dqi_fmt_id;
209
210 struct list_head dqi_dirty_list;
211 unsigned long dqi_flags;
212 unsigned int dqi_bgrace;
213 unsigned int dqi_igrace;
214 qsize_t dqi_maxblimit;
215 qsize_t dqi_maxilimit;
216 void *dqi_priv;
217};
218
219struct super_block;
220
221#define DQF_MASK 0xffff
222#define DQF_GETINFO_MASK 0x1ffff
223#define DQF_SETINFO_MASK 0xffff
224#define DQF_SYS_FILE_B 16
225#define DQF_SYS_FILE (1 << DQF_SYS_FILE_B)
226#define DQF_INFO_DIRTY_B 31
227#define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B)
228
229extern void mark_info_dirty(struct super_block *sb, int type);
230static inline int info_dirty(struct mem_dqinfo *info)
231{
232 return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
233}
234
235enum {
236 DQST_LOOKUPS,
237 DQST_DROPS,
238 DQST_READS,
239 DQST_WRITES,
240 DQST_CACHE_HITS,
241 DQST_ALLOC_DQUOTS,
242 DQST_FREE_DQUOTS,
243 DQST_SYNCS,
244 _DQST_DQSTAT_LAST
245};
246
247struct dqstats {
248 int stat[_DQST_DQSTAT_LAST];
249 struct percpu_counter counter[_DQST_DQSTAT_LAST];
250};
251
252extern struct dqstats *dqstats_pcpu;
253extern struct dqstats dqstats;
254
255static inline void dqstats_inc(unsigned int type)
256{
257 percpu_counter_inc(&dqstats.counter[type]);
258}
259
260static inline void dqstats_dec(unsigned int type)
261{
262 percpu_counter_dec(&dqstats.counter[type]);
263}
264
265#define DQ_MOD_B 0
266#define DQ_BLKS_B 1
267#define DQ_INODES_B 2
268#define DQ_FAKE_B 3
269#define DQ_READ_B 4
270#define DQ_ACTIVE_B 5
271#define DQ_LASTSET_B 6
272
273
274
275
276
277struct dquot {
278 struct hlist_node dq_hash;
279 struct list_head dq_inuse;
280 struct list_head dq_free;
281 struct list_head dq_dirty;
282 struct mutex dq_lock;
283 atomic_t dq_count;
284 wait_queue_head_t dq_wait_unused;
285 struct super_block *dq_sb;
286 struct kqid dq_id;
287 loff_t dq_off;
288 unsigned long dq_flags;
289 struct mem_dqblk dq_dqb;
290};
291
292
293struct quota_format_ops {
294 int (*check_quota_file)(struct super_block *sb, int type);
295 int (*read_file_info)(struct super_block *sb, int type);
296 int (*write_file_info)(struct super_block *sb, int type);
297 int (*free_file_info)(struct super_block *sb, int type);
298 int (*read_dqblk)(struct dquot *dquot);
299 int (*commit_dqblk)(struct dquot *dquot);
300 int (*release_dqblk)(struct dquot *dquot);
301};
302
303
304struct dquot_operations {
305 int (*write_dquot) (struct dquot *);
306 struct dquot *(*alloc_dquot)(struct super_block *, int);
307 void (*destroy_dquot)(struct dquot *);
308 int (*acquire_dquot) (struct dquot *);
309 int (*release_dquot) (struct dquot *);
310 int (*mark_dirty) (struct dquot *);
311 int (*write_info) (struct super_block *, int);
312
313
314 qsize_t *(*get_reserved_space) (struct inode *);
315};
316
317struct path;
318
319
320struct quotactl_ops {
321 int (*quota_on)(struct super_block *, int, int, struct path *);
322 int (*quota_on_meta)(struct super_block *, int, int);
323 int (*quota_off)(struct super_block *, int);
324 int (*quota_sync)(struct super_block *, int);
325 int (*get_info)(struct super_block *, int, struct if_dqinfo *);
326 int (*set_info)(struct super_block *, int, struct if_dqinfo *);
327 int (*get_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *);
328 int (*set_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *);
329 int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
330 int (*set_xstate)(struct super_block *, unsigned int, int);
331 int (*get_xstatev)(struct super_block *, struct fs_quota_statv *);
332};
333
334struct quota_format_type {
335 int qf_fmt_id;
336 const struct quota_format_ops *qf_ops;
337 struct module *qf_owner;
338 struct quota_format_type *qf_next;
339};
340
341
342enum {
343 _DQUOT_USAGE_ENABLED = 0,
344 _DQUOT_LIMITS_ENABLED,
345 _DQUOT_SUSPENDED,
346
347
348 _DQUOT_STATE_FLAGS
349};
350#define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED)
351#define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED)
352#define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED)
353#define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
354 DQUOT_SUSPENDED)
355
356#define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
357#define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
358
359
360
361
362
363
364#define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
365
366
367static inline unsigned int dquot_state_flag(unsigned int flags, int type)
368{
369 return flags << _DQUOT_STATE_FLAGS * type;
370}
371
372static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
373{
374 return (flags >> _DQUOT_STATE_FLAGS * type) & DQUOT_STATE_FLAGS;
375}
376
377#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
378extern void quota_send_warning(struct kqid qid, dev_t dev,
379 const char warntype);
380#else
381static inline void quota_send_warning(struct kqid qid, dev_t dev,
382 const char warntype)
383{
384 return;
385}
386#endif
387
388struct quota_info {
389 unsigned int flags;
390 struct mutex dqio_mutex;
391 struct mutex dqonoff_mutex;
392 struct rw_semaphore dqptr_sem;
393 struct inode *files[MAXQUOTAS];
394 struct mem_dqinfo info[MAXQUOTAS];
395 const struct quota_format_ops *ops[MAXQUOTAS];
396};
397
398int register_quota_format(struct quota_format_type *fmt);
399void unregister_quota_format(struct quota_format_type *fmt);
400
401struct quota_module_name {
402 int qm_fmt_id;
403 char *qm_mod_name;
404};
405
406#define INIT_QUOTA_MODULE_NAMES {\
407 {QFMT_VFS_OLD, "quota_v1"},\
408 {QFMT_VFS_V0, "quota_v2"},\
409 {QFMT_VFS_V1, "quota_v2"},\
410 {0, NULL}}
411
412#endif
413