all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v5 storage 11/36] lvm: activate a missing base volume before using the volume group
Date: Mon, 16 Nov 2026 02:23:20 +0100	[thread overview]
Message-ID: <20261116012355.3187417-12-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261116012355.3187417-1-t.lamprecht@proxmox.com>

Activating an LVM storage activates its base storage, but not the
base volume. Right after the login its device can still be appearing,
for example while multipathd assembles the map, and a guest start
then does not find the volume group.

If the volume group is missing, activate the base volume, which waits
for its device, and look again, without the LVM hints if needed. This
also applies to the status update, which then waits for a missing map
on every pass. A visible volume group is used as before.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/Storage/LVMPlugin.pm             |  29 ++++++
 src/test/Makefile                        |   5 +-
 src/test/run_test_lvm_base_activation.pl | 118 +++++++++++++++++++++++
 3 files changed, 151 insertions(+), 1 deletion(-)
 create mode 100755 src/test/run_test_lvm_base_activation.pl

diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 78538111..1d3eff65 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -1635,11 +1635,40 @@ my sub find_unhinted_vgs {
     delete $cache->{lvs};
 }
 
+# The base device may still be appearing after transport activation; wait before retrying LVM.
+my sub activate_missing_base {
+    my ($storeid, $scfg, $cache) = @_;
+
+    # the volume group list of the cache can predate the device
+    $cache->{vgs} = lvm_vgs();
+    return if $cache->{vgs}->{ $scfg->{vgname} };
+
+    eval {
+        my $cfg = PVE::Storage::config();
+        my ($baseid, $volname) = PVE::Storage::Plugin::parse_volume_id($scfg->{base});
+        my $basecfg = PVE::Storage::storage_config($cfg, $baseid);
+        my $plugin = PVE::Storage::Plugin->lookup($basecfg->{type});
+        # the activation of this storage activated the base storage with the same cache before
+        $plugin->activate_volume($baseid, $basecfg, $volname, undef, $cache);
+    };
+    warn "storage '$storeid': activating base volume '$scfg->{base}' failed - $@" if $@;
+
+    # A new device invalidates LVM's hints, but a PV written remotely to an existing device does
+    # not; retry without hints after each missing-base activation.
+    $cache->{vgs} = lvm_vgs();
+    # the logical volume list of the cache can predate the volume group too
+    delete $cache->{lvs};
+    find_unhinted_vgs($cache) if !$cache->{vgs}->{ $scfg->{vgname} };
+}
+
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
 
     $cache->{vgs} = lvm_vgs() if !$cache->{vgs};
 
+    activate_missing_base($storeid, $scfg, $cache)
+        if $scfg->{base} && !$cache->{vgs}->{ $scfg->{vgname} };
+
     find_unhinted_vgs($cache) if !$cache->{vgscaned} && !$cache->{vgs}->{ $scfg->{vgname} };
 
     # we do not acticate any volumes here ('vgchange -aly')
diff --git a/src/test/Makefile b/src/test/Makefile
index 389aac31..c3632e05 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_iscsi test_zfspoolplugin test_lvmplugin test_lvm_create test_lvm_lock_retry test_lvm_base_volume test_lvm_hints test_disklist test_bwlimit test_plugin test_ovf test_volume_access test_remote_command test_multipath test_san_libraries test_lun_identity
+test: test_iscsi test_zfspoolplugin test_lvmplugin test_lvm_create test_lvm_lock_retry test_lvm_base_volume test_lvm_hints test_disklist test_bwlimit test_plugin test_ovf test_volume_access test_remote_command test_multipath test_san_libraries test_lun_identity test_lvm_base_activation
 
 test_zfspoolplugin: run_test_zfspoolplugin.pl
 	./run_test_zfspoolplugin.pl
@@ -56,3 +56,6 @@ test_san_libraries: run_san_library_tests.pl
 
 test_lun_identity: run_lun_identity_tests.pl
 	./run_lun_identity_tests.pl
+
+test_lvm_base_activation: run_test_lvm_base_activation.pl
+	./run_test_lvm_base_activation.pl
diff --git a/src/test/run_test_lvm_base_activation.pl b/src/test/run_test_lvm_base_activation.pl
new file mode 100755
index 00000000..e1735fe6
--- /dev/null
+++ b/src/test/run_test_lvm_base_activation.pl
@@ -0,0 +1,118 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib '..';
+use Test::More;
+use Test::MockModule;
+
+use PVE::Storage;
+use PVE::Storage::LVMPlugin;
+
+my $CLASS = 'PVE::Storage::LVMPlugin';
+
+# the volume groups that vgs lists with its device hints, and those that only a listing without
+# hints finds
+my ($vgs, $unhinted, @calls) = ([], []);
+
+my $lvm = Test::MockModule->new('PVE::Storage::LVMPlugin');
+$lvm->mock(
+    lvm_vgs => sub {
+        my ($includepvs, $nohints) = @_;
+        push @calls, $nohints ? 'vgs --nohints' : 'vgs';
+        return { map { $_ => {} } $vgs->@*, ($nohints ? $unhinted->@* : ()) };
+    },
+    run_command => sub {
+        my ($cmd) = @_;
+        push @calls, join(' ', $cmd->[0] =~ s|^/sbin/||r, $cmd->@[1 .. $#$cmd]);
+    },
+);
+
+my $storage = Test::MockModule->new('PVE::Storage');
+$storage->mock(config => sub { return { ids => {} } });
+$storage->mock(storage_config => sub { return { type => 'fakebase' } });
+
+my $base_fails;
+my $plugin = Test::MockModule->new('PVE::Storage::Plugin');
+$plugin->mock(lookup => sub { return 'FakeBasePlugin' });
+
+{
+    no warnings 'once';
+    *FakeBasePlugin::activate_volume = sub {
+        my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
+        push @calls, "base $storeid:$volname" . ($cache->{marker} ? ' shared-cache' : '');
+        die "volume '$volname' is not available on this node\n" if $base_fails;
+        # the device appeared while waiting, and with it the volume group
+        push $vgs->@*, $volname =~ s/^vol-//r;
+    };
+}
+
+my sub activate {
+    my ($scfg, $cache, $vgs_now, $unhinted_now) = @_;
+
+    ($vgs, $unhinted, @calls) = ($vgs_now // [], $unhinted_now // []);
+    my @warnings;
+    local $SIG{__WARN__} = sub { push @warnings, $_[0] };
+    $CLASS->activate_storage('lvm', $scfg, $cache);
+    return (join(', ', @calls), \@warnings);
+}
+
+my $with_base = { vgname => 'vg1', base => 'san:vol-vg1' };
+
+my ($calls, $warnings) = activate($with_base, { vgs => { vg1 => {} } });
+is($calls, '', 'present volume group: no base activation, no scan');
+
+($calls) = activate($with_base, { vgs => {} }, ['vg1']);
+is($calls, 'vgs', 'volume group appeared meanwhile: a fresh list, no base activation');
+
+my $cache = { marker => 1, vgs => {}, lvs => {} };
+($calls) = activate($with_base, $cache);
+is(
+    $calls,
+    'vgs, base san:vol-vg1 shared-cache, vgs',
+    'missing volume group: base activated with the shared cache, the device brings it into the list',
+);
+ok($cache->{vgs}->{vg1}, 'and the volume group list of the cache is refreshed');
+ok(!exists($cache->{lvs}), 'and its logical volume list is dropped');
+
+# another node created the volume group after this node probed the device, which it had before
+$cache = { vgs => {}, vgscaned => 1 };
+{
+    no warnings 'redefine';
+    local *FakeBasePlugin::activate_volume = sub { push @calls, 'base present' };
+    ($calls) = activate($with_base, $cache, [], ['vg1']);
+}
+is(
+    $calls,
+    'vgs, base present, vgs, vgs --nohints, pvscan --cache',
+    'volume group missing from the hints: found without them despite an earlier probe',
+);
+ok($cache->{vgs}->{vg1}, 'and added to the volume group list of the cache');
+
+$cache = { vgs => {} };
+activate($with_base, $cache);
+($calls) = activate({ vgname => 'vg2', base => 'san:vol-vg2' }, $cache, ['vg1']);
+is($calls, 'vgs, base san:vol-vg2, vgs', 'a second base in the same cache is activated');
+
+$base_fails = 1;
+($calls, $warnings) = activate($with_base, { vgs => {} });
+is(
+    $calls,
+    'vgs, base san:vol-vg1, vgs, vgs --nohints',
+    'a failed base activation still looks for the volume group',
+);
+like(
+    $warnings->[0] // '',
+    qr/^storage 'lvm': activating base volume 'san:vol-vg1' failed - volume/,
+    'and warns about it',
+);
+$base_fails = 0;
+
+$cache = { vgs => {} };
+($calls) = activate({ vgname => 'vg1' }, $cache);
+is($calls, 'vgs --nohints', 'without base: one listing without hints per cache');
+($calls) = activate({ vgname => 'vg3' }, $cache);
+is($calls, '', 'and not again for the next storage');
+
+done_testing();




  parent reply	other threads:[~2026-11-16  1:25 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  1:23 [PATCH v5 cluster,storage,docs,manager 00/36] SAN: cluster-wide multipath, SAN views and a guided setup for shared LVM Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 cluster 01/36] cfs: observe the multipath configuration files Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 02/36] diskmanage: collect disk transport type from lsblk Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 03/36] diskmanage: qualify NVMe over fabrics transport Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 04/36] diskmanage: optionally include iSCSI session devices in disk enumeration Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 05/36] diskmanage: collect native NVMe multipath path state Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 06/36] iscsi: factor out session device map from device list Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 07/36] multipath: add a library around multipathd Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 08/36] diskmanage: add helper to list multipath devices Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 09/36] multipath: add a cluster-wide configuration Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 10/36] iscsi: add an option to manage storage LUNs with multipath Thomas Lamprecht
