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 AB3361FF0B7 for ; Fri, 13 Nov 2026 04:28:30 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 91CE821A98; Fri, 13 Nov 2026 04:22:06 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH storage 06/17] api: scan: san-luns: attribute NVMe namespaces to storage Date: Fri, 13 Nov 2026 04:04:34 +0100 Message-ID: <20261113030541.1591528-7-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113030541.1591528-1-t.lamprecht@proxmox.com> References: <20261113030541.1591528-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: 1794539148278 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.234 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: BXL4VKJF5MQ2I3NXEOBVCHVGFAUOXBUG X-Message-ID-Hash: BXL4VKJF5MQ2I3NXEOBVCHVGFAUOXBUG 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 SAN LUN inventory lists NVMe namespaces without relation to an NVMe over Fabrics storage. Report the subsystem NQN and the namespace ID of a namespace, and expect one path per portal of the storage that connects its subsystem, so that a namespace with fewer paths shows as degraded. A namespace counts as used by the LVM storage that has it as base volume, else by the storage of its subsystem if that one serves the namespaces as images. Signed-off-by: Thomas Lamprecht --- src/PVE/API2/Storage/Scan.pm | 10 +++++++++ src/PVE/Storage/SAN.pm | 25 ++++++++++++++++++---- src/test/run_san_lun_scan_tests.pl | 33 +++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/PVE/API2/Storage/Scan.pm b/src/PVE/API2/Storage/Scan.pm index a9d05f79..35c1c71f 100644 --- a/src/PVE/API2/Storage/Scan.pm +++ b/src/PVE/API2/Storage/Scan.pm @@ -596,6 +596,16 @@ __PACKAGE__->register_method({ type => 'string', optional => 1, }, + 'nvme-subsystem' => { + description => 'The NVMe subsystem NQN.', + type => 'string', + optional => 1, + }, + 'nvme-nsid' => { + description => 'The namespace ID within the NVMe subsystem.', + type => 'integer', + optional => 1, + }, 'iscsi-target' => { description => "The IQN of the iSCSI target the LUN is attached through.", type => 'string', diff --git a/src/PVE/Storage/SAN.pm b/src/PVE/Storage/SAN.pm index f3682106..b281177b 100644 --- a/src/PVE/Storage/SAN.pm +++ b/src/PVE/Storage/SAN.pm @@ -15,6 +15,7 @@ use PVE::Multipath; use PVE::Multipath::Generator; use PVE::Multipath::Config; use PVE::Multipath::Identity; +use PVE::NVMeOF; use PVE::Storage; use PVE::Storage::LVMPlugin; use PVE::Tools qw(file_read_firstline dir_glob_foreach run_command); @@ -34,7 +35,7 @@ sub scan_luns($cfg) { PVE::Multipath::Config::wwids_for_node($mpcfg, PVE::INotify::nodename())->@*; my %listed = map { $_ => 1 } PVE::Multipath::list_etc_multipath_wwids()->@*; my $derived = PVE::Multipath::Generator::derived_wwids($cfg, $ids); - my (%storage, %expected, %vg_owner, %target_owner, %base_owner); + my (%storage, %expected, %vg_owner, %target_owner, %base_owner, %nvme_owner); for my $sid (sort keys %$derived) { for my $wwid (keys $derived->{$sid}->{wwids}->%*) { @@ -52,7 +53,9 @@ sub scan_luns($cfg) { $vg_owner{ $scfg->{vgname} } //= $sid if defined($scfg->{vgname}); $target_owner{ $scfg->{target} } //= $sid if defined($scfg->{target}) && PVE::Storage::san_storage_serves_images($scfg); - $base_owner{$1} //= $sid if ($scfg->{base} // '') =~ m/(?:^|\.)dm-uuid-mpath-(.+)$/; + $base_owner{$1} //= $sid + if ($scfg->{base} // '') =~ m/(?:^|[.:])(?:dm-uuid-mpath|nvme)-(.+)$/; + $nvme_owner{ $scfg->{subsysnqn} } //= $sid if $scfg->{type} eq 'nvmeof'; } my %rows; @@ -96,7 +99,19 @@ sub scan_luns($cfg) { : $storage{$wwid} ? 'storage' : 'unmanaged'; } - $row->{multipath} = 'native' if $name =~ /^nvme\d+n\d+$/; + if ($name =~ /^nvme\d+n\d+$/) { + $row->{multipath} = 'native'; + my $nqn = PVE::Diskmanage::read_subsysnqn("/sys/block/$name/device/subsysnqn"); + if (defined($nqn)) { + $row->{'nvme-subsystem'} = $nqn; + my $nsid = file_read_firstline("/sys/block/$name/nsid"); + $row->{'nvme-nsid'} = int($nsid) if defined($nsid) && $nsid =~ /^\d+$/; + if (my $sid = $nvme_owner{$nqn}) { + $row->{'paths-expected'} = + scalar(PVE::NVMeOF::storage_paths($cfg->{ids}->{$sid})->@*); + } + } + } for my $key (qw(transport vendor model serial)) { my $value = $disk->{$key}; $row->{$key} //= $value if defined($value) && $value ne 'unknown'; @@ -150,8 +165,10 @@ sub scan_luns($cfg) { $row->{'paths-expected'}, ); } + my $nvme = $nvme_owner{ $row->{'nvme-subsystem'} // '' }; + undef $nvme if $nvme && !PVE::Storage::san_storage_serves_images($cfg->{ids}->{$nvme}); my $owner = $base_owner{ $row->{wwid} } // $vg_owner{ $row->{vgname} // '' } - // $target_owner{ $row->{'iscsi-target'} // '' }; + // $target_owner{ $row->{'iscsi-target'} // '' } // $nvme; $row->{'used-by-storage'} = $owner if defined($owner); } return [map { $rows{$_} } sort keys %rows]; diff --git a/src/test/run_san_lun_scan_tests.pl b/src/test/run_san_lun_scan_tests.pl index 94df0d5c..3578a3af 100755 --- a/src/test/run_san_lun_scan_tests.pl +++ b/src/test/run_san_lun_scan_tests.pl @@ -165,7 +165,14 @@ is($rows->[0]->{'by-id'}, '/dev/disk/by-id/scsi-3600plain', 'by-id link of the s is($rows->[0]->{devpath}, '/dev/sdc', 'the row names the path that its by-id link resolves to'); $disks = { nvme0n1 => { devpath => '/dev/nvme0n1', size => 100, transport => 'nvme-fc' } }; -$scan->mock(file_read_firstline => sub { 'eui.0123456789abcdef' }); +$scan->mock(file_read_firstline => sub { $_[0] =~ m{/nsid$} ? 1 : 'eui.0123456789abcdef' }); +$disk->mock(read_subsysnqn => sub { 'nqn.test' }); +$cfg->{ids}->{fabric} = { + type => 'nvmeof', + subsysnqn => 'nqn.test', + 'nvme-portals' => '192.0.2.1,192.0.2.2', + content => { images => 1 }, +}; $scan->unmock('stable_path'); $scan->mock(abs_path => sub { '/dev/nvme0n1' }); $rows = PVE::Storage::SAN::scan_luns($cfg); @@ -173,6 +180,30 @@ is($rows->[0]->{multipath}, 'native', 'NVMe uses kernel-native multipath'); is($rows->[0]->{'by-id'}, '/dev/disk/by-id/nvme-eui.0123456789abcdef', 'NVMe stable name'); eval { PVE::JSONSchema::validate($rows, $schema) }; is($@, '', 'native row matches the API schema'); +is($rows->[0]->{'nvme-subsystem'}, 'nqn.test', 'subsystem NQN exposed'); +is($rows->[0]->{'nvme-nsid'}, 1, 'namespace ID exposed'); +is($rows->[0]->{'used-by-storage'}, 'fabric', 'a storage serving the namespaces uses them'); +is($rows->[0]->{'paths-expected'}, 2, 'one expected path per configured portal'); + +for my $count (1, 3) { + $config->mock( + read_config => sub { { + ids => { 'eui.0123456789abcdef' => { type => 'wwid', 'paths-expected' => $count } }, + } }, + ); + my $entry = PVE::Storage::SAN::scan_luns($cfg); + is($entry->[0]->{'paths-expected'}, 2, "a multipath entry does not change it ($count)"); +} +$config->mock(read_config => sub { { ids => { '3600map' => { type => 'wwid' } } } }); +{ + local $cfg->{ids}->{fabric}->{content} = { none => 1 }; + my $plain = PVE::Storage::SAN::scan_luns($cfg); + is($plain->[0]->{'used-by-storage'}, undef, 'a connection storage does not'); + is($plain->[0]->{'paths-expected'}, 2, 'but still tells the expected paths'); +} +$cfg->{ids}->{data}->{base} = 'fabric:nvme-eui.0123456789abcdef'; +$rows = PVE::Storage::SAN::scan_luns($cfg); +is($rows->[0]->{'used-by-storage'}, 'data', 'LVM base consumer takes precedence'); $disk->mock(is_partition => sub { 1 }); ok(!PVE::Storage::SAN::is_san_device('/dev/sdb1'), 'a partition is never a LUN');