From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.reiter@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 4F2106D202
 for <pve-devel@lists.proxmox.com>; Wed, 31 Mar 2021 16:40:03 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 46D3C117DA
 for <pve-devel@lists.proxmox.com>; Wed, 31 Mar 2021 16:39:33 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 1A508117D2
 for <pve-devel@lists.proxmox.com>; Wed, 31 Mar 2021 16:39:32 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D72E842F7C;
 Wed, 31 Mar 2021 16:39:31 +0200 (CEST)
From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 31 Mar 2021 16:39:23 +0200
Message-Id: <20210331143923.29006-1-s.reiter@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.017 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 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
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm, machine.pm, 8006.pid, proxmox.com]
Subject: [pve-devel] [PATCH qemu-server] cfg2cmd: fix +pveN machine types
 with pxe
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 31 Mar 2021 14:40:03 -0000

Pinned machine versions like "pc-i440fx-4.2+pve2.pxe" would otherwise
get a second "+pve0" suffix, which is incorrect.

Also deal with non-pve pinned versions correctly, i.e.
"pc-i440fx-5.2.pxe" becomes "pc-i440fx-5.2+pve0.pxe".

Handle .pxe suffixes in Machine.pm as well, and add two test cases.

Co-developed-by: Luca Berneking <luca@berneking.net>
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---

@Luca: First off, thanks for the contribution! I wanted to take a closer look at
your patch and ended up with this diff - I thought I'd just send it out and add
you as Co-dev, I hope that's fine with you. If you give this patch a shot, let
me know if it does indeed fix your issue correctly as well - "Tested-by:" is
always appreciated!

Also, if you haven't already done so, to submit patches you need to send us a
signed contributor license agreement, see our developer documentation for more:
https://pve.proxmox.com/wiki/Developer_Documentation#Software_License_and_Copyright
- since this one doesn't actually include the changes you posted verbatim, I've
signed off on it myself, so it shouldn't be required, but for the future :)

 PVE/QemuServer.pm                            |  7 ++++-
 PVE/QemuServer/Machine.pm                    |  6 ++--
 test/cfg2cmd/pinned-version-pxe-pve.conf     | 17 ++++++++++
 test/cfg2cmd/pinned-version-pxe-pve.conf.cmd | 33 ++++++++++++++++++++
 test/cfg2cmd/pinned-version-pxe.conf         | 15 +++++++++
 test/cfg2cmd/pinned-version-pxe.conf.cmd     | 31 ++++++++++++++++++
 6 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 test/cfg2cmd/pinned-version-pxe-pve.conf
 create mode 100644 test/cfg2cmd/pinned-version-pxe-pve.conf.cmd
 create mode 100644 test/cfg2cmd/pinned-version-pxe.conf
 create mode 100644 test/cfg2cmd/pinned-version-pxe.conf.cmd

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 8c483e6..333d455 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2942,10 +2942,15 @@ sub get_vm_machine {
 	}
     }
 
