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
This commit is contained in:
Marek Marczykowski-Górecki 2016-11-04 12:39:29 +01:00
parent 4323651afb
commit ab9d7fbb76
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 22 additions and 8 deletions

View File

@ -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

View File

@ -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(