From ab9d7fbb76ef2d12637af385560138a1eebf3f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 4 Nov 2016 12:39:29 +0100 Subject: [PATCH] storage: improve/fix handling extra volumes Just calling pool.init_volume isn't enough - a lot of code depends on additional data loaded into vm.storage object. Provide a convenient wrapper for this. At the same time, fix loading extra volumes from qubes.xml - don't fail on volume not mentioned in initial vm.volume_config. QubesOS/qubes-issues#2256 --- qubes/storage/__init__.py | 19 ++++++++++++++----- qubes/vm/qubesvm.py | 11 ++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 5f0d64bd..db06a232 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -194,14 +194,23 @@ class Storage(object): if hasattr(vm, 'volume_config'): for name, conf in self.vm.volume_config.items(): - assert 'pool' in conf, "Pool missing in volume_config" % str( - conf) if 'volume_type' in conf: conf = self._migrate_config(conf) - pool = self.vm.app.get_pool(conf['pool']) - self.vm.volumes[name] = pool.init_volume(self.vm, conf) - self.pools[name] = pool + self.init_volume(name, conf) + + def init_volume(self, name, volume_config): + ''' Initialize Volume instance attached to this domain ''' + assert 'pool' in volume_config, "Pool missing in volume_config" % str( + volume_config) + + if 'name' not in volume_config: + volume_config['name'] = name + pool = self.vm.app.get_pool(volume_config['pool']) + volume = pool.init_volume(self.vm, volume_config) + self.vm.volumes[name] = volume + self.pools[name] = pool + return volume def _migrate_config(self, conf): ''' Migrates from the old config style to new diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 20061bf3..66845f56 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -427,14 +427,19 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): for key, value in node.items(): # pylint: disable=no-member if value == 'True': - self.volume_config[name][key] = True - else: + value = True + try: self.volume_config[name][key] = value + except KeyError: + self.volume_config[name] = {key: value} for name, conf in volume_config.items(): for key, value in conf.items(): # pylint: disable=no-member - self.volume_config[name][key] = value + try: + self.volume_config[name][key] = value + except KeyError: + self.volume_config[name] = {key: value} elif volume_config: raise TypeError(