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 C38681FF0E3 for ; Wed, 18 Nov 2026 21:43:44 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 77C4E21850; Wed, 18 Nov 2026 21:43:25 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v2 storage 06/17] api: scan: san-luns: attribute NVMe namespaces to storage Date: Wed, 18 Nov 2026 21:42:25 +0100 Message-ID: <20261118204302.3100813-7-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118204302.3100813-1-t.lamprecht@proxmox.com> References: <20261118204302.3100813-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: 1795034587485 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.162 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: 4PWUJCJ6NE2OAZJEMXXMQKE7YVH575MF X-Message-ID-Hash: 4PWUJCJ6NE2OAZJEMXXMQKE7YVH575MF 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 with their subsystem, but without relation to an NVMe over Fabrics storage. Expect one path per portal of the storage that connects the subsystem of a namespace, 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 | 9 +++++---- src/PVE/Storage/SAN.pm | 16 +++++++++++++--- src/test/run_san_lun_scan_tests.pl | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/PVE/API2/Storage/Scan.pm b/src/PVE/API2/Storage/Scan.pm index 84848847..7d3fd242 100644 --- a/src/PVE/API2/Storage/Scan.pm +++ b/src/PVE/API2/Storage/Scan.pm @@ -499,8 +499,9 @@ __PACKAGE__->register_method({ 'paths-expected' => { description => "The number of paths the LUN should have on this node: the" . " highest of the count of its multipath entry and, for each managed" - . " iSCSI storage of the LUN, the number of its portals. Absent if no" - . " count is known.", + . " iSCSI storage of the LUN, the number of its portals. For a namespace" + . " of an NVMe over Fabrics storage, the number of its portals. Absent if" + . " no count is known.", type => 'integer', optional => 1, }, @@ -579,8 +580,8 @@ __PACKAGE__->register_method({ }, 'used-by-storage' => { description => "The storage that uses the LUN: as its base volume or" - . " through the volume group on it, or as an iSCSI storage that serves the" - . " LUNs of its target as images.", + . " through the volume group on it, or as an iSCSI or NVMe over Fabrics" + . " storage that serves the LUNs of its target or subsystem as images.", type => 'string', optional => 1, }, diff --git a/src/PVE/Storage/SAN.pm b/src/PVE/Storage/SAN.pm index 86469f5c..abf992d9 100644 --- a/src/PVE/Storage/SAN.pm +++ b/src/PVE/Storage/SAN.pm @@ -16,6 +16,7 @@ use PVE::Multipath; use PVE::Multipath::Config; use PVE::Multipath::Generator; use PVE::Multipath::Identity; +use PVE::NVMeOF; use PVE::Storage; use PVE::Storage::LVMPlugin; @@ -42,7 +43,8 @@ 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, %targets, %paths, %unmapped); + my (%storage, %expected, %vg_owner, %target_owner, %base_owner, %nvme_owner, %targets, %paths); + my %unmapped; for my $sid (sort keys %$derived) { for my $wwid (keys $derived->{$sid}->{wwids}->%*) { @@ -61,7 +63,8 @@ sub scan_luns($cfg) { $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-(?:part\d+-)?mpath|scsi)-(.+)$/; + if ($scfg->{base} // '') =~ m/(?:^|[.:])(?:dm-uuid-(?:part\d+-)?mpath|scsi|nvme)-(.+)$/; + $nvme_owner{ $scfg->{subsysnqn} } //= $sid if $scfg->{type} eq 'nvmeof'; } my %rows; @@ -106,6 +109,10 @@ sub scan_luns($cfg) { $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)) { @@ -205,9 +212,12 @@ 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 ($target) = map { $target_owner{$_} // () } sort keys(($targets{ $row->{wwid} } // {})->%*); - my $owner = $base_owner{ $row->{wwid} } // $vg_owner{ $row->{vgname} // '' } // $target; + my $owner = $base_owner{ $row->{wwid} } // $vg_owner{ $row->{vgname} // '' } // $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 a98e2563..06db1202 100755 --- a/src/test/run_san_lun_scan_tests.pl +++ b/src/test/run_san_lun_scan_tests.pl @@ -304,6 +304,12 @@ is($rows->[0]->{devpath}, '/dev/sdc', 'the row names the path that its by-id lin $disks = { nvme0n1 => { devpath => '/dev/nvme0n1', size => 100, transport => 'nvme-fc' } }; $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', + 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); @@ -321,6 +327,28 @@ 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');