drivers/block/loop.c | 10 ++++++---- drivers/block/nbd.c | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-)
Commit 267ec4d7223a ("loop: fix partition scan race between udev and
loop_reread_partitions()") stopped disk_force_media_change() from setting
GD_NEED_PART_SCAN. The caller audit in that commit only considered the bit
as a request to rescan partitions, but it did more than that:
bdev_disk_changed() drops every entry in disk->part_tbl before it consults
disk_has_partscan(), and only the re-adding half is gated on partition
scanning being enabled. The lazy scan on the next open was therefore also
the only thing removing partitions from a device that has partitions but
no partition scanning.
Loop devices without LO_FLAGS_PARTSCAN are exactly such devices, and they
are not unusual. bdev_add_partition() only rejects GENHD_FL_NO_PART disks,
so BLKPG_ADD_PARTITION works while GD_SUPPRESS_PART_SCAN is set, and
parted, libfdisk and systemd all fall back to BLKPG when BLKRRPART fails
with -EINVAL, which is what a loop device without LO_FLAGS_PARTSCAN
returns.
Commit c4f4c0fc551c ("loop: remove manually added partitions on detach")
fixed the detach path after this was reported as loop devices picking up
partition devices from a previously built image:
https://bugs.debian.org/1141434
These two patches fix the two remaining places that relied on the same
lazy cleanup, LOOP_CHANGE_FD and NBD_CLEAR_SOCK.
Both were tested with the blktests loop and nbd groups on 7.2-rc5. New
cases covering the two paths fail without these patches and pass with
them; they will be submitted to blktests separately.
Signed-off-by: Daan De Meyer <daan@amutable.com>
---
Daan De Meyer (2):
loop: drop stale partitions on LOOP_CHANGE_FD
nbd: drop stale partitions on NBD_CLEAR_SOCK
drivers/block/loop.c | 10 ++++++----
drivers/block/nbd.c | 7 +++++++
2 files changed, 13 insertions(+), 4 deletions(-)
---
base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df
change-id: 20260806-b4-loop-nbd-stale-partitions-2d10ede71a2a
Best regards,
--
Daan De Meyer <daan@amutable.com>
On Thu, Aug 06, 2026 at 12:36:56PM +0200, Daan De Meyer via B4 Relay wrote:
> Commit 267ec4d7223a ("loop: fix partition scan race between udev and
> loop_reread_partitions()") stopped disk_force_media_change() from setting
> GD_NEED_PART_SCAN. The caller audit in that commit only considered the bit
> as a request to rescan partitions, but it did more than that:
> bdev_disk_changed() drops every entry in disk->part_tbl before it consults
> disk_has_partscan(), and only the re-adding half is gated on partition
> scanning being enabled. The lazy scan on the next open was therefore also
> the only thing removing partitions from a device that has partitions but
> no partition scanning.
>
> Loop devices without LO_FLAGS_PARTSCAN are exactly such devices, and they
> are not unusual. bdev_add_partition() only rejects GENHD_FL_NO_PART disks,
> so BLKPG_ADD_PARTITION works while GD_SUPPRESS_PART_SCAN is set, and
> parted, libfdisk and systemd all fall back to BLKPG when BLKRRPART fails
> with -EINVAL, which is what a loop device without LO_FLAGS_PARTSCAN
> returns.
>
> Commit c4f4c0fc551c ("loop: remove manually added partitions on detach")
> fixed the detach path after this was reported as loop devices picking up
> partition devices from a previously built image:
>
> https://bugs.debian.org/1141434
>
> These two patches fix the two remaining places that relied on the same
> lazy cleanup, LOOP_CHANGE_FD and NBD_CLEAR_SOCK.
>
> Both were tested with the blktests loop and nbd groups on 7.2-rc5. New
> cases covering the two paths fail without these patches and pass with
> them; they will be submitted to blktests separately.
>
> Signed-off-by: Daan De Meyer <daan@amutable.com>
Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org>
On 8/6/26 3:36 AM, Daan De Meyer via B4 Relay wrote: > These two patches fix the two remaining places that relied on the same > lazy cleanup, LOOP_CHANGE_FD and NBD_CLEAR_SOCK. Reviewed-by: Bart Van Assche <bvanassche@acm.org>
© 2016 - 2026 Red Hat, Inc.