ARM: report present cpus instead of online CPUs
[linux-2.6.git] / fs / namespace.c
index 46cc26b..e5e1c7d 100644 (file)
@@ -934,8 +934,8 @@ int mnt_had_events(struct proc_mounts *p)
        int res = 0;
 
        br_read_lock(vfsmount_lock);
-       if (p->event != ns->event) {
-               p->event = ns->event;
+       if (p->m.poll_event != ns->event) {
+               p->m.poll_event = ns->event;
                res = 1;
        }
        br_read_unlock(vfsmount_lock);
@@ -1030,18 +1030,6 @@ const struct seq_operations mounts_op = {
        .show   = show_vfsmnt
 };
 
-static int uuid_is_nil(u8 *uuid)
-{
-       int i;
-       u8  *cp = (u8 *)uuid;
-
-       for (i = 0; i < 16; i++) {
-               if (*cp++)
-                       return 0;
-       }
-       return 1;
-}
-
 static int show_mountinfo(struct seq_file *m, void *v)
 {
        struct proc_mounts *p = m->private;
@@ -1085,10 +1073,6 @@ static int show_mountinfo(struct seq_file *m, void *v)
        if (IS_MNT_UNBINDABLE(mnt))
                seq_puts(m, " unbindable");
 
-       if (!uuid_is_nil(mnt->mnt_sb->s_uuid))
-               /* print the uuid */
-               seq_printf(m, " uuid:%pU", mnt->mnt_sb->s_uuid);
-
        /* Filesystem specific data */
        seq_puts(m, " - ");
        show_type(m, sb);
@@ -1125,6 +1109,7 @@ static int show_vfsstat(struct seq_file *m, void *v)
 
        /* device */
        if (mnt->mnt_sb->s_op->show_devname) {
+               seq_puts(m, "device ");
                err = mnt->mnt_sb->s_op->show_devname(m, mnt);
        } else {
                if (mnt->mnt_devname) {
@@ -1663,9 +1648,35 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
        return err;
 }
 
+static int lock_mount(struct path *path)
+{
+       struct vfsmount *mnt;
+retry:
+       mutex_lock(&path->dentry->d_inode->i_mutex);
+       if (unlikely(cant_mount(path->dentry))) {
+               mutex_unlock(&path->dentry->d_inode->i_mutex);
+               return -ENOENT;
+       }
+       down_write(&namespace_sem);
+       mnt = lookup_mnt(path);
+       if (likely(!mnt))
+               return 0;
+       up_write(&namespace_sem);
+       mutex_unlock(&path->dentry->d_inode->i_mutex);
+       path_put(path);
+       path->mnt = mnt;
+       path->dentry = dget(mnt->mnt_root);
+       goto retry;
+}
+
+static void unlock_mount(struct path *path)
+{
+       up_write(&namespace_sem);
+       mutex_unlock(&path->dentry->d_inode->i_mutex);
+}
+
 static int graft_tree(struct vfsmount *mnt, struct path *path)
 {
-       int err;
        if (mnt->mnt_sb->s_flags & MS_NOUSER)
                return -EINVAL;
 
@@ -1673,16 +1684,10 @@ static int graft_tree(struct vfsmount *mnt, struct path *path)
              S_ISDIR(mnt->mnt_root->d_inode->i_mode))
                return -ENOTDIR;
 
-       err = -ENOENT;
-       mutex_lock(&path->dentry->d_inode->i_mutex);
-       if (cant_mount(path->dentry))
-               goto out_unlock;
+       if (d_unlinked(path->dentry))
+               return -ENOENT;
 
-       if (!d_unlinked(path->dentry))
-               err = attach_recursive_mnt(mnt, path, NULL);
-out_unlock:
-       mutex_unlock(&path->dentry->d_inode->i_mutex);
-       return err;
+       return attach_recursive_mnt(mnt, path, NULL);
 }
 
 /*
@@ -1691,7 +1696,7 @@ out_unlock:
 
 static int flags_to_propagation_type(int flags)
 {
-       int type = flags & ~MS_REC;
+       int type = flags & ~(MS_REC | MS_SILENT);
 
        /* Fail if any non-propagation flags are set */
        if (type & ~(MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
@@ -1745,6 +1750,7 @@ static int do_change_type(struct path *path, int flag)
 static int do_loopback(struct path *path, char *old_name,
                                int recurse)
 {
+       LIST_HEAD(umount_list);
        struct path old_path;
        struct vfsmount *mnt = NULL;
        int err = mount_is_safe(path);
@@ -1752,17 +1758,20 @@ static int do_loopback(struct path *path, char *old_name,
                return err;
        if (!old_name || !*old_name)
                return -EINVAL;
-       err = kern_path(old_name, LOOKUP_FOLLOW, &old_path);
+       err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
        if (err)
                return err;
 
-       down_write(&namespace_sem);
+       err = lock_mount(path);
+       if (err)
+               goto out;
+
        err = -EINVAL;
        if (IS_MNT_UNBINDABLE(old_path.mnt))
-               goto out;
+               goto out2;
 
        if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt))
-               goto out;
+               goto out2;
 
        err = -ENOMEM;
        if (recurse)
@@ -1771,20 +1780,18 @@ static int do_loopback(struct path *path, char *old_name,
                mnt = clone_mnt(old_path.mnt, old_path.dentry, 0);
 
        if (!mnt)
-               goto out;
+               goto out2;
 
        err = graft_tree(mnt, path);
        if (err) {
-               LIST_HEAD(umount_list);
-
                br_write_lock(vfsmount_lock);
                umount_tree(mnt, 0, &umount_list);
                br_write_unlock(vfsmount_lock);
-               release_mounts(&umount_list);
        }
-
+out2:
+       unlock_mount(path);
+       release_mounts(&umount_list);
 out:
-       up_write(&namespace_sem);
        path_put(&old_path);
        return err;
 }
@@ -1873,18 +1880,12 @@ static int do_move_mount(struct path *path, char *old_name)
        if (err)
                return err;
 
-       down_write(&namespace_sem);
-       err = follow_down(path, true);
+       err = lock_mount(path);
        if (err < 0)
                goto out;
 
        err = -EINVAL;
        if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt))
-               goto out;
-
-       err = -ENOENT;
-       mutex_lock(&path->dentry->d_inode->i_mutex);
-       if (cant_mount(path->dentry))
                goto out1;
 
        if (d_unlinked(path->dentry))
@@ -1926,9 +1927,8 @@ static int do_move_mount(struct path *path, char *old_name)
         * automatically */
        list_del_init(&old_path.mnt->mnt_expire);
 out1:
-       mutex_unlock(&path->dentry->d_inode->i_mutex);
+       unlock_mount(path);
 out:
-       up_write(&namespace_sem);
        if (!err)
                path_put(&parent_path);
        path_put(&old_path);
@@ -1983,11 +1983,9 @@ static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flag
 
        mnt_flags &= ~(MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL);
 
-       down_write(&namespace_sem);
-       /* Something was mounted here while we slept */
-       err = follow_down(path, true);
-       if (err < 0)
-               goto unlock;
+       err = lock_mount(path);
+       if (err)
+               return err;
 
        err = -EINVAL;
        if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(path->mnt))
@@ -2007,7 +2005,7 @@ static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flag
        err = graft_tree(newmnt, path);
 
 unlock:
-       up_write(&namespace_sem);
+       unlock_mount(path);
        return err;
 }
 
