Re: [PATCH 2/2] block: loop: delete partitions after clearing & changing fd

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

 



On Wed, Jul 08, 2020 at 05:13:18PM +0800, Ming Lei wrote:
> On Tue, Jul 07, 2020 at 07:53:12PM +0200, Christoph Hellwig wrote:
> > On Tue, Jul 07, 2020 at 04:45:52PM +0800, Ming Lei wrote:
> > > After clearing fd or changing fd, we have to delete old partitions,
> > > otherwise they may become ghost partitions.
> > > 
> > > Fix this issue by clearing GENHD_FL_NO_PART_SCAN during calling
> > > bdev_disk_changed() which won't drop old partitions if GENHD_FL_NO_PART_SCAN
> > > isn't set.
> > 
> > I don't think messing with GENHD_FL_NO_PART_SCAN is a good idea, as
> > that will also cause an actual partition scan.  But except for historic
> > reasons I can't think of a good idea to even check for
> > GENHD_FL_NO_PART_SCAN in blk_drop_partitions.
> 
> I think it is safe to not check it in blk_drop_partitions(), how about
> the following patch?
> 
> From a20209464c367c338beee5555f2cb5c8e8ad9f78 Mon Sep 17 00:00:00 2001
> From: Ming Lei <ming.lei@xxxxxxxxxx>
> Date: Wed, 8 Jul 2020 16:07:19 +0800
> Subject: [PATCH] block: always remove partitions in blk_drop_partitions()
> 
> So far blk_drop_partitions() only removes partitions when
> disk_part_scan_enabled() return true. This way can make ghost partition on
> loop device after changing/clearing FD in case that PARTSCAN is disabled.
> 
> Fix this issue by always removing partitions in blk_drop_partitions(), and
> this way is correct because:
> 
> 1) only loop, mmc and GENHD_FL_HIDDEN disks(nvme multipath) may set
> GENHD_FL_NO_PART_SCAN
> 
> 2) GENHD_FL_HIDDEN disks doesn't expose disk to block device fs, and
> bdev_disk_changed()/blk_drop_partitions() won't be called for this kind of
> disk
> 
> 3) for mmc, if GENHD_FL_NO_PART_SCAN is set, no any partitions can be added
> for this kind of disk, so blk_drop_partitions() basically does nothing no
> matter if GENHD_FL_NO_PART_SCAN is set or not because disk_max_parts(disk) <= 1
> 
> 4) for loop, bdev_disk_changed() is called in two cases: one is set fd and set
> status, when there shouldn't be any partitions; another is clearing/changing fd,
> we need to remove old partitions and re-read new partitions if there are and
> PART_SCAN is enabled.

BTW, the partitions shouldn't have been added, but ioctl(BLKPG, BLKPG_ADD_PARTITION)
doesn't check GENHD_FL_NO_PART_SCAN, so the partitions are added.

However, changing ioctl(BLKPG, BLKPG_ADD_PARTITION) might break some userspace.

Thanks,
Ming




[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