Prevent removal of in-use storage pool

Fixes QubesOS/qubes-issues#4454
This commit is contained in:
Marek Marczykowski-Górecki 2019-02-19 00:37:30 +01:00
parent 23bfc18535
commit 4f5687440f
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 18 additions and 0 deletions

View File

@ -1262,6 +1262,17 @@ class Qubes(qubes.PropertyHolder):
""" Remove a storage pool from config file. """
try:
pool = self.pools[name]
volumes = [(vm, volume) for vm in self.domains
for volume in vm.volumes.values()
if volume.pool is pool]
if volumes:
raise qubes.exc.QubesPoolInUseError(pool)
prop_suffixes = ['', '_kernel', '_private', '_root', '_volatile']
for suffix in prop_suffixes:
if getattr(self, 'default_pool' + suffix, None) is pool:
raise qubes.exc.QubesPoolInUseError(pool,
'Storage pool is in use: set as {}'.format(
'default_pool' + suffix))
yield from self.fire_event_async('pool-pre-delete',
pre_event=True, pool=pool)
del self.pools[name]

View File

@ -116,6 +116,13 @@ class QubesNoTemplateError(QubesVMError):
msg or 'Template for the domain {!r} not found'.format(vm.name))
class QubesPoolInUseError(QubesException):
'''VM is in use, cannot remove.'''
def __init__(self, pool, msg=None):
super(QubesPoolInUseError, self).__init__(
msg or 'Storage pool is in use: {!r}'.format(pool.name))
class QubesValueError(QubesException, ValueError):
'''Cannot set some value, because it is invalid, out of bounds, etc.'''