From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 8DB9A1FF0A7 for ; Wed, 19 Aug 2026 16:47:28 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 94BD5215C2; Wed, 19 Aug 2026 16:47:03 +0200 (CEST) From: Christian Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH v2 qemu-server 2/5] helpers: optionally get package version for kvm_user_version() Date: Wed, 19 Aug 2026 16:46:39 +0200 Message-ID: <20260819144642.453513-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260819144642.453513-1-c.ebner@proxmox.com> References: <20260819144642.453513-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1787150793978 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.802 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: 2XNS343CAUTWBDZ3DDIS5AJQVYHAUHGV X-Message-ID-Hash: 2XNS343CAUTWBDZ3DDIS5AJQVYHAUHGV X-MailFrom: c.ebner@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: Allows to specify whether to return the binary version or the package version by adding a flag to kvm_user_version(). This will allow comparing the package version including it's revision when the binary version is not enough. Signed-off-by: Christian Ebner --- changes: - new in version 2 src/PVE/QemuServer/Helpers.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm index dd17eef5..658400f2 100644 --- a/src/PVE/QemuServer/Helpers.pm +++ b/src/PVE/QemuServer/Helpers.pm @@ -53,30 +53,40 @@ my $kvm_user_version = {}; my $kvm_mtime = {}; sub kvm_user_version { - my ($binary) = @_; + my ($binary, $query_package_version) = @_; $binary //= get_command_for_arch(get_host_arch()); # get the native arch by default my $st = stat($binary); my $cachedmtime = $kvm_mtime->{$binary} // -1; - return $kvm_user_version->{$binary} - if $kvm_user_version->{$binary} - && $cachedmtime == $st->mtime; + my $version_type = $query_package_version ? 'package' : 'version'; + if ($kvm_user_version->{$binary}->{$version_type} && $cachedmtime == $st->mtime) { + return $kvm_user_version->{$binary}->{$version_type}; + } - $kvm_user_version->{$binary} = 'unknown'; + $kvm_user_version->{$binary} = { + version => 'unknown', + package => 'unknown', + }; $kvm_mtime->{$binary} = $st->mtime; + my $version_regex = '(\d+\.\d+(\.\d+)?)(\.\d+)?'; my $code = sub { my $line = shift; - if ($line =~ m/^QEMU( PC)? emulator version (\d+\.\d+(\.\d+)?)(\.\d+)?[,\s]/) { - $kvm_user_version->{$binary} = $2; + if ($line =~ + m/^QEMU( PC)? emulator version $version_regex[,\s]\(pve-qemu-kvm_($version_regex-\d+)\)/ + ) { + $kvm_user_version->{$binary} = { + version => $2, + package => $5, + }; } }; eval { PVE::Tools::run_command([$binary, '--version'], outfunc => $code); }; warn $@ if $@; - return $kvm_user_version->{$binary}; + return $kvm_user_version->{$binary}->{$version_type}; } # Paths and directories -- 2.47.3