]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/namespace.c
[PATCH] autofs4: change may_umount* functions to boolean
[linux-2.6-omap-h63xx.git] / fs / namespace.c
index 3e8fb61ad597cfd90164bf40aefdf0a761a02a13..bf478addb852b70c1ec036e33100f93031c5dc6b 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/quotaops.h>
 #include <linux/acct.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/seq_file.h>
 #include <linux/namespace.h>
@@ -42,11 +43,15 @@ __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
 
 static int event;
 
-static struct list_head *mount_hashtable;
+static struct list_head *mount_hashtable __read_mostly;
 static int hash_mask __read_mostly, hash_bits __read_mostly;
-static kmem_cache_t *mnt_cache;
+static kmem_cache_t *mnt_cache __read_mostly;
 static struct rw_semaphore namespace_sem;
 
+/* /sys/fs */
+decl_subsys(fs, NULL, NULL);
+EXPORT_SYMBOL_GPL(fs_subsys);
+
 static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
 {
        unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
@@ -355,14 +360,14 @@ static int show_vfsmnt(struct seq_file *m, void *v)
                { MS_SYNCHRONOUS, ",sync" },
                { MS_DIRSYNC, ",dirsync" },
                { MS_MANDLOCK, ",mand" },
-               { MS_NOATIME, ",noatime" },
-               { MS_NODIRATIME, ",nodiratime" },
                { 0, NULL }
        };
        static struct proc_fs_info mnt_info[] = {
                { MNT_NOSUID, ",nosuid" },
                { MNT_NODEV, ",nodev" },
                { MNT_NOEXEC, ",noexec" },
+               { MNT_NOATIME, ",noatime" },
+               { MNT_NODIRATIME, ",nodiratime" },
                { 0, NULL }
        };
        struct proc_fs_info *fs_infop;
@@ -394,6 +399,44 @@ struct seq_operations mounts_op = {
        .show   = show_vfsmnt
 };
 
+static int show_vfsstat(struct seq_file *m, void *v)
+{
+       struct vfsmount *mnt = v;
+       int err = 0;
+
+       /* device */
+       if (mnt->mnt_devname) {
+               seq_puts(m, "device ");
+               mangle(m, mnt->mnt_devname);
+       } else
+               seq_puts(m, "no device");
+
+       /* mount point */
+       seq_puts(m, " mounted on ");
+       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
+       seq_putc(m, ' ');
+
+       /* file system type */
+       seq_puts(m, "with fstype ");
+       mangle(m, mnt->mnt_sb->s_type->name);
+
+       /* optional statistics */
+       if (mnt->mnt_sb->s_op->show_stats) {
+               seq_putc(m, ' ');
+               err = mnt->mnt_sb->s_op->show_stats(m, mnt);
+       }
+
+       seq_putc(m, '\n');
+       return err;
+}
+
+struct seq_operations mountstats_op = {
+       .start  = m_start,
+       .next   = m_next,
+       .stop   = m_stop,
+       .show   = show_vfsstat,
+};
+
 /**
  * may_umount_tree - check if a mount tree is busy
  * @mnt: root of mount tree
@@ -416,9 +459,9 @@ int may_umount_tree(struct vfsmount *mnt)
        spin_unlock(&vfsmount_lock);
 
        if (actual_refs > minimum_refs)
-               return -EBUSY;
+               return 0;
 
-       return 0;
+       return 1;
 }
 
 EXPORT_SYMBOL(may_umount_tree);
@@ -438,10 +481,10 @@ EXPORT_SYMBOL(may_umount_tree);
  */
 int may_umount(struct vfsmount *mnt)
 {
-       int ret = 0;
+       int ret = 1;
        spin_lock(&vfsmount_lock);
        if (propagate_mount_busy(mnt, 2))
-               ret = -EBUSY;
+               ret = 0;
        spin_unlock(&vfsmount_lock);
        return ret;
 }
@@ -489,7 +532,7 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
                p->mnt_namespace = NULL;
                list_del_init(&p->mnt_child);
                if (p->mnt_parent != p)
-                       mnt->mnt_mountpoint->d_mounted--;
+                       p->mnt_mountpoint->d_mounted--;
                change_mnt_propagation(p, MS_PRIVATE);
        }
 }
@@ -814,7 +857,7 @@ static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
                return -ENOTDIR;
 
        err = -ENOENT;
-       down(&nd->dentry->d_inode->i_sem);
+       mutex_lock(&nd->dentry->d_inode->i_mutex);
        if (IS_DEADDIR(nd->dentry->d_inode))
                goto out_unlock;
 
@@ -826,7 +869,7 @@ static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
        if (IS_ROOT(nd->dentry) || !d_unhashed(nd->dentry))
                err = attach_recursive_mnt(mnt, nd, NULL);
 out_unlock:
-       up(&nd->dentry->d_inode->i_sem);
+       mutex_unlock(&nd->dentry->d_inode->i_mutex);
        if (!err)
                security_sb_post_addmount(mnt, nd);
        return err;
