From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 712EE1FF0C0 for ; Wed, 18 Nov 2026 21:28:23 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1E60E216F7; Wed, 18 Nov 2026 21:27:57 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v7 storage 11/43] lvm: activate a missing base volume before using the volume group Date: Wed, 18 Nov 2026 21:25:54 +0100 Message-ID: <20261118202646.3017286-12-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118202646.3017286-1-t.lamprecht@proxmox.com> References: <20261118202646.3017286-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: 1795033611700 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.168 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: J7CAHI2K24ITCGA62GISO5GKBBYOOCXJ X-Message-ID-Hash: J7CAHI2K24ITCGA62GISO5GKBBYOOCXJ 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: 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 and look again, without the LVM hints if needed. For the map of an iSCSI storage with the multipath option, activating waits for the map to appear. The status update does not wait. So there, the storage stays inactive until a later pass finds its volume group. Signed-off-by: Thomas Lamprecht --- src/PVE/Storage/LVMPlugin.pm | 33 ++++++- src/test/Makefile | 5 +- src/test/run_test_lvm_base_activation.pl | 121 +++++++++++++++++++++++ 3 files changed, 156 insertions(+), 3 deletions(-) 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 63e5a473..966a70d3 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -1632,8 +1632,8 @@ sub volume_snapshot_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. +# hints, normally once per activation cache and again after activating a missing base volume; +# rebuild only when new VGs appear, since rebuilding also resets LVM autoactivation records. my sub find_unhinted_vgs { my ($cache) = @_; @@ -1654,11 +1654,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();