public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v3 storage 05/76] lvm: find a shared volume group created by another node
Date: Fri,  6 Nov 2026 00:30:40 +0100	[thread overview]
Message-ID: <20261105233336.2178064-6-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261105233336.2178064-1-t.lamprecht@proxmox.com>

LVM hints restrict scans to devices that previously held PVs. A shared
volume group created by another node on an already attached device can
remain invisible until the hints are invalidated, leaving the storage
inactive and blocking guest startup and migration to that node. The
fallback vgscan finds the group but updates neither the hints nor the
cached volume-group list.

Retry the listing without hints. If it finds additional groups, rebuild
the hints with 'pvscan --cache', update the cached groups, and
invalidate the logical-volume list used by thin pool activation. Rebuild
only when needed: pvscan also resets LVM autoactivation records and must
not run on every status pass merely because a group remains absent.

This was observed on a five-node cluster with shared groups created on
iSCSI multipath LUNs and NVMe over Fabrics namespaces already attached
to the other nodes.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/Storage/LVMPlugin.pm   |  43 ++++++++-----
 src/test/Makefile              |   5 +-
 src/test/run_test_lvm_hints.pl | 109 +++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+), 17 deletions(-)
 create mode 100755 src/test/run_test_lvm_hints.pl

diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index a6a5eb70..3ed5bc78 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -161,7 +161,7 @@ sub lvm_destroy_volume_group {
 }
 
 sub lvm_vgs {
-    my ($includepvs) = @_;
+    my ($includepvs, $nohints) = @_;
 
     my $cmd = [
         '/sbin/vgs',
@@ -172,8 +172,9 @@ sub lvm_vgs {
         'b',
         '--unbuffered',
         '--nosuffix',
-        '--options',
     ];
+    push @$cmd, '--nohints' if $nohints;
+    push @$cmd, '--options';
 
     my $cols = [qw(vg_name vg_size vg_free lv_count)];
 
@@ -1420,25 +1421,35 @@ sub volume_snapshot_info {
     return $info;
 }
 
+# LVM hints can miss PVs written by another node onto previously empty devices. Probe without
+# hints once per activation cache; rebuild only when new VGs appear, since rebuilding also resets
+# LVM autoactivation records.
+my sub find_unhinted_vgs {
+    my ($cache) = @_;
+
+    $cache->{vgscaned} = 1;
+
+    my $vgs = lvm_vgs(0, 1);
+    my @unhinted = grep { !$cache->{vgs}->{$_} } sort keys %$vgs;
+    return if !@unhinted;
+
+    eval {
+        run_command(['/sbin/pvscan', '--cache'], outfunc => sub { });
+    };
+    warn "rebuilding the LVM device hints failed - $@" if $@;
+
+    # add, never replace: an incomplete listing must not hide volume groups found before
+    $cache->{vgs}->{$_} = $vgs->{$_} for @unhinted;
+    # the cached logical volume list lacks the volumes of these volume groups
+    delete $cache->{lvs};
+}
+
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
 
     $cache->{vgs} = lvm_vgs() if !$cache->{vgs};
 
-    # In LVM2, vgscans take place automatically;
-    # this is just to be sure
-    if (
-        $cache->{vgs}
-        && !$cache->{vgscaned}
-        && !$cache->{vgs}->{ $scfg->{vgname} }
-    ) {
-        $cache->{vgscaned} = 1;
-        my $cmd = ['/sbin/vgscan', '--ignorelockingfailure', '--mknodes'];
-        eval {
-            run_command($cmd, outfunc => sub { });
-        };
-        warn $@ if $@;
-    }
+    find_unhinted_vgs($cache) if !$cache->{vgscaned} && !$cache->{vgs}->{ $scfg->{vgname} };
 
     # we do not acticate any volumes here ('vgchange -aly')
     # instead, volumes are activate individually later
diff --git a/src/test/Makefile b/src/test/Makefile
index 1fe50885..02d833e8 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_iscsi test_zfspoolplugin test_lvmplugin test_lvm_lock_retry test_lvm_base_volume test_disklist test_bwlimit test_plugin test_ovf test_volume_access
+test: test_iscsi test_zfspoolplugin test_lvmplugin test_lvm_lock_retry test_lvm_base_volume test_lvm_hints test_disklist test_bwlimit test_plugin test_ovf test_volume_access
 
 test_zfspoolplugin: run_test_zfspoolplugin.pl
 	./run_test_zfspoolplugin.pl
@@ -15,6 +15,9 @@ test_lvm_lock_retry: run_test_lvm_lock_retry.pl
 test_lvm_base_volume: run_test_lvm_base_volume.pl
 	./run_test_lvm_base_volume.pl
 
+test_lvm_hints: run_test_lvm_hints.pl
+	./run_test_lvm_hints.pl
+
 test_disklist: run_disk_tests.pl
 	./run_disk_tests.pl
 
diff --git a/src/test/run_test_lvm_hints.pl b/src/test/run_test_lvm_hints.pl
new file mode 100755
index 00000000..fc2ffff7
--- /dev/null
+++ b/src/test/run_test_lvm_hints.pl
@@ -0,0 +1,109 @@
+#!/usr/bin/perl
+
+# Unit test for the activation of an LVM storage whose volume group is missing from the volume
+# groups LVM lists through its device hints, as after another node created it on a device this node
+# already had: a listing without the hints finds it, and only then the hints are rebuilt. vgs and
+# pvscan are mocked, so the test needs neither root nor a real LVM setup.
+
+use strict;
+use warnings;
+
+use lib '..';
+use Test::More;
+use Test::MockModule;
+
+use PVE::Storage::LVMPlugin;
+use PVE::Storage::LvmThinPlugin;
+
+my $CLASS = 'PVE::Storage::LVMPlugin';
+
+# the volume groups vgs lists with and without the hints, and the commands run
+my ($hinted, $all, $vgs_fails, $pvscan_fails, @calls);
+
+my $lvm = Test::MockModule->new('PVE::Storage::LVMPlugin');
+$lvm->mock(
+    run_command => sub {
+        my ($cmd, %param) = @_;
+        if ($cmd->[0] eq '/sbin/vgs') {
+            my $nohints = grep { $_ eq '--nohints' } @$cmd;
+            push @calls, $nohints ? 'vgs --nohints' : 'vgs';
+            die "vgs failed\n" if $nohints && $vgs_fails;
+            $param{outfunc}->("$_:1024:512:0") for ($nohints ? $all : $hinted)->@*;
+        } elsif ($cmd->[0] eq '/sbin/pvscan') {
+            push @calls, 'pvscan --cache';
+            die "pvscan failed\n" if $pvscan_fails;
+        } else {
+            push @calls, join(' ', @$cmd);
+        }
+    },
+);
+
+my sub activate {
+    my ($vgname, $cache) = @_;
+
+    @calls = ();
+    my @warnings;
+    local $SIG{__WARN__} = sub { push @warnings, $_[0] };
+    $CLASS->activate_storage('lvm', { vgname => $vgname }, $cache);
+    return (join(', ', @calls), \@warnings);
+}
+
+($hinted, $all) = (['vg1'], ['vg1']);
+my ($calls) = activate('vg1', {});
+is($calls, 'vgs', 'listed volume group: no listing without the hints');
+
+($hinted, $all) = (['vg1'], ['vg1', 'vg2']);
+my $cache = { lvs => { vg1 => {} } };
+($calls) = activate('vg2', $cache);
+is($calls, 'vgs, vgs --nohints, pvscan --cache', 'unhinted volume group: hints rebuilt');
+ok($cache->{vgs}->{vg2} && $cache->{vgs}->{vg1}, 'and added to the volume groups of the cache');
+ok(!exists($cache->{lvs}), 'and the logical volume list of the cache is dropped');
+is_deeply(
+    [$CLASS->status('lvm', { vgname => 'vg2' }, $cache)],
+    [1024, 512, 512, 1],
+    'the status of the same cache sees the volume group',
+);
+
+($calls) = activate('vg3', $cache);
+is($calls, '', 'once per cache: no second listing for the next missing volume group');
+
+($hinted, $all) = (['vg1'], ['vg1']);
+($calls) = activate('vg2', {});
+is($calls, 'vgs, vgs --nohints', 'volume group missing everywhere: hints left alone');
+
+($hinted, $all, $vgs_fails) = (['vg1'], [], 1);
+$cache = {};
+my $warnings;
+($calls, $warnings) = activate('vg2', $cache);
+is($calls, 'vgs, vgs --nohints', 'failed listing without the hints: hints left alone');
+ok($cache->{vgs}->{vg1}, 'and the volume groups found before stay');
+like($warnings->[0] // '', qr/vgs failed/, 'and it warns');
+$vgs_fails = 0;
+
+($hinted, $all, $pvscan_fails) = (['vg1'], ['vg1', 'vg2'], 1);
+$cache = {};
+($calls, $warnings) = activate('vg2', $cache);
+ok($cache->{vgs}->{vg2}, 'failed rebuild of the hints: the volume group still counts');
+like(
+    $warnings->[0] // '',
+    qr/^rebuilding the LVM device hints failed - pvscan failed/,
+    'and it warns about the rebuild',
+);
+$pvscan_fails = 0;
+
+# a thin pool storage activates through the LVM activation and reads the logical volume list
+my $listed;
+$lvm->mock(
+    lvm_list_volumes => sub {
+        $listed++;
+        return { vg2 => { data => { lv_type => 't', lv_state => 'a' } } };
+    },
+);
+($hinted, $all) = (['vg1'], ['vg1', 'vg2']);
+$cache = { lvs => { vg1 => {} } };
+PVE::Storage::LvmThinPlugin->activate_storage(
+    'thin', { vgname => 'vg2', thinpool => 'data' }, $cache,
+);
+ok($listed, 'thin pool: the logical volumes are listed again after the volume group was found');
+
+done_testing();
-- 
2.47.3




  parent reply	other threads:[~2026-11-06  0:50 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 23:30 [PATCH v3 proxmox,proxmox-perl-rs,cluster,storage,docs,manager 00/76] SAN: cluster-wide multipath, SAN views and a guided storage setup Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 proxmox 01/76] add proxmox-multipath crate Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 proxmox-perl-rs 02/76] pve-rs: add PVE::RS::Multipath bindings for multipathd status parsing Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 cluster 03/76] cfs: observe the multipath configuration files Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 04/76] storage: distinguish status-only activation in plugins Thomas Lamprecht
