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 7D0851FF0B2 for ; Thu, 20 Aug 2026 11:06:46 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4B6992166B; Thu, 20 Aug 2026 11:05:58 +0200 (CEST) From: Christian Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH v3 qemu-server 3/6] helpers: optionally get package version for kvm_user_version() Date: Thu, 20 Aug 2026 11:05:25 +0200 Message-ID: <20260820090528.117853-4-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260820090528.117853-1-c.ebner@proxmox.com> References: <20260820090528.117853-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: 1787216718465 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.768 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: CQBJ52EX7FI2RNHHT2LMEDOIQ6PEQ2II X-Message-ID-Hash: CQBJ52EX7FI2RNHHT2LMEDOIQ6PEQ2II 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. Regex matching is performed on both, the package version being kept as optional for full backwards compatibility in the binary version check case. Signed-off-by: Christian Ebner --- changes since version 2: - precompile regex via qr - adapt binary version regex variable name - add dedicated regex for package version, dropping subversion and therefore only matching major.minor.micro-rel - keep package version regex matching optional for full backwards compat in binary version check case src/PVE/QemuServer/Helpers.pm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm index ebb1a874..8047d9e6 100644 --- a/src/PVE/QemuServer/Helpers.pm +++ b/src/PVE/QemuServer/Helpers.pm @@ -53,29 +53,42 @@ 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 defined($kvm_user_version->{$binary}) - && $cachedmtime == $st->mtime; + my $version_type = $query_package_version ? 'package' : 'version'; + if (defined($kvm_user_version->{$binary}->{$version_type}) && $cachedmtime == $st->mtime) { + return $kvm_user_version->{$binary}->{$version_type}; + } $kvm_mtime->{$binary} = $st->mtime; + my $binary_version_re = qr/(\d+\.\d+(\.\d+)?)(\.\d+)?/; + my $package_version_re = qr/\(pve-qemu-kvm_(\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 $binary_version_re[,\s]($package_version_re)?/ + ) { + $kvm_user_version->{$binary} = { + version => $2, + package => $6, + }; } }; eval { PVE::Tools::run_command([$binary, '--version'], outfunc => $code); }; warn $@ if $@; - return defined($kvm_user_version->{$binary}) ? $kvm_user_version->{$binary} : 'unknown'; + if (defined($kvm_user_version->{$binary}->{$version_type})) { + return $kvm_user_version->{$binary}->{$version_type}; + } + + return 'unknown'; } # Paths and directories -- 2.47.3