Linux block layer
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: Jan Kara <jack@suse.cz>, Christoph Hellwig <hch@infradead.org>,
	Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] block: Do not reread partition table on exclusively open device
Date: Thu, 9 Feb 2023 10:57:29 +0100	[thread overview]
Message-ID: <20230209095729.igkpj23afj6nbxxi@quack3> (raw)
In-Reply-To: <1bf91d5c-6130-43de-7995-af09045d4b98@huaweicloud.com>

On Thu 09-02-23 17:32:45, Yu Kuai wrote:
> 在 2023/02/09 17:04, Jan Kara 写道:
> > On Wed 08-02-23 22:13:02, Yu Kuai wrote:
> > > Hi,
> > > 
> > > 在 2023/02/08 20:02, Jan Kara 写道:
> > > > 
> > > > After some thought I don't like opencoding blkdev_get_by_dev() in disk_scan
> > > > partitions. But I agree Christoph's approach with blkdev_get_whole() does
> > > > not quite work either. We could propagate holder/owner into
> > > > blkdev_get_whole() to fix Christoph's check but still we are left with a
> > > > question what to do with GD_NEED_PART_SCAN set bit when we get into
> > > > blkdev_get_whole() and find out we are not elligible to rescan partitions.
> > > > Because then some exclusive opener later might be caught by surprise when
> > > > the partition rescan happens due to this bit being set from the past failed
> > > > attempt to rescan.
> > > > 
> > > > So what we could do is play a similar trick as we do in the loop device and
> > > > do in disk_scan_partitions():
> > > > 
> > > > 	/*
> > > > 	 * If we don't hold exclusive handle for the device, upgrade to it
> > > > 	 * here to avoid changing partitions under exclusive owner.
> > > > 	 */
> > > > 	if (!(mode & FMODE_EXCL)) {
> > > This is not necessary, all the caller make sure FMODE_EXCL is not set.
> > 
> > Yes, but we need to propagate it correctly from blkdev_common_ioctl() now,
> > exactly so that ioctl does not fail if you exclusively opened the device as
> > you realized below :)
> 
> Ok, I get it that you want to pass in FMODE_EXCL from ioctl(). But I'm
> not sure let others fail to open device extl is a good idea.

Other exclusive openers will not fail. They will block until we call
bd_abort_claiming() after the partitions have been reread.

> I still prefer to open code blkdev_get_by_dev(), because many operations
> is not necessary here. And this way, we can clear GD_NEED_PART_SCAN
> inside open_mutex if rescan failed.

I understand many operations are not needed there but this is not a hot
path and leaking of bdev internal details into genhd.c is not a good
practice either (e.g. you'd have to make blkdev_get_whole() extern).

We could create a special helper for partition rescan in block/bdev.c to
hide the details but think that bd_start_claiming() - bd_abort_claiming()
trick is the simplest solution to temporarily grab exclusive ownership if
we don't have it.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2023-02-09  9:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 17:56 [PATCH] block: Do not reread partition table on exclusively open device Jan Kara
2022-11-30 22:52 ` Jens Axboe
2022-11-30 22:54 ` Jens Axboe
2022-12-01  7:10 ` Christoph Hellwig
2022-12-01 11:44   ` Jan Kara
2023-01-31 14:00 ` Yu Kuai
2023-01-31 14:15   ` Christoph Hellwig
2023-02-01  1:04     ` Yu Kuai
2023-02-01  6:22       ` Christoph Hellwig
2023-02-01  7:20         ` Yu Kuai
2023-02-06  3:24           ` Yu Kuai
2023-02-08 12:02             ` Jan Kara
2023-02-08 14:13               ` Yu Kuai
2023-02-09  9:04                 ` Jan Kara
2023-02-09  9:32                   ` Yu Kuai
2023-02-09  9:57                     ` Jan Kara [this message]
2023-02-09 11:19                       ` Yu Kuai
2023-02-09 13:58                         ` Jan Kara
2023-02-10  1:58                           ` Yu Kuai
2023-02-10 10:31                             ` Jan Kara
2023-02-11  3:46                               ` Yu Kuai
2023-02-02 12:50 ` Yu Kuai

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=20230209095729.igkpj23afj6nbxxi@quack3 \
    --to=jack@suse.cz \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=yukuai1@huaweicloud.com \
    --cc=yukuai3@huawei.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