public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20260820090528.117853-4-c.ebner@proxmox.com> (raw)
In-Reply-To: <20260820090528.117853-1-c.ebner@proxmox.com>

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 <c.ebner@proxmox.com>
---
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





  parent reply	other threads:[~2026-08-20  9:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20  9:05 [PATCH v3 pve-qemu qemu-server 0/6] bypass host page cache for restore on zvol Christian Ebner
2026-08-20  9:05 ` [PATCH v3 pve-qemu 1/1] pbs-restore: add optional no-cache flag to bypass host page cache Christian Ebner
2026-08-20  9:05 ` [PATCH v3 qemu-server 2/6] helpers: never cache `unknown` on failed kvm binary version check Christian Ebner
2026-08-20  9:05 ` Christian Ebner [this message]
2026-08-20  9:05 ` [PATCH v3 qemu-server 4/6] helpers: add helper for min kvm package version comparison Christian Ebner
2026-08-20  9:05 ` [PATCH v3 qemu-server 5/6] pbs-restore: set 'no-cache' on block devices backed by zfspool Christian Ebner
2026-08-20  9:05 ` [PATCH v3 qemu-server 6/6] vma restore: skip page cache " Christian Ebner
2026-08-20  9:56 ` [PATCH v3 pve-qemu qemu-server 0/6] bypass host page cache for restore on zvol Lukas Sichert
2026-08-20 12:07   ` Thomas Lamprecht
2026-08-20 12:36     ` Christian Ebner
2026-08-20 11:36 ` Lukas Sichert
2026-08-20 13:12 ` Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260820090528.117853-4-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal