aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2010-11-13 05:55:18 -0500
committerTejun Heo <tj@kernel.org>2010-11-13 05:55:18 -0500
commitd4d77629953eabd3c14f6fa5746f6b28babfc55f (patch)
tree38cce0d4764ecb34a9f7f49332959780e28bb786
parent75f1dc0d076d1c1168f2115f1941ea627d38bd5a (diff)
block: clean up blkdev_get() wrappers and their users
After recent blkdev_get() modifications, open_by_devnum() and open_bdev_exclusive() are simple wrappers around blkdev_get(). Replace them with blkdev_get_by_dev() and blkdev_get_by_path(). blkdev_get_by_dev() is identical to open_by_devnum(). blkdev_get_by_path() is slightly different in that it doesn't automatically add %FMODE_EXCL to @mode. All users are converted. Most conversions are mechanical and don't introduce any behavior difference. There are several exceptions. * btrfs now sets FMODE_EXCL in btrfs_device->mode, so there's no reason to OR it explicitly on blkdev_put(). * gfs2, nilfs2 and the generic mount_bdev() now set FMODE_EXCL in sb->s_mode. * With the above changes, sb->s_mode now always should contain FMODE_EXCL. WARN_ON_ONCE() added to kill_block_super() to detect errors. The new blkdev_get_*() functions are with proper docbook comments. While at it, add function description to blkdev_get() too. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Philipp Reisner <philipp.reisner@linbit.com> Cc: Neil Brown <neilb@suse.de> Cc: Mike Snitzer <snitzer@redhat.com> Cc: Joern Engel <joern@lazybastard.org> Cc: Chris Mason <chris.mason@oracle.com> Cc: Jan Kara <jack@suse.cz> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: KONISHI Ryusuke <konishi.ryusuke@lab.ntt.co.jp> Cc: reiserfs-devel@vger.kernel.org Cc: xfs-masters@oss.sgi.com Cc: Alexander Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/block/drbd/drbd_nl.c12
-rw-r--r--drivers/md/dm-table.c2
-rw-r--r--drivers/md/md.c4
-rw-r--r--drivers/mtd/devices/block2mtd.c4
-rw-r--r--fs/block_dev.c139
-rw-r--r--fs/btrfs/volumes.c24
-rw-r--r--fs/btrfs/volumes.h2
-rw-r--r--fs/ext3/super.c2
-rw-r--r--fs/ext4/super.c2
-rw-r--r--fs/gfs2/ops_fstype.c8
-rw-r--r--fs/jfs/jfs_logmgr.c4
-rw-r--r--fs/logfs/dev_bdev.c3
-rw-r--r--fs/nilfs2/super.c8
-rw-r--r--fs/reiserfs/journal.c6
-rw-r--r--fs/super.c9
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c3
-rw-r--r--include/linux/fs.h7
-rw-r--r--kernel/power/swap.c4
18 files changed, 149 insertions, 94 deletions
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index fd0346090289..650e43ba4f7c 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -902,8 +902,8 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
902 } 902 }
903 } 903 }
904 904
905 bdev = open_bdev_exclusive(nbc->dc.backing_dev, 905 bdev = blkdev_get_by_path(nbc->dc.backing_dev,
906 FMODE_READ | FMODE_WRITE, mdev); 906 FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev);
907 if (IS_ERR(bdev)) { 907 if (IS_ERR(bdev)) {
908 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev, 908 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev,
909 PTR_ERR(bdev)); 909 PTR_ERR(bdev));
@@ -920,10 +920,10 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
920 * should check it for you already; but if you don't, or 920 * should check it for you already; but if you don't, or
921 * someone fooled it, we need to double check here) 921 * someone fooled it, we need to double check here)
922 */ 922 */
923 bdev = open_bdev_exclusive(nbc->dc.meta_dev, 923 bdev = blkdev_get_by_path(nbc->dc.meta_dev,
924 FMODE_READ | FMODE_WRITE, 924 FMODE_READ | FMODE_WRITE | FMODE_EXCL,
925 (nbc->dc.meta_dev_idx < 0) ? 925 (nbc->dc.meta_dev_idx < 0) ?
926 (void *)mdev : (void *)drbd_m_holder); 926 (void *)mdev : (void *)drbd_m_holder);
927 if (IS_ERR(bdev)) { 927 if (IS_ERR(bdev)) {
928 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev, 928 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev,
929 PTR_ERR(bdev)); 929 PTR_ERR(bdev));
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 9e88ca0c55e9..67150c32986c 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -325,7 +325,7 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev,
325 325
326 BUG_ON(d->dm_dev.bdev); 326 BUG_ON(d->dm_dev.bdev);
327 327
328 bdev = open_by_devnum(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr); 328 bdev = blkdev_get_by_dev(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr);
329 if (IS_ERR(bdev)) 329 if (IS_ERR(bdev))
330 return PTR_ERR(bdev); 330 return PTR_ERR(bdev);
331 331
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 6af951ffe0bb..5aaa6bfbe638 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1934,8 +1934,8 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared)
1934 struct block_device *bdev; 1934 struct block_device *bdev;
1935 char b[BDEVNAME_SIZE]; 1935 char b[BDEVNAME_SIZE];
1936 1936
1937 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, 1937 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
1938 shared ? (mdk_rdev_t *)lock_rdev : rdev); 1938 shared ? (mdk_rdev_t *)lock_rdev : rdev);
1939 if (IS_ERR(bdev)) { 1939 if (IS_ERR(bdev)) {
1940 printk(KERN_ERR "md: could not open %s.\n", 1940 printk(KERN_ERR "md: could not open %s.\n",
1941 __bdevname(dev, b)); 1941 __bdevname(dev, b));
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index aa557beb8f51..f29a6f9df6e7 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -247,7 +247,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
247 return NULL; 247 return NULL;
248 248
249 /* Get a handle on the device */ 249 /* Get a handle on the device */
250 bdev = open_bdev_exclusive(devname, mode, dev); 250 bdev = blkdev_get_by_path(devname, mode, dev);
251#ifndef MODULE 251#ifndef MODULE
252 if (IS_ERR(bdev)) { 252 if (IS_ERR(bdev)) {
253 253
@@ -256,7 +256,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
256 256
257 dev_t devt = name_to_dev_t(devname); 257 dev_t devt = name_to_dev_t(devname);
258 if (devt) 258 if (devt)
259 bdev = open_by_devnum(devt, mode, dev); 259 bdev = blkdev_get_by_dev(devt, mode, dev);
260 } 260 }
261#endif 261#endif
262 262
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 606a5259f87f..c1c1b8c3fb99 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -854,24 +854,6 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev)
854{ } 854{ }
855#endif 855#endif
856 856
857/*
858 * Tries to open block device by device number. Use it ONLY if you
859 * really do not have anything better - i.e. when you are behind a
860 * truly sucky interface and all you are given is a device number. _Never_
861 * to be used for internal purposes. If you ever need it - reconsider
862 * your API.
863 */
864struct block_device *open_by_devnum(dev_t dev, fmode_t mode, void *holder)
865{
866 struct block_device *bdev = bdget(dev);
867 int err = -ENOMEM;
868 if (bdev)
869 err = blkdev_get(bdev, mode, holder);
870 return err ? ERR_PTR(err) : bdev;
871}
872
873EXPORT_SYMBOL(open_by_devnum);
874
875/** 857/**
876 * flush_disk - invalidates all buffer-cache entries on a disk 858 * flush_disk - invalidates all buffer-cache entries on a disk
877 * 859 *
@@ -1132,6 +1114,25 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1132 return ret; 1114 return ret;
1133} 1115}
1134 1116
1117/**
1118 * blkdev_get - open a block device
1119 * @bdev: block_device to open
1120 * @mode: FMODE_* mask
1121 * @holder: exclusive holder identifier
1122 *
1123 * Open @bdev with @mode. If @mode includes %FMODE_EXCL, @bdev is
1124 * open with exclusive access. Specifying %FMODE_EXCL with %NULL
1125 * @holder is invalid. Exclusive opens may nest for the same @holder.
1126 *
1127 * On success, the reference count of @bdev is unchanged. On failure,
1128 * @bdev is put.
1129 *
1130 * CONTEXT:
1131 * Might sleep.
1132 *
1133 * RETURNS:
1134 * 0 on success, -errno on failure.
1135 */
1135int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) 1136int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
1136{ 1137{
1137 struct block_device *whole = NULL; 1138 struct block_device *whole = NULL;
@@ -1186,6 +1187,80 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
1186} 1187}
1187EXPORT_SYMBOL(blkdev_get); 1188EXPORT_SYMBOL(blkdev_get);
1188 1189
1190/**
1191 * blkdev_get_by_path - open a block device by name
1192 * @path: path to the block device to open
1193 * @mode: FMODE_* mask
1194 * @holder: exclusive holder identifier
1195 *
1196 * Open the blockdevice described by the device file at @path. @mode
1197 * and @holder are identical to blkdev_get().
1198 *
1199 * On success, the returned block_device has reference count of one.
1200 *
1201 * CONTEXT:
1202 * Might sleep.
1203 *
1204 * RETURNS:
1205 * Pointer to block_device on success, ERR_PTR(-errno) on failure.
1206 */
1207struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
1208 void *holder)