aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/block_dev.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index fe41a76769fa..fe09ef9c21f3 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1058,6 +1058,27 @@ retry:
1058 return 0; 1058 return 0;
1059} 1059}
1060 1060
1061static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno)
1062{
1063 struct gendisk *disk = get_gendisk(bdev->bd_dev, partno);
1064
1065 if (!disk)
1066 return NULL;
1067 /*
1068 * Now that we hold gendisk reference we make sure bdev we looked up is
1069 * not stale. If it is, it means device got removed and created before
1070 * we looked up gendisk and we fail open in such case. Associating
1071 * unhashed bdev with newly created gendisk could lead to two bdevs
1072 * (and thus two independent caches) being associated with one device
1073 * which is bad.
1074 */
1075 if (inode_unhashed(bdev->bd_inode)) {
1076 put_disk_and_module(disk);
1077 return NULL;
1078 }
1079 return disk;
1080}
1081
1061/** 1082/**
1062 * bd_start_claiming - start claiming a block device 1083 * bd_start_claiming - start claiming a block device
1063 * @bdev: block device of interest 1084 * @bdev: block device of interest
@@ -1094,7 +1115,7 @@ static struct block_device *bd_start_claiming(struct block_device *bdev,
1094 * @bdev might not have been initialized properly yet, look up 1115 * @bdev might not have been initialized properly yet, look up
1095 * and grab the outer block device the hard way. 1116 * and grab the outer block device the hard way.
1096 */ 1117 */
1097 disk = get_gendisk(bdev->bd_dev, &partno); 1118 disk = bdev_get_gendisk(bdev, &partno);
1098 if (!disk) 1119 if (!disk)
1099 return ERR_PTR(-ENXIO); 1120 return ERR_PTR(-ENXIO);
1100 1121
@@ -1429,7 +1450,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1429 restart: 1450 restart:
1430 1451
1431 ret = -ENXIO; 1452 ret = -ENXIO;
1432 disk = get_gendisk(bdev->bd_dev, &partno); 1453 disk = bdev_get_gendisk(bdev, &partno);
1433 if (!disk) 1454 if (!disk)
1434 goto out; 1455 goto out;
1435 1456