[pve-devel] [PATCH qemu-server 1/4] add forcemachine rollback code

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Sep 13 12:56:17 CEST 2018


On Thu, Sep 13, 2018 at 12:15:04PM +0200, Dominik Csapak wrote:
> this was in guest-common, makes more sense to do it here
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  PVE/QemuConfig.pm | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
> index b24773c..5cc2d48 100644
> --- a/PVE/QemuConfig.pm
> +++ b/PVE/QemuConfig.pm
> @@ -281,6 +281,25 @@ sub __snapshot_delete_vol_snapshot {
>      push @$unused, $volid;
>  }
>  
> +sub __snapshot_rollback_hook {
> +    my ($class, $vmid, $conf, $snap, $prepare, $data) = @_;
> +
> +    if ($prepare) {
> +	# we save the machine of the current config
> +	$data->{oldmachine} = $conf->{machine};
> +    } else {
> +	# Note: old code did not store 'machine', so we try to be smart
> +	# and guess the snapshot was generated with kvm 1.4 (pc-i440fx-1.4).
> +	$data->{forcemachine} = $conf->{machine} || 'pc-i440fx-1.4';
> +
> +	# we remove the 'machine' configuration if not explicitly specified
> +	# in the original config.
> +	delete $conf->{machine} if $snap->{vmstate} && !defined($data->{oldmachine});
> +    }
> +
> +    return;
> +}
> +
>  sub __snapshot_rollback_vol_possible {
>      my ($class, $drive, $snapname) = @_;
>  
> @@ -309,10 +328,20 @@ sub __snapshot_rollback_vm_stop {
>  }
>  
>  sub __snapshot_rollback_vm_start {
> -    my ($class, $vmid, $vmstate, $forcemachine) = @_;
> +    my ($class, $vmid, $vmstate, $data) = @_;
>  
>      my $storecfg = PVE::Storage::config();
>      my $statefile = PVE::Storage::path($storecfg, $vmstate);
> +
> +    # workaround for cyclic dependcy
> +    # works with old and new pve-guest-common
> +    # (without and with rollback hook respectively)

I'd prefer a versioned dependency (qemu-server ->
libpve-guest-common-perl) and a versioned breaks (<-) instead of
workarounds that we have to carry until the end of PVE 5, and then
remember to remove.

> +    my $forcemachine;
> +    if (ref($data) eq 'HASH') {
> +	$forcemachine = $data->{forcemachine};
> +    } elsif (!ref($data)) {
> +	$forcemachine = $data;
> +    }
>      PVE::QemuServer::vm_start($storecfg, $vmid, $statefile, undef, undef, undef, $forcemachine);
>  }
>  
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list