From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 063651FF065 for ; Mon, 23 Nov 2026 14:35:00 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5D32421713; Mon, 23 Nov 2026 14:34:31 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v5 storage 04/26] api: disks: refuse a local wipe of a network NVMe namespace Date: Mon, 23 Nov 2026 14:31:56 +0100 Message-ID: <20261123133412.3710030-5-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261123133412.3710030-1-t.lamprecht@proxmox.com> References: <20261123133412.3710030-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795440864068 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.148 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: KFL64IGPOKEG7EV4HLYR666YT4U3QILW X-Message-ID-Hash: KFL64IGPOKEG7EV4HLYR666YT4U3QILW X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The disk lists leave out NVMe namespaces attached over TCP or RDMA, but the wipe API still took a partition of one by its kernel name. It then checked only for mounts and holders on this node, while other nodes can use the namespace, for example through an nvmeof storage that serves it as disk image. A whole namespace whose last controller is gone took the same path, as its transport cannot be read, and with I/O that waits for a path, the wipe went through once a path returned. Refuse both, taking a namespace of unknown transport as one over a network. Node > SAN wipes the namespace as a whole, with the checks of the SAN code. Partitions of iSCSI and Fibre Channel LUNs are still wiped like those of local disks. Signed-off-by: Thomas Lamprecht --- src/PVE/API2/Disks.pm | 23 +++++++++++++++++++++++ src/PVE/Diskmanage.pm | 12 +++++++++--- src/test/disk_api_test.pm | 26 ++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/PVE/API2/Disks.pm b/src/PVE/API2/Disks.pm index d157c430..f9b79e7a 100644 --- a/src/PVE/API2/Disks.pm +++ b/src/PVE/API2/Disks.pm @@ -318,6 +318,29 @@ __PACKAGE__->register_method({ . " SAN LUN\n"; } + # Other nodes can use a namespace attached over a network, which the checks for mounts + # and holders do not see, and one without a path gets written once it has one again. + # Under Node > SAN, it is wiped as a whole with the SAN checks. The name tells the + # namespace of a partition, also if its partition number is one that the checks of the + # partition table refuse. + if (basename($disk) =~ m/^(nvme[0-9]+n[0-9]+)(p[0-9]+)?$/) { + my ($namespace, $partition) = ($1, $2); + my $transport = PVE::Diskmanage::get_nvme_transport("/sys/block/$namespace"); + die + "cannot wipe '$disk' - the transport of namespace '/dev/$namespace' cannot be" + . " read, as when it has no path\n" + if !defined($transport); + if (PVE::Diskmanage::is_network_nvme_transport($transport)) { + die + "cannot wipe '$disk' - a partition of namespace '/dev/$namespace', which" + . " is attached over a network, cannot be wiped on its own; Node > SAN" + . " wipes the whole namespace\n" + if defined($partition); + # it got a path since the SAN check above, which found none + die "cannot wipe '$disk' - its transport changed, try again\n"; + } + } + my $mounted = PVE::Diskmanage::is_mounted($disk); die "disk/partition '${mounted}' is mounted\n" if $mounted; diff --git a/src/PVE/Diskmanage.pm b/src/PVE/Diskmanage.pm index d70647c8..2790aedf 100644 --- a/src/PVE/Diskmanage.pm +++ b/src/PVE/Diskmanage.pm @@ -578,6 +578,14 @@ sub get_nvme_transport { return $first; } +# A namespace attached over TCP or RDMA is no local disk, and neither is one whose transport is +# unknown, like one whose last controller is gone, which can be one over a network. +sub is_network_nvme_transport { + my ($transport) = @_; + + return !defined($transport) || $transport =~ m/^(?:tcp|rdma)$/; +} + # SAS does not distinguish local from remote attachments, so it is not classified as remote. sub is_remote_transport { my ($transport) = @_; @@ -691,10 +699,8 @@ sub get_disks { my $nvme_transport; if ($dev =~ m/^nvme/) { $nvme_transport = get_nvme_transport($sysdir); - # like a namespace whose last controller is gone, which can be one over a network - return if !$san_inventory && !defined($nvme_transport); + return if !$san_inventory && is_network_nvme_transport($nvme_transport); } - return if !$san_inventory && ($nvme_transport // '') =~ /^(?:tcp|rdma)$/; $udev_db //= get_udev_db() if ++$udev_queries > $udev_single; my $data = get_udev_info("/sys/block/$dev", $udev_db) // return; diff --git a/src/test/disk_api_test.pm b/src/test/disk_api_test.pm index 1d2f8d33..3ae932e0 100644 --- a/src/test/disk_api_test.pm +++ b/src/test/disk_api_test.pm @@ -298,16 +298,38 @@ subtest 'wipe takes names beyond the old pattern for a LUN only' => sub { for my $name (@other) { like($wipe->($name), qr/only accepted for a SAN LUN/, "$name is refused"); } + my %transport = (nvme1n1 => 'pcie', nvme2n1 => 'tcp', nvme3n1 => 'rdma', nvme4n1 => undef); + $diskmanage_module->mock( + get_nvme_transport => sub { $transport{ (split('/', $_[0]))[-1] } }); is($wipe->('/dev/sdb1'), '', 'a partition by its kernel name is wiped'); + is($wipe->('/dev/nvme1n1p1'), '', 'so is one of a local namespace'); + is($wipe->('/dev/nvme1n1'), '', 'and a local namespace'); + for my $name (qw(/dev/nvme2n1p1 /dev/nvme2n1p200 /dev/nvme3n1p1)) { + like( + $wipe->($name), + qr/attached over a network, cannot be wiped on its own/, + "but not $name", + ); + } + for my $name (qw(/dev/nvme4n1p1 /dev/nvme4n1)) { + like($wipe->($name), qr/transport of namespace .* cannot be read/, "nor $name"); + } + like($wipe->('/dev/nvme2n1'), qr/transport changed/, 'nor one the SAN check missed'); $lun = { wwid => '3600a' }; is( $wipe->('/dev/disk/by-id/dm-uuid-mpath-3600a'), '', 'a LUN by the name of its map is wiped', ); - is_deeply(\@wiped, ['/dev/sdb1', '3600a'], 'nothing else got wiped'); + is_deeply( + \@wiped, + ['/dev/sdb1', '/dev/nvme1n1p1', '/dev/nvme1n1', '3600a'], + 'nothing else got wiped', + ); - my @mocked = qw(verify_blockdev_path is_mounted has_holder wipe_blockdev udevadm_trigger); + my @mocked = qw( + verify_blockdev_path is_mounted has_holder wipe_blockdev udevadm_trigger get_nvme_transport + ); $diskmanage_module->unmock($_) for @mocked; };