All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Seewald <tseewald@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-block@vger.kernel.org, axboe@kernel.dk
Subject: Re: [Regression] [Bisected] Errors when ejecting USB storage drives since v5.10
Date: Mon, 22 Feb 2021 12:27:40 -0600	[thread overview]
Message-ID: <940375ab-2a92-6e09-9746-e87e8ea8c7fc@gmail.com> (raw)
In-Reply-To: <20210222114455.GA1749@lst.de>

On 2/22/21 5:44 AM, Christoph Hellwig wrote:

> Ok, let's try something else entirely, which restores the full revalidation
> that BLKRRPART previously caused by accident:
>
> diff --git a/block/ioctl.c b/block/ioctl.c
> index d61d652078f41c..06b2ecdce593c6 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -81,20 +81,25 @@ 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);
> -
> -	return ret;
> +	/*
> +	 * Reopen the device to revalidate the driver state and force a
> +	 * partition rescan.
> +	 */
> +	set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
> +	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 +503,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 & ~FMODE_EXCL);
>  	case BLKTRACESTART:
>  	case BLKTRACESTOP:
>  	case BLKTRACETEARDOWN:
I can confirm the above patch results in my USB drives being unmounted cleanly
and there are no errors in dmesg afterwards. One minor nit I have noticed is
that after ejecting the device, the kernel still reports:

"sde: detected capacity change from 0 to 62333952"

This appears to be reversed from what was previously reported by the kernel in
v5.9 and earlier. I would expect that after ejection it would report:

"sde: detected capacity change from 62333952 to 0"

This appears to be purely cosmetic and it is not something your above patch
introduced so you can add Tested-by: Tom Seewald <tseewald@gmail.com> if you
wish. Thank you again for your help.

      reply	other threads:[~2021-02-22 18:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12  5:42 [Regression] [Bisected] Errors when ejecting USB storage drives since v5.10 Tom Seewald
2021-02-16 12:15 ` Christoph Hellwig
2021-02-16 12:37 ` Christoph Hellwig
2021-02-16 20:01   ` Tom Seewald
2021-02-17  2:11   ` Tom Seewald
2021-02-22 11:44     ` Christoph Hellwig
2021-02-22 18:27       ` Tom Seewald [this message]

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=940375ab-2a92-6e09-9746-e87e8ea8c7fc@gmail.com \
    --to=tseewald@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.