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 C613E1FF0AF for ; Fri, 06 Nov 2026 01:50:15 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4BE5F216AD; Fri, 06 Nov 2026 01:49:45 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v3 storage 10/76] lvm: refuse a base volume of a target that serves disk images Date: Fri, 6 Nov 2026 00:30:45 +0100 Message-ID: <20261105233336.2178064-11-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261105233336.2178064-1-t.lamprecht@proxmox.com> References: <20261105233336.2178064-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: 1793926177940 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.343 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: VC7IKGMPBQWAMMZCNMSSFRYLQUSXXMU5 X-Message-ID-Hash: VC7IKGMPBQWAMMZCNMSSFRYLQUSXXMU5 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: A LUN can be a guest disk without any signature. Refuse LVM initialization if another storage uses its target for disk images: iSCSI with content images, iSCSI direct, or ZFS over iSCSI. Check all storages using the target, regardless of their state or node restriction. Signed-off-by: Thomas Lamprecht --- src/PVE/Storage/LVMPlugin.pm | 11 +++++ src/test/Makefile | 3 +- src/test/run_test_lvm_base_conflicts.pl | 62 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 src/test/run_test_lvm_base_conflicts.pl diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 26908d7e..d718d8f8 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -1041,6 +1041,17 @@ sub on_add_hook { my $basecfg = PVE::Storage::storage_config($cfg, $baseid, 1); die "base storage ID '$baseid' does not exist\n" if !$basecfg; + if (my $target = $basecfg->{target}) { + for my $sid (sort keys $cfg->{ids}->%*) { + my $other = $cfg->{ids}->{$sid}; + next if ($other->{target} // '') ne $target; + die "storage '$sid' serves disk images from this target\n" + if $other->{content}->{images} + || $other->{type} eq 'iscsidirect' + || $other->{type} eq 'zfs'; + } + } + # we only support iscsi for now die "unsupported base type '$basecfg->{type}'" if $basecfg->{type} ne 'iscsi'; diff --git a/src/test/Makefile b/src/test/Makefile index 1cc8f00e..415d62bf 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -9,8 +9,9 @@ test_lvmplugin: run_test_lvmplugin.pl run_test_lvm_throughput.pl ./run_test_lvmplugin.pl ./run_test_lvm_throughput.pl -test_lvm_create: run_test_lvm_create.pl +test_lvm_create: run_test_lvm_create.pl run_test_lvm_base_conflicts.pl ./run_test_lvm_create.pl + ./run_test_lvm_base_conflicts.pl test_lvm_lock_retry: run_test_lvm_lock_retry.pl ./run_test_lvm_lock_retry.pl diff --git a/src/test/run_test_lvm_base_conflicts.pl b/src/test/run_test_lvm_base_conflicts.pl new file mode 100755 index 00000000..ccb77e00 --- /dev/null +++ b/src/test/run_test_lvm_base_conflicts.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::MockModule; +use Test::More; + +use lib ('.', '..'); +use PVE::Storage; +use PVE::Storage::LVMPlugin; + +my $storage = Test::MockModule->new('PVE::Storage'); +my $lvm = Test::MockModule->new('PVE::Storage::LVMPlugin'); +my ($cfg, $created); +$storage->mock( + config => sub { $cfg }, + path => sub { '/dev/sda' }, + activate_storage => sub { }, + activate_volumes => sub { }, +); +$lvm->mock( + lvm_create_volume_group => sub { $created++ }, + assert_discard_supported => sub { }, +); + +for my $case ( + ['iscsi', {}, 0], + ['iscsi', { images => 1 }, 1], + ['iscsidirect', {}, 1], + ['zfs', {}, 1], + ['vendor', { images => 1 }, 1], +) { + my ($type, $content, $conflict) = @$case; + $created = 0; + $cfg = { + ids => { + base => { type => 'iscsi', target => 'iqn.test', content => { none => 1 } }, + other => { + type => $type, + target => 'iqn.test', + content => $content, + disable => 1, + nodes => { elsewhere => 1 }, + }, + }, + }; + eval { + PVE::Storage::LVMPlugin->on_add_hook( + 'test', + { base => 'base:0.0.1.scsi-test', vgname => 'test' }, + ); + }; + if ($conflict) { + like($@, qr/storage 'other' serves disk images from this target/, "$type conflict refused"); + } else { + is($@, '', 'connection-only storage permits initialization'); + } + is($created, $conflict ? 0 : 1, 'no writes on conflicting target'); +} + +done_testing(); -- 2.47.3