From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id F23AB1FF13F for ; Thu, 12 Mar 2026 09:40:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 279109214; Thu, 12 Mar 2026 09:40:28 +0100 (CET) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 6/8] qemu: Add helpers for new custom models endpoints Date: Thu, 12 Mar 2026 09:40:19 +0100 Message-ID: <20260312084021.124465-7-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260312084021.124465-1-a.bied-charreton@proxmox.com> References: <20260312084021.124465-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.102 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS 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 Message-ID-Hash: AS4THYNVKRXA7IUG6KZTSLOZZLCXJG7K X-Message-ID-Hash: AS4THYNVKRXA7IUG6KZTSLOZZLCXJG7K X-MailFrom: abied-charreton@jett.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 CC: Stefan Reiter X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add functionality to lock & write the custom CPU config and some other helpers that will be needed in custom CPU models CRUD endpoints. Original patch: https://lore.proxmox.com/pve-devel/20211028114150.3245864-5-s.reiter@proxmox.com/ Originally-by: Stefan Reiter Signed-off-by: Arthur Bied-Charreton --- src/PVE/QemuServer/CPUConfig.pm | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm index 32ec4954..2b6665a7 100644 --- a/src/PVE/QemuServer/CPUConfig.pm +++ b/src/PVE/QemuServer/CPUConfig.pm @@ -6,10 +6,10 @@ use warnings; use JSON; use PVE::JSONSchema qw(json_bool); -use PVE::Cluster qw(cfs_register_file cfs_read_file); +use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file); use PVE::ProcFSTools; use PVE::RESTEnvironment qw(log_warn); -use PVE::Tools qw(run_command); +use PVE::Tools qw(run_command lock_file); use PVE::QemuServer::Helpers qw(min_version); @@ -51,6 +51,19 @@ sub load_custom_model_conf { return cfs_read_file($default_filename); } +sub write_custom_model_conf { + my ($conf) = @_; + cfs_write_file($default_filename, $conf); +} + +sub lock_cpu_config { + my ($code) = @_; + cfs_lock_file($default_filename, undef, $code); + if (my $err = $@) { + die $err; + } +} + #builtin models : reported-model is mandatory my $builtin_models_by_arch = { x86_64 => { @@ -298,6 +311,19 @@ sub get_supported_cpu_flags { return $supported_cpu_flags_by_arch->{$arch}; } +sub description_by_flag { + my ($arch) = @_; + return { map { $_->{name} => $_->{description} } get_supported_cpu_flags($arch)->@* }; +} + +sub get_cpu_vendor { + my ($cputype, $arch) = @_; + $arch = $host_arch if !defined($arch); + my $retval = $cpu_models_by_arch->{$arch}->{$cputype} + or die "Built-in CPU type '$cputype' does not exist"; + return $retval; +} + my $all_supported_cpu_flags = {}; for my $arch ($supported_cpu_flags_by_arch->%*) { for my $flag ($supported_cpu_flags_by_arch->{$arch}->@*) { @@ -375,6 +401,7 @@ my $cpu_fmt = { optional => 1, }, }; +PVE::JSONSchema::register_standard_option('pve-qemu-cpu', $cpu_fmt); my $sev_fmt = { type => { @@ -564,6 +591,7 @@ sub write_config { # saved in section header delete $model_conf->{cputype}; + $model_conf->{type} = $class->type(); } $class->SUPER::write_config($filename, $cfg); @@ -612,7 +640,8 @@ sub get_cpu_models { my $conf = load_custom_model_conf(); for my $custom_model (keys %{ $conf->{ids} }) { - my $reported_model = $conf->{ids}->{$custom_model}->{'reported-model'}; + my $model = $conf->{ids}->{$custom_model}; + my $reported_model = $model->{'reported-model'}; $reported_model //= $cpu_fmt->{'reported-model'}->{default}; my $vendor = $all_cpu_models->{$reported_model}; push @$models, -- 2.47.3