]> git.proxmox.com Git - pve-guest-common.git/commitdiff
PVE/ReplicationState.pm: implement write_vmid_job_states
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 12 Jun 2017 09:33:05 +0000 (11:33 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 12 Jun 2017 09:33:05 +0000 (11:33 +0200)
Update all job states related to a specific $vmid

PVE/ReplicationState.pm

index 22649f91110252af2097db469c7a9b6ae510f831..ae4deaf0f500b99a4ca758f447fda9aae12e79be 100644 (file)
@@ -68,6 +68,7 @@ sub read_job_state {
     return extract_job_state($stateobj, $jobcfg);
 }
 
+# update state for a single job
 sub write_job_state {
     my ($jobcfg, $state) = @_;
 
@@ -94,6 +95,25 @@ sub write_job_state {
     PVE::GuestHelpers::guest_migration_lock($vmid, undef, $code);
 }
 
+# update all job states related to a specific $vmid
+sub write_vmid_job_states {
+    my ($vmid_state, $vmid) = @_;
+
+    my $update = sub {
+       my $stateobj = read_state();
+       $stateobj->{$vmid} = $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);
+}
+
 sub replication_snapshot_name {
     my ($jobid, $last_sync) = @_;