1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

fix(instances): a VM starts only with host devices the host can give now

A device is checked when it is given to a VM, but a start later did not
check it again: a PCI device bound back to a host driver for the host's
own network or disks, or a USB device the host no longer has as named,
was taken from the host or failed in libvirt. Power On and Power Cycle now
check the definition the VM starts from (its saved state's when restored)
as a snapshot revert does, and refuse with the reasons; Power Cycle checks
before it stops the VM.
This commit is contained in:
catborise 2026-11-11 16:16:55 +03:00
parent 4045819b8d
commit a36ffcd3ba
4 changed files with 59 additions and 1 deletions

View file

@ -72,7 +72,7 @@ from lxml import etree
from vrtManager import util
from vrtManager.connection import NVRAM_DIR, wvmConnect
from vrtManager.nodedevs import pci_address, usb_selector
from vrtManager.nodedevs import check_hostdevs, pci_address, usb_selector
from vrtManager.storage import wvmStorage, wvmStorages
logger = logging.getLogger(__name__)
@ -652,6 +652,17 @@ class wvmInstance(wvmConnect):
def start(self, flags=0):
self.instance.createWithFlags(flags)
def check_start_hostdevs(self, restore=True):
"""Refuses a start whose host devices the host cannot give now
(check_hostdevs): a device given while free may since be another
VM's or the host's, and libvirt takes a managed one from its host
driver as the VM starts. The definition checked is the one the VM
starts from: its saved state's when restored."""
dom = self.instance
restore = restore and dom.hasManagedSaveImage(0)
xml = dom.managedSaveGetXMLDesc(0) if restore else dom.XMLDesc(VIR_DOMAIN_XML_INACTIVE)
check_hostdevs(self, dom.name(), [etree.fromstring(xml)], restore)
def shutdown(self):
self.instance.shutdown()