2026-11-05 23:30 ` Thomas Lamprecht [this message]
2026-11-05 23:30 ` [PATCH v3 storage 06/76] storage: bound LVM status commands Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 07/76] iscsi: rate-limit session rescans per target Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 08/76] iscsi: list the LUNs of each session, not of its SCSI host Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 09/76] lvm: refuse to create a volume group on a device that holds data Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 10/76] lvm: refuse a base volume of a target that serves disk images Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 11/76] iscsi: refuse virtual devices other than multipath maps as volumes Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 12/76] diskmanage: collect disk transport type from lsblk Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 13/76] diskmanage: add helper to list multipath devices Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 14/76] diskmanage: qualify NVMe over fabrics transport Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 15/76] disks: list: add include-remote parameter Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 16/76] diskmanage: include iSCSI session devices in disk enumeration Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 17/76] diskmanage: link multipath member disks to their map device Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 18/76] iscsi: factor out session device map from device list Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 19/76] api: scan: add a SAN LUN inventory Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 20/76] pvesm: expose the " Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 21/76] disks: lvm: allow volume groups on SAN LUNs and multipath maps Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 22/76] multipath: add a library around multipathd Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 23/76] diskmanage: collect native NVMe multipath path state Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 24/76] api: scan: san-luns: report " Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 25/76] diskmanage: collect local block device users Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 26/76] api: add node-level iSCSI status and maintenance Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 27/76] api: iscsi: add session logout with last-path protection Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 28/76] multipath: add a cluster-wide configuration Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 29/76] iscsi: add an option to manage storage LUNs with multipath Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 30/76] lvm: activate a missing base volume before using the volume group Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 31/76] multipath: apply the configuration on every node Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 32/76] iscsi: share the initiator identity reader Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 33/76] multipath: publish per-node status Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 34/76] api: add endpoints for the cluster-wide multipath configuration Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 35/76] api: multipath: add the cluster-wide health status Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 36/76] multipath: collect identities of non-iSCSI SCSI paths Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 37/76] api: scan: san-luns: report the multipath state of each LUN Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 38/76] api: scan: flag duplicate physical volumes on distinct LUNs Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 39/76] api: disks: recheck local users and retain wipe device references Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 40/76] iscsi: name plain LUNs after their identity link Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 41/76] api: disks: guard SAN wipes with stable identities and storage checks Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 42/76] api: scan: refresh SAN usage with bounded probes Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 docs 43/76] storage: lvm: note the rescan after extending a shared volume group Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 docs 44/76] storage: document the cluster-wide multipath management Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 45/76] api: ceph: osd: keep iSCSI LUNs out of OSD creation Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 46/76] pvestatd: track pending storage status commands across re-exec Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 47/76] ui: storage: factor out the scan picker error mask Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 48/76] ui: storage: nfs: show scan errors and empty results Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 49/76] ui: storage: allow changing the node for NFS/CIFS scans Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 50/76] ui: storage: add guided remote storage wizard with NFS support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 51/76] ui: storage wizard: add SMB/CIFS support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 52/76] ui: storage wizard: preserve settings after partial setup Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 53/76] ui: storage wizard: add Fibre Channel shared LVM setup Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 54/76] ui: storage wizard: reconcile unanswered storage creation Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 55/76] ui: storage wizard: add ZFS over iSCSI support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 56/76] ui: dc: storage: add remote storage wizard entry to the add menu Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 57/76] ui: node: add SAN LUNs panel Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 58/76] ui: san luns: show multipath path state Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 59/76] api: nodes: expose iSCSI status and maintenance Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 60/76] pvenode: add iscsi commands Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 61/76] ui: node: san: add iSCSI target and session management Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 62/76] pvestatd: apply the multipath configuration and report the node status Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 63/76] api: cluster: add the multipath endpoints Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 64/76] ui: dc: add a cluster-wide multipath view Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 65/76] ui: storage: iscsi: add the multipath option Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 66/76] ui: san luns: show multipath state and manage LUN entries Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 67/76] ui: storage wizard: add iSCSI support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 68/76] ui: storage wizard: iscsi: show cluster initiator names Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 69/76] ui: storage wizard: iscsi: enable multipath for shared LVM Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 70/76] ui: node: san: wipe a LUN that no storage uses Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 71/76] ui: storage wizard: iscsi: reuse existing target connections Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 72/76] ui: storage wizard: fibre channel: enable multipath for a LUN Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 73/76] ui: storage wizard: let root@pam wipe a LUN with data Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 74/76] ui: storage wizard: do not offer LUNs in use for a new volume group Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 75/76] ui: san: show the local users of a LUN in its usage tooltip Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 76/76] ui: san: check the other nodes for users before wiping a LUN Thomas Lamprecht

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=20261105233336.2178064-6-t.lamprecht@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal