4 * (C) Copyright Al Viro 2000, 2001
5 * Released under GPL v2.
7 * Based on code from fs/super.c, copyright Linus Torvalds and others.
11 #include <linux/config.h>
12 #include <linux/slab.h>
13 #include <linux/smp_lock.h>
14 #include <linux/init.h>
15 #include <linux/quotaops.h>
16 #include <linux/acct.h>
17 #include <linux/module.h>
19 #include <asm/uaccess.h>
21 #include <linux/seq_file.h>
22 #include <linux/namespace.h>
24 struct vfsmount *do_kern_mount(const char *type, int flags, char *name, void *data);
25 int do_remount_sb(struct super_block *sb, int flags, void * data);
26 void kill_super(struct super_block *sb);
27 extern int __init init_rootfs(void);
29 static struct list_head *mount_hashtable;
30 static int hash_mask, hash_bits;
31 static kmem_cache_t *mnt_cache;
33 static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
35 unsigned long tmp = ((unsigned long) mnt / L1_CACHE_BYTES);
36 tmp += ((unsigned long) dentry / L1_CACHE_BYTES);
37 tmp = tmp + (tmp >> hash_bits);
38 return tmp & hash_mask;
41 struct vfsmount *alloc_vfsmnt(char *name)
43 struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL);
45 memset(mnt, 0, sizeof(struct vfsmount));
46 atomic_set(&mnt->mnt_count,1);
47 INIT_LIST_HEAD(&mnt->mnt_hash);
48 INIT_LIST_HEAD(&mnt->mnt_child);
49 INIT_LIST_HEAD(&mnt->mnt_mounts);
50 INIT_LIST_HEAD(&mnt->mnt_list);
52 int size = strlen(name)+1;
53 char * newname = kmalloc(size, GFP_KERNEL);
55 memcpy(newname, name, size);
56 mnt->mnt_devname = newname;
63 void free_vfsmnt(struct vfsmount *mnt)
66 kfree(mnt->mnt_devname);
67 kmem_cache_free(mnt_cache, mnt);
70 struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
72 struct list_head * head = mount_hashtable + hash(mnt, dentry);
73 struct list_head * tmp = head;
81 p = list_entry(tmp, struct vfsmount, mnt_hash);
82 if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry)
88 static int check_mnt(struct vfsmount *mnt)
90 spin_lock(&dcache_lock);
91 while (mnt->mnt_parent != mnt)
92 mnt = mnt->mnt_parent;
93 spin_unlock(&dcache_lock);
94 return mnt == current->namespace->root;
97 static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd)
99 old_nd->dentry = mnt->mnt_mountpoint;
100 old_nd->mnt = mnt->mnt_parent;
101 mnt->mnt_parent = mnt;
102 mnt->mnt_mountpoint = mnt->mnt_root;
103 list_del_init(&mnt->mnt_child);
104 list_del_init(&mnt->mnt_hash);
105 old_nd->dentry->d_mounted--;
108 static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd)
110 mnt->mnt_parent = mntget(nd->mnt);
111 mnt->mnt_mountpoint = dget(nd->dentry);
112 list_add(&mnt->mnt_hash, mount_hashtable+hash(nd->mnt, nd->dentry));
113 list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts);
114 nd->dentry->d_mounted++;
117 static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
119 struct list_head *next = p->mnt_mounts.next;
120 if (next == &p->mnt_mounts) {
124 next = p->mnt_child.next;
125 if (next != &p->mnt_parent->mnt_mounts)
130 return list_entry(next, struct vfsmount, mnt_child);
133 static struct vfsmount *
134 clone_mnt(struct vfsmount *old, struct dentry *root)
136 struct super_block *sb = old->mnt_sb;
137 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
140 mnt->mnt_flags = old->mnt_flags;
141 atomic_inc(&sb->s_active);
143 mnt->mnt_root = dget(root);
144 mnt->mnt_mountpoint = mnt->mnt_root;
145 mnt->mnt_parent = mnt;
150 void __mntput(struct vfsmount *mnt)
152 struct super_block *sb = mnt->mnt_sb;
159 static void *m_start(struct seq_file *m, loff_t *pos)
161 struct namespace *n = m->private;
166 list_for_each(p, &n->list)
168 return list_entry(p, struct vfsmount, mnt_list);
172 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
174 struct namespace *n = m->private;
175 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next;
177 return p==&n->list ? NULL : list_entry(p, struct vfsmount, mnt_list);
180 static void m_stop(struct seq_file *m, void *v)
182 struct namespace *n = m->private;
186 static inline void mangle(struct seq_file *m, const char *s)
188 seq_escape(m, s, " \t\n\\");
191 static int show_vfsmnt(struct seq_file *m, void *v)
193 struct vfsmount *mnt = v;
195 static struct proc_fs_info {
199 { MS_SYNCHRONOUS, ",sync" },
200 { MS_MANDLOCK, ",mand" },
201 { MS_NOATIME, ",noatime" },
202 { MS_NODIRATIME, ",nodiratime" },
205 static struct proc_fs_info mnt_info[] = {
206 { MNT_NOSUID, ",nosuid" },
207 { MNT_NODEV, ",nodev" },
208 { MNT_NOEXEC, ",noexec" },
211 struct proc_fs_info *fs_infop;
212 char *path_buf, *path;
214 path_buf = (char *) __get_free_page(GFP_KERNEL);
217 path = d_path(mnt->mnt_root, mnt, path_buf, PAGE_SIZE);
219 free_page((unsigned long) path_buf);
220 return PTR_ERR(path);
223 mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
226 free_page((unsigned long) path_buf);
228 mangle(m, mnt->mnt_sb->s_type->name);
229 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
230 for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
231 if (mnt->mnt_sb->s_flags & fs_infop->flag)
232 seq_puts(m, fs_infop->str);
234 for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
235 if (mnt->mnt_flags & fs_infop->flag)
236 seq_puts(m, fs_infop->str);
238 if (mnt->mnt_sb->s_op->show_options)
239 err = mnt->mnt_sb->s_op->show_options(m, mnt);
240 seq_puts(m, " 0 0\n");
244 struct seq_operations mounts_op = {
252 * Doesn't take quota and stuff into account. IOW, in some cases it will
253 * give false negatives. The main reason why it's here is that we need
254 * a non-destructive way to look for easily umountable filesystems.
256 int may_umount(struct vfsmount *mnt)
258 if (atomic_read(&mnt->mnt_count) > 2)
263 void umount_tree(struct vfsmount *mnt)
268 for (p = mnt; p; p = next_mnt(p, mnt)) {
269 list_del(&p->mnt_list);
270 list_add(&p->mnt_list, &kill);
273 while (!list_empty(&kill)) {
274 mnt = list_entry(kill.next, struct vfsmount, mnt_list);
275 list_del_init(&mnt->mnt_list);
276 if (mnt->mnt_parent == mnt) {
277 spin_unlock(&dcache_lock);
279 struct nameidata old_nd;
280 detach_mnt(mnt, &old_nd);
281 spin_unlock(&dcache_lock);
282 path_release(&old_nd);
285 spin_lock(&dcache_lock);
289 static int do_umount(struct vfsmount *mnt, int flags)
291 struct super_block * sb = mnt->mnt_sb;
295 * If we may have to abort operations to get out of this
296 * mount, and they will themselves hold resources we must
297 * allow the fs to do things. In the Unix tradition of
298 * 'Gee thats tricky lets do it in userspace' the umount_begin
299 * might fail to complete on the first run through as other tasks
300 * must return, and the like. Thats for the mount program to worry
301 * about for the moment.
305 if( (flags&MNT_FORCE) && sb->s_op->umount_begin)
306 sb->s_op->umount_begin(sb);
310 * No sense to grab the lock for this test, but test itself looks
311 * somewhat bogus. Suggestions for better replacement?
312 * Ho-hum... In principle, we might treat that as umount + switch
313 * to rootfs. GC would eventually take care of the old vfsmount.
314 * Actually it makes sense, especially if rootfs would contain a
315 * /reboot - static binary that would close all descriptors and
316 * call reboot(9). Then init(8) could umount root and exec /reboot.
318 if (mnt == current->fs->rootmnt && !(flags & MNT_DETACH)) {
320 * Special case for "unmounting" root ...
321 * we just try to remount it readonly.
323 down_write(&sb->s_umount);
324 if (!(sb->s_flags & MS_RDONLY)) {
326 retval = do_remount_sb(sb, MS_RDONLY, 0);
329 up_write(&sb->s_umount);
333 down_write(¤t->namespace->sem);
334 spin_lock(&dcache_lock);
336 if (atomic_read(&sb->s_active) == 1) {
337 /* last instance - try to be smart */
338 spin_unlock(&dcache_lock);
341 acct_auto_close(sb->s_dev);
343 spin_lock(&dcache_lock);
346 if (atomic_read(&mnt->mnt_count) == 2 || flags & MNT_DETACH) {
347 if (!list_empty(&mnt->mnt_list))
351 spin_unlock(&dcache_lock);
352 up_write(¤t->namespace->sem);
357 * Now umount can handle mount points as well as block devices.
358 * This is important for filesystems which use unnamed block devices.
360 * We now support a flag for forced unmount like the other 'big iron'
361 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
364 asmlinkage long sys_umount(char * name, int flags)
369 retval = __user_walk(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd);
373 if (nd.dentry != nd.mnt->mnt_root)
375 if (!check_mnt(nd.mnt))
379 if (!capable(CAP_SYS_ADMIN))
382 retval = do_umount(nd.mnt, flags);
390 * The 2.0 compatible umount. No flags.
393 asmlinkage long sys_oldumount(char * name)
395 return sys_umount(name,0);
398 static int mount_is_safe(struct nameidata *nd)
400 if (capable(CAP_SYS_ADMIN))
404 if (S_ISLNK(nd->dentry->d_inode->i_mode))
406 if (nd->dentry->d_inode->i_mode & S_ISVTX) {
407 if (current->uid != nd->dentry->d_inode->i_uid)
410 if (permission(nd->dentry->d_inode, MAY_WRITE))
416 static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
418 struct vfsmount *p, *next, *q, *res;
422 res = nd.mnt = q = clone_mnt(p, dentry);
426 q->mnt_mountpoint = p->mnt_mountpoint;
428 while ( (next = next_mnt(p, mnt)) != NULL) {
429 while (p != next->mnt_parent) {
435 nd.dentry = p->mnt_mountpoint;
436 q = clone_mnt(p, p->mnt_root);
439 spin_lock(&dcache_lock);
440 list_add_tail(&q->mnt_list, &res->mnt_list);
442 spin_unlock(&dcache_lock);
447 spin_lock(&dcache_lock);
449 spin_unlock(&dcache_lock);
454 static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
457 if (mnt->mnt_sb->s_flags & MS_NOUSER)
460 if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
461 S_ISDIR(mnt->mnt_root->d_inode->i_mode))
465 down(&nd->dentry->d_inode->i_zombie);
466 if (IS_DEADDIR(nd->dentry->d_inode))
469 spin_lock(&dcache_lock);
470 if (IS_ROOT(nd->dentry) || !d_unhashed(nd->dentry)) {
471 struct list_head head;
473 list_add_tail(&head, &mnt->mnt_list);
474 list_splice(&head, current->namespace->list.prev);
478 spin_unlock(&dcache_lock);
480 up(&nd->dentry->d_inode->i_zombie);
487 static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
489 struct nameidata old_nd;
490 struct vfsmount *mnt = NULL;
491 int err = mount_is_safe(nd);
494 if (!old_name || !*old_name)
496 err = path_lookup(old_name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &old_nd);
500 down_write(¤t->namespace->sem);
502 if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
505 mnt = copy_tree(old_nd.mnt, old_nd.dentry);
507 mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
511 err = graft_tree(mnt, nd);
513 spin_lock(&dcache_lock);
515 spin_unlock(&dcache_lock);
520 up_write(¤t->namespace->sem);
521 path_release(&old_nd);
526 * change filesystem flags. dir should be a physical root of filesystem.
527 * If you've mounted a non-root directory somewhere and want to do remount
528 * on it - tough luck.
531 static int do_remount(struct nameidata *nd,int flags,int mnt_flags,void *data)
534 struct super_block * sb = nd->mnt->mnt_sb;
536 if (!capable(CAP_SYS_ADMIN))
539 if (!check_mnt(nd->mnt))
542 if (nd->dentry != nd->mnt->mnt_root)
545 down_write(&sb->s_umount);
546 err = do_remount_sb(sb, flags, data);
548 nd->mnt->mnt_flags=mnt_flags;
549 up_write(&sb->s_umount);
553 static int do_move_mount(struct nameidata *nd, char *old_name)
555 struct nameidata old_nd, parent_nd;
558 if (!capable(CAP_SYS_ADMIN))
560 if (!old_name || !*old_name)
562 err = path_lookup(old_name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &old_nd);
566 down_write(¤t->namespace->sem);
567 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
570 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
574 down(&nd->dentry->d_inode->i_zombie);
575 if (IS_DEADDIR(nd->dentry->d_inode))
578 spin_lock(&dcache_lock);
579 if (!IS_ROOT(nd->dentry) && d_unhashed(nd->dentry))
583 if (old_nd.dentry != old_nd.mnt->mnt_root)
586 if (old_nd.mnt == old_nd.mnt->mnt_parent)
589 if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
590 S_ISDIR(old_nd.dentry->d_inode->i_mode))
594 for (p = nd->mnt; p->mnt_parent!=p; p = p->mnt_parent)
599 detach_mnt(old_nd.mnt, &parent_nd);
600 attach_mnt(old_nd.mnt, nd);
602 spin_unlock(&dcache_lock);
604 up(&nd->dentry->d_inode->i_zombie);
606 up_write(¤t->namespace->sem);
608 path_release(&parent_nd);
609 path_release(&old_nd);
613 static int do_add_mount(struct nameidata *nd, char *type, int flags,
614 int mnt_flags, char *name, void *data)
616 struct vfsmount *mnt;
619 if (!type || !memchr(type, 0, PAGE_SIZE))
622 /* we need capabilities... */
623 if (!capable(CAP_SYS_ADMIN))
626 mnt = do_kern_mount(type, flags, name, data);
631 down_write(¤t->namespace->sem);
632 /* Something was mounted here while we slept */
633 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
636 if (!check_mnt(nd->mnt))
639 /* Refuse the same filesystem on the same mount point */
641 if (nd->mnt->mnt_sb == mnt->mnt_sb && nd->mnt->mnt_root == nd->dentry)
644 mnt->mnt_flags = mnt_flags;
645 err = graft_tree(mnt, nd);
647 up_write(¤t->namespace->sem);
653 static int copy_mount_options (const void *data, unsigned long *where)
663 if (!(page = __get_free_page(GFP_KERNEL)))
666 /* We only care that *some* data at the address the user
667 * gave us is valid. Just in case, we'll zero
668 * the remainder of the page.
670 /* copy_from_user cannot cross TASK_SIZE ! */
671 size = TASK_SIZE - (unsigned long)data;
672 if (size > PAGE_SIZE)
675 i = size - copy_from_user((void *)page, data, size);
681 memset((char *)page + i, 0, PAGE_SIZE - i);
687 * Flags is a 32-bit value that allows up to 31 non-fs dependent flags to
688 * be given to the mount() call (ie: read-only, no-dev, no-suid etc).
690 * data is a (void *) that can point to any structure up to
691 * PAGE_SIZE-1 bytes, which can contain arbitrary fs-dependent
692 * information (or be NULL).
694 * Pre-0.97 versions of mount() didn't have a flags word.
695 * When the flags word was introduced its top half was required
696 * to have the magic value 0xC0ED, and this remained so until 2.4.0-test9.
697 * Therefore, if this magic number is present, it carries no information
698 * and must be discarded.
700 long do_mount(char * dev_name, char * dir_name, char *type_page,
701 unsigned long flags, void *data_page)
708 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
709 flags &= ~MS_MGC_MSK;
711 /* Basic sanity checks */
713 if (!dir_name || !*dir_name || !memchr(dir_name, 0, PAGE_SIZE))
715 if (dev_name && !memchr(dev_name, 0, PAGE_SIZE))
719 ((char *)data_page)[PAGE_SIZE - 1] = 0;
721 /* Separate the per-mountpoint flags */
722 if (flags & MS_NOSUID)
723 mnt_flags |= MNT_NOSUID;
724 if (flags & MS_NODEV)
725 mnt_flags |= MNT_NODEV;
726 if (flags & MS_NOEXEC)
727 mnt_flags |= MNT_NOEXEC;
728 flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV);
730 /* ... and get the mountpoint */
731 retval = path_lookup(dir_name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd);
735 if (flags & MS_REMOUNT)
736 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
738 else if (flags & MS_BIND)
739 retval = do_loopback(&nd, dev_name, flags & MS_REC);
740 else if (flags & MS_MOVE)
741 retval = do_move_mount(&nd, dev_name);
743 retval = do_add_mount(&nd, type_page, flags, mnt_flags,
744 dev_name, data_page);
749 int copy_namespace(int flags, struct task_struct *tsk)
751 struct namespace *namespace = tsk->namespace;
752 struct namespace *new_ns;
753 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
754 struct fs_struct *fs = tsk->fs;
759 get_namespace(namespace);
761 if (! (flags & CLONE_NEWNS))
764 if (!capable(CAP_SYS_ADMIN)) {
765 put_namespace(namespace);
769 new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
773 atomic_set(&new_ns->count, 1);
774 init_rwsem(&new_ns->sem);
776 INIT_LIST_HEAD(&new_ns->list);
778 down_write(&tsk->namespace->sem);
779 /* First pass: copy the tree topology */
780 new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root);
781 spin_lock(&dcache_lock);
782 list_add_tail(&new_ns->list, &new_ns->root->mnt_list);
783 spin_unlock(&dcache_lock);
785 /* Second pass: switch the tsk->fs->* elements */
787 struct vfsmount *p, *q;
788 write_lock(&fs->lock);
793 if (p == fs->rootmnt) {
795 fs->rootmnt = mntget(q);
797 if (p == fs->pwdmnt) {
799 fs->pwdmnt = mntget(q);
801 if (p == fs->altrootmnt) {
803 fs->altrootmnt = mntget(q);
805 p = next_mnt(p, namespace->root);
806 q = next_mnt(q, new_ns->root);
808 write_unlock(&fs->lock);
810 up_write(&tsk->namespace->sem);
812 tsk->namespace = new_ns;
821 put_namespace(namespace);
825 put_namespace(namespace);
829 asmlinkage long sys_mount(char * dev_name, char * dir_name, char * type,
830 unsigned long flags, void * data)
833 unsigned long data_page;
834 unsigned long type_page;
835 unsigned long dev_page;
838 retval = copy_mount_options (type, &type_page);
842 dir_page = getname(dir_name);
843 retval = PTR_ERR(dir_page);
844 if (IS_ERR(dir_page))
847 retval = copy_mount_options (dev_name, &dev_page);
851 retval = copy_mount_options (data, &data_page);
856 retval = do_mount((char*)dev_page, dir_page, (char*)type_page,
857 flags, (void*)data_page);
859 free_page(data_page);
866 free_page(type_page);
870 static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
872 struct task_struct *p;
873 struct fs_struct *fs;
875 read_lock(&tasklist_lock);
880 atomic_inc(&fs->count);
882 if (fs->root==old_nd->dentry&&fs->rootmnt==old_nd->mnt)
883 set_fs_root(fs, new_nd->mnt, new_nd->dentry);
884 if (fs->pwd==old_nd->dentry&&fs->pwdmnt==old_nd->mnt)
885 set_fs_pwd(fs, new_nd->mnt, new_nd->dentry);
890 read_unlock(&tasklist_lock);
894 * Moves the current root to put_root, and sets root/cwd of all processes
895 * which had them on the old root to new_root.
898 * - we don't move root/cwd if they are not at the root (reason: if something
899 * cared enough to change them, it's probably wrong to force them elsewhere)
900 * - it's okay to pick a root that isn't the root of a file system, e.g.
901 * /nfs/my_root where /nfs is the mount point. It must be a mountpoint,
902 * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root
906 asmlinkage long sys_pivot_root(const char *new_root, const char *put_old)
908 struct vfsmount *tmp;
909 struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;
912 if (!capable(CAP_SYS_ADMIN))
917 error = __user_walk(new_root, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd);
921 if (!check_mnt(new_nd.mnt))
924 error = __user_walk(put_old, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd);
928 read_lock(¤t->fs->lock);
929 user_nd.mnt = mntget(current->fs->rootmnt);
930 user_nd.dentry = dget(current->fs->root);
931 read_unlock(¤t->fs->lock);
932 down_write(¤t->namespace->sem);
933 down(&old_nd.dentry->d_inode->i_zombie);
935 if (!check_mnt(user_nd.mnt))
938 if (IS_DEADDIR(new_nd.dentry->d_inode))
940 if (d_unhashed(new_nd.dentry) && !IS_ROOT(new_nd.dentry))
942 if (d_unhashed(old_nd.dentry) && !IS_ROOT(old_nd.dentry))
945 if (new_nd.mnt == user_nd.mnt || old_nd.mnt == user_nd.mnt)
946 goto out2; /* loop */
948 if (user_nd.mnt->mnt_root != user_nd.dentry)
950 if (new_nd.mnt->mnt_root != new_nd.dentry)
951 goto out2; /* not a mountpoint */
952 tmp = old_nd.mnt; /* make sure we can reach put_old from new_root */
953 spin_lock(&dcache_lock);
954 if (tmp != new_nd.mnt) {
956 if (tmp->mnt_parent == tmp)
958 if (tmp->mnt_parent == new_nd.mnt)
960 tmp = tmp->mnt_parent;
962 if (!is_subdir(tmp->mnt_mountpoint, new_nd.dentry))
964 } else if (!is_subdir(old_nd.dentry, new_nd.dentry))
966 detach_mnt(new_nd.mnt, &parent_nd);
967 detach_mnt(user_nd.mnt, &root_parent);
968 attach_mnt(user_nd.mnt, &old_nd);
969 attach_mnt(new_nd.mnt, &root_parent);
970 spin_unlock(&dcache_lock);
971 chroot_fs_refs(&user_nd, &new_nd);
973 path_release(&root_parent);
974 path_release(&parent_nd);
976 up(&old_nd.dentry->d_inode->i_zombie);
977 up_write(¤t->namespace->sem);
978 path_release(&user_nd);
979 path_release(&old_nd);
981 path_release(&new_nd);
986 spin_unlock(&dcache_lock);
990 static void __init init_mount_tree(void)
992 struct vfsmount *mnt;
993 struct namespace *namespace;
994 struct task_struct *p;
996 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
998 panic("Can't create rootfs");
999 namespace = kmalloc(sizeof(*namespace), GFP_KERNEL);
1001 panic("Can't allocate initial namespace");
1002 atomic_set(&namespace->count, 1);
1003 INIT_LIST_HEAD(&namespace->list);
1004 init_rwsem(&namespace->sem);
1005 list_add(&mnt->mnt_list, &namespace->list);
1006 namespace->root = mnt;
1008 init_task.namespace = namespace;
1009 read_lock(&tasklist_lock);
1011 get_namespace(namespace);
1012 p->namespace = namespace;
1014 read_unlock(&tasklist_lock);
1016 set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root);
1017 set_fs_root(current->fs, namespace->root, namespace->root->mnt_root);
1020 void __init mnt_init(unsigned long mempages)
1022 struct list_head *d;
1023 unsigned long order;
1024 unsigned int nr_hash;
1027 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),
1028 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
1030 panic("Cannot create vfsmount cache");
1032 /* using single pointer list heads would save half of the hash table. */
1034 mount_hashtable = (struct list_head *)
1035 __get_free_pages(GFP_ATOMIC, order);
1037 if (!mount_hashtable)
1038 panic("Failed to allocate mount hash table\n");
1041 * Find the power-of-two list-heads that can fit into the allocation..
1042 * We don't guarantee that "sizeof(struct list_head)" is necessarily
1045 nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct list_head);
1049 } while ((nr_hash >> hash_bits) != 0);
1053 * Re-calculate the actual number of entries and the mask
1054 * from the number of bits we can fit.
1056 nr_hash = 1UL << hash_bits;
1057 hash_mask = nr_hash-1;
1059 printk(KERN_INFO "Mount cache hash table entries: %d"
1060 " (order: %ld, %ld bytes)\n",
1061 nr_hash, order, (PAGE_SIZE << order));
1063 /* And initialize the newly allocated array */
1064 d = mount_hashtable;