use JSON;
use PVE::INotify;
+use PVE::ProcFSTools;
use PVE::Tools;
use PVE::CalendarEvent;
use PVE::Cluster;
return $state;
}
+sub extract_vmid_tranfer_state {
+ my ($stateobj, $vmid, $old_target, $new_target) = @_;
+
+ my $oldid = PVE::ReplicationConfig::Cluster->get_unique_target_id({ target => $old_target });
+ my $newid = PVE::ReplicationConfig::Cluster->get_unique_target_id({ target => $new_target });
+
+ if (defined(my $vmstate = $stateobj->{$vmid})) {
+ $vmstate->{$newid} = delete($vmstate->{$oldid}) if defined($vmstate->{$oldid});
+ return $vmstate;
+ }
+
+ return {};
+}
+
sub read_job_state {
my ($jobcfg) = @_;
PVE::GuestHelpers::guest_migration_lock($vmid, undef, $code);
}
+sub record_job_start {
+ my ($jobcfg, $state, $start_time, $iteration) = @_;
+
+ $state->{pid} = $$;
+ $state->{ptime} = PVE::ProcFSTools::read_proc_starttime($state->{pid});
+ $state->{last_node} = PVE::INotify::nodename();
+ $state->{last_try} = $start_time;
+ $state->{last_iteration} = $iteration;
+ $state->{storeid_list} //= [];
+
+ write_job_state($jobcfg, $state);
+}
+
+sub record_job_end {
+ my ($jobcfg, $state, $start_time, $duration, $err) = @_;
+
+ $state->{duration} = $duration;
+ delete $state->{pid};
+ delete $state->{ptime};
+
+ if ($err) {
+ chomp $err;
+ $state->{fail_count}++;
+ $state->{error} = "$err";
+ } else {
+ $state->{last_sync} = $start_time;
+ $state->{fail_count} = 0;
+ delete $state->{error};
+ }
+ write_job_state($jobcfg, $state);
+}
+
sub replication_snapshot_name {
my ($jobid, $last_sync) = @_;