patch-2.4.0-test6 linux/fs/super.c

Next file: linux/fs/udf/file.c
Previous file: linux/fs/stat.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test5/linux/fs/super.c linux/fs/super.c
@@ -1566,15 +1566,22 @@
 			   struct vfsmount *new_rootmnt)
 {
 	struct task_struct *p;
+	struct fs_struct *fs;
 
 	read_lock(&tasklist_lock);
 	for_each_task(p) {
-		/* FIXME - unprotected usage of ->fs + (harmless) race */
-		if (!p->fs) continue;
-		if (p->fs->root == old_root && p->fs->rootmnt == old_rootmnt)
-			set_fs_root(p->fs, new_rootmnt, new_root);
-		if (p->fs->pwd == old_root && p->fs->pwdmnt == old_rootmnt)
-			set_fs_pwd(p->fs, new_rootmnt, new_root);
+		task_lock(p);
+		fs = p->fs;
+		if (fs) {
+			atomic_inc(&fs->count);
+			task_unlock(p);
+			if (fs->root==old_root && fs->rootmnt==old_rootmnt)
+				set_fs_root(fs, new_rootmnt, new_root);
+			if (fs->pwd==old_root && fs->pwdmnt==old_rootmnt)
+				set_fs_pwd(fs, new_rootmnt, new_root);
+			put_fs_struct(fs);
+		} else
+			task_unlock(p);
 	}
 	read_unlock(&tasklist_lock);
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)