This source file includes following definitions.
- make_kqid
- make_kqid_invalid
- make_kqid_uid
- make_kqid_gid
- make_kqid_projid
- qid_has_mapping
- info_dirty
- dqstats_inc
- dqstats_dec
- dquot_state_flag
- dquot_generic_flag
- dquot_state_types
- quota_send_warning
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
53 #undef PRJQUOTA
54 enum quota_type {
55 USRQUOTA = 0,
56 GRPQUOTA = 1,
57 PRJQUOTA = 2,
58 };
59
60
61 #define QTYPE_MASK_USR (1 << USRQUOTA)
62 #define QTYPE_MASK_GRP (1 << GRPQUOTA)
63 #define QTYPE_MASK_PRJ (1 << PRJQUOTA)
64
65 typedef __kernel_uid32_t qid_t;
66 typedef long long qsize_t;
67
68 struct kqid {
69 union {
70 kuid_t uid;
71 kgid_t gid;
72 kprojid_t projid;
73 };
74 enum quota_type type;
75 };
76
77 extern bool qid_eq(struct kqid left, struct kqid right);
78 extern bool qid_lt(struct kqid left, struct kqid right);
79 extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81 extern bool qid_valid(struct kqid qid);
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 static inline struct kqid make_kqid(struct user_namespace *from,
98 enum quota_type type, qid_t qid)
99 {
100 struct kqid kqid;
101
102 kqid.type = type;
103 switch (type) {
104 case USRQUOTA:
105 kqid.uid = make_kuid(from, qid);
106 break;
107 case GRPQUOTA:
108 kqid.gid = make_kgid(from, qid);
109 break;
110 case PRJQUOTA:
111 kqid.projid = make_kprojid(from, qid);
112 break;
113 default:
114 BUG();
115 }
116 return kqid;
117 }
118
119
120
121
122
123
124
125 static inline struct kqid make_kqid_invalid(enum quota_type type)
126 {
127 struct kqid kqid;
128
129 kqid.type = type;
130 switch (type) {
131 case USRQUOTA:
132 kqid.uid = INVALID_UID;
133 break;
134 case GRPQUOTA:
135 kqid.gid = INVALID_GID;
136 break;
137 case PRJQUOTA:
138 kqid.projid = INVALID_PROJID;
139 break;
140 default:
141 BUG();
142 }
143 return kqid;
144 }
145
146
147
148
149
150 static inline struct kqid make_kqid_uid(kuid_t uid)
151 {
152 struct kqid kqid;
153 kqid.type = USRQUOTA;
154 kqid.uid = uid;
155 return kqid;
156 }
157
158
159
160
161
162 static inline struct kqid make_kqid_gid(kgid_t gid)
163 {
164 struct kqid kqid;
165 kqid.type = GRPQUOTA;
166 kqid.gid = gid;
167 return kqid;
168 }
169
170
171
172
173
174 static inline struct kqid make_kqid_projid(kprojid_t projid)
175 {
176 struct kqid kqid;
177 kqid.type = PRJQUOTA;
178 kqid.projid = projid;
179 return kqid;
180 }
181
182
183
184
185
186
187 static inline bool qid_has_mapping(struct user_namespace *ns, struct kqid qid)
188 {
189 return from_kqid(ns, qid) != (qid_t) -1;
190 }
191
192
193 extern spinlock_t dq_data_lock;
194
195
196
197 #define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
198 #define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
199 #define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
200 #define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
201
202
203
204
205 struct mem_dqblk {
206 qsize_t dqb_bhardlimit;
207 qsize_t dqb_bsoftlimit;
208 qsize_t dqb_curspace;
209 qsize_t dqb_rsvspace;
210 qsize_t dqb_ihardlimit;
211 qsize_t dqb_isoftlimit;
212 qsize_t dqb_curinodes;
213 time64_t dqb_btime;
214 time64_t dqb_itime;
215 };
216
217
218
219
220 struct quota_format_type;
221
222 struct mem_dqinfo {
223 struct quota_format_type *dqi_format;
224 int dqi_fmt_id;
225
226 struct list_head dqi_dirty_list;
227 unsigned long dqi_flags;
228 unsigned int dqi_bgrace;
229 unsigned int dqi_igrace;
230 qsize_t dqi_max_spc_limit;
231 qsize_t dqi_max_ino_limit;
232 void *dqi_priv;
233 };
234
235 struct super_block;
236
237
238 #define DQF_GETINFO_MASK (DQF_ROOT_SQUASH | DQF_SYS_FILE)
239
240 #define DQF_SETINFO_MASK DQF_ROOT_SQUASH
241
242 enum {
243 DQF_INFO_DIRTY_B = DQF_PRIVATE,
244 };
245 #define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B)
246
247 extern void mark_info_dirty(struct super_block *sb, int type);
248 static inline int info_dirty(struct mem_dqinfo *info)
249 {
250 return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
251 }
252
253 enum {
254 DQST_LOOKUPS,
255 DQST_DROPS,
256 DQST_READS,
257 DQST_WRITES,
258 DQST_CACHE_HITS,
259 DQST_ALLOC_DQUOTS,
260 DQST_FREE_DQUOTS,
261 DQST_SYNCS,
262 _DQST_DQSTAT_LAST
263 };
264
265 struct dqstats {
266 unsigned long stat[_DQST_DQSTAT_LAST];
267 struct percpu_counter counter[_DQST_DQSTAT_LAST];
268 };
269
270 extern struct dqstats dqstats;
271
272 static inline void dqstats_inc(unsigned int type)
273 {
274 percpu_counter_inc(&dqstats.counter[type]);
275 }
276
277 static inline void dqstats_dec(unsigned int type)
278 {
279 percpu_counter_dec(&dqstats.counter[type]);
280 }
281
282 #define DQ_MOD_B 0
283 #define DQ_BLKS_B 1
284 #define DQ_INODES_B 2
285 #define DQ_FAKE_B 3
286 #define DQ_READ_B 4
287 #define DQ_ACTIVE_B 5
288 #define DQ_LASTSET_B 6
289
290
291
292
293
294 struct dquot {
295 struct hlist_node dq_hash;
296 struct list_head dq_inuse;
297 struct list_head dq_free;
298 struct list_head dq_dirty;
299 struct mutex dq_lock;
300 spinlock_t dq_dqb_lock;
301 atomic_t dq_count;
302 struct super_block *dq_sb;
303 struct kqid dq_id;
304 loff_t dq_off;
305 unsigned long dq_flags;
306 struct mem_dqblk dq_dqb;
307 };
308
309
310 struct quota_format_ops {
311 int (*check_quota_file)(struct super_block *sb, int type);
312 int (*read_file_info)(struct super_block *sb, int type);
313 int (*write_file_info)(struct super_block *sb, int type);
314 int (*free_file_info)(struct super_block *sb, int type);
315 int (*read_dqblk)(struct dquot *dquot);
316 int (*commit_dqblk)(struct dquot *dquot);
317 int (*release_dqblk)(struct dquot *dquot);
318 int (*get_next_id)(struct super_block *sb, struct kqid *qid);
319 };
320
321
322 struct dquot_operations {
323 int (*write_dquot) (struct dquot *);
324 struct dquot *(*alloc_dquot)(struct super_block *, int);
325 void (*destroy_dquot)(struct dquot *);
326 int (*acquire_dquot) (struct dquot *);
327 int (*release_dquot) (struct dquot *);
328 int (*mark_dirty) (struct dquot *);
329 int (*write_info) (struct super_block *, int);
330
331
332 qsize_t *(*get_reserved_space) (struct inode *);
333 int (*get_projid) (struct inode *, kprojid_t *);
334
335 int (*get_inode_usage) (struct inode *, qsize_t *);
336
337 int (*get_next_id) (struct super_block *sb, struct kqid *qid);
338 };
339
340 struct path;
341
342
343 struct qc_dqblk {
344 int d_fieldmask;
345 u64 d_spc_hardlimit;
346 u64 d_spc_softlimit;
347 u64 d_ino_hardlimit;
348 u64 d_ino_softlimit;
349 u64 d_space;
350 u64 d_ino_count;
351 s64 d_ino_timer;
352
353 s64 d_spc_timer;
354 int d_ino_warns;
355 int d_spc_warns;
356 u64 d_rt_spc_hardlimit;
357 u64 d_rt_spc_softlimit;
358 u64 d_rt_space;
359 s64 d_rt_spc_timer;
360 int d_rt_spc_warns;
361 };
362
363
364
365
366
367 #define QC_INO_SOFT (1<<0)
368 #define QC_INO_HARD (1<<1)
369 #define QC_SPC_SOFT (1<<2)
370 #define QC_SPC_HARD (1<<3)
371 #define QC_RT_SPC_SOFT (1<<4)
372 #define QC_RT_SPC_HARD (1<<5)
373 #define QC_LIMIT_MASK (QC_INO_SOFT | QC_INO_HARD | QC_SPC_SOFT | QC_SPC_HARD | \
374 QC_RT_SPC_SOFT | QC_RT_SPC_HARD)
375 #define QC_SPC_TIMER (1<<6)
376 #define QC_INO_TIMER (1<<7)
377 #define QC_RT_SPC_TIMER (1<<8)
378 #define QC_TIMER_MASK (QC_SPC_TIMER | QC_INO_TIMER | QC_RT_SPC_TIMER)
379 #define QC_SPC_WARNS (1<<9)
380 #define QC_INO_WARNS (1<<10)
381 #define QC_RT_SPC_WARNS (1<<11)
382 #define QC_WARNS_MASK (QC_SPC_WARNS | QC_INO_WARNS | QC_RT_SPC_WARNS)
383 #define QC_SPACE (1<<12)
384 #define QC_INO_COUNT (1<<13)
385 #define QC_RT_SPACE (1<<14)
386 #define QC_ACCT_MASK (QC_SPACE | QC_INO_COUNT | QC_RT_SPACE)
387 #define QC_FLAGS (1<<15)
388
389 #define QCI_SYSFILE (1 << 0)
390 #define QCI_ROOT_SQUASH (1 << 1)
391 #define QCI_ACCT_ENABLED (1 << 2)
392 #define QCI_LIMITS_ENFORCED (1 << 3)
393
394
395 struct qc_type_state {
396 unsigned int flags;
397 unsigned int spc_timelimit;
398
399 unsigned int ino_timelimit;
400 unsigned int rt_spc_timelimit;
401 unsigned int spc_warnlimit;
402 unsigned int ino_warnlimit;
403 unsigned int rt_spc_warnlimit;
404 unsigned long long ino;
405 blkcnt_t blocks;
406 blkcnt_t nextents;
407 };
408
409 struct qc_state {
410 unsigned int s_incoredqs;
411 struct qc_type_state s_state[MAXQUOTAS];
412 };
413
414
415 struct qc_info {
416 int i_fieldmask;
417 unsigned int i_flags;
418 unsigned int i_spc_timelimit;
419
420 unsigned int i_ino_timelimit;
421 unsigned int i_rt_spc_timelimit;
422 unsigned int i_spc_warnlimit;
423 unsigned int i_ino_warnlimit;
424 unsigned int i_rt_spc_warnlimit;
425 };
426
427
428 struct quotactl_ops {
429 int (*quota_on)(struct super_block *, int, int, const struct path *);
430 int (*quota_off)(struct super_block *, int);
431 int (*quota_enable)(struct super_block *, unsigned int);
432 int (*quota_disable)(struct super_block *, unsigned int);
433 int (*quota_sync)(struct super_block *, int);
434 int (*set_info)(struct super_block *, int, struct qc_info *);
435 int (*get_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
436 int (*get_nextdqblk)(struct super_block *, struct kqid *,
437 struct qc_dqblk *);
438 int (*set_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
439 int (*get_state)(struct super_block *, struct qc_state *);
440 int (*rm_xquota)(struct super_block *, unsigned int);
441 };
442
443 struct quota_format_type {
444 int qf_fmt_id;
445 const struct quota_format_ops *qf_ops;
446 struct module *qf_owner;
447 struct quota_format_type *qf_next;
448 };
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463 enum {
464 _DQUOT_USAGE_ENABLED = 0,
465 _DQUOT_LIMITS_ENABLED,
466 _DQUOT_SUSPENDED,
467
468
469 _DQUOT_STATE_FLAGS
470 };
471 #define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED * MAXQUOTAS)
472 #define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED * MAXQUOTAS)
473 #define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED * MAXQUOTAS)
474 #define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
475 DQUOT_SUSPENDED)
476
477 #define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
478 #define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
479
480
481
482
483
484
485 #define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
486
487
488 #define DQUOT_NOLIST_DIRTY (1 << (DQUOT_STATE_LAST + 2))
489
490 static inline unsigned int dquot_state_flag(unsigned int flags, int type)
491 {
492 return flags << type;
493 }
494
495 static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
496 {
497 return (flags >> type) & DQUOT_STATE_FLAGS;
498 }
499
500
501 static __always_inline unsigned dquot_state_types(unsigned flags, unsigned flag)
502 {
503 BUILD_BUG_ON_NOT_POWER_OF_2(flag);
504 return (flags / flag) & ((1 << MAXQUOTAS) - 1);
505 }
506
507 #ifdef CONFIG_QUOTA_NETLINK_INTERFACE
508 extern void quota_send_warning(struct kqid qid, dev_t dev,
509 const char warntype);
510 #else
511 static inline void quota_send_warning(struct kqid qid, dev_t dev,
512 const char warntype)
513 {
514 return;
515 }
516 #endif
517
518 struct quota_info {
519 unsigned int flags;
520 struct rw_semaphore dqio_sem;
521 struct inode *files[MAXQUOTAS];
522 struct mem_dqinfo info[MAXQUOTAS];
523 const struct quota_format_ops *ops[MAXQUOTAS];
524 };
525
526 int register_quota_format(struct quota_format_type *fmt);
527 void unregister_quota_format(struct quota_format_type *fmt);
528
529 struct quota_module_name {
530 int qm_fmt_id;
531 char *qm_mod_name;
532 };
533
534 #define INIT_QUOTA_MODULE_NAMES {\
535 {QFMT_VFS_OLD, "quota_v1"},\
536 {QFMT_VFS_V0, "quota_v2"},\
537 {QFMT_VFS_V1, "quota_v2"},\
538 {0, NULL}}
539
540 #endif