cfg2cmd: fix +pveN machine types with pxe

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>
This commit is contained in:
Stefan Reiter 2021-03-31 16:39:23 +02:00 committed by Thomas Lamprecht
parent a0d8d8592a
commit d4be7f31b5
6 changed files with 106 additions and 3 deletions

View File

@ -2986,10 +2986,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;

View File

@ -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;

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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'