aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/block_dev.c24
-rw-r--r--fs/reiserfs/journal.c3
-rw-r--r--fs/super.c14
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c4
4 files changed, 25 insertions, 20 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 05131baf3cf8..4b595904cefd 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1309,32 +1309,29 @@ fail:
1309EXPORT_SYMBOL(lookup_bdev); 1309EXPORT_SYMBOL(lookup_bdev);
1310 1310
1311/** 1311/**
1312 * open_bdev_excl - open a block device by name and set it up for use 1312 * open_bdev_exclusive - open a block device by name and set it up for use
1313 * 1313 *
1314 * @path: special file representing the block device 1314 * @path: special file representing the block device
1315 * @flags: %MS_RDONLY for opening read-only 1315 * @mode: FMODE_... combination to pass be used
1316 * @holder: owner for exclusion 1316 * @holder: owner for exclusion
1317 * 1317 *
1318 * Open the blockdevice described by the special file at @path, claim it 1318 * Open the blockdevice described by the special file at @path, claim it
1319 * for the @holder. 1319 * for the @holder.
1320 */ 1320 */
1321struct block_device *open_bdev_excl(const char *path, int flags, void *holder) 1321struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder)
1322{ 1322{
1323 struct block_device *bdev; 1323 struct block_device *bdev;
1324 fmode_t mode = FMODE_READ;
1325 int error = 0; 1324 int error = 0;
1326 1325
1327 bdev = lookup_bdev(path); 1326 bdev = lookup_bdev(path);
1328 if (IS_ERR(bdev)) 1327 if (IS_ERR(bdev))
1329 return bdev; 1328 return bdev;
1330 1329
1331 if (!(flags & MS_RDONLY))
1332 mode |= FMODE_WRITE;
1333 error = blkdev_get(bdev, mode, 0); 1330 error = blkdev_get(bdev, mode, 0);
1334 if (error) 1331 if (error)
1335 return ERR_PTR(error); 1332 return ERR_PTR(error);
1336 error = -EACCES; 1333 error = -EACCES;
1337 if (!(flags & MS_RDONLY) && bdev_read_only(bdev)) 1334 if ((mode & FMODE_WRITE) && bdev_read_only(bdev))
1338 goto blkdev_put; 1335 goto blkdev_put;
1339 error = bd_claim(bdev, holder); 1336 error = bd_claim(bdev, holder);
1340 if (error) 1337 if (error)
@@ -1347,22 +1344,23 @@ blkdev_put:
1347 return ERR_PTR(error); 1344 return ERR_PTR(error);
1348} 1345}
1349 1346
1350EXPORT_SYMBOL(open_bdev_excl); 1347EXPORT_SYMBOL(open_bdev_exclusive);
1351 1348
1352/** 1349/**
1353 * close_bdev_excl - release a blockdevice openen by open_bdev_excl() 1350 * close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive()
1354 * 1351 *
1355 * @bdev: blockdevice to close 1352 * @bdev: blockdevice to close
1353 * @mode: mode, must match that used to open.
1356 * 1354 *
1357 * This is the counterpart to open_bdev_excl(). 1355 * This is the counterpart to open_bdev_exclusive().
1358 */ 1356 */
1359void close_bdev_excl(struct block_device *bdev) 1357void close_bdev_exclusive(struct block_device *bdev, fmode_t mode)
1360{ 1358{
1361 bd_release(bdev); 1359 bd_release(bdev);
1362 blkdev_put(bdev, 0); /* move up in the next patches */ 1360 blkdev_put(bdev, mode);
1363} 1361}
1364 1362
1365EXPORT_SYMBOL(close_bdev_excl); 1363EXPORT_SYMBOL(close_bdev_exclusive);
1366 1364
1367int __invalidate_device(struct block_device *bdev) 1365int __invalidate_device(struct block_device *bdev)
1368{ 1366{
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 3261518478f4..70b896076676 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2628,7 +2628,8 @@ static int journal_init_dev(struct super_block *super,
2628 return 0; 2628 return 0;
2629 } 2629 }
2630 2630
2631 journal->j_dev_bd = open_bdev_excl(jdev_name, 0, journal); 2631 journal->j_dev_bd = open_bdev_exclusive(jdev_name,
2632 FMODE_READ|FMODE_WRITE, journal);
2632 if (IS_ERR(journal->j_dev_bd)) { 2633 if (IS_ERR(journal->j_dev_bd)) {
2633 result = PTR_ERR(journal->j_dev_bd); 2634 result = PTR_ERR(journal->j_dev_bd);
2634 journal->j_dev_bd = NULL; 2635 journal->j_dev_bd = NULL;
diff --git a/fs/super.c b/fs/super.c
index e931ae9511fe..0d77ac20d03e 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -760,9 +760,13 @@ int get_sb_bdev(struct file_system_type *fs_type,
760{ 760{
761 struct block_device *bdev; 761 struct block_device *bdev;
762 struct super_block *s; 762 struct super_block *s;
763 fmode_t mode = FMODE_READ;
763 int error = 0; 764 int error = 0;
764 765
765 bdev = open_bdev_excl(dev_name, flags, fs_type); 766 if (!(flags & MS_RDONLY))
767 mode |= FMODE_WRITE;
768
769 bdev = open_bdev_exclusive(dev_name, mode, fs_type);
766 if (IS_ERR(bdev)) 770 if (IS_ERR(bdev))
767 return PTR_ERR(bdev); 771 return PTR_ERR(bdev);
768 772
@@ -785,11 +789,12 @@ int get_sb_bdev(struct file_system_type *fs_type,
785 goto error_bdev; 789 goto error_bdev;
786 } 790 }
787 791
788 close_bdev_excl(bdev); 792 close_bdev_exclusive(bdev, mode);
789 } else { 793 } else {
790 char b[BDEVNAME_SIZE]; 794 char b[BDEVNAME_SIZE];
791 795
792 s->s_flags = flags; 796 s->s_flags = flags;
797 s->s_mode = mode;
793 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); 798 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
794 sb_set_blocksize(s, block_size(bdev)); 799 sb_set_blocksize(s, block_size(bdev));
795 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); 800 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
@@ -807,7 +812,7 @@ int get_sb_bdev(struct file_system_type *fs_type,
807error_s: 812error_s:
808 error = PTR_ERR(s); 813 error = PTR_ERR(s);
809error_bdev: 814error_bdev:
810 close_bdev_excl(bdev); 815 close_bdev_exclusive(bdev, mode);
811error: 816error:
812 return error; 817 return error;
813} 818}
@@ -817,10 +822,11 @@ EXPORT_SYMBOL(get_sb_bdev);
817void kill_block_super(struct super_block *sb) 822void kill_block_super(struct super_block *sb)
818{ 823{
819 struct block_device *bdev = sb->s_bdev; 824 struct block_device *bdev = sb->s_bdev;
825 fmode_t mode = sb->s_mode;
820 826
821 generic_shutdown_super(sb); 827 generic_shutdown_super(sb);
822 sync_blockdev(bdev); 828 sync_blockdev(bdev);
823 close_bdev_excl(bdev); 829 close_bdev_exclusive(bdev, mode);
824} 830}
825 831
826EXPORT_SYMBOL(kill_block_super); 832EXPORT_SYMBOL(kill_block_super);
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index e39013619b26..37ebe36056eb 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -589,7 +589,7 @@ xfs_blkdev_get(
589{ 589{
590 int error = 0; 590 int error = 0;
591 591
592 *bdevp = open_bdev_excl(name, 0, mp); 592 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
593 if (IS_ERR(*bdevp)) { 593 if (IS_ERR(*bdevp)) {
594 error = PTR_ERR(*bdevp); 594 error = PTR_ERR(*bdevp);
595 printk("XFS: Invalid device [%s], error=%d\n", name, error); 595 printk("XFS: Invalid device [%s], error=%d\n", name, error);
@@ -603,7 +603,7 @@ xfs_blkdev_put(
603 struct block_device *bdev) 603 struct block_device *bdev)
604{ 604{
605 if (bdev) 605 if (bdev)
606 close_bdev_excl(bdev); 606 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
607} 607}
608 608
609/* 609/*