public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: David Riley <d.riley@proxmox.com>
To: Fiona Ebner <f.ebner@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH pve-common v3 01/12] tools: add helpers for version comparison
Date: Tue, 13 Oct 2026 10:56:50 +0200	[thread overview]
Message-ID: <a4ce41d7-3510-4ce4-b486-4f8821c84d76@proxmox.com> (raw)
In-Reply-To: <b7b0c2bd-5ba9-49c8-aee5-e4fffb67f389@proxmox.com>


On 10/8/26 12:31 PM, Fiona Ebner wrote:
> Am 24.07.26 um 4:26 PM schrieb David Riley:
>> Move 'version_cmp' and 'pvecfg_min_version' over from qemu-server, to
>> make them more accessible.
>>
>> Prepare for #7294 to enable centralized cluster wide version
>> assertions.
>>
>> Originally-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
>> Originally-by: Alexandre Derumier <aderumier@odiso.com>
>> Signed-off-by: David Riley <d.riley@proxmox.com>
>> Reviewed-by: Daniel Kral <d.kral@proxmox.com>
>>
>> Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7294
>> ---
>>   src/PVE/Tools.pm | 41 +++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 41 insertions(+)
>>
>> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
>> index 2915b61..445cb74 100644
>> --- a/src/PVE/Tools.pm
>> +++ b/src/PVE/Tools.pm
>> @@ -53,6 +53,8 @@ our @EXPORT_OK = qw(
>>       extract_sensitive_params
>>       file_copy
>>       get_host_arch
>> +    pvecfg_min_version
>> +    version_cmp
>>       CLONE_NEWNS
>>       CLONE_NEWUTS
>>       CLONE_NEWIPC
>> @@ -1628,4 +1630,43 @@ sub is_deeply {
>>       return 1;
>>   }
>>   
>> +sub pvecfg_min_version {
>> +    my ($verstr, $major, $minor, $release) = @_;
>> +
>> +    return 0 if !$verstr;
>> +
>> +    if ($verstr =~ m/^(\d+)\.(\d+)(?:[.-](\d+))?/) {
>> +        return 1 if version_cmp($1, $major, $2, $minor, $3 // 0, $release) >= 0;
>> +        return 0;
>> +    }
>> +
>> +    die "internal error: cannot check version of invalid string '$verstr'";
>> +}
> I feel like this one would be better placed in pve-cluster and not
> separated from get_node_pvecfg_version(). I require these helpers more
> centrally in one of my series [0] as well (and Lukas needs it too, which
> prompted me to reply here now), where I moved the helper to pve-cluster,
> and also added a new node_pvecfg_version_at_least() helper, since that
> one is nicer for the usage in QemuMigrate.pm.
>
> Could you check out if that also works well for your use case
> here/review the relevant patches? Then we could think about applying
> those already.
>
> [0]:
> https://lore.proxmox.com/pve-devel/20260918160841.128088-1-f.ebner@proxmox.com/

Thanks for the heads up. I'll take a look at your patches and adapt my series accordingly in
version 4.

>
>> +
>> +# gets in pairs the versions you want to compares, i.e.:
>> +# ($a-major, $b-major, $a-minor, $b-minor, $a-extra, $b-extra, ...)
>> +# returns 0 if same, -1 if $a is older than $b, +1 if $a is newer than $b
>> +sub version_cmp {
>> +    my @versions = @_;
>> +
>> +    my $size = scalar(@versions);
>> +
>> +    return 0 if $size == 0;
>> +
>> +    if ($size & 1) {
>> +        my (undef, $fn, $line) = caller(0);
>> +        die "cannot compare odd count of versions, called from $fn:$line\n";
>> +    }
>> +
>> +    for (my $i = 0; $i < $size; $i += 2) {
>> +        my ($left, $right) = splice(@versions, 0, 2);
>> +        $left //= 0;
>> +        $right //= 0;
>> +
>> +        return 1 if $left > $right;
>> +        return -1 if $left < $right;
>> +    }
>> +    return 0;
>> +}
>> +
>>   1;
>
>
>
>




  reply	other threads:[~2026-10-13  8:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 14:25 [PATCH access-control/cluster/common/manager/network/proxmox-widget-toolkit/qemu-server v3 00/12] fix #7294: pool: add SDN VNets as pool members David Riley
2026-07-24 14:25 ` [PATCH pve-common v3 01/12] tools: add helpers for version comparison David Riley
2026-10-08 10:30   ` Fiona Ebner
2026-10-13  8:56     ` David Riley [this message]
2026-07-24 14:25 ` [PATCH qemu-server v3 02/12] helpers: drop local version helpers in favor of pve-common David Riley
2026-07-24 14:25 ` [PATCH pve-cluster v3 03/12] cluster: helpers: add cluster-wide version assertion David Riley
2026-07-24 14:25 ` [PATCH pve-access-control v3 04/12] fix #7294: acl: pool: add SDN VNets as pool members David Riley
2026-07-24 14:25 ` [PATCH pve-access-control v3 05/12] fix #7294: acl: pool: add helpers to remove and migrate pool VNets David Riley
2026-07-24 14:25 ` [PATCH pve-access-control v3 06/12] readme: document SDN VNets as pool members David Riley
2026-07-24 14:25 ` [PATCH pve-network v3 07/12] sdn: register api formats for zones and vnets David Riley
2026-07-24 14:25 ` [PATCH pve-network v3 08/12] fix #7294: sdn: vnet: update pool members on vnet migration and deletion David Riley
2026-07-24 14:25 ` [PATCH pve-manager v3 09/12] ui: replace var with let to match style guide for variable declaration David Riley
2026-07-24 14:25 ` [PATCH pve-manager v3 10/12] fix #7294: api: pool: add SDN VNets as pool members David Riley
2026-07-24 14:25 ` [PATCH pve-manager v3 11/12] fix #7294: ui: " David Riley
2026-07-24 14:25 ` [PATCH proxmox-widget-toolkit v3 12/12] fix #7294: css: theme: add opacity override for pool VNet icon David Riley

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=a4ce41d7-3510-4ce4-b486-4f8821c84d76@proxmox.com \
    --to=d.riley@proxmox.com \
    --cc=f.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