]> git.karo-electronics.de Git - linux-beck.git/blobdiff - fs/autofs4/root.c
autofs4: pass mode to autofs4_get_inode() explicitly
[linux-beck.git] / fs / autofs4 / root.c
index 62c1229a4d3174369f14f60cb6c28e53b923feb7..e55dcdbeb45091d19b0846005495679919d29722 100644 (file)
@@ -36,7 +36,7 @@ static long autofs4_root_compat_ioctl(struct file *,unsigned int,unsigned long);
 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);
+static int autofs4_d_manage(struct dentry *, bool, bool);
 
 const struct file_operations autofs4_root_operations = {
        .open           = dcache_dir_open,
@@ -66,13 +66,7 @@ const struct inode_operations autofs4_dir_inode_operations = {
        .rmdir          = autofs4_dir_rmdir,
 };
 
-/* For dentries that don't initiate mounting */
 const struct dentry_operations autofs4_dentry_operations = {
-       .d_release      = autofs4_dentry_release,
-};
-
-/* For dentries that do initiate mounting */
-const struct dentry_operations autofs4_mount_dentry_operations = {
        .d_automount    = autofs4_d_automount,
        .d_manage       = autofs4_d_manage,
        .d_release      = autofs4_dentry_release,
@@ -151,11 +145,8 @@ void autofs4_dentry_release(struct dentry *de)
        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))
@@ -164,10 +155,6 @@ void autofs4_dentry_release(struct dentry *de)
                                list_del(&inf->expiring);
                        spin_unlock(&sbi->lookup_lock);
                }
-
-               inf->dentry = NULL;
-               inf->inode = NULL;
-
                autofs4_free_ino(inf);
        }
 }
@@ -457,7 +444,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);
 
@@ -471,6 +458,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);
 
@@ -497,14 +488,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_dentry_operations);
-
                /*
                 * A dentry that is not within the root can never trigger a
                 * mount operation, unless the directory already exists, so we
@@ -515,12 +505,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_mount_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_init_ino(NULL, sbi);
                if (!ino)
                        return ERR_PTR(-ENOMEM);
 
@@ -550,7 +538,7 @@ static int autofs4_dir_symlink(struct inode *dir,
        if (!autofs4_oz_mode(sbi))
                return -EACCES;
 
-       ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
+       ino = autofs4_init_ino(ino, sbi);
        if (!ino)
                return -ENOMEM;
 
@@ -566,26 +554,23 @@ static int autofs4_dir_symlink(struct inode *dir,
 
        strcpy(cp, symname);
 
-       inode = autofs4_get_inode(dir->i_sb, ino);
+       inode = autofs4_get_inode(dir->i_sb, ino, S_IFLNK | 0555);
        if (!inode) {
                kfree(cp);
                if (!dentry->d_fsdata)
                        kfree(ino);
                return -ENOMEM;
        }
+       inode->i_private = cp;
        d_add(dentry, inode);
 
-       d_set_d_op(dentry, &autofs4_dentry_operations);
-
        dentry->d_fsdata = ino;
        ino->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;
@@ -638,6 +623,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);
@@ -665,6 +702,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)
@@ -693,13 +733,13 @@ 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);
+       ino = autofs4_init_ino(ino, sbi);
        if (!ino)
                return -ENOMEM;
 
        autofs4_del_active(dentry);
 
-       inode = autofs4_get_inode(dir->i_sb, ino);
+       inode = autofs4_get_inode(dir->i_sb, ino, S_IFDIR | 0555);
        if (!inode) {
                if (!dentry->d_fsdata)
                        kfree(ino);
@@ -707,13 +747,15 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        }
        d_add(dentry, inode);
 
+       if (sbi->version < 5)
+               autofs_set_leaf_automount_flags(dentry);
+
        dentry->d_fsdata = ino;
        ino->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;
 
@@ -795,8 +837,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_mount_dentry_operations ||
-                dentry->d_op == &autofs4_dentry_operations) &&
+               dentry->d_op == &autofs4_dentry_operations &&
                dentry->d_fsdata != NULL;
 }