[pve-devel] [pve-guest-common 2/2] set_remote_state

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jun 9 11:13:48 CEST 2017


why not use PVE::ReplicatioNState::write_job_state() ?

On Fri, Jun 09, 2017 at 08:19:48AM +0200, Wolfgang Link wrote:
> ---
>  PVE/ReplicationState.pm | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/PVE/ReplicationState.pm b/PVE/ReplicationState.pm
> index be5cf5f..086d62f 100644
> --- a/PVE/ReplicationState.pm
> +++ b/PVE/ReplicationState.pm
> @@ -92,4 +92,23 @@ sub replication_snapshot_name {
>      wantarray ? ($prefix, $snapname) : $snapname;
>  }
>  
> +sub set_remote_state {
> +    my ($state, $vmid) = @_;
> +
> +    my $update = sub {
> +	my $stateobj = read_state();
> +	$stateobj->{$vmid} = $state;
> +	PVE::Tools::file_set_contents($state_path, encode_json($stateobj));
> +    };
> +
> +    my $code = sub {
> +	PVE::Tools::lock_file($state_lock, 10, $update);
> +	die $@ if $@;
> +    };
> +
> +    # make sure we have guest_migration_lock during update
> +    PVE::GuestHelpers::guest_migration_lock($vmid, undef, $code);
> +
> +}
> +
>  1;
> -- 
> 2.11.0
> 




More information about the pve-devel mailing list