- pre3:
[davej-history.git] / fs / inode.c
blob2199d68884e77f7be5c1bceebc24452d5d9833c4
1 /*
2 * linux/fs/inode.c
4 * (C) 1997 Linus Torvalds
5 */
7 #include <linux/config.h>
8 #include <linux/fs.h>
9 #include <linux/string.h>
10 #include <linux/mm.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".
24 * Famous last words.
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..
70 struct {
71 int nr_inodes;
72 int nr_unused;
73 int dummy[5];
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;
129 if (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);
148 repeat:
149 set_current_state(TASK_UNINTERRUPTIBLE);
150 if (inode->i_state & I_LOCK) {
151 schedule();
152 goto repeat;
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);
175 return;
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) {
188 __iget(inode);
189 spin_unlock(&inode_lock);
190 __wait_on_inode(inode);
191 iput(inode);
192 spin_lock(&inode_lock);
193 } else {
194 list_del(&inode->i_list);
195 list_add(&inode->i_list, atomic_read(&inode->i_count)
196 ? &inode_in_use
197 : &inode_unused);
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);
219 * sync_inodes
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)) {
235 if (!sb->s_dev)
236 continue;
237 if (dev && sb->s_dev != dev)
238 continue;
240 sync_list(&sb->s_dirty);
242 if (dev)
243 break;
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)) {
255 if (!sb->s_dev)
256 continue;
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;
274 if (sb) {
275 spin_lock(&inode_lock);
276 while (inode->i_state & I_DIRTY)
277 sync_one(inode, sync);
278 spin_unlock(&inode_lock);
280 else
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)
296 BUG();
297 if (!(inode->i_state & I_FREEING))
298 BUG();
299 if (inode->i_state & I_CLEAR)
300 BUG();
301 wait_on_inode(inode);
302 if (IS_QUOTAINIT(inode))
303 DQUOT_DROP(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);
306 if (inode->i_bdev) {
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);
329 clear_inode(inode);
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;
343 next = head->next;
344 for (;;) {
345 struct list_head * tmp = next;
346 struct inode * inode;
348 next = next->next;
349 if (tmp == head)
350 break;
351 inode = list_entry(tmp, struct inode, i_list);
352 if (inode->i_sb != sb)
353 continue;
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;
360 count++;
361 continue;
363 busy = 1;
365 /* only unused inodes may be cached with i_count zero */
366 inodes_stat.nr_unused -= count;
367 return busy;
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
380 * @sb: superblock
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)
389 int busy;
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);
400 return busy;
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
407 * dispose_list.
409 * We don't expect to have to call this very often.
411 * N.B. The spinlock is released during the call to
412 * dispose_list.
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)
420 LIST_HEAD(list);
421 struct list_head *entry, *freeable = &list;
422 int count = 0;
423 struct inode * inode;
425 spin_lock(&inode_lock);
426 /* go simple and safe syncing everything before starting */
427 sync_all_inodes();
429 entry = inode_unused.prev;
430 while (entry != &inode_unused)
432 struct list_head *tmp = entry;
434 entry = entry->prev;
435 inode = INODE(tmp);
436 if (inode->i_state & (I_FREEING|I_CLEAR))
437 BUG();
438 if (!CAN_UNUSE(inode))
439 continue;
440 if (atomic_read(&inode->i_count))
441 BUG();
442 list_del(tmp);
443 list_del(&inode->i_hash);
444 INIT_LIST_HEAD(&inode->i_hash);
445 list_add(tmp, freeable);
446 inode->i_state |= I_FREEING;
447 count++;
448 if (!--goal)
449 break;
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)
459 int count = 0;
461 if (priority)
462 count = inodes_stat.nr_unused / priority;
463 prune_icache(count);
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);
471 return 0;
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;
485 tmp = head;
486 for (;;) {
487 tmp = tmp->next;
488 inode = NULL;
489 if (tmp == head)
490 break;
491 inode = list_entry(tmp, struct inode, i_hash);
492 if (inode->i_ino != ino)
493 continue;
494 if (inode->i_sb != sb)
495 continue;
496 if (find_actor && !find_actor(inode, ino, opaque))
497 continue;
498 break;
500 return inode;
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));
516 inode->i_sock = 0;
517 inode->i_op = &empty_iops;
518 inode->i_fop = &empty_fops;
519 inode->i_nlink = 1;
520 atomic_set(&inode->i_writecount, 0);
521 inode->i_size = 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
541 * lists.
544 struct inode * get_empty_inode(void)
546 static unsigned long last_ino = 0;
547 struct inode * inode;
549 inode = alloc_inode();
550 if (inode)
552 spin_lock(&inode_lock);
553 inodes_stat.nr_inodes++;
554 list_add(&inode->i_list, &inode_in_use);
555 inode->i_sb = NULL;
556 inode->i_dev = 0;
557 inode->i_ino = ++last_ino;
558 inode->i_flags = 0;
559 atomic_set(&inode->i_count, 1);
560 inode->i_state = 0;
561 spin_unlock(&inode_lock);
562 clean_inode(inode);
564 return inode;
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();
578 if (inode) {
579 struct inode * old;
581 spin_lock(&inode_lock);
582 /* We released the lock, so.. */
583 old = find_inode(sb, ino, head, find_actor, opaque);
584 if (!old) {
585 inodes_stat.nr_inodes++;
586 list_add(&inode->i_list, &inode_in_use);
587 list_add(&inode->i_hash, head);
588 inode->i_sb = sb;
589 inode->i_dev = sb->s_dev;
590 inode->i_ino = ino;
591 inode->i_flags = 0;
592 atomic_set(&inode->i_count, 1);
593 inode->i_state = I_LOCK;
594 spin_unlock(&inode_lock);
596 clean_inode(inode);
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);
610 return inode;
614 * Uhhuh, somebody else created the same inode under
615 * us. Use the old inode instead of the one we just
616 * allocated.
618 __iget(old);
619 spin_unlock(&inode_lock);
620 destroy_inode(inode);
621 inode = old;
622 wait_on_inode(inode);
624 return 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
638 * @sb: superblock
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.
646 * BUGS:
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;
654 struct inode *inode;
655 struct list_head * head;
656 ino_t res;
657 spin_lock(&inode_lock);
658 retry:
659 if (counter > max_reserved) {
660 head = inode_hashtable + hash(sb,counter);
661 inode = find_inode(sb, res = counter++, head, NULL, NULL);
662 if (!inode) {
663 spin_unlock(&inode_lock);
664 return res;
666 } else {
667 counter = max_reserved + 1;
669 goto retry;
673 struct inode *igrab(struct inode *inode)
675 spin_lock(&inode_lock);
676 if (!(inode->i_state & I_FREEING))
677 __iget(inode);
678 else
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.
684 inode = NULL;
685 spin_unlock(&inode_lock);
686 if (inode)
687 wait_on_inode(inode);
688 return 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);
699 if (inode) {
700 __iget(inode);
701 spin_unlock(&inode_lock);
702 wait_on_inode(inode);
703 return 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;
725 if (inode->i_sb)
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)
757 if (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))
766 return;
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() */
783 delete(inode);
784 } else
785 clear_inode(inode);
786 if (inode->i_state != I_CLEAR)
787 BUG();
788 } else {
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,
793 &inode_unused);
795 inodes_stat.nr_unused++;
796 spin_unlock(&inode_lock);
797 return;
798 } else {
799 /* magic nfs path */
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);
805 clear_inode(inode);
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)
819 inode->i_nlink = 0;
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
831 * file.
834 int bmap(struct inode * inode, int block)
836 int res = 0;
837 if (inode->i_mapping->a_ops->bmap)
838 res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block);
839 return res;
843 * Initialize the hash tables.
845 void __init inode_init(unsigned long mempages)
847 struct list_head *head;
848 unsigned long order;
849 unsigned int nr_hash;
850 int i;
852 mempages >>= (14 - PAGE_SHIFT);
853 mempages *= sizeof(struct list_head);
854 for (order = 0; ((1UL << order) << PAGE_SHIFT) < mempages; order++)
857 do {
858 unsigned long tmp;
860 nr_hash = (1UL << order) * PAGE_SIZE /
861 sizeof(struct list_head);
862 i_hash_mask = (nr_hash - 1);
864 tmp = nr_hash;
865 i_hash_shift = 0;
866 while ((tmp >>= 1UL) != 0UL)
867 i_hash_shift++;
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;
880 i = nr_hash;
881 do {
882 INIT_LIST_HEAD(head);
883 head++;
884 i--;
885 } while (i);
887 /* inode slab cache */
888 inode_cachep = kmem_cache_create("inode_cache", sizeof(struct inode),
889 0, SLAB_HWCACHE_ALIGN, init_once,
890 NULL);
891 if (!inode_cachep)
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..
917 #ifdef CONFIG_QUOTA
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);
926 struct inode *inode;
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))
939 continue;
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))
945 continue;
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))
951 continue;
952 remove_inode_dquot_ref(inode, type, &tofree_head);
954 spin_unlock(&inode_lock);
956 put_dquot_list(&tofree_head);
959 #endif