Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] autofs4: fix infamous "Busy inodes after umount ..." message

If the automount daemon receives a signal which causes it to sumarily
terminate the autofs4 module leaks dentries. The same problem exists with
detached mount requests without the warning.

This patch cleans these dentries at umount.

Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Ian Kent and committed by
Linus Torvalds
104e49fc 0f94c8e1

+74
+1
fs/autofs4/autofs_i.h
··· 92 92 93 93 struct autofs_sb_info { 94 94 u32 magic; 95 + struct dentry *root; 95 96 struct file *pipe; 96 97 pid_t oz_pgrp; 97 98 int catatonic;
+73
fs/autofs4/inode.c
··· 16 16 #include <linux/pagemap.h> 17 17 #include <linux/parser.h> 18 18 #include <linux/bitops.h> 19 + #include <linux/smp_lock.h> 19 20 #include "autofs_i.h" 20 21 #include <linux/module.h> 21 22 ··· 77 76 kfree(ino); 78 77 } 79 78 79 + /* 80 + * Deal with the infamous "Busy inodes after umount ..." message. 81 + * 82 + * Clean up the dentry tree. This happens with autofs if the user 83 + * space program goes away due to a SIGKILL, SIGSEGV etc. 84 + */ 85 + static void autofs4_force_release(struct autofs_sb_info *sbi) 86 + { 87 + struct dentry *this_parent = sbi->root; 88 + struct list_head *next; 89 + 90 + spin_lock(&dcache_lock); 91 + repeat: 92 + next = this_parent->d_subdirs.next; 93 + resume: 94 + while (next != &this_parent->d_subdirs) { 95 + struct dentry *dentry = list_entry(next, struct dentry, d_child); 96 + 97 + /* Negative dentry - don`t care */ 98 + if (!simple_positive(dentry)) { 99 + next = next->next; 100 + continue; 101 + } 102 + 103 + if (!list_empty(&dentry->d_subdirs)) { 104 + this_parent = dentry; 105 + goto repeat; 106 + } 107 + 108 + next = next->next; 109 + spin_unlock(&dcache_lock); 110 + 111 + DPRINTK("dentry %p %.*s", 112 + dentry, (int)dentry->d_name.len, dentry->d_name.name); 113 + 114 + dput(dentry); 115 + spin_lock(&dcache_lock); 116 + } 117 + 118 + if (this_parent != sbi->root) { 119 + struct dentry *dentry = this_parent; 120 + 121 + next = this_parent->d_child.next; 122 + this_parent = this_parent->d_parent; 123 + spin_unlock(&dcache_lock); 124 + DPRINTK("parent dentry %p %.*s", 125 + dentry, (int)dentry->d_name.len, dentry->d_name.name); 126 + dput(dentry); 127 + spin_lock(&dcache_lock); 128 + goto resume; 129 + } 130 + spin_unlock(&dcache_lock); 131 + 132 + dput(sbi->root); 133 + sbi->root = NULL; 134 + shrink_dcache_sb(sbi->sb); 135 + 136 + return; 137 + } 138 + 80 139 static void autofs4_put_super(struct super_block *sb) 81 140 { 82 141 struct autofs_sb_info *sbi = autofs4_sbi(sb); ··· 145 84 146 85 if ( !sbi->catatonic ) 147 86 autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */ 87 + 88 + /* Clean up and release dangling references */ 89 + if (sbi) 90 + autofs4_force_release(sbi); 148 91 149 92 kfree(sbi); 150 93 ··· 264 199 265 200 s->s_fs_info = sbi; 266 201 sbi->magic = AUTOFS_SBI_MAGIC; 202 + sbi->root = NULL; 267 203 sbi->catatonic = 0; 268 204 sbi->exp_timeout = 0; 269 205 sbi->oz_pgrp = process_group(current); ··· 331 265 if ( !pipe->f_op || !pipe->f_op->write ) 332 266 goto fail_fput; 333 267 sbi->pipe = pipe; 268 + 269 + /* 270 + * Take a reference to the root dentry so we get a chance to 271 + * clean up the dentry tree on umount. 272 + * See autofs4_force_release. 273 + */ 274 + sbi->root = dget(root); 334 275 335 276 /* 336 277 * Success! Install the root dentry now to indicate completion.