]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/dquot.c
quota: Make _SUSPENDED just a flag
[mirror_ubuntu-artful-kernel.git] / fs / dquot.c
CommitLineData
1da177e4
LT
1/*
2 * Implementation of the diskquota system for the LINUX operating system. QUOTA
3 * is implemented using the BSD system call interface as the means of
4 * communication with the user level. This file contains the generic routines
5 * called by the different filesystems on allocation of an inode or block.
6 * These routines take care of the administration needed to have a consistent
7 * diskquota tracking system. The ideas of both user and group quotas are based
8 * on the Melbourne quota system as used on BSD derived systems. The internal
9 * implementation is based on one of the several variants of the LINUX
10 * inode-subsystem with added complexity of the diskquota system.
11 *
1da177e4
LT
12 * Author: Marco van Wieringen <mvw@planets.elm.net>
13 *
14 * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96
15 *
16 * Revised list management to avoid races
17 * -- Bill Hawes, <whawes@star.net>, 9/98
18 *
19 * Fixed races in dquot_transfer(), dqget() and dquot_alloc_...().
20 * As the consequence the locking was moved from dquot_decr_...(),
21 * dquot_incr_...() to calling functions.
22 * invalidate_dquots() now writes modified dquots.
23 * Serialized quota_off() and quota_on() for mount point.
24 * Fixed a few bugs in grow_dquots().
25 * Fixed deadlock in write_dquot() - we no longer account quotas on
26 * quota files
27 * remove_dquot_ref() moved to inode.c - it now traverses through inodes
28 * add_dquot_ref() restarts after blocking
29 * Added check for bogus uid and fixed check for group in quotactl.
30 * Jan Kara, <jack@suse.cz>, sponsored by SuSE CR, 10-11/99
31 *
32 * Used struct list_head instead of own list struct
33 * Invalidation of referenced dquots is no longer possible
34 * Improved free_dquots list management
35 * Quota and i_blocks are now updated in one place to avoid races
36 * Warnings are now delayed so we won't block in critical section
37 * Write updated not to require dquot lock
38 * Jan Kara, <jack@suse.cz>, 9/2000
39 *
40 * Added dynamic quota structure allocation
41 * Jan Kara <jack@suse.cz> 12/2000
42 *
43 * Rewritten quota interface. Implemented new quota format and
44 * formats registering.
45 * Jan Kara, <jack@suse.cz>, 2001,2002
46 *
47 * New SMP locking.
48 * Jan Kara, <jack@suse.cz>, 10/2002
49 *
50 * Added journalled quota support, fix lock inversion problems
51 * Jan Kara, <jack@suse.cz>, 2003,2004
52 *
53 * (C) Copyright 1994 - 1997 Marco van Wieringen
54 */
55
56#include <linux/errno.h>
57#include <linux/kernel.h>
58#include <linux/fs.h>
59#include <linux/mount.h>
60#include <linux/mm.h>
61#include <linux/time.h>
62#include <linux/types.h>
63#include <linux/string.h>
64#include <linux/fcntl.h>
65#include <linux/stat.h>
66#include <linux/tty.h>
67#include <linux/file.h>
68#include <linux/slab.h>
69#include <linux/sysctl.h>
1da177e4
LT
70#include <linux/init.h>
71#include <linux/module.h>
72#include <linux/proc_fs.h>
73#include <linux/security.h>
74#include <linux/kmod.h>
75#include <linux/namei.h>
76#include <linux/buffer_head.h>
16f7e0fe 77#include <linux/capability.h>
be586bab 78#include <linux/quotaops.h>
fb58b731 79#include <linux/writeback.h> /* for inode_lock, oddly enough.. */
8e893469
JK
80#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
81#include <net/netlink.h>
82#include <net/genetlink.h>
83#endif
1da177e4
LT
84
85#include <asm/uaccess.h>
86
87#define __DQUOT_PARANOIA
88
89/*
90 * There are two quota SMP locks. dq_list_lock protects all lists with quotas
91 * and quota formats and also dqstats structure containing statistics about the
92 * lists. dq_data_lock protects data from dq_dqb and also mem_dqinfo structures
93 * and also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
94 * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly
95 * in inode_add_bytes() and inode_sub_bytes().
96 *
97 * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock
98 *
99 * Note that some things (eg. sb pointer, type, id) doesn't change during
100 * the life of the dquot structure and so needn't to be protected by a lock
101 *
102 * Any operation working on dquots via inode pointers must hold dqptr_sem. If
103 * operation is just reading pointers from inode (or not using them at all) the
104 * read lock is enough. If pointers are altered function must hold write lock
105 * (these locking rules also apply for S_NOQUOTA flag in the inode - note that
1b1dcc1b 106 * for altering the flag i_mutex is also needed). If operation is holding
1da177e4 107 * reference to dquot in other way (e.g. quotactl ops) it must be guarded by
d3be915f 108 * dqonoff_mutex.
1da177e4
LT
109 * This locking assures that:
110 * a) update/access to dquot pointers in inode is serialized
111 * b) everyone is guarded against invalidate_dquots()
112 *
d3be915f 113 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
1da177e4
LT
114 * from inodes (dquot_alloc_space() and such don't check the dq_lock).
115 * Currently dquot is locked only when it is being read to memory (or space for
116 * it is being allocated) on the first dqget() and when it is being released on
117 * the last dqput(). The allocation and release oparations are serialized by
118 * the dq_lock and by checking the use count in dquot_release(). Write
119 * operations on dquots don't hold dq_lock as they copy data under dq_data_lock
120 * spinlock to internal buffers before writing.
121 *
122 * Lock ordering (including related VFS locks) is the following:
d3be915f
IM
123 * i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock >
124 * dqio_mutex
125 * i_mutex on quota files is special (it's below dqio_mutex)
1da177e4
LT
126 */
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 */
e18b890b 136static struct kmem_cache *dquot_cachep;
1da177e4
LT
137
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{
8e13059a 255 list_add_tail(&dquot->dq_free, &free_dquots);
1da177e4
LT
256 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 */
8e13059a 271 list_add_tail(&dquot->dq_inuse, &inuse_list);
1da177e4
LT
272 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{
d3be915f
IM
286 mutex_lock(&dquot->dq_lock);
287 mutex_unlock(&dquot->dq_lock);
1da177e4
LT
288}
289
03f6e92b
JK
290static 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}
1da177e4
LT
299
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
d3be915f
IM
334 mutex_lock(&dquot->dq_lock);
335 mutex_lock(&dqopt->dqio_mutex);
1da177e4
LT
336 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:
d3be915f
IM
356 mutex_unlock(&dqopt->dqio_mutex);
357 mutex_unlock(&dquot->dq_lock);
1da177e4
LT
358 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
d3be915f 369 mutex_lock(&dqopt->dqio_mutex);
1da177e4
LT
370 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:
d3be915f 386 mutex_unlock(&dqopt->dqio_mutex);
1da177e4
LT
387 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
d3be915f 398 mutex_lock(&dquot->dq_lock);
1da177e4
LT
399 /* Check whether we are not racing with some other dqget() */
400 if (atomic_read(&dquot->dq_count) > 1)
401 goto out_dqlock;
d3be915f 402 mutex_lock(&dqopt->dqio_mutex);
1da177e4
LT
403 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);
d3be915f 412 mutex_unlock(&dqopt->dqio_mutex);
1da177e4 413out_dqlock:
d3be915f 414 mutex_unlock(&dquot->dq_lock);
1da177e4
LT
415 return ret;
416}
417
74f783af
JK
418static 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
1da177e4
LT
428/* 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
6362e4d4
JK
430 * 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 */
1da177e4
LT
434static void invalidate_dquots(struct super_block *sb, int type)
435{
c33ed271 436 struct dquot *dquot, *tmp;
1da177e4 437
6362e4d4 438restart:
1da177e4 439 spin_lock(&dq_list_lock);
c33ed271 440 list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) {
1da177e4
LT
441 if (dquot->dq_sb != sb)
442 continue;
443 if (dquot->dq_type != type)
444 continue;
6362e4d4
JK
445 /* 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 */
1da177e4
LT
473 remove_dquot_hash(dquot);
474 remove_free_dquot(dquot);
475 remove_inuse(dquot);
74f783af 476 do_destroy_dquot(dquot);
1da177e4
LT
477 }
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
d3be915f 488 mutex_lock(&dqopt->dqonoff_mutex);
1da177e4
LT
489 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
490 if (type != -1 && cnt != type)
491 continue;
492 if (!sb_has_quota_enabled(sb, cnt))
493 continue;
494 spin_lock(&dq_list_lock);
495 dirty = &dqopt->info[cnt].dqi_dirty_list;
496 while (!list_empty(dirty)) {
b5e61818 497 dquot = list_first_entry(dirty, struct dquot, dq_dirty);
1da177e4
LT
498 /* 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++)
517 if ((cnt == type || type == -1) && sb_has_quota_enabled(sb, cnt)
518 && info_dirty(&dqopt->info[cnt]))
519 sb->dq_op->write_info(sb, cnt);
520 spin_lock(&dq_list_lock);
521 dqstats.syncs++;
522 spin_unlock(&dq_list_lock);
d3be915f 523 mutex_unlock(&dqopt->dqonoff_mutex);
1da177e4
LT
524
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);
74f783af 540 do_destroy_dquot(dquot);
1da177e4
LT
541 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
27496a8c 551static int shrink_dqcache_memory(int nr, gfp_t gfp_mask)
1da177e4
LT
552{
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
8e1f936b
RR
561static struct shrinker dqcache_shrinker = {
562 .shrink = shrink_dqcache_memory,
563 .seeks = DEFAULT_SEEKS,
564};
565
1da177e4
LT
566/*
567 * Put reference to dquot
568 * NOTE: If you change this function please check whether dqput_blocks() works right...
d3be915f 569 * MUST be called with either dqptr_sem or dqonoff_mutex held
1da177e4
LT
570 */
571static void dqput(struct dquot *dquot)
572{
b48d3805
JK
573 int ret;
574
1da177e4
LT
575 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);
6362e4d4
JK
596 /* Releasing dquot during quotaoff phase? */
597 if (!sb_has_quota_enabled(dquot->dq_sb, dquot->dq_type) &&
598 atomic_read(&dquot->dq_count) == 1)
599 wake_up(&dquot->dq_wait_unused);
1da177e4
LT
600 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 */
b48d3805
JK
607 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 }
1da177e4
LT
620 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 */
8abf6a47 632 BUG_ON(!list_empty(&dquot->dq_free));
1da177e4
LT
633#endif
634 put_dquot_last(dquot);
635 spin_unlock(&dq_list_lock);
636}
637
74f783af
JK
638static struct dquot *dquot_alloc(struct super_block *sb, int type)
639{
640 return kmem_cache_zalloc(dquot_cachep, GFP_NOFS);
641}
642
1da177e4
LT
643static struct dquot *get_empty_dquot(struct super_block *sb, int type)
644{
645 struct dquot *dquot;
646
74f783af 647 dquot = sb->dq_op->alloc_dquot(sb, type);
1da177e4
LT
648 if(!dquot)
649 return NODQUOT;
650
d3be915f 651 mutex_init(&dquot->dq_lock);
1da177e4
LT
652 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);
6362e4d4 656 init_waitqueue_head(&dquot->dq_wait_unused);
1da177e4
LT
657 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
d3be915f 666 * MUST be called with either dqptr_sem or dqonoff_mutex held
1da177e4
LT
667 */
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
673 if (!sb_has_quota_enabled(sb, type))
674 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)
74f783af 700 do_destroy_dquot(empty);
1da177e4
LT
701 }
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
8abf6a47 711 BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */
1da177e4
LT
712#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
d3be915f 731/* This routine is guarded by dqonoff_mutex mutex */
1da177e4
LT
732static void add_dquot_ref(struct super_block *sb, int type)
733{
941d2380 734 struct inode *inode, *old_inode = NULL;
1da177e4 735
d003fb70
CH
736 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
941d2380 748 iput(old_inode);
d003fb70 749 sb->dq_op->initialize(inode, type);
941d2380
JK
750 /* 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);
1da177e4 757 }
d003fb70 758 spin_unlock(&inode_lock);
941d2380 759 iput(old_inode);
1da177e4
LT
760}
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... */
e5f00f42
AB
772static int remove_inode_dquot_ref(struct inode *inode, int type,
773 struct list_head *tofree_head)
1da177e4
LT
774{
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
fb58b731
CH
812static 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
1da177e4
LT
825/* 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
fb58b731
CH
830 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 }
1da177e4
LT
836}
837
12095460 838static inline void dquot_incr_inodes(struct dquot *dquot, qsize_t number)
1da177e4
LT
839{
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
12095460 848static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
1da177e4
LT
849{
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;
12095460 865 if (dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit)
1da177e4
LT
866 dquot->dq_dqb.dqb_btime = (time_t) 0;
867 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
868}
869
c525460e
JK
870static 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
8e893469 882#ifdef CONFIG_PRINT_QUOTA_WARNING
1da177e4
LT
883static 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:
da9592ed 892 return current_fsuid() == dquot->dq_id;
1da177e4
LT
893 case GRPQUOTA:
894 return in_group_p(dquot->dq_id);
895 }
896 return 0;
897}
898
1da177e4 899/* Print warning to user which exceeded quota */
c525460e 900static void print_warning(struct dquot *dquot, const int warntype)
1da177e4
LT
901{
902 char *msg = NULL;
24ec839c 903 struct tty_struct *tty;
1da177e4 904
657d3bfa
JK
905 if (warntype == QUOTA_NL_IHARDBELOW ||
906 warntype == QUOTA_NL_ISOFTBELOW ||
907 warntype == QUOTA_NL_BHARDBELOW ||
908 warntype == QUOTA_NL_BSOFTBELOW || !need_print_warning(dquot))
1da177e4
LT
909 return;
910
24ec839c
PZ
911 tty = get_current_tty();
912 if (!tty)
452a00d2 913 return;
24ec839c 914 tty_write_message(tty, dquot->dq_sb->s_id);
8e893469 915 if (warntype == QUOTA_NL_ISOFTWARN || warntype == QUOTA_NL_BSOFTWARN)
24ec839c 916 tty_write_message(tty, ": warning, ");
1da177e4 917 else
24ec839c
PZ
918 tty_write_message(tty, ": write failed, ");
919 tty_write_message(tty, quotatypes[dquot->dq_type]);
1da177e4 920 switch (warntype) {
8e893469 921 case QUOTA_NL_IHARDWARN:
1da177e4
LT
922 msg = " file limit reached.\r\n";
923 break;
8e893469 924 case QUOTA_NL_ISOFTLONGWARN:
1da177e4
LT
925 msg = " file quota exceeded too long.\r\n";
926 break;
8e893469 927 case QUOTA_NL_ISOFTWARN:
1da177e4
LT
928 msg = " file quota exceeded.\r\n";
929 break;
8e893469 930 case QUOTA_NL_BHARDWARN:
1da177e4
LT
931 msg = " block limit reached.\r\n";
932 break;
8e893469 933 case QUOTA_NL_BSOFTLONGWARN:
1da177e4
LT
934 msg = " block quota exceeded too long.\r\n";
935 break;
8e893469 936 case QUOTA_NL_BSOFTWARN:
1da177e4
LT
937 msg = " block quota exceeded.\r\n";
938 break;
939 }
24ec839c 940 tty_write_message(tty, msg);
452a00d2 941 tty_kref_put(tty);
1da177e4 942}
8e893469
JK
943#endif
944
945#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
946
8e893469
JK
947/* 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;
22dd4837
JK
963 int msg_size = 4 * nla_total_size(sizeof(u32)) +
964 2 * nla_total_size(sizeof(u64));
8e893469
JK
965
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. */
22dd4837 969 skb = genlmsg_new(msg_size, GFP_NOFS);
8e893469
JK
970 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;
da9592ed 999 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid());
8e893469
JK
1000 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:
22dd4837 1010 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
8e893469
JK
1011err_out:
1012 kfree_skb(skb);
1013}
1014#endif
1da177e4 1015
087ee8d5 1016static inline void flush_warnings(struct dquot * const *dquots, char *warntype)
1da177e4
LT
1017{
1018 int i;
1019
1020 for (i = 0; i < MAXQUOTAS; i++)
c525460e
JK
1021 if (dquots[i] != NODQUOT && warntype[i] != QUOTA_NL_NOWARN &&
1022 !warning_issued(dquots[i], warntype[i])) {
8e893469 1023#ifdef CONFIG_PRINT_QUOTA_WARNING
1da177e4 1024 print_warning(dquots[i], warntype[i]);
8e893469
JK
1025#endif
1026#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
1027 send_warning(dquots[i], warntype[i]);
1028#endif
1029 }
1da177e4
LT
1030}
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 */
12095460 1041static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1da177e4 1042{
8e893469 1043 *warntype = QUOTA_NL_NOWARN;
1497d3ad 1044 if (test_bit(DQ_FAKE_B, &dquot->dq_flags))
1da177e4
LT
1045 return QUOTA_OK;
1046
1047 if (dquot->dq_dqb.dqb_ihardlimit &&
1048 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit &&
1049 !ignore_hardlimit(dquot)) {
8e893469 1050 *warntype = QUOTA_NL_IHARDWARN;
1da177e4
LT
1051 return NO_QUOTA;
1052 }
1053
1054 if (dquot->dq_dqb.dqb_isoftlimit &&
1055 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
1056 dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime &&
1057 !ignore_hardlimit(dquot)) {
8e893469 1058 *warntype = QUOTA_NL_ISOFTLONGWARN;
1da177e4
LT
1059 return NO_QUOTA;
1060 }
1061
1062 if (dquot->dq_dqb.dqb_isoftlimit &&
1063 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
1064 dquot->dq_dqb.dqb_itime == 0) {
8e893469 1065 *warntype = QUOTA_NL_ISOFTWARN;
1da177e4
LT
1066 dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1067 }
1068
1069 return QUOTA_OK;
1070}
1071
1072/* needs dq_data_lock */
1073static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
1074{
8e893469 1075 *warntype = QUOTA_NL_NOWARN;
1497d3ad 1076 if (test_bit(DQ_FAKE_B, &dquot->dq_flags))
1da177e4
LT
1077 return QUOTA_OK;
1078
1079 if (dquot->dq_dqb.dqb_bhardlimit &&
12095460 1080 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bhardlimit &&
1da177e4
LT
1081 !ignore_hardlimit(dquot)) {
1082 if (!prealloc)
8e893469 1083 *warntype = QUOTA_NL_BHARDWARN;
1da177e4
LT
1084 return NO_QUOTA;
1085 }
1086
1087 if (dquot->dq_dqb.dqb_bsoftlimit &&
12095460 1088 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit &&
1da177e4
LT
1089 dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime &&
1090 !ignore_hardlimit(dquot)) {
1091 if (!prealloc)
8e893469 1092 *warntype = QUOTA_NL_BSOFTLONGWARN;
1da177e4
LT
1093 return NO_QUOTA;
1094 }
1095
1096 if (dquot->dq_dqb.dqb_bsoftlimit &&
12095460 1097 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit &&
1da177e4
LT
1098 dquot->dq_dqb.dqb_btime == 0) {
1099 if (!prealloc) {
8e893469 1100 *warntype = QUOTA_NL_BSOFTWARN;
1da177e4
LT
1101 dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
1102 }
1103 else
1104 /*
1105 * We don't allow preallocation to exceed softlimit so exceeding will
1106 * be always printed
1107 */
1108 return NO_QUOTA;
1109 }
1110
1111 return QUOTA_OK;
1112}
1113
12095460 1114static int info_idq_free(struct dquot *dquot, qsize_t inodes)
657d3bfa
JK
1115{
1116 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
1117 dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit)
1118 return QUOTA_NL_NOWARN;
1119
1120 if (dquot->dq_dqb.dqb_curinodes - inodes <= dquot->dq_dqb.dqb_isoftlimit)
1121 return QUOTA_NL_ISOFTBELOW;
1122 if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit &&
1123 dquot->dq_dqb.dqb_curinodes - inodes < dquot->dq_dqb.dqb_ihardlimit)
1124 return QUOTA_NL_IHARDBELOW;
1125 return QUOTA_NL_NOWARN;
1126}
1127
1128static int info_bdq_free(struct dquot *dquot, qsize_t space)
1129{
1130 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
12095460 1131 dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit)
657d3bfa
JK
1132 return QUOTA_NL_NOWARN;
1133
12095460 1134 if (dquot->dq_dqb.dqb_curspace - space <= dquot->dq_dqb.dqb_bsoftlimit)
657d3bfa 1135 return QUOTA_NL_BSOFTBELOW;
12095460
JK
1136 if (dquot->dq_dqb.dqb_curspace >= dquot->dq_dqb.dqb_bhardlimit &&
1137 dquot->dq_dqb.dqb_curspace - space < dquot->dq_dqb.dqb_bhardlimit)
657d3bfa
JK
1138 return QUOTA_NL_BHARDBELOW;
1139 return QUOTA_NL_NOWARN;
1140}
1da177e4
LT
1141/*
1142 * Initialize quota pointers in inode
1143 * Transaction must be started at entry
1144 */
1145int dquot_initialize(struct inode *inode, int type)
1146{
1147 unsigned int id = 0;
1148 int cnt, ret = 0;
1149
d3be915f
IM
1150 /* First test before acquiring mutex - solves deadlocks when we
1151 * re-enter the quota code and are already holding the mutex */
1da177e4
LT
1152 if (IS_NOQUOTA(inode))
1153 return 0;
1154 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1155 /* Having dqptr_sem we know NOQUOTA flags can't be altered... */
1156 if (IS_NOQUOTA(inode))
1157 goto out_err;
1158 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1159 if (type != -1 && cnt != type)
1160 continue;
1161 if (inode->i_dquot[cnt] == NODQUOT) {
1162 switch (cnt) {
1163 case USRQUOTA:
1164 id = inode->i_uid;
1165 break;
1166 case GRPQUOTA:
1167 id = inode->i_gid;
1168 break;
1169 }
1170 inode->i_dquot[cnt] = dqget(inode->i_sb, id, cnt);
1171 }
1172 }
1173out_err:
1174 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1175 return ret;
1176}
1177
1178/*
1179 * Release all quotas referenced by inode
1180 * Transaction must be started at an entry
1181 */
1182int dquot_drop(struct inode *inode)
1183{
1184 int cnt;
1185
1186 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1187 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1188 if (inode->i_dquot[cnt] != NODQUOT) {
1189 dqput(inode->i_dquot[cnt]);
1190 inode->i_dquot[cnt] = NODQUOT;
1191 }
1192 }
1193 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1194 return 0;
1195}
1196
b85f4b87
JK
1197/* Wrapper to remove references to quota structures from inode */
1198void vfs_dq_drop(struct inode *inode)
1199{
1200 /* Here we can get arbitrary inode from clear_inode() so we have
1201 * to be careful. OTOH we don't need locking as quota operations
1202 * are allowed to change only at mount time */
1203 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
1204 && inode->i_sb->dq_op->drop) {
1205 int cnt;
1206 /* Test before calling to rule out calls from proc and such
1207 * where we are not allowed to block. Note that this is
1208 * actually reliable test even without the lock - the caller
1209 * must assure that nobody can come after the DQUOT_DROP and
1210 * add quota pointers back anyway */
1211 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1212 if (inode->i_dquot[cnt] != NODQUOT)
1213 break;
1214 if (cnt < MAXQUOTAS)
1215 inode->i_sb->dq_op->drop(inode);
1216 }
1217}
1218
1da177e4
LT
1219/*
1220 * Following four functions update i_blocks+i_bytes fields and
1221 * quota information (together with appropriate checks)
1222 * NOTE: We absolutely rely on the fact that caller dirties
1223 * the inode (usually macros in quotaops.h care about this) and
1224 * holds a handle for the current transaction so that dquot write and
1225 * inode write go into the same transaction.
1226 */
1227
1228/*
1229 * This operation can block, but only after everything is updated
1230 */
1231int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
1232{
1233 int cnt, ret = NO_QUOTA;
1234 char warntype[MAXQUOTAS];
1235
d3be915f
IM
1236 /* First test before acquiring mutex - solves deadlocks when we
1237 * re-enter the quota code and are already holding the mutex */
1da177e4
LT
1238 if (IS_NOQUOTA(inode)) {
1239out_add:
1240 inode_add_bytes(inode, number);
1241 return QUOTA_OK;
1242 }
1243 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
8e893469 1244 warntype[cnt] = QUOTA_NL_NOWARN;
1da177e4
LT
1245
1246 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1247 if (IS_NOQUOTA(inode)) { /* Now we can do reliable test... */
1248 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1249 goto out_add;
1250 }
1251 spin_lock(&dq_data_lock);
1252 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1253 if (inode->i_dquot[cnt] == NODQUOT)
1254 continue;
1255 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA)
1256 goto warn_put_all;
1257 }
1258 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1259 if (inode->i_dquot[cnt] == NODQUOT)
1260 continue;
1261 dquot_incr_space(inode->i_dquot[cnt], number);
1262 }
1263 inode_add_bytes(inode, number);
1264 ret = QUOTA_OK;
1265warn_put_all:
1266 spin_unlock(&dq_data_lock);
1267 if (ret == QUOTA_OK)
1268 /* Dirtify all the dquots - this can block when journalling */
1269 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1270 if (inode->i_dquot[cnt])
1271 mark_dquot_dirty(inode->i_dquot[cnt]);
1272 flush_warnings(inode->i_dquot, warntype);
1273 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1274 return ret;
1275}
1276
1277/*
1278 * This operation can block, but only after everything is updated
1279 */
12095460 1280int dquot_alloc_inode(const struct inode *inode, qsize_t number)
1da177e4
LT
1281{
1282 int cnt, ret = NO_QUOTA;
1283 char warntype[MAXQUOTAS];
1284
d3be915f
IM
1285 /* First test before acquiring mutex - solves deadlocks when we
1286 * re-enter the quota code and are already holding the mutex */
1da177e4
LT
1287 if (IS_NOQUOTA(inode))
1288 return QUOTA_OK;
1289 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
8e893469 1290 warntype[cnt] = QUOTA_NL_NOWARN;
1da177e4
LT
1291 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1292 if (IS_NOQUOTA(inode)) {
1293 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1294 return QUOTA_OK;
1295 }
1296 spin_lock(&dq_data_lock);
1297 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1298 if (inode->i_dquot[cnt] == NODQUOT)
1299 continue;
1300 if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA)
1301 goto warn_put_all;
1302 }
1303
1304 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1305 if (inode->i_dquot[cnt] == NODQUOT)
1306 continue;
1307 dquot_incr_inodes(inode->i_dquot[cnt], number);
1308 }
1309 ret = QUOTA_OK;
1310warn_put_all:
1311 spin_unlock(&dq_data_lock);
1312 if (ret == QUOTA_OK)
1313 /* Dirtify all the dquots - this can block when journalling */
1314 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1315 if (inode->i_dquot[cnt])
1316 mark_dquot_dirty(inode->i_dquot[cnt]);
087ee8d5 1317 flush_warnings(inode->i_dquot, warntype);
1da177e4
LT
1318 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1319 return ret;
1320}
1321
1322/*
1323 * This operation can block, but only after everything is updated
1324 */
1325int dquot_free_space(struct inode *inode, qsize_t number)
1326{
1327 unsigned int cnt;
657d3bfa 1328 char warntype[MAXQUOTAS];
1da177e4 1329
d3be915f
IM
1330 /* First test before acquiring mutex - solves deadlocks when we
1331 * re-enter the quota code and are already holding the mutex */
1da177e4
LT
1332 if (IS_NOQUOTA(inode)) {
1333out_sub:
1334 inode_sub_bytes(inode, number);
1335 return QUOTA_OK;
1336 }
657d3bfa 1337
1da177e4
LT
1338 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1339 /* Now recheck reliably when holding dqptr_sem */
1340 if (IS_NOQUOTA(inode)) {
1341 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1342 goto out_sub;
1343 }
1344 spin_lock(&dq_data_lock);
1345 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1346 if (inode->i_dquot[cnt] == NODQUOT)
1347 continue;
657d3bfa 1348 warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number);
1da177e4
LT
1349 dquot_decr_space(inode->i_dquot[cnt], number);
1350 }
1351 inode_sub_bytes(inode, number);
1352 spin_unlock(&dq_data_lock);
1353 /* Dirtify all the dquots - this can block when journalling */
1354 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1355 if (inode->i_dquot[cnt])
1356 mark_dquot_dirty(inode->i_dquot[cnt]);
657d3bfa 1357 flush_warnings(inode->i_dquot, warntype);
1da177e4
LT
1358 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1359 return QUOTA_OK;
1360}
1361
1362/*
1363 * This operation can block, but only after everything is updated
1364 */
12095460 1365int dquot_free_inode(const struct inode *inode, qsize_t number)
1da177e4
LT
1366{
1367 unsigned int cnt;
657d3bfa 1368 char warntype[MAXQUOTAS];
1da177e4 1369
d3be915f
IM
1370 /* First test before acquiring mutex - solves deadlocks when we
1371 * re-enter the quota code and are already holding the mutex */
1da177e4
LT
1372 if (IS_NOQUOTA(inode))
1373 return QUOTA_OK;
657d3bfa 1374
1da177e4
LT
1375 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1376 /* Now recheck reliably when holding dqptr_sem */
1377 if (IS_NOQUOTA(inode)) {
1378 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1379 return QUOTA_OK;
1380 }
1381 spin_lock(&dq_data_lock);
1382 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1383 if (inode->i_dquot[cnt] == NODQUOT)
1384 continue;
657d3bfa 1385 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number);
1da177e4
LT
1386 dquot_decr_inodes(inode->i_dquot[cnt], number);
1387 }
1388 spin_unlock(&dq_data_lock);
1389 /* Dirtify all the dquots - this can block when journalling */
1390 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1391 if (inode->i_dquot[cnt])
1392 mark_dquot_dirty(inode->i_dquot[cnt]);
657d3bfa 1393 flush_warnings(inode->i_dquot, warntype);
1da177e4
LT
1394 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1395 return QUOTA_OK;
1396}
1397
1398/*
1399 * Transfer the number of inode and blocks from one diskquota to an other.
1400 *
1401 * This operation can block, but only after everything is updated
1402 * A transaction must be started when entering this function.
1403 */
1404int dquot_transfer(struct inode *inode, struct iattr *iattr)
1405{
1406 qsize_t space;
1407 struct dquot *transfer_from[MAXQUOTAS];
1408 struct dquot *transfer_to[MAXQUOTAS];
1409 int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid,
1410 chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid;
657d3bfa
JK
1411 char warntype_to[MAXQUOTAS];
1412 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS];
1da177e4 1413
d3be915f
IM
1414 /* First test before acquiring mutex - solves deadlocks when we
1415 * re-enter the quota code and are already holding the mutex */
1da177e4
LT
1416 if (IS_NOQUOTA(inode))
1417 return QUOTA_OK;
1418 /* Clear the arrays */
1419 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1420 transfer_to[cnt] = transfer_from[cnt] = NODQUOT;
657d3bfa 1421 warntype_to[cnt] = QUOTA_NL_NOWARN;
1da177e4
LT
1422 }
1423 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1424 /* Now recheck reliably when holding dqptr_sem */
1425 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */
1426 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1427 return QUOTA_OK;
1428 }
1429 /* First build the transfer_to list - here we can block on
1430 * reading/instantiating of dquots. We know that the transaction for
1431 * us was already started so we don't violate lock ranking here */
1432 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1433 switch (cnt) {
1434 case USRQUOTA:
1435 if (!chuid)
1436 continue;
1437 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
1438 break;
1439 case GRPQUOTA:
1440 if (!chgid)
1441 continue;
1442 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt);
1443 break;
1444 }
1445 }
1446 spin_lock(&dq_data_lock);
1447 space = inode_get_bytes(inode);
1448 /* Build the transfer_from list and check the limits */
1449 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1450 if (transfer_to[cnt] == NODQUOT)
1451 continue;
1452 transfer_from[cnt] = inode->i_dquot[cnt];
657d3bfa
JK
1453 if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) ==
1454 NO_QUOTA || check_bdq(transfer_to[cnt], space, 0,
1455 warntype_to + cnt) == NO_QUOTA)
1da177e4
LT
1456 goto warn_put_all;
1457 }
1458
1459 /*
1460 * Finally perform the needed transfer from transfer_from to transfer_to
1461 */
1462 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1463 /*
1464 * Skip changes for same uid or gid or for turned off quota-type.
1465 */
1466 if (transfer_to[cnt] == NODQUOT)
1467 continue;
1468
1469 /* Due to IO error we might not have transfer_from[] structure */
1470 if (transfer_from[cnt]) {
657d3bfa
JK
1471 warntype_from_inodes[cnt] =
1472 info_idq_free(transfer_from[cnt], 1);
1473 warntype_from_space[cnt] =
1474 info_bdq_free(transfer_from[cnt], space);
1da177e4
LT
1475 dquot_decr_inodes(transfer_from[cnt], 1);
1476 dquot_decr_space(transfer_from[cnt], space);
1477 }
1478
1479 dquot_incr_inodes(transfer_to[cnt], 1);
1480 dquot_incr_space(transfer_to[cnt], space);
1481
1482 inode->i_dquot[cnt] = transfer_to[cnt];
1483 }
1484 ret = QUOTA_OK;
1485warn_put_all:
1486 spin_unlock(&dq_data_lock);
1487 /* Dirtify all the dquots - this can block when journalling */
1488 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1489 if (transfer_from[cnt])
1490 mark_dquot_dirty(transfer_from[cnt]);
1491 if (transfer_to[cnt])
1492 mark_dquot_dirty(transfer_to[cnt]);
1493 }
657d3bfa
JK
1494 flush_warnings(transfer_to, warntype_to);
1495 flush_warnings(transfer_from, warntype_from_inodes);
1496 flush_warnings(transfer_from, warntype_from_space);
1da177e4
LT
1497
1498 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1499 if (ret == QUOTA_OK && transfer_from[cnt] != NODQUOT)
1500 dqput(transfer_from[cnt]);
1501 if (ret == NO_QUOTA && transfer_to[cnt] != NODQUOT)
1502 dqput(transfer_to[cnt]);
1503 }
1504 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1505 return ret;
1506}
1507
b85f4b87
JK
1508/* Wrapper for transferring ownership of an inode */
1509int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
1510{
1511 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
1512 vfs_dq_init(inode);
1513 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
1514 return 1;
1515 }
1516 return 0;
1517}
1518
1519
1da177e4
LT
1520/*
1521 * Write info of quota file to disk
1522 */
1523int dquot_commit_info(struct super_block *sb, int type)
1524{
1525 int ret;
1526 struct quota_info *dqopt = sb_dqopt(sb);
1527
d3be915f 1528 mutex_lock(&dqopt->dqio_mutex);
1da177e4 1529 ret = dqopt->ops[type]->write_file_info(sb, type);
d3be915f 1530 mutex_unlock(&dqopt->dqio_mutex);
1da177e4
LT
1531 return ret;
1532}
1533
1534/*
1535 * Definitions of diskquota operations.
1536 */
1537struct dquot_operations dquot_operations = {
1538 .initialize = dquot_initialize,
1539 .drop = dquot_drop,
1540 .alloc_space = dquot_alloc_space,
1541 .alloc_inode = dquot_alloc_inode,
1542 .free_space = dquot_free_space,
1543 .free_inode = dquot_free_inode,
1544 .transfer = dquot_transfer,
1545 .write_dquot = dquot_commit,
1546 .acquire_dquot = dquot_acquire,
1547 .release_dquot = dquot_release,
1548 .mark_dirty = dquot_mark_dquot_dirty,
74f783af
JK
1549 .write_info = dquot_commit_info,
1550 .alloc_dquot = dquot_alloc,
1551 .destroy_dquot = dquot_destroy,
1da177e4
LT
1552};
1553
1554static inline void set_enable_flags(struct quota_info *dqopt, int type)
1555{
1556 switch (type) {
1557 case USRQUOTA:
1558 dqopt->flags |= DQUOT_USR_ENABLED;
0ff5af83 1559 dqopt->flags &= ~DQUOT_USR_SUSPENDED;
1da177e4
LT
1560 break;
1561 case GRPQUOTA:
1562 dqopt->flags |= DQUOT_GRP_ENABLED;
0ff5af83 1563 dqopt->flags &= ~DQUOT_GRP_SUSPENDED;
1da177e4
LT
1564 break;
1565 }
1566}
1567
0ff5af83
JK
1568static inline void reset_enable_flags(struct quota_info *dqopt, int type,
1569 int remount)
1da177e4
LT
1570{
1571 switch (type) {
1572 case USRQUOTA:
0ff5af83
JK
1573 if (remount)
1574 dqopt->flags |= DQUOT_USR_SUSPENDED;
e4bc7b4b
JK
1575 else {
1576 dqopt->flags &= ~DQUOT_USR_ENABLED;
0ff5af83 1577 dqopt->flags &= ~DQUOT_USR_SUSPENDED;
e4bc7b4b 1578 }
1da177e4
LT
1579 break;
1580 case GRPQUOTA:
0ff5af83
JK
1581 if (remount)
1582 dqopt->flags |= DQUOT_GRP_SUSPENDED;
e4bc7b4b
JK
1583 else {
1584 dqopt->flags &= ~DQUOT_GRP_ENABLED;
0ff5af83 1585 dqopt->flags &= ~DQUOT_GRP_SUSPENDED;
e4bc7b4b 1586 }
1da177e4
LT
1587 break;
1588 }
1589}
1590
0ff5af83 1591
1da177e4
LT
1592/*
1593 * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount)
1594 */
0ff5af83 1595int vfs_quota_off(struct super_block *sb, int type, int remount)
1da177e4 1596{
0ff5af83 1597 int cnt, ret = 0;
1da177e4
LT
1598 struct quota_info *dqopt = sb_dqopt(sb);
1599 struct inode *toputinode[MAXQUOTAS];
1da177e4
LT
1600
1601 /* We need to serialize quota_off() for device */
d3be915f 1602 mutex_lock(&dqopt->dqonoff_mutex);
9377abd0
JK
1603
1604 /*
1605 * Skip everything if there's nothing to do. We have to do this because
1606 * sometimes we are called when fill_super() failed and calling
1607 * sync_fs() in such cases does no good.
1608 */
1609 if (!sb_any_quota_enabled(sb) && !sb_any_quota_suspended(sb)) {
1610 mutex_unlock(&dqopt->dqonoff_mutex);
1611 return 0;
1612 }
1da177e4
LT
1613 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1614 toputinode[cnt] = NULL;
1da177e4
LT
1615 if (type != -1 && cnt != type)
1616 continue;
0ff5af83
JK
1617 /* If we keep inodes of quota files after remount and quotaoff
1618 * is called, drop kept inodes. */
1619 if (!remount && sb_has_quota_suspended(sb, cnt)) {
1620 iput(dqopt->files[cnt]);
1621 dqopt->files[cnt] = NULL;
1622 reset_enable_flags(dqopt, cnt, 0);
1623 continue;
1624 }
1da177e4
LT
1625 if (!sb_has_quota_enabled(sb, cnt))
1626 continue;
0ff5af83 1627 reset_enable_flags(dqopt, cnt, remount);
1da177e4
LT
1628
1629 /* Note: these are blocking operations */
1630 drop_dquot_ref(sb, cnt);
1631 invalidate_dquots(sb, cnt);
1632 /*
1633 * Now all dquots should be invalidated, all writes done so we should be only
1634 * users of the info. No locks needed.
1635 */
1636 if (info_dirty(&dqopt->info[cnt]))
1637 sb->dq_op->write_info(sb, cnt);
1638 if (dqopt->ops[cnt]->free_file_info)
1639 dqopt->ops[cnt]->free_file_info(sb, cnt);
1640 put_quota_format(dqopt->info[cnt].dqi_format);
1641
1642 toputinode[cnt] = dqopt->files[cnt];
0ff5af83
JK
1643 if (!remount)
1644 dqopt->files[cnt] = NULL;
1da177e4
LT
1645 dqopt->info[cnt].dqi_flags = 0;
1646 dqopt->info[cnt].dqi_igrace = 0;
1647 dqopt->info[cnt].dqi_bgrace = 0;
1648 dqopt->ops[cnt] = NULL;
1649 }
d3be915f 1650 mutex_unlock(&dqopt->dqonoff_mutex);
1da177e4 1651 /* Sync the superblock so that buffers with quota data are written to
7b7b1ace 1652 * disk (and so userspace sees correct data afterwards). */
1da177e4
LT
1653 if (sb->s_op->sync_fs)
1654 sb->s_op->sync_fs(sb, 1);
1655 sync_blockdev(sb->s_bdev);
1656 /* Now the quota files are just ordinary files and we can set the
1657 * inode flags back. Moreover we discard the pagecache so that
1658 * userspace sees the writes we did bypassing the pagecache. We
1659 * must also discard the blockdev buffers so that we see the
1660 * changes done by userspace on the next quotaon() */
1661 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1662 if (toputinode[cnt]) {
d3be915f 1663 mutex_lock(&dqopt->dqonoff_mutex);
1da177e4
LT
1664 /* If quota was reenabled in the meantime, we have
1665 * nothing to do */
1666 if (!sb_has_quota_enabled(sb, cnt)) {
7925409e 1667 mutex_lock_nested(&toputinode[cnt]->i_mutex, I_MUTEX_QUOTA);
1da177e4
LT
1668 toputinode[cnt]->i_flags &= ~(S_IMMUTABLE |
1669 S_NOATIME | S_NOQUOTA);
1670 truncate_inode_pages(&toputinode[cnt]->i_data, 0);
1b1dcc1b 1671 mutex_unlock(&toputinode[cnt]->i_mutex);
1da177e4 1672 mark_inode_dirty(toputinode[cnt]);
1da177e4 1673 }
d3be915f 1674 mutex_unlock(&dqopt->dqonoff_mutex);
0ff5af83
JK
1675 /* On remount RO, we keep the inode pointer so that we
1676 * can reenable quota on the subsequent remount RW.
1677 * But we have better not keep inode pointer when there
1678 * is pending delete on the quota file... */
1679 if (!remount)
1680 iput(toputinode[cnt]);
1681 else if (!toputinode[cnt]->i_nlink)
1682 ret = -EBUSY;
1da177e4
LT
1683 }
1684 if (sb->s_bdev)
f98393a6 1685 invalidate_bdev(sb->s_bdev);
0ff5af83 1686 return ret;
1da177e4
LT
1687}
1688
1689/*
1690 * Turn quotas on on a device
1691 */
1692
1693/* Helper function when we already have the inode */
1694static int vfs_quota_on_inode(struct inode *inode, int type, int format_id)
1695{
1696 struct quota_format_type *fmt = find_quota_format(format_id);
1697 struct super_block *sb = inode->i_sb;
1698 struct quota_info *dqopt = sb_dqopt(sb);
1699 int error;
1700 int oldflags = -1;
1701
1702 if (!fmt)
1703 return -ESRCH;
1704 if (!S_ISREG(inode->i_mode)) {
1705 error = -EACCES;
1706 goto out_fmt;
1707 }
1708 if (IS_RDONLY(inode)) {
1709 error = -EROFS;
1710 goto out_fmt;
1711 }
1712 if (!sb->s_op->quota_write || !sb->s_op->quota_read) {
1713 error = -EINVAL;
1714 goto out_fmt;
1715 }
1716
1717 /* As we bypass the pagecache we must now flush the inode so that
1718 * we see all the changes from userspace... */
1719 write_inode_now(inode, 1);
1720 /* And now flush the block cache so that kernel sees the changes */
f98393a6 1721 invalidate_bdev(sb->s_bdev);
1b1dcc1b 1722 mutex_lock(&inode->i_mutex);
d3be915f 1723 mutex_lock(&dqopt->dqonoff_mutex);
0ff5af83
JK
1724 if (sb_has_quota_enabled(sb, type) ||
1725 sb_has_quota_suspended(sb, type)) {
1da177e4
LT
1726 error = -EBUSY;
1727 goto out_lock;
1728 }
1729 /* We don't want quota and atime on quota files (deadlocks possible)
1730 * Also nobody should write to the file - we use special IO operations
1731 * which ignore the immutable bit. */
1732 down_write(&dqopt->dqptr_sem);
1733 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | S_NOQUOTA);
1734 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
1735 up_write(&dqopt->dqptr_sem);
31e7ad6a 1736 sb->dq_op->drop(inode);
1da177e4
LT
1737
1738 error = -EIO;
1739 dqopt->files[type] = igrab(inode);
1740 if (!dqopt->files[type])
1741 goto out_lock;
1742 error = -EINVAL;
1743 if (!fmt->qf_ops->check_quota_file(sb, type))
1744 goto out_file_init;
1745
1746 dqopt->ops[type] = fmt->qf_ops;
1747 dqopt->info[type].dqi_format = fmt;
0ff5af83 1748 dqopt->info[type].dqi_fmt_id = format_id;
1da177e4 1749 INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list);
d3be915f 1750 mutex_lock(&dqopt->dqio_mutex);
1da177e4 1751 if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) {
d3be915f 1752 mutex_unlock(&dqopt->dqio_mutex);
1da177e4
LT
1753 goto out_file_init;
1754 }
d3be915f 1755 mutex_unlock(&dqopt->dqio_mutex);
1b1dcc1b 1756 mutex_unlock(&inode->i_mutex);
1da177e4
LT
1757 set_enable_flags(dqopt, type);
1758
1759 add_dquot_ref(sb, type);
d3be915f 1760 mutex_unlock(&dqopt->dqonoff_mutex);
1da177e4
LT
1761
1762 return 0;
1763
1764out_file_init:
1765 dqopt->files[type] = NULL;
1766 iput(inode);
1767out_lock:
d3be915f 1768 mutex_unlock(&dqopt->dqonoff_mutex);
1da177e4
LT
1769 if (oldflags != -1) {
1770 down_write(&dqopt->dqptr_sem);
1771 /* Set the flags back (in the case of accidental quotaon()
1772 * on a wrong file we don't want to mess up the flags) */
1773 inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE);
1774 inode->i_flags |= oldflags;
1775 up_write(&dqopt->dqptr_sem);
1776 }
1b1dcc1b 1777 mutex_unlock(&inode->i_mutex);
1da177e4
LT
1778out_fmt:
1779 put_quota_format(fmt);
1780
1781 return error;
1782}
1783
0ff5af83
JK
1784/* Reenable quotas on remount RW */
1785static int vfs_quota_on_remount(struct super_block *sb, int type)
1786{
1787 struct quota_info *dqopt = sb_dqopt(sb);
1788 struct inode *inode;
1789 int ret;
1790
1791 mutex_lock(&dqopt->dqonoff_mutex);
1792 if (!sb_has_quota_suspended(sb, type)) {
1793 mutex_unlock(&dqopt->dqonoff_mutex);
1794 return 0;
1795 }
1796 BUG_ON(sb_has_quota_enabled(sb, type));
1797
1798 inode = dqopt->files[type];
1799 dqopt->files[type] = NULL;
1800 reset_enable_flags(dqopt, type, 0);
1801 mutex_unlock(&dqopt->dqonoff_mutex);
1802
1803 ret = vfs_quota_on_inode(inode, type, dqopt->info[type].dqi_fmt_id);
1804 iput(inode);
1805
1806 return ret;
1807}
1808
77e69dac
AV
1809int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
1810 struct path *path)
1811{
1812 int error = security_quota_on(path->dentry);
1813 if (error)
1814 return error;
1815 /* Quota file not on the same filesystem? */
1816 if (path->mnt->mnt_sb != sb)
1817 error = -EXDEV;
1818 else
1819 error = vfs_quota_on_inode(path->dentry->d_inode, type,
1820 format_id);
1821 return error;
1822}
1823
1da177e4 1824/* Actual function called from quotactl() */
8264613d 1825int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name,
0ff5af83 1826 int remount)
1da177e4 1827{
8264613d 1828 struct path path;
1da177e4
LT
1829 int error;
1830
0ff5af83
JK
1831 if (remount)
1832 return vfs_quota_on_remount(sb, type);
1833
8264613d 1834 error = kern_path(name, LOOKUP_FOLLOW, &path);
77e69dac 1835 if (!error) {
8264613d
AV
1836 error = vfs_quota_on_path(sb, type, format_id, &path);
1837 path_put(&path);
77e69dac 1838 }
1da177e4
LT
1839 return error;
1840}
1841
1842/*
1843 * This function is used when filesystem needs to initialize quotas
1844 * during mount time.
1845 */
84de856e
CH
1846int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
1847 int format_id, int type)
1da177e4 1848{
84de856e 1849 struct dentry *dentry;
1da177e4
LT
1850 int error;
1851
2fa389c5 1852 dentry = lookup_one_len(qf_name, sb->s_root, strlen(qf_name));
84de856e
CH
1853 if (IS_ERR(dentry))
1854 return PTR_ERR(dentry);
1855
154f484b
JK
1856 if (!dentry->d_inode) {
1857 error = -ENOENT;
1858 goto out;
1859 }
1860
1da177e4 1861 error = security_quota_on(dentry);
84de856e
CH
1862 if (!error)
1863 error = vfs_quota_on_inode(dentry->d_inode, type, format_id);
1864
154f484b 1865out:
84de856e
CH
1866 dput(dentry);
1867 return error;
1da177e4
LT
1868}
1869
b85f4b87
JK
1870/* Wrapper to turn on quotas when remounting rw */
1871int vfs_dq_quota_on_remount(struct super_block *sb)
1872{
1873 int cnt;
1874 int ret = 0, err;
1875
1876 if (!sb->s_qcop || !sb->s_qcop->quota_on)
1877 return -ENOSYS;
1878 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1879 err = sb->s_qcop->quota_on(sb, cnt, 0, NULL, 1);
1880 if (err < 0 && !ret)
1881 ret = err;
1882 }
1883 return ret;
1884}
1885
12095460
JK
1886static inline qsize_t qbtos(qsize_t blocks)
1887{
1888 return blocks << QIF_DQBLKSIZE_BITS;
1889}
1890
1891static inline qsize_t stoqb(qsize_t space)
1892{
1893 return (space + QIF_DQBLKSIZE - 1) >> QIF_DQBLKSIZE_BITS;
1894}
1895
1da177e4
LT
1896/* Generic routine for getting common part of quota structure */
1897static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di)
1898{
1899 struct mem_dqblk *dm = &dquot->dq_dqb;
1900
1901 spin_lock(&dq_data_lock);
12095460
JK
1902 di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit);
1903 di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit);
1da177e4
LT
1904 di->dqb_curspace = dm->dqb_curspace;
1905 di->dqb_ihardlimit = dm->dqb_ihardlimit;
1906 di->dqb_isoftlimit = dm->dqb_isoftlimit;
1907 di->dqb_curinodes = dm->dqb_curinodes;
1908 di->dqb_btime = dm->dqb_btime;
1909 di->dqb_itime = dm->dqb_itime;
1910 di->dqb_valid = QIF_ALL;
1911 spin_unlock(&dq_data_lock);
1912}
1913
1914int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
1915{
1916 struct dquot *dquot;
1917
d3be915f 1918 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4 1919 if (!(dquot = dqget(sb, id, type))) {
d3be915f 1920 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
1921 return -ESRCH;
1922 }
1923 do_get_dqblk(dquot, di);
1924 dqput(dquot);
d3be915f 1925 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
1926 return 0;
1927}
1928
1929/* Generic routine for setting common part of quota structure */
338bf9af 1930static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
1da177e4
LT
1931{
1932 struct mem_dqblk *dm = &dquot->dq_dqb;
1933 int check_blim = 0, check_ilim = 0;
338bf9af
AP
1934 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
1935
1936 if ((di->dqb_valid & QIF_BLIMITS &&
1937 (di->dqb_bhardlimit > dqi->dqi_maxblimit ||
1938 di->dqb_bsoftlimit > dqi->dqi_maxblimit)) ||
1939 (di->dqb_valid & QIF_ILIMITS &&
1940 (di->dqb_ihardlimit > dqi->dqi_maxilimit ||
1941 di->dqb_isoftlimit > dqi->dqi_maxilimit)))
1942 return -ERANGE;
1da177e4
LT
1943
1944 spin_lock(&dq_data_lock);
1945 if (di->dqb_valid & QIF_SPACE) {
1946 dm->dqb_curspace = di->dqb_curspace;
1947 check_blim = 1;
1948 }
1949 if (di->dqb_valid & QIF_BLIMITS) {
12095460
JK
1950 dm->dqb_bsoftlimit = qbtos(di->dqb_bsoftlimit);
1951 dm->dqb_bhardlimit = qbtos(di->dqb_bhardlimit);
1da177e4
LT
1952 check_blim = 1;
1953 }
1954 if (di->dqb_valid & QIF_INODES) {
1955 dm->dqb_curinodes = di->dqb_curinodes;
1956 check_ilim = 1;
1957 }
1958 if (di->dqb_valid & QIF_ILIMITS) {
1959 dm->dqb_isoftlimit = di->dqb_isoftlimit;
1960 dm->dqb_ihardlimit = di->dqb_ihardlimit;
1961 check_ilim = 1;
1962 }
1963 if (di->dqb_valid & QIF_BTIME)
1964 dm->dqb_btime = di->dqb_btime;
1965 if (di->dqb_valid & QIF_ITIME)
1966 dm->dqb_itime = di->dqb_itime;
1967
1968 if (check_blim) {
12095460 1969 if (!dm->dqb_bsoftlimit || dm->dqb_curspace < dm->dqb_bsoftlimit) {
1da177e4
LT
1970 dm->dqb_btime = 0;
1971 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
1972 }
1973 else if (!(di->dqb_valid & QIF_BTIME)) /* Set grace only if user hasn't provided his own... */
338bf9af 1974 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace;
1da177e4
LT
1975 }
1976 if (check_ilim) {
1977 if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) {
1978 dm->dqb_itime = 0;
1979 clear_bit(DQ_INODES_B, &dquot->dq_flags);
1980 }
1981 else if (!(di->dqb_valid & QIF_ITIME)) /* Set grace only if user hasn't provided his own... */
338bf9af 1982 dm->dqb_itime = get_seconds() + dqi->dqi_igrace;
1da177e4
LT
1983 }
1984 if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit)
1985 clear_bit(DQ_FAKE_B, &dquot->dq_flags);
1986 else
1987 set_bit(DQ_FAKE_B, &dquot->dq_flags);
1988 spin_unlock(&dq_data_lock);
1989 mark_dquot_dirty(dquot);
338bf9af
AP
1990
1991 return 0;
1da177e4
LT
1992}
1993
1994int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
1995{
1996 struct dquot *dquot;
338bf9af 1997 int rc;
1da177e4 1998
d3be915f 1999 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4 2000 if (!(dquot = dqget(sb, id, type))) {
d3be915f 2001 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
2002 return -ESRCH;
2003 }
338bf9af 2004 rc = do_set_dqblk(dquot, di);
1da177e4 2005 dqput(dquot);
d3be915f 2006 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
338bf9af 2007 return rc;
1da177e4
LT
2008}
2009
2010/* Generic routine for getting common part of quota file information */
2011int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
2012{
2013 struct mem_dqinfo *mi;
2014
d3be915f 2015 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4 2016 if (!sb_has_quota_enabled(sb, type)) {
d3be915f 2017 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
2018 return -ESRCH;
2019 }
2020 mi = sb_dqopt(sb)->info + type;
2021 spin_lock(&dq_data_lock);
2022 ii->dqi_bgrace = mi->dqi_bgrace;
2023 ii->dqi_igrace = mi->dqi_igrace;
2024 ii->dqi_flags = mi->dqi_flags & DQF_MASK;
2025 ii->dqi_valid = IIF_ALL;
2026 spin_unlock(&dq_data_lock);
d3be915f 2027 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
2028 return 0;
2029}
2030
2031/* Generic routine for setting common part of quota file information */
2032int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
2033{
2034 struct mem_dqinfo *mi;
2035
d3be915f 2036 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4 2037 if (!sb_has_quota_enabled(sb, type)) {
d3be915f 2038 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
2039 return -ESRCH;
2040 }
2041 mi = sb_dqopt(sb)->info + type;
2042 spin_lock(&dq_data_lock);
2043 if (ii->dqi_valid & IIF_BGRACE)
2044 mi->dqi_bgrace = ii->dqi_bgrace;
2045 if (ii->dqi_valid & IIF_IGRACE)
2046 mi->dqi_igrace = ii->dqi_igrace;
2047 if (ii->dqi_valid & IIF_FLAGS)
2048 mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK);
2049 spin_unlock(&dq_data_lock);
2050 mark_info_dirty(sb, type);
2051 /* Force write to disk */
2052 sb->dq_op->write_info(sb, type);
d3be915f 2053 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
1da177e4
LT
2054 return 0;
2055}
2056
2057struct quotactl_ops vfs_quotactl_ops = {
2058 .quota_on = vfs_quota_on,
2059 .quota_off = vfs_quota_off,
2060 .quota_sync = vfs_quota_sync,
2061 .get_info = vfs_get_dqinfo,
2062 .set_info = vfs_set_dqinfo,
2063 .get_dqblk = vfs_get_dqblk,
2064 .set_dqblk = vfs_set_dqblk
2065};
2066
2067static ctl_table fs_dqstats_table[] = {
2068 {
2069 .ctl_name = FS_DQ_LOOKUPS,
2070 .procname = "lookups",
2071 .data = &dqstats.lookups,
2072 .maxlen = sizeof(int),
2073 .mode = 0444,
2074 .proc_handler = &proc_dointvec,
2075 },
2076 {
2077 .ctl_name = FS_DQ_DROPS,
2078 .procname = "drops",
2079 .data = &dqstats.drops,
2080 .maxlen = sizeof(int),
2081 .mode = 0444,
2082 .proc_handler = &proc_dointvec,
2083 },
2084 {
2085 .ctl_name = FS_DQ_READS,
2086 .procname = "reads",
2087 .data = &dqstats.reads,
2088 .maxlen = sizeof(int),
2089 .mode = 0444,
2090 .proc_handler = &proc_dointvec,
2091 },
2092 {
2093 .ctl_name = FS_DQ_WRITES,
2094 .procname = "writes",
2095 .data = &dqstats.writes,
2096 .maxlen = sizeof(int),
2097 .mode = 0444,
2098 .proc_handler = &proc_dointvec,
2099 },
2100 {
2101 .ctl_name = FS_DQ_CACHE_HITS,
2102 .procname = "cache_hits",
2103 .data = &dqstats.cache_hits,
2104 .maxlen = sizeof(int),
2105 .mode = 0444,
2106 .proc_handler = &proc_dointvec,
2107 },
2108 {
2109 .ctl_name = FS_DQ_ALLOCATED,
2110 .procname = "allocated_dquots",
2111 .data = &dqstats.allocated_dquots,
2112 .maxlen = sizeof(int),
2113 .mode = 0444,
2114 .proc_handler = &proc_dointvec,
2115 },
2116 {
2117 .ctl_name = FS_DQ_FREE,
2118 .procname = "free_dquots",
2119 .data = &dqstats.free_dquots,
2120 .maxlen = sizeof(int),
2121 .mode = 0444,
2122 .proc_handler = &proc_dointvec,
2123 },
2124 {
2125 .ctl_name = FS_DQ_SYNCS,
2126 .procname = "syncs",
2127 .data = &dqstats.syncs,
2128 .maxlen = sizeof(int),
2129 .mode = 0444,
2130 .proc_handler = &proc_dointvec,
2131 },
8e893469 2132#ifdef CONFIG_PRINT_QUOTA_WARNING
1da177e4
LT
2133 {
2134 .ctl_name = FS_DQ_WARNINGS,
2135 .procname = "warnings",
2136 .data = &flag_print_warnings,
2137 .maxlen = sizeof(int),
2138 .mode = 0644,
2139 .proc_handler = &proc_dointvec,
2140 },
8e893469 2141#endif
1da177e4
LT
2142 { .ctl_name = 0 },
2143};
2144
2145static ctl_table fs_table[] = {
2146 {
2147 .ctl_name = FS_DQSTATS,
2148 .procname = "quota",
2149 .mode = 0555,
2150 .child = fs_dqstats_table,
2151 },
2152 { .ctl_name = 0 },
2153};
2154
2155static ctl_table sys_table[] = {
2156 {
2157 .ctl_name = CTL_FS,
2158 .procname = "fs",
2159 .mode = 0555,
2160 .child = fs_table,
2161 },
2162 { .ctl_name = 0 },
2163};
2164
2165static int __init dquot_init(void)
2166{
2167 int i;
2168 unsigned long nr_hash, order;
2169
2170 printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__);
2171
0b4d4147 2172 register_sysctl_table(sys_table);
1da177e4 2173
20c2df83 2174 dquot_cachep = kmem_cache_create("dquot",
1da177e4 2175 sizeof(struct dquot), sizeof(unsigned long) * 4,
fffb60f9
PJ
2176 (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
2177 SLAB_MEM_SPREAD|SLAB_PANIC),
20c2df83 2178 NULL);
1da177e4
LT
2179
2180 order = 0;
2181 dquot_hash = (struct hlist_head *)__get_free_pages(GFP_ATOMIC, order);
2182 if (!dquot_hash)
2183 panic("Cannot create dquot hash table");
2184
2185 /* Find power-of-two hlist_heads which can fit into allocation */
2186 nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
2187 dq_hash_bits = 0;
2188 do {
2189 dq_hash_bits++;
2190 } while (nr_hash >> dq_hash_bits);
2191 dq_hash_bits--;
2192
2193 nr_hash = 1UL << dq_hash_bits;
2194 dq_hash_mask = nr_hash - 1;
2195 for (i = 0; i < nr_hash; i++)
2196 INIT_HLIST_HEAD(dquot_hash + i);
2197
2198 printk("Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n",
2199 nr_hash, order, (PAGE_SIZE << order));
2200
8e1f936b 2201 register_shrinker(&dqcache_shrinker);
1da177e4 2202
8e893469
JK
2203#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
2204 if (genl_register_family(&quota_genl_family) != 0)
2205 printk(KERN_ERR "VFS: Failed to create quota netlink interface.\n");
2206#endif
2207
1da177e4
LT
2208 return 0;
2209}
2210module_init(dquot_init);
2211
2212EXPORT_SYMBOL(register_quota_format);
2213EXPORT_SYMBOL(unregister_quota_format);
2214EXPORT_SYMBOL(dqstats);
2215EXPORT_SYMBOL(dq_data_lock);
2216EXPORT_SYMBOL(vfs_quota_on);
77e69dac 2217EXPORT_SYMBOL(vfs_quota_on_path);
1da177e4
LT
2218EXPORT_SYMBOL(vfs_quota_on_mount);
2219EXPORT_SYMBOL(vfs_quota_off);
2220EXPORT_SYMBOL(vfs_quota_sync);
2221EXPORT_SYMBOL(vfs_get_dqinfo);
2222EXPORT_SYMBOL(vfs_set_dqinfo);
2223EXPORT_SYMBOL(vfs_get_dqblk);
2224EXPORT_SYMBOL(vfs_set_dqblk);
2225EXPORT_SYMBOL(dquot_commit);
2226EXPORT_SYMBOL(dquot_commit_info);
2227EXPORT_SYMBOL(dquot_acquire);
2228EXPORT_SYMBOL(dquot_release);
2229EXPORT_SYMBOL(dquot_mark_dquot_dirty);
2230EXPORT_SYMBOL(dquot_initialize);
2231EXPORT_SYMBOL(dquot_drop);
b85f4b87 2232EXPORT_SYMBOL(vfs_dq_drop);
1da177e4
LT
2233EXPORT_SYMBOL(dquot_alloc_space);
2234EXPORT_SYMBOL(dquot_alloc_inode);
2235EXPORT_SYMBOL(dquot_free_space);
2236EXPORT_SYMBOL(dquot_free_inode);
2237EXPORT_SYMBOL(dquot_transfer);
b85f4b87
JK
2238EXPORT_SYMBOL(vfs_dq_transfer);
2239EXPORT_SYMBOL(vfs_dq_quota_on_remount);