From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3A97E1FF15C for ; Fri, 31 Oct 2025 13:28:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 316BD10B2D; Fri, 31 Oct 2025 13:29:14 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Fri, 31 Oct 2025 13:27:37 +0100 Message-ID: <20251031122834.62482-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251031122834.62482-1-f.ebner@proxmox.com> References: <20251031122834.62482-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1761913704154 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.020 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 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server 1/7] cpu config: style fix: avoid multiline post-if expressions 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Should improve readability. No functional change intended. Signed-off-by: Fiona Ebner --- src/PVE/QemuServer/CPUConfig.pm | 98 +++++++++++++++++---------------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm index 786a99d8..1fdae415 100644 --- a/src/PVE/QemuServer/CPUConfig.pm +++ b/src/PVE/QemuServer/CPUConfig.pm @@ -326,19 +326,19 @@ sub validate_vm_cpu_conf { if (is_custom_model($cputype)) { # dies on unknown model get_custom_model($cputype); - } else { - die "Built-in cputype '$cputype' is not defined (missing 'custom-' prefix?)\n" - if !defined($cpu_vendor_list->{$cputype}) && !defined($builtin_models->{$cputype}); + } elsif (!defined($cpu_vendor_list->{$cputype}) && !defined($builtin_models->{$cputype})) { + die "Built-in cputype '$cputype' is not defined (missing 'custom-' prefix?)\n"; } # in a VM-specific config, certain properties are limited/forbidden - die "VM-specific CPU flags must be a subset of: @{[join(', ', @supported_cpu_flags)]}\n" - if ($cpu->{flags} - && $cpu->{flags} !~ m/^$cpu_flag_supported_re(;$cpu_flag_supported_re)*$/); + if ($cpu->{flags} && $cpu->{flags} !~ m/^$cpu_flag_supported_re(;$cpu_flag_supported_re)*$/) { + die "VM-specific CPU flags must be a subset of: @{[join(', ', @supported_cpu_flags)]}\n"; + } - die "Property 'reported-model' not allowed in VM-specific CPU config.\n" - if defined($cpu->{'reported-model'}); + if (defined($cpu->{'reported-model'})) { + die "Property 'reported-model' not allowed in VM-specific CPU config.\n"; + } return $cpu; } @@ -387,13 +387,15 @@ sub write_config { for my $model (keys %{ $cfg->{ids} }) { my $model_conf = $cfg->{ids}->{$model}; - die - "internal error: tried saving built-in CPU model (or missing prefix): $model_conf->{cputype}\n" - if !is_custom_model($model_conf->{cputype}); + if (!is_custom_model($model_conf->{cputype})) { + die "internal error: tried saving built-in CPU model (or missing prefix):" + . " $model_conf->{cputype}\n"; + } - die - "internal error: tried saving custom cpumodel with cputype (ignoring prefix: $model_conf->{cputype}) not equal to \$cfg->ids entry ($model)\n" - if "custom-$model" ne $model_conf->{cputype}; + if ("custom-$model" ne $model_conf->{cputype}) { + die "internal error: tried saving custom cpumodel with cputype (ignoring prefix:" + . " $model_conf->{cputype}) not equal to \$cfg->ids entry ($model)\n"; + } # saved in section header delete $model_conf->{cputype}; @@ -654,23 +656,23 @@ sub get_cpu_options { my $vm_flags = parse_cpuflag_list($cpu_flag_supported_re, "manually set for VM", $cpu->{flags}); my $pve_forced_flags = {}; - $pve_forced_flags->{'enforce'} = { - reason => "error if requested CPU settings not available", - } - if $cputype ne 'host' && $kvm && $arch eq 'x86_64'; - $pve_forced_flags->{'kvm'} = { - value => "off", - reason => "hide KVM virtualization from guest", - } - if $kvm_off; + if ($cputype ne 'host' && $kvm && $arch eq 'x86_64') { + $pve_forced_flags->{'enforce'} = { + reason => "error if requested CPU settings not available", + }; + } + if ($kvm_off) { + $pve_forced_flags->{'kvm'} = { + value => "off", + reason => "hide KVM virtualization from guest", + }; + } # $cputype is the "reported-model" for custom types, so we can just look up # the vendor in the default list my $cpu_vendor = $cpu_vendor_list->{$cputype}; if ($cpu_vendor) { - $pve_forced_flags->{'vendor'} = { - value => $cpu_vendor, - } if $cpu_vendor ne 'default'; + $pve_forced_flags->{'vendor'} = { value => $cpu_vendor } if $cpu_vendor ne 'default'; } elsif ($arch ne 'aarch64') { die "internal error"; # should not happen } @@ -714,29 +716,33 @@ sub get_pve_cpu_flags { my $pve_flags = {}; my $pve_msg = "set by PVE;"; - $pve_flags->{'lahf_lm'} = { - op => '+', - reason => "$pve_msg to support Windows 8.1+", - } - if $cputype eq 'kvm64' && $arch eq 'x86_64'; + if ($cputype eq 'kvm64' && $arch eq 'x86_64') { + $pve_flags->{'lahf_lm'} = { + op => '+', + reason => "$pve_msg to support Windows 8.1+", + }; + } - $pve_flags->{'x2apic'} = { - op => '-', - reason => "$pve_msg incompatible with Solaris", - } - if $conf->{ostype} && $conf->{ostype} eq 'solaris'; + if ($conf->{ostype} && $conf->{ostype} eq 'solaris') { + $pve_flags->{'x2apic'} = { + op => '-', + reason => "$pve_msg incompatible with Solaris", + }; + } - $pve_flags->{'sep'} = { - op => '+', - reason => "$pve_msg to support Windows 8+ and improve Windows XP+", - } - if $cputype eq 'kvm64' || $cputype eq 'kvm32'; + if ($cputype eq 'kvm64' || $cputype eq 'kvm32') { + $pve_flags->{'sep'} = { + op => '+', + reason => "$pve_msg to support Windows 8+ and improve Windows XP+", + }; + } - $pve_flags->{'rdtscp'} = { - op => '-', - reason => "$pve_msg broken on AMD Opteron", - } - if $cputype =~ m/^Opteron/; + if ($cputype =~ m/^Opteron/) { + $pve_flags->{'rdtscp'} = { + op => '-', + reason => "$pve_msg broken on AMD Opteron", + }; + } if (min_version($machine_version, 2, 3) && $kvm && $arch eq 'x86_64') { $pve_flags->{'kvm_pv_unhalt'} = { -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel