4 * (C) 1997 Linus Torvalds
7 #include <linux/config.h>
9 #include <linux/string.h>
11 #include <linux/dcache.h>
12 #include <linux/init.h>
13 #include <linux/quotaops.h>
14 #include <linux/slab.h>
15 #include <linux/cache.h>
18 * New inode.c implementation.
20 * This implementation has the basic premise of trying
21 * to be extremely low-overhead and SMP-safe, yet be
22 * simple enough to be "obviously correct".
27 /* inode dynamic allocation 1999, Andrea Arcangeli <andrea@suse.de> */
29 /* #define INODE_PARANOIA 1 */
30 /* #define INODE_DEBUG 1 */
33 * Inode lookup is no longer as critical as it used to be:
34 * most of the lookups are going to be through the dcache.
36 #define I_HASHBITS i_hash_shift
37 #define I_HASHMASK i_hash_mask
39 static unsigned int i_hash_mask
;
40 static unsigned int i_hash_shift
;
43 * Each inode can be on two separate lists. One is
44 * the hash list of the inode, used for lookups. The
45 * other linked list is the "type" list:
46 * "in_use" - valid inode, i_count > 0, i_nlink > 0
47 * "dirty" - as "in_use" but also dirty
48 * "unused" - valid inode, i_count = 0
50 * A "dirty" list is maintained for each super block,
51 * allowing for low-overhead inode sync() operations.
54 static LIST_HEAD(inode_in_use
);
55 static LIST_HEAD(inode_unused
);
56 static struct list_head
*inode_hashtable
;
57 static LIST_HEAD(anon_hash_chain
); /* for inodes with NULL i_sb */
60 * A simple spinlock to protect the list manipulations.
62 * NOTE! You also have to own the lock if you change
63 * the i_state of an inode while it is in use..
65 spinlock_t inode_lock
= SPIN_LOCK_UNLOCKED
;
68 * Statistics gathering..
74 } inodes_stat
= {0, 0,};
76 static kmem_cache_t
* inode_cachep
;
78 #define alloc_inode() \
79 ((struct inode *) kmem_cache_alloc(inode_cachep, SLAB_KERNEL))
80 #define destroy_inode(inode) kmem_cache_free(inode_cachep, (inode))
83 * These are initializations that only need to be done
84 * once, because the fields are idempotent across use
85 * of the inode, so let the slab aware of that.
87 static void init_once(void * foo
, kmem_cache_t
* cachep
, unsigned long flags
)
89 struct inode
* inode
= (struct inode
*) foo
;
91 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
92 SLAB_CTOR_CONSTRUCTOR
)
94 memset(inode
, 0, sizeof(*inode
));
95 init_waitqueue_head(&inode
->i_wait
);
96 INIT_LIST_HEAD(&inode
->i_hash
);
97 INIT_LIST_HEAD(&inode
->i_data
.pages
);
98 INIT_LIST_HEAD(&inode
->i_dentry
);
99 sema_init(&inode
->i_sem
, 1);
100 sema_init(&inode
->i_zombie
, 1);
101 spin_lock_init(&inode
->i_data
.i_shared_lock
);
106 * Put the inode on the super block's dirty list.
108 * CAREFUL! We mark it dirty unconditionally, but
109 * move it onto the dirty list only if it is hashed.
110 * If it was not hashed, it will never be added to
111 * the dirty list even if it is later hashed, as it
112 * will have been marked dirty already.
114 * In short, make sure you hash any inodes _before_
115 * you start marking them dirty..
119 * __mark_inode_dirty - internal function
120 * @inode: inode to mark
122 * Mark an inode as dirty. Callers should use mark_inode_dirty.
125 void __mark_inode_dirty(struct inode
*inode
)
127 struct super_block
* sb
= inode
->i_sb
;
130 spin_lock(&inode_lock
);
131 if (!(inode
->i_state
& I_DIRTY
)) {
132 inode
->i_state
|= I_DIRTY
;
133 /* Only add valid (ie hashed) inodes to the dirty list */
134 if (!list_empty(&inode
->i_hash
)) {
135 list_del(&inode
->i_list
);
136 list_add(&inode
->i_list
, &sb
->s_dirty
);
139 spin_unlock(&inode_lock
);
143 static void __wait_on_inode(struct inode
* inode
)
145 DECLARE_WAITQUEUE(wait
, current
);
147 add_wait_queue(&inode
->i_wait
, &wait
);
149 set_current_state(TASK_UNINTERRUPTIBLE
);
150 if (inode
->i_state
& I_LOCK
) {
154 remove_wait_queue(&inode
->i_wait
, &wait
);
155 current
->state
= TASK_RUNNING
;
158 static inline void wait_on_inode(struct inode
*inode
)
160 if (inode
->i_state
& I_LOCK
)
161 __wait_on_inode(inode
);
165 static inline void write_inode(struct inode
*inode
, int sync
)
167 if (inode
->i_sb
&& inode
->i_sb
->s_op
&& inode
->i_sb
->s_op
->write_inode
)
168 inode
->i_sb
->s_op
->write_inode(inode
, sync
);
171 static inline void __iget(struct inode
* inode
)
173 if (atomic_read(&inode
->i_count
)) {
174 atomic_inc(&inode
->i_count
);
177 atomic_inc(&inode
->i_count
);
178 if (!(inode
->i_state
& I_DIRTY
)) {
179 list_del(&inode
->i_list
);
180 list_add(&inode
->i_list
, &inode_in_use
);
182 inodes_stat
.nr_unused
--;
185 static inline void sync_one(struct inode
*inode
, int sync
)
187 if (inode
->i_state
& I_LOCK
) {
189 spin_unlock(&inode_lock
);
190 __wait_on_inode(inode
);
192 spin_lock(&inode_lock
);
194 list_del(&inode
->i_list
);
195 list_add(&inode
->i_list
, atomic_read(&inode
->i_count
)
198 /* Set I_LOCK, reset I_DIRTY */
199 inode
->i_state
^= I_DIRTY
| I_LOCK
;
200 spin_unlock(&inode_lock
);
202 write_inode(inode
, sync
);
204 spin_lock(&inode_lock
);
205 inode
->i_state
&= ~I_LOCK
;
206 wake_up(&inode
->i_wait
);
210 static inline void sync_list(struct list_head
*head
)
212 struct list_head
* tmp
;
214 while ((tmp
= head
->prev
) != head
)
215 sync_one(list_entry(tmp
, struct inode
, i_list
), 0);
220 * @dev: device to sync the inodes from.
222 * sync_inodes goes through the super block's dirty list,
223 * writes them out, and puts them back on the normal list.
226 void sync_inodes(kdev_t dev
)
228 struct super_block
* sb
= sb_entry(super_blocks
.next
);
231 * Search the super_blocks array for the device(s) to sync.
233 spin_lock(&inode_lock
);
234 for (; sb
!= sb_entry(&super_blocks
); sb
= sb_entry(sb
->s_list
.next
)) {
237 if (dev
&& sb
->s_dev
!= dev
)
240 sync_list(&sb
->s_dirty
);
245 spin_unlock(&inode_lock
);
249 * Called with the spinlock already held..
251 static void sync_all_inodes(void)
253 struct super_block
* sb
= sb_entry(super_blocks
.next
);
254 for (; sb
!= sb_entry(&super_blocks
); sb
= sb_entry(sb
->s_list
.next
)) {
257 sync_list(&sb
->s_dirty
);
262 * write_inode_now - write an inode to disk
263 * @inode: inode to write to disk
264 * @sync: whether the write should be synchronous or not
266 * This function commits an inode to disk immediately if it is
267 * dirty. This is primarily needed by knfsd.
270 void write_inode_now(struct inode
*inode
, int sync
)
272 struct super_block
* sb
= inode
->i_sb
;
275 spin_lock(&inode_lock
);
276 while (inode
->i_state
& I_DIRTY
)
277 sync_one(inode
, sync
);
278 spin_unlock(&inode_lock
);
281 printk("write_inode_now: no super block\n");
285 * clear_inode - clear an inode
286 * @inode: inode to clear
288 * This is called by the filesystem to tell us
289 * that the inode is no longer useful. We just
290 * terminate it with extreme prejudice.
293 void clear_inode(struct inode
*inode
)
295 if (inode
->i_data
.nrpages
)
297 if (!(inode
->i_state
& I_FREEING
))
299 if (inode
->i_state
& I_CLEAR
)
301 wait_on_inode(inode
);
302 if (IS_QUOTAINIT(inode
))
304 if (inode
->i_sb
&& inode
->i_sb
->s_op
&& inode
->i_sb
->s_op
->clear_inode
)
305 inode
->i_sb
->s_op
->clear_inode(inode
);
307 bdput(inode
->i_bdev
);
308 inode
->i_bdev
= NULL
;
310 inode
->i_state
= I_CLEAR
;
314 * Dispose-list gets a local list with local inodes in it, so it doesn't
315 * need to worry about list corruption and SMP locks.
317 static void dispose_list(struct list_head
* head
)
319 struct list_head
* inode_entry
;
320 struct inode
* inode
;
322 while ((inode_entry
= head
->next
) != head
)
324 list_del(inode_entry
);
326 inode
= list_entry(inode_entry
, struct inode
, i_list
);
327 if (inode
->i_data
.nrpages
)
328 truncate_inode_pages(&inode
->i_data
, 0);
330 destroy_inode(inode
);
331 inodes_stat
.nr_inodes
--;
336 * Invalidate all inodes for a device.
338 static int invalidate_list(struct list_head
*head
, struct super_block
* sb
, struct list_head
* dispose
)
340 struct list_head
*next
;
341 int busy
= 0, count
= 0;
345 struct list_head
* tmp
= next
;
346 struct inode
* inode
;
351 inode
= list_entry(tmp
, struct inode
, i_list
);
352 if (inode
->i_sb
!= sb
)
354 if (!atomic_read(&inode
->i_count
)) {
355 list_del(&inode
->i_hash
);
356 INIT_LIST_HEAD(&inode
->i_hash
);
357 list_del(&inode
->i_list
);
358 list_add(&inode
->i_list
, dispose
);
359 inode
->i_state
|= I_FREEING
;
365 /* only unused inodes may be cached with i_count zero */
366 inodes_stat
.nr_unused
-= count
;
371 * This is a two-stage process. First we collect all
372 * offending inodes onto the throw-away list, and in
373 * the second stage we actually dispose of them. This
374 * is because we don't want to sleep while messing
375 * with the global lists..
379 * invalidate_inodes - discard the inodes on a device
382 * Discard all of the inodes for a given superblock. If the discard
383 * fails because there are busy inodes then a non zero value is returned.
384 * If the discard is successful all the inodes have been discarded.
387 int invalidate_inodes(struct super_block
* sb
)
390 LIST_HEAD(throw_away
);
392 spin_lock(&inode_lock
);
393 busy
= invalidate_list(&inode_in_use
, sb
, &throw_away
);
394 busy
|= invalidate_list(&inode_unused
, sb
, &throw_away
);
395 busy
|= invalidate_list(&sb
->s_dirty
, sb
, &throw_away
);
396 spin_unlock(&inode_lock
);
398 dispose_list(&throw_away
);
404 * This is called with the inode lock held. It searches
405 * the in-use for freeable inodes, which are moved to a
406 * temporary list and then placed on the unused list by
409 * We don't expect to have to call this very often.
411 * N.B. The spinlock is released during the call to
414 #define CAN_UNUSE(inode) \
415 (((inode)->i_state | (inode)->i_data.nrpages) == 0)
416 #define INODE(entry) (list_entry(entry, struct inode, i_list))
418 void prune_icache(int goal
)
421 struct list_head
*entry
, *freeable
= &list
;
423 struct inode
* inode
;
425 spin_lock(&inode_lock
);
426 /* go simple and safe syncing everything before starting */
429 entry
= inode_unused
.prev
;
430 while (entry
!= &inode_unused
)
432 struct list_head
*tmp
= entry
;
436 if (inode
->i_state
& (I_FREEING
|I_CLEAR
))
438 if (!CAN_UNUSE(inode
))
440 if (atomic_read(&inode
->i_count
))
443 list_del(&inode
->i_hash
);
444 INIT_LIST_HEAD(&inode
->i_hash
);
445 list_add(tmp
, freeable
);
446 inode
->i_state
|= I_FREEING
;
451 inodes_stat
.nr_unused
-= count
;
452 spin_unlock(&inode_lock
);
454 dispose_list(freeable
);
457 int shrink_icache_memory(int priority
, int gfp_mask
)
462 count
= inodes_stat
.nr_unused
/ priority
;
464 /* FIXME: kmem_cache_shrink here should tell us
465 the number of pages freed, and it should
466 work in a __GFP_DMA/__GFP_HIGHMEM behaviour
467 to free only the interesting pages in
468 function of the needs of the current allocation. */
469 kmem_cache_shrink(inode_cachep
);
475 * Called with the inode lock held.
476 * NOTE: we are not increasing the inode-refcount, you must call __iget()
477 * by hand after calling find_inode now! This simplifies iunique and won't
478 * add any additional branch in the common code.
480 static struct inode
* find_inode(struct super_block
* sb
, unsigned long ino
, struct list_head
*head
, find_inode_t find_actor
, void *opaque
)
482 struct list_head
*tmp
;
483 struct inode
* inode
;
491 inode
= list_entry(tmp
, struct inode
, i_hash
);
492 if (inode
->i_ino
!= ino
)
494 if (inode
->i_sb
!= sb
)
496 if (find_actor
&& !find_actor(inode
, ino
, opaque
))
504 * This just initializes the inode fields
505 * to known values before returning the inode..
507 * i_sb, i_ino, i_count, i_state and the lists have
508 * been initialized elsewhere..
510 static void clean_inode(struct inode
*inode
)
512 static struct address_space_operations empty_aops
= {};
513 static struct inode_operations empty_iops
= {};
514 static struct file_operations empty_fops
= {};
515 memset(&inode
->u
, 0, sizeof(inode
->u
));
517 inode
->i_op
= &empty_iops
;
518 inode
->i_fop
= &empty_fops
;
520 atomic_set(&inode
->i_writecount
, 0);
522 inode
->i_generation
= 0;
523 memset(&inode
->i_dquot
, 0, sizeof(inode
->i_dquot
));
524 inode
->i_pipe
= NULL
;
525 inode
->i_bdev
= NULL
;
526 inode
->i_data
.a_ops
= &empty_aops
;
527 inode
->i_data
.host
= (void*)inode
;
528 inode
->i_mapping
= &inode
->i_data
;
532 * get_empty_inode - obtain an inode
534 * This is called by things like the networking layer
535 * etc that want to get an inode without any inode
536 * number, or filesystems that allocate new inodes with
537 * no pre-existing information.
539 * On a successful return the inode pointer is returned. On a failure
540 * a %NULL pointer is returned. The returned inode is not on any superblock
544 struct inode
* get_empty_inode(void)
546 static unsigned long last_ino
= 0;
547 struct inode
* inode
;
549 inode
= alloc_inode();
552 spin_lock(&inode_lock
);
553 inodes_stat
.nr_inodes
++;
554 list_add(&inode
->i_list
, &inode_in_use
);
557 inode
->i_ino
= ++last_ino
;
559 atomic_set(&inode
->i_count
, 1);
561 spin_unlock(&inode_lock
);
568 * This is called without the inode lock held.. Be careful.
570 * We no longer cache the sb_flags in i_flags - see fs.h
571 * -- rmk@arm.uk.linux.org
573 static struct inode
* get_new_inode(struct super_block
*sb
, unsigned long ino
, struct list_head
*head
, find_inode_t find_actor
, void *opaque
)
575 struct inode
* inode
;
577 inode
= alloc_inode();
581 spin_lock(&inode_lock
);
582 /* We released the lock, so.. */
583 old
= find_inode(sb
, ino
, head
, find_actor
, opaque
);
585 inodes_stat
.nr_inodes
++;
586 list_add(&inode
->i_list
, &inode_in_use
);
587 list_add(&inode
->i_hash
, head
);
589 inode
->i_dev
= sb
->s_dev
;
592 atomic_set(&inode
->i_count
, 1);
593 inode
->i_state
= I_LOCK
;
594 spin_unlock(&inode_lock
);
597 sb
->s_op
->read_inode(inode
);
600 * This is special! We do not need the spinlock
601 * when clearing I_LOCK, because we're guaranteed
602 * that nobody else tries to do anything about the
603 * state of the inode when it is locked, as we
604 * just created it (so there can be no old holders
605 * that haven't tested I_LOCK).
607 inode
->i_state
&= ~I_LOCK
;
608 wake_up(&inode
->i_wait
);
614 * Uhhuh, somebody else created the same inode under
615 * us. Use the old inode instead of the one we just
619 spin_unlock(&inode_lock
);
620 destroy_inode(inode
);
622 wait_on_inode(inode
);
627 static inline unsigned long hash(struct super_block
*sb
, unsigned long i_ino
)
629 unsigned long tmp
= i_ino
| ((unsigned long) sb
/ L1_CACHE_BYTES
);
630 tmp
= tmp
+ (tmp
>> I_HASHBITS
) + (tmp
>> I_HASHBITS
*2);
631 return tmp
& I_HASHMASK
;
634 /* Yeah, I know about quadratic hash. Maybe, later. */
637 * iunique - get a unique inode number
639 * @max_reserved: highest reserved inode number
641 * Obtain an inode number that is unique on the system for a given
642 * superblock. This is used by file systems that have no natural
643 * permanent inode numbering system. An inode number is returned that
644 * is higher than the reserved limit but unique.
647 * With a large number of inodes live on the file system this function
648 * currently becomes quite slow.
651 ino_t
iunique(struct super_block
*sb
, ino_t max_reserved
)
653 static ino_t counter
= 0;
655 struct list_head
* head
;
657 spin_lock(&inode_lock
);
659 if (counter
> max_reserved
) {
660 head
= inode_hashtable
+ hash(sb
,counter
);
661 inode
= find_inode(sb
, res
= counter
++, head
, NULL
, NULL
);
663 spin_unlock(&inode_lock
);
667 counter
= max_reserved
+ 1;
673 struct inode
*igrab(struct inode
*inode
)
675 spin_lock(&inode_lock
);
676 if (!(inode
->i_state
& I_FREEING
))
680 * Handle the case where s_op->clear_inode is not been
681 * called yet, and somebody is calling igrab
682 * while the inode is getting freed.
685 spin_unlock(&inode_lock
);
687 wait_on_inode(inode
);
692 struct inode
*iget4(struct super_block
*sb
, unsigned long ino
, find_inode_t find_actor
, void *opaque
)
694 struct list_head
* head
= inode_hashtable
+ hash(sb
,ino
);
695 struct inode
* inode
;
697 spin_lock(&inode_lock
);
698 inode
= find_inode(sb
, ino
, head
, find_actor
, opaque
);
701 spin_unlock(&inode_lock
);
702 wait_on_inode(inode
);
705 spin_unlock(&inode_lock
);
708 * get_new_inode() will do the right thing, re-trying the search
709 * in case it had to block at any point.
711 return get_new_inode(sb
, ino
, head
, find_actor
, opaque
);
715 * insert_inode_hash - hash an inode
716 * @inode: unhashed inode
718 * Add an inode to the inode hash for this superblock. If the inode
719 * has no superblock it is added to a separate anonymous chain.
722 void insert_inode_hash(struct inode
*inode
)
724 struct list_head
*head
= &anon_hash_chain
;
726 head
= inode_hashtable
+ hash(inode
->i_sb
, inode
->i_ino
);
727 spin_lock(&inode_lock
);
728 list_add(&inode
->i_hash
, head
);
729 spin_unlock(&inode_lock
);
733 * remove_inode_hash - remove an inode from the hash
734 * @inode: inode to unhash
736 * Remove an inode from the superblock or anonymous hash.
739 void remove_inode_hash(struct inode
*inode
)
741 spin_lock(&inode_lock
);
742 list_del(&inode
->i_hash
);
743 INIT_LIST_HEAD(&inode
->i_hash
);
744 spin_unlock(&inode_lock
);
748 * iput - put an inode
749 * @inode: inode to put
751 * Puts an inode, dropping its usage count. If the inode use count hits
752 * zero the inode is also then freed and may be destroyed.
755 void iput(struct inode
*inode
)
758 struct super_operations
*op
= NULL
;
760 if (inode
->i_sb
&& inode
->i_sb
->s_op
)
761 op
= inode
->i_sb
->s_op
;
762 if (op
&& op
->put_inode
)
763 op
->put_inode(inode
);
765 if (!atomic_dec_and_lock(&inode
->i_count
, &inode_lock
))
768 if (!inode
->i_nlink
) {
769 list_del(&inode
->i_hash
);
770 INIT_LIST_HEAD(&inode
->i_hash
);
771 list_del(&inode
->i_list
);
772 INIT_LIST_HEAD(&inode
->i_list
);
773 inode
->i_state
|=I_FREEING
;
774 inodes_stat
.nr_inodes
--;
775 spin_unlock(&inode_lock
);
777 if (inode
->i_data
.nrpages
)
778 truncate_inode_pages(&inode
->i_data
, 0);
780 if (op
&& op
->delete_inode
) {
781 void (*delete)(struct inode
*) = op
->delete_inode
;
782 /* s_op->delete_inode internally recalls clear_inode() */
786 if (inode
->i_state
!= I_CLEAR
)
789 if (!list_empty(&inode
->i_hash
)) {
790 if (!(inode
->i_state
& I_DIRTY
)) {
791 list_del(&inode
->i_list
);
792 list_add(&inode
->i_list
,
795 inodes_stat
.nr_unused
++;
796 spin_unlock(&inode_lock
);
800 list_del(&inode
->i_list
);
801 INIT_LIST_HEAD(&inode
->i_list
);
802 inode
->i_state
|=I_FREEING
;
803 inodes_stat
.nr_inodes
--;
804 spin_unlock(&inode_lock
);
808 destroy_inode(inode
);
812 void force_delete(struct inode
*inode
)
815 * Kill off unused inodes ... iput() will unhash and
816 * delete the inode if we set i_nlink to zero.
818 if (atomic_read(&inode
->i_count
) == 1)
823 * bmap - find a block number in a file
824 * @inode: inode of file
825 * @block: block to find
827 * Returns the block number on the device holding the inode that
828 * is the disk block number for the block of the file requested.
829 * That is, asked for block 4 of inode 1 the function will return the
830 * disk block relative to the disk start that holds that block of the
834 int bmap(struct inode
* inode
, int block
)
837 if (inode
->i_mapping
->a_ops
->bmap
)
838 res
= inode
->i_mapping
->a_ops
->bmap(inode
->i_mapping
, block
);
843 * Initialize the hash tables.
845 void __init
inode_init(unsigned long mempages
)
847 struct list_head
*head
;
849 unsigned int nr_hash
;
852 mempages
>>= (14 - PAGE_SHIFT
);
853 mempages
*= sizeof(struct list_head
);
854 for (order
= 0; ((1UL << order
) << PAGE_SHIFT
) < mempages
; order
++)
860 nr_hash
= (1UL << order
) * PAGE_SIZE
/
861 sizeof(struct list_head
);
862 i_hash_mask
= (nr_hash
- 1);
866 while ((tmp
>>= 1UL) != 0UL)
869 inode_hashtable
= (struct list_head
*)
870 __get_free_pages(GFP_ATOMIC
, order
);
871 } while (inode_hashtable
== NULL
&& --order
>= 0);
873 printk("Inode-cache hash table entries: %d (order: %ld, %ld bytes)\n",
874 nr_hash
, order
, (PAGE_SIZE
<< order
));
876 if (!inode_hashtable
)
877 panic("Failed to allocate inode hash table\n");
879 head
= inode_hashtable
;
882 INIT_LIST_HEAD(head
);
887 /* inode slab cache */
888 inode_cachep
= kmem_cache_create("inode_cache", sizeof(struct inode
),
889 0, SLAB_HWCACHE_ALIGN
, init_once
,
892 panic("cannot create inode slab cache");
896 * update_atime - update the access time
897 * @inode: inode accessed
899 * Update the accessed time on an inode and mark it for writeback.
900 * This function automatically handles read only file systems and media,
901 * as well as the "noatime" flag and inode specific "noatime" markers.
904 void update_atime (struct inode
*inode
)
906 if ( IS_NOATIME (inode
) ) return;
907 if ( IS_NODIRATIME (inode
) && S_ISDIR (inode
->i_mode
) ) return;
908 if ( IS_RDONLY (inode
) ) return;
909 inode
->i_atime
= CURRENT_TIME
;
910 mark_inode_dirty (inode
);
911 } /* End Function update_atime */
915 * Quota functions that want to walk the inode lists..
919 /* Functions back in dquot.c */
920 void put_dquot_list(struct list_head
*);
921 int remove_inode_dquot_ref(struct inode
*, short, struct list_head
*);
923 void remove_dquot_ref(kdev_t dev
, short type
)
925 struct super_block
*sb
= get_super(dev
);
927 struct list_head
*act_head
;
928 LIST_HEAD(tofree_head
);
930 if (!sb
|| !sb
->dq_op
)
931 return; /* nothing to do */
933 /* We have to be protected against other CPUs */
934 spin_lock(&inode_lock
);
936 for (act_head
= inode_in_use
.next
; act_head
!= &inode_in_use
; act_head
= act_head
->next
) {
937 inode
= list_entry(act_head
, struct inode
, i_list
);
938 if (inode
->i_sb
!= sb
|| !IS_QUOTAINIT(inode
))
940 remove_inode_dquot_ref(inode
, type
, &tofree_head
);
942 for (act_head
= inode_unused
.next
; act_head
!= &inode_unused
; act_head
= act_head
->next
) {
943 inode
= list_entry(act_head
, struct inode
, i_list
);
944 if (inode
->i_sb
!= sb
|| !IS_QUOTAINIT(inode
))
946 remove_inode_dquot_ref(inode
, type
, &tofree_head
);
948 for (act_head
= sb
->s_dirty
.next
; act_head
!= &sb
->s_dirty
; act_head
= act_head
->next
) {
949 inode
= list_entry(act_head
, struct inode
, i_list
);
950 if (!IS_QUOTAINIT(inode
))
952 remove_inode_dquot_ref(inode
, type
, &tofree_head
);
954 spin_unlock(&inode_lock
);
956 put_dquot_list(&tofree_head
);