use Data::Dumper;
use JSON;
use Time::HiRes qw(gettimeofday tv_interval);
+use POSIX qw(strftime);
use PVE::INotify;
use PVE::ProcFSTools;
# regression tests should overwrite this
sub get_log_time {
- return time();
+ return strftime("%F %H:%M:%S", localtime);
}
# Find common base replication snapshot, available on local and remote side.
PVE::ReplicationConfig::delete_job($jobid); # update config
$logfunc->("job removed");
- return;
+ return undef;
}
my $ssh_info = PVE::Cluster::get_ssh_info($jobcfg->{target}, $migration_network);
remote_finalize_local_job($ssh_info, $jobid, $vmid, $sorted_volids, $start_time, $logfunc);
die $err if $err;
+
+ return $volumes;
}
my $run_replication_nolock = sub {
- my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc) = @_;
+ my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $verbose) = @_;
my $jobid = $jobcfg->{id};
+ my $volumes;
+
# we normaly write errors into the state file,
# but we also catch unexpected errors and log them to syslog
# (for examply when there are problems writing the state file)
my $ctime = get_log_time();
print $logfd "$ctime $jobid: $msg\n";
- $logfunc->("$ctime $jobid: $msg") if $logfunc;
+ if ($logfunc) {
+ if ($verbose) {
+ $logfunc->("$ctime $jobid: $msg");
+ } else {
+ $logfunc->($msg);
+ }
+ }
};
$logfunc_wrapper->("start replication job");
eval {
- replicate($guest_class, $jobcfg, $state, $start_time, $logfunc_wrapper);
+ $volumes = replicate($guest_class, $jobcfg, $state, $start_time, $logfunc_wrapper);
};
my $err = $@;
if (my $err = $@) {
warn "$jobid: got unexpected replication job error - $err";
}
+
+ return $volumes;
};
sub run_replication {
- my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $noerr) = @_;
+ my ($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $noerr, $verbose) = @_;
+
+ my $volumes;
eval {
my $timeout = 2; # do not wait too long - we repeat periodically anyways
- PVE::GuestHelpers::guest_migration_lock(
+ $volumes = PVE::GuestHelpers::guest_migration_lock(
$jobcfg->{guest}, $timeout, $run_replication_nolock,
- $guest_class, $jobcfg, $iteration, $start_time, $logfunc);
+ $guest_class, $jobcfg, $iteration, $start_time, $logfunc, $verbose);
};
if (my $err = $@) {
return undef if $noerr;
die $err;
}
+ return $volumes;
}
1;