[PATCH] fix make rpm versioning
[linux-2.6/history.git] / fs / dcache.c
blob6c7e6bf1846774ad6cd4e520fafcb88bf9dd389b
1 /*
2 * fs/dcache.c
4 * Complete reimplementation
5 * (C) 1997 Thomas Schoebel-Theuer,
6 * with heavy changes by Linus Torvalds
7 */
9 /*
10 * Notes on the allocation strategy:
12 * The dcache is a master of the icache - whenever a dcache entry
13 * exists, the inode will always exist. "iput()" is done either when
14 * the dcache entry is deleted or garbage collected.
17 #include <linux/config.h>
18 #include <linux/string.h>
19 #include <linux/mm.h>
20 #include <linux/fs.h>
21 #include <linux/slab.h>
22 #include <linux/init.h>
23 #include <linux/smp_lock.h>
24 #include <linux/cache.h>
25 #include <linux/module.h>
26 #include <linux/mount.h>
27 #include <linux/file.h>
28 #include <asm/uaccess.h>
29 #include <linux/security.h>
30 #include <linux/seqlock.h>
32 #define DCACHE_PARANOIA 1
33 /* #define DCACHE_DEBUG 1 */
35 spinlock_t dcache_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
36 seqlock_t rename_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED;
38 static kmem_cache_t *dentry_cache;
41 * This is the single most critical data structure when it comes
42 * to the dcache: the hashtable for lookups. Somebody should try
43 * to make this good - I've just made it work.
45 * This hash-function tries to avoid losing too many bits of hash
46 * information, yet avoid using a prime hash-size or similar.
48 #define D_HASHBITS d_hash_shift
49 #define D_HASHMASK d_hash_mask
51 static unsigned int d_hash_mask;
52 static unsigned int d_hash_shift;
53 static struct hlist_head *dentry_hashtable;
54 static LIST_HEAD(dentry_unused);
56 /* Statistics gathering. */
57 struct dentry_stat_t dentry_stat = {
58 .age_limit = 45,
61 static void d_callback(void *arg)
63 struct dentry * dentry = (struct dentry *)arg;
65 if (dname_external(dentry)) {
66 kfree(dentry->d_qstr);
68 kmem_cache_free(dentry_cache, dentry);
72 * no dcache_lock, please. The caller must decrement dentry_stat.nr_dentry
73 * inside dcache_lock.
75 static void d_free(struct dentry *dentry)
77 if (dentry->d_op && dentry->d_op->d_release)
78 dentry->d_op->d_release(dentry);
79 call_rcu(&dentry->d_rcu, d_callback, dentry);
83 * Release the dentry's inode, using the filesystem
84 * d_iput() operation if defined.
85 * Called with dcache_lock held, drops it.
87 static inline void dentry_iput(struct dentry * dentry)
89 struct inode *inode = dentry->d_inode;
90 if (inode) {
91 dentry->d_inode = NULL;
92 list_del_init(&dentry->d_alias);
93 spin_unlock(&dcache_lock);
94 if (dentry->d_op && dentry->d_op->d_iput)
95 dentry->d_op->d_iput(dentry, inode);
96 else
97 iput(inode);
98 } else
99 spin_unlock(&dcache_lock);
103 * This is dput
105 * This is complicated by the fact that we do not want to put
106 * dentries that are no longer on any hash chain on the unused
107 * list: we'd much rather just get rid of them immediately.
109 * However, that implies that we have to traverse the dentry
110 * tree upwards to the parents which might _also_ now be
111 * scheduled for deletion (it may have been only waiting for
112 * its last child to go away).
114 * This tail recursion is done by hand as we don't want to depend
115 * on the compiler to always get this right (gcc generally doesn't).
116 * Real recursion would eat up our stack space.
120 * dput - release a dentry
121 * @dentry: dentry to release
123 * Release a dentry. This will drop the usage count and if appropriate
124 * call the dentry unlink method as well as removing it from the queues and
125 * releasing its resources. If the parent dentries were scheduled for release
126 * they too may now get deleted.
128 * no dcache lock, please.
131 void dput(struct dentry *dentry)
133 if (!dentry)
134 return;
136 repeat:
137 if (!atomic_dec_and_lock(&dentry->d_count, &dcache_lock))
138 return;
140 spin_lock(&dentry->d_lock);
141 if (atomic_read(&dentry->d_count)) {
142 spin_unlock(&dentry->d_lock);
143 spin_unlock(&dcache_lock);
144 return;
148 * AV: ->d_delete() is _NOT_ allowed to block now.
150 if (dentry->d_op && dentry->d_op->d_delete) {
151 if (dentry->d_op->d_delete(dentry))
152 goto unhash_it;
154 /* Unreachable? Get rid of it */
155 if (d_unhashed(dentry))
156 goto kill_it;
157 if (list_empty(&dentry->d_lru)) {
158 dentry->d_vfs_flags |= DCACHE_REFERENCED;
159 list_add(&dentry->d_lru, &dentry_unused);
160 dentry_stat.nr_unused++;
162 spin_unlock(&dentry->d_lock);
163 spin_unlock(&dcache_lock);
164 return;
166 unhash_it:
167 __d_drop(dentry);
169 kill_it: {
170 struct dentry *parent;
172 /* If dentry was on d_lru list
173 * delete it from there
175 if (!list_empty(&dentry->d_lru)) {
176 list_del(&dentry->d_lru);
177 dentry_stat.nr_unused--;
179 list_del(&dentry->d_child);
180 spin_unlock(&dentry->d_lock);
181 dentry_stat.nr_dentry--; /* For d_free, below */
182 /* drops the lock, at that point nobody can reach this dentry */
183 dentry_iput(dentry);
184 parent = dentry->d_parent;
185 d_free(dentry);
186 if (dentry == parent)
187 return;
188 dentry = parent;
189 goto repeat;
194 * d_invalidate - invalidate a dentry
195 * @dentry: dentry to invalidate
197 * Try to invalidate the dentry if it turns out to be
198 * possible. If there are other dentries that can be
199 * reached through this one we can't delete it and we
200 * return -EBUSY. On success we return 0.
202 * no dcache lock.
205 int d_invalidate(struct dentry * dentry)
208 * If it's already been dropped, return OK.
210 spin_lock(&dcache_lock);
211 if (d_unhashed(dentry)) {
212 spin_unlock(&dcache_lock);
213 return 0;
216 * Check whether to do a partial shrink_dcache
217 * to get rid of unused child entries.
219 if (!list_empty(&dentry->d_subdirs)) {
220 spin_unlock(&dcache_lock);
221 shrink_dcache_parent(dentry);
222 spin_lock(&dcache_lock);
226 * Somebody else still using it?
228 * If it's a directory, we can't drop it
229 * for fear of somebody re-populating it
230 * with children (even though dropping it
231 * would make it unreachable from the root,
232 * we might still populate it if it was a
233 * working directory or similar).
235 spin_lock(&dentry->d_lock);
236 if (atomic_read(&dentry->d_count) > 1) {
237 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
238 spin_unlock(&dentry->d_lock);
239 spin_unlock(&dcache_lock);
240 return -EBUSY;
244 __d_drop(dentry);
245 spin_unlock(&dentry->d_lock);
246 spin_unlock(&dcache_lock);
247 return 0;
250 /* This should be called _only_ with dcache_lock held */
252 static inline struct dentry * __dget_locked(struct dentry *dentry)
254 atomic_inc(&dentry->d_count);
255 if (atomic_read(&dentry->d_count) == 1) {
256 dentry_stat.nr_unused--;
257 list_del_init(&dentry->d_lru);
259 return dentry;
262 struct dentry * dget_locked(struct dentry *dentry)
264 return __dget_locked(dentry);
268 * d_find_alias - grab a hashed alias of inode
269 * @inode: inode in question
271 * If inode has a hashed alias - acquire the reference to alias and
272 * return it. Otherwise return NULL. Notice that if inode is a directory
273 * there can be only one alias and it can be unhashed only if it has
274 * no children.
276 * If the inode has a DCACHE_DISCONNECTED alias, then prefer
277 * any other hashed alias over that one.
280 struct dentry * d_find_alias(struct inode *inode)
282 struct list_head *head, *next, *tmp;
283 struct dentry *alias, *discon_alias=NULL;
285 spin_lock(&dcache_lock);
286 head = &inode->i_dentry;
287 next = inode->i_dentry.next;
288 while (next != head) {
289 tmp = next;
290 next = tmp->next;
291 prefetch(next);
292 alias = list_entry(tmp, struct dentry, d_alias);
293 if (!d_unhashed(alias)) {
294 if (alias->d_flags & DCACHE_DISCONNECTED)
295 discon_alias = alias;
296 else {
297 __dget_locked(alias);
298 spin_unlock(&dcache_lock);
299 return alias;
303 if (discon_alias)
304 __dget_locked(discon_alias);
305 spin_unlock(&dcache_lock);
306 return discon_alias;
310 * Try to kill dentries associated with this inode.
311 * WARNING: you must own a reference to inode.
313 void d_prune_aliases(struct inode *inode)
315 struct list_head *tmp, *head = &inode->i_dentry;
316 restart:
317 spin_lock(&dcache_lock);
318 tmp = head;
319 while ((tmp = tmp->next) != head) {
320 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
321 if (!atomic_read(&dentry->d_count)) {
322 __dget_locked(dentry);
323 __d_drop(dentry);
324 spin_unlock(&dcache_lock);
325 dput(dentry);
326 goto restart;
329 spin_unlock(&dcache_lock);
333 * Throw away a dentry - free the inode, dput the parent.
334 * This requires that the LRU list has already been
335 * removed.
336 * Called with dcache_lock, drops it and then regains.
338 static inline void prune_one_dentry(struct dentry * dentry)
340 struct dentry * parent;
342 __d_drop(dentry);
343 list_del(&dentry->d_child);
344 spin_unlock(&dentry->d_lock);
345 dentry_stat.nr_dentry--; /* For d_free, below */
346 dentry_iput(dentry);
347 parent = dentry->d_parent;
348 d_free(dentry);
349 if (parent != dentry)
350 dput(parent);
351 spin_lock(&dcache_lock);
355 * prune_dcache - shrink the dcache
356 * @count: number of entries to try and free
358 * Shrink the dcache. This is done when we need
359 * more memory, or simply when we need to unmount
360 * something (at which point we need to unuse
361 * all dentries).
363 * This function may fail to free any resources if
364 * all the dentries are in use.
367 static void prune_dcache(int count)
369 spin_lock(&dcache_lock);
370 for (; count ; count--) {
371 struct dentry *dentry;
372 struct list_head *tmp;
374 tmp = dentry_unused.prev;
375 if (tmp == &dentry_unused)
376 break;
377 list_del_init(tmp);
378 prefetch(dentry_unused.prev);
379 dentry_stat.nr_unused--;
380 dentry = list_entry(tmp, struct dentry, d_lru);
382 spin_lock(&dentry->d_lock);
383 /* leave inuse dentries */
384 if (atomic_read(&dentry->d_count)) {
385 spin_unlock(&dentry->d_lock);
386 continue;
388 /* If the dentry was recently referenced, don't free it. */
389 if (dentry->d_vfs_flags & DCACHE_REFERENCED) {
390 dentry->d_vfs_flags &= ~DCACHE_REFERENCED;
391 list_add(&dentry->d_lru, &dentry_unused);
392 dentry_stat.nr_unused++;
393 spin_unlock(&dentry->d_lock);
394 continue;
396 prune_one_dentry(dentry);
398 spin_unlock(&dcache_lock);
402 * Shrink the dcache for the specified super block.
403 * This allows us to unmount a device without disturbing
404 * the dcache for the other devices.
406 * This implementation makes just two traversals of the
407 * unused list. On the first pass we move the selected
408 * dentries to the most recent end, and on the second
409 * pass we free them. The second pass must restart after
410 * each dput(), but since the target dentries are all at
411 * the end, it's really just a single traversal.
415 * shrink_dcache_sb - shrink dcache for a superblock
416 * @sb: superblock
418 * Shrink the dcache for the specified super block. This
419 * is used to free the dcache before unmounting a file
420 * system
423 void shrink_dcache_sb(struct super_block * sb)
425 struct list_head *tmp, *next;
426 struct dentry *dentry;
429 * Pass one ... move the dentries for the specified
430 * superblock to the most recent end of the unused list.
432 spin_lock(&dcache_lock);
433 next = dentry_unused.next;
434 while (next != &dentry_unused) {
435 tmp = next;
436 next = tmp->next;
437 dentry = list_entry(tmp, struct dentry, d_lru);
438 if (dentry->d_sb != sb)
439 continue;
440 list_del(tmp);
441 list_add(tmp, &dentry_unused);
445 * Pass two ... free the dentries for this superblock.
447 repeat:
448 next = dentry_unused.next;
449 while (next != &dentry_unused) {
450 tmp = next;
451 next = tmp->next;
452 dentry = list_entry(tmp, struct dentry, d_lru);
453 if (dentry->d_sb != sb)
454 continue;
455 dentry_stat.nr_unused--;
456 list_del_init(tmp);
457 spin_lock(&dentry->d_lock);
458 if (atomic_read(&dentry->d_count)) {
459 spin_unlock(&dentry->d_lock);
460 continue;
462 prune_one_dentry(dentry);
463 goto repeat;
465 spin_unlock(&dcache_lock);
469 * Search for at least 1 mount point in the dentry's subdirs.
470 * We descend to the next level whenever the d_subdirs
471 * list is non-empty and continue searching.
475 * have_submounts - check for mounts over a dentry
476 * @parent: dentry to check.
478 * Return true if the parent or its subdirectories contain
479 * a mount point
482 int have_submounts(struct dentry *parent)
484 struct dentry *this_parent = parent;
485 struct list_head *next;
487 spin_lock(&dcache_lock);
488 if (d_mountpoint(parent))
489 goto positive;
490 repeat:
491 next = this_parent->d_subdirs.next;
492 resume:
493 while (next != &this_parent->d_subdirs) {
494 struct list_head *tmp = next;
495 struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
496 next = tmp->next;
497 /* Have we found a mount point ? */
498 if (d_mountpoint(dentry))
499 goto positive;
500 if (!list_empty(&dentry->d_subdirs)) {
501 this_parent = dentry;
502 goto repeat;
506 * All done at this level ... ascend and resume the search.
508 if (this_parent != parent) {
509 next = this_parent->d_child.next;
510 this_parent = this_parent->d_parent;
511 goto resume;
513 spin_unlock(&dcache_lock);
514 return 0; /* No mount points found in tree */
515 positive:
516 spin_unlock(&dcache_lock);
517 return 1;
521 * Search the dentry child list for the specified parent,
522 * and move any unused dentries to the end of the unused
523 * list for prune_dcache(). We descend to the next level
524 * whenever the d_subdirs list is non-empty and continue
525 * searching.
527 static int select_parent(struct dentry * parent)
529 struct dentry *this_parent = parent;
530 struct list_head *next;
531 int found = 0;
533 spin_lock(&dcache_lock);
534 repeat:
535 next = this_parent->d_subdirs.next;
536 resume:
537 while (next != &this_parent->d_subdirs) {
538 struct list_head *tmp = next;
539 struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
540 next = tmp->next;
542 if (!list_empty(&dentry->d_lru)) {
543 dentry_stat.nr_unused--;
544 list_del_init(&dentry->d_lru);
547 * move only zero ref count dentries to the end
548 * of the unused list for prune_dcache
550 if (!atomic_read(&dentry->d_count)) {
551 list_add(&dentry->d_lru, dentry_unused.prev);
552 dentry_stat.nr_unused++;
553 found++;
556 * Descend a level if the d_subdirs list is non-empty.
558 if (!list_empty(&dentry->d_subdirs)) {
559 this_parent = dentry;
560 #ifdef DCACHE_DEBUG
561 printk(KERN_DEBUG "select_parent: descending to %s/%s, found=%d\n",
562 dentry->d_parent->d_name.name, dentry->d_name.name, found);
563 #endif
564 goto repeat;
568 * All done at this level ... ascend and resume the search.
570 if (this_parent != parent) {
571 next = this_parent->d_child.next;
572 this_parent = this_parent->d_parent;
573 #ifdef DCACHE_DEBUG
574 printk(KERN_DEBUG "select_parent: ascending to %s/%s, found=%d\n",
575 this_parent->d_parent->d_name.name, this_parent->d_name.name, found);
576 #endif
577 goto resume;
579 spin_unlock(&dcache_lock);
580 return found;
584 * shrink_dcache_parent - prune dcache
585 * @parent: parent of entries to prune
587 * Prune the dcache to remove unused children of the parent dentry.
590 void shrink_dcache_parent(struct dentry * parent)
592 int found;
594 while ((found = select_parent(parent)) != 0)
595 prune_dcache(found);
599 * shrink_dcache_anon - further prune the cache
600 * @head: head of d_hash list of dentries to prune
602 * Prune the dentries that are anonymous
604 * parsing d_hash list does not read_barrier_depends() as it
605 * done under dcache_lock.
608 void shrink_dcache_anon(struct hlist_head *head)
610 struct hlist_node *lp;
611 int found;
612 do {
613 found = 0;
614 spin_lock(&dcache_lock);
615 hlist_for_each(lp, head) {
616 struct dentry *this = hlist_entry(lp, struct dentry, d_hash);
617 if (!list_empty(&this->d_lru)) {
618 dentry_stat.nr_unused--;
619 list_del(&this->d_lru);
623 * move only zero ref count dentries to the end
624 * of the unused list for prune_dcache
626 if (!atomic_read(&this->d_count)) {
627 list_add_tail(&this->d_lru, &dentry_unused);
628 dentry_stat.nr_unused++;
629 found++;
632 spin_unlock(&dcache_lock);
633 prune_dcache(found);
634 } while(found);
638 * This is called from kswapd when we think we need some more memory.
640 * We don't want the VM to steal _all_ unused dcache. Because that leads to
641 * the VM stealing all unused inodes, which shoots down recently-used
642 * pagecache. So what we do is to tell fibs to the VM about how many reapable
643 * objects there are in this cache. If the number of unused dentries is
644 * less than half of the total dentry count then return zero. The net effect
645 * is that the number of unused dentries will be, at a minimum, equal to the
646 * number of used ones.
648 * If unused_ratio is set to 5, the number of unused dentries will not fall
649 * below 5* the number of used ones.
651 static int shrink_dcache_memory(int nr, unsigned int gfp_mask)
653 int nr_used;
654 int nr_unused;
655 const int unused_ratio = 1;
657 if (nr) {
659 * Nasty deadlock avoidance.
661 * ext2_new_block->getblk->GFP->shrink_dcache_memory->
662 * prune_dcache->prune_one_dentry->dput->dentry_iput->iput->
663 * inode->i_sb->s_op->put_inode->ext2_discard_prealloc->
664 * ext2_free_blocks->lock_super->DEADLOCK.
666 * We should make sure we don't hold the superblock lock over
667 * block allocations, but for now:
669 if (gfp_mask & __GFP_FS)
670 prune_dcache(nr);
672 nr_unused = dentry_stat.nr_unused;
673 nr_used = dentry_stat.nr_dentry - nr_unused;
674 if (nr_unused < nr_used * unused_ratio)
675 return 0;
676 return nr_unused - nr_used * unused_ratio;
679 #define NAME_ALLOC_LEN(len) ((len+16) & ~15)
682 * d_alloc - allocate a dcache entry
683 * @parent: parent of entry to allocate
684 * @name: qstr of the name
686 * Allocates a dentry. It returns %NULL if there is insufficient memory
687 * available. On a success the dentry is returned. The name passed in is
688 * copied and the copy passed in may be reused after this call.
691 struct dentry * d_alloc(struct dentry * parent, const struct qstr *name)
693 char * str;
694 struct dentry *dentry;
695 struct qstr * qstr;
697 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
698 if (!dentry)
699 return NULL;
701 if (name->len > DNAME_INLINE_LEN-1) {
702 qstr = kmalloc(sizeof(*qstr) + NAME_ALLOC_LEN(name->len),
703 GFP_KERNEL);
704 if (!qstr) {
705 kmem_cache_free(dentry_cache, dentry);
706 return NULL;
708 qstr->name = qstr->name_str;
709 qstr->len = name->len;
710 qstr->hash = name->hash;
711 dentry->d_qstr = qstr;
712 str = qstr->name_str;
713 } else {
714 dentry->d_qstr = &dentry->d_name;
715 str = dentry->d_iname;
718 memcpy(str, name->name, name->len);
719 str[name->len] = 0;
721 atomic_set(&dentry->d_count, 1);
722 dentry->d_vfs_flags = DCACHE_UNHASHED;
723 dentry->d_lock = SPIN_LOCK_UNLOCKED;
724 dentry->d_flags = 0;
725 dentry->d_inode = NULL;
726 dentry->d_parent = NULL;
727 dentry->d_move_count = 0;
728 dentry->d_sb = NULL;
729 dentry->d_name.name = str;
730 dentry->d_name.len = name->len;
731 dentry->d_name.hash = name->hash;
732 dentry->d_op = NULL;
733 dentry->d_fsdata = NULL;
734 dentry->d_mounted = 0;
735 dentry->d_cookie = NULL;
736 dentry->d_bucket = NULL;
737 INIT_HLIST_NODE(&dentry->d_hash);
738 INIT_LIST_HEAD(&dentry->d_lru);
739 INIT_LIST_HEAD(&dentry->d_subdirs);
740 INIT_LIST_HEAD(&dentry->d_alias);
742 if (parent) {
743 dentry->d_parent = dget(parent);
744 dentry->d_sb = parent->d_sb;
745 } else {
746 INIT_LIST_HEAD(&dentry->d_child);
749 spin_lock(&dcache_lock);
750 if (parent)
751 list_add(&dentry->d_child, &parent->d_subdirs);
752 dentry_stat.nr_dentry++;
753 spin_unlock(&dcache_lock);
755 return dentry;
759 * d_instantiate - fill in inode information for a dentry
760 * @entry: dentry to complete
761 * @inode: inode to attach to this dentry
763 * Fill in inode information in the entry.
765 * This turns negative dentries into productive full members
766 * of society.
768 * NOTE! This assumes that the inode count has been incremented
769 * (or otherwise set) by the caller to indicate that it is now
770 * in use by the dcache.
773 void d_instantiate(struct dentry *entry, struct inode * inode)
775 if (!list_empty(&entry->d_alias)) BUG();
776 spin_lock(&dcache_lock);
777 if (inode)
778 list_add(&entry->d_alias, &inode->i_dentry);
779 entry->d_inode = inode;
780 spin_unlock(&dcache_lock);
781 security_d_instantiate(entry, inode);
785 * d_alloc_root - allocate root dentry
786 * @root_inode: inode to allocate the root for
788 * Allocate a root ("/") dentry for the inode given. The inode is
789 * instantiated and returned. %NULL is returned if there is insufficient
790 * memory or the inode passed is %NULL.
793 struct dentry * d_alloc_root(struct inode * root_inode)
795 struct dentry *res = NULL;
797 if (root_inode) {
798 static const struct qstr name = { .name = "/", .len = 1, .hash = 0 };
799 res = d_alloc(NULL, &name);
800 if (res) {
801 res->d_sb = root_inode->i_sb;
802 res->d_parent = res;
803 d_instantiate(res, root_inode);
806 return res;
809 static inline struct hlist_head * d_hash(struct dentry * parent, unsigned long hash)
811 hash += (unsigned long) parent / L1_CACHE_BYTES;
812 hash = hash ^ (hash >> D_HASHBITS);
813 return dentry_hashtable + (hash & D_HASHMASK);
817 * d_alloc_anon - allocate an anonymous dentry
818 * @inode: inode to allocate the dentry for
820 * This is similar to d_alloc_root. It is used by filesystems when
821 * creating a dentry for a given inode, often in the process of
822 * mapping a filehandle to a dentry. The returned dentry may be
823 * anonymous, or may have a full name (if the inode was already
824 * in the cache). The file system may need to make further
825 * efforts to connect this dentry into the dcache properly.
827 * When called on a directory inode, we must ensure that
828 * the inode only ever has one dentry. If a dentry is
829 * found, that is returned instead of allocating a new one.
831 * On successful return, the reference to the inode has been transferred
832 * to the dentry. If %NULL is returned (indicating kmalloc failure),
833 * the reference on the inode has not been released.
836 struct dentry * d_alloc_anon(struct inode *inode)
838 static const struct qstr anonstring = { "", 0, 0};
839 struct dentry *tmp;
840 struct dentry *res;
842 if ((res = d_find_alias(inode))) {
843 iput(inode);
844 return res;
847 tmp = d_alloc(NULL, &anonstring);
848 if (!tmp)
849 return NULL;
851 tmp->d_parent = tmp; /* make sure dput doesn't croak */
853 spin_lock(&dcache_lock);
854 if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry)) {
855 /* A directory can only have one dentry.
856 * This (now) has one, so use it.
858 res = list_entry(inode->i_dentry.next, struct dentry, d_alias);
859 __dget_locked(res);
860 } else {
861 /* attach a disconnected dentry */
862 res = tmp;
863 tmp = NULL;
864 if (res) {
865 spin_lock(&res->d_lock);
866 res->d_sb = inode->i_sb;
867 res->d_parent = res;
868 res->d_inode = inode;
869 res->d_bucket = d_hash(res, res->d_name.hash);
870 res->d_flags |= DCACHE_DISCONNECTED;
871 res->d_vfs_flags &= ~DCACHE_UNHASHED;
872 list_add(&res->d_alias, &inode->i_dentry);
873 hlist_add_head(&res->d_hash, &inode->i_sb->s_anon);
874 spin_unlock(&res->d_lock);
876 inode = NULL; /* don't drop reference */
878 spin_unlock(&dcache_lock);
880 if (inode)
881 iput(inode);
882 if (tmp)
883 dput(tmp);
884 return res;
889 * d_splice_alias - splice a disconnected dentry into the tree if one exists
890 * @inode: the inode which may have a disconnected dentry
891 * @dentry: a negative dentry which we want to point to the inode.
893 * If inode is a directory and has a 'disconnected' dentry (i.e. IS_ROOT and
894 * DCACHE_DISCONNECTED), then d_move that in place of the given dentry
895 * and return it, else simply d_add the inode to the dentry and return NULL.
897 * This is (will be) needed in the lookup routine of any filesystem that is exportable
898 * (via knfsd) so that we can build dcache paths to directories effectively.
900 * If a dentry was found and moved, then it is returned. Otherwise NULL
901 * is returned. This matches the expected return value of ->lookup.
904 struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
906 struct dentry *new = NULL;
908 if (inode && S_ISDIR(inode->i_mode)) {
909 spin_lock(&dcache_lock);
910 if (!list_empty(&inode->i_dentry)) {
911 new = list_entry(inode->i_dentry.next, struct dentry, d_alias);
912 __dget_locked(new);
913 spin_unlock(&dcache_lock);
914 security_d_instantiate(dentry, inode);
915 d_rehash(dentry);
916 d_move(new, dentry);
917 iput(inode);
918 } else {
919 /* d_instantiate takes dcache_lock, so we do it by hand */
920 list_add(&dentry->d_alias, &inode->i_dentry);
921 dentry->d_inode = inode;
922 spin_unlock(&dcache_lock);
923 security_d_instantiate(dentry, inode);
924 d_rehash(dentry);
926 } else
927 d_add(dentry, inode);
928 return new;
933 * d_lookup - search for a dentry
934 * @parent: parent dentry
935 * @name: qstr of name we wish to find
937 * Searches the children of the parent dentry for the name in question. If
938 * the dentry is found its reference count is incremented and the dentry
939 * is returned. The caller must use d_put to free the entry when it has
940 * finished using it. %NULL is returned on failure.
942 * __d_lookup is dcache_lock free. The hash list is protected using RCU.
943 * Memory barriers are used while updating and doing lockless traversal.
944 * To avoid races with d_move while rename is happening, d_move_count is
945 * used.
947 * Overflows in memcmp(), while d_move, are avoided by keeping the length
948 * and name pointer in one structure pointed by d_qstr.
950 * rcu_read_lock() and rcu_read_unlock() are used to disable preemption while
951 * lookup is going on.
953 * d_lru list is not updated, which can leave non-zero d_count dentries
954 * around in d_lru list.
956 * d_lookup() is protected against the concurrent renames in some unrelated
957 * directory using the seqlockt_t rename_lock.
960 struct dentry * d_lookup(struct dentry * parent, struct qstr * name)
962 struct dentry * dentry = NULL;
963 unsigned long seq;
965 do {
966 seq = read_seqbegin(&rename_lock);
967 dentry = __d_lookup(parent, name);
968 if (dentry)
969 break;
970 } while (read_seqretry(&rename_lock, seq));
971 return dentry;
974 struct dentry * __d_lookup(struct dentry * parent, struct qstr * name)
976 unsigned int len = name->len;
977 unsigned int hash = name->hash;
978 const unsigned char *str = name->name;
979 struct hlist_head *head = d_hash(parent,hash);
980 struct dentry *found = NULL;
981 struct hlist_node *node;
983 rcu_read_lock();
985 hlist_for_each (node, head) {
986 struct dentry *dentry;
987 unsigned long move_count;
988 struct qstr * qstr;
990 smp_read_barrier_depends();
991 dentry = hlist_entry(node, struct dentry, d_hash);
993 /* if lookup ends up in a different bucket
994 * due to concurrent rename, fail it
996 if (unlikely(dentry->d_bucket != head))
997 break;
1000 * We must take a snapshot of d_move_count followed by
1001 * read memory barrier before any search key comparison
1003 move_count = dentry->d_move_count;
1004 smp_rmb();
1006 if (dentry->d_name.hash != hash)
1007 continue;
1008 if (dentry->d_parent != parent)
1009 continue;
1011 qstr = dentry->d_qstr;
1012 smp_read_barrier_depends();
1013 if (parent->d_op && parent->d_op->d_compare) {
1014 if (parent->d_op->d_compare(parent, qstr, name))
1015 continue;
1016 } else {
1017 if (qstr->len != len)
1018 continue;
1019 if (memcmp(qstr->name, str, len))
1020 continue;
1022 spin_lock(&dentry->d_lock);
1024 * If dentry is moved, fail the lookup
1026 if (likely(move_count == dentry->d_move_count)) {
1027 if (!d_unhashed(dentry)) {
1028 atomic_inc(&dentry->d_count);
1029 found = dentry;
1032 spin_unlock(&dentry->d_lock);
1033 break;
1035 rcu_read_unlock();
1037 return found;
1041 * d_validate - verify dentry provided from insecure source
1042 * @dentry: The dentry alleged to be valid child of @dparent
1043 * @dparent: The parent dentry (known to be valid)
1044 * @hash: Hash of the dentry
1045 * @len: Length of the name
1047 * An insecure source has sent us a dentry, here we verify it and dget() it.
1048 * This is used by ncpfs in its readdir implementation.
1049 * Zero is returned in the dentry is invalid.
1052 int d_validate(struct dentry *dentry, struct dentry *dparent)
1054 unsigned long dent_addr = (unsigned long) dentry;
1055 unsigned long min_addr = PAGE_OFFSET;
1056 unsigned long align_mask = 0x0F;
1057 struct hlist_head *base;
1058 struct hlist_node *lhp;
1060 if (dent_addr < min_addr)
1061 goto out;
1062 if (dent_addr > (unsigned long)high_memory - sizeof(struct dentry))
1063 goto out;
1064 if (dent_addr & align_mask)
1065 goto out;
1066 if ((!kern_addr_valid(dent_addr)) || (!kern_addr_valid(dent_addr -1 +
1067 sizeof(struct dentry))))
1068 goto out;
1070 if (dentry->d_parent != dparent)
1071 goto out;
1073 spin_lock(&dcache_lock);
1074 base = d_hash(dparent, dentry->d_name.hash);
1075 hlist_for_each(lhp,base) {
1076 /* read_barrier_depends() not required for d_hash list
1077 * as it is parsed under dcache_lock
1079 if (dentry == hlist_entry(lhp, struct dentry, d_hash)) {
1080 __dget_locked(dentry);
1081 spin_unlock(&dcache_lock);
1082 return 1;
1085 spin_unlock(&dcache_lock);
1086 out:
1087 return 0;
1091 * When a file is deleted, we have two options:
1092 * - turn this dentry into a negative dentry
1093 * - unhash this dentry and free it.
1095 * Usually, we want to just turn this into
1096 * a negative dentry, but if anybody else is
1097 * currently using the dentry or the inode
1098 * we can't do that and we fall back on removing
1099 * it from the hash queues and waiting for
1100 * it to be deleted later when it has no users
1104 * d_delete - delete a dentry
1105 * @dentry: The dentry to delete
1107 * Turn the dentry into a negative dentry if possible, otherwise
1108 * remove it from the hash queues so it can be deleted later
1111 void d_delete(struct dentry * dentry)
1114 * Are we the only user?
1116 spin_lock(&dcache_lock);
1117 spin_lock(&dentry->d_lock);
1118 if (atomic_read(&dentry->d_count) == 1) {
1119 spin_unlock(&dentry->d_lock);
1120 dentry_iput(dentry);
1121 return;
1124 if (!d_unhashed(dentry))
1125 __d_drop(dentry);
1127 spin_unlock(&dentry->d_lock);
1128 spin_unlock(&dcache_lock);
1132 * d_rehash - add an entry back to the hash
1133 * @entry: dentry to add to the hash
1135 * Adds a dentry to the hash according to its name.
1138 void d_rehash(struct dentry * entry)
1140 struct hlist_head *list = d_hash(entry->d_parent, entry->d_name.hash);
1141 spin_lock(&dcache_lock);
1142 entry->d_vfs_flags &= ~DCACHE_UNHASHED;
1143 entry->d_bucket = list;
1144 hlist_add_head_rcu(&entry->d_hash, list);
1145 spin_unlock(&dcache_lock);
1148 #define do_switch(x,y) do { \
1149 __typeof__ (x) __tmp = x; \
1150 x = y; y = __tmp; } while (0)
1153 * When switching names, the actual string doesn't strictly have to
1154 * be preserved in the target - because we're dropping the target
1155 * anyway. As such, we can just do a simple memcpy() to copy over
1156 * the new name before we switch.
1158 * Note that we have to be a lot more careful about getting the hash
1159 * switched - we have to switch the hash value properly even if it
1160 * then no longer matches the actual (corrupted) string of the target.
1161 * The hash value has to match the hash queue that the dentry is on..
1163 static inline void switch_names(struct dentry * dentry, struct dentry * target)
1165 const unsigned char *old_name, *new_name;
1166 struct qstr *old_qstr, *new_qstr;
1168 memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
1169 old_qstr = target->d_qstr;
1170 old_name = target->d_name.name;
1171 new_qstr = dentry->d_qstr;
1172 new_name = dentry->d_name.name;
1173 if (old_name == target->d_iname) {
1174 old_name = dentry->d_iname;
1175 old_qstr = &dentry->d_name;
1177 if (new_name == dentry->d_iname) {
1178 new_name = target->d_iname;
1179 new_qstr = &target->d_name;
1181 target->d_name.name = new_name;
1182 dentry->d_name.name = old_name;
1183 target->d_qstr = new_qstr;
1184 dentry->d_qstr = old_qstr;
1188 * We cannibalize "target" when moving dentry on top of it,
1189 * because it's going to be thrown away anyway. We could be more
1190 * polite about it, though.
1192 * This forceful removal will result in ugly /proc output if
1193 * somebody holds a file open that got deleted due to a rename.
1194 * We could be nicer about the deleted file, and let it show
1195 * up under the name it got deleted rather than the name that
1196 * deleted it.
1200 * d_move - move a dentry
1201 * @dentry: entry to move
1202 * @target: new dentry
1204 * Update the dcache to reflect the move of a file name. Negative
1205 * dcache entries should not be moved in this way.
1208 void d_move(struct dentry * dentry, struct dentry * target)
1210 if (!dentry->d_inode)
1211 printk(KERN_WARNING "VFS: moving negative dcache entry\n");
1213 spin_lock(&dcache_lock);
1214 write_seqlock(&rename_lock);
1216 * XXXX: do we really need to take target->d_lock?
1218 if (target < dentry) {
1219 spin_lock(&target->d_lock);
1220 spin_lock(&dentry->d_lock);
1221 } else {
1222 spin_lock(&dentry->d_lock);
1223 spin_lock(&target->d_lock);
1226 /* Move the dentry to the target hash queue, if on different bucket */
1227 if (dentry->d_vfs_flags & DCACHE_UNHASHED)
1228 goto already_unhashed;
1229 if (dentry->d_bucket != target->d_bucket) {
1230 hlist_del_rcu(&dentry->d_hash);
1231 already_unhashed:
1232 dentry->d_bucket = target->d_bucket;
1233 hlist_add_head_rcu(&dentry->d_hash, target->d_bucket);
1234 dentry->d_vfs_flags &= ~DCACHE_UNHASHED;
1237 /* Unhash the target: dput() will then get rid of it */
1238 __d_drop(target);
1240 list_del(&dentry->d_child);
1241 list_del(&target->d_child);
1243 /* Switch the names.. */
1244 switch_names(dentry, target);
1245 smp_wmb();
1246 do_switch(dentry->d_name.len, target->d_name.len);
1247 do_switch(dentry->d_name.hash, target->d_name.hash);
1249 /* ... and switch the parents */
1250 if (IS_ROOT(dentry)) {
1251 dentry->d_parent = target->d_parent;
1252 target->d_parent = target;
1253 INIT_LIST_HEAD(&target->d_child);
1254 } else {
1255 do_switch(dentry->d_parent, target->d_parent);
1257 /* And add them back to the (new) parent lists */
1258 list_add(&target->d_child, &target->d_parent->d_subdirs);
1261 list_add(&dentry->d_child, &dentry->d_parent->d_subdirs);
1262 dentry->d_move_count++;
1263 spin_unlock(&target->d_lock);
1264 spin_unlock(&dentry->d_lock);
1265 write_sequnlock(&rename_lock);
1266 spin_unlock(&dcache_lock);
1270 * d_path - return the path of a dentry
1271 * @dentry: dentry to report
1272 * @vfsmnt: vfsmnt to which the dentry belongs
1273 * @root: root dentry
1274 * @rootmnt: vfsmnt to which the root dentry belongs
1275 * @buffer: buffer to return value in
1276 * @buflen: buffer length
1278 * Convert a dentry into an ASCII path name. If the entry has been deleted
1279 * the string " (deleted)" is appended. Note that this is ambiguous.
1281 * Returns the buffer or an error code if the path was too long.
1283 * "buflen" should be positive. Caller holds the dcache_lock.
1285 static char * __d_path( struct dentry *dentry, struct vfsmount *vfsmnt,
1286 struct dentry *root, struct vfsmount *rootmnt,
1287 char *buffer, int buflen)
1289 char * end = buffer+buflen;
1290 char * retval;
1291 int namelen;
1293 *--end = '\0';
1294 buflen--;
1295 if (!IS_ROOT(dentry) && d_unhashed(dentry)) {
1296 buflen -= 10;
1297 end -= 10;
1298 if (buflen < 0)
1299 goto Elong;
1300 memcpy(end, " (deleted)", 10);
1303 if (buflen < 1)
1304 goto Elong;
1305 /* Get '/' right */
1306 retval = end-1;
1307 *retval = '/';
1309 for (;;) {
1310 struct dentry * parent;
1312 if (dentry == root && vfsmnt == rootmnt)
1313 break;
1314 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
1315 /* Global root? */
1316 if (vfsmnt->mnt_parent == vfsmnt)
1317 goto global_root;
1318 dentry = vfsmnt->mnt_mountpoint;
1319 vfsmnt = vfsmnt->mnt_parent;
1320 continue;
1322 parent = dentry->d_parent;
1323 prefetch(parent);
1324 namelen = dentry->d_name.len;
1325 buflen -= namelen + 1;
1326 if (buflen < 0)
1327 goto Elong;
1328 end -= namelen;
1329 memcpy(end, dentry->d_name.name, namelen);
1330 *--end = '/';
1331 retval = end;
1332 dentry = parent;
1335 return retval;
1337 global_root:
1338 namelen = dentry->d_name.len;
1339 buflen -= namelen;
1340 if (buflen < 0)
1341 goto Elong;
1342 retval -= namelen-1; /* hit the slash */
1343 memcpy(retval, dentry->d_name.name, namelen);
1344 return retval;
1345 Elong:
1346 return ERR_PTR(-ENAMETOOLONG);
1349 /* write full pathname into buffer and return start of pathname */
1350 char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
1351 char *buf, int buflen)
1353 char *res;
1354 struct vfsmount *rootmnt;
1355 struct dentry *root;
1356 read_lock(&current->fs->lock);
1357 rootmnt = mntget(current->fs->rootmnt);
1358 root = dget(current->fs->root);
1359 read_unlock(&current->fs->lock);
1360 spin_lock(&dcache_lock);
1361 res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
1362 spin_unlock(&dcache_lock);
1363 dput(root);
1364 mntput(rootmnt);
1365 return res;
1369 * NOTE! The user-level library version returns a
1370 * character pointer. The kernel system call just
1371 * returns the length of the buffer filled (which
1372 * includes the ending '\0' character), or a negative
1373 * error value. So libc would do something like
1375 * char *getcwd(char * buf, size_t size)
1377 * int retval;
1379 * retval = sys_getcwd(buf, size);
1380 * if (retval >= 0)
1381 * return buf;
1382 * errno = -retval;
1383 * return NULL;
1386 asmlinkage long sys_getcwd(char __user *buf, unsigned long size)
1388 int error;
1389 struct vfsmount *pwdmnt, *rootmnt;
1390 struct dentry *pwd, *root;
1391 char *page = (char *) __get_free_page(GFP_USER);
1393 if (!page)
1394 return -ENOMEM;
1396 read_lock(&current->fs->lock);
1397 pwdmnt = mntget(current->fs->pwdmnt);
1398 pwd = dget(current->fs->pwd);
1399 rootmnt = mntget(current->fs->rootmnt);
1400 root = dget(current->fs->root);
1401 read_unlock(&current->fs->lock);
1403 error = -ENOENT;
1404 /* Has the current directory has been unlinked? */
1405 spin_lock(&dcache_lock);
1406 if (pwd->d_parent == pwd || !d_unhashed(pwd)) {
1407 unsigned long len;
1408 char * cwd;
1410 cwd = __d_path(pwd, pwdmnt, root, rootmnt, page, PAGE_SIZE);
1411 spin_unlock(&dcache_lock);
1413 error = PTR_ERR(cwd);
1414 if (IS_ERR(cwd))
1415 goto out;
1417 error = -ERANGE;
1418 len = PAGE_SIZE + page - cwd;
1419 if (len <= size) {
1420 error = len;
1421 if (copy_to_user(buf, cwd, len))
1422 error = -EFAULT;
1424 } else
1425 spin_unlock(&dcache_lock);
1427 out:
1428 dput(pwd);
1429 mntput(pwdmnt);
1430 dput(root);
1431 mntput(rootmnt);
1432 free_page((unsigned long) page);
1433 return error;
1437 * Test whether new_dentry is a subdirectory of old_dentry.
1439 * Trivially implemented using the dcache structure
1443 * is_subdir - is new dentry a subdirectory of old_dentry
1444 * @new_dentry: new dentry
1445 * @old_dentry: old dentry
1447 * Returns 1 if new_dentry is a subdirectory of the parent (at any depth).
1448 * Returns 0 otherwise.
1451 int is_subdir(struct dentry * new_dentry, struct dentry * old_dentry)
1453 int result;
1454 unsigned long seq;
1456 result = 0;
1457 do {
1458 seq = read_seqbegin(&rename_lock);
1459 for (;;) {
1460 if (new_dentry != old_dentry) {
1461 struct dentry * parent = new_dentry->d_parent;
1462 if (parent == new_dentry)
1463 break;
1464 new_dentry = parent;
1465 continue;
1467 result = 1;
1468 break;
1470 } while (read_seqretry(&rename_lock, seq));
1472 return result;
1475 void d_genocide(struct dentry *root)
1477 struct dentry *this_parent = root;
1478 struct list_head *next;
1480 spin_lock(&dcache_lock);
1481 repeat:
1482 next = this_parent->d_subdirs.next;
1483 resume:
1484 while (next != &this_parent->d_subdirs) {
1485 struct list_head *tmp = next;
1486 struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
1487 next = tmp->next;
1488 if (d_unhashed(dentry)||!dentry->d_inode)
1489 continue;
1490 if (!list_empty(&dentry->d_subdirs)) {
1491 this_parent = dentry;
1492 goto repeat;
1494 atomic_dec(&dentry->d_count);
1496 if (this_parent != root) {
1497 next = this_parent->d_child.next;
1498 atomic_dec(&this_parent->d_count);
1499 this_parent = this_parent->d_parent;
1500 goto resume;
1502 spin_unlock(&dcache_lock);
1506 * find_inode_number - check for dentry with name
1507 * @dir: directory to check
1508 * @name: Name to find.
1510 * Check whether a dentry already exists for the given name,
1511 * and return the inode number if it has an inode. Otherwise
1512 * 0 is returned.
1514 * This routine is used to post-process directory listings for
1515 * filesystems using synthetic inode numbers, and is necessary
1516 * to keep getcwd() working.
1519 ino_t find_inode_number(struct dentry *dir, struct qstr *name)
1521 struct dentry * dentry;
1522 ino_t ino = 0;
1525 * Check for a fs-specific hash function. Note that we must
1526 * calculate the standard hash first, as the d_op->d_hash()
1527 * routine may choose to leave the hash value unchanged.
1529 name->hash = full_name_hash(name->name, name->len);
1530 if (dir->d_op && dir->d_op->d_hash)
1532 if (dir->d_op->d_hash(dir, name) != 0)
1533 goto out;
1536 dentry = d_lookup(dir, name);
1537 if (dentry)
1539 if (dentry->d_inode)
1540 ino = dentry->d_inode->i_ino;
1541 dput(dentry);
1543 out:
1544 return ino;
1547 static void __init dcache_init(unsigned long mempages)
1549 struct hlist_head *d;
1550 unsigned long order;
1551 unsigned int nr_hash;
1552 int i;
1555 * A constructor could be added for stable state like the lists,
1556 * but it is probably not worth it because of the cache nature
1557 * of the dcache.
1558 * If fragmentation is too bad then the SLAB_HWCACHE_ALIGN
1559 * flag could be removed here, to hint to the allocator that
1560 * it should not try to get multiple page regions.
1562 dentry_cache = kmem_cache_create("dentry_cache",
1563 sizeof(struct dentry),
1565 SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1566 NULL, NULL);
1567 if (!dentry_cache)
1568 panic("Cannot create dentry cache");
1570 set_shrinker(DEFAULT_SEEKS, shrink_dcache_memory);
1572 #if PAGE_SHIFT < 13
1573 mempages >>= (13 - PAGE_SHIFT);
1574 #endif
1575 mempages *= sizeof(struct hlist_head);
1576 for (order = 0; ((1UL << order) << PAGE_SHIFT) < mempages; order++)
1579 do {
1580 unsigned long tmp;
1582 nr_hash = (1UL << order) * PAGE_SIZE /
1583 sizeof(struct hlist_head);
1584 d_hash_mask = (nr_hash - 1);
1586 tmp = nr_hash;
1587 d_hash_shift = 0;
1588 while ((tmp >>= 1UL) != 0UL)
1589 d_hash_shift++;
1591 dentry_hashtable = (struct hlist_head *)
1592 __get_free_pages(GFP_ATOMIC, order);
1593 } while (dentry_hashtable == NULL && --order >= 0);
1595 printk(KERN_INFO "Dentry cache hash table entries: %d (order: %ld, %ld bytes)\n",
1596 nr_hash, order, (PAGE_SIZE << order));
1598 if (!dentry_hashtable)
1599 panic("Failed to allocate dcache hash table\n");
1601 d = dentry_hashtable;
1602 i = nr_hash;
1603 do {
1604 INIT_HLIST_HEAD(d);
1605 d++;
1606 i--;
1607 } while (i);
1610 /* SLAB cache for __getname() consumers */
1611 kmem_cache_t *names_cachep;
1613 /* SLAB cache for file structures */
1614 kmem_cache_t *filp_cachep;
1616 EXPORT_SYMBOL(d_genocide);
1618 extern void bdev_cache_init(void);
1619 extern void chrdev_init(void);
1621 void __init vfs_caches_init(unsigned long mempages)
1623 names_cachep = kmem_cache_create("names_cache",
1624 PATH_MAX, 0,
1625 SLAB_HWCACHE_ALIGN, NULL, NULL);
1626 if (!names_cachep)
1627 panic("Cannot create names SLAB cache");
1629 filp_cachep = kmem_cache_create("filp",
1630 sizeof(struct file), 0,
1631 SLAB_HWCACHE_ALIGN, filp_ctor, filp_dtor);
1632 if(!filp_cachep)
1633 panic("Cannot create filp SLAB cache");
1635 dcache_init(mempages);
1636 inode_init(mempages);
1637 files_init(mempages);
1638 mnt_init(mempages);
1639 bdev_cache_init();
1640 chrdev_init();