Skip to content

Commit

Permalink
storage: improve/fix handling extra volumes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marmarek committed Nov 4, 2016
1 parent 4323651 commit ab9d7fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 14 additions & 5 deletions qubes/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,23 @@ def __init__(self, vm):

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
Expand Down
11 changes: 8 additions & 3 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,19 @@ def __init__(self, app, xml, volume_config=None, **kwargs):
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(
Expand Down

0 comments on commit ab9d7fb

Please sign in to comment.