public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 2/2] fix #6648: api: machine versions: fix ordering
Date: Mon, 11 Aug 2025 12:47:13 +0200	[thread overview]
Message-ID: <20250811104812.189393-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250811104812.189393-1-f.ebner@proxmox.com>

It's necessary to numerically compare versions in machine types, so
introduce a new helper which does that.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/API2/Qemu/Machine.pm  |  6 +++++-
 src/PVE/QemuServer/Machine.pm | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/Qemu/Machine.pm b/src/PVE/API2/Qemu/Machine.pm
index 41281af2..0fc1ea6c 100644
--- a/src/PVE/API2/Qemu/Machine.pm
+++ b/src/PVE/API2/Qemu/Machine.pm
@@ -81,7 +81,11 @@ __PACKAGE__->register_method({
                 }
             }
 
-            return [sort { $b->{id} cmp $a->{id} } ($machines->@*, $pve_machines->@*)]; # merge & sort
+            return [
+                sort {
+                    PVE::QemuServer::Machine::machine_version_cmp($b->{id}, $a->{id})
+                } ($machines->@*, $pve_machines->@*)
+            ]; # merge & sort
         };
         die "could not load supported machine versions - $@\n" if $@;
         return $supported_machine_list;
diff --git a/src/PVE/QemuServer/Machine.pm b/src/PVE/QemuServer/Machine.pm
index 3d98ee0b..9d17344a 100644
--- a/src/PVE/QemuServer/Machine.pm
+++ b/src/PVE/QemuServer/Machine.pm
@@ -198,6 +198,30 @@ sub extract_version {
     return;
 }
 
+=head3 machine_version_cmp
+
+    sort { machine_version_cmp($a, $b) } @machine_types
+
+Comparision function for sorting machine types by version.
+
+=cut
+
+sub machine_version_cmp {
+    my ($machine_type_a, $machine_type_b) = @_;
+
+    my ($major_a, $minor_a, $pve_a) = extract_version_parts($machine_type_a);
+    my ($major_b, $minor_b, $pve_b) = extract_version_parts($machine_type_b);
+
+    return PVE::QemuServer::Helpers::version_cmp(
+        $major_a,
+        $major_b,
+        $minor_a,
+        $minor_b,
+        $pve_a,
+        $pve_b,
+    );
+}
+
 sub is_machine_version_at_least {
     my ($machine_type, $major, $minor, $pve) = @_;
 
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-08-11 10:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 10:47 [pve-devel] [PATCH-SERIES qemu-server 0/2] " Fiona Ebner
2025-08-11 10:47 ` [pve-devel] [PATCH qemu-server 1/2] machine: add extract_version_parts helper Fiona Ebner
2025-08-11 10:47 ` Fiona Ebner [this message]
2025-08-11 13:03 ` [pve-devel] applied-series: [PATCH-SERIES qemu-server 0/2] fix #6648: api: machine versions: fix ordering Fabian Grünbichler

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=20250811104812.189393-3-f.ebner@proxmox.com \
    --to=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