[PATCH qemu-server v4 05/17] cpu config: add helpers to lock and write config

Arthur Bied-Charreton
2026-04-30T16:03:12Z

Add lock/write primitives to allow programmatic access to
/etc/pve/virtual-guest/cpu-models.conf as a preparatory step for adding a
custom CPU models CRUD API to pve-manager.

Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
src/PVE/QemuServer/CPUConfig.pm | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index 0ee9b991..65ced94f 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -6,7 +6,7 @@ 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_lock_file cfs_write_file);
use PVE::ProcFSTools;
use PVE::RESTEnvironment qw(log_warn);
use PVE::Tools qw(run_command);
@@ -50,6 +50,17 @@ sub load_custom_model_conf {
return cfs_read_file($cpu_models_filename);
}

+sub write_custom_model_conf {
+ my ($conf) = @_;
+ cfs_write_file($cpu_models_filename, $conf);
+}
+
+sub lock_cpu_config {
+ my ($code) = @_;
+ cfs_lock_file($cpu_models_filename, undef, $code);
+ die $@ if $@;
+}
+
#builtin models : reported-model is mandatory
my $builtin_models_by_arch = {
x86_64 => {
--
2.47.3