diff --git a/qubes/app.py b/qubes/app.py index ea87a4ed..10884651 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -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] diff --git a/qubes/exc.py b/qubes/exc.py index cac2437c..49ef6f6f 100644 --- a/qubes/exc.py +++ b/qubes/exc.py @@ -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.'''