[pve-devel] [PATCH qemu-server] fix #3577: prevent vms with pci passthrough to suspend to disk

Dominik Csapak d.csapak at proxmox.com
Tue Jun 21 16:07:04 CEST 2022


while it may work to suspend, resume will most likely not work, because
we do/can not save/restore the hardware state of the devices

instead, prevent the user from suspending the vm at all.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Qemu.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 99b426e..24d0f59 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2977,10 +2977,17 @@ __PACKAGE__->register_method({
 	# early check for storage permission, for better user feedback
 	if ($todisk) {
 	    $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']);
+	    my $conf = PVE::QemuConfig->load_config($vmid);
+
+	    # check for hostpci devices (suspend will maybe work, resume won't),
+	    # so prevent users from suspending in the first place
+	    for my $key (keys %$conf) {
+		next if $key !~ /^hostpci\d+/;
+		die "Cannot suspend VM to disk with assigned PCI devices\n";
+	    }
 
 	    if (!$statestorage) {
 		# get statestorage from config if none is given
-		my $conf = PVE::QemuConfig->load_config($vmid);
 		my $storecfg = PVE::Storage::config();
 		$statestorage = PVE::QemuServer::find_vmstate_storage($conf, $storecfg);
 	    }
-- 
2.30.2






More information about the pve-devel mailing list