From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id AE4CB1FF066 for ; Tue, 24 Nov 2026 17:34:01 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 29CD62181D; Tue, 24 Nov 2026 17:32:46 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v2 14/20] migrate: factor out asserting the CPU compatibility of the target Date: Tue, 24 Nov 2026 17:30:38 +0100 Message-ID: <20261124163136.320992-15-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124163136.320992-1-j.theisen@proxmox.com> References: <20261124163136.320992-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795537936631 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.075 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: GLIMDBHYIZG5LVX4D2P4B6P43CCIGUED X-Message-ID-Hash: GLIMDBHYIZG5LVX4D2P4B6P43CCIGUED X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Move deciding which CPU incompatibilities of the target node prevent the migration, and which are only logged, out of the migration preparation into a helper, so that the API can check this before handing a migration over to the HA stack. No functional change intended. Signed-off-by: Jonas Theisen --- src/PVE/QemuMigrate.pm | 38 +++----------------------- src/PVE/QemuMigrate/Helpers.pm | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm index 0b286f58..5c85ec36 100644 --- a/src/PVE/QemuMigrate.pm +++ b/src/PVE/QemuMigrate.pm @@ -326,40 +326,10 @@ sub prepare { # nodes of other clusters do not broadcast their CPU information to this cluster if (!$self->{opts}->{remote}) { - my $node = $self->{node}; - my ($cpu_issues, $unchecked_nodes) = - PVE::QemuMigrate::Helpers::check_target_cpu_compatibility( - $vmid, $conf, $running, [$node], - ); - - my @errors; - for my $issue (($cpu_issues->{$node} // [])->@*) { - my $override = $issue->{override}; - if ($issue->{severity} eq 'warning') { - log_warn("CPU of node '$node' might be incompatible: $issue->{message}"); - } elsif (defined($override) && $self->{opts}->{$override}) { - log_warn("ignoring incompatible CPU of node '$node' due to '$override':" - . " $issue->{message}"); - } else { - push @errors, $issue; - } - } - if (scalar(@errors)) { - my $hint = ''; - if (!grep { !defined($_->{override}) } @errors) { - my %overrides = map { $_->{override} => 1 } @errors; - $hint = - " - use " . join(' and ', map { "'$_'" } sort keys %overrides) . " to override"; - } - die "can't migrate VM to '$node' - incompatible CPU: " - . join('; ', map { $_->{message} } @errors) - . "$hint\n"; - } - - if (scalar($unchecked_nodes->@*)) { - log_warn("unable to check CPU compatibility of node '$node' - CPU information not" - . " available"); - } + my $warnings = PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility( + $vmid, $conf, $running, $self->{node}, $self->{opts}, + ); + log_warn($_) for $warnings->@*; } my $vollist = PVE::QemuServer::get_vm_volumes($conf); diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm index 1ac0e7f9..c4995672 100644 --- a/src/PVE/QemuMigrate/Helpers.pm +++ b/src/PVE/QemuMigrate/Helpers.pm @@ -500,6 +500,56 @@ sub check_target_cpu_compatibility { return ($issues_by_node, $unchecked_nodes); } +=head3 assert_target_cpu_compatibility + + my $warnings = assert_target_cpu_compatibility($vmid, $conf, $pid, $node, $opts); + +Checks whether the running VM can run with its current virtual CPU on the node C<$node>, see +check_target_cpu_compatibility(). Dies if the node is incompatible, unless the migration options +C<$opts> override all the incompatibilities. + +Returns an array reference with the warnings to log, about possible incompatibilities, overridden +incompatibilities, and missing CPU information of the node. + +=cut + +sub assert_target_cpu_compatibility { + my ($vmid, $conf, $pid, $node, $opts) = @_; + + my ($issues_by_node, $unchecked_nodes) = + check_target_cpu_compatibility($vmid, $conf, $pid, [$node]); + + my ($errors, $warnings) = ([], []); + for my $issue (($issues_by_node->{$node} // [])->@*) { + my $override = $issue->{override}; + if ($issue->{severity} eq 'warning') { + push $warnings->@*, "CPU of node '$node' might be incompatible: $issue->{message}"; + } elsif (defined($override) && $opts->{$override}) { + push $warnings->@*, + "ignoring incompatible CPU of node '$node' due to '$override': $issue->{message}"; + } else { + push $errors->@*, $issue; + } + } + + if (scalar($errors->@*)) { + my $hint = ''; + if (!grep { !defined($_->{override}) } $errors->@*) { + my %overrides = map { $_->{override} => 1 } $errors->@*; + $hint = " - use " . join(' and ', map { "'$_'" } sort keys %overrides) . " to override"; + } + die "can't migrate VM to '$node' - incompatible CPU: " + . join('; ', map { $_->{message} } $errors->@*) + . "$hint\n"; + } + + push $warnings->@*, + "unable to check CPU compatibility of node '$node' - CPU information not available" + if scalar($unchecked_nodes->@*); + + return $warnings; +} + sub set_migration_caps { my ($vmid, $savevm) = @_; -- 2.47.3