mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
feat(instances): a guest that crashes or hangs is restarted or stopped
The VM Settings "When the guest crashes" choice (on_crash, restart for new VMs) never acted: a guest reports a crash through a panic device, and the panel gave VMs none. A guest whose kernel panicked stayed "running" until someone noticed. - new VMs get the panic device the host offers (get_panic_model: x86 ISA pvpanic, which Linux has built in and Windows gets with virtio-win; the PCI one elsewhere; ISA on x86 when libvirt does not tell), and an x86 machine without a watchdog of its own (not q35, which has the iTCO; not microvm, which has no PCI bus) an i6300esb - choosing Restart or Stop adds the panic device to a VM without one, an i6300esb when it has no watchdog (libvirt before 9.1 shows no iTCO on q35), and gives its watchdogs the matching action (reset, poweroff): a guest that arms its watchdog and hangs is met as one that crashed. A VM without these devices shows no choice made and says it cannot report a crash or a hang yet. From the next start, as before Checked live on a Vagrant host with a guest whose init exits (kernel panic): without the device it stayed "running (booted)"; after Stop it ended "shut off (crashed)", after Restart it booted again.
This commit is contained in:
parent
bdc5569cc8
commit
ede9e0bca7
14 changed files with 179 additions and 25 deletions
|
|
@ -3383,15 +3383,37 @@ class wvmInstance(wvmConnect):
|
|||
"""What the next start does when the guest crashes; libvirt's default is destroy."""
|
||||
return etree.fromstring(self._XMLDesc(PERSISTENT_XML)).findtext("on_crash") or "destroy"
|
||||
|
||||
def has_crash_devices(self):
|
||||
"""The next start has the device the guest reports a crash through
|
||||
(without it on_crash never acts) and a watchdog where its machine
|
||||
takes one: what set_on_crash adds."""
|
||||
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
|
||||
arch, machine = tree.find("os/type").get("arch"), tree.find("os/type").get("machine")
|
||||
return tree.find("devices/panic") is not None and (
|
||||
tree.find("devices/watchdog") is not None or not util.takes_watchdog(arch, machine))
|
||||
|
||||
def set_on_crash(self, action):
|
||||
"""restart or destroy (stop) the VM when the guest crashes, from the next start."""
|
||||
if action not in ("restart", "destroy"):
|
||||
"""restart or destroy (stop) the VM when the guest crashes or, once it
|
||||
arms its watchdog, hangs; from the next start. The VM gets the panic
|
||||
device a crash is reported through, and an i6300esb when it has no
|
||||
watchdog and its machine takes one (libvirt before 9.1 does not show
|
||||
q35's iTCO), when it lacks them."""
|
||||
if action not in util.WATCHDOG_ACTIONS:
|
||||
raise util.OperationError(gettext_noop("Unknown crash action %(action)s"), action=action)
|
||||
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
|
||||
on_crash = tree.find("on_crash")
|
||||
if on_crash is None:
|
||||
on_crash = etree.SubElement(tree, "on_crash")
|
||||
on_crash.text = action
|
||||
arch, machine = tree.find("os/type").get("arch"), tree.find("os/type").get("machine")
|
||||
devices = tree.find("devices")
|
||||
if devices.find("panic") is None and (model := self.get_panic_model(arch, machine)):
|
||||
etree.SubElement(devices, "panic", model=model)
|
||||
watchdogs = devices.findall("watchdog")
|
||||
if not watchdogs and util.takes_watchdog(arch, machine):
|
||||
watchdogs = [etree.SubElement(devices, "watchdog", model="i6300esb")]
|
||||
for watchdog in watchdogs:
|
||||
watchdog.set("action", util.WATCHDOG_ACTIONS[action])
|
||||
self._defineXML(etree.tostring(tree).decode())
|
||||
|
||||
def set_options(self, options):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue