blob: a3374dc3a91bf6149aa12968360ba624b0fcbbd1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 1982, 1986 Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#ifndef _LINUX_QUOTA_
33#define _LINUX_QUOTA_
34
Matthew Wilcox8b91de22008-02-26 09:53:20 -050035#include <linux/list.h>
David Woodhouse0409d3a2006-04-25 14:52:13 +010036#include <linux/mutex.h>
Matthew Wilcox8b91de22008-02-26 09:53:20 -050037#include <linux/rwsem.h>
38#include <linux/spinlock.h>
39#include <linux/wait.h>
Dmitry Monakhovf32764b2010-05-26 23:21:58 +020040#include <linux/percpu_counter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include <linux/dqblk_xfs.h>
43#include <linux/dqblk_v1.h>
44#include <linux/dqblk_v2.h>
45
Arun Sharma600634972011-07-26 16:09:06 -070046#include <linux/atomic.h>
Eric W. Biedermane8a3e472012-09-16 01:11:45 -070047#include <linux/uidgid.h>
48#include <linux/projid.h>
David Howells607ca462012-10-13 10:46:48 +010049#include <uapi/linux/quota.h>
Eric W. Biedermane8a3e472012-09-16 01:11:45 -070050
51#undef USRQUOTA
52#undef GRPQUOTA
53enum quota_type {
54 USRQUOTA = 0, /* element used for user quotas */
55 GRPQUOTA = 1, /* element used for group quotas */
56 PRJQUOTA = 2, /* element used for project quotas */
57};
Matthew Wilcox8b91de22008-02-26 09:53:20 -050058
Jan Kara2c5f6482014-09-30 10:43:09 +020059/* Masks for quota types when used as a bitmask */
60#define QTYPE_MASK_USR (1 << USRQUOTA)
61#define QTYPE_MASK_GRP (1 << GRPQUOTA)
62#define QTYPE_MASK_PRJ (1 << PRJQUOTA)
63
Jan Kara74abb982008-07-25 01:46:51 -070064typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
Jan Karadb49d2d2008-10-01 18:21:39 +020065typedef long long qsize_t; /* Type in which we store sizes */
Jan Kara74abb982008-07-25 01:46:51 -070066
Eric W. Biedermane8a3e472012-09-16 01:11:45 -070067struct kqid { /* Type in which we store the quota identifier */
68 union {
69 kuid_t uid;
70 kgid_t gid;
71 kprojid_t projid;
72 };
73 enum quota_type type; /* USRQUOTA (uid) or GRPQUOTA (gid) or PRJQUOTA (projid) */
74};
75
76extern bool qid_eq(struct kqid left, struct kqid right);
77extern bool qid_lt(struct kqid left, struct kqid right);
78extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80extern bool qid_valid(struct kqid qid);
81
82/**
83 * make_kqid - Map a user-namespace, type, qid tuple into a kqid.
84 * @from: User namespace that the qid is in
85 * @type: The type of quota
86 * @qid: Quota identifier
87 *
88 * Maps a user-namespace, type qid tuple into a kernel internal
89 * kqid, and returns that kqid.
90 *
91 * When there is no mapping defined for the user-namespace, type,
92 * qid tuple an invalid kqid is returned. Callers are expected to
93 * test for and handle handle invalid kqids being returned.
94 * Invalid kqids may be tested for using qid_valid().
95 */
96static inline struct kqid make_kqid(struct user_namespace *from,
97 enum quota_type type, qid_t qid)
98{
99 struct kqid kqid;
100
101 kqid.type = type;
102 switch (type) {
103 case USRQUOTA:
104 kqid.uid = make_kuid(from, qid);
105 break;
106 case GRPQUOTA:
107 kqid.gid = make_kgid(from, qid);
108 break;
109 case PRJQUOTA:
110 kqid.projid = make_kprojid(from, qid);
111 break;
112 default:
113 BUG();
114 }
115 return kqid;
116}
117
118/**
119 * make_kqid_invalid - Explicitly make an invalid kqid
120 * @type: The type of quota identifier
121 *
122 * Returns an invalid kqid with the specified type.
123 */
124static inline struct kqid make_kqid_invalid(enum quota_type type)
125{
126 struct kqid kqid;
127
128 kqid.type = type;
129 switch (type) {
130 case USRQUOTA:
131 kqid.uid = INVALID_UID;
132 break;
133 case GRPQUOTA:
134 kqid.gid = INVALID_GID;
135 break;
136 case PRJQUOTA:
137 kqid.projid = INVALID_PROJID;
138 break;
139 default:
140 BUG();
141 }
142 return kqid;
143}
144
145/**
146 * make_kqid_uid - Make a kqid from a kuid
147 * @uid: The kuid to make the quota identifier from
148 */
149static inline struct kqid make_kqid_uid(kuid_t uid)
150{
151 struct kqid kqid;
152 kqid.type = USRQUOTA;
153 kqid.uid = uid;
154 return kqid;
155}
156
157/**
158 * make_kqid_gid - Make a kqid from a kgid
159 * @gid: The kgid to make the quota identifier from
160 */
161static inline struct kqid make_kqid_gid(kgid_t gid)
162{
163 struct kqid kqid;
164 kqid.type = GRPQUOTA;
165 kqid.gid = gid;
166 return kqid;
167}
168
169/**
170 * make_kqid_projid - Make a kqid from a projid
171 * @projid: The kprojid to make the quota identifier from
172 */
173static inline struct kqid make_kqid_projid(kprojid_t projid)
174{
175 struct kqid kqid;
176 kqid.type = PRJQUOTA;
177 kqid.projid = projid;
178 return kqid;
179}
180
181
Mike Frysingeracd64b72007-05-08 00:31:51 -0700182extern spinlock_t dq_data_lock;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* Maximal numbers of writes for quota operation (insert/delete/update)
Jan Kara4e5117b2005-06-23 22:01:03 -0700185 * (over VFS all formats) */
186#define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
187#define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
188#define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
189#define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191/*
192 * Data for one user/group kept in memory
193 */
194struct mem_dqblk {
Jan Kara12095462008-08-20 14:45:12 +0200195 qsize_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
196 qsize_t dqb_bsoftlimit; /* preferred limit on disk blks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 qsize_t dqb_curspace; /* current used space */
Mingming Caof18df222009-01-13 16:43:09 +0100198 qsize_t dqb_rsvspace; /* current reserved space for delalloc*/
Jan Kara12095462008-08-20 14:45:12 +0200199 qsize_t dqb_ihardlimit; /* absolute limit on allocated inodes */
200 qsize_t dqb_isoftlimit; /* preferred inode limit */
201 qsize_t dqb_curinodes; /* current # allocated inodes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 time_t dqb_btime; /* time limit for excessive disk use */
203 time_t dqb_itime; /* time limit for excessive inode use */
204};
205
206/*
207 * Data for one quotafile kept in memory
208 */
209struct quota_format_type;
210
211struct mem_dqinfo {
212 struct quota_format_type *dqi_format;
Jan Kara0ff5af82008-04-28 02:14:33 -0700213 int dqi_fmt_id; /* Id of the dqi_format - used when turning
214 * quotas on after remount RW */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 struct list_head dqi_dirty_list; /* List of dirty dquots */
216 unsigned long dqi_flags;
217 unsigned int dqi_bgrace;
218 unsigned int dqi_igrace;
Jan Karab10a0812014-10-09 16:54:13 +0200219 qsize_t dqi_max_spc_limit;
220 qsize_t dqi_max_ino_limit;
Jan Karae3d4d562008-10-02 18:44:14 +0200221 void *dqi_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222};
223
224struct super_block;
225
Jan Kara9c451012014-11-19 09:21:58 +0100226/* Mask for flags passed to userspace */
227#define DQF_GETINFO_MASK (DQF_ROOT_SQUASH | DQF_SYS_FILE)
228/* Mask for flags modifiable from userspace */
229#define DQF_SETINFO_MASK DQF_ROOT_SQUASH
230
231enum {
232 DQF_INFO_DIRTY_B = DQF_PRIVATE,
233};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B) /* Is info dirty? */
235
236extern void mark_info_dirty(struct super_block *sb, int type);
Jan Kara03b06342008-07-25 01:46:52 -0700237static inline int info_dirty(struct mem_dqinfo *info)
238{
239 return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
240}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Dmitry Monakhovdde95882010-04-26 20:03:33 +0400242enum {
243 DQST_LOOKUPS,
244 DQST_DROPS,
245 DQST_READS,
246 DQST_WRITES,
247 DQST_CACHE_HITS,
248 DQST_ALLOC_DQUOTS,
249 DQST_FREE_DQUOTS,
250 DQST_SYNCS,
251 _DQST_DQSTAT_LAST
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
Dmitry Monakhovdde95882010-04-26 20:03:33 +0400254struct dqstats {
255 int stat[_DQST_DQSTAT_LAST];
Dmitry Monakhovf32764b2010-05-26 23:21:58 +0200256 struct percpu_counter counter[_DQST_DQSTAT_LAST];
Dmitry Monakhovdde95882010-04-26 20:03:33 +0400257};
258
259extern struct dqstats *dqstats_pcpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260extern struct dqstats dqstats;
261
Dmitry Monakhovdde95882010-04-26 20:03:33 +0400262static inline void dqstats_inc(unsigned int type)
263{
Dmitry Monakhovf32764b2010-05-26 23:21:58 +0200264 percpu_counter_inc(&dqstats.counter[type]);
Dmitry Monakhovdde95882010-04-26 20:03:33 +0400265}
266
267static inline void dqstats_dec(unsigned int type)
268{
Dmitry Monakhovf32764b2010-05-26 23:21:58 +0200269 percpu_counter_dec(&dqstats.counter[type]);
Dmitry Monakhovdde95882010-04-26 20:03:33 +0400270}
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#define DQ_MOD_B 0 /* dquot modified since read */
273#define DQ_BLKS_B 1 /* uid/gid has been warned about blk limit */
274#define DQ_INODES_B 2 /* uid/gid has been warned about inode limit */
275#define DQ_FAKE_B 3 /* no limits only usage */
276#define DQ_READ_B 4 /* dquot was read into memory */
277#define DQ_ACTIVE_B 5 /* dquot is active (dquot_release not called) */
Jan Kara4d59bce2008-10-02 16:48:10 +0200278#define DQ_LASTSET_B 6 /* Following 6 bits (see QIF_) are reserved\
279 * for the mask of entries set via SETQUOTA\
280 * quotactl. They are set under dq_data_lock\
281 * and the quota format handling dquot can\
282 * clear them when it sees fit. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284struct dquot {
285 struct hlist_node dq_hash; /* Hash list in memory */
286 struct list_head dq_inuse; /* List of all quotas */
287 struct list_head dq_free; /* Free list element */
288 struct list_head dq_dirty; /* List of dirty dquots */
Ingo Molnard3be9152006-03-23 03:00:29 -0800289 struct mutex dq_lock; /* dquot IO lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 atomic_t dq_count; /* Use count */
291 wait_queue_head_t dq_wait_unused; /* Wait queue for dquot to become unused */
292 struct super_block *dq_sb; /* superblock this applies to */
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700293 struct kqid dq_id; /* ID this applies to (uid, gid, projid) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 loff_t dq_off; /* Offset of dquot on disk */
295 unsigned long dq_flags; /* See DQ_* */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 struct mem_dqblk dq_dqb; /* Diskquota usage */
297};
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299/* Operations which must be implemented by each quota format */
300struct quota_format_ops {
301 int (*check_quota_file)(struct super_block *sb, int type); /* Detect whether file is in our format */
302 int (*read_file_info)(struct super_block *sb, int type); /* Read main info about file - called on quotaon() */
303 int (*write_file_info)(struct super_block *sb, int type); /* Write main info about file */
304 int (*free_file_info)(struct super_block *sb, int type); /* Called on quotaoff() */
305 int (*read_dqblk)(struct dquot *dquot); /* Read structure for one user */
306 int (*commit_dqblk)(struct dquot *dquot); /* Write structure for one user */
307 int (*release_dqblk)(struct dquot *dquot); /* Called when last reference to dquot is being dropped */
308};
309
310/* Operations working with dquots */
311struct dquot_operations {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 int (*write_dquot) (struct dquot *); /* Ordinary dquot write */
Jan Kara74f783a2008-08-19 14:51:22 +0200313 struct dquot *(*alloc_dquot)(struct super_block *, int); /* Allocate memory for new dquot */
314 void (*destroy_dquot)(struct dquot *); /* Free memory for dquot */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 int (*acquire_dquot) (struct dquot *); /* Quota is going to be created on disk */
316 int (*release_dquot) (struct dquot *); /* Quota is going to be deleted from disk */
317 int (*mark_dirty) (struct dquot *); /* Dquot is marked dirty */
318 int (*write_info) (struct super_block *, int); /* Write of quota "superblock" */
Dmitry Monakhovfd8fbfc2009-12-14 15:21:13 +0300319 /* get reserved quota for delayed alloc, value returned is managed by
320 * quota code only */
321 qsize_t *(*get_reserved_space) (struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322};
323
Jan Karaf00c9e42010-09-15 17:38:58 +0200324struct path;
325
Jan Kara14bf61f2014-10-09 16:03:13 +0200326/* Structure for communicating via ->get_dqblk() & ->set_dqblk() */
327struct qc_dqblk {
328 int d_fieldmask; /* mask of fields to change in ->set_dqblk() */
329 u64 d_spc_hardlimit; /* absolute limit on used space */
330 u64 d_spc_softlimit; /* preferred limit on used space */
331 u64 d_ino_hardlimit; /* maximum # allocated inodes */
332 u64 d_ino_softlimit; /* preferred inode limit */
333 u64 d_space; /* Space owned by the user */
334 u64 d_ino_count; /* # inodes owned by the user */
335 s64 d_ino_timer; /* zero if within inode limits */
336 /* if not, we refuse service */
337 s64 d_spc_timer; /* similar to above; for space */
338 int d_ino_warns; /* # warnings issued wrt num inodes */
339 int d_spc_warns; /* # warnings issued wrt used space */
340 u64 d_rt_spc_hardlimit; /* absolute limit on realtime space */
341 u64 d_rt_spc_softlimit; /* preferred limit on RT space */
342 u64 d_rt_space; /* realtime space owned */
343 s64 d_rt_spc_timer; /* similar to above; for RT space */
344 int d_rt_spc_warns; /* # warnings issued wrt RT space */
345};
346
347/* Field specifiers for ->set_dqblk() in struct qc_dqblk */
348#define QC_INO_SOFT (1<<0)
349#define QC_INO_HARD (1<<1)
350#define QC_SPC_SOFT (1<<2)
351#define QC_SPC_HARD (1<<3)
352#define QC_RT_SPC_SOFT (1<<4)
353#define QC_RT_SPC_HARD (1<<5)
354#define QC_LIMIT_MASK (QC_INO_SOFT | QC_INO_HARD | QC_SPC_SOFT | QC_SPC_HARD | \
355 QC_RT_SPC_SOFT | QC_RT_SPC_HARD)
356#define QC_SPC_TIMER (1<<6)
357#define QC_INO_TIMER (1<<7)
358#define QC_RT_SPC_TIMER (1<<8)
359#define QC_TIMER_MASK (QC_SPC_TIMER | QC_INO_TIMER | QC_RT_SPC_TIMER)
360#define QC_SPC_WARNS (1<<9)
361#define QC_INO_WARNS (1<<10)
362#define QC_RT_SPC_WARNS (1<<11)
363#define QC_WARNS_MASK (QC_SPC_WARNS | QC_INO_WARNS | QC_RT_SPC_WARNS)
364#define QC_SPACE (1<<12)
365#define QC_INO_COUNT (1<<13)
366#define QC_RT_SPACE (1<<14)
367#define QC_ACCT_MASK (QC_SPACE | QC_INO_COUNT | QC_RT_SPACE)
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369/* Operations handling requests from userspace */
370struct quotactl_ops {
Jan Karaf00c9e42010-09-15 17:38:58 +0200371 int (*quota_on)(struct super_block *, int, int, struct path *);
Christoph Hellwig307ae182010-05-19 07:16:43 -0400372 int (*quota_off)(struct super_block *, int);
Jan Kara38e478c2014-10-08 15:56:21 +0200373 int (*quota_enable)(struct super_block *, unsigned int);
374 int (*quota_disable)(struct super_block *, unsigned int);
Jan Karaceed1722012-07-03 16:45:28 +0200375 int (*quota_sync)(struct super_block *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 int (*get_info)(struct super_block *, int, struct if_dqinfo *);
377 int (*set_info)(struct super_block *, int, struct if_dqinfo *);
Jan Kara14bf61f2014-10-09 16:03:13 +0200378 int (*get_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
379 int (*set_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
Chandra Seetharamanaf30cb42013-08-06 17:27:07 -0500381 int (*get_xstatev)(struct super_block *, struct fs_quota_statv *);
Eric Sandeen9da93f92014-05-05 17:25:50 +1000382 int (*rm_xquota)(struct super_block *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383};
384
385struct quota_format_type {
386 int qf_fmt_id; /* Quota format id */
Alexey Dobriyan1472da52009-10-16 15:26:03 +0400387 const struct quota_format_ops *qf_ops; /* Operations of format */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 struct module *qf_owner; /* Module implementing quota format */
389 struct quota_format_type *qf_next;
390};
391
Konstantin Khlebnikov78197022015-02-12 19:08:16 +0300392/**
393 * Quota state flags - they actually come in two flavors - for users and groups.
394 *
395 * Actual typed flags layout:
396 * USRQUOTA GRPQUOTA
397 * DQUOT_USAGE_ENABLED 0x0001 0x0002
398 * DQUOT_LIMITS_ENABLED 0x0004 0x0008
399 * DQUOT_SUSPENDED 0x0010 0x0020
400 *
401 * Following bits are used for non-typed flags:
402 * DQUOT_QUOTA_SYS_FILE 0x0040
403 * DQUOT_NEGATIVE_USAGE 0x0080
404 */
Jan Karaf55abc02008-08-20 17:50:32 +0200405enum {
406 _DQUOT_USAGE_ENABLED = 0, /* Track disk usage for users */
407 _DQUOT_LIMITS_ENABLED, /* Enforce quota limits for users */
408 _DQUOT_SUSPENDED, /* User diskquotas are off, but
Jan Kara0ff5af82008-04-28 02:14:33 -0700409 * we have necessary info in
410 * memory to turn them on */
Jan Karaf55abc02008-08-20 17:50:32 +0200411 _DQUOT_STATE_FLAGS
412};
Konstantin Khlebnikov78197022015-02-12 19:08:16 +0300413#define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED * MAXQUOTAS)
414#define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED * MAXQUOTAS)
415#define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED * MAXQUOTAS)
Jan Karaf55abc02008-08-20 17:50:32 +0200416#define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
417 DQUOT_SUSPENDED)
Jan Karaca785ec2008-09-30 17:53:37 +0200418/* Other quota flags */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300419#define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS)
420#define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST)
421 /* Quota file is a special
Jan Karaca785ec2008-09-30 17:53:37 +0200422 * system file and user cannot
423 * touch it. Filesystem is
424 * responsible for setting
425 * S_NOQUOTA, S_NOATIME flags
426 */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300427#define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1))
428 /* Allow negative quota usage */
Jan Karaf55abc02008-08-20 17:50:32 +0200429static inline unsigned int dquot_state_flag(unsigned int flags, int type)
430{
Konstantin Khlebnikov78197022015-02-12 19:08:16 +0300431 return flags << type;
Jan Karaf55abc02008-08-20 17:50:32 +0200432}
433
434static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
435{
Konstantin Khlebnikov78197022015-02-12 19:08:16 +0300436 return (flags >> type) & DQUOT_STATE_FLAGS;
437}
438
439/* Bitmap of quota types where flag is set in flags */
440static __always_inline unsigned dquot_state_types(unsigned flags, unsigned flag)
441{
442 BUILD_BUG_ON_NOT_POWER_OF_2(flag);
443 return (flags / flag) & ((1 << MAXQUOTAS) - 1);
Jan Karaf55abc02008-08-20 17:50:32 +0200444}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Steven Whitehouse86e931a2009-09-28 12:35:17 +0100446#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
Eric W. Biederman431f1972012-09-16 02:32:43 -0700447extern void quota_send_warning(struct kqid qid, dev_t dev,
Steven Whitehouse86e931a2009-09-28 12:35:17 +0100448 const char warntype);
449#else
Eric W. Biederman431f1972012-09-16 02:32:43 -0700450static inline void quota_send_warning(struct kqid qid, dev_t dev,
Steven Whitehouse86e931a2009-09-28 12:35:17 +0100451 const char warntype)
452{
453 return;
454}
455#endif /* CONFIG_QUOTA_NETLINK_INTERFACE */
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457struct quota_info {
458 unsigned int flags; /* Flags for diskquotas on this device */
Ingo Molnard3be9152006-03-23 03:00:29 -0800459 struct mutex dqio_mutex; /* lock device while I/O in progress */
460 struct mutex dqonoff_mutex; /* Serialize quotaon & quotaoff */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
Alexey Dobriyan1472da52009-10-16 15:26:03 +0400463 const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464};
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466int register_quota_format(struct quota_format_type *fmt);
467void unregister_quota_format(struct quota_format_type *fmt);
468
469struct quota_module_name {
470 int qm_fmt_id;
471 char *qm_mod_name;
472};
473
474#define INIT_QUOTA_MODULE_NAMES {\
475 {QFMT_VFS_OLD, "quota_v1"},\
476 {QFMT_VFS_V0, "quota_v2"},\
Theodore Ts'oc3ad83d2013-01-24 23:24:56 -0500477 {QFMT_VFS_V1, "quota_v2"},\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 {0, NULL}}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#endif /* _QUOTA_ */