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 60F501FF0B7 for ; Fri, 13 Nov 2026 04:05:37 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 00A2621860; Fri, 13 Nov 2026 04:02:21 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v4 storage 11/36] lvm: activate a missing base volume before using the volume group Date: Fri, 13 Nov 2026 04:00:29 +0100 Message-ID: <20261113030146.1559030-12-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113030146.1559030-1-t.lamprecht@proxmox.com> References: <20261113030146.1559030-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: 1794538914228 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.247 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: WMVK7GOJPFFBE7RBHQD3FGOXOLE6NDZ3 X-Message-ID-Hash: WMVK7GOJPFFBE7RBHQD3FGOXOLE6NDZ3 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 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 --- src/PVE/Storage/LVMPlugin.pm | 29 ++++++ src/test/Makefile | 5 +- src/test/run_test_lvm_base_activation.pl | 117 +++++++++++++++++++++++ 3 files changed, 150 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 479e27e9..ccae074a 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -1607,11 +1607,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..fe0c573f --- /dev/null +++ b/src/test/run_test_lvm_base_activation.pl @@ -0,0 +1,117 @@ +#!/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 vgs lists through the device hints, those only a listing without them 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'); + +# the volume group another node created on a device this node had before, after an earlier probe +$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();