From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v6 storage 11/42] lvm: activate a missing base volume before using the volume group
Date: Wed, 18 Nov 2026 07:52:28 +0100 [thread overview]
Message-ID: <20261118065302.3033937-12-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261118065302.3033937-1-t.lamprecht@proxmox.com>
Activating an LVM storage activates its base storage, but not the
base volume. Right after the login, the device of the base volume can
still be appearing, for example while multipathd assembles the map. 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. The
status update does not wait for the device. So there, the storage
stays inactive until a later pass finds its volume group.
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 | 121 +++++++++++++++++++++++
3 files changed, 154 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 16a3d65f..f9c72764 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -1653,11 +1653,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 lists of the cache can predate the device; add, as an incomplete listing must not hide
+ # volume groups found before
+ $cache->{vgs} = { $cache->{vgs}->%*, lvm_vgs()->%* };
+ delete $cache->{lvs};
+ 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} = { $cache->{vgs}->%*, lvm_vgs()->%* };
+ 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 904f2b29..72e306f7 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_sensitive_properties test_import_stream 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_sensitive_properties test_import_stream test_multipath test_san_libraries test_lun_identity test_lvm_base_activation
test_zfspoolplugin: run_test_zfspoolplugin.pl
./run_test_zfspoolplugin.pl
@@ -62,3 +62,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..a5e641fe
--- /dev/null
+++ b/src/test/run_test_lvm_base_activation.pl
@@ -0,0 +1,121 @@
+#!/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');
+$cache = { vgs => { vgold => {} } };
+activate($with_base, $cache, ['vg1']);
+ok($cache->{vgs}->{vgold}, 'a volume group found before stays in the list');
+
+# 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();
next prev parent reply other threads:[~2026-11-18 6:54 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 6:52 [PATCH v6 cluster,storage,docs,manager 00/42] SAN: cluster-wide multipath, SAN views and a guided setup for shared LVM Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 cluster 01/42] cfs: observe the multipath configuration files Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 02/42] diskmanage: collect disk transport type from lsblk Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 03/42] diskmanage: qualify NVMe over fabrics transport Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 04/42] diskmanage: optionally include iSCSI session devices in disk enumeration Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 05/42] diskmanage: collect native NVMe multipath path state Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 06/42] iscsi: factor out session device map from device list Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 07/42] multipath: add a library around multipathd Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 08/42] diskmanage: add helper to list multipath devices Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 09/42] multipath: add a cluster-wide configuration Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 10/42] iscsi: add an option to manage storage LUNs with multipath Thomas Lamprecht
2026-11-18 6:52 ` Thomas Lamprecht [this message]
2026-11-18 6:52 ` [PATCH v6 storage 12/42] multipath: apply the configuration on every node Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 13/42] multipath: publish per-node status Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 14/42] api: add endpoints for the cluster-wide multipath configuration Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 15/42] api: multipath: add the cluster-wide health status Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 16/42] diskmanage: look up the requested disks by name Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 17/42] diskmanage: read the udev data of all disks with one call Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 18/42] api: scan: add a SAN LUN inventory Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 19/42] pvesm: expose the " Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 20/42] api: add node-level iSCSI status Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 21/42] disks: lvm: drop unused imports Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 22/42] disks: lvm: allow volume groups on SAN LUNs and multipath maps Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 23/42] disks: lvm: refuse to destroy the volume group of a shared storage Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 24/42] disks: allow wiping a SAN LUN that no storage uses Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 storage 25/42] api: scan: report the process that has a SAN LUN open Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 docs 26/42] storage: document the cluster-wide multipath management Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 docs 27/42] storage: multipath: describe the use shown for an open LUN Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 28/42] pvestatd: apply the multipath configuration and report the node status Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 29/42] report: add the managed multipath configuration Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 30/42] api: cluster: add the multipath endpoints Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 31/42] api: nodes: expose the iSCSI status Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 32/42] ui: dc: add a SAN view Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 33/42] ui: storage: iscsi: add the multipath option Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 34/42] ui: lvm: enable shared when a base storage is selected Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 35/42] ui: node: add SAN LUNs panel Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 36/42] ui: node: san: wipe a LUN that no storage uses Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 37/42] ui: node: san: show iSCSI targets and sessions Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 38/42] ui: dc: san: add a guided setup for shared LVM on iSCSI Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 39/42] ui: dc: san: add a guided setup for shared LVM on Fibre Channel Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 40/42] ui: storage: point the iSCSI and LVM add dialogs to the SAN view Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 41/42] ui: san: show the guest or process that has a LUN open Thomas Lamprecht
2026-11-18 6:52 ` [PATCH v6 manager 42/42] ui: node: san: add a column for the iSCSI target of a LUN Thomas Lamprecht
2026-11-18 20:28 ` superseded: [PATCH v6 cluster,storage,docs,manager 00/42] 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=20261118065302.3033937-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.