From: Fiona Ebner <f.ebner@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH v2 qemu-server 2/5] helpers: optionally get package version for kvm_user_version()
Date: Wed, 19 Aug 2026 18:37:23 +0200 [thread overview]
Message-ID: <498588bf-64fb-4fff-a6e2-20b1c08d5cfa@proxmox.com> (raw)
In-Reply-To: <20260819144642.453513-3-c.ebner@proxmox.com>
Am 19.08.26 um 4:47 PM schrieb Christian Ebner:
> 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 <c.ebner@proxmox.com>
> ---
> 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) {
Pre-existing, but a definedness check would be slightly nicer. I'd also
only check for $kvm_user_version->{$binary} if making the package match
optional (see my comment below).
> + return $kvm_user_version->{$binary}->{$version_type};
> + }
>
> - $kvm_user_version->{$binary} = 'unknown';
> + $kvm_user_version->{$binary} = {
> + version => 'unknown',
> + package => 'unknown',
> + };
Pre-existing, but like this the values will be initialized even if the
version command later fails for some reason and then they will stay
'unknown'. I'd rather re-attempt the query instead.
> $kvm_mtime->{$binary} = $st->mtime;
>
> + my $version_regex = '(\d+\.\d+(\.\d+)?)(\.\d+)?';
Nit: could compile the regex with qr already
Nit: $version_re is a bit shorter which helps in a longer regex.
Nit: could also add a second $package_re
For the package I wouldn't even match the last number, because that
cannot be defined: in debian/rules we use
--with-pkgversion="${DEB_SOURCE}_${DEB_VERSION_UPSTREAM_REVISION}
and we only use major.minor.micro-rel
> 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+)\)/
I would make the latter half of the regex an optional match, just
because we didn't require it before.
> + ) {
> + $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
next prev parent reply other threads:[~2026-08-19 16:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 14:46 [PATCH v2 qemu-server 0/5] bypass host page cache for restore on zvol Christian Ebner
2026-08-19 14:46 ` [PATCH v2 pve-qemu 1/5] add optional no-cache flag to bypass host page cache on pbs-restore Christian Ebner
2026-08-19 16:44 ` Fiona Ebner
2026-08-19 14:46 ` [PATCH v2 qemu-server 2/5] helpers: optionally get package version for kvm_user_version() Christian Ebner
2026-08-19 16:37 ` Fiona Ebner [this message]
2026-08-19 14:46 ` [PATCH v2 qemu-server 3/5] helpers: add helper for min package version comparison Christian Ebner
2026-08-19 16:37 ` Fiona Ebner
2026-08-19 14:46 ` [PATCH v2 qemu-server 4/5] pbs-restore: set 'no-cache' on block devices backed by zfspool Christian Ebner
2026-08-19 14:46 ` [PATCH v2 qemu-server 5/5] vma restore: skip page cache " Christian Ebner
2026-08-19 16:44 ` [PATCH v2 qemu-server 0/5] bypass host page cache for restore on zvol Jonas Theisen
2026-08-20 9:06 ` 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=498588bf-64fb-4fff-a6e2-20b1c08d5cfa@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=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