From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id AA05A1FF187 for ; Mon, 11 Aug 2025 12:46:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0117133649; Mon, 11 Aug 2025 12:48:19 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Mon, 11 Aug 2025 12:47:13 +0200 Message-ID: <20250811104812.189393-3-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250811104812.189393-1-f.ebner@proxmox.com> References: <20250811104812.189393-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754909267022 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.026 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_MAILER 2 Automated Mailer Tag Left in Email RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server 2/2] fix #6648: api: machine versions: fix ordering X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" It's necessary to numerically compare versions in machine types, so introduce a new helper which does that. Signed-off-by: Fiona Ebner --- 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