aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2008-02-22 19:50:45 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2008-10-21 07:49:00 -0400
commit30c40d2c01f68c7eb1a41ab3552bdaf5dbf300d4 (patch)
tree38b69a80c4c0df13ef3b905f5195f6cadf930223
parent9a1c3542768b5a58e45a9216921cd10a3bae1205 (diff)
[PATCH] propagate mode through open_bdev_excl/close_bdev_excl
replace open_bdev_excl/close_bdev_excl with variants taking fmode_t. superblock gets the value used to mount it stored in sb->s_mode Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/mtd/devices/block2mtd.c4
-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
-rw-r--r--include/linux/fs.h6
6 files changed, 31 insertions, 24 deletions
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 91fbba767635..8c295f40d2ac 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -224,7 +224,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
224 if (dev->blkdev) { 224 if (dev->blkdev) {
225 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, 225 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
226 0, -1); 226 0, -1);
227 close_bdev_excl(dev->blkdev); 227 close_bdev_exclusive(dev->blkdev, FMODE_READ|FMODE_WRITE);
228 } 228 }
229 229
230 kfree(dev); 230 kfree(dev);
@@ -246,7 +246,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
246 return NULL; 246 return NULL;
247 247
248 /* Get a handle on the device */ 248 /* Get a handle on the device */
249 bdev = open_bdev_excl(devname, O_RDWR, NULL); 249 bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, NULL);
250#ifndef MODULE 250#ifndef MODULE
251 if (IS_ERR(bdev)) { 251 if (IS_ERR(bdev)) {
252 252
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/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 04c8dc41f454..c6766314dc5e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1157,6 +1157,7 @@ struct super_block {
1157 char s_id[32]; /* Informational name */ 1157 char s_id[32]; /* Informational name */
1158 1158
1159 void *s_fs_info; /* Filesystem private info */ 1159 void *s_fs_info; /* Filesystem private info */
1160 fmode_t s_mode;
1160 1161
1161 /* 1162 /*
1162 * The next field is for VFS *only*. No filesystems have any business 1163 * The next field is for VFS *only*. No filesystems have any business
@@ -1753,9 +1754,10 @@ extern void chrdev_show(struct seq_file *,off_t);
1753extern const char *__bdevname(dev_t, char *buffer); 1754extern const char *__bdevname(dev_t, char *buffer);
1754extern const char *bdevname(struct block_device *bdev, char *buffer); 1755extern const char *bdevname(struct block_device *bdev, char *buffer);
1755extern struct block_device *lookup_bdev(const char *); 1756extern struct block_device *lookup_bdev(const char *);
1756extern struct block_device *open_bdev_excl(const char *, int, void *); 1757extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *);
1757extern void close_bdev_excl(struct block_device *); 1758extern void close_bdev_exclusive(struct block_device *, fmode_t);
1758extern void blkdev_show(struct seq_file *,off_t); 1759extern void blkdev_show(struct seq_file *,off_t);
1760
1759#else 1761#else
1760#define BLKDEV_MAJOR_HASH_SIZE 0 1762#define BLKDEV_MAJOR_HASH_SIZE 0
1761#endif 1763#endif