@@ -2575,55 +2573,53 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
                goto out1;
 
        error = security_sb_pivotroot(&old, &new);
-       if (error) {
-               path_put(&old);
-               goto out1;
-       }
+       if (error)
+               goto out2;
 
        get_fs_root(current->fs, &root);
-       down_write(&namespace_sem);
-       mutex_lock(&old.dentry->d_inode->i_mutex);
+       error = lock_mount(&old);
+       if (error)
+               goto out3;
+
        error = -EINVAL;
        if (IS_MNT_SHARED(old.mnt) ||
                IS_MNT_SHARED(new.mnt->mnt_parent) ||
                IS_MNT_SHARED(root.mnt->mnt_parent))
-               goto out2;
+               goto out4;
        if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
-               goto out2;
+               goto out4;
        error = -ENOENT;
-       if (cant_mount(old.dentry))
-               goto out2;
        if (d_unlinked(new.dentry))
-               goto out2;
+               goto out4;
        if (d_unlinked(old.dentry))
-               goto out2;
+               goto out4;
        error = -EBUSY;
        if (new.mnt == root.mnt ||
            old.mnt == root.mnt)
-               goto out2; /* loop, on the same file system  */
+               goto out4; /* loop, on the same file system  */
        error = -EINVAL;
        if (root.mnt->mnt_root != root.dentry)
