Commit 731dc486 authored by Jan Kara's avatar Jan Kara Committed by Jens Axboe

bdev: Factor out bdev revalidation into a common helper

Factor out code handling revalidation of bdev on disk change into a
common helper.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8962842c
...@@ -1512,6 +1512,14 @@ EXPORT_SYMBOL(bd_set_size); ...@@ -1512,6 +1512,14 @@ EXPORT_SYMBOL(bd_set_size);
static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
static void bdev_disk_changed(struct block_device *bdev, bool invalidate)
{
if (invalidate)
invalidate_partitions(bdev->bd_disk, bdev);
else
rescan_partitions(bdev->bd_disk, bdev);
}
/* /*
* bd_mutex locking: * bd_mutex locking:
* *
...@@ -1594,12 +1602,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1594,12 +1602,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
* The latter is necessary to prevent ghost * The latter is necessary to prevent ghost
* partitions on a removed medium. * partitions on a removed medium.
*/ */
if (bdev->bd_invalidated) { if (bdev->bd_invalidated &&
if (!ret) (!ret || ret == -ENOMEDIUM))
rescan_partitions(disk, bdev); bdev_disk_changed(bdev, ret == -ENOMEDIUM);
else if (ret == -ENOMEDIUM)
invalidate_partitions(disk, bdev);
}
if (ret) if (ret)
goto out_clear; goto out_clear;
...@@ -1632,12 +1637,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1632,12 +1637,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
if (bdev->bd_disk->fops->open) if (bdev->bd_disk->fops->open)
ret = bdev->bd_disk->fops->open(bdev, mode); ret = bdev->bd_disk->fops->open(bdev, mode);
/* the same as first opener case, read comment there */ /* the same as first opener case, read comment there */
if (bdev->bd_invalidated) { if (bdev->bd_invalidated &&
if (!ret) (!ret || ret == -ENOMEDIUM))
rescan_partitions(bdev->bd_disk, bdev); bdev_disk_changed(bdev, ret == -ENOMEDIUM);
else if (ret == -ENOMEDIUM)
invalidate_partitions(bdev->bd_disk, bdev);
}
if (ret) if (ret)
goto out_unlock_bdev; goto out_unlock_bdev;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment