1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(storages): a share or LVM pool a VM's disk path is in is not deleted

Deleting a pool was refused only while a VM's definition named the pool
for a disk; a disk given by its file path was taken not to need it. That
holds for a directory pool, but a share's or a file system's pool mounts
the path and an LVM pool activates it: with the pool deleted, the path is
gone at the next boot and the VM no longer starts (seen live with an NFS
pool). Such a disk now refuses the delete too: a path under the pool's
mount point, or an LVM volume by its /dev/<group> or /dev/mapper name.
iSCSI and disk pools share their device directories with other pools and
are left as they were.

A pool libvirt reports as inaccessible (state 4: running, its storage out
of reach) made the pool page fail with an IndexError; it now shows an
Inaccessible badge.
This commit is contained in:
catborise 2026-11-13 10:27:50 +03:00
parent 044945bd97
commit fb3b2f479e
7 changed files with 86 additions and 24 deletions

View file

@ -168,10 +168,11 @@ class wvmStorage(wvmConnect):
"Initializing pool, not available",
"Running normally",
"Running degraded",
"Inaccessible", # running, but its storage cannot be reached: a share whose server is gone
]
try:
return status[self.pool.info()[0]]
except ValueError:
except IndexError: # a state newer than these
return "Unknown"
def get_size(self):
@ -215,10 +216,22 @@ class wvmStorage(wvmConnect):
def delete(self):
"""Refused while a VM's definition names it for a disk: that VM would
no longer start. A disk given by its file path does not need it."""
name = self.pool.name()
if vms := self.domains_using(lambda domain: domain.xpath("devices/disk/source[@pool=$name]", name=name)):
raise util.OperationError(gettext_noop("VMs %(vms)s have disks in pool %(name)s by its name and would no longer start; detach those disks first"), vms=', '.join(vms), name=name)
no longer start. So is a disk given by its path in a pool that mounts
or activates its storage (a share, a file system, an LVM group): the
path is gone with the pool. A directory pool's files stay; the device
directories of iSCSI and disk pools are every pool's, not this one's."""
name, kind = self.pool.name(), self.get_type()
target = (self.get_target_path() or "").rstrip("/")
under = (target + "/",) if kind in ("fs", "netfs", "logical") and target else ()
if kind == "logical" and (group := self.get_source_name()):
under += ("/dev/mapper/" + group.replace("-", "--") + "-",) # device mapper's name of its volumes
def needs(domain):
return domain.xpath("devices/disk/source[@pool=$name]", name=name) or any(
path.startswith(under) for path in domain.xpath("devices/disk//source/@file | devices/disk//source/@dev"))
if vms := self.domains_using(needs):
raise util.OperationError(gettext_noop("VMs %(vms)s have disks in pool %(name)s and would no longer start; detach those disks first"), vms=', '.join(vms), name=name)
self.pool.undefine()
def get_autostart(self):