-               goto out2; /* not a mountpoint */
+               goto out4; /* not a mountpoint */
        if (root.mnt->mnt_parent == root.mnt)
-               goto out2; /* not attached */
+               goto out4; /* not attached */
        if (new.mnt->mnt_root != new.dentry)
-               goto out2; /* not a mountpoint */
+               goto out4; /* not a mountpoint */
        if (new.mnt->mnt_parent == new.mnt)
-               goto out2; /* not attached */
+               goto out4; /* not attached */
        /* make sure we can reach put_old from new_root */
        tmp = old.mnt;
        if (tmp != new.mnt) {
                for (;;) {
                        if (tmp->mnt_parent == tmp)
-                               goto out2; /* already mounted on put_old */
+                               goto out4; /* already mounted on put_old */
                        if (tmp->mnt_parent == new.mnt)
                                break;
                        tmp = tmp->mnt_parent;
                }
                if (!is_subdir(tmp->mnt_mountpoint, new.dentry))
-                       goto out2;
+                       goto out4;
        } else if (!is_subdir(old.dentry, new.dentry))
-               goto out2;
+               goto out4;
        br_write_lock(vfsmount_lock);
        detach_mnt(new.mnt, &parent_path);
        detach_mnt(root.mnt, &root_parent);
@@ -2634,14 +2630,16 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
        touch_mnt_namespace(current->nsproxy->mnt_ns);
        br_write_unlock(vfsmount_lock);
        chroot_fs_refs(&root, &new);
-
        error = 0;
-       path_put(&root_parent);
-       path_put(&parent_path);
-out2:
-       mutex_unlock(&old.dentry->d_inode->i_mutex);
-       up_write(&namespace_sem);
+out4:
+       unlock_mount(&old);
+       if (!error) {
+               path_put(&root_parent);
+               path_put(&parent_path);
+       }
+out3:
        path_put(&root);
+out2:
        path_put(&old);
 out1:
        path_put(&new);
@@ -2688,7 +2686,7 @@ void __init mnt_init(void)
        if (!mount_hashtable)
                panic("Failed to allocate mount hash table\n");
 
-       printk("Mount-cache hash table entries: %lu\n", HASH_SIZE);
+       printk(KERN_INFO "Mount-cache hash table entries: %lu\n", HASH_SIZE);
 
        for (u = 0; u < HASH_SIZE; u++)
                INIT_LIST_HEAD(&mount_hashtable[u]);
@@ -2724,6 +2722,25 @@ EXPORT_SYMBOL(put_mnt_ns);
 
 struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
 {
-       return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
+       struct vfsmount *mnt;
+       mnt = vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
+       if (!IS_ERR(mnt)) {
+               /*
+                * it is a longterm mount, don't release mnt until
+                * we unmount before file sys is unregistered
+               */
+               mnt_make_longterm(mnt);
+       }
+       return mnt;
 }
 EXPORT_SYMBOL_GPL(kern_mount_data);
+
+void kern_unmount(struct vfsmount *mnt)
+{
+       /* release long term mount so mount point can be released */
+       if (!IS_ERR_OR_NULL(mnt)) {
+               mnt_make_shortterm(mnt);
+               mntput(mnt);
+       }
+}
+EXPORT_SYMBOL(kern_unmount);