all lists on 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 1/2] machine: add extract_version_parts helper
Date: Mon, 11 Aug 2025 12:47:12 +0200	[thread overview]
Message-ID: <20250811104812.189393-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250811104812.189393-1-f.ebner@proxmox.com>

Note that the regex is changed to not include the '+pve' part. No
functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/QemuServer/Machine.pm | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/PVE/QemuServer/Machine.pm b/src/PVE/QemuServer/Machine.pm
index b2bac932..3d98ee0b 100644
--- a/src/PVE/QemuServer/Machine.pm
+++ b/src/PVE/QemuServer/Machine.pm
@@ -156,19 +156,37 @@ sub get_current_qemu_machine {
     return current_from_query_machines($res);
 }
 
+=head3 extract_version_parts
+
+    my ($major, $minor, $pve) = extract_version_parts($machine_type);
+
+Returns the major, minor and pve versions from the given C<$machine_type> string. Returns nothing if
+the string did not contain any version or if parsing failed.
+
+=cut
+
+my sub extract_version_parts {
+    my ($machine_type) = @_;
+
+    if ($machine_type =~
+        m/^(?:pc(?:-i440fx|-q35)?|virt)-(\d+)\.(\d+)(?:\.(\d+))?(?:\+pve(\d+))?(?:\.pxe)?/
+    ) {
+        return ($1, $2, $4);
+    }
+    return;
+}
+
 # returns a string with major.minor+pve<VERSION>, patch version-part is ignored
 # as it's seldom resembling a real QEMU machine type, so it would be '0' 99% of
 # the time anyway.. This explicitly separates pveversion from the machine.
 sub extract_version {
     my ($machine_type, $kvmversion) = @_;
 
-    if (
-        defined($machine_type)
-        && $machine_type =~
-        m/^(?:pc(?:-i440fx|-q35)?|virt)-(\d+)\.(\d+)(?:\.(\d+))?(\+pve\d+)?(?:\.pxe)?/
-    ) {
-        my $versionstr = "$1.$2";
-        $versionstr .= $4 if $4;
+    my ($major, $minor, $pve);
+    ($major, $minor, $pve) = extract_version_parts($machine_type) if defined($machine_type);
+    if (defined($major) && defined($minor)) {
+        my $versionstr = "${major}.${minor}";
+        $versionstr .= "+pve${pve}" if $pve;
         return $versionstr;
     } elsif (defined($kvmversion)) {
         if ($kvmversion =~ m/^(\d+)\.(\d+)/) {
-- 
2.47.2



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


  reply	other threads:[~2025-08-11 10:47 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] fix #6648: api: machine versions: fix ordering Fiona Ebner
2025-08-11 10:47 ` Fiona Ebner [this message]
2025-08-11 10:47 ` [pve-devel] [PATCH qemu-server 2/2] " Fiona Ebner
2025-08-11 13:03 ` [pve-devel] applied-series: [PATCH-SERIES qemu-server 0/2] " 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-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal