Re: [PATCH] block: Do not reread partition table on exclusively open device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On Mon 06-02-23 11:24:10, Yu Kuai wrote:
> 在 2023/02/01 15:20, Yu Kuai 写道:
> > Hi,
> > 
> > 在 2023/02/01 14:22, Christoph Hellwig 写道:
> > > On Wed, Feb 01, 2023 at 09:04:12AM +0800, Yu Kuai wrote:
> > > > > +    if (test_bit(GD_NEED_PART_SCAN, &disk->state) && !bdev->bd_holder)
> > > > >            bdev_disk_changed(disk, false);
> > > > 
> > > > I think this is wrong here... We should at least allow the exclusively
> > > > opener to scan partition, right?
> > > 
> > > bd_holder is only set in bd_finish_claiming, which is called after
> > > the partition rescan.
> > > .
> > > 
> > 
> > I mean that someone open bdev exclusively first, and then call ioctl to
> > rescan partition.
> 
> Any suggestions?

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)) {
		error = bd_prepare_to_claim(disk->part0, disk_scan_partitions);
		if (error)
			return error;
	}
	set_bit(GD_NEED_PART_SCAN, &disk->state);
	bdev = blkdev_get_by_dev(disk_devt(disk), mode & ~FMODE_EXCL, NULL);
	if (IS_ERR(bdev)) {
		error = PTR_ERR(bdev);
		goto abort;
	}
	blkdev_put(bdev, mode & ~FMODE_EXCL);
	error = 0;
abort:
	if (!(mode & FMODE_EXCL))
		bd_abort_claiming(disk->part0, disk_scan_partitions);
	return error;

So esentially we'll temporarily block any exlusive openers by claiming the
bdev while we set the GD_NEED_PART_SCAN and force partition rescan. What do
you think?

								Honza
-- 
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux