[pve-devel] applied: [PATCH qemu-server 2/2] fix #3352: templates: minimize config when starting templates

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Jul 1 10:54:42 CEST 2024


we could also think about using qemu-storage-daemon and skip starting of
the VM entirely.. that might be interesting for other use cases as well
(mostly storage-agnostic replication via block-mirror, I guess?)

On June 20, 2024 12:09 pm, Dominik Csapak wrote:
> templates can only be started in context of a pbs backup, and there we
> don't need or want to use most of the config, since they cannot be
> started normally anyway.
> 
> We minimize the config by copying some specific relevant options (see
> the comments for why the options were chosen) and all disk
> configurations.
> 
> Since we change the qemu commandline for templates, we now have to adapt
> the tests involving templates.
> 
> Without this, users can get into a situation where the template cannot
> be backed up when there are some resources not available (such as cpu
> cores, kvm, pci devices, etc.) even if the backup process does not need
> them.
> 
> This change has some nice side effects, such as we don't need to
> allocate the full amount of memory anymore for templates that have a
> hostpci device configured, the configured bridges don't have to exist,
> etc.
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> this replaces: "fix #5543: pci: don't use pci devices when starting templates"
> https://lists.proxmox.com/pipermail/pve-devel/2024-June/064238.html
> 
> 
>  PVE/QemuServer.pm                             | 25 +++++++++++++
>  test/cfg2cmd/efi-raw-template.conf.cmd        |  9 +++--
>  .../q35-linux-hostpci-template.conf.cmd       | 35 ++++++-------------
>  test/cfg2cmd/simple1-template.conf.cmd        | 18 ++++------
>  4 files changed, 46 insertions(+), 41 deletions(-)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 7815b608..0d998798 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -3497,6 +3497,28 @@ sub config_to_command {
>      my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu,
>          $live_restore_backing) = @_;
>  
> +    # minimize config for templates, they can only start for backup,
> +    # so most options besides the disks are irrelevant
> +    if (PVE::QemuConfig->is_template($conf)) {
> +	my $newconf = {
> +	    template => 1, # in case below code checks that
> +	    kvm => 0, # to prevent an error on hosts without virtualization extensions
> +	    vga => 'none', # to not start a vnc server
> +	    scsihw => $conf->{scsihw}, # so that the scsi disks are correctly added
> +	    bios => $conf->{bios}, # so efidisk gets included if it exists
> +	    name => $conf->{name}, # so it's correct in the process list
> +	};
> +
> +	# copy all disks over
> +	for my $device (PVE::QemuServer::Drive::valid_drive_names()) {
> +	    $newconf->{$device} = $conf->{$device};
> +	}
> +
> +	# remaining configs stay default
> +
> +	$conf = $newconf;
> +    }
> +
>      my ($globalFlags, $machineFlags, $rtcFlags) = ([], [], []);
>      my $devices = [];
>      my $bridges = {};
> @@ -6137,6 +6159,9 @@ sub get_vm_volumes {
>  sub cleanup_pci_devices {
>      my ($vmid, $conf) = @_;
>  
> +    # templates don't use pci devices
> +    return if $conf->{template};
> +
>      foreach my $key (keys %$conf) {
>  	next if $key !~ m/^hostpci(\d+)$/;
>  	my $hostpciindex = $1;
> diff --git a/test/cfg2cmd/efi-raw-template.conf.cmd b/test/cfg2cmd/efi-raw-template.conf.cmd
> index b1d4d1f6..3e90c335 100644
> --- a/test/cfg2cmd/efi-raw-template.conf.cmd
> +++ b/test/cfg2cmd/efi-raw-template.conf.cmd
> @@ -8,21 +8,20 @@
>    -mon 'chardev=qmp-event,mode=control' \
>    -pidfile /var/run/qemu-server/8006.pid \
>    -daemonize \
> -  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
>    -drive 'if=pflash,unit=0,format=raw,readonly=on,file=/usr/share/pve-edk2-firmware//OVMF_CODE.fd' \
>    -drive 'if=pflash,unit=1,id=drive-efidisk0,format=raw,file=/var/lib/vz/images/100/base-disk-100-0.raw,size=131072,readonly=on' \
>    -smp '1,sockets=1,cores=1,maxcpus=1' \
>    -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=on' \
> -  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
> +  -vga none \
> +  -nographic \
> +  -cpu qemu64 \
>    -m 512 \
>    -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \
>    -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \
>    -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
>    -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
> -  -device 'VGA,id=vga,bus=pci.0,addr=0x2' \
>    -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3,free-page-reporting=on' \
>    -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
> -  -machine 'type=pc+pve0' \
> +  -machine 'accel=tcg,type=pc+pve0' \
>    -snapshot
> diff --git a/test/cfg2cmd/q35-linux-hostpci-template.conf.cmd b/test/cfg2cmd/q35-linux-hostpci-template.conf.cmd
> index f9b9bf69..cda10630 100644
> --- a/test/cfg2cmd/q35-linux-hostpci-template.conf.cmd
> +++ b/test/cfg2cmd/q35-linux-hostpci-template.conf.cmd
> @@ -8,38 +8,23 @@
>    -mon 'chardev=qmp-event,mode=control' \
>    -pidfile /var/run/qemu-server/8006.pid \
>    -daemonize \
> -  -smbios 'type=1,uuid=3dd750ce-d910-44d0-9493-525c0be4e687' \
>    -drive 'if=pflash,unit=0,format=raw,readonly=on,file=/usr/share/pve-edk2-firmware//OVMF_CODE.fd' \
>    -drive 'if=pflash,unit=1,id=drive-efidisk0,format=qcow2,file=/var/lib/vz/images/100/base-100-disk-1.qcow2,readonly=on' \
> -  -global 'ICH9-LPC.acpi-pci-hotplug-with-bridge-support=off' \
> -  -smp '2,sockets=2,cores=1,maxcpus=2' \
> +  -smp '1,sockets=1,cores=1,maxcpus=1' \
>    -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=on' \
> -  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
> +  -vga none \
> +  -nographic \
> +  -cpu qemu64 \
>    -m 512 \
> -  -object 'memory-backend-ram,id=ram-node0,size=256M' \
> -  -numa 'node,nodeid=0,cpus=0,memdev=ram-node0' \
> -  -object 'memory-backend-ram,id=ram-node1,size=256M' \
> -  -numa 'node,nodeid=1,cpus=1,memdev=ram-node1' \
> -  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
> -  -device 'vmgenid,guid=54d1c06c-8f5b-440f-b5b2-6eab1380e13d' \
> -  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
> -  -device 'vfio-pci,host=0000:00:ff.1,id=hostpci0,bus=pci.0,addr=0x10' \
> -  -device 'vfio-pci,host=0000:d0:13.0,id=hostpci1,bus=ich9-pcie-port-2,addr=0x0' \
> -  -device 'vfio-pci,host=0000:00:f4.0,id=hostpci2,bus=pci.0,addr=0x1b' \
> -  -device 'vfio-pci,host=0000:d0:15.1,id=hostpci3,bus=ich9-pcie-port-4,addr=0x0' \
> -  -device 'pcie-root-port,id=ich9-pcie-port-5,addr=10.0,x-speed=16,x-width=32,multifunction=on,bus=pcie.0,port=5,chassis=5' \
> -  -device 'vfio-pci,host=0000:d0:17.0,id=hostpci4,bus=ich9-pcie-port-5,addr=0x0,rombar=0' \
> -  -device 'pcie-root-port,id=ich9-pcie-port-8,addr=10.3,x-speed=16,x-width=32,multifunction=on,bus=pcie.0,port=8,chassis=8' \
> -  -device 'vfio-pci,host=0000:d0:15.2,id=hostpci7,bus=ich9-pcie-port-8,addr=0x0' \
> -  -device 'VGA,id=vga,bus=pcie.0,addr=0x1' \
> +  -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \
> +  -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \
> +  -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
> +  -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
>    -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3,free-page-reporting=on' \
>    -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
>    -device 'virtio-scsi-pci,id=scsihw0,bus=pci.0,addr=0x5' \
>    -drive 'file=/var/lib/vz/images/100/base-100-disk-2.raw,if=none,id=drive-scsi0,format=raw,cache=none,aio=io_uring,detect-zeroes=on,readonly=on' \
> -  -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=2E:01:68:F9:9C:87,netdev=net0,bus=pci.0,addr=0x12,id=net0,rx_queue_size=1024,tx_queue_size=256,bootindex=300' \
> -  -machine 'type=q35+pve0' \
> +  -device 'scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0,id=scsi0' \
> +  -machine 'accel=tcg,type=pc+pve0' \
>    -snapshot
> diff --git a/test/cfg2cmd/simple1-template.conf.cmd b/test/cfg2cmd/simple1-template.conf.cmd
> index a24151f8..e514446c 100644
> --- a/test/cfg2cmd/simple1-template.conf.cmd
> +++ b/test/cfg2cmd/simple1-template.conf.cmd
> @@ -8,30 +8,26 @@
>    -mon 'chardev=qmp-event,mode=control' \
>    -pidfile /var/run/qemu-server/8006.pid \
>    -daemonize \
> -  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
> -  -smp '3,sockets=1,cores=3,maxcpus=3' \
> +  -smp '1,sockets=1,cores=1,maxcpus=1' \
>    -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=on' \
> -  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
> -  -m 768 \
> +  -vga none \
> +  -nographic \
> +  -cpu qemu64 \
> +  -m 512 \
>    -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \
>    -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \
> -  -device 'vmgenid,guid=c773c261-d800-4348-9f5d-167fadd53cf8' \
>    -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
>    -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
> -  -device 'VGA,id=vga,bus=pci.0,addr=0x2' \
>    -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/base-8006-disk-1.qcow2,if=none,id=drive-scsi0,discard=on,format=qcow2,cache=none,aio=native,detect-zeroes=unmap,readonly=on' \
> -  -device 'scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0,id=scsi0,bootindex=100' \
> +  -device 'scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0,id=scsi0' \
>    -device 'ahci,id=ahci0,multifunction=on,bus=pci.0,addr=0x7' \
>    -drive 'file=/var/lib/vz/images/8006/base-8006-disk-0.qcow2,if=none,id=drive-sata0,discard=on,format=qcow2,cache=none,aio=native,detect-zeroes=unmap' \
>    -device 'ide-hd,bus=ahci0.0,drive=drive-sata0,id=sata0' \
> -  -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:A0,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300' \
> -  -machine 'type=pc' \
> +  -machine 'accel=tcg,smm=off,type=pc' \
>    -snapshot
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




More information about the pve-devel mailing list