1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +00:00

fix(vrtManager): a disk in an inactive pool keeps the files it may be made from

Only a running disk's definition has its backing chain; for the others the
in-use check reads it from the volumes of active pools. With such a disk's
overlay in an inactive pool (a stopped VM's, the next start's, a saved
state's or a snapshot's), its backing file counted as unused, so deleting
another VM with its disks, or the volume itself, could delete it. The check
now refuses (InUse) while a disk that is not running and not raw has its
file in an inactive pool, and says to start the pool. A snapshot delete
that is done reports no left-behind files then, rather than failing.

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 14:32:46 +03:00
parent effe2a33f0
commit b91daf0525
8 changed files with 413 additions and 338 deletions

View file

@ -176,6 +176,10 @@ request_finished.connect(_request_finished, dispatch_uid="vrtManager.connection.
# libvirt's per-host directory of the VMs' UEFI variables (NVRAM)
NVRAM_DIR = "/var/lib/libvirt/qemu/nvram"
# the files and devices of a definition's disks that may grow from others; a
# raw one does not
UNREAD_DISKS = etree.XPath("devices/disk[@device='disk'][not(driver/@type='raw')]/source/@file|"
"devices/disk[@device='disk'][not(driver/@type='raw')]/source/@dev")
class wvmConnection(object):
@ -1127,13 +1131,16 @@ class wvmConnect(object):
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()
do not count. util.InUse when a disk not running has its file in an
inactive pool: the files it is made from cannot be read."""
used, unread = set(), set()
for dom in self.wvm.listAllDomains():
if dom.UUIDString() == skip_uuid:
continue
for flags in (0, libvirt.VIR_DOMAIN_XML_INACTIVE):
used.update(self._source_paths(etree.fromstring(dom.XMLDesc(flags))))
live, config = (etree.fromstring(dom.XMLDesc(flags)) for flags in (0, libvirt.VIR_DOMAIN_XML_INACTIVE))
used.update(self._source_paths(live), self._source_paths(config))
# a running disk's definition has its backing chain; the others' volumes have it
unread.update(set(UNREAD_DISKS(config)) - (set(UNREAD_DISKS(live)) if dom.isActive() else set()))
# a saved state starts with the disks it was saved with, detached since or not
if dom.hasManagedSaveImage(0):
try:
@ -1145,16 +1152,24 @@ class wvmConnect(object):
raise
# the image went meanwhile: the VM may have started from it
saved = dom.XMLDesc(0)
used.update(self._source_paths(etree.fromstring(saved)))
saved = etree.fromstring(saved)
used.update(self._source_paths(saved))
unread.update(UNREAD_DISKS(saved))
for snap in dom.listAllSnapshots(0):
tree = etree.fromstring(snap.getXMLDesc(0))
used.update(tree.xpath("disks/disk/source/@file|memory/@file"))
for saved in tree.xpath("domain|inactiveDomain"):
used.update(self._source_paths(saved))
unread.update(UNREAD_DISKS(saved))
# A stopped domain's XML has no backing chain; the volumes have it.
# Any volume backed by a path keeps that path, even an unattached one.
for pool in self.wvm.listAllStoragePools():
if not pool.isActive():
target = util.get_xml_path(pool.XMLDesc(0), "/pool/target/path")
if target and any(path.startswith(target.rstrip("/") + "/") for path in unread):
raise util.InUse(gettext_noop(
"Pool %(pool)s is not active: the files the disks of the VMs in it are made from cannot be "
"checked; start the pool first"), pool=pool.name())
continue
with contextlib.suppress(libvirtError):
pool.refresh(0)