1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix(instances): a VM's saved state keeps the disks it starts with

A VM with a saved state (managed save, as libvirt-guests leaves VMs when
its host shuts down) shows as shut off, and its start restores the
definition it was saved with. The panel let the VM's Delete remove a disk
of it, and the storage pool delete a volume detached since: the VM then
did not start ("Cannot access storage file"), and the panel has no way to
drop the saved state.

A VM's Delete now refuses a disk while the VM has a saved state, and a
volume in a domain's saved state is in use for every delete check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-11 12:35:27 +03:00
parent a4bfe77949
commit a53a3623d2
7 changed files with 59 additions and 2 deletions

View file

@ -1123,8 +1123,9 @@ class wvmConnect(object):
def paths_in_use(self, skip_uuid=None, own=()):
"""Paths (names for network disks) a domain uses as a disk or a
backing file of one, or as a file of its snapshots (overlays, memory,
the disks they were taken on); and the backing files of volumes.
backing file of one, in its saved state too, or as a file of its
snapshots (overlays, memory, the disks they were taken on); and the
backing files of volumes.
skip_uuid leaves out one domain, own the volumes whose backing files
do not count."""
used = set()
@ -1133,6 +1134,18 @@ class wvmConnect(object):
continue
for flags in (0, libvirt.VIR_DOMAIN_XML_INACTIVE):
used.update(self._source_paths(etree.fromstring(dom.XMLDesc(flags))))
# a saved state starts with the disks it was saved with, detached since or not
if dom.hasManagedSaveImage(0):
try:
saved = dom.managedSaveGetXMLDesc(0)
except libvirtError as err:
if err.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
continue
if err.get_error_code() != libvirt.VIR_ERR_OPERATION_INVALID:
raise
# the image went meanwhile: the VM may have started from it
saved = dom.XMLDesc(0)
used.update(self._source_paths(etree.fromstring(saved)))
for snap in dom.listAllSnapshots(0):
tree = etree.fromstring(snap.getXMLDesc(0))
used.update(tree.xpath("disks/disk/source/@file|memory/@file"))