From: Ming Lei <ming.lei@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Subject: Re: [PATCH 2/2] block: loop: delete partitions after clearing & changing fd
Date: Wed, 8 Jul 2020 17:52:32 +0800 [thread overview]
Message-ID: <20200708095232.GB3321276@T590> (raw)
In-Reply-To: <20200708091318.GA3321276@T590>
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@redhat.com>
> 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
next prev parent reply other threads:[~2020-07-08 9:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-07 8:45 [PATCH 0/2] block: loop: delete partitions after clearing & changing fd Ming Lei
2020-07-07 8:45 ` [PATCH 1/2] block: loop: share code of reread partitions Ming Lei
2020-07-07 17:49 ` Christoph Hellwig
2020-07-07 8:45 ` [PATCH 2/2] block: loop: delete partitions after clearing & changing fd Ming Lei
2020-07-07 17:53 ` Christoph Hellwig
2020-07-08 9:13 ` Ming Lei
2020-07-08 9:52 ` Ming Lei [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-03-08 16:14 [PATCH 0/5] loop: improve loop aio perf by IOCB_NOWAIT Ming Lei
2025-03-08 16:14 ` [PATCH 2/2] block: loop: delete partitions after clearing & changing fd Ming Lei
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=20200708095232.GB3321276@T590 \
--to=ming.lei@redhat.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 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).