mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 03:36:48 +00:00
fix(storages): keep volumes a VM still needs
libvirt deletes any volume it is asked to. The storage page and the API deleted a VM's disk, the base image of another volume or the file a snapshot was taken on without a check, breaking the VM or its snapshots. wvmStorage.del_volume now refuses a volume a domain on the compute uses as a disk or a backing file of one, a file of a domain's snapshots, or the backing file of another volume. The check is the one destroy already used, moved to wvmConnect and extended to snapshot files, so destroy also keeps the files of another VM's snapshots. The storage page shows the refusal; the API answers 400 with it, as for other refusals. Deleting a disk from a VM refuses after the detach when the VM's own snapshots need the volume, and says the volume was kept. Network disks count by their source name, pool volume disks by their volume's path. A volume whose metadata cannot be read stops the check instead of counting as unused; only one removed meanwhile is skipped. The check and the delete hold the compute lock, so no VM operation attaches the volume in between; a busy compute is a message on the page and 409 in the API.
This commit is contained in:
parent
08cad04468
commit
c970f8e853
11 changed files with 345 additions and 30 deletions
|
|
@ -1480,29 +1480,9 @@ class wvmInstance(wvmConnect):
|
|||
return iso
|
||||
|
||||
def paths_used_by_other_domains(self, own=()):
|
||||
"""Paths another domain uses as a disk or as a backing file of one.
|
||||
The volumes in own are this VM's: their backing files do not count."""
|
||||
uuid = self.instance.UUIDString()
|
||||
used = set()
|
||||
for dom in self.wvm.listAllDomains():
|
||||
if dom.UUIDString() == uuid:
|
||||
continue
|
||||
for flags in (0, VIR_DOMAIN_XML_INACTIVE):
|
||||
tree = etree.fromstring(dom.XMLDesc(flags))
|
||||
# "//" also reaches backingStore chains in a running domain's XML
|
||||
used.update(tree.xpath("./devices/disk//source/@file|./devices/disk//source/@dev"))
|
||||
# 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():
|
||||
continue
|
||||
with contextlib.suppress(libvirtError):
|
||||
pool.refresh(0)
|
||||
for vol in pool.listAllVolumes():
|
||||
with contextlib.suppress(libvirtError):
|
||||
if vol.path() not in own:
|
||||
used.update(etree.fromstring(vol.XMLDesc(0)).xpath("./backingStore/path/text()"))
|
||||
return used
|
||||
"""Paths another domain uses (see paths_in_use). The volumes in own
|
||||
are this VM's: their backing files do not count."""
|
||||
return self.paths_in_use(self.instance.UUIDString(), own)
|
||||
|
||||
def split_disk_paths_by_use(self):
|
||||
"""This VM's disk paths, split into (only this VM, also used by another
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue