Re: [PATCH 2/2] nbd: drop stale partitions on NBD_CLEAR_SOCK

Shin'ichiro Kawasaki <[email protected]>
Newsgroups org.kernel.vger.linux-block,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <anwyEbZhRHgSAyqB@shinmob>
On Aug 06, 2026 / 12:36, Daan De Meyer via B4 Relay wrote:
> From: Daan De Meyer <[email protected]>
> 
> Commit 267ec4d7223a ("loop: fix partition scan race between udev and
> loop_reread_partitions()") stopped disk_force_media_change() from
> setting GD_NEED_PART_SCAN. Besides requesting a rescan, that bit was what
> removed stale partitions on the next open, as bdev_disk_changed() drops
> all partitions before it consults disk_has_partscan().
> 
> nbd_clear_sock_ioctl() relied on that. It zeroes the capacity through
> nbd_bdev_reset(), but nothing removes the partitions of the disconnected
> device anymore. With the default max_part=16 they linger until the next
> connect sets GD_NEED_PART_SCAN again. With max_part=0 nothing ever sets
> it, so they are never removed at all, even though nbd does not set
> GENHD_FL_NO_PART and partitions can therefore still be added with BLKPG.
> 
> Set GD_NEED_PART_SCAN in nbd_clear_sock_ioctl() so the partitions are
> dropped on the next open. Calling bdev_disk_changed() directly is not an
> option as it needs open_mutex, which nbd_open() acquires under
> config_lock.
> 
> Fixes: 267ec4d7223a ("loop: fix partition scan race between udev and loop_reread_partitions()")
> Cc: [email protected]
> Signed-off-by: Daan De Meyer <[email protected]>

Daan provided another new, blktests test case to recreate the problem describe
above [*]. I confirmed that the test case failed on v7.2-rc7 kernel, and this
patch avoids the failure.

Tested-by: Shin'ichiro Kawasaki <[email protected]>

[*] https://github.com/linux-blktests/blktests/pull/260
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.