storage: make volume snap_on_start/save_on_stop explicit

Always define those properties, always include them in volume config.
Also simplify overriding pool based on volume type defined by those:
override pool unless snap_on_start=True.

QubesOS/qubes-issues#2256
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-01 20:47:08 +02:00
parent 697eb05c20
commit 820539e909
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
6 changed files with 32 additions and 27 deletions

View File

@ -262,29 +262,21 @@ class Volume(object):
@property
def config(self):
''' return config data for serialization to qubes.xml '''
result = {'name': self.name, 'pool': str(self.pool), 'vid': self.vid, }
if self.internal:
result['internal'] = self.internal
if self.removable:
result['removable'] = self.removable
if self.revisions_to_keep:
result['revisions_to_keep'] = self.revisions_to_keep
if self.rw:
result['rw'] = self.rw
if self.save_on_stop:
result['save_on_stop'] = self.save_on_stop
result = {
'name': self.name,
'pool': str(self.pool),
'vid': self.vid,
'internal': self.internal,
'removable': self.removable,
'revisions_to_keep': self.revisions_to_keep,
'rw': self.rw,
'save_on_stop': self.save_on_stop,
'snap_on_start': self.snap_on_start,
}
if self.size:
result['size'] = self.size
if self.snap_on_start:
result['snap_on_start'] = self.snap_on_start
if self.source:
result['source'] = str(self.source)

View File

@ -63,6 +63,8 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
'volatile': {
'name': 'volatile',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': False,
'size': defaults['root_img_size'],
'internal': True,
'rw': True,
@ -70,6 +72,8 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,
'internal': True
}

View File

@ -61,6 +61,8 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
'name': 'volatile',
'pool': 'default',
'internal': True,
'snap_on_start': False,
'save_on_stop': False,
'rw': True,
'size': qubes.config.defaults['root_img_size'] +
qubes.config.defaults['private_img_size'],
@ -68,6 +70,8 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,
'internal': True
}

View File

@ -1824,20 +1824,17 @@ def _clean_volume_config(config):
def _patch_pool_config(config, pool=None, pools=None):
assert pool is not None or pools is not None
is_saveable = 'save_on_stop' in config and config['save_on_stop']
is_resetable = not ('snap_on_start' in config and # volatile
config['snap_on_start'] and not is_saveable)
is_exportable = is_saveable or is_resetable
is_snapshot = config['snap_on_start']
is_rw = config['rw']
name = config['name']
if pool and is_exportable and config['pool'] == 'default':
if pool and not is_snapshot and is_rw:
config['pool'] = str(pool)
elif pool and not is_exportable:
elif pool:
pass
elif pools and name in pools.keys():
if is_exportable:
if not is_snapshot:
config['pool'] = str(pools[name])
else:
msg = "Can't clone a snapshot volume {!s} to pool {!s} " \

View File

@ -51,6 +51,8 @@ class StandaloneVM(qubes.vm.qubesvm.QubesVM):
'volatile': {
'name': 'volatile',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': False,
'internal': True,
'rw': True,
'size': qubes.config.defaults['root_img_size'],
@ -58,6 +60,8 @@ class StandaloneVM(qubes.vm.qubesvm.QubesVM):
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,
'internal': True
}

View File

@ -88,12 +88,16 @@ class TemplateVM(QubesVM):
'name': 'volatile',
'pool': 'default',
'size': defaults['root_img_size'],
'snap_on_start': False,
'save_on_stop': False,
'internal': True,
'rw': True,
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'internal': True,
'rw': False
}