[pve-devel] applied: [PATCH qemu-server] api create: cleanup the new config log on error

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jun 12 10:57:13 CEST 2018


On 6/12/18 10:50 AM, Wolfgang Bumiller wrote:
> Otherwise cases like trying to restore a protected VM would
> leave a lock in the config.
> 

thanks for the followup, applied

> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> ---
>  PVE/API2/Qemu.pm | 36 ++++++++++++++++++++++++++++++++----
>  1 file changed, 32 insertions(+), 4 deletions(-)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index a5ab282..c15c71f 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -564,7 +564,10 @@ __PACKAGE__->register_method({
>  
>  		PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
>  
> -		PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) if $start_after_create;
> +		if ($start_after_create) {
> +		    eval { PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) };
> +		    warn $@ if $@;
> +		}
>  	    };
>  
>  	    # ensure no old replication state are exists
> @@ -617,12 +620,37 @@ __PACKAGE__->register_method({
>  
>  	    if ($start_after_create) {
>  		print "Execute autostart\n";
> -		PVE::API2::Qemu->vm_start({vmid => $vmid, node => $node});
> +		eval { PVE::API2::Qemu->vm_start({vmid => $vmid, node => $node}) };
> +		warn $@ if $@;
>  	    }
>  	};
>  
> -	my $worker_name = $is_restore ? 'qmrestore' : 'qmcreate';
> -	my $code = $is_restore ? $restorefn : $createfn;
> +	my ($code, $worker_name);
> +	if ($is_restore) {
> +	    $worker_name = 'qmrestore';
> +	    $code = sub {
> +		eval { $restorefn->() };
> +		if (my $err = $@) {
> +		    eval { PVE::QemuConfig->remove_lock($vmid, 'create') };
> +		    warn $@ if $@;
> +		    die $err;
> +		}
> +	    };
> +	} else {
> +	    $worker_name = 'qmcreate';
> +	    $code = sub {
> +		eval { $createfn->() };
> +		if (my $err = $@) {
> +		    eval {
> +			my $conffile = PVE::QemuConfig->config_file($vmid);
> +			unlink($conffile)
> +			    or die "failed to remove config file: $@\n";
> +		    };
> +		    warn $@ if $@;
> +		    die $err;
> +		}
> +	    };
> +	}
>  
>  	return $rpcenv->fork_worker($worker_name, $vmid, $authuser, $code);
>      }});
> 





More information about the pve-devel mailing list