[pve-devel] [PATCH qemu-server 07/10] qm mtunnel/migrate: add resume VMID command
Thomas Lamprecht
t.lamprecht at proxmox.com
Fri Aug 4 12:19:59 CEST 2017
On 08/04/2017 10:55 AM, Fabian Grünbichler wrote:
> and reformat the legacy SSH variant for readability.
>
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
> PVE/CLI/qm.pm | 12 ++++++++++++
> PVE/QemuMigrate.pm | 34 ++++++++++++++++++++++++----------
> 2 files changed, 36 insertions(+), 10 deletions(-)
>
> diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> index 1bfbc1e..1792cb0 100755
> --- a/PVE/CLI/qm.pm
> +++ b/PVE/CLI/qm.pm
> @@ -280,6 +280,18 @@ __PACKAGE__->register_method ({
> if ($line =~ /^quit$/) {
> $tunnel_write->("OK");
> last;
> + } elsif ($line =~ /^resume (\d+)$/) {
> + my $vmid = $1;
> + if (PVE::QemuServer::check_running($vmid, 1)) {
> + eval { PVE::QemuServer::vm_resume($vmid, 1, 1); };
> + if ($@) {
> + $tunnel_write->("ERR: resume failed - $@");
> + } else {
> + $tunnel_write->("OK");
> + }
> + } else {
> + $tunnel_write->("ERR: resume failed - VM $vmid not running");
> + }
> }
> }
>
> diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
> index 1924754..4082122 100644
> --- a/PVE/QemuMigrate.pm
> +++ b/PVE/QemuMigrate.pm
> @@ -903,6 +903,8 @@ sub phase3_cleanup {
> my $conf = $self->{vmconf};
> return if $self->{phase2errors};
>
> + my $tunnel = $self->{tunnel};
> +
> if ($self->{storage_migration}) {
> # finish block-job
> eval { PVE::QemuServer::qemu_drive_mirror_monitor($vmid, undef, $self->{storage_migration_jobs}); };
> @@ -948,17 +950,29 @@ sub phase3_cleanup {
> $self->{errors} = 1;
> }
> }
> +
> # config moved and nbd server stopped - now we can resume vm on target
> - my $cmd = [@{$self->{rem_ssh}}, 'qm', 'resume', $vmid, '--skiplock', '--nocheck'];
> - eval{ PVE::Tools::run_command($cmd, outfunc => sub {},
> - errfunc => sub {
> - my $line = shift;
> - $self->log('err', $line);
> - });
> - };
> - if (my $err = $@) {
> - $self->log('err', $err);
> - $self->{errors} = 1;
> + if ($tunnel && $tunnel->{version} && $tunnel->{version} >= 1.0) {
> + 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'];
> + eval {
> + my $logf = sub {
> + my $line = shift;
> + $self->log('err', $line);
> + };
nitpick: I'd define this either out of the eval scope or directly as
inline sub, preferring the former.
Setting "$self->{errors} = 1;" in the $logf would make sense, I guess?
> + PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => $logf);
> + };
> + if (my $err = $@) {
> + $self->log('err', $err);
> + $self->{errors} = 1;
> + }
> }
> }
>
>
More information about the pve-devel
mailing list