-    if ($add_pve_version && $machine !~ m/\+pve\d+$/) {
+    if ($add_pve_version && $machine !~ m/\+pve\d+?(?:\.pxe)?$/) {
+	my $is_pxe = $machine =~ m/^(.*?)\.pxe$/;
+	$machine = $1 if $is_pxe;
+
 	# for version-pinned machines that do not include a pve-version (e.g.
 	# pc-q35-4.1), we assume 0 to keep them stable in case we bump
 	$machine .= '+pve0';
+
+	$machine .= '.pxe' if $is_pxe;
     }
 
     return $machine;
diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
index 0d17891..d9429ed 100644
--- a/PVE/QemuServer/Machine.pm
+++ b/PVE/QemuServer/Machine.pm
@@ -49,7 +49,9 @@ sub get_current_qemu_machine {
 sub extract_version {
     my ($machine_type, $kvmversion) = @_;
 
-    if (defined($machine_type) && $machine_type =~ m/^(?:pc(?:-i440fx|-q35)?|virt)-(\d+)\.(\d+)(?:\.(\d+))?(\+pve\d+)?/) {
+    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;
 	return $versionstr;
@@ -83,7 +85,7 @@ sub get_pve_version {
 sub can_run_pve_machine_version {
     my ($machine_version, $kvmversion) = @_;
 
-    $machine_version =~ m/^(\d+)\.(\d+)(?:\+pve(\d+))?$/;
+    $machine_version =~ m/^(\d+)\.(\d+)(?:\+pve(\d+))?(?:\.pxe)?$/;
     my $major = $1;
     my $minor = $2;
     my $pvever = $3;
diff --git a/test/cfg2cmd/pinned-version-pxe-pve.conf b/test/cfg2cmd/pinned-version-pxe-pve.conf
new file mode 100644
index 0000000..36169d7
--- /dev/null
+++ b/test/cfg2cmd/pinned-version-pxe-pve.conf
@@ -0,0 +1,17 @@
+# TEST: for a basic configuration with a .pxe machine and +pve pinned
+bootdisk: scsi0
+cores: 3
+ide2: none,media=cdrom
+machine: pc-q35-4.1+pve2.pxe
+memory: 1024
+name: pinned
+net0: virtio=A2:C0:43:77:08:A1,bridge=vmbr0
+numa: 0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.raw,discard=on,size=104858K
+scsihw: virtio-scsi-pci
+smbios1: uuid=c7fdd046-fefc-11e9-832e-770e1d5636a0
+sockets: 1
+vmgenid: bdd46b98-fefc-11e9-97b4-d72c378e0f96
+# add rng0 to stress +pve2 version requirement
+rng0: source=/dev/urandom
diff --git a/test/cfg2cmd/pinned-version-pxe-pve.conf.cmd b/test/cfg2cmd/pinned-version-pxe-pve.conf.cmd
new file mode 100644
index 0000000..28b8b23
--- /dev/null
+++ b/test/cfg2cmd/pinned-version-pxe-pve.conf.cmd
@@ -0,0 +1,33 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name pinned \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server,nowait' \
+  -mon 'chardev=qmp,mode=control' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect=5' \
+  -mon 'chardev=qmp-event,mode=control' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=c7fdd046-fefc-11e9-832e-770e1d5636a0' \
+  -smp '3,sockets=1,cores=3,maxcpus=3' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc unix:/var/run/qemu-server/8006.vnc,password \
+  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
+  -m 1024 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=bdd46b98-fefc-11e9-97b4-d72c378e0f96' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1' \
+  -object 'rng-random,filename=/dev/urandom,id=rng0' \
+  -device 'virtio-rng-pci,rng=rng0,max-bytes=1024,period=1000,bus=pci.1,addr=0x1d' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -drive 'if=none,id=drive-ide2,media=cdrom,aio=threads' \
+  -device 'ide-cd,bus=ide.1,unit=0,drive=drive-ide2,id=ide2,bootindex=200' \
+  -device 'virtio-scsi-pci,id=scsihw0,bus=pci.0,addr=0x5' \
+  -drive 'file=/var/lib/vz/images/8006/vm-8006-disk-0.raw,if=none,id=drive-scsi0,discard=on,format=raw,cache=none,aio=native,detect-zeroes=unmap' \
+  -device 'scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0,id=scsi0,bootindex=100' \
+  -netdev 'type=tap,id=net0,ifname=tap8006i0,script=/var/lib/qemu-server/pve-bridge,downscript=/var/lib/qemu-server/pve-bridgedown,vhost=on' \
+  -device 'virtio-net-pci,mac=A2:C0:43:77:08:A1,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300,romfile=pxe-virtio.rom' \
+  -machine 'type=pc-q35-4.1+pve2'
diff --git a/test/cfg2cmd/pinned-version-pxe.conf b/test/cfg2cmd/pinned-version-pxe.conf
new file mode 100644
index 0000000..738868f
--- /dev/null
+++ b/test/cfg2cmd/pinned-version-pxe.conf
@@ -0,0 +1,15 @@
+# TEST: for a basic configuration with a .pxe machine
+bootdisk: scsi0
+cores: 3
+ide2: none,media=cdrom
+machine: pc-q35-5.1.pxe
+memory: 1024
+name: pinned
+net0: virtio=A2:C0:43:77:08:A1,bridge=vmbr0
+numa: 0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.raw,discard=on,size=104858K
+scsihw: virtio-scsi-pci
+smbios1: uuid=c7fdd046-fefc-11e9-832e-770e1d5636a0
+sockets: 1
+vmgenid: bdd46b98-fefc-11e9-97b4-d72c378e0f96
diff --git a/test/cfg2cmd/pinned-version-pxe.conf.cmd b/test/cfg2cmd/pinned-version-pxe.conf.cmd
new file mode 100644
index 0000000..ceb5473
--- /dev/null
+++ b/test/cfg2cmd/pinned-version-pxe.conf.cmd
@@ -0,0 +1,31 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name pinned \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server,nowait' \
+  -mon 'chardev=qmp,mode=control' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect=5' \
+  -mon 'chardev=qmp-event,mode=control' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=c7fdd046-fefc-11e9-832e-770e1d5636a0' \
+  -smp '3,sockets=1,cores=3,maxcpus=3' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc unix:/var/run/qemu-server/8006.vnc,password \
+  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
+  -m 1024 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=bdd46b98-fefc-11e9-97b4-d72c378e0f96' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -drive 'if=none,id=drive-ide2,media=cdrom,aio=threads' \
+  -device 'ide-cd,bus=ide.1,unit=0,drive=drive-ide2,id=ide2,bootindex=200' \
+  -device 'virtio-scsi-pci,id=scsihw0,bus=pci.0,addr=0x5' \
+  -drive 'file=/var/lib/vz/images/8006/vm-8006-disk-0.raw,if=none,id=drive-scsi0,discard=on,format=raw,cache=none,aio=native,detect-zeroes=unmap' \
+  -device 'scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0,id=scsi0,bootindex=100' \
+  -netdev 'type=tap,id=net0,ifname=tap8006i0,script=/var/lib/qemu-server/pve-bridge,downscript=/var/lib/qemu-server/pve-bridgedown,vhost=on' \
+  -device 'virtio-net-pci,mac=A2:C0:43:77:08:A1,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300,romfile=pxe-virtio.rom' \
+  -machine 'type=pc-q35-5.1+pve0'
-- 
2.20.1