From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C760C9D5F8 for ; Thu, 26 Oct 2023 10:57:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A98291D0C6 for ; Thu, 26 Oct 2023 10:57:22 +0200 (CEST) Received: from bastionodiso.odiso.net (bastionodiso.odiso.net [185.151.191.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 26 Oct 2023 10:57:17 +0200 (CEST) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id 7F0ED7CEB; Thu, 26 Oct 2023 10:57:11 +0200 (CEST) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 67C945CFC9; Thu, 26 Oct 2023 10:57:11 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Thu, 26 Oct 2023 10:57:09 +0200 Message-Id: <20231026085710.1611413-3-aderumier@odiso.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231026085710.1611413-1-aderumier@odiso.com> References: <20231026085710.1611413-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy HEADER_FROM_DIFFERENT_DOMAINS 0.25 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods SPF_NONE 0.001 SPF: sender does not publish an SPF Record T_SPF_HELO_TEMPERROR 0.01 SPF: test of HELO record failed (temperror) URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemu.pm, qemumigrate.pm, qm.pm] Subject: [pve-devel] [PATCH v5 qemu-server 2/3] remote-migration: add restart param X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Oct 2023 08:57:52 -0000 This patch add support for migration without memory transfert. After the optionnal storage migration, we cleanly shutdown source vm and restart the target vm. (like a virtual restart between source/dest) Signed-off-by: Alexandre Derumier --- PVE/API2/Qemu.pm | 19 +++++++++++++++++++ PVE/CLI/qm.pm | 5 +++++ PVE/QemuMigrate.pm | 31 ++++++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 38bdaab..c0ae516 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -4583,6 +4583,11 @@ __PACKAGE__->register_method({ optional => 1, default => 0, }, + 'restart' => { + type => 'boolean', + description => "For online migration, skip memory migration and restart the vm.", + optional => 1, + }, 'target-storage' => get_standard_option('pve-targetstorage', { completion => \&PVE::QemuServer::complete_migration_storage, optional => 0, @@ -5729,6 +5734,20 @@ __PACKAGE__->register_method({ PVE::QemuServer::nbd_stop($state->{vmid}); return; }, + 'restart' => sub { + my $nocheck = 1; + my $timeout = 1; + my $shutdown = undef; + my $force = undef; + my $keepactive = 1; + PVE::QemuServer::vm_stop($storecfg, $state->{vmid}, $nocheck, $timeout, undef, undef, $keepactive); + my $info = PVE::QemuServer::vm_start_nolock( + $state->{storecfg}, + $state->{vmid}, + $state->{conf}, + ); + return; + }, 'resume' => sub { if (PVE::QemuServer::Helpers::vm_running_locally($state->{vmid})) { PVE::QemuServer::vm_resume($state->{vmid}, 1, 1); diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm index b17b4fe..12c5291 100755 --- a/PVE/CLI/qm.pm +++ b/PVE/CLI/qm.pm @@ -189,6 +189,11 @@ __PACKAGE__->register_method({ optional => 1, default => 0, }, + 'restart' => { + type => 'boolean', + description => "For online migration , skip memory migration and restart the vm.", + optional => 1, + }, 'target-storage' => get_standard_option('pve-targetstorage', { completion => \&PVE::QemuServer::complete_migration_storage, optional => 0, diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm index 7dd3455..c801362 100644 --- a/PVE/QemuMigrate.pm +++ b/PVE/QemuMigrate.pm @@ -731,6 +731,11 @@ sub cleanup_bitmaps { sub live_migration { my ($self, $vmid, $migrate_uri, $spice_port) = @_; + if($self->{opts}->{'restart'}){ + $self->log('info', "using restart migration - skipping live migration."); + return; + } + my $conf = $self->{vmconf}; $self->log('info', "starting online/live migration on $migrate_uri"); @@ -1358,7 +1363,14 @@ sub phase2 { # finish block-job with block-job-cancel, to disconnect source VM from NBD # to avoid it trying to re-establish it. We are in blockjob ready state, # thus, this command changes to it to blockjob complete (see qapi docs) - eval { PVE::QemuServer::qemu_drive_mirror_monitor($vmid, undef, $self->{storage_migration_jobs}, 'cancel'); }; + my $finish_cmd = "cancel"; + if ($self->{opts}->{'restart'}) { + # no live migration. + # finish block-job with block-job-complete, the source will switch to remote NDB + # then we cleanly stop the source vm during phase3 + $finish_cmd = "complete"; + } + eval { PVE::QemuServer::qemu_drive_mirror_monitor($vmid, undef, $self->{storage_migration_jobs}, $finish_cmd); }; if (my $err = $@) { die "Failed to complete storage migration: $err\n"; } @@ -1575,7 +1587,17 @@ sub phase3_cleanup { }; # always stop local VM with nocheck, since config is moved already - eval { PVE::QemuServer::vm_stop($self->{storecfg}, $vmid, 1, 1); }; + my $shutdown_timeout = undef; + my $shutdown = undef; + my $force_stop = undef; + if ($self->{opts}->{'restart'}) { + $shutdown_timeout = 180; + $shutdown = 1; + $force_stop = 1; + $self->log('info', "shutting down source vm"); + } + + eval { PVE::QemuServer::vm_stop($self->{storecfg}, $vmid, 1, 1, $shutdown_timeout, $shutdown, $force_stop); }; if (my $err = $@) { $self->log('err', "stopping vm failed - $err"); $self->{errors} = 1; @@ -1609,7 +1631,10 @@ sub phase3_cleanup { # clear migrate lock if ($tunnel && $tunnel->{version} >= 2) { PVE::Tunnel::write_tunnel($tunnel, 10, "unlock"); - + if ($self->{opts}->{'restart'}) { + $self->log('info', "restart target vm"); + PVE::Tunnel::write_tunnel($tunnel, 10, 'restart'); + } PVE::Tunnel::finish_tunnel($tunnel); } else { my $cmd = [ @{$self->{rem_ssh}}, 'qm', 'unlock', $vmid ]; -- 2.39.2