blob: 41b9dbd68b0e88e4a466685e1150e262e5d03c59 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
12 * Version: $Id: dquot.c,v 6.3 1996/11/17 18:35:34 mvw Exp mvw $
13 *
14 * Author: Marco van Wieringen <mvw@planets.elm.net>
15 *
16 * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96
17 *
18 * Revised list management to avoid races
19 * -- Bill Hawes, <whawes@star.net>, 9/98
20 *
21 * Fixed races in dquot_transfer(), dqget() and dquot_alloc_...().
22 * As the consequence the locking was moved from dquot_decr_...(),
23 * dquot_incr_...() to calling functions.
24 * invalidate_dquots() now writes modified dquots.
25 * Serialized quota_off() and quota_on() for mount point.
26 * Fixed a few bugs in grow_dquots().
27 * Fixed deadlock in write_dquot() - we no longer account quotas on
28 * quota files
29 * remove_dquot_ref() moved to inode.c - it now traverses through inodes
30 * add_dquot_ref() restarts after blocking
31 * Added check for bogus uid and fixed check for group in quotactl.
32 * Jan Kara, <jack@suse.cz>, sponsored by SuSE CR, 10-11/99
33 *
34 * Used struct list_head instead of own list struct
35 * Invalidation of referenced dquots is no longer possible
36 * Improved free_dquots list management
37 * Quota and i_blocks are now updated in one place to avoid races
38 * Warnings are now delayed so we won't block in critical section
39 * Write updated not to require dquot lock
40 * Jan Kara, <jack@suse.cz>, 9/2000
41 *
42 * Added dynamic quota structure allocation
43 * Jan Kara <jack@suse.cz> 12/2000
44 *
45 * Rewritten quota interface. Implemented new quota format and
46 * formats registering.
47 * Jan Kara, <jack@suse.cz>, 2001,2002
48 *
49 * New SMP locking.
50 * Jan Kara, <jack@suse.cz>, 10/2002
51 *
52 * Added journalled quota support, fix lock inversion problems
53 * Jan Kara, <jack@suse.cz>, 2003,2004
54 *
55 * (C) Copyright 1994 - 1997 Marco van Wieringen
56 */
57
58#include <linux/errno.h>
59#include <linux/kernel.h>
60#include <linux/fs.h>
61#include <linux/mount.h>
62#include <linux/mm.h>
63#include <linux/time.h>
64#include <linux/types.h>
65#include <linux/string.h>
66#include <linux/fcntl.h>
67#include <linux/stat.h>
68#include <linux/tty.h>
69#include <linux/file.h>
70#include <linux/slab.h>
71#include <linux/sysctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <linux/init.h>
73#include <linux/module.h>
74#include <linux/proc_fs.h>
75#include <linux/security.h>
76#include <linux/kmod.h>
77#include <linux/namei.h>
78#include <linux/buffer_head.h>
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080079#include <linux/capability.h>
Adrian Bunkbe586ba2005-11-07 00:59:35 -080080#include <linux/quotaops.h>
Christoph Hellwigfb58b732007-02-12 00:51:57 -080081#include <linux/writeback.h> /* for inode_lock, oddly enough.. */
Jan Kara8e893462007-10-16 23:29:31 -070082#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
83#include <net/netlink.h>
84#include <net/genetlink.h>
85#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87#include <asm/uaccess.h>
88
89#define __DQUOT_PARANOIA
90
91/*
92 * There are two quota SMP locks. dq_list_lock protects all lists with quotas
93 * and quota formats and also dqstats structure containing statistics about the
94 * lists. dq_data_lock protects data from dq_dqb and also mem_dqinfo structures
95 * and also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
96 * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly
97 * in inode_add_bytes() and inode_sub_bytes().
98 *
99 * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock
100 *
101 * Note that some things (eg. sb pointer, type, id) doesn't change during
102 * the life of the dquot structure and so needn't to be protected by a lock
103 *
104 * Any operation working on dquots via inode pointers must hold dqptr_sem. If
105 * operation is just reading pointers from inode (or not using them at all) the
106 * read lock is enough. If pointers are altered function must hold write lock
107 * (these locking rules also apply for S_NOQUOTA flag in the inode - note that
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800108 * for altering the flag i_mutex is also needed). If operation is holding
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * reference to dquot in other way (e.g. quotactl ops) it must be guarded by
Ingo Molnard3be9152006-03-23 03:00:29 -0800110 * dqonoff_mutex.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 * This locking assures that:
112 * a) update/access to dquot pointers in inode is serialized
113 * b) everyone is guarded against invalidate_dquots()
114 *
Ingo Molnard3be9152006-03-23 03:00:29 -0800115 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * from inodes (dquot_alloc_space() and such don't check the dq_lock).
117 * Currently dquot is locked only when it is being read to memory (or space for
118 * it is being allocated) on the first dqget() and when it is being released on
119 * the last dqput(). The allocation and release oparations are serialized by
120 * the dq_lock and by checking the use count in dquot_release(). Write
121 * operations on dquots don't hold dq_lock as they copy data under dq_data_lock
122 * spinlock to internal buffers before writing.
123 *
124 * Lock ordering (including related VFS locks) is the following:
Ingo Molnard3be9152006-03-23 03:00:29 -0800125 * i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock >
126 * dqio_mutex
127 * i_mutex on quota files is special (it's below dqio_mutex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 */
129
130static DEFINE_SPINLOCK(dq_list_lock);
131DEFINE_SPINLOCK(dq_data_lock);
132
133static char *quotatypes[] = INITQFNAMES;
134static struct quota_format_type *quota_formats; /* List of registered formats */
135static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES;
136
137/* SLAB cache for dquot structures */
Christoph Lametere18b8902006-12-06 20:33:20 -0800138static struct kmem_cache *dquot_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140int register_quota_format(struct quota_format_type *fmt)
141{
142 spin_lock(&dq_list_lock);
143 fmt->qf_next = quota_formats;
144 quota_formats = fmt;
145 spin_unlock(&dq_list_lock);
146 return 0;
147}
148
149void unregister_quota_format(struct quota_format_type *fmt)
150{
151 struct quota_format_type **actqf;
152
153 spin_lock(&dq_list_lock);
154 for (actqf = &quota_formats; *actqf && *actqf != fmt; actqf = &(*actqf)->qf_next);
155 if (*actqf)
156 *actqf = (*actqf)->qf_next;
157 spin_unlock(&dq_list_lock);
158}
159
160static struct quota_format_type *find_quota_format(int id)
161{
162 struct quota_format_type *actqf;
163
164 spin_lock(&dq_list_lock);
165 for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next);
166 if (!actqf || !try_module_get(actqf->qf_owner)) {
167 int qm;
168
169 spin_unlock(&dq_list_lock);
170
171 for (qm = 0; module_names[qm].qm_fmt_id && module_names[qm].qm_fmt_id != id; qm++);
172 if (!module_names[qm].qm_fmt_id || request_module(module_names[qm].qm_mod_name))
173 return NULL;
174
175 spin_lock(&dq_list_lock);
176 for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next);
177 if (actqf && !try_module_get(actqf->qf_owner))
178 actqf = NULL;
179 }
180 spin_unlock(&dq_list_lock);
181 return actqf;
182}
183
184static void put_quota_format(struct quota_format_type *fmt)
185{
186 module_put(fmt->qf_owner);
187}
188
189/*
190 * Dquot List Management:
191 * The quota code uses three lists for dquot management: the inuse_list,
192 * free_dquots, and dquot_hash[] array. A single dquot structure may be
193 * on all three lists, depending on its current state.
194 *
195 * All dquots are placed to the end of inuse_list when first created, and this
196 * list is used for invalidate operation, which must look at every dquot.
197 *
198 * Unused dquots (dq_count == 0) are added to the free_dquots list when freed,
199 * and this list is searched whenever we need an available dquot. Dquots are
200 * removed from the list as soon as they are used again, and
201 * dqstats.free_dquots gives the number of dquots on the list. When
202 * dquot is invalidated it's completely released from memory.
203 *
204 * Dquots with a specific identity (device, type and id) are placed on
205 * one of the dquot_hash[] hash chains. The provides an efficient search
206 * mechanism to locate a specific dquot.
207 */
208
209static LIST_HEAD(inuse_list);
210static LIST_HEAD(free_dquots);
211static unsigned int dq_hash_bits, dq_hash_mask;
212static struct hlist_head *dquot_hash;
213
214struct dqstats dqstats;
215
216static void dqput(struct dquot *dquot);
217
218static inline unsigned int
219hashfn(const struct super_block *sb, unsigned int id, int type)
220{
221 unsigned long tmp;
222
223 tmp = (((unsigned long)sb>>L1_CACHE_SHIFT) ^ id) * (MAXQUOTAS - type);
224 return (tmp + (tmp >> dq_hash_bits)) & dq_hash_mask;
225}
226
227/*
228 * Following list functions expect dq_list_lock to be held
229 */
230static inline void insert_dquot_hash(struct dquot *dquot)
231{
232 struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
233 hlist_add_head(&dquot->dq_hash, head);
234}
235
236static inline void remove_dquot_hash(struct dquot *dquot)
237{
238 hlist_del_init(&dquot->dq_hash);
239}
240
241static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type)
242{
243 struct hlist_node *node;
244 struct dquot *dquot;
245
246 hlist_for_each (node, dquot_hash+hashent) {
247 dquot = hlist_entry(node, struct dquot, dq_hash);
248 if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type)
249 return dquot;
250 }
251 return NODQUOT;
252}
253
254/* Add a dquot to the tail of the free list */
255static inline void put_dquot_last(struct dquot *dquot)
256{
Akinobu Mita8e130592006-06-26 00:24:37 -0700257 list_add_tail(&dquot->dq_free, &free_dquots);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 dqstats.free_dquots++;
259}
260
261static inline void remove_free_dquot(struct dquot *dquot)
262{
263 if (list_empty(&dquot->dq_free))
264 return;
265 list_del_init(&dquot->dq_free);
266 dqstats.free_dquots--;
267}
268
269static inline void put_inuse(struct dquot *dquot)
270{
271 /* We add to the back of inuse list so we don't have to restart
272 * when traversing this list and we block */
Akinobu Mita8e130592006-06-26 00:24:37 -0700273 list_add_tail(&dquot->dq_inuse, &inuse_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 dqstats.allocated_dquots++;
275}
276
277static inline void remove_inuse(struct dquot *dquot)
278{
279 dqstats.allocated_dquots--;
280 list_del(&dquot->dq_inuse);
281}
282/*
283 * End of list functions needing dq_list_lock
284 */
285
286static void wait_on_dquot(struct dquot *dquot)
287{
Ingo Molnard3be9152006-03-23 03:00:29 -0800288 mutex_lock(&dquot->dq_lock);
289 mutex_unlock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
292#define mark_dquot_dirty(dquot) ((dquot)->dq_sb->dq_op->mark_dirty(dquot))
293
294int dquot_mark_dquot_dirty(struct dquot *dquot)
295{
296 spin_lock(&dq_list_lock);
297 if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags))
298 list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)->
299 info[dquot->dq_type].dqi_dirty_list);
300 spin_unlock(&dq_list_lock);
301 return 0;
302}
303
304/* This function needs dq_list_lock */
305static inline int clear_dquot_dirty(struct dquot *dquot)
306{
307 if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags))
308 return 0;
309 list_del_init(&dquot->dq_dirty);
310 return 1;
311}
312
313void mark_info_dirty(struct super_block *sb, int type)
314{
315 set_bit(DQF_INFO_DIRTY_B, &sb_dqopt(sb)->info[type].dqi_flags);
316}
317EXPORT_SYMBOL(mark_info_dirty);
318
319/*
320 * Read dquot from disk and alloc space for it
321 */
322
323int dquot_acquire(struct dquot *dquot)
324{
325 int ret = 0, ret2 = 0;
326 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
327
Ingo Molnard3be9152006-03-23 03:00:29 -0800328 mutex_lock(&dquot->dq_lock);
329 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (!test_bit(DQ_READ_B, &dquot->dq_flags))
331 ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot);
332 if (ret < 0)
333 goto out_iolock;
334 set_bit(DQ_READ_B, &dquot->dq_flags);
335 /* Instantiate dquot if needed */
336 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) {
337 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
338 /* Write the info if needed */
339 if (info_dirty(&dqopt->info[dquot->dq_type]))
340 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
341 if (ret < 0)
342 goto out_iolock;
343 if (ret2 < 0) {
344 ret = ret2;
345 goto out_iolock;
346 }
347 }
348 set_bit(DQ_ACTIVE_B, &dquot->dq_flags);
349out_iolock:
Ingo Molnard3be9152006-03-23 03:00:29 -0800350 mutex_unlock(&dqopt->dqio_mutex);
351 mutex_unlock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return ret;
353}
354
355/*
356 * Write dquot to disk
357 */
358int dquot_commit(struct dquot *dquot)
359{
360 int ret = 0, ret2 = 0;
361 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
362
Ingo Molnard3be9152006-03-23 03:00:29 -0800363 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 spin_lock(&dq_list_lock);
365 if (!clear_dquot_dirty(dquot)) {
366 spin_unlock(&dq_list_lock);
367 goto out_sem;
368 }
369 spin_unlock(&dq_list_lock);
370 /* Inactive dquot can be only if there was error during read/init
371 * => we have better not writing it */
372 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
373 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
374 if (info_dirty(&dqopt->info[dquot->dq_type]))
375 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
376 if (ret >= 0)
377 ret = ret2;
378 }
379out_sem:
Ingo Molnard3be9152006-03-23 03:00:29 -0800380 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return ret;
382}
383
384/*
385 * Release dquot
386 */
387int dquot_release(struct dquot *dquot)
388{
389 int ret = 0, ret2 = 0;
390 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
391
Ingo Molnard3be9152006-03-23 03:00:29 -0800392 mutex_lock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 /* Check whether we are not racing with some other dqget() */
394 if (atomic_read(&dquot->dq_count) > 1)
395 goto out_dqlock;
Ingo Molnard3be9152006-03-23 03:00:29 -0800396 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (dqopt->ops[dquot->dq_type]->release_dqblk) {
398 ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot);
399 /* Write the info */
400 if (info_dirty(&dqopt->info[dquot->dq_type]))
401 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
402 if (ret >= 0)
403 ret = ret2;
404 }
405 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
Ingo Molnard3be9152006-03-23 03:00:29 -0800406 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407out_dqlock:
Ingo Molnard3be9152006-03-23 03:00:29 -0800408 mutex_unlock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 return ret;
410}
411
412/* Invalidate all dquots on the list. Note that this function is called after
413 * quota is disabled and pointers from inodes removed so there cannot be new
Jan Kara6362e4d2006-03-23 03:00:17 -0800414 * quota users. There can still be some users of quotas due to inodes being
415 * just deleted or pruned by prune_icache() (those are not attached to any
416 * list). We have to wait for such users.
417 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418static void invalidate_dquots(struct super_block *sb, int type)
419{
Domen Puncerc33ed272005-06-25 14:59:36 -0700420 struct dquot *dquot, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Jan Kara6362e4d2006-03-23 03:00:17 -0800422restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 spin_lock(&dq_list_lock);
Domen Puncerc33ed272005-06-25 14:59:36 -0700424 list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (dquot->dq_sb != sb)
426 continue;
427 if (dquot->dq_type != type)
428 continue;
Jan Kara6362e4d2006-03-23 03:00:17 -0800429 /* Wait for dquot users */
430 if (atomic_read(&dquot->dq_count)) {
431 DEFINE_WAIT(wait);
432
433 atomic_inc(&dquot->dq_count);
434 prepare_to_wait(&dquot->dq_wait_unused, &wait,
435 TASK_UNINTERRUPTIBLE);
436 spin_unlock(&dq_list_lock);
437 /* Once dqput() wakes us up, we know it's time to free
438 * the dquot.
439 * IMPORTANT: we rely on the fact that there is always
440 * at most one process waiting for dquot to free.
441 * Otherwise dq_count would be > 1 and we would never
442 * wake up.
443 */
444 if (atomic_read(&dquot->dq_count) > 1)
445 schedule();
446 finish_wait(&dquot->dq_wait_unused, &wait);
447 dqput(dquot);
448 /* At this moment dquot() need not exist (it could be
449 * reclaimed by prune_dqcache(). Hence we must
450 * restart. */
451 goto restart;
452 }
453 /*
454 * Quota now has no users and it has been written on last
455 * dqput()
456 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 remove_dquot_hash(dquot);
458 remove_free_dquot(dquot);
459 remove_inuse(dquot);
460 kmem_cache_free(dquot_cachep, dquot);
461 }
462 spin_unlock(&dq_list_lock);
463}
464
465int vfs_quota_sync(struct super_block *sb, int type)
466{
467 struct list_head *dirty;
468 struct dquot *dquot;
469 struct quota_info *dqopt = sb_dqopt(sb);
470 int cnt;
471
Ingo Molnard3be9152006-03-23 03:00:29 -0800472 mutex_lock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
474 if (type != -1 && cnt != type)
475 continue;
476 if (!sb_has_quota_enabled(sb, cnt))
477 continue;
478 spin_lock(&dq_list_lock);
479 dirty = &dqopt->info[cnt].dqi_dirty_list;
480 while (!list_empty(dirty)) {
Pavel Emelianovb5e61812007-05-08 00:30:19 -0700481 dquot = list_first_entry(dirty, struct dquot, dq_dirty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 /* Dirty and inactive can be only bad dquot... */
483 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
484 clear_dquot_dirty(dquot);
485 continue;
486 }
487 /* Now we have active dquot from which someone is
488 * holding reference so we can safely just increase
489 * use count */
490 atomic_inc(&dquot->dq_count);
491 dqstats.lookups++;
492 spin_unlock(&dq_list_lock);
493 sb->dq_op->write_dquot(dquot);
494 dqput(dquot);
495 spin_lock(&dq_list_lock);
496 }
497 spin_unlock(&dq_list_lock);
498 }
499
500 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
501 if ((cnt == type || type == -1) && sb_has_quota_enabled(sb, cnt)
502 && info_dirty(&dqopt->info[cnt]))
503 sb->dq_op->write_info(sb, cnt);
504 spin_lock(&dq_list_lock);
505 dqstats.syncs++;
506 spin_unlock(&dq_list_lock);
Ingo Molnard3be9152006-03-23 03:00:29 -0800507 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 return 0;
510}
511
512/* Free unused dquots from cache */
513static void prune_dqcache(int count)
514{
515 struct list_head *head;
516 struct dquot *dquot;
517
518 head = free_dquots.prev;
519 while (head != &free_dquots && count) {
520 dquot = list_entry(head, struct dquot, dq_free);
521 remove_dquot_hash(dquot);
522 remove_free_dquot(dquot);
523 remove_inuse(dquot);
524 kmem_cache_free(dquot_cachep, dquot);
525 count--;
526 head = free_dquots.prev;
527 }
528}
529
530/*
531 * This is called from kswapd when we think we need some
532 * more memory
533 */
534
Al Viro27496a82005-10-21 03:20:48 -0400535static int shrink_dqcache_memory(int nr, gfp_t gfp_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
537 if (nr) {
538 spin_lock(&dq_list_lock);
539 prune_dqcache(nr);
540 spin_unlock(&dq_list_lock);
541 }
542 return (dqstats.free_dquots / 100) * sysctl_vfs_cache_pressure;
543}
544
Rusty Russell8e1f9362007-07-17 04:03:17 -0700545static struct shrinker dqcache_shrinker = {
546 .shrink = shrink_dqcache_memory,
547 .seeks = DEFAULT_SEEKS,
548};
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550/*
551 * Put reference to dquot
552 * NOTE: If you change this function please check whether dqput_blocks() works right...
Ingo Molnard3be9152006-03-23 03:00:29 -0800553 * MUST be called with either dqptr_sem or dqonoff_mutex held
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 */
555static void dqput(struct dquot *dquot)
556{
557 if (!dquot)
558 return;
559#ifdef __DQUOT_PARANOIA
560 if (!atomic_read(&dquot->dq_count)) {
561 printk("VFS: dqput: trying to free free dquot\n");
562 printk("VFS: device %s, dquot of %s %d\n",
563 dquot->dq_sb->s_id,
564 quotatypes[dquot->dq_type],
565 dquot->dq_id);
566 BUG();
567 }
568#endif
569
570 spin_lock(&dq_list_lock);
571 dqstats.drops++;
572 spin_unlock(&dq_list_lock);
573we_slept:
574 spin_lock(&dq_list_lock);
575 if (atomic_read(&dquot->dq_count) > 1) {
576 /* We have more than one user... nothing to do */
577 atomic_dec(&dquot->dq_count);
Jan Kara6362e4d2006-03-23 03:00:17 -0800578 /* Releasing dquot during quotaoff phase? */
579 if (!sb_has_quota_enabled(dquot->dq_sb, dquot->dq_type) &&
580 atomic_read(&dquot->dq_count) == 1)
581 wake_up(&dquot->dq_wait_unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 spin_unlock(&dq_list_lock);
583 return;
584 }
585 /* Need to release dquot? */
586 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) {
587 spin_unlock(&dq_list_lock);
588 /* Commit dquot before releasing */
589 dquot->dq_sb->dq_op->write_dquot(dquot);
590 goto we_slept;
591 }
592 /* Clear flag in case dquot was inactive (something bad happened) */
593 clear_dquot_dirty(dquot);
594 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
595 spin_unlock(&dq_list_lock);
596 dquot->dq_sb->dq_op->release_dquot(dquot);
597 goto we_slept;
598 }
599 atomic_dec(&dquot->dq_count);
600#ifdef __DQUOT_PARANOIA
601 /* sanity check */
Eric Sesterhenn8abf6a42006-04-02 13:36:13 +0200602 BUG_ON(!list_empty(&dquot->dq_free));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#endif
604 put_dquot_last(dquot);
605 spin_unlock(&dq_list_lock);
606}
607
608static struct dquot *get_empty_dquot(struct super_block *sb, int type)
609{
610 struct dquot *dquot;
611
Robert P. J. Dayc3762222007-02-10 01:45:03 -0800612 dquot = kmem_cache_zalloc(dquot_cachep, GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if(!dquot)
614 return NODQUOT;
615
Ingo Molnard3be9152006-03-23 03:00:29 -0800616 mutex_init(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 INIT_LIST_HEAD(&dquot->dq_free);
618 INIT_LIST_HEAD(&dquot->dq_inuse);
619 INIT_HLIST_NODE(&dquot->dq_hash);
620 INIT_LIST_HEAD(&dquot->dq_dirty);
Jan Kara6362e4d2006-03-23 03:00:17 -0800621 init_waitqueue_head(&dquot->dq_wait_unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 dquot->dq_sb = sb;
623 dquot->dq_type = type;
624 atomic_set(&dquot->dq_count, 1);
625
626 return dquot;
627}
628
629/*
630 * Get reference to dquot
Ingo Molnard3be9152006-03-23 03:00:29 -0800631 * MUST be called with either dqptr_sem or dqonoff_mutex held
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 */
633static struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
634{
635 unsigned int hashent = hashfn(sb, id, type);
636 struct dquot *dquot, *empty = NODQUOT;
637
638 if (!sb_has_quota_enabled(sb, type))
639 return NODQUOT;
640we_slept:
641 spin_lock(&dq_list_lock);
642 if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) {
643 if (empty == NODQUOT) {
644 spin_unlock(&dq_list_lock);
645 if ((empty = get_empty_dquot(sb, type)) == NODQUOT)
646 schedule(); /* Try to wait for a moment... */
647 goto we_slept;
648 }
649 dquot = empty;
650 dquot->dq_id = id;
651 /* all dquots go on the inuse_list */
652 put_inuse(dquot);
653 /* hash it first so it can be found */
654 insert_dquot_hash(dquot);
655 dqstats.lookups++;
656 spin_unlock(&dq_list_lock);
657 } else {
658 if (!atomic_read(&dquot->dq_count))
659 remove_free_dquot(dquot);
660 atomic_inc(&dquot->dq_count);
661 dqstats.cache_hits++;
662 dqstats.lookups++;
663 spin_unlock(&dq_list_lock);
664 if (empty)
665 kmem_cache_free(dquot_cachep, empty);
666 }
667 /* Wait for dq_lock - after this we know that either dquot_release() is already
668 * finished or it will be canceled due to dq_count > 1 test */
669 wait_on_dquot(dquot);
670 /* Read the dquot and instantiate it (everything done only if needed) */
671 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) {
672 dqput(dquot);
673 return NODQUOT;
674 }
675#ifdef __DQUOT_PARANOIA
Eric Sesterhenn8abf6a42006-04-02 13:36:13 +0200676 BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#endif
678
679 return dquot;
680}
681
682static int dqinit_needed(struct inode *inode, int type)
683{
684 int cnt;
685
686 if (IS_NOQUOTA(inode))
687 return 0;
688 if (type != -1)
689 return inode->i_dquot[type] == NODQUOT;
690 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
691 if (inode->i_dquot[cnt] == NODQUOT)
692 return 1;
693 return 0;
694}
695
Ingo Molnard3be9152006-03-23 03:00:29 -0800696/* This routine is guarded by dqonoff_mutex mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697static void add_dquot_ref(struct super_block *sb, int type)
698{
Jan Kara941d2382008-02-06 01:37:36 -0800699 struct inode *inode, *old_inode = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Christoph Hellwigd003fb72007-02-12 00:51:58 -0800701 spin_lock(&inode_lock);
702 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
703 if (!atomic_read(&inode->i_writecount))
704 continue;
705 if (!dqinit_needed(inode, type))
706 continue;
707 if (inode->i_state & (I_FREEING|I_WILL_FREE))
708 continue;
709
710 __iget(inode);
711 spin_unlock(&inode_lock);
712
Jan Kara941d2382008-02-06 01:37:36 -0800713 iput(old_inode);
Christoph Hellwigd003fb72007-02-12 00:51:58 -0800714 sb->dq_op->initialize(inode, type);
Jan Kara941d2382008-02-06 01:37:36 -0800715 /* We hold a reference to 'inode' so it couldn't have been
716 * removed from s_inodes list while we dropped the inode_lock.
717 * We cannot iput the inode now as we can be holding the last
718 * reference and we cannot iput it under inode_lock. So we
719 * keep the reference and iput it later. */
720 old_inode = inode;
721 spin_lock(&inode_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
Christoph Hellwigd003fb72007-02-12 00:51:58 -0800723 spin_unlock(&inode_lock);
Jan Kara941d2382008-02-06 01:37:36 -0800724 iput(old_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725}
726
727/* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */
728static inline int dqput_blocks(struct dquot *dquot)
729{
730 if (atomic_read(&dquot->dq_count) <= 1)
731 return 1;
732 return 0;
733}
734
735/* Remove references to dquots from inode - add dquot to list for freeing if needed */
736/* We can't race with anybody because we hold dqptr_sem for writing... */
Adrian Bunke5f00f42007-05-08 00:27:22 -0700737static int remove_inode_dquot_ref(struct inode *inode, int type,
738 struct list_head *tofree_head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
740 struct dquot *dquot = inode->i_dquot[type];
741
742 inode->i_dquot[type] = NODQUOT;
743 if (dquot != NODQUOT) {
744 if (dqput_blocks(dquot)) {
745#ifdef __DQUOT_PARANOIA
746 if (atomic_read(&dquot->dq_count) != 1)
747 printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count));
748#endif
749 spin_lock(&dq_list_lock);
750 list_add(&dquot->dq_free, tofree_head); /* As dquot must have currently users it can't be on the free list... */
751 spin_unlock(&dq_list_lock);
752 return 1;
753 }
754 else
755 dqput(dquot); /* We have guaranteed we won't block */
756 }
757 return 0;
758}
759
760/* Free list of dquots - called from inode.c */
761/* dquots are removed from inodes, no new references can be got so we are the only ones holding reference */
762static void put_dquot_list(struct list_head *tofree_head)
763{
764 struct list_head *act_head;
765 struct dquot *dquot;
766
767 act_head = tofree_head->next;
768 /* So now we have dquots on the list... Just free them */
769 while (act_head != tofree_head) {
770 dquot = list_entry(act_head, struct dquot, dq_free);
771 act_head = act_head->next;
772 list_del_init(&dquot->dq_free); /* Remove dquot from the list so we won't have problems... */
773 dqput(dquot);
774 }
775}
776
Christoph Hellwigfb58b732007-02-12 00:51:57 -0800777static void remove_dquot_ref(struct super_block *sb, int type,
778 struct list_head *tofree_head)
779{
780 struct inode *inode;
781
782 spin_lock(&inode_lock);
783 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
784 if (!IS_NOQUOTA(inode))
785 remove_inode_dquot_ref(inode, type, tofree_head);
786 }
787 spin_unlock(&inode_lock);
788}
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790/* Gather all references from inodes and drop them */
791static void drop_dquot_ref(struct super_block *sb, int type)
792{
793 LIST_HEAD(tofree_head);
794
Christoph Hellwigfb58b732007-02-12 00:51:57 -0800795 if (sb->dq_op) {
796 down_write(&sb_dqopt(sb)->dqptr_sem);
797 remove_dquot_ref(sb, type, &tofree_head);
798 up_write(&sb_dqopt(sb)->dqptr_sem);
799 put_dquot_list(&tofree_head);
800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
803static inline void dquot_incr_inodes(struct dquot *dquot, unsigned long number)
804{
805 dquot->dq_dqb.dqb_curinodes += number;
806}
807
808static inline void dquot_incr_space(struct dquot *dquot, qsize_t number)
809{
810 dquot->dq_dqb.dqb_curspace += number;
811}
812
813static inline void dquot_decr_inodes(struct dquot *dquot, unsigned long number)
814{
815 if (dquot->dq_dqb.dqb_curinodes > number)
816 dquot->dq_dqb.dqb_curinodes -= number;
817 else
818 dquot->dq_dqb.dqb_curinodes = 0;
819 if (dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit)
820 dquot->dq_dqb.dqb_itime = (time_t) 0;
821 clear_bit(DQ_INODES_B, &dquot->dq_flags);
822}
823
824static inline void dquot_decr_space(struct dquot *dquot, qsize_t number)
825{
826 if (dquot->dq_dqb.dqb_curspace > number)
827 dquot->dq_dqb.dqb_curspace -= number;
828 else
829 dquot->dq_dqb.dqb_curspace = 0;
830 if (toqb(dquot->dq_dqb.dqb_curspace) <= dquot->dq_dqb.dqb_bsoftlimit)
831 dquot->dq_dqb.dqb_btime = (time_t) 0;
832 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
833}
834
Jan Karac5254602007-12-22 14:03:25 -0800835static int warning_issued(struct dquot *dquot, const int warntype)
836{
837 int flag = (warntype == QUOTA_NL_BHARDWARN ||
838 warntype == QUOTA_NL_BSOFTLONGWARN) ? DQ_BLKS_B :
839 ((warntype == QUOTA_NL_IHARDWARN ||
840 warntype == QUOTA_NL_ISOFTLONGWARN) ? DQ_INODES_B : 0);
841
842 if (!flag)
843 return 0;
844 return test_and_set_bit(flag, &dquot->dq_flags);
845}
846
Jan Kara8e893462007-10-16 23:29:31 -0700847#ifdef CONFIG_PRINT_QUOTA_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848static int flag_print_warnings = 1;
849
850static inline int need_print_warning(struct dquot *dquot)
851{
852 if (!flag_print_warnings)
853 return 0;
854
855 switch (dquot->dq_type) {
856 case USRQUOTA:
857 return current->fsuid == dquot->dq_id;
858 case GRPQUOTA:
859 return in_group_p(dquot->dq_id);
860 }
861 return 0;
862}
863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864/* Print warning to user which exceeded quota */
Jan Karac5254602007-12-22 14:03:25 -0800865static void print_warning(struct dquot *dquot, const int warntype)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
867 char *msg = NULL;
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800868 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Jan Karac5254602007-12-22 14:03:25 -0800870 if (!need_print_warning(dquot))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 return;
872
Jan Karab525a7e2006-09-29 02:00:26 -0700873 mutex_lock(&tty_mutex);
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800874 tty = get_current_tty();
875 if (!tty)
Jan Karab525a7e2006-09-29 02:00:26 -0700876 goto out_lock;
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800877 tty_write_message(tty, dquot->dq_sb->s_id);
Jan Kara8e893462007-10-16 23:29:31 -0700878 if (warntype == QUOTA_NL_ISOFTWARN || warntype == QUOTA_NL_BSOFTWARN)
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800879 tty_write_message(tty, ": warning, ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 else
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800881 tty_write_message(tty, ": write failed, ");
882 tty_write_message(tty, quotatypes[dquot->dq_type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 switch (warntype) {
Jan Kara8e893462007-10-16 23:29:31 -0700884 case QUOTA_NL_IHARDWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 msg = " file limit reached.\r\n";
886 break;
Jan Kara8e893462007-10-16 23:29:31 -0700887 case QUOTA_NL_ISOFTLONGWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 msg = " file quota exceeded too long.\r\n";
889 break;
Jan Kara8e893462007-10-16 23:29:31 -0700890 case QUOTA_NL_ISOFTWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 msg = " file quota exceeded.\r\n";
892 break;
Jan Kara8e893462007-10-16 23:29:31 -0700893 case QUOTA_NL_BHARDWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 msg = " block limit reached.\r\n";
895 break;
Jan Kara8e893462007-10-16 23:29:31 -0700896 case QUOTA_NL_BSOFTLONGWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 msg = " block quota exceeded too long.\r\n";
898 break;
Jan Kara8e893462007-10-16 23:29:31 -0700899 case QUOTA_NL_BSOFTWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 msg = " block quota exceeded.\r\n";
901 break;
902 }
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800903 tty_write_message(tty, msg);
Jan Karab525a7e2006-09-29 02:00:26 -0700904out_lock:
905 mutex_unlock(&tty_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
Jan Kara8e893462007-10-16 23:29:31 -0700907#endif
908
909#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
910
Jan Kara8e893462007-10-16 23:29:31 -0700911/* Netlink family structure for quota */
912static struct genl_family quota_genl_family = {
913 .id = GENL_ID_GENERATE,
914 .hdrsize = 0,
915 .name = "VFS_DQUOT",
916 .version = 1,
917 .maxattr = QUOTA_NL_A_MAX,
918};
919
920/* Send warning to userspace about user which exceeded quota */
921static void send_warning(const struct dquot *dquot, const char warntype)
922{
923 static atomic_t seq;
924 struct sk_buff *skb;
925 void *msg_head;
926 int ret;
Jan Kara22dd4832007-12-22 14:03:25 -0800927 int msg_size = 4 * nla_total_size(sizeof(u32)) +
928 2 * nla_total_size(sizeof(u64));
Jan Kara8e893462007-10-16 23:29:31 -0700929
930 /* We have to allocate using GFP_NOFS as we are called from a
931 * filesystem performing write and thus further recursion into
932 * the fs to free some data could cause deadlocks. */
Jan Kara22dd4832007-12-22 14:03:25 -0800933 skb = genlmsg_new(msg_size, GFP_NOFS);
Jan Kara8e893462007-10-16 23:29:31 -0700934 if (!skb) {
935 printk(KERN_ERR
936 "VFS: Not enough memory to send quota warning.\n");
937 return;
938 }
939 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
940 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
941 if (!msg_head) {
942 printk(KERN_ERR
943 "VFS: Cannot store netlink header in quota warning.\n");
944 goto err_out;
945 }
946 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, dquot->dq_type);
947 if (ret)
948 goto attr_err_out;
949 ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, dquot->dq_id);
950 if (ret)
951 goto attr_err_out;
952 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
953 if (ret)
954 goto attr_err_out;
955 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR,
956 MAJOR(dquot->dq_sb->s_dev));
957 if (ret)
958 goto attr_err_out;
959 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR,
960 MINOR(dquot->dq_sb->s_dev));
961 if (ret)
962 goto attr_err_out;
963 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current->user->uid);
964 if (ret)
965 goto attr_err_out;
966 genlmsg_end(skb, msg_head);
967
968 ret = genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
969 if (ret < 0 && ret != -ESRCH)
970 printk(KERN_ERR
971 "VFS: Failed to send notification message: %d\n", ret);
972 return;
973attr_err_out:
Jan Kara22dd4832007-12-22 14:03:25 -0800974 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
Jan Kara8e893462007-10-16 23:29:31 -0700975err_out:
976 kfree_skb(skb);
977}
978#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Jan Kara087ee8d2007-12-17 16:20:26 -0800980static inline void flush_warnings(struct dquot * const *dquots, char *warntype)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
982 int i;
983
984 for (i = 0; i < MAXQUOTAS; i++)
Jan Karac5254602007-12-22 14:03:25 -0800985 if (dquots[i] != NODQUOT && warntype[i] != QUOTA_NL_NOWARN &&
986 !warning_issued(dquots[i], warntype[i])) {
Jan Kara8e893462007-10-16 23:29:31 -0700987#ifdef CONFIG_PRINT_QUOTA_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 print_warning(dquots[i], warntype[i]);
Jan Kara8e893462007-10-16 23:29:31 -0700989#endif
990#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
991 send_warning(dquots[i], warntype[i]);
992#endif
993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
996static inline char ignore_hardlimit(struct dquot *dquot)
997{
998 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
999
1000 return capable(CAP_SYS_RESOURCE) &&
1001 (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH));
1002}
1003
1004/* needs dq_data_lock */
1005static int check_idq(struct dquot *dquot, ulong inodes, char *warntype)
1006{
Jan Kara8e893462007-10-16 23:29:31 -07001007 *warntype = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (inodes <= 0 || test_bit(DQ_FAKE_B, &dquot->dq_flags))
1009 return QUOTA_OK;
1010
1011 if (dquot->dq_dqb.dqb_ihardlimit &&
1012 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit &&
1013 !ignore_hardlimit(dquot)) {
Jan Kara8e893462007-10-16 23:29:31 -07001014 *warntype = QUOTA_NL_IHARDWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return NO_QUOTA;
1016 }
1017
1018 if (dquot->dq_dqb.dqb_isoftlimit &&
1019 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
1020 dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime &&
1021 !ignore_hardlimit(dquot)) {
Jan Kara8e893462007-10-16 23:29:31 -07001022 *warntype = QUOTA_NL_ISOFTLONGWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 return NO_QUOTA;
1024 }
1025
1026 if (dquot->dq_dqb.dqb_isoftlimit &&
1027 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
1028 dquot->dq_dqb.dqb_itime == 0) {
Jan Kara8e893462007-10-16 23:29:31 -07001029 *warntype = QUOTA_NL_ISOFTWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1031 }
1032
1033 return QUOTA_OK;
1034}
1035
1036/* needs dq_data_lock */
1037static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
1038{
Jan Kara8e893462007-10-16 23:29:31 -07001039 *warntype = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (space <= 0 || test_bit(DQ_FAKE_B, &dquot->dq_flags))
1041 return QUOTA_OK;
1042
1043 if (dquot->dq_dqb.dqb_bhardlimit &&
1044 toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bhardlimit &&
1045 !ignore_hardlimit(dquot)) {
1046 if (!prealloc)
Jan Kara8e893462007-10-16 23:29:31 -07001047 *warntype = QUOTA_NL_BHARDWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 return NO_QUOTA;
1049 }
1050
1051 if (dquot->dq_dqb.dqb_bsoftlimit &&
1052 toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bsoftlimit &&
1053 dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime &&
1054 !ignore_hardlimit(dquot)) {
1055 if (!prealloc)
Jan Kara8e893462007-10-16 23:29:31 -07001056 *warntype = QUOTA_NL_BSOFTLONGWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 return NO_QUOTA;
1058 }
1059
1060 if (dquot->dq_dqb.dqb_bsoftlimit &&
1061 toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bsoftlimit &&
1062 dquot->dq_dqb.dqb_btime == 0) {
1063 if (!prealloc) {
Jan Kara8e893462007-10-16 23:29:31 -07001064 *warntype = QUOTA_NL_BSOFTWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
1066 }
1067 else
1068 /*
1069 * We don't allow preallocation to exceed softlimit so exceeding will
1070 * be always printed
1071 */
1072 return NO_QUOTA;
1073 }
1074
1075 return QUOTA_OK;
1076}
1077
1078/*
1079 * Initialize quota pointers in inode
1080 * Transaction must be started at entry
1081 */
1082int dquot_initialize(struct inode *inode, int type)
1083{
1084 unsigned int id = 0;
1085 int cnt, ret = 0;
1086
Ingo Molnard3be9152006-03-23 03:00:29 -08001087 /* First test before acquiring mutex - solves deadlocks when we
1088 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 if (IS_NOQUOTA(inode))
1090 return 0;
1091 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1092 /* Having dqptr_sem we know NOQUOTA flags can't be altered... */
1093 if (IS_NOQUOTA(inode))
1094 goto out_err;
1095 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1096 if (type != -1 && cnt != type)
1097 continue;
1098 if (inode->i_dquot[cnt] == NODQUOT) {
1099 switch (cnt) {
1100 case USRQUOTA:
1101 id = inode->i_uid;
1102 break;
1103 case GRPQUOTA:
1104 id = inode->i_gid;
1105 break;
1106 }
1107 inode->i_dquot[cnt] = dqget(inode->i_sb, id, cnt);
1108 }
1109 }
1110out_err:
1111 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1112 return ret;
1113}
1114
1115/*
1116 * Release all quotas referenced by inode
1117 * Transaction must be started at an entry
1118 */
1119int dquot_drop(struct inode *inode)
1120{
1121 int cnt;
1122
1123 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1124 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1125 if (inode->i_dquot[cnt] != NODQUOT) {
1126 dqput(inode->i_dquot[cnt]);
1127 inode->i_dquot[cnt] = NODQUOT;
1128 }
1129 }
1130 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1131 return 0;
1132}
1133
1134/*
1135 * Following four functions update i_blocks+i_bytes fields and
1136 * quota information (together with appropriate checks)
1137 * NOTE: We absolutely rely on the fact that caller dirties
1138 * the inode (usually macros in quotaops.h care about this) and
1139 * holds a handle for the current transaction so that dquot write and
1140 * inode write go into the same transaction.
1141 */
1142
1143/*
1144 * This operation can block, but only after everything is updated
1145 */
1146int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
1147{
1148 int cnt, ret = NO_QUOTA;
1149 char warntype[MAXQUOTAS];
1150
Ingo Molnard3be9152006-03-23 03:00:29 -08001151 /* First test before acquiring mutex - solves deadlocks when we
1152 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 if (IS_NOQUOTA(inode)) {
1154out_add:
1155 inode_add_bytes(inode, number);
1156 return QUOTA_OK;
1157 }
1158 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
Jan Kara8e893462007-10-16 23:29:31 -07001159 warntype[cnt] = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1162 if (IS_NOQUOTA(inode)) { /* Now we can do reliable test... */
1163 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1164 goto out_add;
1165 }
1166 spin_lock(&dq_data_lock);
1167 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1168 if (inode->i_dquot[cnt] == NODQUOT)
1169 continue;
1170 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA)
1171 goto warn_put_all;
1172 }
1173 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1174 if (inode->i_dquot[cnt] == NODQUOT)
1175 continue;
1176 dquot_incr_space(inode->i_dquot[cnt], number);
1177 }
1178 inode_add_bytes(inode, number);
1179 ret = QUOTA_OK;
1180warn_put_all:
1181 spin_unlock(&dq_data_lock);
1182 if (ret == QUOTA_OK)
1183 /* Dirtify all the dquots - this can block when journalling */
1184 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1185 if (inode->i_dquot[cnt])
1186 mark_dquot_dirty(inode->i_dquot[cnt]);
1187 flush_warnings(inode->i_dquot, warntype);
1188 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1189 return ret;
1190}
1191
1192/*
1193 * This operation can block, but only after everything is updated
1194 */
1195int dquot_alloc_inode(const struct inode *inode, unsigned long number)
1196{
1197 int cnt, ret = NO_QUOTA;
1198 char warntype[MAXQUOTAS];
1199
Ingo Molnard3be9152006-03-23 03:00:29 -08001200 /* First test before acquiring mutex - solves deadlocks when we
1201 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 if (IS_NOQUOTA(inode))
1203 return QUOTA_OK;
1204 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
Jan Kara8e893462007-10-16 23:29:31 -07001205 warntype[cnt] = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1207 if (IS_NOQUOTA(inode)) {
1208 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1209 return QUOTA_OK;
1210 }
1211 spin_lock(&dq_data_lock);
1212 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1213 if (inode->i_dquot[cnt] == NODQUOT)
1214 continue;
1215 if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA)
1216 goto warn_put_all;
1217 }
1218
1219 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1220 if (inode->i_dquot[cnt] == NODQUOT)
1221 continue;
1222 dquot_incr_inodes(inode->i_dquot[cnt], number);
1223 }
1224 ret = QUOTA_OK;
1225warn_put_all:
1226 spin_unlock(&dq_data_lock);
1227 if (ret == QUOTA_OK)
1228 /* Dirtify all the dquots - this can block when journalling */
1229 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1230 if (inode->i_dquot[cnt])
1231 mark_dquot_dirty(inode->i_dquot[cnt]);
Jan Kara087ee8d2007-12-17 16:20:26 -08001232 flush_warnings(inode->i_dquot, warntype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1234 return ret;
1235}
1236
1237/*
1238 * This operation can block, but only after everything is updated
1239 */
1240int dquot_free_space(struct inode *inode, qsize_t number)
1241{
1242 unsigned int cnt;
1243
Ingo Molnard3be9152006-03-23 03:00:29 -08001244 /* First test before acquiring mutex - solves deadlocks when we
1245 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 if (IS_NOQUOTA(inode)) {
1247out_sub:
1248 inode_sub_bytes(inode, number);
1249 return QUOTA_OK;
1250 }
1251 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1252 /* Now recheck reliably when holding dqptr_sem */
1253 if (IS_NOQUOTA(inode)) {
1254 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1255 goto out_sub;
1256 }
1257 spin_lock(&dq_data_lock);
1258 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1259 if (inode->i_dquot[cnt] == NODQUOT)
1260 continue;
1261 dquot_decr_space(inode->i_dquot[cnt], number);
1262 }
1263 inode_sub_bytes(inode, number);
1264 spin_unlock(&dq_data_lock);
1265 /* Dirtify all the dquots - this can block when journalling */
1266 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1267 if (inode->i_dquot[cnt])
1268 mark_dquot_dirty(inode->i_dquot[cnt]);
1269 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1270 return QUOTA_OK;
1271}
1272
1273/*
1274 * This operation can block, but only after everything is updated
1275 */
1276int dquot_free_inode(const struct inode *inode, unsigned long number)
1277{
1278 unsigned int cnt;
1279
Ingo Molnard3be9152006-03-23 03:00:29 -08001280 /* First test before acquiring mutex - solves deadlocks when we
1281 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 if (IS_NOQUOTA(inode))
1283 return QUOTA_OK;
1284 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1285 /* Now recheck reliably when holding dqptr_sem */
1286 if (IS_NOQUOTA(inode)) {
1287 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1288 return QUOTA_OK;
1289 }
1290 spin_lock(&dq_data_lock);
1291 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1292 if (inode->i_dquot[cnt] == NODQUOT)
1293 continue;
1294 dquot_decr_inodes(inode->i_dquot[cnt], number);
1295 }
1296 spin_unlock(&dq_data_lock);
1297 /* Dirtify all the dquots - this can block when journalling */
1298 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1299 if (inode->i_dquot[cnt])
1300 mark_dquot_dirty(inode->i_dquot[cnt]);
1301 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1302 return QUOTA_OK;
1303}
1304
1305/*
1306 * Transfer the number of inode and blocks from one diskquota to an other.
1307 *
1308 * This operation can block, but only after everything is updated
1309 * A transaction must be started when entering this function.
1310 */
1311int dquot_transfer(struct inode *inode, struct iattr *iattr)
1312{
1313 qsize_t space;
1314 struct dquot *transfer_from[MAXQUOTAS];
1315 struct dquot *transfer_to[MAXQUOTAS];
1316 int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid,
1317 chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid;
1318 char warntype[MAXQUOTAS];
1319
Ingo Molnard3be9152006-03-23 03:00:29 -08001320 /* First test before acquiring mutex - solves deadlocks when we
1321 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 if (IS_NOQUOTA(inode))
1323 return QUOTA_OK;
1324 /* Clear the arrays */
1325 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1326 transfer_to[cnt] = transfer_from[cnt] = NODQUOT;
Jan Kara8e893462007-10-16 23:29:31 -07001327 warntype[cnt] = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 }
1329 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1330 /* Now recheck reliably when holding dqptr_sem */
1331 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */
1332 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1333 return QUOTA_OK;
1334 }
1335 /* First build the transfer_to list - here we can block on
1336 * reading/instantiating of dquots. We know that the transaction for
1337 * us was already started so we don't violate lock ranking here */
1338 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1339 switch (cnt) {
1340 case USRQUOTA:
1341 if (!chuid)
1342 continue;
1343 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
1344 break;
1345 case GRPQUOTA:
1346 if (!chgid)
1347 continue;
1348 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt);
1349 break;
1350 }
1351 }
1352 spin_lock(&dq_data_lock);
1353 space = inode_get_bytes(inode);
1354 /* Build the transfer_from list and check the limits */
1355 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1356 if (transfer_to[cnt] == NODQUOT)
1357 continue;
1358 transfer_from[cnt] = inode->i_dquot[cnt];
1359 if (check_idq(transfer_to[cnt], 1, warntype+cnt) == NO_QUOTA ||
1360 check_bdq(transfer_to[cnt], space, 0, warntype+cnt) == NO_QUOTA)
1361 goto warn_put_all;
1362 }
1363
1364 /*
1365 * Finally perform the needed transfer from transfer_from to transfer_to
1366 */
1367 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1368 /*
1369 * Skip changes for same uid or gid or for turned off quota-type.
1370 */
1371 if (transfer_to[cnt] == NODQUOT)
1372 continue;
1373
1374 /* Due to IO error we might not have transfer_from[] structure */
1375 if (transfer_from[cnt]) {
1376 dquot_decr_inodes(transfer_from[cnt], 1);
1377 dquot_decr_space(transfer_from[cnt], space);
1378 }
1379
1380 dquot_incr_inodes(transfer_to[cnt], 1);
1381 dquot_incr_space(transfer_to[cnt], space);
1382
1383 inode->i_dquot[cnt] = transfer_to[cnt];
1384 }
1385 ret = QUOTA_OK;
1386warn_put_all:
1387 spin_unlock(&dq_data_lock);
1388 /* Dirtify all the dquots - this can block when journalling */
1389 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1390 if (transfer_from[cnt])
1391 mark_dquot_dirty(transfer_from[cnt]);
1392 if (transfer_to[cnt])
1393 mark_dquot_dirty(transfer_to[cnt]);
1394 }
1395 flush_warnings(transfer_to, warntype);
1396
1397 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1398 if (ret == QUOTA_OK && transfer_from[cnt] != NODQUOT)
1399 dqput(transfer_from[cnt]);
1400 if (ret == NO_QUOTA && transfer_to[cnt] != NODQUOT)
1401 dqput(transfer_to[cnt]);
1402 }
1403 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1404 return ret;
1405}
1406
1407/*
1408 * Write info of quota file to disk
1409 */
1410int dquot_commit_info(struct super_block *sb, int type)
1411{
1412 int ret;
1413 struct quota_info *dqopt = sb_dqopt(sb);
1414
Ingo Molnard3be9152006-03-23 03:00:29 -08001415 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 ret = dqopt->ops[type]->write_file_info(sb, type);
Ingo Molnard3be9152006-03-23 03:00:29 -08001417 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return ret;
1419}
1420
1421/*
1422 * Definitions of diskquota operations.
1423 */
1424struct dquot_operations dquot_operations = {
1425 .initialize = dquot_initialize,
1426 .drop = dquot_drop,
1427 .alloc_space = dquot_alloc_space,
1428 .alloc_inode = dquot_alloc_inode,
1429 .free_space = dquot_free_space,
1430 .free_inode = dquot_free_inode,
1431 .transfer = dquot_transfer,
1432 .write_dquot = dquot_commit,
1433 .acquire_dquot = dquot_acquire,
1434 .release_dquot = dquot_release,
1435 .mark_dirty = dquot_mark_dquot_dirty,
1436 .write_info = dquot_commit_info
1437};
1438
1439static inline void set_enable_flags(struct quota_info *dqopt, int type)
1440{
1441 switch (type) {
1442 case USRQUOTA:
1443 dqopt->flags |= DQUOT_USR_ENABLED;
1444 break;
1445 case GRPQUOTA:
1446 dqopt->flags |= DQUOT_GRP_ENABLED;
1447 break;
1448 }
1449}
1450
1451static inline void reset_enable_flags(struct quota_info *dqopt, int type)
1452{
1453 switch (type) {
1454 case USRQUOTA:
1455 dqopt->flags &= ~DQUOT_USR_ENABLED;
1456 break;
1457 case GRPQUOTA:
1458 dqopt->flags &= ~DQUOT_GRP_ENABLED;
1459 break;
1460 }
1461}
1462
1463/*
1464 * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount)
1465 */
1466int vfs_quota_off(struct super_block *sb, int type)
1467{
1468 int cnt;
1469 struct quota_info *dqopt = sb_dqopt(sb);
1470 struct inode *toputinode[MAXQUOTAS];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 /* We need to serialize quota_off() for device */
Ingo Molnard3be9152006-03-23 03:00:29 -08001473 mutex_lock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1475 toputinode[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 if (type != -1 && cnt != type)
1477 continue;
1478 if (!sb_has_quota_enabled(sb, cnt))
1479 continue;
1480 reset_enable_flags(dqopt, cnt);
1481
1482 /* Note: these are blocking operations */
1483 drop_dquot_ref(sb, cnt);
1484 invalidate_dquots(sb, cnt);
1485 /*
1486 * Now all dquots should be invalidated, all writes done so we should be only
1487 * users of the info. No locks needed.
1488 */
1489 if (info_dirty(&dqopt->info[cnt]))
1490 sb->dq_op->write_info(sb, cnt);
1491 if (dqopt->ops[cnt]->free_file_info)
1492 dqopt->ops[cnt]->free_file_info(sb, cnt);
1493 put_quota_format(dqopt->info[cnt].dqi_format);
1494
1495 toputinode[cnt] = dqopt->files[cnt];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 dqopt->files[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 dqopt->info[cnt].dqi_flags = 0;
1498 dqopt->info[cnt].dqi_igrace = 0;
1499 dqopt->info[cnt].dqi_bgrace = 0;
1500 dqopt->ops[cnt] = NULL;
1501 }
Ingo Molnard3be9152006-03-23 03:00:29 -08001502 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 /* Sync the superblock so that buffers with quota data are written to
Al Viro7b7b1ac2005-11-07 17:13:39 -05001504 * disk (and so userspace sees correct data afterwards). */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 if (sb->s_op->sync_fs)
1506 sb->s_op->sync_fs(sb, 1);
1507 sync_blockdev(sb->s_bdev);
1508 /* Now the quota files are just ordinary files and we can set the
1509 * inode flags back. Moreover we discard the pagecache so that
1510 * userspace sees the writes we did bypassing the pagecache. We
1511 * must also discard the blockdev buffers so that we see the
1512 * changes done by userspace on the next quotaon() */
1513 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1514 if (toputinode[cnt]) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001515 mutex_lock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /* If quota was reenabled in the meantime, we have
1517 * nothing to do */
1518 if (!sb_has_quota_enabled(sb, cnt)) {
Jan Kara79254092007-05-16 22:11:19 -07001519 mutex_lock_nested(&toputinode[cnt]->i_mutex, I_MUTEX_QUOTA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 toputinode[cnt]->i_flags &= ~(S_IMMUTABLE |
1521 S_NOATIME | S_NOQUOTA);
1522 truncate_inode_pages(&toputinode[cnt]->i_data, 0);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001523 mutex_unlock(&toputinode[cnt]->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 mark_inode_dirty(toputinode[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
Jan Kara87cb0552008-03-19 17:00:46 -07001526 iput(toputinode[cnt]);
Ingo Molnard3be9152006-03-23 03:00:29 -08001527 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 }
1529 if (sb->s_bdev)
Peter Zijlstraf98393a2007-05-06 14:49:54 -07001530 invalidate_bdev(sb->s_bdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 return 0;
1532}
1533
1534/*
1535 * Turn quotas on on a device
1536 */
1537
1538/* Helper function when we already have the inode */
1539static int vfs_quota_on_inode(struct inode *inode, int type, int format_id)
1540{
1541 struct quota_format_type *fmt = find_quota_format(format_id);
1542 struct super_block *sb = inode->i_sb;
1543 struct quota_info *dqopt = sb_dqopt(sb);
1544 int error;
1545 int oldflags = -1;
1546
1547 if (!fmt)
1548 return -ESRCH;
1549 if (!S_ISREG(inode->i_mode)) {
1550 error = -EACCES;
1551 goto out_fmt;
1552 }
1553 if (IS_RDONLY(inode)) {
1554 error = -EROFS;
1555 goto out_fmt;
1556 }
1557 if (!sb->s_op->quota_write || !sb->s_op->quota_read) {
1558 error = -EINVAL;
1559 goto out_fmt;
1560 }
1561
1562 /* As we bypass the pagecache we must now flush the inode so that
1563 * we see all the changes from userspace... */
1564 write_inode_now(inode, 1);
1565 /* And now flush the block cache so that kernel sees the changes */
Peter Zijlstraf98393a2007-05-06 14:49:54 -07001566 invalidate_bdev(sb->s_bdev);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001567 mutex_lock(&inode->i_mutex);
Ingo Molnard3be9152006-03-23 03:00:29 -08001568 mutex_lock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if (sb_has_quota_enabled(sb, type)) {
1570 error = -EBUSY;
1571 goto out_lock;
1572 }
1573 /* We don't want quota and atime on quota files (deadlocks possible)
1574 * Also nobody should write to the file - we use special IO operations
1575 * which ignore the immutable bit. */
1576 down_write(&dqopt->dqptr_sem);
1577 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | S_NOQUOTA);
1578 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
1579 up_write(&dqopt->dqptr_sem);
Jan Kara31e7ad62005-04-16 15:25:46 -07001580 sb->dq_op->drop(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 error = -EIO;
1583 dqopt->files[type] = igrab(inode);
1584 if (!dqopt->files[type])
1585 goto out_lock;
1586 error = -EINVAL;
1587 if (!fmt->qf_ops->check_quota_file(sb, type))
1588 goto out_file_init;
1589
1590 dqopt->ops[type] = fmt->qf_ops;
1591 dqopt->info[type].dqi_format = fmt;
1592 INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list);
Ingo Molnard3be9152006-03-23 03:00:29 -08001593 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001595 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 goto out_file_init;
1597 }
Ingo Molnard3be9152006-03-23 03:00:29 -08001598 mutex_unlock(&dqopt->dqio_mutex);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001599 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 set_enable_flags(dqopt, type);
1601
1602 add_dquot_ref(sb, type);
Ingo Molnard3be9152006-03-23 03:00:29 -08001603 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605 return 0;
1606
1607out_file_init:
1608 dqopt->files[type] = NULL;
1609 iput(inode);
1610out_lock:
Ingo Molnard3be9152006-03-23 03:00:29 -08001611 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 if (oldflags != -1) {
1613 down_write(&dqopt->dqptr_sem);
1614 /* Set the flags back (in the case of accidental quotaon()
1615 * on a wrong file we don't want to mess up the flags) */
1616 inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE);
1617 inode->i_flags |= oldflags;
1618 up_write(&dqopt->dqptr_sem);
1619 }
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001620 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621out_fmt:
1622 put_quota_format(fmt);
1623
1624 return error;
1625}
1626
1627/* Actual function called from quotactl() */
1628int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path)
1629{
1630 struct nameidata nd;
1631 int error;
1632
1633 error = path_lookup(path, LOOKUP_FOLLOW, &nd);
1634 if (error < 0)
1635 return error;
Jan Blunck4ac91372008-02-14 19:34:32 -08001636 error = security_quota_on(nd.path.dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 if (error)
1638 goto out_path;
1639 /* Quota file not on the same filesystem? */
Jan Blunck4ac91372008-02-14 19:34:32 -08001640 if (nd.path.mnt->mnt_sb != sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 error = -EXDEV;
Al Viro7b7b1ac2005-11-07 17:13:39 -05001642 else
Jan Blunck4ac91372008-02-14 19:34:32 -08001643 error = vfs_quota_on_inode(nd.path.dentry->d_inode, type,
1644 format_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645out_path:
Jan Blunck1d957f92008-02-14 19:34:35 -08001646 path_put(&nd.path);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 return error;
1648}
1649
1650/*
1651 * This function is used when filesystem needs to initialize quotas
1652 * during mount time.
1653 */
Christoph Hellwig84de8562005-06-23 00:09:16 -07001654int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
1655 int format_id, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Christoph Hellwig84de8562005-06-23 00:09:16 -07001657 struct dentry *dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 int error;
1659
Christoph Hellwig2fa389c2005-06-23 00:09:16 -07001660 dentry = lookup_one_len(qf_name, sb->s_root, strlen(qf_name));
Christoph Hellwig84de8562005-06-23 00:09:16 -07001661 if (IS_ERR(dentry))
1662 return PTR_ERR(dentry);
1663
Jan Kara154f4842005-11-28 13:44:14 -08001664 if (!dentry->d_inode) {
1665 error = -ENOENT;
1666 goto out;
1667 }
1668
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 error = security_quota_on(dentry);
Christoph Hellwig84de8562005-06-23 00:09:16 -07001670 if (!error)
1671 error = vfs_quota_on_inode(dentry->d_inode, type, format_id);
1672
Jan Kara154f4842005-11-28 13:44:14 -08001673out:
Christoph Hellwig84de8562005-06-23 00:09:16 -07001674 dput(dentry);
1675 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
1678/* Generic routine for getting common part of quota structure */
1679static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di)
1680{
1681 struct mem_dqblk *dm = &dquot->dq_dqb;
1682
1683 spin_lock(&dq_data_lock);
1684 di->dqb_bhardlimit = dm->dqb_bhardlimit;
1685 di->dqb_bsoftlimit = dm->dqb_bsoftlimit;
1686 di->dqb_curspace = dm->dqb_curspace;
1687 di->dqb_ihardlimit = dm->dqb_ihardlimit;
1688 di->dqb_isoftlimit = dm->dqb_isoftlimit;
1689 di->dqb_curinodes = dm->dqb_curinodes;
1690 di->dqb_btime = dm->dqb_btime;
1691 di->dqb_itime = dm->dqb_itime;
1692 di->dqb_valid = QIF_ALL;
1693 spin_unlock(&dq_data_lock);
1694}
1695
1696int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
1697{
1698 struct dquot *dquot;
1699
Ingo Molnard3be9152006-03-23 03:00:29 -08001700 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (!(dquot = dqget(sb, id, type))) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001702 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return -ESRCH;
1704 }
1705 do_get_dqblk(dquot, di);
1706 dqput(dquot);
Ingo Molnard3be9152006-03-23 03:00:29 -08001707 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 return 0;
1709}
1710
1711/* Generic routine for setting common part of quota structure */
1712static void do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
1713{
1714 struct mem_dqblk *dm = &dquot->dq_dqb;
1715 int check_blim = 0, check_ilim = 0;
1716
1717 spin_lock(&dq_data_lock);
1718 if (di->dqb_valid & QIF_SPACE) {
1719 dm->dqb_curspace = di->dqb_curspace;
1720 check_blim = 1;
1721 }
1722 if (di->dqb_valid & QIF_BLIMITS) {
1723 dm->dqb_bsoftlimit = di->dqb_bsoftlimit;
1724 dm->dqb_bhardlimit = di->dqb_bhardlimit;
1725 check_blim = 1;
1726 }
1727 if (di->dqb_valid & QIF_INODES) {
1728 dm->dqb_curinodes = di->dqb_curinodes;
1729 check_ilim = 1;
1730 }
1731 if (di->dqb_valid & QIF_ILIMITS) {
1732 dm->dqb_isoftlimit = di->dqb_isoftlimit;
1733 dm->dqb_ihardlimit = di->dqb_ihardlimit;
1734 check_ilim = 1;
1735 }
1736 if (di->dqb_valid & QIF_BTIME)
1737 dm->dqb_btime = di->dqb_btime;
1738 if (di->dqb_valid & QIF_ITIME)
1739 dm->dqb_itime = di->dqb_itime;
1740
1741 if (check_blim) {
1742 if (!dm->dqb_bsoftlimit || toqb(dm->dqb_curspace) < dm->dqb_bsoftlimit) {
1743 dm->dqb_btime = 0;
1744 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
1745 }
1746 else if (!(di->dqb_valid & QIF_BTIME)) /* Set grace only if user hasn't provided his own... */
1747 dm->dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
1748 }
1749 if (check_ilim) {
1750 if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) {
1751 dm->dqb_itime = 0;
1752 clear_bit(DQ_INODES_B, &dquot->dq_flags);
1753 }
1754 else if (!(di->dqb_valid & QIF_ITIME)) /* Set grace only if user hasn't provided his own... */
1755 dm->dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1756 }
1757 if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit)
1758 clear_bit(DQ_FAKE_B, &dquot->dq_flags);
1759 else
1760 set_bit(DQ_FAKE_B, &dquot->dq_flags);
1761 spin_unlock(&dq_data_lock);
1762 mark_dquot_dirty(dquot);
1763}
1764
1765int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
1766{
1767 struct dquot *dquot;
1768
Ingo Molnard3be9152006-03-23 03:00:29 -08001769 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 if (!(dquot = dqget(sb, id, type))) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001771 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 return -ESRCH;
1773 }
1774 do_set_dqblk(dquot, di);
1775 dqput(dquot);
Ingo Molnard3be9152006-03-23 03:00:29 -08001776 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 return 0;
1778}
1779
1780/* Generic routine for getting common part of quota file information */
1781int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
1782{
1783 struct mem_dqinfo *mi;
1784
Ingo Molnard3be9152006-03-23 03:00:29 -08001785 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 if (!sb_has_quota_enabled(sb, type)) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001787 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 return -ESRCH;
1789 }
1790 mi = sb_dqopt(sb)->info + type;
1791 spin_lock(&dq_data_lock);
1792 ii->dqi_bgrace = mi->dqi_bgrace;
1793 ii->dqi_igrace = mi->dqi_igrace;
1794 ii->dqi_flags = mi->dqi_flags & DQF_MASK;
1795 ii->dqi_valid = IIF_ALL;
1796 spin_unlock(&dq_data_lock);
Ingo Molnard3be9152006-03-23 03:00:29 -08001797 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 return 0;
1799}
1800
1801/* Generic routine for setting common part of quota file information */
1802int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
1803{
1804 struct mem_dqinfo *mi;
1805
Ingo Molnard3be9152006-03-23 03:00:29 -08001806 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 if (!sb_has_quota_enabled(sb, type)) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001808 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return -ESRCH;
1810 }
1811 mi = sb_dqopt(sb)->info + type;
1812 spin_lock(&dq_data_lock);
1813 if (ii->dqi_valid & IIF_BGRACE)
1814 mi->dqi_bgrace = ii->dqi_bgrace;
1815 if (ii->dqi_valid & IIF_IGRACE)
1816 mi->dqi_igrace = ii->dqi_igrace;
1817 if (ii->dqi_valid & IIF_FLAGS)
1818 mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK);
1819 spin_unlock(&dq_data_lock);
1820 mark_info_dirty(sb, type);
1821 /* Force write to disk */
1822 sb->dq_op->write_info(sb, type);
Ingo Molnard3be9152006-03-23 03:00:29 -08001823 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 return 0;
1825}
1826
1827struct quotactl_ops vfs_quotactl_ops = {
1828 .quota_on = vfs_quota_on,
1829 .quota_off = vfs_quota_off,
1830 .quota_sync = vfs_quota_sync,
1831 .get_info = vfs_get_dqinfo,
1832 .set_info = vfs_set_dqinfo,
1833 .get_dqblk = vfs_get_dqblk,
1834 .set_dqblk = vfs_set_dqblk
1835};
1836
1837static ctl_table fs_dqstats_table[] = {
1838 {
1839 .ctl_name = FS_DQ_LOOKUPS,
1840 .procname = "lookups",
1841 .data = &dqstats.lookups,
1842 .maxlen = sizeof(int),
1843 .mode = 0444,
1844 .proc_handler = &proc_dointvec,
1845 },
1846 {
1847 .ctl_name = FS_DQ_DROPS,
1848 .procname = "drops",
1849 .data = &dqstats.drops,
1850 .maxlen = sizeof(int),
1851 .mode = 0444,
1852 .proc_handler = &proc_dointvec,
1853 },
1854 {
1855 .ctl_name = FS_DQ_READS,
1856 .procname = "reads",
1857 .data = &dqstats.reads,
1858 .maxlen = sizeof(int),
1859 .mode = 0444,
1860 .proc_handler = &proc_dointvec,
1861 },
1862 {
1863 .ctl_name = FS_DQ_WRITES,
1864 .procname = "writes",
1865 .data = &dqstats.writes,
1866 .maxlen = sizeof(int),
1867 .mode = 0444,
1868 .proc_handler = &proc_dointvec,
1869 },
1870 {
1871 .ctl_name = FS_DQ_CACHE_HITS,
1872 .procname = "cache_hits",
1873 .data = &dqstats.cache_hits,
1874 .maxlen = sizeof(int),
1875 .mode = 0444,
1876 .proc_handler = &proc_dointvec,
1877 },
1878 {
1879 .ctl_name = FS_DQ_ALLOCATED,
1880 .procname = "allocated_dquots",
1881 .data = &dqstats.allocated_dquots,
1882 .maxlen = sizeof(int),
1883 .mode = 0444,
1884 .proc_handler = &proc_dointvec,
1885 },
1886 {
1887 .ctl_name = FS_DQ_FREE,
1888 .procname = "free_dquots",
1889 .data = &dqstats.free_dquots,
1890 .maxlen = sizeof(int),
1891 .mode = 0444,
1892 .proc_handler = &proc_dointvec,
1893 },
1894 {
1895 .ctl_name = FS_DQ_SYNCS,
1896 .procname = "syncs",
1897 .data = &dqstats.syncs,
1898 .maxlen = sizeof(int),
1899 .mode = 0444,
1900 .proc_handler = &proc_dointvec,
1901 },
Jan Kara8e893462007-10-16 23:29:31 -07001902#ifdef CONFIG_PRINT_QUOTA_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 {
1904 .ctl_name = FS_DQ_WARNINGS,
1905 .procname = "warnings",
1906 .data = &flag_print_warnings,
1907 .maxlen = sizeof(int),
1908 .mode = 0644,
1909 .proc_handler = &proc_dointvec,
1910 },
Jan Kara8e893462007-10-16 23:29:31 -07001911#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 { .ctl_name = 0 },
1913};
1914
1915static ctl_table fs_table[] = {
1916 {
1917 .ctl_name = FS_DQSTATS,
1918 .procname = "quota",
1919 .mode = 0555,
1920 .child = fs_dqstats_table,
1921 },
1922 { .ctl_name = 0 },
1923};
1924
1925static ctl_table sys_table[] = {
1926 {
1927 .ctl_name = CTL_FS,
1928 .procname = "fs",
1929 .mode = 0555,
1930 .child = fs_table,
1931 },
1932 { .ctl_name = 0 },
1933};
1934
1935static int __init dquot_init(void)
1936{
1937 int i;
1938 unsigned long nr_hash, order;
1939
1940 printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__);
1941
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001942 register_sysctl_table(sys_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Paul Mundt20c2df82007-07-20 10:11:58 +09001944 dquot_cachep = kmem_cache_create("dquot",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 sizeof(struct dquot), sizeof(unsigned long) * 4,
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001946 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1947 SLAB_MEM_SPREAD|SLAB_PANIC),
Paul Mundt20c2df82007-07-20 10:11:58 +09001948 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
1950 order = 0;
1951 dquot_hash = (struct hlist_head *)__get_free_pages(GFP_ATOMIC, order);
1952 if (!dquot_hash)
1953 panic("Cannot create dquot hash table");
1954
1955 /* Find power-of-two hlist_heads which can fit into allocation */
1956 nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
1957 dq_hash_bits = 0;
1958 do {
1959 dq_hash_bits++;
1960 } while (nr_hash >> dq_hash_bits);
1961 dq_hash_bits--;
1962
1963 nr_hash = 1UL << dq_hash_bits;
1964 dq_hash_mask = nr_hash - 1;
1965 for (i = 0; i < nr_hash; i++)
1966 INIT_HLIST_HEAD(dquot_hash + i);
1967
1968 printk("Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n",
1969 nr_hash, order, (PAGE_SIZE << order));
1970
Rusty Russell8e1f9362007-07-17 04:03:17 -07001971 register_shrinker(&dqcache_shrinker);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Jan Kara8e893462007-10-16 23:29:31 -07001973#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
1974 if (genl_register_family(&quota_genl_family) != 0)
1975 printk(KERN_ERR "VFS: Failed to create quota netlink interface.\n");
1976#endif
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 return 0;
1979}
1980module_init(dquot_init);
1981
1982EXPORT_SYMBOL(register_quota_format);
1983EXPORT_SYMBOL(unregister_quota_format);
1984EXPORT_SYMBOL(dqstats);
1985EXPORT_SYMBOL(dq_data_lock);
1986EXPORT_SYMBOL(vfs_quota_on);
1987EXPORT_SYMBOL(vfs_quota_on_mount);
1988EXPORT_SYMBOL(vfs_quota_off);
1989EXPORT_SYMBOL(vfs_quota_sync);
1990EXPORT_SYMBOL(vfs_get_dqinfo);
1991EXPORT_SYMBOL(vfs_set_dqinfo);
1992EXPORT_SYMBOL(vfs_get_dqblk);
1993EXPORT_SYMBOL(vfs_set_dqblk);
1994EXPORT_SYMBOL(dquot_commit);
1995EXPORT_SYMBOL(dquot_commit_info);
1996EXPORT_SYMBOL(dquot_acquire);
1997EXPORT_SYMBOL(dquot_release);
1998EXPORT_SYMBOL(dquot_mark_dquot_dirty);
1999EXPORT_SYMBOL(dquot_initialize);
2000EXPORT_SYMBOL(dquot_drop);
2001EXPORT_SYMBOL(dquot_alloc_space);
2002EXPORT_SYMBOL(dquot_alloc_inode);
2003EXPORT_SYMBOL(dquot_free_space);
2004EXPORT_SYMBOL(dquot_free_inode);
2005EXPORT_SYMBOL(dquot_transfer);