Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #ifndef _LINUX_QUOTA_ |
| 33 | #define _LINUX_QUOTA_ |
| 34 | |
Matthew Wilcox | 8b91de2 | 2008-02-26 09:53:20 -0500 | [diff] [blame] | 35 | #include <linux/list.h> |
David Woodhouse | 0409d3a | 2006-04-25 14:52:13 +0100 | [diff] [blame] | 36 | #include <linux/mutex.h> |
Matthew Wilcox | 8b91de2 | 2008-02-26 09:53:20 -0500 | [diff] [blame] | 37 | #include <linux/rwsem.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/wait.h> |
Dmitry Monakhov | f32764b | 2010-05-26 23:21:58 +0200 | [diff] [blame] | 40 | #include <linux/percpu_counter.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #include <linux/dqblk_xfs.h> |
| 43 | #include <linux/dqblk_v1.h> |
| 44 | #include <linux/dqblk_v2.h> |
| 45 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 46 | #include <linux/atomic.h> |
Eric W. Biederman | e8a3e47 | 2012-09-16 01:11:45 -0700 | [diff] [blame] | 47 | #include <linux/uidgid.h> |
| 48 | #include <linux/projid.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 49 | #include <uapi/linux/quota.h> |
Eric W. Biederman | e8a3e47 | 2012-09-16 01:11:45 -0700 | [diff] [blame] | 50 | |
| 51 | #undef USRQUOTA |
| 52 | #undef GRPQUOTA |
| 53 | enum 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 Wilcox | 8b91de2 | 2008-02-26 09:53:20 -0500 | [diff] [blame] | 58 | |
Jan Kara | 2c5f648 | 2014-09-30 10:43:09 +0200 | [diff] [blame] | 59 | /* 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 Kara | 74abb98 | 2008-07-25 01:46:51 -0700 | [diff] [blame] | 64 | typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */ |
Jan Kara | db49d2d | 2008-10-01 18:21:39 +0200 | [diff] [blame] | 65 | typedef long long qsize_t; /* Type in which we store sizes */ |
Jan Kara | 74abb98 | 2008-07-25 01:46:51 -0700 | [diff] [blame] | 66 | |
Eric W. Biederman | e8a3e47 | 2012-09-16 01:11:45 -0700 | [diff] [blame] | 67 | struct 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 | |
| 76 | extern bool qid_eq(struct kqid left, struct kqid right); |
| 77 | extern bool qid_lt(struct kqid left, struct kqid right); |
| 78 | extern qid_t from_kqid(struct user_namespace *to, struct kqid qid); |
| 79 | extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid); |
| 80 | extern 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 | */ |
| 96 | static 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 | */ |
| 124 | static 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 | */ |
| 149 | static 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 | */ |
| 161 | static 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 | */ |
| 173 | static 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 Frysinger | acd64b7 | 2007-05-08 00:31:51 -0700 | [diff] [blame] | 182 | extern spinlock_t dq_data_lock; |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /* Maximal numbers of writes for quota operation (insert/delete/update) |
Jan Kara | 4e5117b | 2005-06-23 22:01:03 -0700 | [diff] [blame] | 185 | * (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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Data for one user/group kept in memory |
| 193 | */ |
| 194 | struct mem_dqblk { |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 195 | qsize_t dqb_bhardlimit; /* absolute limit on disk blks alloc */ |
| 196 | qsize_t dqb_bsoftlimit; /* preferred limit on disk blks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | qsize_t dqb_curspace; /* current used space */ |
Mingming Cao | f18df22 | 2009-01-13 16:43:09 +0100 | [diff] [blame] | 198 | qsize_t dqb_rsvspace; /* current reserved space for delalloc*/ |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 199 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | 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 | */ |
| 209 | struct quota_format_type; |
| 210 | |
| 211 | struct mem_dqinfo { |
| 212 | struct quota_format_type *dqi_format; |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 213 | int dqi_fmt_id; /* Id of the dqi_format - used when turning |
| 214 | * quotas on after remount RW */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | 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; |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 219 | qsize_t dqi_maxblimit; |
| 220 | qsize_t dqi_maxilimit; |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 221 | void *dqi_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | struct super_block; |
| 225 | |
| 226 | #define DQF_MASK 0xffff /* Mask for format specific flags */ |
Jan Kara | 46fe44c | 2011-11-16 15:03:59 +0100 | [diff] [blame] | 227 | #define DQF_GETINFO_MASK 0x1ffff /* Mask for flags passed to userspace */ |
| 228 | #define DQF_SETINFO_MASK 0xffff /* Mask for flags modifiable from userspace */ |
| 229 | #define DQF_SYS_FILE_B 16 |
| 230 | #define DQF_SYS_FILE (1 << DQF_SYS_FILE_B) /* Quota file stored as system file */ |
| 231 | #define DQF_INFO_DIRTY_B 31 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | #define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B) /* Is info dirty? */ |
| 233 | |
| 234 | extern void mark_info_dirty(struct super_block *sb, int type); |
Jan Kara | 03b0634 | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 235 | static inline int info_dirty(struct mem_dqinfo *info) |
| 236 | { |
| 237 | return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags); |
| 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Dmitry Monakhov | dde9588 | 2010-04-26 20:03:33 +0400 | [diff] [blame] | 240 | enum { |
| 241 | DQST_LOOKUPS, |
| 242 | DQST_DROPS, |
| 243 | DQST_READS, |
| 244 | DQST_WRITES, |
| 245 | DQST_CACHE_HITS, |
| 246 | DQST_ALLOC_DQUOTS, |
| 247 | DQST_FREE_DQUOTS, |
| 248 | DQST_SYNCS, |
| 249 | _DQST_DQSTAT_LAST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
Dmitry Monakhov | dde9588 | 2010-04-26 20:03:33 +0400 | [diff] [blame] | 252 | struct dqstats { |
| 253 | int stat[_DQST_DQSTAT_LAST]; |
Dmitry Monakhov | f32764b | 2010-05-26 23:21:58 +0200 | [diff] [blame] | 254 | struct percpu_counter counter[_DQST_DQSTAT_LAST]; |
Dmitry Monakhov | dde9588 | 2010-04-26 20:03:33 +0400 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | extern struct dqstats *dqstats_pcpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | extern struct dqstats dqstats; |
| 259 | |
Dmitry Monakhov | dde9588 | 2010-04-26 20:03:33 +0400 | [diff] [blame] | 260 | static inline void dqstats_inc(unsigned int type) |
| 261 | { |
Dmitry Monakhov | f32764b | 2010-05-26 23:21:58 +0200 | [diff] [blame] | 262 | percpu_counter_inc(&dqstats.counter[type]); |
Dmitry Monakhov | dde9588 | 2010-04-26 20:03:33 +0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static inline void dqstats_dec(unsigned int type) |
| 266 | { |
Dmitry Monakhov | f32764b | 2010-05-26 23:21:58 +0200 | [diff] [blame] | 267 | percpu_counter_dec(&dqstats.counter[type]); |
Dmitry Monakhov | dde9588 | 2010-04-26 20:03:33 +0400 | [diff] [blame] | 268 | } |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | #define DQ_MOD_B 0 /* dquot modified since read */ |
| 271 | #define DQ_BLKS_B 1 /* uid/gid has been warned about blk limit */ |
| 272 | #define DQ_INODES_B 2 /* uid/gid has been warned about inode limit */ |
| 273 | #define DQ_FAKE_B 3 /* no limits only usage */ |
| 274 | #define DQ_READ_B 4 /* dquot was read into memory */ |
| 275 | #define DQ_ACTIVE_B 5 /* dquot is active (dquot_release not called) */ |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 276 | #define DQ_LASTSET_B 6 /* Following 6 bits (see QIF_) are reserved\ |
| 277 | * for the mask of entries set via SETQUOTA\ |
| 278 | * quotactl. They are set under dq_data_lock\ |
| 279 | * and the quota format handling dquot can\ |
| 280 | * clear them when it sees fit. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | struct dquot { |
| 283 | struct hlist_node dq_hash; /* Hash list in memory */ |
| 284 | struct list_head dq_inuse; /* List of all quotas */ |
| 285 | struct list_head dq_free; /* Free list element */ |
| 286 | struct list_head dq_dirty; /* List of dirty dquots */ |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 287 | struct mutex dq_lock; /* dquot IO lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | atomic_t dq_count; /* Use count */ |
| 289 | wait_queue_head_t dq_wait_unused; /* Wait queue for dquot to become unused */ |
| 290 | struct super_block *dq_sb; /* superblock this applies to */ |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 291 | struct kqid dq_id; /* ID this applies to (uid, gid, projid) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | loff_t dq_off; /* Offset of dquot on disk */ |
| 293 | unsigned long dq_flags; /* See DQ_* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | struct mem_dqblk dq_dqb; /* Diskquota usage */ |
| 295 | }; |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* Operations which must be implemented by each quota format */ |
| 298 | struct quota_format_ops { |
| 299 | int (*check_quota_file)(struct super_block *sb, int type); /* Detect whether file is in our format */ |
| 300 | int (*read_file_info)(struct super_block *sb, int type); /* Read main info about file - called on quotaon() */ |
| 301 | int (*write_file_info)(struct super_block *sb, int type); /* Write main info about file */ |
| 302 | int (*free_file_info)(struct super_block *sb, int type); /* Called on quotaoff() */ |
| 303 | int (*read_dqblk)(struct dquot *dquot); /* Read structure for one user */ |
| 304 | int (*commit_dqblk)(struct dquot *dquot); /* Write structure for one user */ |
| 305 | int (*release_dqblk)(struct dquot *dquot); /* Called when last reference to dquot is being dropped */ |
| 306 | }; |
| 307 | |
| 308 | /* Operations working with dquots */ |
| 309 | struct dquot_operations { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | int (*write_dquot) (struct dquot *); /* Ordinary dquot write */ |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 311 | struct dquot *(*alloc_dquot)(struct super_block *, int); /* Allocate memory for new dquot */ |
| 312 | void (*destroy_dquot)(struct dquot *); /* Free memory for dquot */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | int (*acquire_dquot) (struct dquot *); /* Quota is going to be created on disk */ |
| 314 | int (*release_dquot) (struct dquot *); /* Quota is going to be deleted from disk */ |
| 315 | int (*mark_dirty) (struct dquot *); /* Dquot is marked dirty */ |
| 316 | int (*write_info) (struct super_block *, int); /* Write of quota "superblock" */ |
Dmitry Monakhov | fd8fbfc | 2009-12-14 15:21:13 +0300 | [diff] [blame] | 317 | /* get reserved quota for delayed alloc, value returned is managed by |
| 318 | * quota code only */ |
| 319 | qsize_t *(*get_reserved_space) (struct inode *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 322 | struct path; |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* Operations handling requests from userspace */ |
| 325 | struct quotactl_ops { |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 326 | int (*quota_on)(struct super_block *, int, int, struct path *); |
| 327 | int (*quota_on_meta)(struct super_block *, int, int); |
Christoph Hellwig | 307ae18 | 2010-05-19 07:16:43 -0400 | [diff] [blame] | 328 | int (*quota_off)(struct super_block *, int); |
Jan Kara | ceed172 | 2012-07-03 16:45:28 +0200 | [diff] [blame] | 329 | int (*quota_sync)(struct super_block *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | int (*get_info)(struct super_block *, int, struct if_dqinfo *); |
| 331 | int (*set_info)(struct super_block *, int, struct if_dqinfo *); |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 332 | int (*get_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *); |
| 333 | int (*set_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | int (*get_xstate)(struct super_block *, struct fs_quota_stat *); |
| 335 | int (*set_xstate)(struct super_block *, unsigned int, int); |
Chandra Seetharaman | af30cb4 | 2013-08-06 17:27:07 -0500 | [diff] [blame] | 336 | int (*get_xstatev)(struct super_block *, struct fs_quota_statv *); |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 337 | int (*rm_xquota)(struct super_block *, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | struct quota_format_type { |
| 341 | int qf_fmt_id; /* Quota format id */ |
Alexey Dobriyan | 1472da5 | 2009-10-16 15:26:03 +0400 | [diff] [blame] | 342 | const struct quota_format_ops *qf_ops; /* Operations of format */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | struct module *qf_owner; /* Module implementing quota format */ |
| 344 | struct quota_format_type *qf_next; |
| 345 | }; |
| 346 | |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 347 | /* Quota state flags - they actually come in two flavors - for users and groups */ |
| 348 | enum { |
| 349 | _DQUOT_USAGE_ENABLED = 0, /* Track disk usage for users */ |
| 350 | _DQUOT_LIMITS_ENABLED, /* Enforce quota limits for users */ |
| 351 | _DQUOT_SUSPENDED, /* User diskquotas are off, but |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 352 | * we have necessary info in |
| 353 | * memory to turn them on */ |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 354 | _DQUOT_STATE_FLAGS |
| 355 | }; |
| 356 | #define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED) |
| 357 | #define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED) |
| 358 | #define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED) |
| 359 | #define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \ |
| 360 | DQUOT_SUSPENDED) |
Jan Kara | ca785ec | 2008-09-30 17:53:37 +0200 | [diff] [blame] | 361 | /* Other quota flags */ |
Dmitry Monakhov | ad1e6e8 | 2010-02-16 08:31:49 +0300 | [diff] [blame] | 362 | #define DQUOT_STATE_LAST (_DQUOT_STATE_FLAGS * MAXQUOTAS) |
| 363 | #define DQUOT_QUOTA_SYS_FILE (1 << DQUOT_STATE_LAST) |
| 364 | /* Quota file is a special |
Jan Kara | ca785ec | 2008-09-30 17:53:37 +0200 | [diff] [blame] | 365 | * system file and user cannot |
| 366 | * touch it. Filesystem is |
| 367 | * responsible for setting |
| 368 | * S_NOQUOTA, S_NOATIME flags |
| 369 | */ |
Dmitry Monakhov | ad1e6e8 | 2010-02-16 08:31:49 +0300 | [diff] [blame] | 370 | #define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1)) |
| 371 | /* Allow negative quota usage */ |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 372 | |
| 373 | static inline unsigned int dquot_state_flag(unsigned int flags, int type) |
| 374 | { |
Dmitry Monakhov | ad1e6e8 | 2010-02-16 08:31:49 +0300 | [diff] [blame] | 375 | return flags << _DQUOT_STATE_FLAGS * type; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static inline unsigned int dquot_generic_flag(unsigned int flags, int type) |
| 379 | { |
Dmitry Monakhov | ad1e6e8 | 2010-02-16 08:31:49 +0300 | [diff] [blame] | 380 | return (flags >> _DQUOT_STATE_FLAGS * type) & DQUOT_STATE_FLAGS; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Steven Whitehouse | 86e931a | 2009-09-28 12:35:17 +0100 | [diff] [blame] | 383 | #ifdef CONFIG_QUOTA_NETLINK_INTERFACE |
Eric W. Biederman | 431f197 | 2012-09-16 02:32:43 -0700 | [diff] [blame] | 384 | extern void quota_send_warning(struct kqid qid, dev_t dev, |
Steven Whitehouse | 86e931a | 2009-09-28 12:35:17 +0100 | [diff] [blame] | 385 | const char warntype); |
| 386 | #else |
Eric W. Biederman | 431f197 | 2012-09-16 02:32:43 -0700 | [diff] [blame] | 387 | static inline void quota_send_warning(struct kqid qid, dev_t dev, |
Steven Whitehouse | 86e931a | 2009-09-28 12:35:17 +0100 | [diff] [blame] | 388 | const char warntype) |
| 389 | { |
| 390 | return; |
| 391 | } |
| 392 | #endif /* CONFIG_QUOTA_NETLINK_INTERFACE */ |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | struct quota_info { |
| 395 | unsigned int flags; /* Flags for diskquotas on this device */ |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 396 | struct mutex dqio_mutex; /* lock device while I/O in progress */ |
| 397 | struct mutex dqonoff_mutex; /* Serialize quotaon & quotaoff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */ |
Alexey Dobriyan | 1472da5 | 2009-10-16 15:26:03 +0400 | [diff] [blame] | 400 | const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | }; |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | int register_quota_format(struct quota_format_type *fmt); |
| 404 | void unregister_quota_format(struct quota_format_type *fmt); |
| 405 | |
| 406 | struct quota_module_name { |
| 407 | int qm_fmt_id; |
| 408 | char *qm_mod_name; |
| 409 | }; |
| 410 | |
| 411 | #define INIT_QUOTA_MODULE_NAMES {\ |
| 412 | {QFMT_VFS_OLD, "quota_v1"},\ |
| 413 | {QFMT_VFS_V0, "quota_v2"},\ |
Theodore Ts'o | c3ad83d | 2013-01-24 23:24:56 -0500 | [diff] [blame] | 414 | {QFMT_VFS_V1, "quota_v2"},\ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | {0, NULL}} |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | #endif /* _QUOTA_ */ |