[pve-devel] [PATCH qemu-server] cfg2cmd: fix +pveN machine types with pxe

Stefan Reiter s.reiter at proxmox.com
Wed Mar 31 16:39:23 CEST 2021


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 at berneking.net>
Signed-off-by: Stefan Reiter <s.reiter at 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






More information about the pve-devel mailing list