From b6fefb03ba1ac408ba09d64dffaa7a5b776f2395 Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Wed, 8 Oct 2025 17:11:32 +0200 Subject: [PATCH] lvm plugin: disallow disabling 'snapshot-as-volume-chain' while a qcow2 image exists There are multiple reasons to disallow disabling 'snapshot-as-volume-chain' while a qcow2 image exists: 1. The list of allowed formats depends on 'snapshot-as-volume-chain'. 2. Snapshot functionality is broken. This includes creating snapshots, but also rollback, which removes the current volume and then fails. 3. There already is coupling between having qcow2 on LVM and having 'snapshot-as-volume-chain' enabled. For example, the 'discard-no-unref' option is required for qcow2 on LVM, but qemu-server only checks for 'snapshot-as-volume-chain' to avoid hard-coding LVM. Another one is that volume_qemu_snapshot_method() returns 'mixed' when the format is qcow2 even when 'snapshot-as-volume-chain' is disabled. Hunting down these corner cases just to make it easier to disable does not seem to be worth it, considering there's already 1. and 2. as reasons too. 4. There might be other similar issues that have not surfaced yet, because disabling the feature while qcow2 is present is essentially untested and very uncommon. For file-based storages, the 'snapshot-as-volume-chain' property is already fixed, i.e. is determined upon storage creation. Signed-off-by: Fiona Ebner --- src/PVE/Storage/LVMPlugin.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 3badfef..97f7bf4 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -500,6 +500,25 @@ sub on_add_hook { return; } +sub on_update_hook_full { + my ($class, $storeid, $scfg, $update, $delete, $sensitive) = @_; + + if ( + $scfg->{'snapshot-as-volume-chain'} # currently set + && ( # and won't be set after update, because: + ( + defined($update->{'snapshot-as-volume-chain'}) + && !$update->{'snapshot-as-volume-chain'} + ) # explicitly set to disabled + || grep { $_ eq 'snapshot-as-volume-chain' } $delete->@* # or deleted + ) + ) { + my $images = $class->list_images($storeid, $scfg, undef, undef, undef); + die "$storeid - cannot disable 'snapshot-as-volume-chain' while a qcow2 image exists\n" + if grep { $_->{format} eq 'qcow2' } $images->@*; + } +} + sub parse_volname { my ($class, $volname) = @_;