From: Ming Lei <ming.lei@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
Tom Seewald <tseewald@gmail.com>
Subject: Re: [PATCH] block: reopen the device in blkdev_reread_part
Date: Wed, 24 Feb 2021 09:38:50 +0800 [thread overview]
Message-ID: <YDWuKk3SkyMCFfci@T590> (raw)
In-Reply-To: <20210223151822.399791-1-hch@lst.de>
On Tue, Feb 23, 2021 at 04:18:22PM +0100, Christoph Hellwig wrote:
> 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: 471bd0af544b ("sd: use bdev_check_media_change")
> Reported--by: Tom Seewald <tseewald@gmail.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: Tom Seewald <tseewald@gmail.com>
> ---
> block/ioctl.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/block/ioctl.c b/block/ioctl.c
> index d61d652078f41c..ff241e663c018f 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -81,20 +81,27 @@ static int compat_blkpg_ioctl(struct block_device *bdev,
> }
> #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))
> return -EINVAL;
> if (!capable(CAP_SYS_ADMIN))
> return -EACCES;
>
> - mutex_lock(&bdev->bd_mutex);
> - ret = bdev_disk_changed(bdev, false);
> - mutex_unlock(&bdev->bd_mutex);
> + /*
> + * Reopen the device to revalidate the driver state and force a
> + * 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,
> @@ -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;
> return 0;
> case BLKRRPART:
> - return blkdev_reread_part(bdev);
> + return blkdev_reread_part(bdev, mode);
> case BLKTRACESTART:
> case BLKTRACESTOP:
> case BLKTRACETEARDOWN:
> --
> 2.29.2
>
Looks fine,
Reviewed-by: Ming Lei <ming.lei@redhat.com>
--
Ming
next prev parent reply other threads:[~2021-02-24 1:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-23 15:18 [PATCH] block: reopen the device in blkdev_reread_part Christoph Hellwig
2021-02-24 1:38 ` Ming Lei [this message]
2021-02-24 1:52 ` Minwoo Im
2021-02-24 7:26 ` Christoph Hellwig
2021-02-24 8:32 ` Minwoo Im
2021-02-24 9:34 ` Minwoo Im
2021-02-24 2:23 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YDWuKk3SkyMCFfci@T590 \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=tseewald@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).