From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id B77FB1FF0A7 for ; Wed, 19 Aug 2026 18:37:32 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1A61721540; Wed, 19 Aug 2026 18:37:29 +0200 (CEST) Message-ID: <498588bf-64fb-4fff-a6e2-20b1c08d5cfa@proxmox.com> Date: Wed, 19 Aug 2026 18:37:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 qemu-server 2/5] helpers: optionally get package version for kvm_user_version() To: Christian Ebner , pve-devel@lists.proxmox.com References: <20260819144642.453513-1-c.ebner@proxmox.com> <20260819144642.453513-3-c.ebner@proxmox.com> Content-Language: en-US From: Fiona Ebner In-Reply-To: <20260819144642.453513-3-c.ebner@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1787157419824 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.858 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: HCX42YQMFMKJ43NUFXGQUSGKSUUOGAMC X-Message-ID-Hash: HCX42YQMFMKJ43NUFXGQUSGKSUUOGAMC X-MailFrom: f.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: 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 > --- > 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