]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - fs/autofs4/root.c
Merge branch 'for-38-rc2' of git://codeaurora.org/quic/kernel/davidb/linux-msm
[mv-sheeva.git] / fs / autofs4 / root.c
index b2498c8cb0a7fb90065ab406ea250342db9c07ff..014e7aba3b08dcb6fe4a9395d2ec513d91ad4205 100644 (file)
@@ -35,6 +35,9 @@ static long autofs4_root_compat_ioctl(struct file *,unsigned int,unsigned long);
 #endif
 static int autofs4_dir_open(struct inode *inode, struct file *file);
 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
+static struct vfsmount *autofs4_d_automount(struct path *);
+static int autofs4_d_manage(struct dentry *, bool, bool);
+static void autofs4_dentry_release(struct dentry *);
 
 const struct file_operations autofs4_root_operations = {
        .open           = dcache_dir_open,
@@ -56,7 +59,7 @@ const struct file_operations autofs4_dir_operations = {
        .llseek         = dcache_dir_lseek,
 };
 
-const struct inode_operations autofs4_indirect_root_inode_operations = {
+const struct inode_operations autofs4_dir_inode_operations = {
        .lookup         = autofs4_lookup,
        .unlink         = autofs4_dir_unlink,
        .symlink        = autofs4_dir_symlink,
@@ -64,19 +67,10 @@ const struct inode_operations autofs4_indirect_root_inode_operations = {
        .rmdir          = autofs4_dir_rmdir,
 };
 
-const struct inode_operations autofs4_direct_root_inode_operations = {
-       .lookup         = autofs4_lookup,
-       .unlink         = autofs4_dir_unlink,
-       .mkdir          = autofs4_dir_mkdir,
-       .rmdir          = autofs4_dir_rmdir,
-};
-
-const struct inode_operations autofs4_dir_inode_operations = {
-       .lookup         = autofs4_lookup,
-       .unlink         = autofs4_dir_unlink,
-       .symlink        = autofs4_dir_symlink,
-       .mkdir          = autofs4_dir_mkdir,
-       .rmdir          = autofs4_dir_rmdir,
+const struct dentry_operations autofs4_dentry_operations = {
+       .d_automount    = autofs4_d_automount,
+       .d_manage       = autofs4_d_manage,
+       .d_release      = autofs4_dentry_release,
 };
 
 static void autofs4_add_active(struct dentry *dentry)
@@ -145,45 +139,27 @@ out:
        return dcache_dir_open(inode, file);
 }
 
-void autofs4_dentry_release(struct dentry *de)
+static void autofs4_dentry_release(struct dentry *de)
 {
-       struct autofs_info *inf;
+       struct autofs_info *ino = autofs4_dentry_ino(de);
+       struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
 
        DPRINTK("releasing %p", de);
 
-       inf = autofs4_dentry_ino(de);
-       de->d_fsdata = NULL;
-
-       if (inf) {
-               struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
-
-               if (sbi) {
-                       spin_lock(&sbi->lookup_lock);
-                       if (!list_empty(&inf->active))
-                               list_del(&inf->active);
-                       if (!list_empty(&inf->expiring))
-                               list_del(&inf->expiring);
-                       spin_unlock(&sbi->lookup_lock);
-               }
-
-               inf->dentry = NULL;
-               inf->inode = NULL;
+       if (!ino)
+               return;
 
-               autofs4_free_ino(inf);
+       if (sbi) {
+               spin_lock(&sbi->lookup_lock);
+               if (!list_empty(&ino->active))
+                       list_del(&ino->active);
+               if (!list_empty(&ino->expiring))
+                       list_del(&ino->expiring);
+               spin_unlock(&sbi->lookup_lock);
        }
-}
-
-/* For dentries of directories in the root dir */
-static const struct dentry_operations autofs4_root_dentry_operations = {
-       .d_release      = autofs4_dentry_release,
-};
 
-/* For other dentries */
-static const struct dentry_operations autofs4_dentry_operations = {
-       .d_automount    = autofs4_d_automount,
-       .d_manage       = autofs4_d_manage,
-       .d_release      = autofs4_dentry_release,
-};
+       autofs4_free_ino(ino);
+}
 
 static struct dentry *autofs4_lookup_active(struct dentry *dentry)
 {
@@ -352,7 +328,7 @@ static struct dentry *autofs4_mountpoint_changed(struct path *path)
        return path->dentry;
 }
 
-struct vfsmount *autofs4_d_automount(struct path *path)
+static struct vfsmount *autofs4_d_automount(struct path *path)
 {
        struct dentry *dentry = path->dentry;
        struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
@@ -470,7 +446,7 @@ done:
        return NULL;
 }
 
-int autofs4_d_manage(struct dentry *dentry, bool mounting_here)
+int autofs4_d_manage(struct dentry *dentry, bool mounting_here, bool rcu_walk)
 {
        struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
 
@@ -484,6 +460,10 @@ int autofs4_d_manage(struct dentry *dentry, bool mounting_here)
                return 0;
        }
 
+       /* We need to sleep, so we need pathwalk to be in ref-mode */
+       if (rcu_walk)
+               return -ECHILD;
+
        /* Wait for pending expires */
        do_expire_wait(dentry);
 
@@ -510,14 +490,13 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
        sbi = autofs4_sbi(dir->i_sb);
 
        DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
-               current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
+               current->pid, task_pgrp_nr(current), sbi->catatonic,
+               autofs4_oz_mode(sbi));
 
        active = autofs4_lookup_active(dentry);
        if (active) {
                return active;
        } else {
-               d_set_d_op(dentry, &autofs4_root_dentry_operations);
-
                /*
                 * A dentry that is not within the root can never trigger a
                 * mount operation, unless the directory already exists, so we
@@ -528,12 +507,10 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
                        return ERR_PTR(-ENOENT);
 
                /* Mark entries in the root as mount triggers */
-               if (autofs_type_indirect(sbi->type) && IS_ROOT(dentry->d_parent)) {
-                       d_set_d_op(dentry, &autofs4_dentry_operations);
+               if (autofs_type_indirect(sbi->type) && IS_ROOT(dentry->d_parent))
                        __managed_dentry_set_managed(dentry);
-               }
 
-               ino = autofs4_init_ino(NULL, sbi, 0555);
+               ino = autofs4_new_ino(sbi);
                if (!ino)
                        return ERR_PTR(-ENOMEM);
 
@@ -555,6 +532,7 @@ static int autofs4_dir_symlink(struct inode *dir,
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
        struct autofs_info *p_ino;
        struct inode *inode;
+       size_t size = strlen(symname);
        char *cp;
 
        DPRINTK("%s <- %.*s", symname,
@@ -563,40 +541,35 @@ static int autofs4_dir_symlink(struct inode *dir,
        if (!autofs4_oz_mode(sbi))
                return -EACCES;
 
-       ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
-       if (!ino)
-               return -ENOMEM;
+       BUG_ON(!ino);
+
+       autofs4_clean_ino(ino);
 
        autofs4_del_active(dentry);
 
-       ino->size = strlen(symname);
-       cp = kmalloc(ino->size + 1, GFP_KERNEL);
-       if (!cp) {
-               if (!dentry->d_fsdata)
-                       kfree(ino);
+       cp = kmalloc(size + 1, GFP_KERNEL);
+       if (!cp)
                return -ENOMEM;
-       }
 
        strcpy(cp, symname);
 
-       inode = autofs4_get_inode(dir->i_sb, ino);
+       inode = autofs4_get_inode(dir->i_sb, S_IFLNK | 0555);
        if (!inode) {
                kfree(cp);
                if (!dentry->d_fsdata)
                        kfree(ino);
                return -ENOMEM;
        }
+       inode->i_private = cp;
+       inode->i_size = size;
        d_add(dentry, inode);
 
-       dentry->d_fsdata = ino;
-       ino->dentry = dget(dentry);
+       dget(dentry);
        atomic_inc(&ino->count);
        p_ino = autofs4_dentry_ino(dentry->d_parent);
        if (p_ino && dentry->d_parent != dentry)
                atomic_inc(&p_ino->count);
-       ino->inode = inode;
 
-       ino->u.symlink = cp;
        dir->i_mtime = CURRENT_TIME;
 
        return 0;
@@ -649,6 +622,58 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
        return 0;
 }
 
+/*
+ * Version 4 of autofs provides a pseudo direct mount implementation
+ * that relies on directories at the leaves of a directory tree under
+ * an indirect mount to trigger mounts. To allow for this we need to
+ * set the DMANAGED_AUTOMOUNT and DMANAGED_TRANSIT flags on the leaves
+ * of the directory tree. There is no need to clear the automount flag
+ * following a mount or restore it after an expire because these mounts
+ * are always covered. However, it is neccessary to ensure that these
+ * flags are clear on non-empty directories to avoid unnecessary calls
+ * during path walks.
+ */
+static void autofs_set_leaf_automount_flags(struct dentry *dentry)
+{
+       struct dentry *parent;
+
+       /* root and dentrys in the root are already handled */
+       if (IS_ROOT(dentry->d_parent))
+               return;
+
+       managed_dentry_set_managed(dentry);
+
+       parent = dentry->d_parent;
+       /* only consider parents below dentrys in the root */
+       if (IS_ROOT(parent->d_parent))
+               return;
+       managed_dentry_clear_managed(parent);
+       return;
+}
+
+static void autofs_clear_leaf_automount_flags(struct dentry *dentry)
+{
+       struct list_head *d_child;
+       struct dentry *parent;
+
+       /* flags for dentrys in the root are handled elsewhere */
+       if (IS_ROOT(dentry->d_parent))
+               return;
+
+       managed_dentry_clear_managed(dentry);
+
+       parent = dentry->d_parent;
+       /* only consider parents below dentrys in the root */
+       if (IS_ROOT(parent->d_parent))
+               return;
+       d_child = &dentry->d_u.d_child;
+       /* Set parent managed if it's becoming empty */
+       if (d_child->next == &parent->d_subdirs &&
+           d_child->prev == &parent->d_subdirs)
+               managed_dentry_set_managed(parent);
+       return;
+}
+
 static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
 {
        struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
@@ -676,6 +701,9 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
        spin_unlock(&dentry->d_lock);
        spin_unlock(&autofs4_lock);
 
+       if (sbi->version < 5)
+               autofs_clear_leaf_automount_flags(dentry);
+
        if (atomic_dec_and_test(&ino->count)) {
                p_ino = autofs4_dentry_ino(dentry->d_parent);
                if (p_ino && dentry->d_parent != dentry)
@@ -704,27 +732,25 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        DPRINTK("dentry %p, creating %.*s",
                dentry, dentry->d_name.len, dentry->d_name.name);
 
-       ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
-       if (!ino)
-               return -ENOMEM;
+       BUG_ON(!ino);
+
+       autofs4_clean_ino(ino);
 
        autofs4_del_active(dentry);
 
-       inode = autofs4_get_inode(dir->i_sb, ino);
-       if (!inode) {
-               if (!dentry->d_fsdata)
-                       kfree(ino);
+       inode = autofs4_get_inode(dir->i_sb, S_IFDIR | 0555);
+       if (!inode)
                return -ENOMEM;
-       }
        d_add(dentry, inode);
 
-       dentry->d_fsdata = ino;
-       ino->dentry = dget(dentry);
+       if (sbi->version < 5)
+               autofs_set_leaf_automount_flags(dentry);
+
+       dget(dentry);
        atomic_inc(&ino->count);
        p_ino = autofs4_dentry_ino(dentry->d_parent);
        if (p_ino && dentry->d_parent != dentry)
                atomic_inc(&p_ino->count);
-       ino->inode = inode;
        inc_nlink(dir);
        dir->i_mtime = CURRENT_TIME;
 
@@ -806,8 +832,7 @@ static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
 int is_autofs4_dentry(struct dentry *dentry)
 {
        return dentry && dentry->d_inode &&
-               (dentry->d_op == &autofs4_root_dentry_operations ||
-                dentry->d_op == &autofs4_dentry_operations) &&
+               dentry->d_op == &autofs4_dentry_operations &&
                dentry->d_fsdata != NULL;
 }