- # now that config file is move, we can resume vm on target if livemigrate
- my $cmd = [@{$self->{rem_ssh}}, 'qm', 'resume', $vmid, '--skiplock'];
- eval{ PVE::Tools::run_command($cmd, outfunc => sub {},
- errfunc => sub {
- my $line = shift;
- $self->log('err', $line);
- });
- };
+ if ($self->{storage_migration}) {
+ # stop nbd server on remote vm - requirement for resume since 2.9
+ my $cmd = [@{$self->{rem_ssh}}, 'qm', 'nbdstop', $vmid];
+
+ eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
+ if (my $err = $@) {
+ $self->log('err', $err);
+ $self->{errors} = 1;
+ }
+ }
+
+ # config moved and nbd server stopped - now we can resume vm on target
+ if ($tunnel && $tunnel->{version} && $tunnel->{version} >= 1) {
+ eval {
+ $self->write_tunnel($tunnel, 30, "resume $vmid");
+ };
+ if (my $err = $@) {
+ $self->log('err', $err);
+ $self->{errors} = 1;
+ }
+ } else {
+ my $cmd = [@{$self->{rem_ssh}}, 'qm', 'resume', $vmid, '--skiplock', '--nocheck'];
+ my $logf = sub {
+ my $line = shift;
+ $self->log('err', $line);
+ };
+ eval { PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => $logf); };
+ if (my $err = $@) {
+ $self->log('err', $err);
+ $self->{errors} = 1;
+ }
+ }
+ }
+
+ # close tunnel on successful migration, on error phase2_cleanup closed it
+ if ($tunnel) {
+ eval { finish_tunnel($self, $tunnel); };