Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Implementation of the diskquota system for the LINUX operating system. QUOTA |
| 3 | * is implemented using the BSD system call interface as the means of |
| 4 | * communication with the user level. This file contains the generic routines |
| 5 | * called by the different filesystems on allocation of an inode or block. |
| 6 | * These routines take care of the administration needed to have a consistent |
| 7 | * diskquota tracking system. The ideas of both user and group quotas are based |
| 8 | * on the Melbourne quota system as used on BSD derived systems. The internal |
| 9 | * implementation is based on one of the several variants of the LINUX |
| 10 | * inode-subsystem with added complexity of the diskquota system. |
| 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Author: Marco van Wieringen <mvw@planets.elm.net> |
| 13 | * |
| 14 | * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96 |
| 15 | * |
| 16 | * Revised list management to avoid races |
| 17 | * -- Bill Hawes, <whawes@star.net>, 9/98 |
| 18 | * |
| 19 | * Fixed races in dquot_transfer(), dqget() and dquot_alloc_...(). |
| 20 | * As the consequence the locking was moved from dquot_decr_...(), |
| 21 | * dquot_incr_...() to calling functions. |
| 22 | * invalidate_dquots() now writes modified dquots. |
| 23 | * Serialized quota_off() and quota_on() for mount point. |
| 24 | * Fixed a few bugs in grow_dquots(). |
| 25 | * Fixed deadlock in write_dquot() - we no longer account quotas on |
| 26 | * quota files |
| 27 | * remove_dquot_ref() moved to inode.c - it now traverses through inodes |
| 28 | * add_dquot_ref() restarts after blocking |
| 29 | * Added check for bogus uid and fixed check for group in quotactl. |
| 30 | * Jan Kara, <jack@suse.cz>, sponsored by SuSE CR, 10-11/99 |
| 31 | * |
| 32 | * Used struct list_head instead of own list struct |
| 33 | * Invalidation of referenced dquots is no longer possible |
| 34 | * Improved free_dquots list management |
| 35 | * Quota and i_blocks are now updated in one place to avoid races |
| 36 | * Warnings are now delayed so we won't block in critical section |
| 37 | * Write updated not to require dquot lock |
| 38 | * Jan Kara, <jack@suse.cz>, 9/2000 |
| 39 | * |
| 40 | * Added dynamic quota structure allocation |
| 41 | * Jan Kara <jack@suse.cz> 12/2000 |
| 42 | * |
| 43 | * Rewritten quota interface. Implemented new quota format and |
| 44 | * formats registering. |
| 45 | * Jan Kara, <jack@suse.cz>, 2001,2002 |
| 46 | * |
| 47 | * New SMP locking. |
| 48 | * Jan Kara, <jack@suse.cz>, 10/2002 |
| 49 | * |
| 50 | * Added journalled quota support, fix lock inversion problems |
| 51 | * Jan Kara, <jack@suse.cz>, 2003,2004 |
| 52 | * |
| 53 | * (C) Copyright 1994 - 1997 Marco van Wieringen |
| 54 | */ |
| 55 | |
| 56 | #include <linux/errno.h> |
| 57 | #include <linux/kernel.h> |
| 58 | #include <linux/fs.h> |
| 59 | #include <linux/mount.h> |
| 60 | #include <linux/mm.h> |
| 61 | #include <linux/time.h> |
| 62 | #include <linux/types.h> |
| 63 | #include <linux/string.h> |
| 64 | #include <linux/fcntl.h> |
| 65 | #include <linux/stat.h> |
| 66 | #include <linux/tty.h> |
| 67 | #include <linux/file.h> |
| 68 | #include <linux/slab.h> |
| 69 | #include <linux/sysctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #include <linux/init.h> |
| 71 | #include <linux/module.h> |
| 72 | #include <linux/proc_fs.h> |
| 73 | #include <linux/security.h> |
| 74 | #include <linux/kmod.h> |
| 75 | #include <linux/namei.h> |
| 76 | #include <linux/buffer_head.h> |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 77 | #include <linux/capability.h> |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 78 | #include <linux/quotaops.h> |
Christoph Hellwig | fb58b73 | 2007-02-12 00:51:57 -0800 | [diff] [blame] | 79 | #include <linux/writeback.h> /* for inode_lock, oddly enough.. */ |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 80 | #ifdef CONFIG_QUOTA_NETLINK_INTERFACE |
| 81 | #include <net/netlink.h> |
| 82 | #include <net/genetlink.h> |
| 83 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | #include <asm/uaccess.h> |
| 86 | |
| 87 | #define __DQUOT_PARANOIA |
| 88 | |
| 89 | /* |
| 90 | * There are two quota SMP locks. dq_list_lock protects all lists with quotas |
| 91 | * and quota formats and also dqstats structure containing statistics about the |
| 92 | * lists. dq_data_lock protects data from dq_dqb and also mem_dqinfo structures |
| 93 | * and also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes. |
| 94 | * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly |
| 95 | * in inode_add_bytes() and inode_sub_bytes(). |
| 96 | * |
| 97 | * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock |
| 98 | * |
| 99 | * Note that some things (eg. sb pointer, type, id) doesn't change during |
| 100 | * the life of the dquot structure and so needn't to be protected by a lock |
| 101 | * |
| 102 | * Any operation working on dquots via inode pointers must hold dqptr_sem. If |
| 103 | * operation is just reading pointers from inode (or not using them at all) the |
| 104 | * read lock is enough. If pointers are altered function must hold write lock |
| 105 | * (these locking rules also apply for S_NOQUOTA flag in the inode - note that |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 106 | * for altering the flag i_mutex is also needed). If operation is holding |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | * reference to dquot in other way (e.g. quotactl ops) it must be guarded by |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 108 | * dqonoff_mutex. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | * This locking assures that: |
| 110 | * a) update/access to dquot pointers in inode is serialized |
| 111 | * b) everyone is guarded against invalidate_dquots() |
| 112 | * |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 113 | * Each dquot has its dq_lock mutex. Locked dquots might not be referenced |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | * from inodes (dquot_alloc_space() and such don't check the dq_lock). |
| 115 | * Currently dquot is locked only when it is being read to memory (or space for |
| 116 | * it is being allocated) on the first dqget() and when it is being released on |
| 117 | * the last dqput(). The allocation and release oparations are serialized by |
| 118 | * the dq_lock and by checking the use count in dquot_release(). Write |
| 119 | * operations on dquots don't hold dq_lock as they copy data under dq_data_lock |
| 120 | * spinlock to internal buffers before writing. |
| 121 | * |
| 122 | * Lock ordering (including related VFS locks) is the following: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 123 | * i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock > |
| 124 | * dqio_mutex |
| 125 | * i_mutex on quota files is special (it's below dqio_mutex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | */ |
| 127 | |
| 128 | static DEFINE_SPINLOCK(dq_list_lock); |
| 129 | DEFINE_SPINLOCK(dq_data_lock); |
| 130 | |
| 131 | static char *quotatypes[] = INITQFNAMES; |
| 132 | static struct quota_format_type *quota_formats; /* List of registered formats */ |
| 133 | static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES; |
| 134 | |
| 135 | /* SLAB cache for dquot structures */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 136 | static struct kmem_cache *dquot_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | int register_quota_format(struct quota_format_type *fmt) |
| 139 | { |
| 140 | spin_lock(&dq_list_lock); |
| 141 | fmt->qf_next = quota_formats; |
| 142 | quota_formats = fmt; |
| 143 | spin_unlock(&dq_list_lock); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | void unregister_quota_format(struct quota_format_type *fmt) |
| 148 | { |
| 149 | struct quota_format_type **actqf; |
| 150 | |
| 151 | spin_lock(&dq_list_lock); |
| 152 | for (actqf = "a_formats; *actqf && *actqf != fmt; actqf = &(*actqf)->qf_next); |
| 153 | if (*actqf) |
| 154 | *actqf = (*actqf)->qf_next; |
| 155 | spin_unlock(&dq_list_lock); |
| 156 | } |
| 157 | |
| 158 | static struct quota_format_type *find_quota_format(int id) |
| 159 | { |
| 160 | struct quota_format_type *actqf; |
| 161 | |
| 162 | spin_lock(&dq_list_lock); |
| 163 | for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next); |
| 164 | if (!actqf || !try_module_get(actqf->qf_owner)) { |
| 165 | int qm; |
| 166 | |
| 167 | spin_unlock(&dq_list_lock); |
| 168 | |
| 169 | for (qm = 0; module_names[qm].qm_fmt_id && module_names[qm].qm_fmt_id != id; qm++); |
| 170 | if (!module_names[qm].qm_fmt_id || request_module(module_names[qm].qm_mod_name)) |
| 171 | return NULL; |
| 172 | |
| 173 | spin_lock(&dq_list_lock); |
| 174 | for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next); |
| 175 | if (actqf && !try_module_get(actqf->qf_owner)) |
| 176 | actqf = NULL; |
| 177 | } |
| 178 | spin_unlock(&dq_list_lock); |
| 179 | return actqf; |
| 180 | } |
| 181 | |
| 182 | static void put_quota_format(struct quota_format_type *fmt) |
| 183 | { |
| 184 | module_put(fmt->qf_owner); |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Dquot List Management: |
| 189 | * The quota code uses three lists for dquot management: the inuse_list, |
| 190 | * free_dquots, and dquot_hash[] array. A single dquot structure may be |
| 191 | * on all three lists, depending on its current state. |
| 192 | * |
| 193 | * All dquots are placed to the end of inuse_list when first created, and this |
| 194 | * list is used for invalidate operation, which must look at every dquot. |
| 195 | * |
| 196 | * Unused dquots (dq_count == 0) are added to the free_dquots list when freed, |
| 197 | * and this list is searched whenever we need an available dquot. Dquots are |
| 198 | * removed from the list as soon as they are used again, and |
| 199 | * dqstats.free_dquots gives the number of dquots on the list. When |
| 200 | * dquot is invalidated it's completely released from memory. |
| 201 | * |
| 202 | * Dquots with a specific identity (device, type and id) are placed on |
| 203 | * one of the dquot_hash[] hash chains. The provides an efficient search |
| 204 | * mechanism to locate a specific dquot. |
| 205 | */ |
| 206 | |
| 207 | static LIST_HEAD(inuse_list); |
| 208 | static LIST_HEAD(free_dquots); |
| 209 | static unsigned int dq_hash_bits, dq_hash_mask; |
| 210 | static struct hlist_head *dquot_hash; |
| 211 | |
| 212 | struct dqstats dqstats; |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static inline unsigned int |
| 215 | hashfn(const struct super_block *sb, unsigned int id, int type) |
| 216 | { |
| 217 | unsigned long tmp; |
| 218 | |
| 219 | tmp = (((unsigned long)sb>>L1_CACHE_SHIFT) ^ id) * (MAXQUOTAS - type); |
| 220 | return (tmp + (tmp >> dq_hash_bits)) & dq_hash_mask; |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Following list functions expect dq_list_lock to be held |
| 225 | */ |
| 226 | static inline void insert_dquot_hash(struct dquot *dquot) |
| 227 | { |
| 228 | struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type); |
| 229 | hlist_add_head(&dquot->dq_hash, head); |
| 230 | } |
| 231 | |
| 232 | static inline void remove_dquot_hash(struct dquot *dquot) |
| 233 | { |
| 234 | hlist_del_init(&dquot->dq_hash); |
| 235 | } |
| 236 | |
| 237 | static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type) |
| 238 | { |
| 239 | struct hlist_node *node; |
| 240 | struct dquot *dquot; |
| 241 | |
| 242 | hlist_for_each (node, dquot_hash+hashent) { |
| 243 | dquot = hlist_entry(node, struct dquot, dq_hash); |
| 244 | if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type) |
| 245 | return dquot; |
| 246 | } |
| 247 | return NODQUOT; |
| 248 | } |
| 249 | |
| 250 | /* Add a dquot to the tail of the free list */ |
| 251 | static inline void put_dquot_last(struct dquot *dquot) |
| 252 | { |
Akinobu Mita | 8e13059 | 2006-06-26 00:24:37 -0700 | [diff] [blame] | 253 | list_add_tail(&dquot->dq_free, &free_dquots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | dqstats.free_dquots++; |
| 255 | } |
| 256 | |
| 257 | static inline void remove_free_dquot(struct dquot *dquot) |
| 258 | { |
| 259 | if (list_empty(&dquot->dq_free)) |
| 260 | return; |
| 261 | list_del_init(&dquot->dq_free); |
| 262 | dqstats.free_dquots--; |
| 263 | } |
| 264 | |
| 265 | static inline void put_inuse(struct dquot *dquot) |
| 266 | { |
| 267 | /* We add to the back of inuse list so we don't have to restart |
| 268 | * when traversing this list and we block */ |
Akinobu Mita | 8e13059 | 2006-06-26 00:24:37 -0700 | [diff] [blame] | 269 | list_add_tail(&dquot->dq_inuse, &inuse_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | dqstats.allocated_dquots++; |
| 271 | } |
| 272 | |
| 273 | static inline void remove_inuse(struct dquot *dquot) |
| 274 | { |
| 275 | dqstats.allocated_dquots--; |
| 276 | list_del(&dquot->dq_inuse); |
| 277 | } |
| 278 | /* |
| 279 | * End of list functions needing dq_list_lock |
| 280 | */ |
| 281 | |
| 282 | static void wait_on_dquot(struct dquot *dquot) |
| 283 | { |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 284 | mutex_lock(&dquot->dq_lock); |
| 285 | mutex_unlock(&dquot->dq_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Jan Kara | 03f6e92 | 2008-04-28 02:14:32 -0700 | [diff] [blame] | 288 | static inline int dquot_dirty(struct dquot *dquot) |
| 289 | { |
| 290 | return test_bit(DQ_MOD_B, &dquot->dq_flags); |
| 291 | } |
| 292 | |
| 293 | static inline int mark_dquot_dirty(struct dquot *dquot) |
| 294 | { |
| 295 | return dquot->dq_sb->dq_op->mark_dirty(dquot); |
| 296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | int dquot_mark_dquot_dirty(struct dquot *dquot) |
| 299 | { |
| 300 | spin_lock(&dq_list_lock); |
| 301 | if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) |
| 302 | list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)-> |
| 303 | info[dquot->dq_type].dqi_dirty_list); |
| 304 | spin_unlock(&dq_list_lock); |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | /* This function needs dq_list_lock */ |
| 309 | static inline int clear_dquot_dirty(struct dquot *dquot) |
| 310 | { |
| 311 | if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags)) |
| 312 | return 0; |
| 313 | list_del_init(&dquot->dq_dirty); |
| 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | void mark_info_dirty(struct super_block *sb, int type) |
| 318 | { |
| 319 | set_bit(DQF_INFO_DIRTY_B, &sb_dqopt(sb)->info[type].dqi_flags); |
| 320 | } |
| 321 | EXPORT_SYMBOL(mark_info_dirty); |
| 322 | |
| 323 | /* |
| 324 | * Read dquot from disk and alloc space for it |
| 325 | */ |
| 326 | |
| 327 | int dquot_acquire(struct dquot *dquot) |
| 328 | { |
| 329 | int ret = 0, ret2 = 0; |
| 330 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
| 331 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 332 | mutex_lock(&dquot->dq_lock); |
| 333 | mutex_lock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | if (!test_bit(DQ_READ_B, &dquot->dq_flags)) |
| 335 | ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot); |
| 336 | if (ret < 0) |
| 337 | goto out_iolock; |
| 338 | set_bit(DQ_READ_B, &dquot->dq_flags); |
| 339 | /* Instantiate dquot if needed */ |
| 340 | if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { |
| 341 | ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); |
| 342 | /* Write the info if needed */ |
| 343 | if (info_dirty(&dqopt->info[dquot->dq_type])) |
| 344 | ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); |
| 345 | if (ret < 0) |
| 346 | goto out_iolock; |
| 347 | if (ret2 < 0) { |
| 348 | ret = ret2; |
| 349 | goto out_iolock; |
| 350 | } |
| 351 | } |
| 352 | set_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
| 353 | out_iolock: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 354 | mutex_unlock(&dqopt->dqio_mutex); |
| 355 | mutex_unlock(&dquot->dq_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Write dquot to disk |
| 361 | */ |
| 362 | int dquot_commit(struct dquot *dquot) |
| 363 | { |
| 364 | int ret = 0, ret2 = 0; |
| 365 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
| 366 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 367 | mutex_lock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | spin_lock(&dq_list_lock); |
| 369 | if (!clear_dquot_dirty(dquot)) { |
| 370 | spin_unlock(&dq_list_lock); |
| 371 | goto out_sem; |
| 372 | } |
| 373 | spin_unlock(&dq_list_lock); |
| 374 | /* Inactive dquot can be only if there was error during read/init |
| 375 | * => we have better not writing it */ |
| 376 | if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
| 377 | ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); |
| 378 | if (info_dirty(&dqopt->info[dquot->dq_type])) |
| 379 | ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); |
| 380 | if (ret >= 0) |
| 381 | ret = ret2; |
| 382 | } |
| 383 | out_sem: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 384 | mutex_unlock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * Release dquot |
| 390 | */ |
| 391 | int dquot_release(struct dquot *dquot) |
| 392 | { |
| 393 | int ret = 0, ret2 = 0; |
| 394 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
| 395 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 396 | mutex_lock(&dquot->dq_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /* Check whether we are not racing with some other dqget() */ |
| 398 | if (atomic_read(&dquot->dq_count) > 1) |
| 399 | goto out_dqlock; |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 400 | mutex_lock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | if (dqopt->ops[dquot->dq_type]->release_dqblk) { |
| 402 | ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot); |
| 403 | /* Write the info */ |
| 404 | if (info_dirty(&dqopt->info[dquot->dq_type])) |
| 405 | ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); |
| 406 | if (ret >= 0) |
| 407 | ret = ret2; |
| 408 | } |
| 409 | clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 410 | mutex_unlock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | out_dqlock: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 412 | mutex_unlock(&dquot->dq_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return ret; |
| 414 | } |
| 415 | |
Jan Kara | 7d9056b | 2008-11-25 15:31:32 +0100 | [diff] [blame^] | 416 | void dquot_destroy(struct dquot *dquot) |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 417 | { |
| 418 | kmem_cache_free(dquot_cachep, dquot); |
| 419 | } |
Jan Kara | 7d9056b | 2008-11-25 15:31:32 +0100 | [diff] [blame^] | 420 | EXPORT_SYMBOL(dquot_destroy); |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 421 | |
| 422 | static inline void do_destroy_dquot(struct dquot *dquot) |
| 423 | { |
| 424 | dquot->dq_sb->dq_op->destroy_dquot(dquot); |
| 425 | } |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /* Invalidate all dquots on the list. Note that this function is called after |
| 428 | * quota is disabled and pointers from inodes removed so there cannot be new |
Jan Kara | 6362e4d | 2006-03-23 03:00:17 -0800 | [diff] [blame] | 429 | * quota users. There can still be some users of quotas due to inodes being |
| 430 | * just deleted or pruned by prune_icache() (those are not attached to any |
| 431 | * list). We have to wait for such users. |
| 432 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | static void invalidate_dquots(struct super_block *sb, int type) |
| 434 | { |
Domen Puncer | c33ed27 | 2005-06-25 14:59:36 -0700 | [diff] [blame] | 435 | struct dquot *dquot, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Jan Kara | 6362e4d | 2006-03-23 03:00:17 -0800 | [diff] [blame] | 437 | restart: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | spin_lock(&dq_list_lock); |
Domen Puncer | c33ed27 | 2005-06-25 14:59:36 -0700 | [diff] [blame] | 439 | list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (dquot->dq_sb != sb) |
| 441 | continue; |
| 442 | if (dquot->dq_type != type) |
| 443 | continue; |
Jan Kara | 6362e4d | 2006-03-23 03:00:17 -0800 | [diff] [blame] | 444 | /* Wait for dquot users */ |
| 445 | if (atomic_read(&dquot->dq_count)) { |
| 446 | DEFINE_WAIT(wait); |
| 447 | |
| 448 | atomic_inc(&dquot->dq_count); |
| 449 | prepare_to_wait(&dquot->dq_wait_unused, &wait, |
| 450 | TASK_UNINTERRUPTIBLE); |
| 451 | spin_unlock(&dq_list_lock); |
| 452 | /* Once dqput() wakes us up, we know it's time to free |
| 453 | * the dquot. |
| 454 | * IMPORTANT: we rely on the fact that there is always |
| 455 | * at most one process waiting for dquot to free. |
| 456 | * Otherwise dq_count would be > 1 and we would never |
| 457 | * wake up. |
| 458 | */ |
| 459 | if (atomic_read(&dquot->dq_count) > 1) |
| 460 | schedule(); |
| 461 | finish_wait(&dquot->dq_wait_unused, &wait); |
| 462 | dqput(dquot); |
| 463 | /* At this moment dquot() need not exist (it could be |
| 464 | * reclaimed by prune_dqcache(). Hence we must |
| 465 | * restart. */ |
| 466 | goto restart; |
| 467 | } |
| 468 | /* |
| 469 | * Quota now has no users and it has been written on last |
| 470 | * dqput() |
| 471 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | remove_dquot_hash(dquot); |
| 473 | remove_free_dquot(dquot); |
| 474 | remove_inuse(dquot); |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 475 | do_destroy_dquot(dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | spin_unlock(&dq_list_lock); |
| 478 | } |
| 479 | |
Jan Kara | 12c7752 | 2008-10-20 17:05:00 +0200 | [diff] [blame] | 480 | /* Call callback for every active dquot on given filesystem */ |
| 481 | int dquot_scan_active(struct super_block *sb, |
| 482 | int (*fn)(struct dquot *dquot, unsigned long priv), |
| 483 | unsigned long priv) |
| 484 | { |
| 485 | struct dquot *dquot, *old_dquot = NULL; |
| 486 | int ret = 0; |
| 487 | |
| 488 | mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); |
| 489 | spin_lock(&dq_list_lock); |
| 490 | list_for_each_entry(dquot, &inuse_list, dq_inuse) { |
| 491 | if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) |
| 492 | continue; |
| 493 | if (dquot->dq_sb != sb) |
| 494 | continue; |
| 495 | /* Now we have active dquot so we can just increase use count */ |
| 496 | atomic_inc(&dquot->dq_count); |
| 497 | dqstats.lookups++; |
| 498 | spin_unlock(&dq_list_lock); |
| 499 | dqput(old_dquot); |
| 500 | old_dquot = dquot; |
| 501 | ret = fn(dquot, priv); |
| 502 | if (ret < 0) |
| 503 | goto out; |
| 504 | spin_lock(&dq_list_lock); |
| 505 | /* We are safe to continue now because our dquot could not |
| 506 | * be moved out of the inuse list while we hold the reference */ |
| 507 | } |
| 508 | spin_unlock(&dq_list_lock); |
| 509 | out: |
| 510 | dqput(old_dquot); |
| 511 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
| 512 | return ret; |
| 513 | } |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | int vfs_quota_sync(struct super_block *sb, int type) |
| 516 | { |
| 517 | struct list_head *dirty; |
| 518 | struct dquot *dquot; |
| 519 | struct quota_info *dqopt = sb_dqopt(sb); |
| 520 | int cnt; |
| 521 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 522 | mutex_lock(&dqopt->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 524 | if (type != -1 && cnt != type) |
| 525 | continue; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 526 | if (!sb_has_quota_active(sb, cnt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | continue; |
| 528 | spin_lock(&dq_list_lock); |
| 529 | dirty = &dqopt->info[cnt].dqi_dirty_list; |
| 530 | while (!list_empty(dirty)) { |
Pavel Emelianov | b5e6181 | 2007-05-08 00:30:19 -0700 | [diff] [blame] | 531 | dquot = list_first_entry(dirty, struct dquot, dq_dirty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | /* Dirty and inactive can be only bad dquot... */ |
| 533 | if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
| 534 | clear_dquot_dirty(dquot); |
| 535 | continue; |
| 536 | } |
| 537 | /* Now we have active dquot from which someone is |
| 538 | * holding reference so we can safely just increase |
| 539 | * use count */ |
| 540 | atomic_inc(&dquot->dq_count); |
| 541 | dqstats.lookups++; |
| 542 | spin_unlock(&dq_list_lock); |
| 543 | sb->dq_op->write_dquot(dquot); |
| 544 | dqput(dquot); |
| 545 | spin_lock(&dq_list_lock); |
| 546 | } |
| 547 | spin_unlock(&dq_list_lock); |
| 548 | } |
| 549 | |
| 550 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 551 | if ((cnt == type || type == -1) && sb_has_quota_active(sb, cnt) |
| 552 | && info_dirty(&dqopt->info[cnt])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | sb->dq_op->write_info(sb, cnt); |
| 554 | spin_lock(&dq_list_lock); |
| 555 | dqstats.syncs++; |
| 556 | spin_unlock(&dq_list_lock); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 557 | mutex_unlock(&dqopt->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /* Free unused dquots from cache */ |
| 563 | static void prune_dqcache(int count) |
| 564 | { |
| 565 | struct list_head *head; |
| 566 | struct dquot *dquot; |
| 567 | |
| 568 | head = free_dquots.prev; |
| 569 | while (head != &free_dquots && count) { |
| 570 | dquot = list_entry(head, struct dquot, dq_free); |
| 571 | remove_dquot_hash(dquot); |
| 572 | remove_free_dquot(dquot); |
| 573 | remove_inuse(dquot); |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 574 | do_destroy_dquot(dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | count--; |
| 576 | head = free_dquots.prev; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * This is called from kswapd when we think we need some |
| 582 | * more memory |
| 583 | */ |
| 584 | |
Al Viro | 27496a8 | 2005-10-21 03:20:48 -0400 | [diff] [blame] | 585 | static int shrink_dqcache_memory(int nr, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { |
| 587 | if (nr) { |
| 588 | spin_lock(&dq_list_lock); |
| 589 | prune_dqcache(nr); |
| 590 | spin_unlock(&dq_list_lock); |
| 591 | } |
| 592 | return (dqstats.free_dquots / 100) * sysctl_vfs_cache_pressure; |
| 593 | } |
| 594 | |
Rusty Russell | 8e1f936 | 2007-07-17 04:03:17 -0700 | [diff] [blame] | 595 | static struct shrinker dqcache_shrinker = { |
| 596 | .shrink = shrink_dqcache_memory, |
| 597 | .seeks = DEFAULT_SEEKS, |
| 598 | }; |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* |
| 601 | * Put reference to dquot |
| 602 | * NOTE: If you change this function please check whether dqput_blocks() works right... |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 603 | * MUST be called with either dqptr_sem or dqonoff_mutex held |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | */ |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 605 | void dqput(struct dquot *dquot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
Jan Kara | b48d380 | 2008-07-25 01:46:49 -0700 | [diff] [blame] | 607 | int ret; |
| 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (!dquot) |
| 610 | return; |
| 611 | #ifdef __DQUOT_PARANOIA |
| 612 | if (!atomic_read(&dquot->dq_count)) { |
| 613 | printk("VFS: dqput: trying to free free dquot\n"); |
| 614 | printk("VFS: device %s, dquot of %s %d\n", |
| 615 | dquot->dq_sb->s_id, |
| 616 | quotatypes[dquot->dq_type], |
| 617 | dquot->dq_id); |
| 618 | BUG(); |
| 619 | } |
| 620 | #endif |
| 621 | |
| 622 | spin_lock(&dq_list_lock); |
| 623 | dqstats.drops++; |
| 624 | spin_unlock(&dq_list_lock); |
| 625 | we_slept: |
| 626 | spin_lock(&dq_list_lock); |
| 627 | if (atomic_read(&dquot->dq_count) > 1) { |
| 628 | /* We have more than one user... nothing to do */ |
| 629 | atomic_dec(&dquot->dq_count); |
Jan Kara | 6362e4d | 2006-03-23 03:00:17 -0800 | [diff] [blame] | 630 | /* Releasing dquot during quotaoff phase? */ |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 631 | if (!sb_has_quota_active(dquot->dq_sb, dquot->dq_type) && |
Jan Kara | 6362e4d | 2006-03-23 03:00:17 -0800 | [diff] [blame] | 632 | atomic_read(&dquot->dq_count) == 1) |
| 633 | wake_up(&dquot->dq_wait_unused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | spin_unlock(&dq_list_lock); |
| 635 | return; |
| 636 | } |
| 637 | /* Need to release dquot? */ |
| 638 | if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) { |
| 639 | spin_unlock(&dq_list_lock); |
| 640 | /* Commit dquot before releasing */ |
Jan Kara | b48d380 | 2008-07-25 01:46:49 -0700 | [diff] [blame] | 641 | ret = dquot->dq_sb->dq_op->write_dquot(dquot); |
| 642 | if (ret < 0) { |
| 643 | printk(KERN_ERR "VFS: cannot write quota structure on " |
| 644 | "device %s (error %d). Quota may get out of " |
| 645 | "sync!\n", dquot->dq_sb->s_id, ret); |
| 646 | /* |
| 647 | * We clear dirty bit anyway, so that we avoid |
| 648 | * infinite loop here |
| 649 | */ |
| 650 | spin_lock(&dq_list_lock); |
| 651 | clear_dquot_dirty(dquot); |
| 652 | spin_unlock(&dq_list_lock); |
| 653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | goto we_slept; |
| 655 | } |
| 656 | /* Clear flag in case dquot was inactive (something bad happened) */ |
| 657 | clear_dquot_dirty(dquot); |
| 658 | if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
| 659 | spin_unlock(&dq_list_lock); |
| 660 | dquot->dq_sb->dq_op->release_dquot(dquot); |
| 661 | goto we_slept; |
| 662 | } |
| 663 | atomic_dec(&dquot->dq_count); |
| 664 | #ifdef __DQUOT_PARANOIA |
| 665 | /* sanity check */ |
Eric Sesterhenn | 8abf6a4 | 2006-04-02 13:36:13 +0200 | [diff] [blame] | 666 | BUG_ON(!list_empty(&dquot->dq_free)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | #endif |
| 668 | put_dquot_last(dquot); |
| 669 | spin_unlock(&dq_list_lock); |
| 670 | } |
| 671 | |
Jan Kara | 7d9056b | 2008-11-25 15:31:32 +0100 | [diff] [blame^] | 672 | struct dquot *dquot_alloc(struct super_block *sb, int type) |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 673 | { |
| 674 | return kmem_cache_zalloc(dquot_cachep, GFP_NOFS); |
| 675 | } |
Jan Kara | 7d9056b | 2008-11-25 15:31:32 +0100 | [diff] [blame^] | 676 | EXPORT_SYMBOL(dquot_alloc); |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | static struct dquot *get_empty_dquot(struct super_block *sb, int type) |
| 679 | { |
| 680 | struct dquot *dquot; |
| 681 | |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 682 | dquot = sb->dq_op->alloc_dquot(sb, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if(!dquot) |
| 684 | return NODQUOT; |
| 685 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 686 | mutex_init(&dquot->dq_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | INIT_LIST_HEAD(&dquot->dq_free); |
| 688 | INIT_LIST_HEAD(&dquot->dq_inuse); |
| 689 | INIT_HLIST_NODE(&dquot->dq_hash); |
| 690 | INIT_LIST_HEAD(&dquot->dq_dirty); |
Jan Kara | 6362e4d | 2006-03-23 03:00:17 -0800 | [diff] [blame] | 691 | init_waitqueue_head(&dquot->dq_wait_unused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | dquot->dq_sb = sb; |
| 693 | dquot->dq_type = type; |
| 694 | atomic_set(&dquot->dq_count, 1); |
| 695 | |
| 696 | return dquot; |
| 697 | } |
| 698 | |
| 699 | /* |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 700 | * Check whether dquot is in memory. |
| 701 | * MUST be called with either dqptr_sem or dqonoff_mutex held |
| 702 | */ |
| 703 | int dquot_is_cached(struct super_block *sb, unsigned int id, int type) |
| 704 | { |
| 705 | unsigned int hashent = hashfn(sb, id, type); |
| 706 | int ret = 0; |
| 707 | |
| 708 | if (!sb_has_quota_active(sb, type)) |
| 709 | return 0; |
| 710 | spin_lock(&dq_list_lock); |
| 711 | if (find_dquot(hashent, sb, id, type) != NODQUOT) |
| 712 | ret = 1; |
| 713 | spin_unlock(&dq_list_lock); |
| 714 | return ret; |
| 715 | } |
| 716 | |
| 717 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | * Get reference to dquot |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 719 | * MUST be called with either dqptr_sem or dqonoff_mutex held |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | */ |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 721 | struct dquot *dqget(struct super_block *sb, unsigned int id, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
| 723 | unsigned int hashent = hashfn(sb, id, type); |
| 724 | struct dquot *dquot, *empty = NODQUOT; |
| 725 | |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 726 | if (!sb_has_quota_active(sb, type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | return NODQUOT; |
| 728 | we_slept: |
| 729 | spin_lock(&dq_list_lock); |
| 730 | if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) { |
| 731 | if (empty == NODQUOT) { |
| 732 | spin_unlock(&dq_list_lock); |
| 733 | if ((empty = get_empty_dquot(sb, type)) == NODQUOT) |
| 734 | schedule(); /* Try to wait for a moment... */ |
| 735 | goto we_slept; |
| 736 | } |
| 737 | dquot = empty; |
| 738 | dquot->dq_id = id; |
| 739 | /* all dquots go on the inuse_list */ |
| 740 | put_inuse(dquot); |
| 741 | /* hash it first so it can be found */ |
| 742 | insert_dquot_hash(dquot); |
| 743 | dqstats.lookups++; |
| 744 | spin_unlock(&dq_list_lock); |
| 745 | } else { |
| 746 | if (!atomic_read(&dquot->dq_count)) |
| 747 | remove_free_dquot(dquot); |
| 748 | atomic_inc(&dquot->dq_count); |
| 749 | dqstats.cache_hits++; |
| 750 | dqstats.lookups++; |
| 751 | spin_unlock(&dq_list_lock); |
| 752 | if (empty) |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 753 | do_destroy_dquot(empty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | /* Wait for dq_lock - after this we know that either dquot_release() is already |
| 756 | * finished or it will be canceled due to dq_count > 1 test */ |
| 757 | wait_on_dquot(dquot); |
| 758 | /* Read the dquot and instantiate it (everything done only if needed) */ |
| 759 | if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) { |
| 760 | dqput(dquot); |
| 761 | return NODQUOT; |
| 762 | } |
| 763 | #ifdef __DQUOT_PARANOIA |
Eric Sesterhenn | 8abf6a4 | 2006-04-02 13:36:13 +0200 | [diff] [blame] | 764 | BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | #endif |
| 766 | |
| 767 | return dquot; |
| 768 | } |
| 769 | |
| 770 | static int dqinit_needed(struct inode *inode, int type) |
| 771 | { |
| 772 | int cnt; |
| 773 | |
| 774 | if (IS_NOQUOTA(inode)) |
| 775 | return 0; |
| 776 | if (type != -1) |
| 777 | return inode->i_dquot[type] == NODQUOT; |
| 778 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 779 | if (inode->i_dquot[cnt] == NODQUOT) |
| 780 | return 1; |
| 781 | return 0; |
| 782 | } |
| 783 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 784 | /* This routine is guarded by dqonoff_mutex mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | static void add_dquot_ref(struct super_block *sb, int type) |
| 786 | { |
Jan Kara | 941d238 | 2008-02-06 01:37:36 -0800 | [diff] [blame] | 787 | struct inode *inode, *old_inode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Christoph Hellwig | d003fb7 | 2007-02-12 00:51:58 -0800 | [diff] [blame] | 789 | spin_lock(&inode_lock); |
| 790 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { |
| 791 | if (!atomic_read(&inode->i_writecount)) |
| 792 | continue; |
| 793 | if (!dqinit_needed(inode, type)) |
| 794 | continue; |
| 795 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) |
| 796 | continue; |
| 797 | |
| 798 | __iget(inode); |
| 799 | spin_unlock(&inode_lock); |
| 800 | |
Jan Kara | 941d238 | 2008-02-06 01:37:36 -0800 | [diff] [blame] | 801 | iput(old_inode); |
Christoph Hellwig | d003fb7 | 2007-02-12 00:51:58 -0800 | [diff] [blame] | 802 | sb->dq_op->initialize(inode, type); |
Jan Kara | 941d238 | 2008-02-06 01:37:36 -0800 | [diff] [blame] | 803 | /* We hold a reference to 'inode' so it couldn't have been |
| 804 | * removed from s_inodes list while we dropped the inode_lock. |
| 805 | * We cannot iput the inode now as we can be holding the last |
| 806 | * reference and we cannot iput it under inode_lock. So we |
| 807 | * keep the reference and iput it later. */ |
| 808 | old_inode = inode; |
| 809 | spin_lock(&inode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
Christoph Hellwig | d003fb7 | 2007-02-12 00:51:58 -0800 | [diff] [blame] | 811 | spin_unlock(&inode_lock); |
Jan Kara | 941d238 | 2008-02-06 01:37:36 -0800 | [diff] [blame] | 812 | iput(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */ |
| 816 | static inline int dqput_blocks(struct dquot *dquot) |
| 817 | { |
| 818 | if (atomic_read(&dquot->dq_count) <= 1) |
| 819 | return 1; |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | /* Remove references to dquots from inode - add dquot to list for freeing if needed */ |
| 824 | /* We can't race with anybody because we hold dqptr_sem for writing... */ |
Adrian Bunk | e5f00f4 | 2007-05-08 00:27:22 -0700 | [diff] [blame] | 825 | static int remove_inode_dquot_ref(struct inode *inode, int type, |
| 826 | struct list_head *tofree_head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
| 828 | struct dquot *dquot = inode->i_dquot[type]; |
| 829 | |
| 830 | inode->i_dquot[type] = NODQUOT; |
| 831 | if (dquot != NODQUOT) { |
| 832 | if (dqput_blocks(dquot)) { |
| 833 | #ifdef __DQUOT_PARANOIA |
| 834 | if (atomic_read(&dquot->dq_count) != 1) |
| 835 | printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count)); |
| 836 | #endif |
| 837 | spin_lock(&dq_list_lock); |
| 838 | list_add(&dquot->dq_free, tofree_head); /* As dquot must have currently users it can't be on the free list... */ |
| 839 | spin_unlock(&dq_list_lock); |
| 840 | return 1; |
| 841 | } |
| 842 | else |
| 843 | dqput(dquot); /* We have guaranteed we won't block */ |
| 844 | } |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | /* Free list of dquots - called from inode.c */ |
| 849 | /* dquots are removed from inodes, no new references can be got so we are the only ones holding reference */ |
| 850 | static void put_dquot_list(struct list_head *tofree_head) |
| 851 | { |
| 852 | struct list_head *act_head; |
| 853 | struct dquot *dquot; |
| 854 | |
| 855 | act_head = tofree_head->next; |
| 856 | /* So now we have dquots on the list... Just free them */ |
| 857 | while (act_head != tofree_head) { |
| 858 | dquot = list_entry(act_head, struct dquot, dq_free); |
| 859 | act_head = act_head->next; |
| 860 | list_del_init(&dquot->dq_free); /* Remove dquot from the list so we won't have problems... */ |
| 861 | dqput(dquot); |
| 862 | } |
| 863 | } |
| 864 | |
Christoph Hellwig | fb58b73 | 2007-02-12 00:51:57 -0800 | [diff] [blame] | 865 | static void remove_dquot_ref(struct super_block *sb, int type, |
| 866 | struct list_head *tofree_head) |
| 867 | { |
| 868 | struct inode *inode; |
| 869 | |
| 870 | spin_lock(&inode_lock); |
| 871 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { |
| 872 | if (!IS_NOQUOTA(inode)) |
| 873 | remove_inode_dquot_ref(inode, type, tofree_head); |
| 874 | } |
| 875 | spin_unlock(&inode_lock); |
| 876 | } |
| 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | /* Gather all references from inodes and drop them */ |
| 879 | static void drop_dquot_ref(struct super_block *sb, int type) |
| 880 | { |
| 881 | LIST_HEAD(tofree_head); |
| 882 | |
Christoph Hellwig | fb58b73 | 2007-02-12 00:51:57 -0800 | [diff] [blame] | 883 | if (sb->dq_op) { |
| 884 | down_write(&sb_dqopt(sb)->dqptr_sem); |
| 885 | remove_dquot_ref(sb, type, &tofree_head); |
| 886 | up_write(&sb_dqopt(sb)->dqptr_sem); |
| 887 | put_dquot_list(&tofree_head); |
| 888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 891 | static inline void dquot_incr_inodes(struct dquot *dquot, qsize_t number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
| 893 | dquot->dq_dqb.dqb_curinodes += number; |
| 894 | } |
| 895 | |
| 896 | static inline void dquot_incr_space(struct dquot *dquot, qsize_t number) |
| 897 | { |
| 898 | dquot->dq_dqb.dqb_curspace += number; |
| 899 | } |
| 900 | |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 901 | static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { |
Jan Kara | db49d2d | 2008-10-01 18:21:39 +0200 | [diff] [blame] | 903 | if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE || |
| 904 | dquot->dq_dqb.dqb_curinodes >= number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | dquot->dq_dqb.dqb_curinodes -= number; |
| 906 | else |
| 907 | dquot->dq_dqb.dqb_curinodes = 0; |
| 908 | if (dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit) |
| 909 | dquot->dq_dqb.dqb_itime = (time_t) 0; |
| 910 | clear_bit(DQ_INODES_B, &dquot->dq_flags); |
| 911 | } |
| 912 | |
| 913 | static inline void dquot_decr_space(struct dquot *dquot, qsize_t number) |
| 914 | { |
Jan Kara | db49d2d | 2008-10-01 18:21:39 +0200 | [diff] [blame] | 915 | if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE || |
| 916 | dquot->dq_dqb.dqb_curspace >= number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | dquot->dq_dqb.dqb_curspace -= number; |
| 918 | else |
| 919 | dquot->dq_dqb.dqb_curspace = 0; |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 920 | if (dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | dquot->dq_dqb.dqb_btime = (time_t) 0; |
| 922 | clear_bit(DQ_BLKS_B, &dquot->dq_flags); |
| 923 | } |
| 924 | |
Jan Kara | c525460 | 2007-12-22 14:03:25 -0800 | [diff] [blame] | 925 | static int warning_issued(struct dquot *dquot, const int warntype) |
| 926 | { |
| 927 | int flag = (warntype == QUOTA_NL_BHARDWARN || |
| 928 | warntype == QUOTA_NL_BSOFTLONGWARN) ? DQ_BLKS_B : |
| 929 | ((warntype == QUOTA_NL_IHARDWARN || |
| 930 | warntype == QUOTA_NL_ISOFTLONGWARN) ? DQ_INODES_B : 0); |
| 931 | |
| 932 | if (!flag) |
| 933 | return 0; |
| 934 | return test_and_set_bit(flag, &dquot->dq_flags); |
| 935 | } |
| 936 | |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 937 | #ifdef CONFIG_PRINT_QUOTA_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | static int flag_print_warnings = 1; |
| 939 | |
| 940 | static inline int need_print_warning(struct dquot *dquot) |
| 941 | { |
| 942 | if (!flag_print_warnings) |
| 943 | return 0; |
| 944 | |
| 945 | switch (dquot->dq_type) { |
| 946 | case USRQUOTA: |
David Howells | da9592e | 2008-11-14 10:39:05 +1100 | [diff] [blame] | 947 | return current_fsuid() == dquot->dq_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | case GRPQUOTA: |
| 949 | return in_group_p(dquot->dq_id); |
| 950 | } |
| 951 | return 0; |
| 952 | } |
| 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | /* Print warning to user which exceeded quota */ |
Jan Kara | c525460 | 2007-12-22 14:03:25 -0800 | [diff] [blame] | 955 | static void print_warning(struct dquot *dquot, const int warntype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | { |
| 957 | char *msg = NULL; |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 958 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 960 | if (warntype == QUOTA_NL_IHARDBELOW || |
| 961 | warntype == QUOTA_NL_ISOFTBELOW || |
| 962 | warntype == QUOTA_NL_BHARDBELOW || |
| 963 | warntype == QUOTA_NL_BSOFTBELOW || !need_print_warning(dquot)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | return; |
| 965 | |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 966 | tty = get_current_tty(); |
| 967 | if (!tty) |
Alan Cox | 452a00d | 2008-10-13 10:39:13 +0100 | [diff] [blame] | 968 | return; |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 969 | tty_write_message(tty, dquot->dq_sb->s_id); |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 970 | if (warntype == QUOTA_NL_ISOFTWARN || warntype == QUOTA_NL_BSOFTWARN) |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 971 | tty_write_message(tty, ": warning, "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | else |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 973 | tty_write_message(tty, ": write failed, "); |
| 974 | tty_write_message(tty, quotatypes[dquot->dq_type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | switch (warntype) { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 976 | case QUOTA_NL_IHARDWARN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | msg = " file limit reached.\r\n"; |
| 978 | break; |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 979 | case QUOTA_NL_ISOFTLONGWARN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | msg = " file quota exceeded too long.\r\n"; |
| 981 | break; |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 982 | case QUOTA_NL_ISOFTWARN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | msg = " file quota exceeded.\r\n"; |
| 984 | break; |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 985 | case QUOTA_NL_BHARDWARN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | msg = " block limit reached.\r\n"; |
| 987 | break; |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 988 | case QUOTA_NL_BSOFTLONGWARN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | msg = " block quota exceeded too long.\r\n"; |
| 990 | break; |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 991 | case QUOTA_NL_BSOFTWARN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | msg = " block quota exceeded.\r\n"; |
| 993 | break; |
| 994 | } |
Peter Zijlstra | 24ec839 | 2006-12-08 02:36:04 -0800 | [diff] [blame] | 995 | tty_write_message(tty, msg); |
Alan Cox | 452a00d | 2008-10-13 10:39:13 +0100 | [diff] [blame] | 996 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 998 | #endif |
| 999 | |
| 1000 | #ifdef CONFIG_QUOTA_NETLINK_INTERFACE |
| 1001 | |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1002 | /* Netlink family structure for quota */ |
| 1003 | static struct genl_family quota_genl_family = { |
| 1004 | .id = GENL_ID_GENERATE, |
| 1005 | .hdrsize = 0, |
| 1006 | .name = "VFS_DQUOT", |
| 1007 | .version = 1, |
| 1008 | .maxattr = QUOTA_NL_A_MAX, |
| 1009 | }; |
| 1010 | |
| 1011 | /* Send warning to userspace about user which exceeded quota */ |
| 1012 | static void send_warning(const struct dquot *dquot, const char warntype) |
| 1013 | { |
| 1014 | static atomic_t seq; |
| 1015 | struct sk_buff *skb; |
| 1016 | void *msg_head; |
| 1017 | int ret; |
Jan Kara | 22dd483 | 2007-12-22 14:03:25 -0800 | [diff] [blame] | 1018 | int msg_size = 4 * nla_total_size(sizeof(u32)) + |
| 1019 | 2 * nla_total_size(sizeof(u64)); |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1020 | |
| 1021 | /* We have to allocate using GFP_NOFS as we are called from a |
| 1022 | * filesystem performing write and thus further recursion into |
| 1023 | * the fs to free some data could cause deadlocks. */ |
Jan Kara | 22dd483 | 2007-12-22 14:03:25 -0800 | [diff] [blame] | 1024 | skb = genlmsg_new(msg_size, GFP_NOFS); |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1025 | if (!skb) { |
| 1026 | printk(KERN_ERR |
| 1027 | "VFS: Not enough memory to send quota warning.\n"); |
| 1028 | return; |
| 1029 | } |
| 1030 | msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq), |
| 1031 | "a_genl_family, 0, QUOTA_NL_C_WARNING); |
| 1032 | if (!msg_head) { |
| 1033 | printk(KERN_ERR |
| 1034 | "VFS: Cannot store netlink header in quota warning.\n"); |
| 1035 | goto err_out; |
| 1036 | } |
| 1037 | ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, dquot->dq_type); |
| 1038 | if (ret) |
| 1039 | goto attr_err_out; |
| 1040 | ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, dquot->dq_id); |
| 1041 | if (ret) |
| 1042 | goto attr_err_out; |
| 1043 | ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype); |
| 1044 | if (ret) |
| 1045 | goto attr_err_out; |
| 1046 | ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, |
| 1047 | MAJOR(dquot->dq_sb->s_dev)); |
| 1048 | if (ret) |
| 1049 | goto attr_err_out; |
| 1050 | ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, |
| 1051 | MINOR(dquot->dq_sb->s_dev)); |
| 1052 | if (ret) |
| 1053 | goto attr_err_out; |
David Howells | da9592e | 2008-11-14 10:39:05 +1100 | [diff] [blame] | 1054 | ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid()); |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1055 | if (ret) |
| 1056 | goto attr_err_out; |
| 1057 | genlmsg_end(skb, msg_head); |
| 1058 | |
| 1059 | ret = genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS); |
| 1060 | if (ret < 0 && ret != -ESRCH) |
| 1061 | printk(KERN_ERR |
| 1062 | "VFS: Failed to send notification message: %d\n", ret); |
| 1063 | return; |
| 1064 | attr_err_out: |
Jan Kara | 22dd483 | 2007-12-22 14:03:25 -0800 | [diff] [blame] | 1065 | printk(KERN_ERR "VFS: Not enough space to compose quota message!\n"); |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1066 | err_out: |
| 1067 | kfree_skb(skb); |
| 1068 | } |
| 1069 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Jan Kara | 087ee8d | 2007-12-17 16:20:26 -0800 | [diff] [blame] | 1071 | static inline void flush_warnings(struct dquot * const *dquots, char *warntype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | { |
| 1073 | int i; |
| 1074 | |
| 1075 | for (i = 0; i < MAXQUOTAS; i++) |
Jan Kara | c525460 | 2007-12-22 14:03:25 -0800 | [diff] [blame] | 1076 | if (dquots[i] != NODQUOT && warntype[i] != QUOTA_NL_NOWARN && |
| 1077 | !warning_issued(dquots[i], warntype[i])) { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1078 | #ifdef CONFIG_PRINT_QUOTA_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | print_warning(dquots[i], warntype[i]); |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1080 | #endif |
| 1081 | #ifdef CONFIG_QUOTA_NETLINK_INTERFACE |
| 1082 | send_warning(dquots[i], warntype[i]); |
| 1083 | #endif |
| 1084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static inline char ignore_hardlimit(struct dquot *dquot) |
| 1088 | { |
| 1089 | struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; |
| 1090 | |
| 1091 | return capable(CAP_SYS_RESOURCE) && |
| 1092 | (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH)); |
| 1093 | } |
| 1094 | |
| 1095 | /* needs dq_data_lock */ |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1096 | static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1098 | *warntype = QUOTA_NL_NOWARN; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1099 | if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || |
| 1100 | test_bit(DQ_FAKE_B, &dquot->dq_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | return QUOTA_OK; |
| 1102 | |
| 1103 | if (dquot->dq_dqb.dqb_ihardlimit && |
| 1104 | (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit && |
| 1105 | !ignore_hardlimit(dquot)) { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1106 | *warntype = QUOTA_NL_IHARDWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | return NO_QUOTA; |
| 1108 | } |
| 1109 | |
| 1110 | if (dquot->dq_dqb.dqb_isoftlimit && |
| 1111 | (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit && |
| 1112 | dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime && |
| 1113 | !ignore_hardlimit(dquot)) { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1114 | *warntype = QUOTA_NL_ISOFTLONGWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | return NO_QUOTA; |
| 1116 | } |
| 1117 | |
| 1118 | if (dquot->dq_dqb.dqb_isoftlimit && |
| 1119 | (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit && |
| 1120 | dquot->dq_dqb.dqb_itime == 0) { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1121 | *warntype = QUOTA_NL_ISOFTWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; |
| 1123 | } |
| 1124 | |
| 1125 | return QUOTA_OK; |
| 1126 | } |
| 1127 | |
| 1128 | /* needs dq_data_lock */ |
| 1129 | static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype) |
| 1130 | { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1131 | *warntype = QUOTA_NL_NOWARN; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1132 | if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || |
| 1133 | test_bit(DQ_FAKE_B, &dquot->dq_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | return QUOTA_OK; |
| 1135 | |
| 1136 | if (dquot->dq_dqb.dqb_bhardlimit && |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1137 | dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bhardlimit && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | !ignore_hardlimit(dquot)) { |
| 1139 | if (!prealloc) |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1140 | *warntype = QUOTA_NL_BHARDWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | return NO_QUOTA; |
| 1142 | } |
| 1143 | |
| 1144 | if (dquot->dq_dqb.dqb_bsoftlimit && |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1145 | dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime && |
| 1147 | !ignore_hardlimit(dquot)) { |
| 1148 | if (!prealloc) |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1149 | *warntype = QUOTA_NL_BSOFTLONGWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | return NO_QUOTA; |
| 1151 | } |
| 1152 | |
| 1153 | if (dquot->dq_dqb.dqb_bsoftlimit && |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1154 | dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | dquot->dq_dqb.dqb_btime == 0) { |
| 1156 | if (!prealloc) { |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1157 | *warntype = QUOTA_NL_BSOFTWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace; |
| 1159 | } |
| 1160 | else |
| 1161 | /* |
| 1162 | * We don't allow preallocation to exceed softlimit so exceeding will |
| 1163 | * be always printed |
| 1164 | */ |
| 1165 | return NO_QUOTA; |
| 1166 | } |
| 1167 | |
| 1168 | return QUOTA_OK; |
| 1169 | } |
| 1170 | |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1171 | static int info_idq_free(struct dquot *dquot, qsize_t inodes) |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1172 | { |
| 1173 | if (test_bit(DQ_FAKE_B, &dquot->dq_flags) || |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1174 | dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit || |
| 1175 | !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type)) |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1176 | return QUOTA_NL_NOWARN; |
| 1177 | |
| 1178 | if (dquot->dq_dqb.dqb_curinodes - inodes <= dquot->dq_dqb.dqb_isoftlimit) |
| 1179 | return QUOTA_NL_ISOFTBELOW; |
| 1180 | if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit && |
| 1181 | dquot->dq_dqb.dqb_curinodes - inodes < dquot->dq_dqb.dqb_ihardlimit) |
| 1182 | return QUOTA_NL_IHARDBELOW; |
| 1183 | return QUOTA_NL_NOWARN; |
| 1184 | } |
| 1185 | |
| 1186 | static int info_bdq_free(struct dquot *dquot, qsize_t space) |
| 1187 | { |
| 1188 | if (test_bit(DQ_FAKE_B, &dquot->dq_flags) || |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1189 | dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit) |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1190 | return QUOTA_NL_NOWARN; |
| 1191 | |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1192 | if (dquot->dq_dqb.dqb_curspace - space <= dquot->dq_dqb.dqb_bsoftlimit) |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1193 | return QUOTA_NL_BSOFTBELOW; |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1194 | if (dquot->dq_dqb.dqb_curspace >= dquot->dq_dqb.dqb_bhardlimit && |
| 1195 | dquot->dq_dqb.dqb_curspace - space < dquot->dq_dqb.dqb_bhardlimit) |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1196 | return QUOTA_NL_BHARDBELOW; |
| 1197 | return QUOTA_NL_NOWARN; |
| 1198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | /* |
| 1200 | * Initialize quota pointers in inode |
| 1201 | * Transaction must be started at entry |
| 1202 | */ |
| 1203 | int dquot_initialize(struct inode *inode, int type) |
| 1204 | { |
| 1205 | unsigned int id = 0; |
| 1206 | int cnt, ret = 0; |
| 1207 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1208 | /* First test before acquiring mutex - solves deadlocks when we |
| 1209 | * re-enter the quota code and are already holding the mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | if (IS_NOQUOTA(inode)) |
| 1211 | return 0; |
| 1212 | down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1213 | /* Having dqptr_sem we know NOQUOTA flags can't be altered... */ |
| 1214 | if (IS_NOQUOTA(inode)) |
| 1215 | goto out_err; |
| 1216 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1217 | if (type != -1 && cnt != type) |
| 1218 | continue; |
| 1219 | if (inode->i_dquot[cnt] == NODQUOT) { |
| 1220 | switch (cnt) { |
| 1221 | case USRQUOTA: |
| 1222 | id = inode->i_uid; |
| 1223 | break; |
| 1224 | case GRPQUOTA: |
| 1225 | id = inode->i_gid; |
| 1226 | break; |
| 1227 | } |
| 1228 | inode->i_dquot[cnt] = dqget(inode->i_sb, id, cnt); |
| 1229 | } |
| 1230 | } |
| 1231 | out_err: |
| 1232 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1233 | return ret; |
| 1234 | } |
| 1235 | |
| 1236 | /* |
| 1237 | * Release all quotas referenced by inode |
| 1238 | * Transaction must be started at an entry |
| 1239 | */ |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 1240 | int dquot_drop_locked(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
| 1242 | int cnt; |
| 1243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1245 | if (inode->i_dquot[cnt] != NODQUOT) { |
| 1246 | dqput(inode->i_dquot[cnt]); |
| 1247 | inode->i_dquot[cnt] = NODQUOT; |
| 1248 | } |
| 1249 | } |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | int dquot_drop(struct inode *inode) |
| 1254 | { |
| 1255 | down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1256 | dquot_drop_locked(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
Jan Kara | b85f4b8 | 2008-07-25 01:46:50 -0700 | [diff] [blame] | 1261 | /* Wrapper to remove references to quota structures from inode */ |
| 1262 | void vfs_dq_drop(struct inode *inode) |
| 1263 | { |
| 1264 | /* Here we can get arbitrary inode from clear_inode() so we have |
| 1265 | * to be careful. OTOH we don't need locking as quota operations |
| 1266 | * are allowed to change only at mount time */ |
| 1267 | if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op |
| 1268 | && inode->i_sb->dq_op->drop) { |
| 1269 | int cnt; |
| 1270 | /* Test before calling to rule out calls from proc and such |
| 1271 | * where we are not allowed to block. Note that this is |
| 1272 | * actually reliable test even without the lock - the caller |
| 1273 | * must assure that nobody can come after the DQUOT_DROP and |
| 1274 | * add quota pointers back anyway */ |
| 1275 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1276 | if (inode->i_dquot[cnt] != NODQUOT) |
| 1277 | break; |
| 1278 | if (cnt < MAXQUOTAS) |
| 1279 | inode->i_sb->dq_op->drop(inode); |
| 1280 | } |
| 1281 | } |
| 1282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | /* |
| 1284 | * Following four functions update i_blocks+i_bytes fields and |
| 1285 | * quota information (together with appropriate checks) |
| 1286 | * NOTE: We absolutely rely on the fact that caller dirties |
| 1287 | * the inode (usually macros in quotaops.h care about this) and |
| 1288 | * holds a handle for the current transaction so that dquot write and |
| 1289 | * inode write go into the same transaction. |
| 1290 | */ |
| 1291 | |
| 1292 | /* |
| 1293 | * This operation can block, but only after everything is updated |
| 1294 | */ |
| 1295 | int dquot_alloc_space(struct inode *inode, qsize_t number, int warn) |
| 1296 | { |
| 1297 | int cnt, ret = NO_QUOTA; |
| 1298 | char warntype[MAXQUOTAS]; |
| 1299 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1300 | /* First test before acquiring mutex - solves deadlocks when we |
| 1301 | * re-enter the quota code and are already holding the mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | if (IS_NOQUOTA(inode)) { |
| 1303 | out_add: |
| 1304 | inode_add_bytes(inode, number); |
| 1305 | return QUOTA_OK; |
| 1306 | } |
| 1307 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1308 | warntype[cnt] = QUOTA_NL_NOWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1311 | if (IS_NOQUOTA(inode)) { /* Now we can do reliable test... */ |
| 1312 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1313 | goto out_add; |
| 1314 | } |
| 1315 | spin_lock(&dq_data_lock); |
| 1316 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1317 | if (inode->i_dquot[cnt] == NODQUOT) |
| 1318 | continue; |
| 1319 | if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA) |
| 1320 | goto warn_put_all; |
| 1321 | } |
| 1322 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1323 | if (inode->i_dquot[cnt] == NODQUOT) |
| 1324 | continue; |
| 1325 | dquot_incr_space(inode->i_dquot[cnt], number); |
| 1326 | } |
| 1327 | inode_add_bytes(inode, number); |
| 1328 | ret = QUOTA_OK; |
| 1329 | warn_put_all: |
| 1330 | spin_unlock(&dq_data_lock); |
| 1331 | if (ret == QUOTA_OK) |
| 1332 | /* Dirtify all the dquots - this can block when journalling */ |
| 1333 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1334 | if (inode->i_dquot[cnt]) |
| 1335 | mark_dquot_dirty(inode->i_dquot[cnt]); |
| 1336 | flush_warnings(inode->i_dquot, warntype); |
| 1337 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1338 | return ret; |
| 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * This operation can block, but only after everything is updated |
| 1343 | */ |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1344 | int dquot_alloc_inode(const struct inode *inode, qsize_t number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | { |
| 1346 | int cnt, ret = NO_QUOTA; |
| 1347 | char warntype[MAXQUOTAS]; |
| 1348 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1349 | /* First test before acquiring mutex - solves deadlocks when we |
| 1350 | * re-enter the quota code and are already holding the mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | if (IS_NOQUOTA(inode)) |
| 1352 | return QUOTA_OK; |
| 1353 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 1354 | warntype[cnt] = QUOTA_NL_NOWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1356 | if (IS_NOQUOTA(inode)) { |
| 1357 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1358 | return QUOTA_OK; |
| 1359 | } |
| 1360 | spin_lock(&dq_data_lock); |
| 1361 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1362 | if (inode->i_dquot[cnt] == NODQUOT) |
| 1363 | continue; |
| 1364 | if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA) |
| 1365 | goto warn_put_all; |
| 1366 | } |
| 1367 | |
| 1368 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1369 | if (inode->i_dquot[cnt] == NODQUOT) |
| 1370 | continue; |
| 1371 | dquot_incr_inodes(inode->i_dquot[cnt], number); |
| 1372 | } |
| 1373 | ret = QUOTA_OK; |
| 1374 | warn_put_all: |
| 1375 | spin_unlock(&dq_data_lock); |
| 1376 | if (ret == QUOTA_OK) |
| 1377 | /* Dirtify all the dquots - this can block when journalling */ |
| 1378 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1379 | if (inode->i_dquot[cnt]) |
| 1380 | mark_dquot_dirty(inode->i_dquot[cnt]); |
Jan Kara | 087ee8d | 2007-12-17 16:20:26 -0800 | [diff] [blame] | 1381 | flush_warnings(inode->i_dquot, warntype); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1383 | return ret; |
| 1384 | } |
| 1385 | |
| 1386 | /* |
| 1387 | * This operation can block, but only after everything is updated |
| 1388 | */ |
| 1389 | int dquot_free_space(struct inode *inode, qsize_t number) |
| 1390 | { |
| 1391 | unsigned int cnt; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1392 | char warntype[MAXQUOTAS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1394 | /* First test before acquiring mutex - solves deadlocks when we |
| 1395 | * re-enter the quota code and are already holding the mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | if (IS_NOQUOTA(inode)) { |
| 1397 | out_sub: |
| 1398 | inode_sub_bytes(inode, number); |
| 1399 | return QUOTA_OK; |
| 1400 | } |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1403 | /* Now recheck reliably when holding dqptr_sem */ |
| 1404 | if (IS_NOQUOTA(inode)) { |
| 1405 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1406 | goto out_sub; |
| 1407 | } |
| 1408 | spin_lock(&dq_data_lock); |
| 1409 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1410 | if (inode->i_dquot[cnt] == NODQUOT) |
| 1411 | continue; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1412 | warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | dquot_decr_space(inode->i_dquot[cnt], number); |
| 1414 | } |
| 1415 | inode_sub_bytes(inode, number); |
| 1416 | spin_unlock(&dq_data_lock); |
| 1417 | /* Dirtify all the dquots - this can block when journalling */ |
| 1418 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1419 | if (inode->i_dquot[cnt]) |
| 1420 | mark_dquot_dirty(inode->i_dquot[cnt]); |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1421 | flush_warnings(inode->i_dquot, warntype); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1423 | return QUOTA_OK; |
| 1424 | } |
| 1425 | |
| 1426 | /* |
| 1427 | * This operation can block, but only after everything is updated |
| 1428 | */ |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 1429 | int dquot_free_inode(const struct inode *inode, qsize_t number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | { |
| 1431 | unsigned int cnt; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1432 | char warntype[MAXQUOTAS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1434 | /* First test before acquiring mutex - solves deadlocks when we |
| 1435 | * re-enter the quota code and are already holding the mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | if (IS_NOQUOTA(inode)) |
| 1437 | return QUOTA_OK; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1440 | /* Now recheck reliably when holding dqptr_sem */ |
| 1441 | if (IS_NOQUOTA(inode)) { |
| 1442 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1443 | return QUOTA_OK; |
| 1444 | } |
| 1445 | spin_lock(&dq_data_lock); |
| 1446 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1447 | if (inode->i_dquot[cnt] == NODQUOT) |
| 1448 | continue; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1449 | warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | dquot_decr_inodes(inode->i_dquot[cnt], number); |
| 1451 | } |
| 1452 | spin_unlock(&dq_data_lock); |
| 1453 | /* Dirtify all the dquots - this can block when journalling */ |
| 1454 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1455 | if (inode->i_dquot[cnt]) |
| 1456 | mark_dquot_dirty(inode->i_dquot[cnt]); |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1457 | flush_warnings(inode->i_dquot, warntype); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1459 | return QUOTA_OK; |
| 1460 | } |
| 1461 | |
| 1462 | /* |
| 1463 | * Transfer the number of inode and blocks from one diskquota to an other. |
| 1464 | * |
| 1465 | * This operation can block, but only after everything is updated |
| 1466 | * A transaction must be started when entering this function. |
| 1467 | */ |
| 1468 | int dquot_transfer(struct inode *inode, struct iattr *iattr) |
| 1469 | { |
| 1470 | qsize_t space; |
| 1471 | struct dquot *transfer_from[MAXQUOTAS]; |
| 1472 | struct dquot *transfer_to[MAXQUOTAS]; |
| 1473 | int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid, |
| 1474 | chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1475 | char warntype_to[MAXQUOTAS]; |
| 1476 | char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1478 | /* First test before acquiring mutex - solves deadlocks when we |
| 1479 | * re-enter the quota code and are already holding the mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | if (IS_NOQUOTA(inode)) |
| 1481 | return QUOTA_OK; |
| 1482 | /* Clear the arrays */ |
| 1483 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1484 | transfer_to[cnt] = transfer_from[cnt] = NODQUOT; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1485 | warntype_to[cnt] = QUOTA_NL_NOWARN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | } |
| 1487 | down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1488 | /* Now recheck reliably when holding dqptr_sem */ |
| 1489 | if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ |
| 1490 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1491 | return QUOTA_OK; |
| 1492 | } |
| 1493 | /* First build the transfer_to list - here we can block on |
| 1494 | * reading/instantiating of dquots. We know that the transaction for |
| 1495 | * us was already started so we don't violate lock ranking here */ |
| 1496 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1497 | switch (cnt) { |
| 1498 | case USRQUOTA: |
| 1499 | if (!chuid) |
| 1500 | continue; |
| 1501 | transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt); |
| 1502 | break; |
| 1503 | case GRPQUOTA: |
| 1504 | if (!chgid) |
| 1505 | continue; |
| 1506 | transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt); |
| 1507 | break; |
| 1508 | } |
| 1509 | } |
| 1510 | spin_lock(&dq_data_lock); |
| 1511 | space = inode_get_bytes(inode); |
| 1512 | /* Build the transfer_from list and check the limits */ |
| 1513 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1514 | if (transfer_to[cnt] == NODQUOT) |
| 1515 | continue; |
| 1516 | transfer_from[cnt] = inode->i_dquot[cnt]; |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1517 | if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) == |
| 1518 | NO_QUOTA || check_bdq(transfer_to[cnt], space, 0, |
| 1519 | warntype_to + cnt) == NO_QUOTA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | goto warn_put_all; |
| 1521 | } |
| 1522 | |
| 1523 | /* |
| 1524 | * Finally perform the needed transfer from transfer_from to transfer_to |
| 1525 | */ |
| 1526 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1527 | /* |
| 1528 | * Skip changes for same uid or gid or for turned off quota-type. |
| 1529 | */ |
| 1530 | if (transfer_to[cnt] == NODQUOT) |
| 1531 | continue; |
| 1532 | |
| 1533 | /* Due to IO error we might not have transfer_from[] structure */ |
| 1534 | if (transfer_from[cnt]) { |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1535 | warntype_from_inodes[cnt] = |
| 1536 | info_idq_free(transfer_from[cnt], 1); |
| 1537 | warntype_from_space[cnt] = |
| 1538 | info_bdq_free(transfer_from[cnt], space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | dquot_decr_inodes(transfer_from[cnt], 1); |
| 1540 | dquot_decr_space(transfer_from[cnt], space); |
| 1541 | } |
| 1542 | |
| 1543 | dquot_incr_inodes(transfer_to[cnt], 1); |
| 1544 | dquot_incr_space(transfer_to[cnt], space); |
| 1545 | |
| 1546 | inode->i_dquot[cnt] = transfer_to[cnt]; |
| 1547 | } |
| 1548 | ret = QUOTA_OK; |
| 1549 | warn_put_all: |
| 1550 | spin_unlock(&dq_data_lock); |
| 1551 | /* Dirtify all the dquots - this can block when journalling */ |
| 1552 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1553 | if (transfer_from[cnt]) |
| 1554 | mark_dquot_dirty(transfer_from[cnt]); |
| 1555 | if (transfer_to[cnt]) |
| 1556 | mark_dquot_dirty(transfer_to[cnt]); |
| 1557 | } |
Jan Kara | 657d3bf | 2008-07-25 01:46:52 -0700 | [diff] [blame] | 1558 | flush_warnings(transfer_to, warntype_to); |
| 1559 | flush_warnings(transfer_from, warntype_from_inodes); |
| 1560 | flush_warnings(transfer_from, warntype_from_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | |
| 1562 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1563 | if (ret == QUOTA_OK && transfer_from[cnt] != NODQUOT) |
| 1564 | dqput(transfer_from[cnt]); |
| 1565 | if (ret == NO_QUOTA && transfer_to[cnt] != NODQUOT) |
| 1566 | dqput(transfer_to[cnt]); |
| 1567 | } |
| 1568 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
| 1569 | return ret; |
| 1570 | } |
| 1571 | |
Jan Kara | b85f4b8 | 2008-07-25 01:46:50 -0700 | [diff] [blame] | 1572 | /* Wrapper for transferring ownership of an inode */ |
| 1573 | int vfs_dq_transfer(struct inode *inode, struct iattr *iattr) |
| 1574 | { |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1575 | if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) { |
Jan Kara | b85f4b8 | 2008-07-25 01:46:50 -0700 | [diff] [blame] | 1576 | vfs_dq_init(inode); |
| 1577 | if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA) |
| 1578 | return 1; |
| 1579 | } |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | /* |
| 1585 | * Write info of quota file to disk |
| 1586 | */ |
| 1587 | int dquot_commit_info(struct super_block *sb, int type) |
| 1588 | { |
| 1589 | int ret; |
| 1590 | struct quota_info *dqopt = sb_dqopt(sb); |
| 1591 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1592 | mutex_lock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | ret = dqopt->ops[type]->write_file_info(sb, type); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1594 | mutex_unlock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | /* |
| 1599 | * Definitions of diskquota operations. |
| 1600 | */ |
| 1601 | struct dquot_operations dquot_operations = { |
| 1602 | .initialize = dquot_initialize, |
| 1603 | .drop = dquot_drop, |
| 1604 | .alloc_space = dquot_alloc_space, |
| 1605 | .alloc_inode = dquot_alloc_inode, |
| 1606 | .free_space = dquot_free_space, |
| 1607 | .free_inode = dquot_free_inode, |
| 1608 | .transfer = dquot_transfer, |
| 1609 | .write_dquot = dquot_commit, |
| 1610 | .acquire_dquot = dquot_acquire, |
| 1611 | .release_dquot = dquot_release, |
| 1612 | .mark_dirty = dquot_mark_dquot_dirty, |
Jan Kara | 74f783a | 2008-08-19 14:51:22 +0200 | [diff] [blame] | 1613 | .write_info = dquot_commit_info, |
| 1614 | .alloc_dquot = dquot_alloc, |
| 1615 | .destroy_dquot = dquot_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | }; |
| 1617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | /* |
| 1619 | * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) |
| 1620 | */ |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1621 | int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1623 | int cnt, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | struct quota_info *dqopt = sb_dqopt(sb); |
| 1625 | struct inode *toputinode[MAXQUOTAS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1627 | /* Cannot turn off usage accounting without turning off limits, or |
| 1628 | * suspend quotas and simultaneously turn quotas off. */ |
| 1629 | if ((flags & DQUOT_USAGE_ENABLED && !(flags & DQUOT_LIMITS_ENABLED)) |
| 1630 | || (flags & DQUOT_SUSPENDED && flags & (DQUOT_LIMITS_ENABLED | |
| 1631 | DQUOT_USAGE_ENABLED))) |
| 1632 | return -EINVAL; |
| 1633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | /* We need to serialize quota_off() for device */ |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1635 | mutex_lock(&dqopt->dqonoff_mutex); |
Jan Kara | 9377abd | 2008-05-12 14:02:08 -0700 | [diff] [blame] | 1636 | |
| 1637 | /* |
| 1638 | * Skip everything if there's nothing to do. We have to do this because |
| 1639 | * sometimes we are called when fill_super() failed and calling |
| 1640 | * sync_fs() in such cases does no good. |
| 1641 | */ |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1642 | if (!sb_any_quota_loaded(sb)) { |
Jan Kara | 9377abd | 2008-05-12 14:02:08 -0700 | [diff] [blame] | 1643 | mutex_unlock(&dqopt->dqonoff_mutex); |
| 1644 | return 0; |
| 1645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1647 | toputinode[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | if (type != -1 && cnt != type) |
| 1649 | continue; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1650 | if (!sb_has_quota_loaded(sb, cnt)) |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1651 | continue; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1652 | |
| 1653 | if (flags & DQUOT_SUSPENDED) { |
| 1654 | dqopt->flags |= |
| 1655 | dquot_state_flag(DQUOT_SUSPENDED, cnt); |
| 1656 | } else { |
| 1657 | dqopt->flags &= ~dquot_state_flag(flags, cnt); |
| 1658 | /* Turning off suspended quotas? */ |
| 1659 | if (!sb_has_quota_loaded(sb, cnt) && |
| 1660 | sb_has_quota_suspended(sb, cnt)) { |
| 1661 | dqopt->flags &= ~dquot_state_flag( |
| 1662 | DQUOT_SUSPENDED, cnt); |
| 1663 | iput(dqopt->files[cnt]); |
| 1664 | dqopt->files[cnt] = NULL; |
| 1665 | continue; |
| 1666 | } |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1667 | } |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1668 | |
| 1669 | /* We still have to keep quota loaded? */ |
| 1670 | if (sb_has_quota_loaded(sb, cnt) && !(flags & DQUOT_SUSPENDED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | |
| 1673 | /* Note: these are blocking operations */ |
| 1674 | drop_dquot_ref(sb, cnt); |
| 1675 | invalidate_dquots(sb, cnt); |
| 1676 | /* |
| 1677 | * Now all dquots should be invalidated, all writes done so we should be only |
| 1678 | * users of the info. No locks needed. |
| 1679 | */ |
| 1680 | if (info_dirty(&dqopt->info[cnt])) |
| 1681 | sb->dq_op->write_info(sb, cnt); |
| 1682 | if (dqopt->ops[cnt]->free_file_info) |
| 1683 | dqopt->ops[cnt]->free_file_info(sb, cnt); |
| 1684 | put_quota_format(dqopt->info[cnt].dqi_format); |
| 1685 | |
| 1686 | toputinode[cnt] = dqopt->files[cnt]; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1687 | if (!sb_has_quota_loaded(sb, cnt)) |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1688 | dqopt->files[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | dqopt->info[cnt].dqi_flags = 0; |
| 1690 | dqopt->info[cnt].dqi_igrace = 0; |
| 1691 | dqopt->info[cnt].dqi_bgrace = 0; |
| 1692 | dqopt->ops[cnt] = NULL; |
| 1693 | } |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1694 | mutex_unlock(&dqopt->dqonoff_mutex); |
Jan Kara | ca785ec | 2008-09-30 17:53:37 +0200 | [diff] [blame] | 1695 | |
| 1696 | /* Skip syncing and setting flags if quota files are hidden */ |
| 1697 | if (dqopt->flags & DQUOT_QUOTA_SYS_FILE) |
| 1698 | goto put_inodes; |
| 1699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | /* Sync the superblock so that buffers with quota data are written to |
Al Viro | 7b7b1ac | 2005-11-07 17:13:39 -0500 | [diff] [blame] | 1701 | * disk (and so userspace sees correct data afterwards). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | if (sb->s_op->sync_fs) |
| 1703 | sb->s_op->sync_fs(sb, 1); |
| 1704 | sync_blockdev(sb->s_bdev); |
| 1705 | /* Now the quota files are just ordinary files and we can set the |
| 1706 | * inode flags back. Moreover we discard the pagecache so that |
| 1707 | * userspace sees the writes we did bypassing the pagecache. We |
| 1708 | * must also discard the blockdev buffers so that we see the |
| 1709 | * changes done by userspace on the next quotaon() */ |
| 1710 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1711 | if (toputinode[cnt]) { |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1712 | mutex_lock(&dqopt->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | /* If quota was reenabled in the meantime, we have |
| 1714 | * nothing to do */ |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1715 | if (!sb_has_quota_loaded(sb, cnt)) { |
Jan Kara | 7925409 | 2007-05-16 22:11:19 -0700 | [diff] [blame] | 1716 | mutex_lock_nested(&toputinode[cnt]->i_mutex, I_MUTEX_QUOTA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | toputinode[cnt]->i_flags &= ~(S_IMMUTABLE | |
| 1718 | S_NOATIME | S_NOQUOTA); |
| 1719 | truncate_inode_pages(&toputinode[cnt]->i_data, 0); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 1720 | mutex_unlock(&toputinode[cnt]->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | mark_inode_dirty(toputinode[cnt]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | } |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1723 | mutex_unlock(&dqopt->dqonoff_mutex); |
Jan Kara | ca785ec | 2008-09-30 17:53:37 +0200 | [diff] [blame] | 1724 | } |
| 1725 | if (sb->s_bdev) |
| 1726 | invalidate_bdev(sb->s_bdev); |
| 1727 | put_inodes: |
| 1728 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 1729 | if (toputinode[cnt]) { |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1730 | /* On remount RO, we keep the inode pointer so that we |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1731 | * can reenable quota on the subsequent remount RW. We |
| 1732 | * have to check 'flags' variable and not use sb_has_ |
| 1733 | * function because another quotaon / quotaoff could |
| 1734 | * change global state before we got here. We refuse |
| 1735 | * to suspend quotas when there is pending delete on |
| 1736 | * the quota file... */ |
| 1737 | if (!(flags & DQUOT_SUSPENDED)) |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1738 | iput(toputinode[cnt]); |
| 1739 | else if (!toputinode[cnt]->i_nlink) |
| 1740 | ret = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | } |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1742 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1745 | int vfs_quota_off(struct super_block *sb, int type, int remount) |
| 1746 | { |
| 1747 | return vfs_quota_disable(sb, type, remount ? DQUOT_SUSPENDED : |
| 1748 | (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED)); |
| 1749 | } |
| 1750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | /* |
| 1752 | * Turn quotas on on a device |
| 1753 | */ |
| 1754 | |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1755 | /* |
| 1756 | * Helper function to turn quotas on when we already have the inode of |
| 1757 | * quota file and no quota information is loaded. |
| 1758 | */ |
| 1759 | static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, |
| 1760 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | { |
| 1762 | struct quota_format_type *fmt = find_quota_format(format_id); |
| 1763 | struct super_block *sb = inode->i_sb; |
| 1764 | struct quota_info *dqopt = sb_dqopt(sb); |
| 1765 | int error; |
| 1766 | int oldflags = -1; |
| 1767 | |
| 1768 | if (!fmt) |
| 1769 | return -ESRCH; |
| 1770 | if (!S_ISREG(inode->i_mode)) { |
| 1771 | error = -EACCES; |
| 1772 | goto out_fmt; |
| 1773 | } |
| 1774 | if (IS_RDONLY(inode)) { |
| 1775 | error = -EROFS; |
| 1776 | goto out_fmt; |
| 1777 | } |
| 1778 | if (!sb->s_op->quota_write || !sb->s_op->quota_read) { |
| 1779 | error = -EINVAL; |
| 1780 | goto out_fmt; |
| 1781 | } |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1782 | /* Usage always has to be set... */ |
| 1783 | if (!(flags & DQUOT_USAGE_ENABLED)) { |
| 1784 | error = -EINVAL; |
| 1785 | goto out_fmt; |
| 1786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Jan Kara | ca785ec | 2008-09-30 17:53:37 +0200 | [diff] [blame] | 1788 | if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
| 1789 | /* As we bypass the pagecache we must now flush the inode so |
| 1790 | * that we see all the changes from userspace... */ |
| 1791 | write_inode_now(inode, 1); |
| 1792 | /* And now flush the block cache so that kernel sees the |
| 1793 | * changes */ |
| 1794 | invalidate_bdev(sb->s_bdev); |
| 1795 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 1796 | mutex_lock(&inode->i_mutex); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1797 | mutex_lock(&dqopt->dqonoff_mutex); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1798 | if (sb_has_quota_loaded(sb, type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | error = -EBUSY; |
| 1800 | goto out_lock; |
| 1801 | } |
Jan Kara | ca785ec | 2008-09-30 17:53:37 +0200 | [diff] [blame] | 1802 | |
| 1803 | if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
| 1804 | /* We don't want quota and atime on quota files (deadlocks |
| 1805 | * possible) Also nobody should write to the file - we use |
| 1806 | * special IO operations which ignore the immutable bit. */ |
| 1807 | down_write(&dqopt->dqptr_sem); |
| 1808 | oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | S_NOQUOTA); |
| 1809 | inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE; |
| 1810 | up_write(&dqopt->dqptr_sem); |
| 1811 | sb->dq_op->drop(inode); |
| 1812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
| 1814 | error = -EIO; |
| 1815 | dqopt->files[type] = igrab(inode); |
| 1816 | if (!dqopt->files[type]) |
| 1817 | goto out_lock; |
| 1818 | error = -EINVAL; |
| 1819 | if (!fmt->qf_ops->check_quota_file(sb, type)) |
| 1820 | goto out_file_init; |
| 1821 | |
| 1822 | dqopt->ops[type] = fmt->qf_ops; |
| 1823 | dqopt->info[type].dqi_format = fmt; |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1824 | dqopt->info[type].dqi_fmt_id = format_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1826 | mutex_lock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) { |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1828 | mutex_unlock(&dqopt->dqio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | goto out_file_init; |
| 1830 | } |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1831 | mutex_unlock(&dqopt->dqio_mutex); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 1832 | mutex_unlock(&inode->i_mutex); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1833 | dqopt->flags |= dquot_state_flag(flags, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | |
| 1835 | add_dquot_ref(sb, type); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1836 | mutex_unlock(&dqopt->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
| 1838 | return 0; |
| 1839 | |
| 1840 | out_file_init: |
| 1841 | dqopt->files[type] = NULL; |
| 1842 | iput(inode); |
| 1843 | out_lock: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 1844 | mutex_unlock(&dqopt->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | if (oldflags != -1) { |
| 1846 | down_write(&dqopt->dqptr_sem); |
| 1847 | /* Set the flags back (in the case of accidental quotaon() |
| 1848 | * on a wrong file we don't want to mess up the flags) */ |
| 1849 | inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE); |
| 1850 | inode->i_flags |= oldflags; |
| 1851 | up_write(&dqopt->dqptr_sem); |
| 1852 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 1853 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | out_fmt: |
| 1855 | put_quota_format(fmt); |
| 1856 | |
| 1857 | return error; |
| 1858 | } |
| 1859 | |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1860 | /* Reenable quotas on remount RW */ |
| 1861 | static int vfs_quota_on_remount(struct super_block *sb, int type) |
| 1862 | { |
| 1863 | struct quota_info *dqopt = sb_dqopt(sb); |
| 1864 | struct inode *inode; |
| 1865 | int ret; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1866 | unsigned int flags; |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1867 | |
| 1868 | mutex_lock(&dqopt->dqonoff_mutex); |
| 1869 | if (!sb_has_quota_suspended(sb, type)) { |
| 1870 | mutex_unlock(&dqopt->dqonoff_mutex); |
| 1871 | return 0; |
| 1872 | } |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1873 | inode = dqopt->files[type]; |
| 1874 | dqopt->files[type] = NULL; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1875 | flags = dqopt->flags & dquot_state_flag(DQUOT_USAGE_ENABLED | |
| 1876 | DQUOT_LIMITS_ENABLED, type); |
| 1877 | dqopt->flags &= ~dquot_state_flag(DQUOT_STATE_FLAGS, type); |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1878 | mutex_unlock(&dqopt->dqonoff_mutex); |
| 1879 | |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1880 | flags = dquot_generic_flag(flags, type); |
| 1881 | ret = vfs_load_quota_inode(inode, type, dqopt->info[type].dqi_fmt_id, |
| 1882 | flags); |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1883 | iput(inode); |
| 1884 | |
| 1885 | return ret; |
| 1886 | } |
| 1887 | |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 1888 | int vfs_quota_on_path(struct super_block *sb, int type, int format_id, |
| 1889 | struct path *path) |
| 1890 | { |
| 1891 | int error = security_quota_on(path->dentry); |
| 1892 | if (error) |
| 1893 | return error; |
| 1894 | /* Quota file not on the same filesystem? */ |
| 1895 | if (path->mnt->mnt_sb != sb) |
| 1896 | error = -EXDEV; |
| 1897 | else |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1898 | error = vfs_load_quota_inode(path->dentry->d_inode, type, |
| 1899 | format_id, DQUOT_USAGE_ENABLED | |
| 1900 | DQUOT_LIMITS_ENABLED); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 1901 | return error; |
| 1902 | } |
| 1903 | |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 1904 | int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name, |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1905 | int remount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | { |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 1907 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | int error; |
| 1909 | |
Jan Kara | 0ff5af8 | 2008-04-28 02:14:33 -0700 | [diff] [blame] | 1910 | if (remount) |
| 1911 | return vfs_quota_on_remount(sb, type); |
| 1912 | |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 1913 | error = kern_path(name, LOOKUP_FOLLOW, &path); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 1914 | if (!error) { |
Al Viro | 8264613 | 2008-08-02 00:57:06 -0400 | [diff] [blame] | 1915 | error = vfs_quota_on_path(sb, type, format_id, &path); |
| 1916 | path_put(&path); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 1917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | return error; |
| 1919 | } |
| 1920 | |
| 1921 | /* |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1922 | * More powerful function for turning on quotas allowing setting |
| 1923 | * of individual quota flags |
| 1924 | */ |
| 1925 | int vfs_quota_enable(struct inode *inode, int type, int format_id, |
| 1926 | unsigned int flags) |
| 1927 | { |
| 1928 | int ret = 0; |
| 1929 | struct super_block *sb = inode->i_sb; |
| 1930 | struct quota_info *dqopt = sb_dqopt(sb); |
| 1931 | |
| 1932 | /* Just unsuspend quotas? */ |
| 1933 | if (flags & DQUOT_SUSPENDED) |
| 1934 | return vfs_quota_on_remount(sb, type); |
| 1935 | if (!flags) |
| 1936 | return 0; |
| 1937 | /* Just updating flags needed? */ |
| 1938 | if (sb_has_quota_loaded(sb, type)) { |
| 1939 | mutex_lock(&dqopt->dqonoff_mutex); |
| 1940 | /* Now do a reliable test... */ |
| 1941 | if (!sb_has_quota_loaded(sb, type)) { |
| 1942 | mutex_unlock(&dqopt->dqonoff_mutex); |
| 1943 | goto load_quota; |
| 1944 | } |
| 1945 | if (flags & DQUOT_USAGE_ENABLED && |
| 1946 | sb_has_quota_usage_enabled(sb, type)) { |
| 1947 | ret = -EBUSY; |
| 1948 | goto out_lock; |
| 1949 | } |
| 1950 | if (flags & DQUOT_LIMITS_ENABLED && |
| 1951 | sb_has_quota_limits_enabled(sb, type)) { |
| 1952 | ret = -EBUSY; |
| 1953 | goto out_lock; |
| 1954 | } |
| 1955 | sb_dqopt(sb)->flags |= dquot_state_flag(flags, type); |
| 1956 | out_lock: |
| 1957 | mutex_unlock(&dqopt->dqonoff_mutex); |
| 1958 | return ret; |
| 1959 | } |
| 1960 | |
| 1961 | load_quota: |
| 1962 | return vfs_load_quota_inode(inode, type, format_id, flags); |
| 1963 | } |
| 1964 | |
| 1965 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | * This function is used when filesystem needs to initialize quotas |
| 1967 | * during mount time. |
| 1968 | */ |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1969 | int vfs_quota_on_mount(struct super_block *sb, char *qf_name, |
| 1970 | int format_id, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | { |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1972 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | int error; |
| 1974 | |
Christoph Hellwig | 2fa389c | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1975 | dentry = lookup_one_len(qf_name, sb->s_root, strlen(qf_name)); |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1976 | if (IS_ERR(dentry)) |
| 1977 | return PTR_ERR(dentry); |
| 1978 | |
Jan Kara | 154f484 | 2005-11-28 13:44:14 -0800 | [diff] [blame] | 1979 | if (!dentry->d_inode) { |
| 1980 | error = -ENOENT; |
| 1981 | goto out; |
| 1982 | } |
| 1983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | error = security_quota_on(dentry); |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1985 | if (!error) |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 1986 | error = vfs_load_quota_inode(dentry->d_inode, type, format_id, |
| 1987 | DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1988 | |
Jan Kara | 154f484 | 2005-11-28 13:44:14 -0800 | [diff] [blame] | 1989 | out: |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 1990 | dput(dentry); |
| 1991 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Jan Kara | b85f4b8 | 2008-07-25 01:46:50 -0700 | [diff] [blame] | 1994 | /* Wrapper to turn on quotas when remounting rw */ |
| 1995 | int vfs_dq_quota_on_remount(struct super_block *sb) |
| 1996 | { |
| 1997 | int cnt; |
| 1998 | int ret = 0, err; |
| 1999 | |
| 2000 | if (!sb->s_qcop || !sb->s_qcop->quota_on) |
| 2001 | return -ENOSYS; |
| 2002 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 2003 | err = sb->s_qcop->quota_on(sb, cnt, 0, NULL, 1); |
| 2004 | if (err < 0 && !ret) |
| 2005 | ret = err; |
| 2006 | } |
| 2007 | return ret; |
| 2008 | } |
| 2009 | |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 2010 | static inline qsize_t qbtos(qsize_t blocks) |
| 2011 | { |
| 2012 | return blocks << QIF_DQBLKSIZE_BITS; |
| 2013 | } |
| 2014 | |
| 2015 | static inline qsize_t stoqb(qsize_t space) |
| 2016 | { |
| 2017 | return (space + QIF_DQBLKSIZE - 1) >> QIF_DQBLKSIZE_BITS; |
| 2018 | } |
| 2019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | /* Generic routine for getting common part of quota structure */ |
| 2021 | static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di) |
| 2022 | { |
| 2023 | struct mem_dqblk *dm = &dquot->dq_dqb; |
| 2024 | |
| 2025 | spin_lock(&dq_data_lock); |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 2026 | di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit); |
| 2027 | di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | di->dqb_curspace = dm->dqb_curspace; |
| 2029 | di->dqb_ihardlimit = dm->dqb_ihardlimit; |
| 2030 | di->dqb_isoftlimit = dm->dqb_isoftlimit; |
| 2031 | di->dqb_curinodes = dm->dqb_curinodes; |
| 2032 | di->dqb_btime = dm->dqb_btime; |
| 2033 | di->dqb_itime = dm->dqb_itime; |
| 2034 | di->dqb_valid = QIF_ALL; |
| 2035 | spin_unlock(&dq_data_lock); |
| 2036 | } |
| 2037 | |
| 2038 | int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di) |
| 2039 | { |
| 2040 | struct dquot *dquot; |
| 2041 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2042 | mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | if (!(dquot = dqget(sb, id, type))) { |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2044 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | return -ESRCH; |
| 2046 | } |
| 2047 | do_get_dqblk(dquot, di); |
| 2048 | dqput(dquot); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2049 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | return 0; |
| 2051 | } |
| 2052 | |
| 2053 | /* Generic routine for setting common part of quota structure */ |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2054 | static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | { |
| 2056 | struct mem_dqblk *dm = &dquot->dq_dqb; |
| 2057 | int check_blim = 0, check_ilim = 0; |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2058 | struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; |
| 2059 | |
| 2060 | if ((di->dqb_valid & QIF_BLIMITS && |
| 2061 | (di->dqb_bhardlimit > dqi->dqi_maxblimit || |
| 2062 | di->dqb_bsoftlimit > dqi->dqi_maxblimit)) || |
| 2063 | (di->dqb_valid & QIF_ILIMITS && |
| 2064 | (di->dqb_ihardlimit > dqi->dqi_maxilimit || |
| 2065 | di->dqb_isoftlimit > dqi->dqi_maxilimit))) |
| 2066 | return -ERANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
| 2068 | spin_lock(&dq_data_lock); |
| 2069 | if (di->dqb_valid & QIF_SPACE) { |
| 2070 | dm->dqb_curspace = di->dqb_curspace; |
| 2071 | check_blim = 1; |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2072 | __set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
| 2074 | if (di->dqb_valid & QIF_BLIMITS) { |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 2075 | dm->dqb_bsoftlimit = qbtos(di->dqb_bsoftlimit); |
| 2076 | dm->dqb_bhardlimit = qbtos(di->dqb_bhardlimit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | check_blim = 1; |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2078 | __set_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | } |
| 2080 | if (di->dqb_valid & QIF_INODES) { |
| 2081 | dm->dqb_curinodes = di->dqb_curinodes; |
| 2082 | check_ilim = 1; |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2083 | __set_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | } |
| 2085 | if (di->dqb_valid & QIF_ILIMITS) { |
| 2086 | dm->dqb_isoftlimit = di->dqb_isoftlimit; |
| 2087 | dm->dqb_ihardlimit = di->dqb_ihardlimit; |
| 2088 | check_ilim = 1; |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2089 | __set_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | } |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2091 | if (di->dqb_valid & QIF_BTIME) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | dm->dqb_btime = di->dqb_btime; |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2093 | __set_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags); |
| 2094 | } |
| 2095 | if (di->dqb_valid & QIF_ITIME) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | dm->dqb_itime = di->dqb_itime; |
Jan Kara | 4d59bce | 2008-10-02 16:48:10 +0200 | [diff] [blame] | 2097 | __set_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags); |
| 2098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
| 2100 | if (check_blim) { |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 2101 | if (!dm->dqb_bsoftlimit || dm->dqb_curspace < dm->dqb_bsoftlimit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | dm->dqb_btime = 0; |
| 2103 | clear_bit(DQ_BLKS_B, &dquot->dq_flags); |
| 2104 | } |
| 2105 | else if (!(di->dqb_valid & QIF_BTIME)) /* Set grace only if user hasn't provided his own... */ |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2106 | dm->dqb_btime = get_seconds() + dqi->dqi_bgrace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | } |
| 2108 | if (check_ilim) { |
| 2109 | if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) { |
| 2110 | dm->dqb_itime = 0; |
| 2111 | clear_bit(DQ_INODES_B, &dquot->dq_flags); |
| 2112 | } |
| 2113 | else if (!(di->dqb_valid & QIF_ITIME)) /* Set grace only if user hasn't provided his own... */ |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2114 | dm->dqb_itime = get_seconds() + dqi->dqi_igrace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | } |
| 2116 | if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit) |
| 2117 | clear_bit(DQ_FAKE_B, &dquot->dq_flags); |
| 2118 | else |
| 2119 | set_bit(DQ_FAKE_B, &dquot->dq_flags); |
| 2120 | spin_unlock(&dq_data_lock); |
| 2121 | mark_dquot_dirty(dquot); |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2122 | |
| 2123 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di) |
| 2127 | { |
| 2128 | struct dquot *dquot; |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2129 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2131 | mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2132 | dquot = dqget(sb, id, type); |
| 2133 | if (!dquot) { |
| 2134 | rc = -ESRCH; |
| 2135 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | } |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2137 | rc = do_set_dqblk(dquot, di); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | dqput(dquot); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2139 | out: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2140 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
Andrew Perepechko | 338bf9a | 2008-04-28 02:14:31 -0700 | [diff] [blame] | 2141 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | /* Generic routine for getting common part of quota file information */ |
| 2145 | int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii) |
| 2146 | { |
| 2147 | struct mem_dqinfo *mi; |
| 2148 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2149 | mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2150 | if (!sb_has_quota_active(sb, type)) { |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2151 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | return -ESRCH; |
| 2153 | } |
| 2154 | mi = sb_dqopt(sb)->info + type; |
| 2155 | spin_lock(&dq_data_lock); |
| 2156 | ii->dqi_bgrace = mi->dqi_bgrace; |
| 2157 | ii->dqi_igrace = mi->dqi_igrace; |
| 2158 | ii->dqi_flags = mi->dqi_flags & DQF_MASK; |
| 2159 | ii->dqi_valid = IIF_ALL; |
| 2160 | spin_unlock(&dq_data_lock); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2161 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | return 0; |
| 2163 | } |
| 2164 | |
| 2165 | /* Generic routine for setting common part of quota file information */ |
| 2166 | int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii) |
| 2167 | { |
| 2168 | struct mem_dqinfo *mi; |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2169 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2171 | mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2172 | if (!sb_has_quota_active(sb, type)) { |
| 2173 | err = -ESRCH; |
| 2174 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | } |
| 2176 | mi = sb_dqopt(sb)->info + type; |
| 2177 | spin_lock(&dq_data_lock); |
| 2178 | if (ii->dqi_valid & IIF_BGRACE) |
| 2179 | mi->dqi_bgrace = ii->dqi_bgrace; |
| 2180 | if (ii->dqi_valid & IIF_IGRACE) |
| 2181 | mi->dqi_igrace = ii->dqi_igrace; |
| 2182 | if (ii->dqi_valid & IIF_FLAGS) |
| 2183 | mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK); |
| 2184 | spin_unlock(&dq_data_lock); |
| 2185 | mark_info_dirty(sb, type); |
| 2186 | /* Force write to disk */ |
| 2187 | sb->dq_op->write_info(sb, type); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2188 | out: |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2189 | mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2190 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | struct quotactl_ops vfs_quotactl_ops = { |
| 2194 | .quota_on = vfs_quota_on, |
| 2195 | .quota_off = vfs_quota_off, |
| 2196 | .quota_sync = vfs_quota_sync, |
| 2197 | .get_info = vfs_get_dqinfo, |
| 2198 | .set_info = vfs_set_dqinfo, |
| 2199 | .get_dqblk = vfs_get_dqblk, |
| 2200 | .set_dqblk = vfs_set_dqblk |
| 2201 | }; |
| 2202 | |
| 2203 | static ctl_table fs_dqstats_table[] = { |
| 2204 | { |
| 2205 | .ctl_name = FS_DQ_LOOKUPS, |
| 2206 | .procname = "lookups", |
| 2207 | .data = &dqstats.lookups, |
| 2208 | .maxlen = sizeof(int), |
| 2209 | .mode = 0444, |
| 2210 | .proc_handler = &proc_dointvec, |
| 2211 | }, |
| 2212 | { |
| 2213 | .ctl_name = FS_DQ_DROPS, |
| 2214 | .procname = "drops", |
| 2215 | .data = &dqstats.drops, |
| 2216 | .maxlen = sizeof(int), |
| 2217 | .mode = 0444, |
| 2218 | .proc_handler = &proc_dointvec, |
| 2219 | }, |
| 2220 | { |
| 2221 | .ctl_name = FS_DQ_READS, |
| 2222 | .procname = "reads", |
| 2223 | .data = &dqstats.reads, |
| 2224 | .maxlen = sizeof(int), |
| 2225 | .mode = 0444, |
| 2226 | .proc_handler = &proc_dointvec, |
| 2227 | }, |
| 2228 | { |
| 2229 | .ctl_name = FS_DQ_WRITES, |
| 2230 | .procname = "writes", |
| 2231 | .data = &dqstats.writes, |
| 2232 | .maxlen = sizeof(int), |
| 2233 | .mode = 0444, |
| 2234 | .proc_handler = &proc_dointvec, |
| 2235 | }, |
| 2236 | { |
| 2237 | .ctl_name = FS_DQ_CACHE_HITS, |
| 2238 | .procname = "cache_hits", |
| 2239 | .data = &dqstats.cache_hits, |
| 2240 | .maxlen = sizeof(int), |
| 2241 | .mode = 0444, |
| 2242 | .proc_handler = &proc_dointvec, |
| 2243 | }, |
| 2244 | { |
| 2245 | .ctl_name = FS_DQ_ALLOCATED, |
| 2246 | .procname = "allocated_dquots", |
| 2247 | .data = &dqstats.allocated_dquots, |
| 2248 | .maxlen = sizeof(int), |
| 2249 | .mode = 0444, |
| 2250 | .proc_handler = &proc_dointvec, |
| 2251 | }, |
| 2252 | { |
| 2253 | .ctl_name = FS_DQ_FREE, |
| 2254 | .procname = "free_dquots", |
| 2255 | .data = &dqstats.free_dquots, |
| 2256 | .maxlen = sizeof(int), |
| 2257 | .mode = 0444, |
| 2258 | .proc_handler = &proc_dointvec, |
| 2259 | }, |
| 2260 | { |
| 2261 | .ctl_name = FS_DQ_SYNCS, |
| 2262 | .procname = "syncs", |
| 2263 | .data = &dqstats.syncs, |
| 2264 | .maxlen = sizeof(int), |
| 2265 | .mode = 0444, |
| 2266 | .proc_handler = &proc_dointvec, |
| 2267 | }, |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 2268 | #ifdef CONFIG_PRINT_QUOTA_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | { |
| 2270 | .ctl_name = FS_DQ_WARNINGS, |
| 2271 | .procname = "warnings", |
| 2272 | .data = &flag_print_warnings, |
| 2273 | .maxlen = sizeof(int), |
| 2274 | .mode = 0644, |
| 2275 | .proc_handler = &proc_dointvec, |
| 2276 | }, |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 2277 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | { .ctl_name = 0 }, |
| 2279 | }; |
| 2280 | |
| 2281 | static ctl_table fs_table[] = { |
| 2282 | { |
| 2283 | .ctl_name = FS_DQSTATS, |
| 2284 | .procname = "quota", |
| 2285 | .mode = 0555, |
| 2286 | .child = fs_dqstats_table, |
| 2287 | }, |
| 2288 | { .ctl_name = 0 }, |
| 2289 | }; |
| 2290 | |
| 2291 | static ctl_table sys_table[] = { |
| 2292 | { |
| 2293 | .ctl_name = CTL_FS, |
| 2294 | .procname = "fs", |
| 2295 | .mode = 0555, |
| 2296 | .child = fs_table, |
| 2297 | }, |
| 2298 | { .ctl_name = 0 }, |
| 2299 | }; |
| 2300 | |
| 2301 | static int __init dquot_init(void) |
| 2302 | { |
| 2303 | int i; |
| 2304 | unsigned long nr_hash, order; |
| 2305 | |
| 2306 | printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__); |
| 2307 | |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 2308 | register_sysctl_table(sys_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2310 | dquot_cachep = kmem_cache_create("dquot", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | sizeof(struct dquot), sizeof(unsigned long) * 4, |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 2312 | (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| |
| 2313 | SLAB_MEM_SPREAD|SLAB_PANIC), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2314 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
| 2316 | order = 0; |
| 2317 | dquot_hash = (struct hlist_head *)__get_free_pages(GFP_ATOMIC, order); |
| 2318 | if (!dquot_hash) |
| 2319 | panic("Cannot create dquot hash table"); |
| 2320 | |
| 2321 | /* Find power-of-two hlist_heads which can fit into allocation */ |
| 2322 | nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head); |
| 2323 | dq_hash_bits = 0; |
| 2324 | do { |
| 2325 | dq_hash_bits++; |
| 2326 | } while (nr_hash >> dq_hash_bits); |
| 2327 | dq_hash_bits--; |
| 2328 | |
| 2329 | nr_hash = 1UL << dq_hash_bits; |
| 2330 | dq_hash_mask = nr_hash - 1; |
| 2331 | for (i = 0; i < nr_hash; i++) |
| 2332 | INIT_HLIST_HEAD(dquot_hash + i); |
| 2333 | |
| 2334 | printk("Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n", |
| 2335 | nr_hash, order, (PAGE_SIZE << order)); |
| 2336 | |
Rusty Russell | 8e1f936 | 2007-07-17 04:03:17 -0700 | [diff] [blame] | 2337 | register_shrinker(&dqcache_shrinker); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | |
Jan Kara | 8e89346 | 2007-10-16 23:29:31 -0700 | [diff] [blame] | 2339 | #ifdef CONFIG_QUOTA_NETLINK_INTERFACE |
| 2340 | if (genl_register_family("a_genl_family) != 0) |
| 2341 | printk(KERN_ERR "VFS: Failed to create quota netlink interface.\n"); |
| 2342 | #endif |
| 2343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | return 0; |
| 2345 | } |
| 2346 | module_init(dquot_init); |
| 2347 | |
| 2348 | EXPORT_SYMBOL(register_quota_format); |
| 2349 | EXPORT_SYMBOL(unregister_quota_format); |
| 2350 | EXPORT_SYMBOL(dqstats); |
| 2351 | EXPORT_SYMBOL(dq_data_lock); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2352 | EXPORT_SYMBOL(vfs_quota_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | EXPORT_SYMBOL(vfs_quota_on); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2354 | EXPORT_SYMBOL(vfs_quota_on_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | EXPORT_SYMBOL(vfs_quota_on_mount); |
Jan Kara | f55abc0 | 2008-08-20 17:50:32 +0200 | [diff] [blame] | 2356 | EXPORT_SYMBOL(vfs_quota_disable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | EXPORT_SYMBOL(vfs_quota_off); |
Jan Kara | 12c7752 | 2008-10-20 17:05:00 +0200 | [diff] [blame] | 2358 | EXPORT_SYMBOL(dquot_scan_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | EXPORT_SYMBOL(vfs_quota_sync); |
| 2360 | EXPORT_SYMBOL(vfs_get_dqinfo); |
| 2361 | EXPORT_SYMBOL(vfs_set_dqinfo); |
| 2362 | EXPORT_SYMBOL(vfs_get_dqblk); |
| 2363 | EXPORT_SYMBOL(vfs_set_dqblk); |
| 2364 | EXPORT_SYMBOL(dquot_commit); |
| 2365 | EXPORT_SYMBOL(dquot_commit_info); |
| 2366 | EXPORT_SYMBOL(dquot_acquire); |
| 2367 | EXPORT_SYMBOL(dquot_release); |
| 2368 | EXPORT_SYMBOL(dquot_mark_dquot_dirty); |
| 2369 | EXPORT_SYMBOL(dquot_initialize); |
| 2370 | EXPORT_SYMBOL(dquot_drop); |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 2371 | EXPORT_SYMBOL(dquot_drop_locked); |
Jan Kara | b85f4b8 | 2008-07-25 01:46:50 -0700 | [diff] [blame] | 2372 | EXPORT_SYMBOL(vfs_dq_drop); |
Jan Kara | 3d9ea25 | 2008-10-10 16:12:23 +0200 | [diff] [blame] | 2373 | EXPORT_SYMBOL(dqget); |
| 2374 | EXPORT_SYMBOL(dqput); |
| 2375 | EXPORT_SYMBOL(dquot_is_cached); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | EXPORT_SYMBOL(dquot_alloc_space); |
| 2377 | EXPORT_SYMBOL(dquot_alloc_inode); |
| 2378 | EXPORT_SYMBOL(dquot_free_space); |
| 2379 | EXPORT_SYMBOL(dquot_free_inode); |
| 2380 | EXPORT_SYMBOL(dquot_transfer); |
Jan Kara | b85f4b8 | 2008-07-25 01:46:50 -0700 | [diff] [blame] | 2381 | EXPORT_SYMBOL(vfs_dq_transfer); |
| 2382 | EXPORT_SYMBOL(vfs_dq_quota_on_remount); |