• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/src/linux/linux-2.6/fs/

Lines Matching refs:dquot

12  * Version: $Id: dquot.c,v 1.1.1.1 2007/08/03 18:53:05 Exp $
39 * Write updated not to require dquot lock
91 * and also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
98 * the life of the dquot structure and so needn't to be protected by a lock
105 * reference to dquot in other way (e.g. quotactl ops) it must be guarded by
108 * a) update/access to dquot pointers in inode is serialized
111 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
113 * Currently dquot is locked only when it is being read to memory (or space for
121 * i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock >
133 /* SLAB cache for dquot structures */
187 * The quota code uses three lists for dquot management: the inuse_list,
188 * free_dquots, and dquot_hash[] array. A single dquot structure may be
192 * list is used for invalidate operation, which must look at every dquot.
195 * and this list is searched whenever we need an available dquot. Dquots are
198 * dquot is invalidated it's completely released from memory.
202 * mechanism to locate a specific dquot.
212 static void dqput(struct dquot *dquot);
226 static inline void insert_dquot_hash(struct dquot *dquot)
228 struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
229 hlist_add_head(&dquot->dq_hash, head);
232 static inline void remove_dquot_hash(struct dquot *dquot)
234 hlist_del_init(&dquot->dq_hash);
237 static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type)
240 struct dquot *dquot;
243 dquot = hlist_entry(node, struct dquot, dq_hash);
244 if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type)
245 return dquot;
250 /* Add a dquot to the tail of the free list */
251 static inline void put_dquot_last(struct dquot *dquot)
253 list_add_tail(&dquot->dq_free, &free_dquots);
257 static inline void remove_free_dquot(struct dquot *dquot)
259 if (list_empty(&dquot->dq_free))
261 list_del_init(&dquot->dq_free);
265 static inline void put_inuse(struct dquot *dquot)
269 list_add_tail(&dquot->dq_inuse, &inuse_list);
273 static inline void remove_inuse(struct dquot *dquot)
276 list_del(&dquot->dq_inuse);
282 static void wait_on_dquot(struct dquot *dquot)
284 mutex_lock(&dquot->dq_lock);
285 mutex_unlock(&dquot->dq_lock);
288 #define mark_dquot_dirty(dquot) ((dquot)->dq_sb->dq_op->mark_dirty(dquot))
290 int dquot_mark_dquot_dirty(struct dquot *dquot)
293 if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags))
294 list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)->
295 info[dquot->dq_type].dqi_dirty_list);
301 static inline int clear_dquot_dirty(struct dquot *dquot)
303 if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags))
305 list_del_init(&dquot->dq_dirty);
316 * Read dquot from disk and alloc space for it
319 int dquot_acquire(struct dquot *dquot)
322 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
324 mutex_lock(&dquot->dq_lock);
326 if (!test_bit(DQ_READ_B, &dquot->dq_flags))
327 ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot);
330 set_bit(DQ_READ_B, &dquot->dq_flags);
331 /* Instantiate dquot if needed */
332 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) {
333 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
335 if (info_dirty(&dqopt->info[dquot->dq_type]))
336 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
344 set_bit(DQ_ACTIVE_B, &dquot->dq_flags);
347 mutex_unlock(&dquot->dq_lock);
352 * Write dquot to disk
354 int dquot_commit(struct dquot *dquot)
357 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
361 if (!clear_dquot_dirty(dquot)) {
366 /* Inactive dquot can be only if there was error during read/init
368 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
369 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
370 if (info_dirty(&dqopt->info[dquot->dq_type]))
371 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
381 * Release dquot
383 int dquot_release(struct dquot *dquot)
386 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
388 mutex_lock(&dquot->dq_lock);
390 if (atomic_read(&dquot->dq_count) > 1)
393 if (dqopt->ops[dquot->dq_type]->release_dqblk) {
394 ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot);
396 if (info_dirty(&dqopt->info[dquot->dq_type]))
397 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type);
401 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
404 mutex_unlock(&dquot->dq_lock);
416 struct dquot *dquot, *tmp;
420 list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) {
421 if (dquot->dq_sb != sb)
423 if (dquot->dq_type != type)
425 /* Wait for dquot users */
426 if (atomic_read(&dquot->dq_count)) {
429 atomic_inc(&dquot->dq_count);
430 prepare_to_wait(&dquot->dq_wait_unused, &wait,
434 * the dquot.
436 * at most one process waiting for dquot to free.
440 if (atomic_read(&dquot->dq_count) > 1)
442 finish_wait(&dquot->dq_wait_unused, &wait);
443 dqput(dquot);
444 /* At this moment dquot() need not exist (it could be
453 remove_dquot_hash(dquot);
454 remove_free_dquot(dquot);
455 remove_inuse(dquot);
456 kmem_cache_free(dquot_cachep, dquot);
464 struct dquot *dquot;
477 dquot = list_first_entry(dirty, struct dquot, dq_dirty);
478 /* Dirty and inactive can be only bad dquot... */
479 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
480 clear_dquot_dirty(dquot);
483 /* Now we have active dquot from which someone is
486 atomic_inc(&dquot->dq_count);
489 sb->dq_op->write_dquot(dquot);
490 dqput(dquot);
512 struct dquot *dquot;
516 dquot = list_entry(head, struct dquot, dq_free);
517 remove_dquot_hash(dquot);
518 remove_free_dquot(dquot);
519 remove_inuse(dquot);
520 kmem_cache_free(dquot_cachep, dquot);
542 * Put reference to dquot
546 static void dqput(struct dquot *dquot)
548 if (!dquot)
551 if (!atomic_read(&dquot->dq_count)) {
552 printk("VFS: dqput: trying to free free dquot\n");
553 printk("VFS: device %s, dquot of %s %d\n",
554 dquot->dq_sb->s_id,
555 quotatypes[dquot->dq_type],
556 dquot->dq_id);
566 if (atomic_read(&dquot->dq_count) > 1) {
568 atomic_dec(&dquot->dq_count);
569 /* Releasing dquot during quotaoff phase? */
570 if (!sb_has_quota_enabled(dquot->dq_sb, dquot->dq_type) &&
571 atomic_read(&dquot->dq_count) == 1)
572 wake_up(&dquot->dq_wait_unused);
576 /* Need to release dquot? */
577 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) {
579 /* Commit dquot before releasing */
580 dquot->dq_sb->dq_op->write_dquot(dquot);
583 /* Clear flag in case dquot was inactive (something bad happened) */
584 clear_dquot_dirty(dquot);
585 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
587 dquot->dq_sb->dq_op->release_dquot(dquot);
590 atomic_dec(&dquot->dq_count);
593 BUG_ON(!list_empty(&dquot->dq_free));
595 put_dquot_last(dquot);
599 static struct dquot *get_empty_dquot(struct super_block *sb, int type)
601 struct dquot *dquot;
603 dquot = kmem_cache_zalloc(dquot_cachep, GFP_NOFS);
604 if(!dquot)
607 mutex_init(&dquot->dq_lock);
608 INIT_LIST_HEAD(&dquot->dq_free);
609 INIT_LIST_HEAD(&dquot->dq_inuse);
610 INIT_HLIST_NODE(&dquot->dq_hash);
611 INIT_LIST_HEAD(&dquot->dq_dirty);
612 init_waitqueue_head(&dquot->dq_wait_unused);
613 dquot->dq_sb = sb;
614 dquot->dq_type = type;
615 atomic_set(&dquot->dq_count, 1);
617 return dquot;
621 * Get reference to dquot
624 static struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
627 struct dquot *dquot, *empty = NODQUOT;
633 if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) {
640 dquot = empty;
641 dquot->dq_id = id;
643 put_inuse(dquot);
645 insert_dquot_hash(dquot);
649 if (!atomic_read(&dquot->dq_count))
650 remove_free_dquot(dquot);
651 atomic_inc(&dquot->dq_count);
660 wait_on_dquot(dquot);
661 /* Read the dquot and instantiate it (everything done only if needed) */
662 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) {
663 dqput(dquot);
667 BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */
670 return dquot;
714 static inline int dqput_blocks(struct dquot *dquot)
716 if (atomic_read(&dquot->dq_count) <= 1)
721 /* Remove references to dquots from inode - add dquot to list for freeing if needed */
726 struct dquot *dquot = inode->i_dquot[type];
729 if (dquot != NODQUOT) {
730 if (dqput_blocks(dquot)) {
732 if (atomic_read(&dquot->dq_count) != 1)
733 printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count));
736 list_add(&dquot->dq_free, tofree_head); /* As dquot must have currently users it can't be on the free list... */
741 dqput(dquot); /* We have guaranteed we won't block */
751 struct dquot *dquot;
756 dquot = list_entry(act_head, struct dquot, dq_free);
758 list_del_init(&dquot->dq_free); /* Remove dquot from the list so we won't have problems... */
759 dqput(dquot);
789 static inline void dquot_incr_inodes(struct dquot *dquot, unsigned long number)
791 dquot->dq_dqb.dqb_curinodes += number;
794 static inline void dquot_incr_space(struct dquot *dquot, qsize_t number)
796 dquot->dq_dqb.dqb_curspace += number;
799 static inline void dquot_decr_inodes(struct dquot *dquot, unsigned long number)
801 if (dquot->dq_dqb.dqb_curinodes > number)
802 dquot->dq_dqb.dqb_curinodes -= number;
804 dquot->dq_dqb.dqb_curinodes = 0;
805 if (dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit)
806 dquot->dq_dqb.dqb_itime = (time_t) 0;
807 clear_bit(DQ_INODES_B, &dquot->dq_flags);
810 static inline void dquot_decr_space(struct dquot *dquot, qsize_t number)
812 if (dquot->dq_dqb.dqb_curspace > number)
813 dquot->dq_dqb.dqb_curspace -= number;
815 dquot->dq_dqb.dqb_curspace = 0;
816 if (toqb(dquot->dq_dqb.dqb_curspace) <= dquot->dq_dqb.dqb_bsoftlimit)
817 dquot->dq_dqb.dqb_btime = (time_t) 0;
818 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
823 static inline int need_print_warning(struct dquot *dquot)
828 switch (dquot->dq_type) {
830 return current->fsuid == dquot->dq_id;
832 return in_group_p(dquot->dq_id);
847 static void print_warning(struct dquot *dquot, const char warntype)
854 if (!need_print_warning(dquot) || (flag && test_and_set_bit(flag, &dquot->dq_flags)))
861 tty_write_message(tty, dquot->dq_sb->s_id);
866 tty_write_message(tty, quotatypes[dquot->dq_type]);
892 static inline void flush_warnings(struct dquot **dquots, char *warntype)
901 static inline char ignore_hardlimit(struct dquot *dquot)
903 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
910 static int check_idq(struct dquot *dquot, ulong inodes, char *warntype)
913 if (inodes <= 0 || test_bit(DQ_FAKE_B, &dquot->dq_flags))
916 if (dquot->dq_dqb.dqb_ihardlimit &&
917 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit &&
918 !ignore_hardlimit(dquot)) {
923 if (dquot->dq_dqb.dqb_isoftlimit &&
924 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
925 dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime &&
926 !ignore_hardlimit(dquot)) {
931 if (dquot->dq_dqb.dqb_isoftlimit &&
932 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
933 dquot->dq_dqb.dqb_itime == 0) {
935 dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
942 static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
945 if (space <= 0 || test_bit(DQ_FAKE_B, &dquot->dq_flags))
948 if (dquot->dq_dqb.dqb_bhardlimit &&
949 toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bhardlimit &&
950 !ignore_hardlimit(dquot)) {
956 if (dquot->dq_dqb.dqb_bsoftlimit &&
957 toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bsoftlimit &&
958 dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime &&
959 !ignore_hardlimit(dquot)) {
965 if (dquot->dq_dqb.dqb_bsoftlimit &&
966 toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bsoftlimit &&
967 dquot->dq_dqb.dqb_btime == 0) {
970 dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
1044 * holds a handle for the current transaction so that dquot write and
1137 flush_warnings((struct dquot **)inode->i_dquot, warntype);
1219 struct dquot *transfer_from[MAXQUOTAS];
1220 struct dquot *transfer_to[MAXQUOTAS];
1583 static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di)
1585 struct mem_dqblk *dm = &dquot->dq_dqb;
1602 struct dquot *dquot;
1605 if (!(dquot = dqget(sb, id, type))) {
1609 do_get_dqblk(dquot, di);
1610 dqput(dquot);
1616 static void do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
1618 struct mem_dqblk *dm = &dquot->dq_dqb;
1648 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
1651 dm->dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
1656 clear_bit(DQ_INODES_B, &dquot->dq_flags);
1659 dm->dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1662 clear_bit(DQ_FAKE_B, &dquot->dq_flags);
1664 set_bit(DQ_FAKE_B, &dquot->dq_flags);
1666 mark_dquot_dirty(dquot);
1671 struct dquot *dquot;
1674 if (!(dquot = dqget(sb, id, type))) {
1678 do_set_dqblk(dquot, di);
1679 dqput(dquot);
1846 dquot_cachep = kmem_cache_create("dquot",
1847 sizeof(struct dquot), sizeof(unsigned long) * 4,
1855 panic("Cannot create dquot hash table");