qemu-server/PVE
Dominik Csapak a672c578e0 mediated device pass-through: fix race condition on VM reboot
When rebooting a VM from PVE (via CLI/API), the reboot code is called
under a guest lock, which creates a reboot request, shuts down the VM
and then calls the regular cleanup code, which includes the mdev
cleanup.

In parallel, the qmeventd observes that the VM process has gone, and
starts 'qm cleanup' which is (among other tasks) also starts the VM
again if a reboot from the PVE side is pending.
The qmeventd synchronizes this through a lock on the guest, with a
default timeout of 10 seconds.

Since we currently also always wait 10 seconds for the NVIDIA driver
to clean up the mdev, this creates a race condition for the cleanup
lock. IOW., when the call to `qm cleanup` starts before we started to
sleep for 10 seconds, it will not be able to acquire its lock and not
start the vm again.

To avoid the race condition in practice, do two things:
* increase the timeout in `qm cleanup` to 60 seconds.
  Technically this still might run into a timeout, as we can configure
  up to 16 mediated devices with each delaying 10 seconds in the worst
  case, but realistically most users won't configure more than two or
  three of them, if even that.

* change the hard-coded `sleep 10` to a loop sleeping for 1 second
  each before checking the state again. This shortens the timeout when
  the NVIDIA driver did not require the full 10s to finish the
  clean-up.

Further, add a bit of logging, so one can properly see in the task log
what is happening at which point in time.

Fixes: 49c51a60 (pci: workaround nvidia driver issue on mdev cleanup)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Mira Limbeck <m.limbeck@proxmox.com>
 [ TL: change warn to print, reword commit message ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-03-08 14:15:38 +01:00
..
API2 api: clone vm: comment and style clean-up deactivation error-handling 2024-03-08 13:51:30 +01:00
CLI mediated device pass-through: fix race condition on VM reboot 2024-03-08 14:15:38 +01:00
QemuServer fix #4085: properly activate cicustom storage(s) 2024-01-31 12:28:46 +01:00
VZDump vzdump: assemble: improve error messages 2023-10-23 17:09:41 +02:00
Makefile buildsys: use $(MAKE) instead of make 2019-09-24 18:06:16 +02:00
QemuConfig.pm qemu_volume_snapshot_delete: drop (now) unused parameter 2024-01-09 10:25:11 +01:00
QemuMigrate.pm migration: secure and use source volume names for deactivation 2024-01-30 10:41:45 +01:00
QemuServer.pm mediated device pass-through: fix race condition on VM reboot 2024-03-08 14:15:38 +01:00
QMPClient.pm remove left-over mentions of to-be-dropped, outdated QMP commands 2023-06-07 19:36:45 +02:00