aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
1209{
1210 struct block_device *bdev;
1211 int err;
1212
1213 bdev = lookup_bdev(path);
1214 if (IS_ERR(bdev))
1215 return bdev;
1216
1217 err = blkdev_get(bdev, mode, holder);
1218 if (err)
1219 return ERR_PTR(err);
1220
1221 return bdev;
1222}
1223EXPORT_SYMBOL(blkdev_get_by_path);
1224
1225/**
1226 * blkdev_get_by_dev - open a block device by device number
1227 * @dev: device number of block device to open
1228 * @mode: FMODE_* mask
1229 * @holder: exclusive holder identifier
1230 *
1231 * Open the blockdevice described by device number @dev. @mode and
1232 * @holder are identical to blkdev_get().
1233 *
1234 * Use it ONLY if you really do not have anything better - i.e. when
1235 * you are behind a truly sucky interface and all you are given is a
1236 * device number. _Never_ to be used for internal purposes. If you
1237 * ever need it - reconsider your API.
1238 *
1239 * On success, the returned block_device has reference count of one.
1240 *
1241 * CONTEXT:
1242 * Might sleep.
1243 *
1244 * RETURNS:
1245 * Pointer to block_device on success, ERR_PTR(-errno) on failure.
1246 */
1247struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)
1248{
1249 struct block_device *bdev;
1250 int err;
1251
1252 bdev = bdget(dev);
1253 if (!bdev)
1254 return ERR_PTR(-ENOMEM);
1255
1256 err = blkdev_get(bdev, mode, holder);
1257 if (err)
1258 return ERR_PTR(err);
1259
1260 return bdev;
1261}
1262EXPORT_SYMBOL(blkdev_get_by_dev);
1263
1189static int blkdev_open(struct inode * inode, struct file * filp) 1264static int blkdev_open(struct inode * inode, struct file * filp)
1190{ 1265{
1191 struct block_device *bdev; 1266 struct block_device *bdev;
@@ -1436,34 +1511,6 @@ fail:
1436} 1511}
1437EXPORT_SYMBOL(lookup_bdev); 1512EXPORT_SYMBOL(lookup_bdev);
1438 1513
1439/**
1440 * open_bdev_exclusive - open a block device by name and set it up for use
1441 *
1442 * @path: special file representing the block device
1443 * @mode: FMODE_... combination to pass be used
1444 * @holder: owner for exclusion
1445 *
1446 * Open the blockdevice described by the special file at @path, claim it
1447 * for the @holder.
1448 */
1449struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder)
1450{
1451 struct block_device *bdev;
1452 int error;
1453
1454 bdev = lookup_bdev(path);
1455 if (IS_ERR(bdev))
1456 return bdev;
1457
1458 error = blkdev_get(bdev, mode | FMODE_EXCL, holder);
1459 if (error)
1460 return ERR_PTR(error);
1461
1462 return bdev;
1463}
1464
1465EXPORT_SYMBOL(open_bdev_exclusive);
1466
1467int __invalidate_device(struct block_device *bdev) 1514int __invalidate_device(struct block_device *bdev)
1468{ 1515{
1469 struct super_block *sb = get_super(bdev); 1516 struct super_block *sb = get_super(bdev);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f1b729d3b883..95324e9f9280 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -489,7 +489,7 @@ again:
489 continue; 489 continue;
490 490
491 if (device->bdev) { 491 if (device->bdev) {
492 blkdev_put(device->bdev, device->mode | FMODE_EXCL); 492 blkdev_put(device->bdev, device->mode);
493 device->bdev = NULL; 493 device->bdev = NULL;
494 fs_devices->open_devices--; 494 fs_devices->open_devices--;
495 } 495 }
@@ -523,7 +523,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
523 523
524 list_for_each_entry(device, &fs_devices->devices, dev_list) { 524 list_for_each_entry(device, &fs_devices->devices, dev_list) {
525 if (device->bdev) { 525 if (device->bdev) {
526 blkdev_put(device->bdev, device->mode | FMODE_EXCL); 526 blkdev_put(device->bdev, device->mode);
527 fs_devices->open_devices--; 527 fs_devices->open_devices--;
528 } 528 }
529 if (device->writeable) { 529 if (device->writeable) {
@@ -580,13 +580,15 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
580 int seeding = 1; 580 int seeding = 1;
581 int ret = 0; 581 int ret = 0;
582 582
583 flags |= FMODE_EXCL;
584
583 list_for_each_entry(device, head, dev_list) { 585 list_for_each_entry(device, head, dev_list) {
584 if (device->bdev) 586 if (device->bdev)
585 continue; 587 continue;
586 if (!device->name) 588 if (!device->name)
587 continue; 589 continue;
588 590
589 bdev = open_bdev_exclusive(device->name, flags, holder); 591 bdev = blkdev_get_by_path(device->name, flags, holder);
590 if (IS_ERR(bdev)) { 592 if (IS_ERR(bdev)) {
591 printk(KERN_INFO "open %s failed\n", device->name); 593 printk(KERN_INFO "open %s failed\n", device->name);
592 goto error; 594 goto error;
@@ -638,7 +640,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
638error_brelse: 640error_brelse:
639 brelse(bh); 641 brelse(bh);
640error_close: 642error_close:
641 blkdev_put(bdev, flags | FMODE_EXCL); 643 blkdev_put(bdev, flags);
642error: 644error:
643 continue; 645 continue;
644 } 646 }
@@ -684,7 +686,8 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
684 686
685 mutex_lock(&uuid_mutex); 687 mutex_lock(&uuid_mutex);
686 688
687 bdev = open_bdev_exclusive(path, flags, holder); 689 flags |= FMODE_EXCL;
690 bdev = blkdev_get_by_path(path, flags, holder);
688 691
689 if (IS_ERR(bdev)) { 692 if (IS_ERR(bdev)) {
690 ret = PTR_ERR(bdev); 693 ret = PTR_ERR(bdev);
@@ -716,7 +719,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
716 719
717 brelse(bh); 720 brelse(bh);
718error_close: 721error_close:
719 blkdev_put(bdev, flags | FMODE_EXCL); 722 blkdev_put(bdev, flags);
720error: 723error:
721 mutex_unlock(&uuid_mutex); 724 mutex_unlock(&uuid_mutex);
722 return ret; 725 return ret;
@@ -1179,8 +1182,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1179 goto out; 1182 goto out;
1180 } 1183 }
1181 } else { 1184 } else {
1182 bdev = open_bdev_exclusive(device_path, FMODE_READ, 1185 bdev = blkdev_get_by_path(device_path, FMODE_READ | FMODE_EXCL,
1183 root->fs_info->bdev_holder); 1186 root->fs_info->bdev_holder);
1184 if (IS_ERR(bdev)) { 1187 if (IS_ERR(bdev)) {
1185 ret = PTR_ERR(bdev); 1188 ret = PTR_ERR(bdev);
1186 goto out; 1189 goto out;
@@ -1244,7 +1247,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1244 root->fs_info->fs_devices->latest_bdev = next_device->bdev; 1247 root->fs_info->fs_devices->latest_bdev = next_device->bdev;
1245 1248
1246 if (device->bdev) { 1249 if (device->bdev) {
1247 blkdev_put(device->bdev, device->mode | FMODE_EXCL); 1250 blkdev_put(device->bdev, device->mode);
1248 device->bdev = NULL; 1251 device->bdev = NULL;
1249 device->fs_devices->open_devices--; 1252 device->fs_devices->open_devices--;
1250 } 1253 }
@@ -1439,7 +1442,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
1439 if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding) 1442 if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding)
1440 return -EINVAL; 1443 return -EINVAL;
1441 1444
1442 bdev = open_bdev_exclusive(device_path, 0, root->fs_info->bdev_holder); 1445 bdev = blkdev_get_by_path(device_path, FMODE_EXCL,
1446 root->fs_info->bdev_holder);
1443 if (IS_ERR(bdev)) 1447 if (IS_ERR(bdev))
1444 return PTR_ERR(bdev); 1448 return PTR_ERR(bdev);
1445 1449
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2b638b6e4eea..856e75770304 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -49,7 +49,7 @@ struct btrfs_device {
49 49
50 struct block_device *bdev; 50 struct block_device *bdev;
51 51
52 /* the mode sent to open_bdev_exclusive */ 52 /* the mode sent to blkdev_get */
53 fmode_t mode; 53 fmode_t mode;
54 54
55 char *name; 55 char *name;
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 23e7513dba9c..123720ba786d 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -347,7 +347,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev, struct super_block *sb)
347 struct block_device *bdev; 347 struct block_device *bdev;
348 char b[BDEVNAME_SIZE]; 348 char b[BDEVNAME_SIZE];
349 349
350 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); 350 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
351 if (IS_ERR(bdev)) 351 if (IS_ERR(bdev))
352 goto fail; 352 goto fail;
353 return bdev; 353 return bdev;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 5dd0b3e76fa8..bd63e6927219 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -647,7 +647,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
647 struct block_device *bdev; 647 struct block_device *bdev;
648 char b[BDEVNAME_SIZE]; 648 char b[BDEVNAME_SIZE];
649 649
650 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); 650 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
651 if (IS_ERR(bdev)) 651 if (IS_ERR(bdev))
652 goto fail; 652 goto fail;
653 return bdev; 653 return bdev;
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index c1f0763a022b..bc56ccf98ffd 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1268,7 +1268,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
1268{ 1268{
1269 struct block_device *bdev; 1269 struct block_device *bdev;
1270 struct super_block *s; 1270 struct super_block *s;
1271 fmode_t mode = FMODE_READ; 1271 fmode_t mode = FMODE_READ | FMODE_EXCL;
1272 int error; 1272 int error;
1273 struct gfs2_args args; 1273 struct gfs2_args args;
1274 struct gfs2_sbd *sdp; 1274 struct gfs2_sbd *sdp;
@@ -1276,7 +1276,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
1276 if (!(flags & MS_RDONLY)) 1276 if (!(flags & MS_RDONLY))
1277 mode |= FMODE_WRITE; 1277 mode |= FMODE_WRITE;
1278 1278
1279 bdev = open_bdev_exclusive(dev_name, mode, fs_type); 1279 bdev = blkdev_get_by_path(dev_name, mode, fs_type);
1280 if (IS_ERR(bdev)) 1280 if (IS_ERR(bdev))
1281 return ERR_CAST(bdev); 1281 return ERR_CAST(bdev);
1282 1282
@@ -1298,7 +1298,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
1298 goto error_bdev; 1298 goto error_bdev;
1299 1299
1300 if (s->s_root) 1300 if (s->s_root)
1301 blkdev_put(bdev, mode | FMODE_EXCL); 1301 blkdev_put(bdev, mode);
1302 1302
1303 memset(&args, 0, sizeof(args)); 1303 memset(&args, 0, sizeof(args));
1304 args.ar_quota = GFS2_QUOTA_DEFAULT; 1304 args.ar_quota = GFS2_QUOTA_DEFAULT;
@@ -1342,7 +1342,7 @@ error_super:
1342 deactivate_locked_super(s); 1342 deactivate_locked_super(s);
1343 return ERR_PTR(error); 1343 return ERR_PTR(error);
1344error_bdev: 1344error_bdev:
1345 blkdev_put(bdev, mode | FMODE_EXCL); 1345 blkdev_put(bdev, mode);
1346 return ERR_PTR(error); 1346 return ERR_PTR(error);
1347} 1347}
1348 1348
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 5a290f22dcc3..278e3fb40b71 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1120,8 +1120,8 @@ int lmLogOpen(struct super_block *sb)
1120 * file systems to log may have n-to-1 relationship; 1120 * file systems to log may have n-to-1 relationship;
1121 */ 1121 */
1122 1122
1123 bdev = open_by_devnum(sbi->logdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, 1123 bdev = blkdev_get_by_dev(sbi->logdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
1124 log); 1124 log);
1125 if (IS_ERR(bdev)) { 1125 if (IS_ERR(bdev)) {
1126 rc = -PTR_ERR(bdev); 1126 rc = -PTR_ERR(bdev);
1127 goto free; 1127 goto free;
diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index 734b9025858e..723bc5bca09a 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -325,7 +325,8 @@ int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type,
325{ 325{
326 struct block_device *bdev; 326 struct block_device *bdev;
327 327
328 bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, type); 328 bdev = blkdev_get_by_path(devname, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
329 type);
329 if (IS_ERR(bdev)) 330 if (IS_ERR(bdev))
330 return PTR_ERR(bdev); 331 return PTR_ERR(bdev);
331 332
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 756a6798d7c8..0030640e2d72 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -1147,14 +1147,14 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1147{ 1147{
1148 struct nilfs_super_data sd; 1148 struct nilfs_super_data sd;
1149 struct super_block *s; 1149 struct super_block *s;
1150 fmode_t mode = FMODE_READ; 1150 fmode_t mode = FMODE_READ | FMODE_EXCL;
1151 struct dentry *root_dentry; 1151 struct dentry *root_dentry;
1152 int err, s_new = false; 1152 int err, s_new = false;
1153 1153
1154 if (!(flags & MS_RDONLY)) 1154 if (!(flags & MS_RDONLY))
1155 mode |= FMODE_WRITE; 1155 mode |= FMODE_WRITE;
1156 1156
1157 sd.bdev = open_bdev_exclusive(dev_name, mode, fs_type); 1157 sd.bdev = blkdev_get_by_path(dev_name, mode, fs_type);
1158 if (IS_ERR(sd.bdev)) 1158 if (IS_ERR(sd.bdev))
1159 return ERR_CAST(sd.bdev); 1159 return ERR_CAST(sd.bdev);
1160 1160
@@ -1233,7 +1233,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1233 } 1233 }
1234 1234
1235 if (!s_new) 1235 if (!s_new)
1236 blkdev_put(sd.bdev, mode | FMODE_EXCL); 1236 blkdev_put(sd.bdev, mode);
1237 1237
1238 return root_dentry; 1238 return root_dentry;
1239 1239
@@ -1242,7 +1242,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1242 1242
1243 failed: 1243 failed:
1244 if (!s_new) 1244 if (!s_new)
1245 blkdev_put(sd.bdev, mode | FMODE_EXCL); 1245 blkdev_put(sd.bdev, mode);
1246 return ERR_PTR(err); 1246 return ERR_PTR(err);
1247} 1247}
1248 1248
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index b488136f5ace..e2fce519c0f2 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2585,7 +2585,8 @@ static int journal_init_dev(struct super_block *super,
2585 if ((!jdev_name || !jdev_name[0])) { 2585 if ((!jdev_name || !jdev_name[0])) {
2586 if (jdev == super->s_dev) 2586 if (jdev == super->s_dev)
2587 blkdev_mode &= ~FMODE_EXCL; 2587 blkdev_mode &= ~FMODE_EXCL;
2588 journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode, journal); 2588 journal->j_dev_bd = blkdev_get_by_dev(jdev, blkdev_mode,
2589 journal);
2589 journal->j_dev_mode = blkdev_mode; 2590 journal->j_dev_mode = blkdev_mode;
2590 if (IS_ERR(journal->j_dev_bd)) { 2591 if (IS_ERR(journal->j_dev_bd)) {
2591 result = PTR_ERR(journal->j_dev_bd); 2592 result = PTR_ERR(journal->j_dev_bd);
@@ -2601,8 +2602,7 @@ static int journal_init_dev(struct super_block *super,
2601 } 2602 }
2602 2603
2603 journal->j_dev_mode = blkdev_mode; 2604 journal->j_dev_mode = blkdev_mode;
2604 journal->j_dev_bd = open_bdev_exclusive(jdev_name, 2605 journal->j_dev_bd = blkdev_get_by_path(jdev_name, blkdev_mode, journal);
2605 blkdev_mode, journal);
2606 if (IS_ERR(journal->j_dev_bd)) { 2606 if (IS_ERR(journal->j_dev_bd)) {
2607 result = PTR_ERR(journal->j_dev_bd); 2607 result = PTR_ERR(journal->j_dev_bd);
2608 journal->j_dev_bd = NULL; 2608 journal->j_dev_bd = NULL;
diff --git a/fs/super.c b/fs/super.c
index 22374bf0ba87..5d9a4497849a 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -766,13 +766,13 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
766{ 766{
767 struct block_device *bdev; 767 struct block_device *bdev;
768 struct super_block *s; 768 struct super_block *s;
769 fmode_t mode = FMODE_READ; 769 fmode_t mode = FMODE_READ | FMODE_EXCL;
770 int error = 0; 770 int error = 0;
771 771
772 if (!(flags & MS_RDONLY)) 772 if (!(flags & MS_RDONLY))
773 mode |= FMODE_WRITE; 773 mode |= FMODE_WRITE;
774 774
775 bdev = open_bdev_exclusive(dev_name, mode, fs_type); 775 bdev = blkdev_get_by_path(dev_name, mode, fs_type);
776 if (IS_ERR(bdev)) 776 if (IS_ERR(bdev))
777 return ERR_CAST(bdev); 777 return ERR_CAST(bdev);
778 778
@@ -807,7 +807,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
807 * holding an active reference. 807 * holding an active reference.
808 */ 808 */
809 up_write(&s->s_umount); 809 up_write(&s->s_umount);
810 blkdev_put(bdev, mode | FMODE_EXCL); 810 blkdev_put(bdev, mode);
811 down_write(&s->s_umount); 811 down_write(&s->s_umount);
812 } else { 812 } else {
813 char b[BDEVNAME_SIZE]; 813 char b[BDEVNAME_SIZE];
@@ -831,7 +831,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
831error_s: 831error_s:
832 error = PTR_ERR(s); 832 error = PTR_ERR(s);
833error_bdev: 833error_bdev:
834 blkdev_put(bdev, mode | FMODE_EXCL); 834 blkdev_put(bdev, mode);
835error: 835error:
836 return ERR_PTR(error); 836 return ERR_PTR(error);
837} 837}
@@ -862,6 +862,7 @@ void kill_block_super(struct super_block *sb)
862 bdev->bd_super = NULL; 862 bdev->bd_super = NULL;
863 generic_shutdown_super(sb); 863 generic_shutdown_super(sb);
864 sync_blockdev(bdev); 864 sync_blockdev(bdev);
865 WARN_ON_ONCE(!(mode & FMODE_EXCL));
865 blkdev_put(bdev, mode | FMODE_EXCL); 866 blkdev_put(bdev, mode | FMODE_EXCL);
866} 867}
867 868
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index a1a6e5ceea67..9209cd199c47 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -609,7 +609,8 @@ xfs_blkdev_get(
609{ 609{
610 int error = 0; 610 int error = 0;
611 611
612 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp); 612 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
613 mp);
613 if (IS_ERR(*bdevp)) { 614 if (IS_ERR(*bdevp)) {
614 error = PTR_ERR(*bdevp); 615 error = PTR_ERR(*bdevp);
615 printk("XFS: Invalid device [%s], error=%d\n", name, error); 616 printk("XFS: Invalid device [%s], error=%d\n", name, error);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1a033e8ebe4c..f48501563917 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2006,8 +2006,6 @@ extern struct block_device *bdgrab(struct block_device *bdev);
2006extern void bd_set_size(struct block_device *, loff_t size); 2006extern void bd_set_size(struct block_device *, loff_t size);
2007extern void bd_forget(struct inode *inode); 2007extern void bd_forget(struct inode *inode);
2008extern void bdput(struct block_device *); 2008extern void bdput(struct block_device *);
2009extern struct block_device *open_by_devnum(dev_t dev, fmode_t mode,
2010 void *holder);
2011extern void invalidate_bdev(struct block_device *); 2009extern void invalidate_bdev(struct block_device *);
2012extern int sync_blockdev(struct block_device *bdev); 2010extern int sync_blockdev(struct block_device *bdev);
2013extern struct super_block *freeze_bdev(struct block_device *); 2011extern struct super_block *freeze_bdev(struct block_device *);
@@ -2039,6 +2037,10 @@ extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
2039extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); 2037extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
2040extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 2038extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
2041extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder); 2039extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
2040extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
2041 void *holder);
2042extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
2043 void *holder);
2042extern int blkdev_put(struct block_device *bdev, fmode_t mode); 2044extern int blkdev_put(struct block_device *bdev, fmode_t mode);
2043#ifdef CONFIG_SYSFS 2045#ifdef CONFIG_SYSFS
2044extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk); 2046extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
@@ -2083,7 +2085,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name)
2083extern const char *__bdevname(dev_t, char *buffer); 2085extern const char *__bdevname(dev_t, char *buffer);
2084extern const char *bdevname(struct block_device *bdev, char *buffer); 2086extern const char *bdevname(struct block_device *bdev, char *buffer);
2085extern struct block_device *lookup_bdev(const char *); 2087extern struct block_device *lookup_bdev(const char *);
2086extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *);
2087extern void blkdev_show(struct seq_file *,off_t); 2088extern void blkdev_show(struct seq_file *,off_t);
2088 2089
2089#else 2090#else
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 513a77f1a0b3..b019609d1b45 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -907,8 +907,8 @@ int swsusp_check(void)
907{ 907{
908 int error; 908 int error;
909 909
910 hib_resume_bdev = open_by_devnum(swsusp_resume_device, 910 hib_resume_bdev = blkdev_get_by_dev(swsusp_resume_device,
911 FMODE_READ, NULL); 911 FMODE_READ, NULL);
912 if (!IS_ERR(hib_resume_bdev)) { 912 if (!IS_ERR(hib_resume_bdev)) {
913 set_blocksize(hib_resume_bdev, PAGE_SIZE); 913 set_blocksize(hib_resume_bdev, PAGE_SIZE);
914 clear_page(swsusp_header); 914 clear_page(swsusp_header);