aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ufs/super.c
diff options
context:
space:
mode:
authorFabian Frederick <fabf@skynet.be>2014-06-06 17:38:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-06 19:08:18 -0400
commit0244756edc4b98c129e92c7061d9f383708cf786 (patch)
tree49ff65c45d2ca48e184e1d931d79c122982461e1 /fs/ufs/super.c
parent0d2b7ea9287d39e87531d233ba885263e6160127 (diff)
ufs: sb mutex merge + mutex_destroy
Commit 788257d6101d ("ufs: remove the BKL") replaced BKL with mutex protection using functions lock_ufs, unlock_ufs and struct mutex 'mutex' in sb_info. Commit b6963327e052 ("ufs: drop lock/unlock super") removed lock/unlock super and added struct mutex 's_lock' in sb_info. Those 2 mutexes are generally locked/unlocked at the same time except in allocation (balloc, ialloc). This patch merges the 2 mutexes and propagates first commit solution. It also adds mutex destruction before kfree during ufs_fill_super failure and ufs_put_super. [akpm@linux-foundation.org: avoid ifdefs, return -EROFS not -EINVAL] Signed-off-by: Fabian Frederick <fabf@skynet.be> Cc: Evgeniy Dushistov <dushistov@mail.ru> Cc: "Chen, Jet" <jet.chen@intel.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ufs/super.c')
-rw-r--r--fs/ufs/super.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index c1183f9f69dc..b879f1ba3439 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -697,7 +697,6 @@ static int ufs_sync_fs(struct super_block *sb, int wait)
697 unsigned flags; 697 unsigned flags;
698 698
699 lock_ufs(sb); 699 lock_ufs(sb);
700 mutex_lock(&UFS_SB(sb)->s_lock);
701 700
702 UFSD("ENTER\n"); 701 UFSD("ENTER\n");
703 702
@@ -715,7 +714,6 @@ static int ufs_sync_fs(struct super_block *sb, int wait)
715 ufs_put_cstotal(sb); 714 ufs_put_cstotal(sb);
716 715
717 UFSD("EXIT\n"); 716 UFSD("EXIT\n");
718 mutex_unlock(&UFS_SB(sb)->s_lock);
719 unlock_ufs(sb); 717 unlock_ufs(sb);
720 718
721 return 0; 719 return 0;
@@ -760,6 +758,7 @@ static void ufs_put_super(struct super_block *sb)
760 758
761 ubh_brelse_uspi (sbi->s_uspi); 759 ubh_brelse_uspi (sbi->s_uspi);
762 kfree (sbi->s_uspi); 760 kfree (sbi->s_uspi);
761 mutex_destroy(&sbi->mutex);
763 kfree (sbi); 762 kfree (sbi);
764 sb->s_fs_info = NULL; 763 sb->s_fs_info = NULL;
765 UFSD("EXIT\n"); 764 UFSD("EXIT\n");
@@ -786,6 +785,14 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
786 flags = 0; 785 flags = 0;
787 786
788 UFSD("ENTER\n"); 787 UFSD("ENTER\n");
788
789#ifndef CONFIG_UFS_FS_WRITE
790 if (!(sb->s_flags & MS_RDONLY)) {
791 printk("ufs was compiled with read-only support, "
792 "can't be mounted as read-write\n");
793 return -EROFS;
794 }
795#endif
789 796
790 sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL); 797 sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
791 if (!sbi) 798 if (!sbi)
@@ -795,15 +802,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
795 802
796 UFSD("flag %u\n", (int)(sb->s_flags & MS_RDONLY)); 803 UFSD("flag %u\n", (int)(sb->s_flags & MS_RDONLY));
797 804
798#ifndef CONFIG_UFS_FS_WRITE
799 if (!(sb->s_flags & MS_RDONLY)) {
800 printk("ufs was compiled with read-only support, "
801 "can't be mounted as read-write\n");
802 goto failed;
803 }
804#endif
805 mutex_init(&sbi->mutex); 805 mutex_init(&sbi->mutex);
806 mutex_init(&sbi->s_lock);
807 spin_lock_init(&sbi->work_lock); 806 spin_lock_init(&sbi->work_lock);
808 INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs); 807 INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
809 /* 808 /*
@@ -1257,6 +1256,7 @@ magic_found:
1257 return 0; 1256 return 0;
1258 1257
1259failed: 1258failed:
1259 mutex_destroy(&sbi->mutex);
1260 if (ubh) 1260 if (ubh)
1261 ubh_brelse_uspi (uspi); 1261 ubh_brelse_uspi (uspi);
1262 kfree (uspi); 1262 kfree (uspi);
@@ -1280,7 +1280,6 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1280 1280
1281 sync_filesystem(sb); 1281 sync_filesystem(sb);
1282 lock_ufs(sb); 1282 lock_ufs(sb);
1283 mutex_lock(&UFS_SB(sb)->s_lock);
1284 uspi = UFS_SB(sb)->s_uspi; 1283 uspi = UFS_SB(sb)->s_uspi;
1285 flags = UFS_SB(sb)->s_flags; 1284 flags = UFS_SB(sb)->s_flags;
1286 usb1 = ubh_get_usb_first(uspi); 1285 usb1 = ubh_get_usb_first(uspi);
@@ -1294,7 +1293,6 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1294 new_mount_opt = 0; 1293 new_mount_opt = 0;
1295 ufs_set_opt (new_mount_opt, ONERROR_LOCK); 1294 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
1296 if (!ufs_parse_options (data, &new_mount_opt)) { 1295 if (!ufs_parse_options (data, &new_mount_opt)) {
1297 mutex_unlock(&UFS_SB(sb)->s_lock);
1298 unlock_ufs(sb); 1296 unlock_ufs(sb);
1299 return -EINVAL; 1297 return -EINVAL;
1300 } 1298 }
@@ -1302,14 +1300,12 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1302 new_mount_opt |= ufstype; 1300 new_mount_opt |= ufstype;
1303 } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) { 1301 } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
1304 printk("ufstype can't be changed during remount\n"); 1302 printk("ufstype can't be changed during remount\n");
1305 mutex_unlock(&UFS_SB(sb)->s_lock);
1306 unlock_ufs(sb); 1303 unlock_ufs(sb);
1307 return -EINVAL; 1304 return -EINVAL;
1308 } 1305 }
1309 1306
1310 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) { 1307 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1311 UFS_SB(sb)->s_mount_opt = new_mount_opt; 1308 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1312 mutex_unlock(&UFS_SB(sb)->s_lock);
1313 unlock_ufs(sb); 1309 unlock_ufs(sb);
1314 return 0; 1310 return 0;
1315 } 1311 }
@@ -1334,7 +1330,6 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1334#ifndef CONFIG_UFS_FS_WRITE 1330#ifndef CONFIG_UFS_FS_WRITE
1335 printk("ufs was compiled with read-only support, " 1331 printk("ufs was compiled with read-only support, "
1336 "can't be mounted as read-write\n"); 1332 "can't be mounted as read-write\n");
1337 mutex_unlock(&UFS_SB(sb)->s_lock);
1338 unlock_ufs(sb); 1333 unlock_ufs(sb);
1339 return -EINVAL; 1334 return -EINVAL;
1340#else 1335#else
@@ -1344,13 +1339,11 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1344 ufstype != UFS_MOUNT_UFSTYPE_SUNx86 && 1339 ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
1345 ufstype != UFS_MOUNT_UFSTYPE_UFS2) { 1340 ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
1346 printk("this ufstype is read-only supported\n"); 1341 printk("this ufstype is read-only supported\n");
1347 mutex_unlock(&UFS_SB(sb)->s_lock);
1348 unlock_ufs(sb); 1342 unlock_ufs(sb);
1349 return -EINVAL; 1343 return -EINVAL;
1350 } 1344 }
1351 if (!ufs_read_cylinder_structures(sb)) { 1345 if (!ufs_read_cylinder_structures(sb)) {
1352 printk("failed during remounting\n"); 1346 printk("failed during remounting\n");
1353 mutex_unlock(&UFS_SB(sb)->s_lock);
1354 unlock_ufs(sb); 1347 unlock_ufs(sb);
1355 return -EPERM; 1348 return -EPERM;
1356 } 1349 }
@@ -1358,7 +1351,6 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1358#endif 1351#endif
1359 } 1352 }
1360 UFS_SB(sb)->s_mount_opt = new_mount_opt; 1353 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1361 mutex_unlock(&UFS_SB(sb)->s_lock);
1362 unlock_ufs(sb); 1354 unlock_ufs(sb);
1363 return 0; 1355 return 0;
1364} 1356}