Commit 4601b4b1 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: reopen the device in blkdev_reread_part

Historically the BLKRRPART ioctls called into the now defunct ->revalidate
method, which caused the sd driver to check if any media is present.
When the ->revalidate method was removed this revalidation was lost,
leading to lots of I/O errors when using the eject command.  Fix this by
reopening the device to rescan the partitions, and thus calling the
revalidation logic in the sd driver.

Fixes: 471bd0af ("sd: use bdev_check_media_change")
Reported--by: default avatarTom Seewald <tseewald@gmail.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Tested-by: default avatarTom Seewald <tseewald@gmail.com>
Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
Reviewed-by: default avatarMinwoo Im <minwoo.im.dev@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 75ab6afa
...@@ -81,20 +81,27 @@ static int compat_blkpg_ioctl(struct block_device *bdev, ...@@ -81,20 +81,27 @@ static int compat_blkpg_ioctl(struct block_device *bdev,
} }
#endif #endif
static int blkdev_reread_part(struct block_device *bdev) static int blkdev_reread_part(struct block_device *bdev, fmode_t mode)
{ {
int ret; struct block_device *tmp;
if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev)) if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev))
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
mutex_lock(&bdev->bd_mutex); /*
ret = bdev_disk_changed(bdev, false); * Reopen the device to revalidate the driver state and force a
mutex_unlock(&bdev->bd_mutex); * partition rescan.
*/
mode &= ~FMODE_EXCL;
set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
return ret; tmp = blkdev_get_by_dev(bdev->bd_dev, mode, NULL);
if (IS_ERR(tmp))
return PTR_ERR(tmp);
blkdev_put(tmp, mode);
return 0;
} }
static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
...@@ -498,7 +505,7 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -498,7 +505,7 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE;
return 0; return 0;
case BLKRRPART: case BLKRRPART:
return blkdev_reread_part(bdev); return blkdev_reread_part(bdev, mode);
case BLKTRACESTART: case BLKTRACESTART:
case BLKTRACESTOP: case BLKTRACESTOP:
case BLKTRACETEARDOWN: case BLKTRACETEARDOWN:
......
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