[pve-devel] [PATCH v2 guest-common 2/2] snapshots: abort if new snapshot name is already parent to existing one

Oguz Bektas o.bektas at proxmox.com
Wed Oct 13 14:31:54 CEST 2021


Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 src/PVE/AbstractConfig.pm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
index 3348d8a..6849664 100644
--- a/src/PVE/AbstractConfig.pm
+++ b/src/PVE/AbstractConfig.pm
@@ -721,14 +721,22 @@ sub __snapshot_prepare {
 
 	$conf->{lock} = 'snapshot';
 
+	my $snapshots = $conf->{snapshots};
+
 	die "snapshot name '$snapname' already used\n"
-	    if defined($conf->{snapshots}->{$snapname});
+	    if defined($snapshots->{$snapname});
 
 	my $storecfg = PVE::Storage::config();
 	die "snapshot feature is not available\n"
 	    if !$class->has_feature('snapshot', $conf, $storecfg, undef, undef, $snapname eq 'vzdump');
 
-	$snap = $conf->{snapshots}->{$snapname} = {};
+	foreach my $existing_snapshot (keys %$snapshots) {
+	    my $parent_name = $snapshots->{$existing_snapshot}->{parent} // '';
+	    die "snapshot '$snapname' cannot be used, $snapname already a parent for $existing_snapshot\n"
+		if $snapname eq $parent_name;
+	}
+
+	$snap = $snapshots->{$snapname} = {};
 
 	if ($save_vmstate && $class->__snapshot_check_running($vmid)) {
 	    $class->__snapshot_save_vmstate($vmid, $conf, $snapname, $storecfg);
-- 
2.30.2





More information about the pve-devel mailing list