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

Fiona Ebner
2026-05-07T12:06:51Z

Am 30.04.26 um 6:01 PM schrieb Arthur Bied-Charreton:
> 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 {

I'd prefer lock_custom_model_conf() to be in-line with the others. Or
even go for *_custom_cpu_model_config(). AFAICT load_custom_model_conf()
is not yet used outside of qemu-server before your series, so can also
be adapted rather easily.

> + 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 => {