mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
fix(storages): a volume another compute's VM uses on shared storage is not deleted
A pool on shared storage (an NFS share, or a directory mounted from one) holds the same file at the same path on every host that mounts it. A VM's delete checks the panel's other computes before it deletes its disk files, but the pool page, its API and a VM's disk delete checked only their own host: a disk of a VM on another compute could be deleted. They now ask the other computes too, and refuse while one uses the file or cannot be reached. The other computes are asked before this host's lock is taken, and before a VM's disk is detached.
This commit is contained in:
parent
fb3b2f479e
commit
143a74b145
11 changed files with 277 additions and 196 deletions
|
|
@ -259,8 +259,17 @@ class wvmStorage(wvmConnect):
|
|||
vol = self.get_volume(name)
|
||||
return vol.XMLDesc(0)
|
||||
|
||||
def check_unused_elsewhere(self, name, elsewhere):
|
||||
"""Refuses a volume a VM of another host sharing this storage uses:
|
||||
elsewhere(paths) gives those the other hosts use
|
||||
(instances.utils.paths_used_on_other_computes). Asked before this
|
||||
host's lock, which a host that does not answer would hold meanwhile."""
|
||||
path = self.pool.storageVolLookupByName(name).path()
|
||||
if path in elsewhere([path]):
|
||||
raise util.InUse(gettext_noop("Volume %(name)s is in use on another compute that shares this storage"), name=name)
|
||||
|
||||
def del_volume(self, name):
|
||||
"""libvirt deletes any volume; one a VM still needs is refused."""
|
||||
"""libvirt deletes any volume; one a VM of this host still needs is refused."""
|
||||
vol = self.pool.storageVolLookupByName(name)
|
||||
if vol.path() in self.paths_in_use():
|
||||
raise util.InUse(gettext_noop("Volume %(name)s is in use: a VM's disk, a backing file or a snapshot's file"), name=name)
|
||||
|
|
|
|||
|
|
@ -191,6 +191,15 @@ class DeleteVolumeTestCase(unittest.TestCase):
|
|||
conn.del_volume("disk.qcow2")
|
||||
vols["disk.qcow2"].delete.assert_called_once_with(0)
|
||||
|
||||
def test_a_volume_another_compute_uses_is_refused(self):
|
||||
# shared storage: another host's VM has the same file at the same path
|
||||
conn, _vols = storage([], [volume("/pool/disk.qcow2")])
|
||||
asked = []
|
||||
conn.check_unused_elsewhere("disk.qcow2", lambda paths: asked.append(paths) or set())
|
||||
self.assertEqual(asked, [["/pool/disk.qcow2"]])
|
||||
with self.assertRaisesRegex(util.InUse, "disk.qcow2 is in use on another compute"):
|
||||
conn.check_unused_elsewhere("disk.qcow2", set)
|
||||
|
||||
|
||||
class RunningCopyTestCase(unittest.TestCase):
|
||||
"""A running guest's disk is not copied: the copy would mix instants."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue