[pve-devel] [PATCH v3 guest-common 2/2] snapshots: delete parent property if new snapshot name is already a parent to existing one

Hannes Laimer h.laimer at proxmox.com
Mon Nov 29 13:31:27 CET 2021


Tested-by: Hannes Laimer <h.laimer at proxmox.com>

Works as advertised, only affects old configs created before the first
patch was applied.

Am 14.10.21 um 11:29 schrieb Oguz Bektas:
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
> v2->v3:
> * automatically delete the 'parent' property for an existing snapshot
> (instead of aborting) if its the same as the new snapshot name (and the
> snapshot referenced by 'parent' is not used)
> 
> 
> 
>  src/PVE/AbstractConfig.pm | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
> index 3348d8a..e4ddeab 100644
> --- a/src/PVE/AbstractConfig.pm
> +++ b/src/PVE/AbstractConfig.pm
> @@ -721,14 +721,21 @@ 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} // '';
> +	    delete $snapshots->{$existing_snapshot}->{parent} if $snapname eq $parent_name;
> +	}
> +
> +	$snap = $snapshots->{$snapname} = {};
>  
>  	if ($save_vmstate && $class->__snapshot_check_running($vmid)) {
>  	    $class->__snapshot_save_vmstate($vmid, $conf, $snapname, $storecfg);
> 





More information about the pve-devel mailing list