From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D28E61FF065 for ; Mon, 23 Nov 2026 14:35:51 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 51EA8217FF; Mon, 23 Nov 2026 14:34:34 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v5 storage 03/26] diskmanage: list NVMe namespaces attached over TCP or RDMA for SAN only Date: Mon, 23 Nov 2026 14:31:55 +0100 Message-ID: <20261123133412.3710030-4-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: 1795440863966 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.147 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: YSS5PK4OBON3JYFPY2I2RDBDJ6GKUPWV X-Message-ID-Hash: YSS5PK4OBON3JYFPY2I2RDBDJ6GKUPWV 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 list for local disk setup leaves out iSCSI LUNs, which storages connect for use on several nodes. Namespaces attached over TCP or RDMA are the same kind of device, but were listed, so Node > Disks offered them for a ZFS pool, a directory, a volume group or a Ceph OSD, while other nodes could use the same namespace. Leave these namespaces out of the list for local disk setup, and also a namespace whose transport cannot be read, like one whose last controller is gone. The SAN views still list those attached over TCP or RDMA. For a subsystem with controllers of several transports, a fabric one counts, whatever their order. The partitions go with their namespace, so the checks before local disk setup refuse both as not a valid local disk, and removing a directory or ZFS pool on one with the cleanup of its disks refuses as for an iSCSI LUN. Namespaces attached over Fibre Channel stay listed, as Fibre Channel LUNs do, since a volume group created under Node > Disks is how these get a shared LVM storage. Signed-off-by: Thomas Lamprecht --- src/PVE/Diskmanage.pm | 30 ++++-- .../multipath/disklist_expected.json | 16 ---- .../nvme_smart/nvme0n1/device/transport | 1 + src/test/disklist_test.pm | 94 +++++++++++++++++-- 4 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 src/test/disk_tests/nvme_smart/nvme0n1/device/transport diff --git a/src/PVE/Diskmanage.pm b/src/PVE/Diskmanage.pm index a23ffe98..d70647c8 100644 --- a/src/PVE/Diskmanage.pm +++ b/src/PVE/Diskmanage.pm @@ -555,23 +555,27 @@ sub read_subsysnqn { } # Returns the NVMe transport (pcie, fc, tcp, rdma, loop) of a namespace, either directly from -# its controller, or from any controller of its subsystem for native NVMe multipath setups. +# its controller, or from the controllers of its subsystem for native NVMe multipath setups. Of +# several transports, one over a fabric wins, independent of the order of the controllers. sub get_nvme_transport { my ($sysdir) = @_; my $transport = file_read_firstline("$sysdir/device/transport"); return $transport if defined($transport); + my $found = {}; dir_glob_foreach( "$sysdir/device", 'nvme\d+', sub { my ($controller) = @_; - $transport //= file_read_firstline("$sysdir/device/$controller/transport"); + my $value = file_read_firstline("$sysdir/device/$controller/transport"); + $found->{$value} = 1 if defined($value); }, ); - return $transport; + my ($first) = grep { $found->{$_} } (qw(tcp rdma fc), sort keys $found->%*); + return $first; } # SAS does not distinguish local from remote attachments, so it is not classified as remote. @@ -614,7 +618,10 @@ sub mounted_paths { sub get_disks { my ($disks, $nosmart, $include_partitions, $san_inventory) = @_; - # SAN inventory includes iSCSI session devices and skips usage probes that read devices. + # Only the SAN inventory includes iSCSI LUNs and NVMe namespaces attached over TCP or RDMA, or + # over an unknown transport, as storages connect them for use on several nodes. Fibre Channel + # devices stay listed, as local disk setup is how a volume group gets onto one. The SAN + # inventory skips usage probes that read devices. my $disklist = {}; my $mounted = mounted_blockdevs(); @@ -679,15 +686,20 @@ sub get_disks { return if !$san_inventory && is_iscsi_device($dev); + my $sysdir = "/sys/block/$dev"; + + 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 && ($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; my $devpath = $data->{devpath}; - my $sysdir = "/sys/block/$dev"; - - my $nvme_transport; - $nvme_transport = get_nvme_transport($sysdir) if $dev =~ m/^nvme/; - my $sysdata = get_sysdir_info($sysdir); return if !defined($sysdata); diff --git a/src/test/disk_tests/multipath/disklist_expected.json b/src/test/disk_tests/multipath/disklist_expected.json index ec442969..8098dd8d 100644 --- a/src/test/disk_tests/multipath/disklist_expected.json +++ b/src/test/disk_tests/multipath/disklist_expected.json @@ -87,21 +87,5 @@ "osdid-list": null, "by_id_link": "/dev/disk/by-id/nvme-FCMODEL_FCNVME1", "transport": "nvme-fc" - }, - "nvme9n1": { - "devpath": "/dev/nvme9n1", - "size": 10737418240, - "vendor": "FABVEND", - "model": "FABRICS CTRL", - "serial": "FAB1", - "wwn": "uuid.10000000-0000-0000-0000-000000000001", - "gpt": 0, - "rpm": 0, - "type": "nvme", - "health": "UNKNOWN", - "wearout": "N/A", - "osdid": -1, - "osdid-list": null, - "transport": "nvme-tcp" } } diff --git a/src/test/disk_tests/nvme_smart/nvme0n1/device/transport b/src/test/disk_tests/nvme_smart/nvme0n1/device/transport new file mode 100644 index 00000000..30e0ba74 --- /dev/null +++ b/src/test/disk_tests/nvme_smart/nvme0n1/device/transport @@ -0,0 +1 @@ +pcie diff --git a/src/test/disklist_test.pm b/src/test/disklist_test.pm index 38823f8b..fae8ce45 100644 --- a/src/test/disklist_test.pm +++ b/src/test/disklist_test.pm @@ -290,12 +290,63 @@ sub test_disk_list { for my $transport (qw(tcp rdma fc pcie)) { $smart_calls = 0; $diskmanage_module->mock(get_nvme_transport => sub { $transport }); - PVE::Diskmanage::get_disks(); + # with SMART, as the SAN inventory lists the namespaces of all transports + PVE::Diskmanage::get_disks(undef, 0, 0, 1); $testcount++; is($smart_calls, $transport eq 'pcie' ? 1 : 0, "SMART queries for $transport"); } $diskmanage_module->unmock('get_smart_data'); - $diskmanage_module->unmock('get_nvme_transport'); + + for my $transport ('tcp', 'rdma', 'fc', 'pcie', undef) { + $diskmanage_module->mock(get_nvme_transport => sub { $transport }); + my $local = ($transport // '') =~ /^(?:fc|pcie)$/; + my $name = $transport // 'an unknown transport'; + $testcount += 3; + is( + !!PVE::Diskmanage::get_disks()->{nvme0n1}, + $local, + "disk list for local setup with $name", + ); + ok( + PVE::Diskmanage::get_disks(undef, 1, 0, 1)->{nvme0n1}, + "SAN inventory with $name", + ); + eval { PVE::Diskmanage::assert_disk_unused('/dev/nvme0n1') }; + like( + $@, + $local ? qr/^$/ : qr/not a valid local disk/, + "local disk setup with $name", + ); + } + + $diskmanage_module->mock( + dir_glob_foreach => sub { + my ($dir, $regex, $sub) = @_; + return $sub->('nvme0n1p1') if $dir eq '/sys/block/nvme0n1'; + return mocked_dir_glob_foreach(@_); + }, + is_partition => sub { return $_[0] eq '/dev/nvme0n1p1' }, + get_blockdev => sub { return '/dev/nvme0n1' }, + ); + for my $transport (qw(tcp rdma fc pcie)) { + $diskmanage_module->mock(get_nvme_transport => sub { $transport }); + my $local = $transport eq 'fc' || $transport eq 'pcie'; + $testcount += 2; + is( + !!PVE::Diskmanage::get_disks(undef, 1, 1)->{nvme0n1p1}, + $local, + "partition list for local setup with $transport", + ); + # partitions have holders in these tests, so a listed one counts as used + eval { PVE::Diskmanage::assert_disk_unused('/dev/nvme0n1p1') }; + like( + $@, + $local ? qr/already in use/ : qr/not a valid local disk/, + "local disk setup on a partition with $transport", + ); + } + $diskmanage_module->mock(dir_glob_foreach => \&mocked_dir_glob_foreach); + $diskmanage_module->unmock($_) for qw(is_partition get_blockdev get_nvme_transport); } if (-f "disk_tests/$testcasedir/multipathd_status_expected.json") { @@ -342,7 +393,8 @@ sub test_disk_list { $udev_single_queries = 0; my $listed = PVE::Diskmanage::get_disks(); $testcount++; - is(scalar(keys %$listed), 6, 'all disks listed'); + is(scalar(keys %$listed), 5, + 'all disks listed but the namespace attached over TCP'); $testcount++; is( $udev_single_queries, @@ -350,8 +402,8 @@ sub test_disk_list { 'the database replaces the queries after the first disks', ); - # six disks: 240 block devices are just enough to ask about each of them on its own - for my $count (240, 239) { + # five disks: 200 block devices are just enough to ask about each of them on its own + for my $count (200, 199) { $diskmanage_module->mock( get_lsblk_info => sub { return { map { ("/dev/dm-$_" => {}) } 1 .. $count }; @@ -363,10 +415,38 @@ sub test_disk_list { $testcount++; is( $udev_single_queries, - $count == 240 ? 6 : 5, - "single queries for six disks among $count block devices", + $count == 200 ? 5 : 4, + "single queries for five disks among $count block devices", ); } + + my $san = PVE::Diskmanage::get_disks(undef, 1, 0, 1); + $testcount++; + is($san->{nvme9n1}->{transport}, 'nvme-tcp', 'SAN inventory lists it'); + + # a second controller of the subsystem over Fibre Channel, listed before or after + for my $order ([qw(nvme4 nvme5)], [qw(nvme5 nvme4)]) { + $diskmanage_module->mock( + dir_glob_foreach => sub { + my ($dir, $regex, $sub) = @_; + return mocked_dir_glob_foreach(@_) + if $dir ne '/sys/block/nvme9n1/device'; + $sub->($_) for $order->@*; + }, + file_read_firstline => sub { + return 'fc' if $_[0] eq '/sys/block/nvme9n1/device/nvme4/transport'; + return mocked_file_read_firstline(@_); + }, + ); + $testcount++; + is( + PVE::Diskmanage::get_nvme_transport('/sys/block/nvme9n1'), + 'tcp', + "TCP wins over Fibre Channel listed as $order->[0], $order->[1]", + ); + } + $diskmanage_module->mock(dir_glob_foreach => \&mocked_dir_glob_foreach); + $diskmanage_module->mock(file_read_firstline => \&mocked_file_read_firstline); } done_testing($testcount);