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 EA37498878 for ; Tue, 25 Apr 2023 18:52:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D33AE3E858 for ; Tue, 25 Apr 2023 18:52:43 +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 ; Tue, 25 Apr 2023 18:52:42 +0200 (CEST) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id D62CB82AD; Tue, 25 Apr 2023 18:52:33 +0200 (CEST) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id C333E350DA; Tue, 25 Apr 2023 18:52:33 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Tue, 25 Apr 2023 18:52:33 +0200 Message-Id: <20230425165233.3745210-3-aderumier@odiso.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230425165233.3745210-1-aderumier@odiso.com> References: <20230425165233.3745210-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 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_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qm.pm, qemumigrate.pm, qemu.pm] Subject: [pve-devel] [PATCH v2 qemu-server 2/2] remote-migration: add target-cpu 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: Tue, 25 Apr 2023 16:52:44 -0000 This patch add support for remote migration when target cpu model is different. The target vm is restart after the migration Signed-off-by: Alexandre Derumier --- PVE/API2/Qemu.pm | 18 ++++++++++++++++++ PVE/CLI/qm.pm | 6 ++++++ PVE/QemuMigrate.pm | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 587bb22..6703c87 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -4460,6 +4460,12 @@ __PACKAGE__->register_method({ optional => 1, default => 0, }, + 'target-cpu' => { + optional => 1, + description => "Target Emulated CPU model. For online migration, the storage is live migrate, but the memory migration is skipped and the target vm is restarted.", + type => 'string', + format => 'pve-vm-cpu-conf', + }, 'target-storage' => get_standard_option('pve-targetstorage', { completion => \&PVE::QemuServer::complete_migration_storage, optional => 0, @@ -4557,11 +4563,14 @@ __PACKAGE__->register_method({ raise_param_exc({ 'target-bridge' => "failed to parse bridge map: $@" }) if $@; + my $target_cpu = extract_param($param, 'target-cpu'); + die "remote migration requires explicit storage mapping!\n" if $storagemap->{identity}; $param->{storagemap} = $storagemap; $param->{bridgemap} = $bridgemap; + $param->{targetcpu} = $target_cpu; $param->{remote} = { conn => $conn_args, # re-use fingerprint for tunnel client => $api_client, @@ -5604,6 +5613,15 @@ __PACKAGE__->register_method({ PVE::QemuServer::nbd_stop($state->{vmid}); return; }, + 'restart' => sub { + PVE::QemuServer::vm_stop(undef, $state->{vmid}, 1, 1); + 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 c3c2982..06c74c1 100755 --- a/PVE/CLI/qm.pm +++ b/PVE/CLI/qm.pm @@ -189,6 +189,12 @@ __PACKAGE__->register_method({ optional => 1, default => 0, }, + 'target-cpu' => { + optional => 1, + description => "Target Emulated CPU model. For online migration, the storage is live migrate, but the memory migration is skipped and the target vm is restarted.", + type => 'string', + format => 'pve-vm-cpu-conf', + }, '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 e182415..04f8053 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}->{targetcpu}){ + $self->log('info', "target cpu is different - skip live migration."); + return; + } + my $conf = $self->{vmconf}; $self->log('info', "starting online/live migration on $migrate_uri"); @@ -995,6 +1000,7 @@ sub phase1_remote { my $remote_conf = PVE::QemuConfig->load_config($vmid); PVE::QemuConfig->update_volume_ids($remote_conf, $self->{volume_map}); + $remote_conf->{cpu} = $self->{opts}->{targetcpu}; my $bridges = map_bridges($remote_conf, $self->{opts}->{bridgemap}); for my $target (keys $bridges->%*) { for my $nic (keys $bridges->{$target}->%*) { @@ -1354,6 +1360,21 @@ sub phase2 { live_migration($self, $vmid, $migrate_uri, $spice_port); if ($self->{storage_migration}) { + + #freeze source vm io/s if target cpu is different (no livemigration) + if ($self->{opts}->{targetcpu}) { + my $agent_running = $self->{conf}->{agent} && PVE::QemuServer::qga_check_running($vmid); + if ($agent_running) { + print "freeze filesystem\n"; + eval { mon_cmd($vmid, "guest-fsfreeze-freeze"); }; + die $@ if $@; + } else { + print "suspend vm\n"; + eval { PVE::QemuServer::vm_suspend($vmid, 1); }; + warn $@ if $@; + } + } + # 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) @@ -1608,6 +1629,10 @@ sub phase3_cleanup { # clear migrate lock if ($tunnel && $tunnel->{version} >= 2) { PVE::Tunnel::write_tunnel($tunnel, 10, "unlock"); + if ($self->{opts}->{targetcpu}) { + $self->log('info', "target cpu is different - restart target vm."); + PVE::Tunnel::write_tunnel($tunnel, 10, 'restart'); + } PVE::Tunnel::finish_tunnel($tunnel); } else { -- 2.30.2