From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: daan@amutable.com
Cc: Jens Axboe <axboe@kernel.dk>,
Christian Brauner <brauner@kernel.org>,
Daan De Meyer <daan.j.demeyer@gmail.com>,
Josef Bacik <josef@toxicpanda.com>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
nbd@other.debian.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] loop: drop stale partitions on LOOP_CHANGE_FD
Date: Wed, 12 Aug 2026 17:10:38 +0900 [thread overview]
Message-ID: <anwpf-WdSj4W8AGp@shinmob> (raw)
In-Reply-To: <20260806-b4-loop-nbd-stale-partitions-v1-1-67bb75a8d7be@amutable.com>
On Aug 06, 2026 / 12:36, Daan De Meyer via B4 Relay wrote:
> From: Daan De Meyer <daan@amutable.com>
>
> Commit 267ec4d7223a ("loop: fix partition scan race between udev and
> loop_reread_partitions()") stopped disk_force_media_change() from
> setting GD_NEED_PART_SCAN. That bit did more than request a rescan:
> bdev_disk_changed() drops every partition before it consults
> disk_has_partscan(), so the lazy scan on the next open was also what
> removed partitions from a loop device without LO_FLAGS_PARTSCAN.
>
> Such devices 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.
>
> loop_change_fd() only rescans when LO_FLAGS_PARTSCAN is set, so those
> partitions now survive the backing file swap and keep describing the old
> file. The new backing file must have the same size, but its partition
> table can be completely different, leaving the partition devices mapping
> the wrong ranges.
>
> Call loop_reread_partitions() unconditionally. Without LO_FLAGS_PARTSCAN,
> blk_add_partitions() returns early, so this drops the stale partitions
> without scanning the new backing file.
Daan also posted a new, blktests test case that recreates the problem described
[*]. I confirmed that the test case failed with v7.2-rc7 kernel, and this patch
avoids the failure.
Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
[*] https://github.com/linux-blktests/blktests/pull/259
next prev parent reply other threads:[~2026-08-12 8:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 10:36 [PATCH 0/2] loop, nbd: drop partitions left behind by the GD_NEED_PART_SCAN removal Daan De Meyer via B4 Relay
2026-08-06 10:36 ` [PATCH 1/2] loop: drop stale partitions on LOOP_CHANGE_FD Daan De Meyer via B4 Relay
2026-08-12 8:10 ` Shin'ichiro Kawasaki [this message]
2026-08-06 10:36 ` [PATCH 2/2] nbd: drop stale partitions on NBD_CLEAR_SOCK Daan De Meyer via B4 Relay
2026-08-12 8:44 ` Shin'ichiro Kawasaki
2026-08-06 16:48 ` [PATCH 0/2] loop, nbd: drop partitions left behind by the GD_NEED_PART_SCAN removal Bart Van Assche
2026-08-12 9:51 ` Christian Brauner
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=anwpf-WdSj4W8AGp@shinmob \
--to=shinichiro.kawasaki@wdc.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=daan.j.demeyer@gmail.com \
--cc=daan@amutable.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=stable@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