patch-2.1.57 linux/fs/super.c

Next file: linux/include/asm-alpha/elf.h
Previous file: linux/fs/select.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.56/linux/fs/super.c linux/fs/super.c
@@ -47,6 +47,14 @@
 #include <linux/nfs_fs_sb.h>
 #include <linux/nfs_mount.h>
 
+/*
+ * We use a semaphore to synchronize all mount/umount
+ * activity - imagine the mess if we have a race between
+ * unmounting a filesystem and re-mounting it (or something
+ * else).
+ */
+static struct semaphore mount_sem = MUTEX;
+
 extern void wait_for_keypress(void);
 extern struct file_operations * get_blkfops(unsigned int major);
 
@@ -665,6 +673,9 @@
 		goto out_iput;
 
 	fsync_dev(dev);
+
+	down(&mount_sem);
+
 	retval = do_umount(dev,0);
 	if (!retval) {
 		fsync_dev(dev);
@@ -673,6 +684,8 @@
 			put_unnamed_dev(dev);
 		}
 	}
+
+	up(&mount_sem);
 out_iput:
 	iput(inode);
 out:
@@ -767,6 +780,7 @@
 	struct vfsmount *vfsmnt;
 	int error;
 
+	down(&mount_sem);
 	error = -EACCES;
 	if (!(flags & MS_RDONLY) && dev && is_read_only(dev))
 		goto out;
@@ -810,12 +824,14 @@
 		vfsmnt->mnt_sb = sb;
 		vfsmnt->mnt_flags = flags;
 		d_mount(dir_d, sb->s_root);
-		return 0;		/* we don't dput(dir) - see umount */
+		error = 0;
+		goto out;		/* we don't dput(dir) - see umount */
 	}
 
 dput_and_out:
 	dput(dir_d);
 out:
+	up(&mount_sem);
 	return error;	
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov