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 @property
def config(self): def config(self):
''' return config data for serialization to qubes.xml ''' ''' return config data for serialization to qubes.xml '''
result = {'name': self.name, 'pool': str(self.pool), 'vid': self.vid, } result = {
'name': self.name,
if self.internal: 'pool': str(self.pool),
result['internal'] = self.internal 'vid': self.vid,
'internal': self.internal,
if self.removable: 'removable': self.removable,
result['removable'] = self.removable 'revisions_to_keep': self.revisions_to_keep,
'rw': self.rw,
if self.revisions_to_keep: 'save_on_stop': self.save_on_stop,
result['revisions_to_keep'] = self.revisions_to_keep 'snap_on_start': self.snap_on_start,
}
if self.rw:
result['rw'] = self.rw
if self.save_on_stop:
result['save_on_stop'] = self.save_on_stop
if self.size: if self.size:
result['size'] = self.size result['size'] = self.size
if self.snap_on_start:
result['snap_on_start'] = self.snap_on_start
if self.source: if self.source:
result['source'] = str(self.source) result['source'] = str(self.source)

View File

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

View File

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

View File

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

View File

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

View File

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