@@ -962,7 +1005,7 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
                goto out;
 
        err = -ENOENT;
-       down(&nd->dentry->d_inode->i_sem);
+       mutex_lock(&nd->dentry->d_inode->i_mutex);
        if (IS_DEADDIR(nd->dentry->d_inode))
                goto out1;
 
@@ -1004,7 +1047,7 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
        list_del_init(&old_nd.mnt->mnt_expire);
        spin_unlock(&vfsmount_lock);
 out1:
-       up(&nd->dentry->d_inode->i_sem);
+       mutex_unlock(&nd->dentry->d_inode->i_mutex);
 out:
        up_write(&namespace_sem);
        if (!err)
@@ -1286,7 +1329,13 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
                mnt_flags |= MNT_NODEV;
        if (flags & MS_NOEXEC)
                mnt_flags |= MNT_NOEXEC;
-       flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE);
+       if (flags & MS_NOATIME)
+               mnt_flags |= MNT_NOATIME;
+       if (flags & MS_NODIRATIME)
+               mnt_flags |= MNT_NODIRATIME;
+
+       flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
+                  MS_NOATIME | MS_NODIRATIME);
 
        /* ... and get the mountpoint */
        retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
@@ -1314,30 +1363,20 @@ dput_out:
        return retval;
 }
 
-int copy_namespace(int flags, struct task_struct *tsk)
+/*
+ * Allocate a new namespace structure and populate it with contents
+ * copied from the namespace of the passed in task structure.
+ */
+struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
 {
        struct namespace *namespace = tsk->namespace;
        struct namespace *new_ns;
        struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
-       struct fs_struct *fs = tsk->fs;
        struct vfsmount *p, *q;
 
-       if (!namespace)
-               return 0;
-
-       get_namespace(namespace);
-
-       if (!(flags & CLONE_NEWNS))
-               return 0;
-
-       if (!capable(CAP_SYS_ADMIN)) {
-               put_namespace(namespace);
-               return -EPERM;
-       }
-
        new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
        if (!new_ns)
-               goto out;
+               return NULL;
 
        atomic_set(&new_ns->count, 1);
        INIT_LIST_HEAD(&new_ns->list);
@@ -1351,7 +1390,7 @@ int copy_namespace(int flags, struct task_struct *tsk)
        if (!new_ns->root) {
                up_write(&namespace_sem);
                kfree(new_ns);
-               goto out;
+               return NULL;
        }
        spin_lock(&vfsmount_lock);
        list_add_tail(&new_ns->list, &new_ns->root->mnt_list);
@@ -1385,8 +1424,6 @@ int copy_namespace(int flags, struct task_struct *tsk)
        }
        up_write(&namespace_sem);
 
-       tsk->namespace = new_ns;
-
        if (rootmnt)
                mntput(rootmnt);
        if (pwdmnt)
@@ -1394,12 +1431,39 @@ int copy_namespace(int flags, struct task_struct *tsk)
        if (altrootmnt)
                mntput(altrootmnt);
 
-       put_namespace(namespace);
-       return 0;
+       return new_ns;
+}
+
+int copy_namespace(int flags, struct task_struct *tsk)
+{
+       struct namespace *namespace = tsk->namespace;
+       struct namespace *new_ns;
+       int err = 0;
+
+       if (!namespace)
+               return 0;
+
+       get_namespace(namespace);
+
+       if (!(flags & CLONE_NEWNS))
+               return 0;
+
+       if (!capable(CAP_SYS_ADMIN)) {
+               err = -EPERM;
+               goto out;
+       }
+
+       new_ns = dup_namespace(tsk, tsk->fs);
+       if (!new_ns) {
+               err = -ENOMEM;
+               goto out;
+       }
+
+       tsk->namespace = new_ns;
 
 out:
        put_namespace(namespace);
-       return -ENOMEM;
+       return err;
 }
 
 asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
@@ -1573,7 +1637,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
        user_nd.dentry = dget(current->fs->root);
        read_unlock(&current->fs->lock);
        down_write(&namespace_sem);
-       down(&old_nd.dentry->d_inode->i_sem);
+       mutex_lock(&old_nd.dentry->d_inode->i_mutex);
        error = -EINVAL;
        if (IS_MNT_SHARED(old_nd.mnt) ||
                IS_MNT_SHARED(new_nd.mnt->mnt_parent) ||
@@ -1626,7 +1690,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
        path_release(&root_parent);
        path_release(&parent_nd);
 out2:
-       up(&old_nd.dentry->d_inode->i_sem);
+       mutex_unlock(&old_nd.dentry->d_inode->i_mutex);
        up_write(&namespace_sem);
        path_release(&user_nd);
        path_release(&old_nd);
@@ -1718,6 +1782,7 @@ void __init mnt_init(unsigned long mempages)
                i--;
        } while (i);
        sysfs_init();
+       subsystem_register(&fs_subsys);
        init_rootfs();
        init_mount_tree();
 }