[PATCH] Revert bd_mount_mutex back to a semaphore

Revert bd_mount_mutex back to a semaphore so that xfs_freeze -f /mnt/newtest;
xfs_freeze -u /mnt/newtest works safely and doesn't produce lockdep warnings.

(XFS unlocks the semaphore from a different task, by design. The mutex
code warns about this)

Signed-off-by: Dave Chinner <dgc@sgi.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by David Chinner and committed by Linus Torvalds f73ca1b7 88bf7b39

+9 -9
+1 -1
fs/block_dev.c
··· 411 { 412 memset(bdev, 0, sizeof(*bdev)); 413 mutex_init(&bdev->bd_mutex); 414 - mutex_init(&bdev->bd_mount_mutex); 415 INIT_LIST_HEAD(&bdev->bd_inodes); 416 INIT_LIST_HEAD(&bdev->bd_list); 417 #ifdef CONFIG_SYSFS
··· 411 { 412 memset(bdev, 0, sizeof(*bdev)); 413 mutex_init(&bdev->bd_mutex); 414 + sema_init(&bdev->bd_mount_sem, 1); 415 INIT_LIST_HEAD(&bdev->bd_inodes); 416 INIT_LIST_HEAD(&bdev->bd_list); 417 #ifdef CONFIG_SYSFS
+3 -3
fs/buffer.c
··· 180 * freeze_bdev -- lock a filesystem and force it into a consistent state 181 * @bdev: blockdevice to lock 182 * 183 - * This takes the block device bd_mount_mutex to make sure no new mounts 184 * happen on bdev until thaw_bdev() is called. 185 * If a superblock is found on this device, we take the s_umount semaphore 186 * on it to make sure nobody unmounts until the snapshot creation is done. ··· 189 { 190 struct super_block *sb; 191 192 - mutex_lock(&bdev->bd_mount_mutex); 193 sb = get_super(bdev); 194 if (sb && !(sb->s_flags & MS_RDONLY)) { 195 sb->s_frozen = SB_FREEZE_WRITE; ··· 231 drop_super(sb); 232 } 233 234 - mutex_unlock(&bdev->bd_mount_mutex); 235 } 236 EXPORT_SYMBOL(thaw_bdev); 237
··· 180 * freeze_bdev -- lock a filesystem and force it into a consistent state 181 * @bdev: blockdevice to lock 182 * 183 + * This takes the block device bd_mount_sem to make sure no new mounts 184 * happen on bdev until thaw_bdev() is called. 185 * If a superblock is found on this device, we take the s_umount semaphore 186 * on it to make sure nobody unmounts until the snapshot creation is done. ··· 189 { 190 struct super_block *sb; 191 192 + down(&bdev->bd_mount_sem); 193 sb = get_super(bdev); 194 if (sb && !(sb->s_flags & MS_RDONLY)) { 195 sb->s_frozen = SB_FREEZE_WRITE; ··· 231 drop_super(sb); 232 } 233 234 + up(&bdev->bd_mount_sem); 235 } 236 EXPORT_SYMBOL(thaw_bdev); 237
+2 -2
fs/gfs2/ops_fstype.c
··· 867 error = -EBUSY; 868 goto error; 869 } 870 - mutex_lock(&sb->s_bdev->bd_mount_mutex); 871 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev); 872 - mutex_unlock(&sb->s_bdev->bd_mount_mutex); 873 if (IS_ERR(new)) { 874 error = PTR_ERR(new); 875 goto error;
··· 867 error = -EBUSY; 868 goto error; 869 } 870 + down(&sb->s_bdev->bd_mount_sem); 871 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev); 872 + up(&sb->s_bdev->bd_mount_sem); 873 if (IS_ERR(new)) { 874 error = PTR_ERR(new); 875 goto error;
+2 -2
fs/super.c
··· 753 * will protect the lockfs code from trying to start a snapshot 754 * while we are mounting 755 */ 756 - mutex_lock(&bdev->bd_mount_mutex); 757 s = sget(fs_type, test_bdev_super, set_bdev_super, bdev); 758 - mutex_unlock(&bdev->bd_mount_mutex); 759 if (IS_ERR(s)) 760 goto error_s; 761
··· 753 * will protect the lockfs code from trying to start a snapshot 754 * while we are mounting 755 */ 756 + down(&bdev->bd_mount_sem); 757 s = sget(fs_type, test_bdev_super, set_bdev_super, bdev); 758 + up(&bdev->bd_mount_sem); 759 if (IS_ERR(s)) 760 goto error_s; 761
+1 -1
include/linux/fs.h
··· 459 struct inode * bd_inode; /* will die */ 460 int bd_openers; 461 struct mutex bd_mutex; /* open/close mutex */ 462 - struct mutex bd_mount_mutex; /* mount mutex */ 463 struct list_head bd_inodes; 464 void * bd_holder; 465 int bd_holders;
··· 459 struct inode * bd_inode; /* will die */ 460 int bd_openers; 461 struct mutex bd_mutex; /* open/close mutex */ 462 + struct semaphore bd_mount_sem; 463 struct list_head bd_inodes; 464 void * bd_holder; 465 int bd_holders;