[pve-devel] [PATCH pve-guest-common 1/2] Add function delete_state

Wolfgang Link w.link at proxmox.com
Mon Jun 26 13:09:50 CEST 2017


This function can be used if a state will not longer needed, like if you delete a job.
---
 PVE/ReplicationState.pm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/PVE/ReplicationState.pm b/PVE/ReplicationState.pm
index 6a743a3..952d474 100644
--- a/PVE/ReplicationState.pm
+++ b/PVE/ReplicationState.pm
@@ -129,6 +129,28 @@ sub write_vmid_job_states {
     PVE::GuestHelpers::guest_migration_lock($vmid, undef, $code);
 }
 
+sub delete_jobs_in_state {
+    my ($vmid, $tid) = @_;
+
+    my $update = sub {
+
+	my $stateobj = read_state();
+	# Note: tuple ($vmid, $tid) is unique
+	delete $stateobj->{$vmid}->{$tid} if $tid;
+	delete $stateobj->{$vmid} if !%{$stateobj->{$vmid}};
+
+	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 record_job_start {
     my ($jobcfg, $state, $start_time, $iteration) = @_;
 
-- 
2.11.0





More information about the pve-devel mailing list