]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/autofs4/inode.c
[PATCH] autofs4: fix another race between mount and expire
[linux-2.6-omap-h63xx.git] / fs / autofs4 / inode.c
index 800ce876caeca6e33fc427e40d34d89a69923ed3..26063dc84a2a623da272a92a5c323058eb63ebb2 100644 (file)
@@ -48,6 +48,8 @@ struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
        ino->dentry = NULL;
        ino->size = 0;
 
+       INIT_LIST_HEAD(&ino->rehash);
+
        ino->last_used = jiffies;
        atomic_set(&ino->count, 0);
 
@@ -96,9 +98,12 @@ void autofs4_free_ino(struct autofs_info *ino)
  */
 static void autofs4_force_release(struct autofs_sb_info *sbi)
 {
-       struct dentry *this_parent = sbi->root;
+       struct dentry *this_parent = sbi->sb->s_root;
        struct list_head *next;
 
+       if (!sbi->sb->s_root)
+               return;
+
        spin_lock(&dcache_lock);
 repeat:
        next = this_parent->d_subdirs.next;
@@ -127,7 +132,7 @@ resume:
                spin_lock(&dcache_lock);
        }
 
-       if (this_parent != sbi->root) {
+       if (this_parent != sbi->sb->s_root) {
                struct dentry *dentry = this_parent;
 
                next = this_parent->d_u.d_child.next;
@@ -140,29 +145,33 @@ resume:
                goto resume;
        }
        spin_unlock(&dcache_lock);
-
-       dput(sbi->root);
-       sbi->root = NULL;
-       shrink_dcache_sb(sbi->sb);
-
-       return;
 }
 
-static void autofs4_put_super(struct super_block *sb)
+void autofs4_kill_sb(struct super_block *sb)
 {
        struct autofs_sb_info *sbi = autofs4_sbi(sb);
 
-       sb->s_fs_info = NULL;
+       /*
+        * In the event of a failure in get_sb_nodev the superblock
+        * info is not present so nothing else has been setup, so
+        * just call kill_anon_super when we are called from
+        * deactivate_super.
+        */
+       if (!sbi)
+               goto out_kill_sb;
 
-       if ( !sbi->catatonic )
+       if (!sbi->catatonic)
                autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
 
        /* Clean up and release dangling references */
        autofs4_force_release(sbi);
 
+       sb->s_fs_info = NULL;
        kfree(sbi);
 
+out_kill_sb:
        DPRINTK("shutting down");
+       kill_anon_super(sb);
 }
 
 static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
@@ -188,8 +197,7 @@ static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
        return 0;
 }
 
-static struct super_operations autofs4_sops = {
-       .put_super      = autofs4_put_super,
+static const struct super_operations autofs4_sops = {
        .statfs         = simple_statfs,
        .show_options   = autofs4_show_options,
 };
@@ -306,7 +314,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
        struct autofs_sb_info *sbi;
        struct autofs_info *ino;
 
-       sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
+       sbi = kmalloc(sizeof(*sbi), GFP_KERNEL);
        if ( !sbi )
                goto fail_unlock;
        DPRINTK("starting up, sbi = %p",sbi);
@@ -315,9 +323,9 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 
        s->s_fs_info = sbi;
        sbi->magic = AUTOFS_SBI_MAGIC;
-       sbi->root = NULL;
        sbi->pipefd = -1;
-       sbi->catatonic = 0;
+       sbi->pipe = NULL;
+       sbi->catatonic = 1;
        sbi->exp_timeout = 0;
        sbi->oz_pgrp = process_group(current);
        sbi->sb = s;
@@ -329,6 +337,8 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
        mutex_init(&sbi->wq_mutex);
        spin_lock_init(&sbi->fs_lock);
        sbi->queues = NULL;
+       spin_lock_init(&sbi->rehash_lock);
+       INIT_LIST_HEAD(&sbi->rehash_list);
        s->s_blocksize = 1024;
        s->s_blocksize_bits = 10;
        s->s_magic = AUTOFS_SUPER_MAGIC;
@@ -395,13 +405,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
                goto fail_fput;
        sbi->pipe = pipe;
        sbi->pipefd = pipefd;
-
-       /*
-        * Take a reference to the root dentry so we get a chance to
-        * clean up the dentry tree on umount.
-        * See autofs4_force_release.
-        */
-       sbi->root = dget(root);
+       sbi->catatonic = 0;
 
        /*
         * Success! Install the root dentry now to indicate completion.
@@ -426,6 +430,7 @@ fail_ino:
        kfree(ino);
 fail_free:
        kfree(sbi);
+       s->s_fs_info = NULL;
 fail_unlock:
        return -EINVAL;
 }