blob: 74185c34a4f035998f15af2f8c53bd602545ffbe [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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 Torvalds1da177e2005-04-16 15:20:36 -070070#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 Dunlap16f7e0f2006-01-11 12:17:46 -080077#include <linux/capability.h>
Adrian Bunkbe586ba2005-11-07 00:59:35 -080078#include <linux/quotaops.h>
Christoph Hellwigfb58b732007-02-12 00:51:57 -080079#include <linux/writeback.h> /* for inode_lock, oddly enough.. */
Jan Kara8e893462007-10-16 23:29:31 -070080#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
81#include <net/netlink.h>
82#include <net/genetlink.h>
83#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
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 Sorensen1b1dcc12006-01-09 15:59:24 -0800106 * for altering the flag i_mutex is also needed). If operation is holding
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * reference to dquot in other way (e.g. quotactl ops) it must be guarded by
Ingo Molnard3be9152006-03-23 03:00:29 -0800108 * dqonoff_mutex.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * 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 Molnard3be9152006-03-23 03:00:29 -0800113 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 * 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 Molnard3be9152006-03-23 03:00:29 -0800123 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700126 */
127
128static DEFINE_SPINLOCK(dq_list_lock);
129DEFINE_SPINLOCK(dq_data_lock);
130
131static char *quotatypes[] = INITQFNAMES;
132static struct quota_format_type *quota_formats; /* List of registered formats */
133static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES;
134
135/* SLAB cache for dquot structures */
Christoph Lametere18b8902006-12-06 20:33:20 -0800136static struct kmem_cache *dquot_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138int 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
147void 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 = &quota_formats; *actqf && *actqf != fmt; actqf = &(*actqf)->qf_next);
153 if (*actqf)
154 *actqf = (*actqf)->qf_next;
155 spin_unlock(&dq_list_lock);
156}
157
158static 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
182static 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
207static LIST_HEAD(inuse_list);
208static LIST_HEAD(free_dquots);
209static unsigned int dq_hash_bits, dq_hash_mask;
210static struct hlist_head *dquot_hash;
211
212struct dqstats dqstats;
213
214static void dqput(struct dquot *dquot);
215
216static inline unsigned int
217hashfn(const struct super_block *sb, unsigned int id, int type)
218{
219 unsigned long tmp;
220
221 tmp = (((unsigned long)sb>>L1_CACHE_SHIFT) ^ id) * (MAXQUOTAS - type);
222 return (tmp + (tmp >> dq_hash_bits)) & dq_hash_mask;
223}
224
225/*
226 * Following list functions expect dq_list_lock to be held
227 */
228static inline void insert_dquot_hash(struct dquot *dquot)
229{
230 struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
231 hlist_add_head(&dquot->dq_hash, head);
232}
233
234static inline void remove_dquot_hash(struct dquot *dquot)
235{
236 hlist_del_init(&dquot->dq_hash);
237}
238
239static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type)
240{
241 struct hlist_node *node;
242 struct dquot *dquot;
243
244 hlist_for_each (node, dquot_hash+hashent) {
245 dquot = hlist_entry(node, struct dquot, dq_hash);
246 if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type)
247 return dquot;
248 }
249 return NODQUOT;
250}
251
252/* Add a dquot to the tail of the free list */
253static inline void put_dquot_last(struct dquot *dquot)
254{
Akinobu Mita8e130592006-06-26 00:24:37 -0700255 list_add_tail(&dquot->dq_free, &free_dquots);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 dqstats.free_dquots++;
257}
258
259static inline void remove_free_dquot(struct dquot *dquot)
260{
261 if (list_empty(&dquot->dq_free))
262 return;
263 list_del_init(&dquot->dq_free);
264 dqstats.free_dquots--;
265}
266
267static inline void put_inuse(struct dquot *dquot)
268{
269 /* We add to the back of inuse list so we don't have to restart
270 * when traversing this list and we block */
Akinobu Mita8e130592006-06-26 00:24:37 -0700271 list_add_tail(&dquot->dq_inuse, &inuse_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 dqstats.allocated_dquots++;
273}
274
275static inline void remove_inuse(struct dquot *dquot)
276{
277 dqstats.allocated_dquots--;
278 list_del(&dquot->dq_inuse);
279}
280/*
281 * End of list functions needing dq_list_lock
282 */
283
284static void wait_on_dquot(struct dquot *dquot)
285{
Ingo Molnard3be9152006-03-23 03:00:29 -0800286 mutex_lock(&dquot->dq_lock);
287 mutex_unlock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Jan Kara03f6e922008-04-28 02:14:32 -0700290static inline int dquot_dirty(struct dquot *dquot)
291{
292 return test_bit(DQ_MOD_B, &dquot->dq_flags);
293}
294
295static inline int mark_dquot_dirty(struct dquot *dquot)
296{
297 return dquot->dq_sb->dq_op->mark_dirty(dquot);
298}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300int dquot_mark_dquot_dirty(struct dquot *dquot)
301{
302 spin_lock(&dq_list_lock);
303 if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags))
304 list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)->
305 info[dquot->dq_type].dqi_dirty_list);
306 spin_unlock(&dq_list_lock);
307 return 0;
308}
309
310/* This function needs dq_list_lock */
311static inline int clear_dquot_dirty(struct dquot *dquot)
312{
313 if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags))
314 return 0;
315 list_del_init(&dquot->dq_dirty);
316 return 1;
317}
318
319void mark_info_dirty(struct super_block *sb, int type)
320{
321 set_bit(DQF_INFO_DIRTY_B, &sb_dqopt(sb)->info[type].dqi_flags);
322}
323EXPORT_SYMBOL(mark_info_dirty);
324
325/*
326 * Read dquot from disk and alloc space for it
327 */
328
329int dquot_acquire(struct dquot *dquot)
330{
331 int ret = 0, ret2 = 0;
332 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
333
Ingo Molnard3be9152006-03-23 03:00:29 -0800334 mutex_lock(&dquot->dq_lock);
335 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!test_bit(DQ_READ_B, &dquot->dq_flags))
337 ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot);
338 if (ret < 0)
339 goto out_iolock;
340 set_bit(DQ_READ_B, &dquot->dq_flags);
341 /* Instantiate dquot if needed */
342 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) {
343 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
344 /* Write the info if needed */
345 if (info_dirty(&dqopt->info[dquot->dq_type]))
346 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
347 if (ret < 0)
348 goto out_iolock;
349 if (ret2 < 0) {
350 ret = ret2;
351 goto out_iolock;
352 }
353 }
354 set_bit(DQ_ACTIVE_B, &dquot->dq_flags);
355out_iolock:
Ingo Molnard3be9152006-03-23 03:00:29 -0800356 mutex_unlock(&dqopt->dqio_mutex);
357 mutex_unlock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 return ret;
359}
360
361/*
362 * Write dquot to disk
363 */
364int dquot_commit(struct dquot *dquot)
365{
366 int ret = 0, ret2 = 0;
367 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
368
Ingo Molnard3be9152006-03-23 03:00:29 -0800369 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 spin_lock(&dq_list_lock);
371 if (!clear_dquot_dirty(dquot)) {
372 spin_unlock(&dq_list_lock);
373 goto out_sem;
374 }
375 spin_unlock(&dq_list_lock);
376 /* Inactive dquot can be only if there was error during read/init
377 * => we have better not writing it */
378 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
379 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
380 if (info_dirty(&dqopt->info[dquot->dq_type]))
381 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
382 if (ret >= 0)
383 ret = ret2;
384 }
385out_sem:
Ingo Molnard3be9152006-03-23 03:00:29 -0800386 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 return ret;
388}
389
390/*
391 * Release dquot
392 */
393int dquot_release(struct dquot *dquot)
394{
395 int ret = 0, ret2 = 0;
396 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
397
Ingo Molnard3be9152006-03-23 03:00:29 -0800398 mutex_lock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 /* Check whether we are not racing with some other dqget() */
400 if (atomic_read(&dquot->dq_count) > 1)
401 goto out_dqlock;
Ingo Molnard3be9152006-03-23 03:00:29 -0800402 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (dqopt->ops[dquot->dq_type]->release_dqblk) {
404 ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot);
405 /* Write the info */
406 if (info_dirty(&dqopt->info[dquot->dq_type]))
407 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
408 if (ret >= 0)
409 ret = ret2;
410 }
411 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
Ingo Molnard3be9152006-03-23 03:00:29 -0800412 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413out_dqlock:
Ingo Molnard3be9152006-03-23 03:00:29 -0800414 mutex_unlock(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return ret;
416}
417
Jan Kara74f783a2008-08-19 14:51:22 +0200418static void dquot_destroy(struct dquot *dquot)
419{
420 kmem_cache_free(dquot_cachep, dquot);
421}
422
423static inline void do_destroy_dquot(struct dquot *dquot)
424{
425 dquot->dq_sb->dq_op->destroy_dquot(dquot);
426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/* Invalidate all dquots on the list. Note that this function is called after
429 * quota is disabled and pointers from inodes removed so there cannot be new
Jan Kara6362e4d2006-03-23 03:00:17 -0800430 * quota users. There can still be some users of quotas due to inodes being
431 * just deleted or pruned by prune_icache() (those are not attached to any
432 * list). We have to wait for such users.
433 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434static void invalidate_dquots(struct super_block *sb, int type)
435{
Domen Puncerc33ed272005-06-25 14:59:36 -0700436 struct dquot *dquot, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Jan Kara6362e4d2006-03-23 03:00:17 -0800438restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 spin_lock(&dq_list_lock);
Domen Puncerc33ed272005-06-25 14:59:36 -0700440 list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (dquot->dq_sb != sb)
442 continue;
443 if (dquot->dq_type != type)
444 continue;
Jan Kara6362e4d2006-03-23 03:00:17 -0800445 /* Wait for dquot users */
446 if (atomic_read(&dquot->dq_count)) {
447 DEFINE_WAIT(wait);
448
449 atomic_inc(&dquot->dq_count);
450 prepare_to_wait(&dquot->dq_wait_unused, &wait,
451 TASK_UNINTERRUPTIBLE);
452 spin_unlock(&dq_list_lock);
453 /* Once dqput() wakes us up, we know it's time to free
454 * the dquot.
455 * IMPORTANT: we rely on the fact that there is always
456 * at most one process waiting for dquot to free.
457 * Otherwise dq_count would be > 1 and we would never
458 * wake up.
459 */
460 if (atomic_read(&dquot->dq_count) > 1)
461 schedule();
462 finish_wait(&dquot->dq_wait_unused, &wait);
463 dqput(dquot);
464 /* At this moment dquot() need not exist (it could be
465 * reclaimed by prune_dqcache(). Hence we must
466 * restart. */
467 goto restart;
468 }
469 /*
470 * Quota now has no users and it has been written on last
471 * dqput()
472 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 remove_dquot_hash(dquot);
474 remove_free_dquot(dquot);
475 remove_inuse(dquot);
Jan Kara74f783a2008-08-19 14:51:22 +0200476 do_destroy_dquot(dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478 spin_unlock(&dq_list_lock);
479}
480
481int vfs_quota_sync(struct super_block *sb, int type)
482{
483 struct list_head *dirty;
484 struct dquot *dquot;
485 struct quota_info *dqopt = sb_dqopt(sb);
486 int cnt;
487
Ingo Molnard3be9152006-03-23 03:00:29 -0800488 mutex_lock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
490 if (type != -1 && cnt != type)
491 continue;
Jan Karaf55abc02008-08-20 17:50:32 +0200492 if (!sb_has_quota_active(sb, cnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 continue;
494 spin_lock(&dq_list_lock);
495 dirty = &dqopt->info[cnt].dqi_dirty_list;
496 while (!list_empty(dirty)) {
Pavel Emelianovb5e61812007-05-08 00:30:19 -0700497 dquot = list_first_entry(dirty, struct dquot, dq_dirty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* Dirty and inactive can be only bad dquot... */
499 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
500 clear_dquot_dirty(dquot);
501 continue;
502 }
503 /* Now we have active dquot from which someone is
504 * holding reference so we can safely just increase
505 * use count */
506 atomic_inc(&dquot->dq_count);
507 dqstats.lookups++;
508 spin_unlock(&dq_list_lock);
509 sb->dq_op->write_dquot(dquot);
510 dqput(dquot);
511 spin_lock(&dq_list_lock);
512 }
513 spin_unlock(&dq_list_lock);
514 }
515
516 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
Jan Karaf55abc02008-08-20 17:50:32 +0200517 if ((cnt == type || type == -1) && sb_has_quota_active(sb, cnt)
518 && info_dirty(&dqopt->info[cnt]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 sb->dq_op->write_info(sb, cnt);
520 spin_lock(&dq_list_lock);
521 dqstats.syncs++;
522 spin_unlock(&dq_list_lock);
Ingo Molnard3be9152006-03-23 03:00:29 -0800523 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 return 0;
526}
527
528/* Free unused dquots from cache */
529static void prune_dqcache(int count)
530{
531 struct list_head *head;
532 struct dquot *dquot;
533
534 head = free_dquots.prev;
535 while (head != &free_dquots && count) {
536 dquot = list_entry(head, struct dquot, dq_free);
537 remove_dquot_hash(dquot);
538 remove_free_dquot(dquot);
539 remove_inuse(dquot);
Jan Kara74f783a2008-08-19 14:51:22 +0200540 do_destroy_dquot(dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 count--;
542 head = free_dquots.prev;
543 }
544}
545
546/*
547 * This is called from kswapd when we think we need some
548 * more memory
549 */
550
Al Viro27496a82005-10-21 03:20:48 -0400551static int shrink_dqcache_memory(int nr, gfp_t gfp_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 if (nr) {
554 spin_lock(&dq_list_lock);
555 prune_dqcache(nr);
556 spin_unlock(&dq_list_lock);
557 }
558 return (dqstats.free_dquots / 100) * sysctl_vfs_cache_pressure;
559}
560
Rusty Russell8e1f9362007-07-17 04:03:17 -0700561static struct shrinker dqcache_shrinker = {
562 .shrink = shrink_dqcache_memory,
563 .seeks = DEFAULT_SEEKS,
564};
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/*
567 * Put reference to dquot
568 * NOTE: If you change this function please check whether dqput_blocks() works right...
Ingo Molnard3be9152006-03-23 03:00:29 -0800569 * MUST be called with either dqptr_sem or dqonoff_mutex held
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 */
571static void dqput(struct dquot *dquot)
572{
Jan Karab48d3802008-07-25 01:46:49 -0700573 int ret;
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (!dquot)
576 return;
577#ifdef __DQUOT_PARANOIA
578 if (!atomic_read(&dquot->dq_count)) {
579 printk("VFS: dqput: trying to free free dquot\n");
580 printk("VFS: device %s, dquot of %s %d\n",
581 dquot->dq_sb->s_id,
582 quotatypes[dquot->dq_type],
583 dquot->dq_id);
584 BUG();
585 }
586#endif
587
588 spin_lock(&dq_list_lock);
589 dqstats.drops++;
590 spin_unlock(&dq_list_lock);
591we_slept:
592 spin_lock(&dq_list_lock);
593 if (atomic_read(&dquot->dq_count) > 1) {
594 /* We have more than one user... nothing to do */
595 atomic_dec(&dquot->dq_count);
Jan Kara6362e4d2006-03-23 03:00:17 -0800596 /* Releasing dquot during quotaoff phase? */
Jan Karaf55abc02008-08-20 17:50:32 +0200597 if (!sb_has_quota_active(dquot->dq_sb, dquot->dq_type) &&
Jan Kara6362e4d2006-03-23 03:00:17 -0800598 atomic_read(&dquot->dq_count) == 1)
599 wake_up(&dquot->dq_wait_unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 spin_unlock(&dq_list_lock);
601 return;
602 }
603 /* Need to release dquot? */
604 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) {
605 spin_unlock(&dq_list_lock);
606 /* Commit dquot before releasing */
Jan Karab48d3802008-07-25 01:46:49 -0700607 ret = dquot->dq_sb->dq_op->write_dquot(dquot);
608 if (ret < 0) {
609 printk(KERN_ERR "VFS: cannot write quota structure on "
610 "device %s (error %d). Quota may get out of "
611 "sync!\n", dquot->dq_sb->s_id, ret);
612 /*
613 * We clear dirty bit anyway, so that we avoid
614 * infinite loop here
615 */
616 spin_lock(&dq_list_lock);
617 clear_dquot_dirty(dquot);
618 spin_unlock(&dq_list_lock);
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 goto we_slept;
621 }
622 /* Clear flag in case dquot was inactive (something bad happened) */
623 clear_dquot_dirty(dquot);
624 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
625 spin_unlock(&dq_list_lock);
626 dquot->dq_sb->dq_op->release_dquot(dquot);
627 goto we_slept;
628 }
629 atomic_dec(&dquot->dq_count);
630#ifdef __DQUOT_PARANOIA
631 /* sanity check */
Eric Sesterhenn8abf6a42006-04-02 13:36:13 +0200632 BUG_ON(!list_empty(&dquot->dq_free));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#endif
634 put_dquot_last(dquot);
635 spin_unlock(&dq_list_lock);
636}
637
Jan Kara74f783a2008-08-19 14:51:22 +0200638static struct dquot *dquot_alloc(struct super_block *sb, int type)
639{
640 return kmem_cache_zalloc(dquot_cachep, GFP_NOFS);
641}
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643static struct dquot *get_empty_dquot(struct super_block *sb, int type)
644{
645 struct dquot *dquot;
646
Jan Kara74f783a2008-08-19 14:51:22 +0200647 dquot = sb->dq_op->alloc_dquot(sb, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if(!dquot)
649 return NODQUOT;
650
Ingo Molnard3be9152006-03-23 03:00:29 -0800651 mutex_init(&dquot->dq_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 INIT_LIST_HEAD(&dquot->dq_free);
653 INIT_LIST_HEAD(&dquot->dq_inuse);
654 INIT_HLIST_NODE(&dquot->dq_hash);
655 INIT_LIST_HEAD(&dquot->dq_dirty);
Jan Kara6362e4d2006-03-23 03:00:17 -0800656 init_waitqueue_head(&dquot->dq_wait_unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 dquot->dq_sb = sb;
658 dquot->dq_type = type;
659 atomic_set(&dquot->dq_count, 1);
660
661 return dquot;
662}
663
664/*
665 * Get reference to dquot
Ingo Molnard3be9152006-03-23 03:00:29 -0800666 * MUST be called with either dqptr_sem or dqonoff_mutex held
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 */
668static struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
669{
670 unsigned int hashent = hashfn(sb, id, type);
671 struct dquot *dquot, *empty = NODQUOT;
672
Jan Karaf55abc02008-08-20 17:50:32 +0200673 if (!sb_has_quota_active(sb, type))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 return NODQUOT;
675we_slept:
676 spin_lock(&dq_list_lock);
677 if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) {
678 if (empty == NODQUOT) {
679 spin_unlock(&dq_list_lock);
680 if ((empty = get_empty_dquot(sb, type)) == NODQUOT)
681 schedule(); /* Try to wait for a moment... */
682 goto we_slept;
683 }
684 dquot = empty;
685 dquot->dq_id = id;
686 /* all dquots go on the inuse_list */
687 put_inuse(dquot);
688 /* hash it first so it can be found */
689 insert_dquot_hash(dquot);
690 dqstats.lookups++;
691 spin_unlock(&dq_list_lock);
692 } else {
693 if (!atomic_read(&dquot->dq_count))
694 remove_free_dquot(dquot);
695 atomic_inc(&dquot->dq_count);
696 dqstats.cache_hits++;
697 dqstats.lookups++;
698 spin_unlock(&dq_list_lock);
699 if (empty)
Jan Kara74f783a2008-08-19 14:51:22 +0200700 do_destroy_dquot(empty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 }
702 /* Wait for dq_lock - after this we know that either dquot_release() is already
703 * finished or it will be canceled due to dq_count > 1 test */
704 wait_on_dquot(dquot);
705 /* Read the dquot and instantiate it (everything done only if needed) */
706 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) {
707 dqput(dquot);
708 return NODQUOT;
709 }
710#ifdef __DQUOT_PARANOIA
Eric Sesterhenn8abf6a42006-04-02 13:36:13 +0200711 BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#endif
713
714 return dquot;
715}
716
717static int dqinit_needed(struct inode *inode, int type)
718{
719 int cnt;
720
721 if (IS_NOQUOTA(inode))
722 return 0;
723 if (type != -1)
724 return inode->i_dquot[type] == NODQUOT;
725 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
726 if (inode->i_dquot[cnt] == NODQUOT)
727 return 1;
728 return 0;
729}
730
Ingo Molnard3be9152006-03-23 03:00:29 -0800731/* This routine is guarded by dqonoff_mutex mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732static void add_dquot_ref(struct super_block *sb, int type)
733{
Jan Kara941d2382008-02-06 01:37:36 -0800734 struct inode *inode, *old_inode = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Christoph Hellwigd003fb72007-02-12 00:51:58 -0800736 spin_lock(&inode_lock);
737 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
738 if (!atomic_read(&inode->i_writecount))
739 continue;
740 if (!dqinit_needed(inode, type))
741 continue;
742 if (inode->i_state & (I_FREEING|I_WILL_FREE))
743 continue;
744
745 __iget(inode);
746 spin_unlock(&inode_lock);
747
Jan Kara941d2382008-02-06 01:37:36 -0800748 iput(old_inode);
Christoph Hellwigd003fb72007-02-12 00:51:58 -0800749 sb->dq_op->initialize(inode, type);
Jan Kara941d2382008-02-06 01:37:36 -0800750 /* We hold a reference to 'inode' so it couldn't have been
751 * removed from s_inodes list while we dropped the inode_lock.
752 * We cannot iput the inode now as we can be holding the last
753 * reference and we cannot iput it under inode_lock. So we
754 * keep the reference and iput it later. */
755 old_inode = inode;
756 spin_lock(&inode_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
Christoph Hellwigd003fb72007-02-12 00:51:58 -0800758 spin_unlock(&inode_lock);
Jan Kara941d2382008-02-06 01:37:36 -0800759 iput(old_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
762/* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */
763static inline int dqput_blocks(struct dquot *dquot)
764{
765 if (atomic_read(&dquot->dq_count) <= 1)
766 return 1;
767 return 0;
768}
769
770/* Remove references to dquots from inode - add dquot to list for freeing if needed */
771/* We can't race with anybody because we hold dqptr_sem for writing... */
Adrian Bunke5f00f42007-05-08 00:27:22 -0700772static int remove_inode_dquot_ref(struct inode *inode, int type,
773 struct list_head *tofree_head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
775 struct dquot *dquot = inode->i_dquot[type];
776
777 inode->i_dquot[type] = NODQUOT;
778 if (dquot != NODQUOT) {
779 if (dqput_blocks(dquot)) {
780#ifdef __DQUOT_PARANOIA
781 if (atomic_read(&dquot->dq_count) != 1)
782 printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count));
783#endif
784 spin_lock(&dq_list_lock);
785 list_add(&dquot->dq_free, tofree_head); /* As dquot must have currently users it can't be on the free list... */
786 spin_unlock(&dq_list_lock);
787 return 1;
788 }
789 else
790 dqput(dquot); /* We have guaranteed we won't block */
791 }
792 return 0;
793}
794
795/* Free list of dquots - called from inode.c */
796/* dquots are removed from inodes, no new references can be got so we are the only ones holding reference */
797static void put_dquot_list(struct list_head *tofree_head)
798{
799 struct list_head *act_head;
800 struct dquot *dquot;
801
802 act_head = tofree_head->next;
803 /* So now we have dquots on the list... Just free them */
804 while (act_head != tofree_head) {
805 dquot = list_entry(act_head, struct dquot, dq_free);
806 act_head = act_head->next;
807 list_del_init(&dquot->dq_free); /* Remove dquot from the list so we won't have problems... */
808 dqput(dquot);
809 }
810}
811
Christoph Hellwigfb58b732007-02-12 00:51:57 -0800812static void remove_dquot_ref(struct super_block *sb, int type,
813 struct list_head *tofree_head)
814{
815 struct inode *inode;
816
817 spin_lock(&inode_lock);
818 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
819 if (!IS_NOQUOTA(inode))
820 remove_inode_dquot_ref(inode, type, tofree_head);
821 }
822 spin_unlock(&inode_lock);
823}
824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825/* Gather all references from inodes and drop them */
826static void drop_dquot_ref(struct super_block *sb, int type)
827{
828 LIST_HEAD(tofree_head);
829
Christoph Hellwigfb58b732007-02-12 00:51:57 -0800830 if (sb->dq_op) {
831 down_write(&sb_dqopt(sb)->dqptr_sem);
832 remove_dquot_ref(sb, type, &tofree_head);
833 up_write(&sb_dqopt(sb)->dqptr_sem);
834 put_dquot_list(&tofree_head);
835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
837
Jan Kara12095462008-08-20 14:45:12 +0200838static inline void dquot_incr_inodes(struct dquot *dquot, qsize_t number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
840 dquot->dq_dqb.dqb_curinodes += number;
841}
842
843static inline void dquot_incr_space(struct dquot *dquot, qsize_t number)
844{
845 dquot->dq_dqb.dqb_curspace += number;
846}
847
Jan Kara12095462008-08-20 14:45:12 +0200848static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
850 if (dquot->dq_dqb.dqb_curinodes > number)
851 dquot->dq_dqb.dqb_curinodes -= number;
852 else
853 dquot->dq_dqb.dqb_curinodes = 0;
854 if (dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit)
855 dquot->dq_dqb.dqb_itime = (time_t) 0;
856 clear_bit(DQ_INODES_B, &dquot->dq_flags);
857}
858
859static inline void dquot_decr_space(struct dquot *dquot, qsize_t number)
860{
861 if (dquot->dq_dqb.dqb_curspace > number)
862 dquot->dq_dqb.dqb_curspace -= number;
863 else
864 dquot->dq_dqb.dqb_curspace = 0;
Jan Kara12095462008-08-20 14:45:12 +0200865 if (dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 dquot->dq_dqb.dqb_btime = (time_t) 0;
867 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
868}
869
Jan Karac5254602007-12-22 14:03:25 -0800870static int warning_issued(struct dquot *dquot, const int warntype)
871{
872 int flag = (warntype == QUOTA_NL_BHARDWARN ||
873 warntype == QUOTA_NL_BSOFTLONGWARN) ? DQ_BLKS_B :
874 ((warntype == QUOTA_NL_IHARDWARN ||
875 warntype == QUOTA_NL_ISOFTLONGWARN) ? DQ_INODES_B : 0);
876
877 if (!flag)
878 return 0;
879 return test_and_set_bit(flag, &dquot->dq_flags);
880}
881
Jan Kara8e893462007-10-16 23:29:31 -0700882#ifdef CONFIG_PRINT_QUOTA_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883static int flag_print_warnings = 1;
884
885static inline int need_print_warning(struct dquot *dquot)
886{
887 if (!flag_print_warnings)
888 return 0;
889
890 switch (dquot->dq_type) {
891 case USRQUOTA:
David Howellsda9592e2008-11-14 10:39:05 +1100892 return current_fsuid() == dquot->dq_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 case GRPQUOTA:
894 return in_group_p(dquot->dq_id);
895 }
896 return 0;
897}
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899/* Print warning to user which exceeded quota */
Jan Karac5254602007-12-22 14:03:25 -0800900static void print_warning(struct dquot *dquot, const int warntype)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
902 char *msg = NULL;
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800903 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Jan Kara657d3bf2008-07-25 01:46:52 -0700905 if (warntype == QUOTA_NL_IHARDBELOW ||
906 warntype == QUOTA_NL_ISOFTBELOW ||
907 warntype == QUOTA_NL_BHARDBELOW ||
908 warntype == QUOTA_NL_BSOFTBELOW || !need_print_warning(dquot))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return;
910
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800911 tty = get_current_tty();
912 if (!tty)
Alan Cox452a00d2008-10-13 10:39:13 +0100913 return;
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800914 tty_write_message(tty, dquot->dq_sb->s_id);
Jan Kara8e893462007-10-16 23:29:31 -0700915 if (warntype == QUOTA_NL_ISOFTWARN || warntype == QUOTA_NL_BSOFTWARN)
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800916 tty_write_message(tty, ": warning, ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 else
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800918 tty_write_message(tty, ": write failed, ");
919 tty_write_message(tty, quotatypes[dquot->dq_type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 switch (warntype) {
Jan Kara8e893462007-10-16 23:29:31 -0700921 case QUOTA_NL_IHARDWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 msg = " file limit reached.\r\n";
923 break;
Jan Kara8e893462007-10-16 23:29:31 -0700924 case QUOTA_NL_ISOFTLONGWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 msg = " file quota exceeded too long.\r\n";
926 break;
Jan Kara8e893462007-10-16 23:29:31 -0700927 case QUOTA_NL_ISOFTWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 msg = " file quota exceeded.\r\n";
929 break;
Jan Kara8e893462007-10-16 23:29:31 -0700930 case QUOTA_NL_BHARDWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 msg = " block limit reached.\r\n";
932 break;
Jan Kara8e893462007-10-16 23:29:31 -0700933 case QUOTA_NL_BSOFTLONGWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 msg = " block quota exceeded too long.\r\n";
935 break;
Jan Kara8e893462007-10-16 23:29:31 -0700936 case QUOTA_NL_BSOFTWARN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 msg = " block quota exceeded.\r\n";
938 break;
939 }
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800940 tty_write_message(tty, msg);
Alan Cox452a00d2008-10-13 10:39:13 +0100941 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
Jan Kara8e893462007-10-16 23:29:31 -0700943#endif
944
945#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
946
Jan Kara8e893462007-10-16 23:29:31 -0700947/* Netlink family structure for quota */
948static struct genl_family quota_genl_family = {
949 .id = GENL_ID_GENERATE,
950 .hdrsize = 0,
951 .name = "VFS_DQUOT",
952 .version = 1,
953 .maxattr = QUOTA_NL_A_MAX,
954};
955
956/* Send warning to userspace about user which exceeded quota */
957static void send_warning(const struct dquot *dquot, const char warntype)
958{
959 static atomic_t seq;
960 struct sk_buff *skb;
961 void *msg_head;
962 int ret;
Jan Kara22dd4832007-12-22 14:03:25 -0800963 int msg_size = 4 * nla_total_size(sizeof(u32)) +
964 2 * nla_total_size(sizeof(u64));
Jan Kara8e893462007-10-16 23:29:31 -0700965
966 /* We have to allocate using GFP_NOFS as we are called from a
967 * filesystem performing write and thus further recursion into
968 * the fs to free some data could cause deadlocks. */
Jan Kara22dd4832007-12-22 14:03:25 -0800969 skb = genlmsg_new(msg_size, GFP_NOFS);
Jan Kara8e893462007-10-16 23:29:31 -0700970 if (!skb) {
971 printk(KERN_ERR
972 "VFS: Not enough memory to send quota warning.\n");
973 return;
974 }
975 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
976 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
977 if (!msg_head) {
978 printk(KERN_ERR
979 "VFS: Cannot store netlink header in quota warning.\n");
980 goto err_out;
981 }
982 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, dquot->dq_type);
983 if (ret)
984 goto attr_err_out;
985 ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, dquot->dq_id);
986 if (ret)
987 goto attr_err_out;
988 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
989 if (ret)
990 goto attr_err_out;
991 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR,
992 MAJOR(dquot->dq_sb->s_dev));
993 if (ret)
994 goto attr_err_out;
995 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR,
996 MINOR(dquot->dq_sb->s_dev));
997 if (ret)
998 goto attr_err_out;
David Howellsda9592e2008-11-14 10:39:05 +1100999 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid());
Jan Kara8e893462007-10-16 23:29:31 -07001000 if (ret)
1001 goto attr_err_out;
1002 genlmsg_end(skb, msg_head);
1003
1004 ret = genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
1005 if (ret < 0 && ret != -ESRCH)
1006 printk(KERN_ERR
1007 "VFS: Failed to send notification message: %d\n", ret);
1008 return;
1009attr_err_out:
Jan Kara22dd4832007-12-22 14:03:25 -08001010 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
Jan Kara8e893462007-10-16 23:29:31 -07001011err_out:
1012 kfree_skb(skb);
1013}
1014#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Jan Kara087ee8d2007-12-17 16:20:26 -08001016static inline void flush_warnings(struct dquot * const *dquots, char *warntype)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
1018 int i;
1019
1020 for (i = 0; i < MAXQUOTAS; i++)
Jan Karac5254602007-12-22 14:03:25 -08001021 if (dquots[i] != NODQUOT && warntype[i] != QUOTA_NL_NOWARN &&
1022 !warning_issued(dquots[i], warntype[i])) {
Jan Kara8e893462007-10-16 23:29:31 -07001023#ifdef CONFIG_PRINT_QUOTA_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 print_warning(dquots[i], warntype[i]);
Jan Kara8e893462007-10-16 23:29:31 -07001025#endif
1026#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
1027 send_warning(dquots[i], warntype[i]);
1028#endif
1029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
1032static inline char ignore_hardlimit(struct dquot *dquot)
1033{
1034 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
1035
1036 return capable(CAP_SYS_RESOURCE) &&
1037 (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH));
1038}
1039
1040/* needs dq_data_lock */
Jan Kara12095462008-08-20 14:45:12 +02001041static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
Jan Kara8e893462007-10-16 23:29:31 -07001043 *warntype = QUOTA_NL_NOWARN;
Jan Karaf55abc02008-08-20 17:50:32 +02001044 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
1045 test_bit(DQ_FAKE_B, &dquot->dq_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 return QUOTA_OK;
1047
1048 if (dquot->dq_dqb.dqb_ihardlimit &&
1049 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit &&
1050 !ignore_hardlimit(dquot)) {
Jan Kara8e893462007-10-16 23:29:31 -07001051 *warntype = QUOTA_NL_IHARDWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 return NO_QUOTA;
1053 }
1054
1055 if (dquot->dq_dqb.dqb_isoftlimit &&
1056 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
1057 dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime &&
1058 !ignore_hardlimit(dquot)) {
Jan Kara8e893462007-10-16 23:29:31 -07001059 *warntype = QUOTA_NL_ISOFTLONGWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 return NO_QUOTA;
1061 }
1062
1063 if (dquot->dq_dqb.dqb_isoftlimit &&
1064 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
1065 dquot->dq_dqb.dqb_itime == 0) {
Jan Kara8e893462007-10-16 23:29:31 -07001066 *warntype = QUOTA_NL_ISOFTWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1068 }
1069
1070 return QUOTA_OK;
1071}
1072
1073/* needs dq_data_lock */
1074static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
1075{
Jan Kara8e893462007-10-16 23:29:31 -07001076 *warntype = QUOTA_NL_NOWARN;
Jan Karaf55abc02008-08-20 17:50:32 +02001077 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
1078 test_bit(DQ_FAKE_B, &dquot->dq_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 return QUOTA_OK;
1080
1081 if (dquot->dq_dqb.dqb_bhardlimit &&
Jan Kara12095462008-08-20 14:45:12 +02001082 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bhardlimit &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 !ignore_hardlimit(dquot)) {
1084 if (!prealloc)
Jan Kara8e893462007-10-16 23:29:31 -07001085 *warntype = QUOTA_NL_BHARDWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 return NO_QUOTA;
1087 }
1088
1089 if (dquot->dq_dqb.dqb_bsoftlimit &&
Jan Kara12095462008-08-20 14:45:12 +02001090 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime &&
1092 !ignore_hardlimit(dquot)) {
1093 if (!prealloc)
Jan Kara8e893462007-10-16 23:29:31 -07001094 *warntype = QUOTA_NL_BSOFTLONGWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 return NO_QUOTA;
1096 }
1097
1098 if (dquot->dq_dqb.dqb_bsoftlimit &&
Jan Kara12095462008-08-20 14:45:12 +02001099 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 dquot->dq_dqb.dqb_btime == 0) {
1101 if (!prealloc) {
Jan Kara8e893462007-10-16 23:29:31 -07001102 *warntype = QUOTA_NL_BSOFTWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
1104 }
1105 else
1106 /*
1107 * We don't allow preallocation to exceed softlimit so exceeding will
1108 * be always printed
1109 */
1110 return NO_QUOTA;
1111 }
1112
1113 return QUOTA_OK;
1114}
1115
Jan Kara12095462008-08-20 14:45:12 +02001116static int info_idq_free(struct dquot *dquot, qsize_t inodes)
Jan Kara657d3bf2008-07-25 01:46:52 -07001117{
1118 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
Jan Karaf55abc02008-08-20 17:50:32 +02001119 dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit ||
1120 !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type))
Jan Kara657d3bf2008-07-25 01:46:52 -07001121 return QUOTA_NL_NOWARN;
1122
1123 if (dquot->dq_dqb.dqb_curinodes - inodes <= dquot->dq_dqb.dqb_isoftlimit)
1124 return QUOTA_NL_ISOFTBELOW;
1125 if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit &&
1126 dquot->dq_dqb.dqb_curinodes - inodes < dquot->dq_dqb.dqb_ihardlimit)
1127 return QUOTA_NL_IHARDBELOW;
1128 return QUOTA_NL_NOWARN;
1129}
1130
1131static int info_bdq_free(struct dquot *dquot, qsize_t space)
1132{
1133 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
Jan Kara12095462008-08-20 14:45:12 +02001134 dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit)
Jan Kara657d3bf2008-07-25 01:46:52 -07001135 return QUOTA_NL_NOWARN;
1136
Jan Kara12095462008-08-20 14:45:12 +02001137 if (dquot->dq_dqb.dqb_curspace - space <= dquot->dq_dqb.dqb_bsoftlimit)
Jan Kara657d3bf2008-07-25 01:46:52 -07001138 return QUOTA_NL_BSOFTBELOW;
Jan Kara12095462008-08-20 14:45:12 +02001139 if (dquot->dq_dqb.dqb_curspace >= dquot->dq_dqb.dqb_bhardlimit &&
1140 dquot->dq_dqb.dqb_curspace - space < dquot->dq_dqb.dqb_bhardlimit)
Jan Kara657d3bf2008-07-25 01:46:52 -07001141 return QUOTA_NL_BHARDBELOW;
1142 return QUOTA_NL_NOWARN;
1143}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144/*
1145 * Initialize quota pointers in inode
1146 * Transaction must be started at entry
1147 */
1148int dquot_initialize(struct inode *inode, int type)
1149{
1150 unsigned int id = 0;
1151 int cnt, ret = 0;
1152
Ingo Molnard3be9152006-03-23 03:00:29 -08001153 /* First test before acquiring mutex - solves deadlocks when we
1154 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (IS_NOQUOTA(inode))
1156 return 0;
1157 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1158 /* Having dqptr_sem we know NOQUOTA flags can't be altered... */
1159 if (IS_NOQUOTA(inode))
1160 goto out_err;
1161 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1162 if (type != -1 && cnt != type)
1163 continue;
1164 if (inode->i_dquot[cnt] == NODQUOT) {
1165 switch (cnt) {
1166 case USRQUOTA:
1167 id = inode->i_uid;
1168 break;
1169 case GRPQUOTA:
1170 id = inode->i_gid;
1171 break;
1172 }
1173 inode->i_dquot[cnt] = dqget(inode->i_sb, id, cnt);
1174 }
1175 }
1176out_err:
1177 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1178 return ret;
1179}
1180
1181/*
1182 * Release all quotas referenced by inode
1183 * Transaction must be started at an entry
1184 */
1185int dquot_drop(struct inode *inode)
1186{
1187 int cnt;
1188
1189 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1190 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1191 if (inode->i_dquot[cnt] != NODQUOT) {
1192 dqput(inode->i_dquot[cnt]);
1193 inode->i_dquot[cnt] = NODQUOT;
1194 }
1195 }
1196 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1197 return 0;
1198}
1199
Jan Karab85f4b82008-07-25 01:46:50 -07001200/* Wrapper to remove references to quota structures from inode */
1201void vfs_dq_drop(struct inode *inode)
1202{
1203 /* Here we can get arbitrary inode from clear_inode() so we have
1204 * to be careful. OTOH we don't need locking as quota operations
1205 * are allowed to change only at mount time */
1206 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
1207 && inode->i_sb->dq_op->drop) {
1208 int cnt;
1209 /* Test before calling to rule out calls from proc and such
1210 * where we are not allowed to block. Note that this is
1211 * actually reliable test even without the lock - the caller
1212 * must assure that nobody can come after the DQUOT_DROP and
1213 * add quota pointers back anyway */
1214 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1215 if (inode->i_dquot[cnt] != NODQUOT)
1216 break;
1217 if (cnt < MAXQUOTAS)
1218 inode->i_sb->dq_op->drop(inode);
1219 }
1220}
1221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222/*
1223 * Following four functions update i_blocks+i_bytes fields and
1224 * quota information (together with appropriate checks)
1225 * NOTE: We absolutely rely on the fact that caller dirties
1226 * the inode (usually macros in quotaops.h care about this) and
1227 * holds a handle for the current transaction so that dquot write and
1228 * inode write go into the same transaction.
1229 */
1230
1231/*
1232 * This operation can block, but only after everything is updated
1233 */
1234int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
1235{
1236 int cnt, ret = NO_QUOTA;
1237 char warntype[MAXQUOTAS];
1238
Ingo Molnard3be9152006-03-23 03:00:29 -08001239 /* First test before acquiring mutex - solves deadlocks when we
1240 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (IS_NOQUOTA(inode)) {
1242out_add:
1243 inode_add_bytes(inode, number);
1244 return QUOTA_OK;
1245 }
1246 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
Jan Kara8e893462007-10-16 23:29:31 -07001247 warntype[cnt] = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1250 if (IS_NOQUOTA(inode)) { /* Now we can do reliable test... */
1251 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1252 goto out_add;
1253 }
1254 spin_lock(&dq_data_lock);
1255 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1256 if (inode->i_dquot[cnt] == NODQUOT)
1257 continue;
1258 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA)
1259 goto warn_put_all;
1260 }
1261 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1262 if (inode->i_dquot[cnt] == NODQUOT)
1263 continue;
1264 dquot_incr_space(inode->i_dquot[cnt], number);
1265 }
1266 inode_add_bytes(inode, number);
1267 ret = QUOTA_OK;
1268warn_put_all:
1269 spin_unlock(&dq_data_lock);
1270 if (ret == QUOTA_OK)
1271 /* Dirtify all the dquots - this can block when journalling */
1272 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1273 if (inode->i_dquot[cnt])
1274 mark_dquot_dirty(inode->i_dquot[cnt]);
1275 flush_warnings(inode->i_dquot, warntype);
1276 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1277 return ret;
1278}
1279
1280/*
1281 * This operation can block, but only after everything is updated
1282 */
Jan Kara12095462008-08-20 14:45:12 +02001283int dquot_alloc_inode(const struct inode *inode, qsize_t number)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
1285 int cnt, ret = NO_QUOTA;
1286 char warntype[MAXQUOTAS];
1287
Ingo Molnard3be9152006-03-23 03:00:29 -08001288 /* First test before acquiring mutex - solves deadlocks when we
1289 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 if (IS_NOQUOTA(inode))
1291 return QUOTA_OK;
1292 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
Jan Kara8e893462007-10-16 23:29:31 -07001293 warntype[cnt] = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1295 if (IS_NOQUOTA(inode)) {
1296 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1297 return QUOTA_OK;
1298 }
1299 spin_lock(&dq_data_lock);
1300 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1301 if (inode->i_dquot[cnt] == NODQUOT)
1302 continue;
1303 if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA)
1304 goto warn_put_all;
1305 }
1306
1307 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1308 if (inode->i_dquot[cnt] == NODQUOT)
1309 continue;
1310 dquot_incr_inodes(inode->i_dquot[cnt], number);
1311 }
1312 ret = QUOTA_OK;
1313warn_put_all:
1314 spin_unlock(&dq_data_lock);
1315 if (ret == QUOTA_OK)
1316 /* Dirtify all the dquots - this can block when journalling */
1317 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1318 if (inode->i_dquot[cnt])
1319 mark_dquot_dirty(inode->i_dquot[cnt]);
Jan Kara087ee8d2007-12-17 16:20:26 -08001320 flush_warnings(inode->i_dquot, warntype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1322 return ret;
1323}
1324
1325/*
1326 * This operation can block, but only after everything is updated
1327 */
1328int dquot_free_space(struct inode *inode, qsize_t number)
1329{
1330 unsigned int cnt;
Jan Kara657d3bf2008-07-25 01:46:52 -07001331 char warntype[MAXQUOTAS];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Ingo Molnard3be9152006-03-23 03:00:29 -08001333 /* First test before acquiring mutex - solves deadlocks when we
1334 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 if (IS_NOQUOTA(inode)) {
1336out_sub:
1337 inode_sub_bytes(inode, number);
1338 return QUOTA_OK;
1339 }
Jan Kara657d3bf2008-07-25 01:46:52 -07001340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1342 /* Now recheck reliably when holding dqptr_sem */
1343 if (IS_NOQUOTA(inode)) {
1344 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1345 goto out_sub;
1346 }
1347 spin_lock(&dq_data_lock);
1348 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1349 if (inode->i_dquot[cnt] == NODQUOT)
1350 continue;
Jan Kara657d3bf2008-07-25 01:46:52 -07001351 warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 dquot_decr_space(inode->i_dquot[cnt], number);
1353 }
1354 inode_sub_bytes(inode, number);
1355 spin_unlock(&dq_data_lock);
1356 /* Dirtify all the dquots - this can block when journalling */
1357 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1358 if (inode->i_dquot[cnt])
1359 mark_dquot_dirty(inode->i_dquot[cnt]);
Jan Kara657d3bf2008-07-25 01:46:52 -07001360 flush_warnings(inode->i_dquot, warntype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1362 return QUOTA_OK;
1363}
1364
1365/*
1366 * This operation can block, but only after everything is updated
1367 */
Jan Kara12095462008-08-20 14:45:12 +02001368int dquot_free_inode(const struct inode *inode, qsize_t number)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369{
1370 unsigned int cnt;
Jan Kara657d3bf2008-07-25 01:46:52 -07001371 char warntype[MAXQUOTAS];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
Ingo Molnard3be9152006-03-23 03:00:29 -08001373 /* First test before acquiring mutex - solves deadlocks when we
1374 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 if (IS_NOQUOTA(inode))
1376 return QUOTA_OK;
Jan Kara657d3bf2008-07-25 01:46:52 -07001377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1379 /* Now recheck reliably when holding dqptr_sem */
1380 if (IS_NOQUOTA(inode)) {
1381 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1382 return QUOTA_OK;
1383 }
1384 spin_lock(&dq_data_lock);
1385 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1386 if (inode->i_dquot[cnt] == NODQUOT)
1387 continue;
Jan Kara657d3bf2008-07-25 01:46:52 -07001388 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 dquot_decr_inodes(inode->i_dquot[cnt], number);
1390 }
1391 spin_unlock(&dq_data_lock);
1392 /* Dirtify all the dquots - this can block when journalling */
1393 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1394 if (inode->i_dquot[cnt])
1395 mark_dquot_dirty(inode->i_dquot[cnt]);
Jan Kara657d3bf2008-07-25 01:46:52 -07001396 flush_warnings(inode->i_dquot, warntype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1398 return QUOTA_OK;
1399}
1400
1401/*
1402 * Transfer the number of inode and blocks from one diskquota to an other.
1403 *
1404 * This operation can block, but only after everything is updated
1405 * A transaction must be started when entering this function.
1406 */
1407int dquot_transfer(struct inode *inode, struct iattr *iattr)
1408{
1409 qsize_t space;
1410 struct dquot *transfer_from[MAXQUOTAS];
1411 struct dquot *transfer_to[MAXQUOTAS];
1412 int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid,
1413 chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid;
Jan Kara657d3bf2008-07-25 01:46:52 -07001414 char warntype_to[MAXQUOTAS];
1415 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Ingo Molnard3be9152006-03-23 03:00:29 -08001417 /* First test before acquiring mutex - solves deadlocks when we
1418 * re-enter the quota code and are already holding the mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 if (IS_NOQUOTA(inode))
1420 return QUOTA_OK;
1421 /* Clear the arrays */
1422 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1423 transfer_to[cnt] = transfer_from[cnt] = NODQUOT;
Jan Kara657d3bf2008-07-25 01:46:52 -07001424 warntype_to[cnt] = QUOTA_NL_NOWARN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
1426 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1427 /* Now recheck reliably when holding dqptr_sem */
1428 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */
1429 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1430 return QUOTA_OK;
1431 }
1432 /* First build the transfer_to list - here we can block on
1433 * reading/instantiating of dquots. We know that the transaction for
1434 * us was already started so we don't violate lock ranking here */
1435 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1436 switch (cnt) {
1437 case USRQUOTA:
1438 if (!chuid)
1439 continue;
1440 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
1441 break;
1442 case GRPQUOTA:
1443 if (!chgid)
1444 continue;
1445 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt);
1446 break;
1447 }
1448 }
1449 spin_lock(&dq_data_lock);
1450 space = inode_get_bytes(inode);
1451 /* Build the transfer_from list and check the limits */
1452 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1453 if (transfer_to[cnt] == NODQUOT)
1454 continue;
1455 transfer_from[cnt] = inode->i_dquot[cnt];
Jan Kara657d3bf2008-07-25 01:46:52 -07001456 if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) ==
1457 NO_QUOTA || check_bdq(transfer_to[cnt], space, 0,
1458 warntype_to + cnt) == NO_QUOTA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 goto warn_put_all;
1460 }
1461
1462 /*
1463 * Finally perform the needed transfer from transfer_from to transfer_to
1464 */
1465 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1466 /*
1467 * Skip changes for same uid or gid or for turned off quota-type.
1468 */
1469 if (transfer_to[cnt] == NODQUOT)
1470 continue;
1471
1472 /* Due to IO error we might not have transfer_from[] structure */
1473 if (transfer_from[cnt]) {
Jan Kara657d3bf2008-07-25 01:46:52 -07001474 warntype_from_inodes[cnt] =
1475 info_idq_free(transfer_from[cnt], 1);
1476 warntype_from_space[cnt] =
1477 info_bdq_free(transfer_from[cnt], space);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 dquot_decr_inodes(transfer_from[cnt], 1);
1479 dquot_decr_space(transfer_from[cnt], space);
1480 }
1481
1482 dquot_incr_inodes(transfer_to[cnt], 1);
1483 dquot_incr_space(transfer_to[cnt], space);
1484
1485 inode->i_dquot[cnt] = transfer_to[cnt];
1486 }
1487 ret = QUOTA_OK;
1488warn_put_all:
1489 spin_unlock(&dq_data_lock);
1490 /* Dirtify all the dquots - this can block when journalling */
1491 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1492 if (transfer_from[cnt])
1493 mark_dquot_dirty(transfer_from[cnt]);
1494 if (transfer_to[cnt])
1495 mark_dquot_dirty(transfer_to[cnt]);
1496 }
Jan Kara657d3bf2008-07-25 01:46:52 -07001497 flush_warnings(transfer_to, warntype_to);
1498 flush_warnings(transfer_from, warntype_from_inodes);
1499 flush_warnings(transfer_from, warntype_from_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1502 if (ret == QUOTA_OK && transfer_from[cnt] != NODQUOT)
1503 dqput(transfer_from[cnt]);
1504 if (ret == NO_QUOTA && transfer_to[cnt] != NODQUOT)
1505 dqput(transfer_to[cnt]);
1506 }
1507 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1508 return ret;
1509}
1510
Jan Karab85f4b82008-07-25 01:46:50 -07001511/* Wrapper for transferring ownership of an inode */
1512int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
1513{
Jan Karaf55abc02008-08-20 17:50:32 +02001514 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) {
Jan Karab85f4b82008-07-25 01:46:50 -07001515 vfs_dq_init(inode);
1516 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
1517 return 1;
1518 }
1519 return 0;
1520}
1521
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523/*
1524 * Write info of quota file to disk
1525 */
1526int dquot_commit_info(struct super_block *sb, int type)
1527{
1528 int ret;
1529 struct quota_info *dqopt = sb_dqopt(sb);
1530
Ingo Molnard3be9152006-03-23 03:00:29 -08001531 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 ret = dqopt->ops[type]->write_file_info(sb, type);
Ingo Molnard3be9152006-03-23 03:00:29 -08001533 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 return ret;
1535}
1536
1537/*
1538 * Definitions of diskquota operations.
1539 */
1540struct dquot_operations dquot_operations = {
1541 .initialize = dquot_initialize,
1542 .drop = dquot_drop,
1543 .alloc_space = dquot_alloc_space,
1544 .alloc_inode = dquot_alloc_inode,
1545 .free_space = dquot_free_space,
1546 .free_inode = dquot_free_inode,
1547 .transfer = dquot_transfer,
1548 .write_dquot = dquot_commit,
1549 .acquire_dquot = dquot_acquire,
1550 .release_dquot = dquot_release,
1551 .mark_dirty = dquot_mark_dquot_dirty,
Jan Kara74f783a2008-08-19 14:51:22 +02001552 .write_info = dquot_commit_info,
1553 .alloc_dquot = dquot_alloc,
1554 .destroy_dquot = dquot_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555};
1556
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557/*
1558 * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount)
1559 */
Jan Karaf55abc02008-08-20 17:50:32 +02001560int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Jan Kara0ff5af82008-04-28 02:14:33 -07001562 int cnt, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 struct quota_info *dqopt = sb_dqopt(sb);
1564 struct inode *toputinode[MAXQUOTAS];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Jan Karaf55abc02008-08-20 17:50:32 +02001566 /* Cannot turn off usage accounting without turning off limits, or
1567 * suspend quotas and simultaneously turn quotas off. */
1568 if ((flags & DQUOT_USAGE_ENABLED && !(flags & DQUOT_LIMITS_ENABLED))
1569 || (flags & DQUOT_SUSPENDED && flags & (DQUOT_LIMITS_ENABLED |
1570 DQUOT_USAGE_ENABLED)))
1571 return -EINVAL;
1572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 /* We need to serialize quota_off() for device */
Ingo Molnard3be9152006-03-23 03:00:29 -08001574 mutex_lock(&dqopt->dqonoff_mutex);
Jan Kara9377abd2008-05-12 14:02:08 -07001575
1576 /*
1577 * Skip everything if there's nothing to do. We have to do this because
1578 * sometimes we are called when fill_super() failed and calling
1579 * sync_fs() in such cases does no good.
1580 */
Jan Karaf55abc02008-08-20 17:50:32 +02001581 if (!sb_any_quota_loaded(sb)) {
Jan Kara9377abd2008-05-12 14:02:08 -07001582 mutex_unlock(&dqopt->dqonoff_mutex);
1583 return 0;
1584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1586 toputinode[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (type != -1 && cnt != type)
1588 continue;
Jan Karaf55abc02008-08-20 17:50:32 +02001589 if (!sb_has_quota_loaded(sb, cnt))
Jan Kara0ff5af82008-04-28 02:14:33 -07001590 continue;
Jan Karaf55abc02008-08-20 17:50:32 +02001591
1592 if (flags & DQUOT_SUSPENDED) {
1593 dqopt->flags |=
1594 dquot_state_flag(DQUOT_SUSPENDED, cnt);
1595 } else {
1596 dqopt->flags &= ~dquot_state_flag(flags, cnt);
1597 /* Turning off suspended quotas? */
1598 if (!sb_has_quota_loaded(sb, cnt) &&
1599 sb_has_quota_suspended(sb, cnt)) {
1600 dqopt->flags &= ~dquot_state_flag(
1601 DQUOT_SUSPENDED, cnt);
1602 iput(dqopt->files[cnt]);
1603 dqopt->files[cnt] = NULL;
1604 continue;
1605 }
Jan Kara0ff5af82008-04-28 02:14:33 -07001606 }
Jan Karaf55abc02008-08-20 17:50:32 +02001607
1608 /* We still have to keep quota loaded? */
1609 if (sb_has_quota_loaded(sb, cnt) && !(flags & DQUOT_SUSPENDED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 /* Note: these are blocking operations */
1613 drop_dquot_ref(sb, cnt);
1614 invalidate_dquots(sb, cnt);
1615 /*
1616 * Now all dquots should be invalidated, all writes done so we should be only
1617 * users of the info. No locks needed.
1618 */
1619 if (info_dirty(&dqopt->info[cnt]))
1620 sb->dq_op->write_info(sb, cnt);
1621 if (dqopt->ops[cnt]->free_file_info)
1622 dqopt->ops[cnt]->free_file_info(sb, cnt);
1623 put_quota_format(dqopt->info[cnt].dqi_format);
1624
1625 toputinode[cnt] = dqopt->files[cnt];
Jan Karaf55abc02008-08-20 17:50:32 +02001626 if (!sb_has_quota_loaded(sb, cnt))
Jan Kara0ff5af82008-04-28 02:14:33 -07001627 dqopt->files[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 dqopt->info[cnt].dqi_flags = 0;
1629 dqopt->info[cnt].dqi_igrace = 0;
1630 dqopt->info[cnt].dqi_bgrace = 0;
1631 dqopt->ops[cnt] = NULL;
1632 }
Ingo Molnard3be9152006-03-23 03:00:29 -08001633 mutex_unlock(&dqopt->dqonoff_mutex);
Jan Karaca785ec2008-09-30 17:53:37 +02001634
1635 /* Skip syncing and setting flags if quota files are hidden */
1636 if (dqopt->flags & DQUOT_QUOTA_SYS_FILE)
1637 goto put_inodes;
1638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /* Sync the superblock so that buffers with quota data are written to
Al Viro7b7b1ac2005-11-07 17:13:39 -05001640 * disk (and so userspace sees correct data afterwards). */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 if (sb->s_op->sync_fs)
1642 sb->s_op->sync_fs(sb, 1);
1643 sync_blockdev(sb->s_bdev);
1644 /* Now the quota files are just ordinary files and we can set the
1645 * inode flags back. Moreover we discard the pagecache so that
1646 * userspace sees the writes we did bypassing the pagecache. We
1647 * must also discard the blockdev buffers so that we see the
1648 * changes done by userspace on the next quotaon() */
1649 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1650 if (toputinode[cnt]) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001651 mutex_lock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 /* If quota was reenabled in the meantime, we have
1653 * nothing to do */
Jan Karaf55abc02008-08-20 17:50:32 +02001654 if (!sb_has_quota_loaded(sb, cnt)) {
Jan Kara79254092007-05-16 22:11:19 -07001655 mutex_lock_nested(&toputinode[cnt]->i_mutex, I_MUTEX_QUOTA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 toputinode[cnt]->i_flags &= ~(S_IMMUTABLE |
1657 S_NOATIME | S_NOQUOTA);
1658 truncate_inode_pages(&toputinode[cnt]->i_data, 0);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001659 mutex_unlock(&toputinode[cnt]->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 mark_inode_dirty(toputinode[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 }
Ingo Molnard3be9152006-03-23 03:00:29 -08001662 mutex_unlock(&dqopt->dqonoff_mutex);
Jan Karaca785ec2008-09-30 17:53:37 +02001663 }
1664 if (sb->s_bdev)
1665 invalidate_bdev(sb->s_bdev);
1666put_inodes:
1667 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1668 if (toputinode[cnt]) {
Jan Kara0ff5af82008-04-28 02:14:33 -07001669 /* On remount RO, we keep the inode pointer so that we
Jan Karaf55abc02008-08-20 17:50:32 +02001670 * can reenable quota on the subsequent remount RW. We
1671 * have to check 'flags' variable and not use sb_has_
1672 * function because another quotaon / quotaoff could
1673 * change global state before we got here. We refuse
1674 * to suspend quotas when there is pending delete on
1675 * the quota file... */
1676 if (!(flags & DQUOT_SUSPENDED))
Jan Kara0ff5af82008-04-28 02:14:33 -07001677 iput(toputinode[cnt]);
1678 else if (!toputinode[cnt]->i_nlink)
1679 ret = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 }
Jan Kara0ff5af82008-04-28 02:14:33 -07001681 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Jan Karaf55abc02008-08-20 17:50:32 +02001684int vfs_quota_off(struct super_block *sb, int type, int remount)
1685{
1686 return vfs_quota_disable(sb, type, remount ? DQUOT_SUSPENDED :
1687 (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED));
1688}
1689
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690/*
1691 * Turn quotas on on a device
1692 */
1693
Jan Karaf55abc02008-08-20 17:50:32 +02001694/*
1695 * Helper function to turn quotas on when we already have the inode of
1696 * quota file and no quota information is loaded.
1697 */
1698static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
1699 unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
1701 struct quota_format_type *fmt = find_quota_format(format_id);
1702 struct super_block *sb = inode->i_sb;
1703 struct quota_info *dqopt = sb_dqopt(sb);
1704 int error;
1705 int oldflags = -1;
1706
1707 if (!fmt)
1708 return -ESRCH;
1709 if (!S_ISREG(inode->i_mode)) {
1710 error = -EACCES;
1711 goto out_fmt;
1712 }
1713 if (IS_RDONLY(inode)) {
1714 error = -EROFS;
1715 goto out_fmt;
1716 }
1717 if (!sb->s_op->quota_write || !sb->s_op->quota_read) {
1718 error = -EINVAL;
1719 goto out_fmt;
1720 }
Jan Karaf55abc02008-08-20 17:50:32 +02001721 /* Usage always has to be set... */
1722 if (!(flags & DQUOT_USAGE_ENABLED)) {
1723 error = -EINVAL;
1724 goto out_fmt;
1725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Jan Karaca785ec2008-09-30 17:53:37 +02001727 if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) {
1728 /* As we bypass the pagecache we must now flush the inode so
1729 * that we see all the changes from userspace... */
1730 write_inode_now(inode, 1);
1731 /* And now flush the block cache so that kernel sees the
1732 * changes */
1733 invalidate_bdev(sb->s_bdev);
1734 }
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001735 mutex_lock(&inode->i_mutex);
Ingo Molnard3be9152006-03-23 03:00:29 -08001736 mutex_lock(&dqopt->dqonoff_mutex);
Jan Karaf55abc02008-08-20 17:50:32 +02001737 if (sb_has_quota_loaded(sb, type)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 error = -EBUSY;
1739 goto out_lock;
1740 }
Jan Karaca785ec2008-09-30 17:53:37 +02001741
1742 if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) {
1743 /* We don't want quota and atime on quota files (deadlocks
1744 * possible) Also nobody should write to the file - we use
1745 * special IO operations which ignore the immutable bit. */
1746 down_write(&dqopt->dqptr_sem);
1747 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | S_NOQUOTA);
1748 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
1749 up_write(&dqopt->dqptr_sem);
1750 sb->dq_op->drop(inode);
1751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 error = -EIO;
1754 dqopt->files[type] = igrab(inode);
1755 if (!dqopt->files[type])
1756 goto out_lock;
1757 error = -EINVAL;
1758 if (!fmt->qf_ops->check_quota_file(sb, type))
1759 goto out_file_init;
1760
1761 dqopt->ops[type] = fmt->qf_ops;
1762 dqopt->info[type].dqi_format = fmt;
Jan Kara0ff5af82008-04-28 02:14:33 -07001763 dqopt->info[type].dqi_fmt_id = format_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list);
Ingo Molnard3be9152006-03-23 03:00:29 -08001765 mutex_lock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001767 mutex_unlock(&dqopt->dqio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 goto out_file_init;
1769 }
Ingo Molnard3be9152006-03-23 03:00:29 -08001770 mutex_unlock(&dqopt->dqio_mutex);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001771 mutex_unlock(&inode->i_mutex);
Jan Karaf55abc02008-08-20 17:50:32 +02001772 dqopt->flags |= dquot_state_flag(flags, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
1774 add_dquot_ref(sb, type);
Ingo Molnard3be9152006-03-23 03:00:29 -08001775 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
1777 return 0;
1778
1779out_file_init:
1780 dqopt->files[type] = NULL;
1781 iput(inode);
1782out_lock:
Ingo Molnard3be9152006-03-23 03:00:29 -08001783 mutex_unlock(&dqopt->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if (oldflags != -1) {
1785 down_write(&dqopt->dqptr_sem);
1786 /* Set the flags back (in the case of accidental quotaon()
1787 * on a wrong file we don't want to mess up the flags) */
1788 inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE);
1789 inode->i_flags |= oldflags;
1790 up_write(&dqopt->dqptr_sem);
1791 }
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001792 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793out_fmt:
1794 put_quota_format(fmt);
1795
1796 return error;
1797}
1798
Jan Kara0ff5af82008-04-28 02:14:33 -07001799/* Reenable quotas on remount RW */
1800static int vfs_quota_on_remount(struct super_block *sb, int type)
1801{
1802 struct quota_info *dqopt = sb_dqopt(sb);
1803 struct inode *inode;
1804 int ret;
Jan Karaf55abc02008-08-20 17:50:32 +02001805 unsigned int flags;
Jan Kara0ff5af82008-04-28 02:14:33 -07001806
1807 mutex_lock(&dqopt->dqonoff_mutex);
1808 if (!sb_has_quota_suspended(sb, type)) {
1809 mutex_unlock(&dqopt->dqonoff_mutex);
1810 return 0;
1811 }
Jan Kara0ff5af82008-04-28 02:14:33 -07001812 inode = dqopt->files[type];
1813 dqopt->files[type] = NULL;
Jan Karaf55abc02008-08-20 17:50:32 +02001814 flags = dqopt->flags & dquot_state_flag(DQUOT_USAGE_ENABLED |
1815 DQUOT_LIMITS_ENABLED, type);
1816 dqopt->flags &= ~dquot_state_flag(DQUOT_STATE_FLAGS, type);
Jan Kara0ff5af82008-04-28 02:14:33 -07001817 mutex_unlock(&dqopt->dqonoff_mutex);
1818
Jan Karaf55abc02008-08-20 17:50:32 +02001819 flags = dquot_generic_flag(flags, type);
1820 ret = vfs_load_quota_inode(inode, type, dqopt->info[type].dqi_fmt_id,
1821 flags);
Jan Kara0ff5af82008-04-28 02:14:33 -07001822 iput(inode);
1823
1824 return ret;
1825}
1826
Al Viro77e69da2008-08-01 04:29:18 -04001827int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
1828 struct path *path)
1829{
1830 int error = security_quota_on(path->dentry);
1831 if (error)
1832 return error;
1833 /* Quota file not on the same filesystem? */
1834 if (path->mnt->mnt_sb != sb)
1835 error = -EXDEV;
1836 else
Jan Karaf55abc02008-08-20 17:50:32 +02001837 error = vfs_load_quota_inode(path->dentry->d_inode, type,
1838 format_id, DQUOT_USAGE_ENABLED |
1839 DQUOT_LIMITS_ENABLED);
Al Viro77e69da2008-08-01 04:29:18 -04001840 return error;
1841}
1842
Al Viro82646132008-08-02 00:57:06 -04001843int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name,
Jan Kara0ff5af82008-04-28 02:14:33 -07001844 int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845{
Al Viro82646132008-08-02 00:57:06 -04001846 struct path path;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 int error;
1848
Jan Kara0ff5af82008-04-28 02:14:33 -07001849 if (remount)
1850 return vfs_quota_on_remount(sb, type);
1851
Al Viro82646132008-08-02 00:57:06 -04001852 error = kern_path(name, LOOKUP_FOLLOW, &path);
Al Viro77e69da2008-08-01 04:29:18 -04001853 if (!error) {
Al Viro82646132008-08-02 00:57:06 -04001854 error = vfs_quota_on_path(sb, type, format_id, &path);
1855 path_put(&path);
Al Viro77e69da2008-08-01 04:29:18 -04001856 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 return error;
1858}
1859
1860/*
Jan Karaf55abc02008-08-20 17:50:32 +02001861 * More powerful function for turning on quotas allowing setting
1862 * of individual quota flags
1863 */
1864int vfs_quota_enable(struct inode *inode, int type, int format_id,
1865 unsigned int flags)
1866{
1867 int ret = 0;
1868 struct super_block *sb = inode->i_sb;
1869 struct quota_info *dqopt = sb_dqopt(sb);
1870
1871 /* Just unsuspend quotas? */
1872 if (flags & DQUOT_SUSPENDED)
1873 return vfs_quota_on_remount(sb, type);
1874 if (!flags)
1875 return 0;
1876 /* Just updating flags needed? */
1877 if (sb_has_quota_loaded(sb, type)) {
1878 mutex_lock(&dqopt->dqonoff_mutex);
1879 /* Now do a reliable test... */
1880 if (!sb_has_quota_loaded(sb, type)) {
1881 mutex_unlock(&dqopt->dqonoff_mutex);
1882 goto load_quota;
1883 }
1884 if (flags & DQUOT_USAGE_ENABLED &&
1885 sb_has_quota_usage_enabled(sb, type)) {
1886 ret = -EBUSY;
1887 goto out_lock;
1888 }
1889 if (flags & DQUOT_LIMITS_ENABLED &&
1890 sb_has_quota_limits_enabled(sb, type)) {
1891 ret = -EBUSY;
1892 goto out_lock;
1893 }
1894 sb_dqopt(sb)->flags |= dquot_state_flag(flags, type);
1895out_lock:
1896 mutex_unlock(&dqopt->dqonoff_mutex);
1897 return ret;
1898 }
1899
1900load_quota:
1901 return vfs_load_quota_inode(inode, type, format_id, flags);
1902}
1903
1904/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 * This function is used when filesystem needs to initialize quotas
1906 * during mount time.
1907 */
Christoph Hellwig84de8562005-06-23 00:09:16 -07001908int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
1909 int format_id, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
Christoph Hellwig84de8562005-06-23 00:09:16 -07001911 struct dentry *dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 int error;
1913
Christoph Hellwig2fa389c2005-06-23 00:09:16 -07001914 dentry = lookup_one_len(qf_name, sb->s_root, strlen(qf_name));
Christoph Hellwig84de8562005-06-23 00:09:16 -07001915 if (IS_ERR(dentry))
1916 return PTR_ERR(dentry);
1917
Jan Kara154f4842005-11-28 13:44:14 -08001918 if (!dentry->d_inode) {
1919 error = -ENOENT;
1920 goto out;
1921 }
1922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 error = security_quota_on(dentry);
Christoph Hellwig84de8562005-06-23 00:09:16 -07001924 if (!error)
Jan Karaf55abc02008-08-20 17:50:32 +02001925 error = vfs_load_quota_inode(dentry->d_inode, type, format_id,
1926 DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
Christoph Hellwig84de8562005-06-23 00:09:16 -07001927
Jan Kara154f4842005-11-28 13:44:14 -08001928out:
Christoph Hellwig84de8562005-06-23 00:09:16 -07001929 dput(dentry);
1930 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931}
1932
Jan Karab85f4b82008-07-25 01:46:50 -07001933/* Wrapper to turn on quotas when remounting rw */
1934int vfs_dq_quota_on_remount(struct super_block *sb)
1935{
1936 int cnt;
1937 int ret = 0, err;
1938
1939 if (!sb->s_qcop || !sb->s_qcop->quota_on)
1940 return -ENOSYS;
1941 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1942 err = sb->s_qcop->quota_on(sb, cnt, 0, NULL, 1);
1943 if (err < 0 && !ret)
1944 ret = err;
1945 }
1946 return ret;
1947}
1948
Jan Kara12095462008-08-20 14:45:12 +02001949static inline qsize_t qbtos(qsize_t blocks)
1950{
1951 return blocks << QIF_DQBLKSIZE_BITS;
1952}
1953
1954static inline qsize_t stoqb(qsize_t space)
1955{
1956 return (space + QIF_DQBLKSIZE - 1) >> QIF_DQBLKSIZE_BITS;
1957}
1958
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959/* Generic routine for getting common part of quota structure */
1960static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di)
1961{
1962 struct mem_dqblk *dm = &dquot->dq_dqb;
1963
1964 spin_lock(&dq_data_lock);
Jan Kara12095462008-08-20 14:45:12 +02001965 di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit);
1966 di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 di->dqb_curspace = dm->dqb_curspace;
1968 di->dqb_ihardlimit = dm->dqb_ihardlimit;
1969 di->dqb_isoftlimit = dm->dqb_isoftlimit;
1970 di->dqb_curinodes = dm->dqb_curinodes;
1971 di->dqb_btime = dm->dqb_btime;
1972 di->dqb_itime = dm->dqb_itime;
1973 di->dqb_valid = QIF_ALL;
1974 spin_unlock(&dq_data_lock);
1975}
1976
1977int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
1978{
1979 struct dquot *dquot;
1980
Ingo Molnard3be9152006-03-23 03:00:29 -08001981 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 if (!(dquot = dqget(sb, id, type))) {
Ingo Molnard3be9152006-03-23 03:00:29 -08001983 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 return -ESRCH;
1985 }
1986 do_get_dqblk(dquot, di);
1987 dqput(dquot);
Ingo Molnard3be9152006-03-23 03:00:29 -08001988 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 return 0;
1990}
1991
1992/* Generic routine for setting common part of quota structure */
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07001993static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
1995 struct mem_dqblk *dm = &dquot->dq_dqb;
1996 int check_blim = 0, check_ilim = 0;
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07001997 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
1998
1999 if ((di->dqb_valid & QIF_BLIMITS &&
2000 (di->dqb_bhardlimit > dqi->dqi_maxblimit ||
2001 di->dqb_bsoftlimit > dqi->dqi_maxblimit)) ||
2002 (di->dqb_valid & QIF_ILIMITS &&
2003 (di->dqb_ihardlimit > dqi->dqi_maxilimit ||
2004 di->dqb_isoftlimit > dqi->dqi_maxilimit)))
2005 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 spin_lock(&dq_data_lock);
2008 if (di->dqb_valid & QIF_SPACE) {
2009 dm->dqb_curspace = di->dqb_curspace;
2010 check_blim = 1;
2011 }
2012 if (di->dqb_valid & QIF_BLIMITS) {
Jan Kara12095462008-08-20 14:45:12 +02002013 dm->dqb_bsoftlimit = qbtos(di->dqb_bsoftlimit);
2014 dm->dqb_bhardlimit = qbtos(di->dqb_bhardlimit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 check_blim = 1;
2016 }
2017 if (di->dqb_valid & QIF_INODES) {
2018 dm->dqb_curinodes = di->dqb_curinodes;
2019 check_ilim = 1;
2020 }
2021 if (di->dqb_valid & QIF_ILIMITS) {
2022 dm->dqb_isoftlimit = di->dqb_isoftlimit;
2023 dm->dqb_ihardlimit = di->dqb_ihardlimit;
2024 check_ilim = 1;
2025 }
2026 if (di->dqb_valid & QIF_BTIME)
2027 dm->dqb_btime = di->dqb_btime;
2028 if (di->dqb_valid & QIF_ITIME)
2029 dm->dqb_itime = di->dqb_itime;
2030
2031 if (check_blim) {
Jan Kara12095462008-08-20 14:45:12 +02002032 if (!dm->dqb_bsoftlimit || dm->dqb_curspace < dm->dqb_bsoftlimit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 dm->dqb_btime = 0;
2034 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
2035 }
2036 else if (!(di->dqb_valid & QIF_BTIME)) /* Set grace only if user hasn't provided his own... */
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07002037 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039 if (check_ilim) {
2040 if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) {
2041 dm->dqb_itime = 0;
2042 clear_bit(DQ_INODES_B, &dquot->dq_flags);
2043 }
2044 else if (!(di->dqb_valid & QIF_ITIME)) /* Set grace only if user hasn't provided his own... */
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07002045 dm->dqb_itime = get_seconds() + dqi->dqi_igrace;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 }
2047 if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit)
2048 clear_bit(DQ_FAKE_B, &dquot->dq_flags);
2049 else
2050 set_bit(DQ_FAKE_B, &dquot->dq_flags);
2051 spin_unlock(&dq_data_lock);
2052 mark_dquot_dirty(dquot);
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07002053
2054 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
2057int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
2058{
2059 struct dquot *dquot;
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07002060 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Ingo Molnard3be9152006-03-23 03:00:29 -08002062 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Jan Karaf55abc02008-08-20 17:50:32 +02002063 dquot = dqget(sb, id, type);
2064 if (!dquot) {
2065 rc = -ESRCH;
2066 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 }
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07002068 rc = do_set_dqblk(dquot, di);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 dqput(dquot);
Jan Karaf55abc02008-08-20 17:50:32 +02002070out:
Ingo Molnard3be9152006-03-23 03:00:29 -08002071 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Andrew Perepechko338bf9a2008-04-28 02:14:31 -07002072 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073}
2074
2075/* Generic routine for getting common part of quota file information */
2076int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
2077{
2078 struct mem_dqinfo *mi;
2079
Ingo Molnard3be9152006-03-23 03:00:29 -08002080 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Jan Karaf55abc02008-08-20 17:50:32 +02002081 if (!sb_has_quota_active(sb, type)) {
Ingo Molnard3be9152006-03-23 03:00:29 -08002082 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 return -ESRCH;
2084 }
2085 mi = sb_dqopt(sb)->info + type;
2086 spin_lock(&dq_data_lock);
2087 ii->dqi_bgrace = mi->dqi_bgrace;
2088 ii->dqi_igrace = mi->dqi_igrace;
2089 ii->dqi_flags = mi->dqi_flags & DQF_MASK;
2090 ii->dqi_valid = IIF_ALL;
2091 spin_unlock(&dq_data_lock);
Ingo Molnard3be9152006-03-23 03:00:29 -08002092 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 return 0;
2094}
2095
2096/* Generic routine for setting common part of quota file information */
2097int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
2098{
2099 struct mem_dqinfo *mi;
Jan Karaf55abc02008-08-20 17:50:32 +02002100 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Ingo Molnard3be9152006-03-23 03:00:29 -08002102 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
Jan Karaf55abc02008-08-20 17:50:32 +02002103 if (!sb_has_quota_active(sb, type)) {
2104 err = -ESRCH;
2105 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
2107 mi = sb_dqopt(sb)->info + type;
2108 spin_lock(&dq_data_lock);
2109 if (ii->dqi_valid & IIF_BGRACE)
2110 mi->dqi_bgrace = ii->dqi_bgrace;
2111 if (ii->dqi_valid & IIF_IGRACE)
2112 mi->dqi_igrace = ii->dqi_igrace;
2113 if (ii->dqi_valid & IIF_FLAGS)
2114 mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK);
2115 spin_unlock(&dq_data_lock);
2116 mark_info_dirty(sb, type);
2117 /* Force write to disk */
2118 sb->dq_op->write_info(sb, type);
Jan Karaf55abc02008-08-20 17:50:32 +02002119out:
Ingo Molnard3be9152006-03-23 03:00:29 -08002120 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
Jan Karaf55abc02008-08-20 17:50:32 +02002121 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122}
2123
2124struct quotactl_ops vfs_quotactl_ops = {
2125 .quota_on = vfs_quota_on,
2126 .quota_off = vfs_quota_off,
2127 .quota_sync = vfs_quota_sync,
2128 .get_info = vfs_get_dqinfo,
2129 .set_info = vfs_set_dqinfo,
2130 .get_dqblk = vfs_get_dqblk,
2131 .set_dqblk = vfs_set_dqblk
2132};
2133
2134static ctl_table fs_dqstats_table[] = {
2135 {
2136 .ctl_name = FS_DQ_LOOKUPS,
2137 .procname = "lookups",
2138 .data = &dqstats.lookups,
2139 .maxlen = sizeof(int),
2140 .mode = 0444,
2141 .proc_handler = &proc_dointvec,
2142 },
2143 {
2144 .ctl_name = FS_DQ_DROPS,
2145 .procname = "drops",
2146 .data = &dqstats.drops,
2147 .maxlen = sizeof(int),
2148 .mode = 0444,
2149 .proc_handler = &proc_dointvec,
2150 },
2151 {
2152 .ctl_name = FS_DQ_READS,
2153 .procname = "reads",
2154 .data = &dqstats.reads,
2155 .maxlen = sizeof(int),
2156 .mode = 0444,
2157 .proc_handler = &proc_dointvec,
2158 },
2159 {
2160 .ctl_name = FS_DQ_WRITES,
2161 .procname = "writes",
2162 .data = &dqstats.writes,
2163 .maxlen = sizeof(int),
2164 .mode = 0444,
2165 .proc_handler = &proc_dointvec,
2166 },
2167 {
2168 .ctl_name = FS_DQ_CACHE_HITS,
2169 .procname = "cache_hits",
2170 .data = &dqstats.cache_hits,
2171 .maxlen = sizeof(int),
2172 .mode = 0444,
2173 .proc_handler = &proc_dointvec,
2174 },
2175 {
2176 .ctl_name = FS_DQ_ALLOCATED,
2177 .procname = "allocated_dquots",
2178 .data = &dqstats.allocated_dquots,
2179 .maxlen = sizeof(int),
2180 .mode = 0444,
2181 .proc_handler = &proc_dointvec,
2182 },
2183 {
2184 .ctl_name = FS_DQ_FREE,
2185 .procname = "free_dquots",
2186 .data = &dqstats.free_dquots,
2187 .maxlen = sizeof(int),
2188 .mode = 0444,
2189 .proc_handler = &proc_dointvec,
2190 },
2191 {
2192 .ctl_name = FS_DQ_SYNCS,
2193 .procname = "syncs",
2194 .data = &dqstats.syncs,
2195 .maxlen = sizeof(int),
2196 .mode = 0444,
2197 .proc_handler = &proc_dointvec,
2198 },
Jan Kara8e893462007-10-16 23:29:31 -07002199#ifdef CONFIG_PRINT_QUOTA_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 {
2201 .ctl_name = FS_DQ_WARNINGS,
2202 .procname = "warnings",
2203 .data = &flag_print_warnings,
2204 .maxlen = sizeof(int),
2205 .mode = 0644,
2206 .proc_handler = &proc_dointvec,
2207 },
Jan Kara8e893462007-10-16 23:29:31 -07002208#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 { .ctl_name = 0 },
2210};
2211
2212static ctl_table fs_table[] = {
2213 {
2214 .ctl_name = FS_DQSTATS,
2215 .procname = "quota",
2216 .mode = 0555,
2217 .child = fs_dqstats_table,
2218 },
2219 { .ctl_name = 0 },
2220};
2221
2222static ctl_table sys_table[] = {
2223 {
2224 .ctl_name = CTL_FS,
2225 .procname = "fs",
2226 .mode = 0555,
2227 .child = fs_table,
2228 },
2229 { .ctl_name = 0 },
2230};
2231
2232static int __init dquot_init(void)
2233{
2234 int i;
2235 unsigned long nr_hash, order;
2236
2237 printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__);
2238
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08002239 register_sysctl_table(sys_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Paul Mundt20c2df82007-07-20 10:11:58 +09002241 dquot_cachep = kmem_cache_create("dquot",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 sizeof(struct dquot), sizeof(unsigned long) * 4,
Paul Jacksonfffb60f2006-03-24 03:16:06 -08002243 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
2244 SLAB_MEM_SPREAD|SLAB_PANIC),
Paul Mundt20c2df82007-07-20 10:11:58 +09002245 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247 order = 0;
2248 dquot_hash = (struct hlist_head *)__get_free_pages(GFP_ATOMIC, order);
2249 if (!dquot_hash)
2250 panic("Cannot create dquot hash table");
2251
2252 /* Find power-of-two hlist_heads which can fit into allocation */
2253 nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
2254 dq_hash_bits = 0;
2255 do {
2256 dq_hash_bits++;
2257 } while (nr_hash >> dq_hash_bits);
2258 dq_hash_bits--;
2259
2260 nr_hash = 1UL << dq_hash_bits;
2261 dq_hash_mask = nr_hash - 1;
2262 for (i = 0; i < nr_hash; i++)
2263 INIT_HLIST_HEAD(dquot_hash + i);
2264
2265 printk("Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n",
2266 nr_hash, order, (PAGE_SIZE << order));
2267
Rusty Russell8e1f9362007-07-17 04:03:17 -07002268 register_shrinker(&dqcache_shrinker);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
Jan Kara8e893462007-10-16 23:29:31 -07002270#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
2271 if (genl_register_family(&quota_genl_family) != 0)
2272 printk(KERN_ERR "VFS: Failed to create quota netlink interface.\n");
2273#endif
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 return 0;
2276}
2277module_init(dquot_init);
2278
2279EXPORT_SYMBOL(register_quota_format);
2280EXPORT_SYMBOL(unregister_quota_format);
2281EXPORT_SYMBOL(dqstats);
2282EXPORT_SYMBOL(dq_data_lock);
Jan Karaf55abc02008-08-20 17:50:32 +02002283EXPORT_SYMBOL(vfs_quota_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284EXPORT_SYMBOL(vfs_quota_on);
Al Viro77e69da2008-08-01 04:29:18 -04002285EXPORT_SYMBOL(vfs_quota_on_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286EXPORT_SYMBOL(vfs_quota_on_mount);
Jan Karaf55abc02008-08-20 17:50:32 +02002287EXPORT_SYMBOL(vfs_quota_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288EXPORT_SYMBOL(vfs_quota_off);
2289EXPORT_SYMBOL(vfs_quota_sync);
2290EXPORT_SYMBOL(vfs_get_dqinfo);
2291EXPORT_SYMBOL(vfs_set_dqinfo);
2292EXPORT_SYMBOL(vfs_get_dqblk);
2293EXPORT_SYMBOL(vfs_set_dqblk);
2294EXPORT_SYMBOL(dquot_commit);
2295EXPORT_SYMBOL(dquot_commit_info);
2296EXPORT_SYMBOL(dquot_acquire);
2297EXPORT_SYMBOL(dquot_release);
2298EXPORT_SYMBOL(dquot_mark_dquot_dirty);
2299EXPORT_SYMBOL(dquot_initialize);
2300EXPORT_SYMBOL(dquot_drop);
Jan Karab85f4b82008-07-25 01:46:50 -07002301EXPORT_SYMBOL(vfs_dq_drop);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302EXPORT_SYMBOL(dquot_alloc_space);
2303EXPORT_SYMBOL(dquot_alloc_inode);
2304EXPORT_SYMBOL(dquot_free_space);
2305EXPORT_SYMBOL(dquot_free_inode);
2306EXPORT_SYMBOL(dquot_transfer);
Jan Karab85f4b82008-07-25 01:46:50 -07002307EXPORT_SYMBOL(vfs_dq_transfer);
2308EXPORT_SYMBOL(vfs_dq_quota_on_remount);