From: Daan De Meyer via B4 Relay <devnull+daan.amutable.com@kernel.org>
To: Jens Axboe <axboe@kernel.dk>,
Christian Brauner <brauner@kernel.org>,
Josef Bacik <josef@toxicpanda.com>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
nbd@other.debian.org, Christoph Hellwig <hch@infradead.org>,
Bart Van Assche <bvanassche@acm.org>,
Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Daan De Meyer <daan@amutable.com>,
stable@vger.kernel.org
Subject: [PATCH v2 2/2] nbd: drop stale partitions on NBD_CLEAR_SOCK
Date: Mon, 24 Aug 2026 15:32:48 +0200 [thread overview]
Message-ID: <20260824-b4-loop-nbd-stale-partitions-v2-2-9815a577cebd@amutable.com> (raw)
In-Reply-To: <20260824-b4-loop-nbd-stale-partitions-v2-0-9815a577cebd@amutable.com>
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. 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: stable@vger.kernel.org
Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Daan De Meyer <daan@amutable.com>
---
drivers/block/nbd.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ffce519bf008..09b4ad70a5d7 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1616,6 +1616,13 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd)
nbd_clear_sock(nbd);
disk_force_media_change(nbd->disk);
nbd_bdev_reset(nbd);
+ /*
+ * Drop the partitions of the disconnected device on the next open.
+ * They can exist even with max_part zero as they may have been added
+ * manually with BLKPG. Dropping them here is not possible as that
+ * needs open_mutex, which nbd_open() acquires under config_lock.
+ */
+ set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
if (test_and_clear_bit(NBD_RT_HAS_CONFIG_REF,
&nbd->config->runtime_flags))
nbd_config_put(nbd);
--
2.54.0
next prev parent reply other threads:[~2026-08-24 13:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:32 [PATCH v2 0/2] loop, nbd: drop partitions left behind by the GD_NEED_PART_SCAN removal Daan De Meyer via B4 Relay
2026-08-24 13:32 ` [PATCH v2 1/2] loop: drop stale partitions on LOOP_CHANGE_FD Daan De Meyer via B4 Relay
2026-08-25 5:45 ` Christoph Hellwig
2026-08-24 13:32 ` Daan De Meyer via B4 Relay [this message]
2026-08-25 5:45 ` [PATCH v2 2/2] nbd: drop stale partitions on NBD_CLEAR_SOCK Christoph Hellwig
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=20260824-b4-loop-nbd-stale-partitions-v2-2-9815a577cebd@amutable.com \
--to=devnull+daan.amutable.com@kernel.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=bvanassche@acm.org \
--cc=daan@amutable.com \
--cc=hch@infradead.org \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=shinichiro.kawasaki@wdc.com \
--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