2026-11-16  1:23 ` Thomas Lamprecht [this message]
2026-11-16  1:23 ` [PATCH v5 storage 12/36] multipath: apply the configuration on every node Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 13/36] multipath: publish per-node status Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 14/36] api: add endpoints for the cluster-wide multipath configuration Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 15/36] api: multipath: add the cluster-wide health status Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 16/36] api: scan: add a SAN LUN inventory Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 17/36] pvesm: expose the " Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 18/36] api: add node-level iSCSI status Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 19/36] disks: lvm: drop unused imports Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 20/36] disks: lvm: allow volume groups on SAN LUNs and multipath maps Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 21/36] disks: lvm: refuse to destroy the volume group of a shared storage Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 storage 22/36] disks: allow wiping a SAN LUN that no storage uses Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 docs 23/36] storage: document the cluster-wide multipath management Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 24/36] pvestatd: apply the multipath configuration and report the node status Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 25/36] report: add the managed multipath configuration Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 26/36] api: cluster: add the multipath endpoints Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 27/36] api: nodes: expose the iSCSI status Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 28/36] ui: dc: add a SAN view Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 29/36] ui: storage: iscsi: add the multipath option Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 30/36] ui: lvm: enable shared when a base storage is selected Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 31/36] ui: node: add SAN LUNs panel Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 32/36] ui: node: san: wipe a LUN that no storage uses Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 33/36] ui: node: san: show iSCSI targets and sessions Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 34/36] ui: dc: san: add a guided setup for shared LVM on iSCSI Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 35/36] ui: dc: san: add a guided setup for shared LVM on Fibre Channel Thomas Lamprecht
2026-11-16  1:23 ` [PATCH v5 manager 36/36] ui: storage: point the iSCSI and LVM add dialogs to the SAN view Thomas Lamprecht
2026-11-18  8:11 ` superseded: [PATCH v5 cluster,storage,docs,manager 00/36] SAN: cluster-wide multipath, SAN views and a guided setup for shared LVM 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=20261116012355.3187417-12-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal