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 015301FF0DA for ; Thu, 19 Nov 2026 20:51:21 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A54C62180F; Thu, 19 Nov 2026 20:48:32 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v8 storage 24/43] disks: lvm: refuse to destroy the volume group of a shared storage Date: Thu, 19 Nov 2026 20:46:29 +0100 Message-ID: <20261119194655.3163258-25-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119194655.3163258-1-t.lamprecht@proxmox.com> References: <20261119194655.3163258-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: 1795117622670 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.152 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: VBTSB2NB4IDUZ6DMJYPFSSDARMHN75BV X-Message-ID-Hash: VBTSB2NB4IDUZ6DMJYPFSSDARMHN75BV 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: Destroying a volume group through the node disk API removes it with 'vgremove -y' and, with cleanup-disks, wipes its physical volumes. For a volume group on a SAN LUN, that destroys the guest disks of all nodes that use it. Refuse the removal if a shared storage is configured with a volume group of that name, also one restricted to other nodes, as this node can see its LUN as well. Volume groups of node-local storages can be destroyed as before, including the cleanup of their storage entry. Signed-off-by: Thomas Lamprecht --- src/PVE/API2/Disks/LVM.pm | 9 +++++++++ src/test/disk_api_test.pm | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/PVE/API2/Disks/LVM.pm b/src/PVE/API2/Disks/LVM.pm index 1fd68f1a..6842d674 100644 --- a/src/PVE/API2/Disks/LVM.pm +++ b/src/PVE/API2/Disks/LVM.pm @@ -3,6 +3,7 @@ package PVE::API2::Disks::LVM; use strict; use warnings; +use PVE::Storage; use PVE::Storage::LVMPlugin; use PVE::Storage::SAN; use PVE::Diskmanage; @@ -266,6 +267,14 @@ __PACKAGE__->register_method({ my $worker = sub { PVE::Diskmanage::locked_disk_action(sub { + my $cfg = PVE::Storage::config(); + for my $sid (sort keys $cfg->{ids}->%*) { + my $scfg = $cfg->{ids}->{$sid}; + if ($scfg->{shared} && ($scfg->{vgname} // '') eq $name) { + die "cannot remove volume group '$name' - shared storage '$sid' is" + . " configured with a volume group of that name\n"; + } + } my $vgs = PVE::Storage::LVMPlugin::lvm_vgs(1); die "no such volume group '$name'\n" if !$vgs->{$name}; diff --git a/src/test/disk_api_test.pm b/src/test/disk_api_test.pm index 474ad663..6fa2a2e3 100644 --- a/src/test/disk_api_test.pm +++ b/src/test/disk_api_test.pm @@ -244,4 +244,25 @@ subtest 'volume group creation leaves SAN locking to the LVM helper' => sub { $disk->unmock($_) for @mocked; }; +subtest 'shared volume groups cannot be destroyed' => sub { + my $storage = Test::MockModule->new('PVE::Storage'); + my $lvm = Test::MockModule->new('PVE::Storage::LVMPlugin'); + my $rpc = Test::MockModule->new('PVE::RPCEnvironment'); + $rpc->mock(get => sub { bless {}, 'MultipathTestRPC' }); + my $cfg = { ids => { shared => { type => 'lvm', vgname => 'data', shared => 1 } } }; + $storage->mock(config => sub { $cfg }); + $diskmanage_module->mock(locked_disk_action => sub { $_[0]->() }); + my @writes; + $lvm->mock(lvm_vgs => sub { { data => { pvs => [] } } }); + $lvm->mock(lvm_destroy_volume_group => sub { push @writes, $_[0] }); + eval { + PVE::API2::Disks::LVM->delete({ node => 'n1', name => 'data', 'cleanup-disks' => 1 }); + }; + like($@, qr/shared storage 'shared'/, 'shared reference refuses deletion'); + is_deeply(\@writes, [], 'refused VG is not removed'); + $cfg->{ids}->{shared}->{shared} = 0; + PVE::API2::Disks::LVM->delete({ node => 'n1', name => 'data' }); + is_deeply(\@writes, ['data'], 'node-local deletion still works'); +}; + done_testing();