Skip to content

Commit

Permalink
storage: make volume snap_on_start/save_on_stop explicit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marmarek committed Jul 4, 2017
1 parent 697eb05 commit 820539e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
30 changes: 11 additions & 19 deletions qubes/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,21 @@ def size(self, size):
@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)

Expand Down
4 changes: 4 additions & 0 deletions qubes/vm/appvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ 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,
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,
'internal': True
}
Expand Down
4 changes: 4 additions & 0 deletions qubes/vm/dispvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ def __init__(self, *args, **kwargs):
'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'],
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,
'internal': True
}
Expand Down
13 changes: 5 additions & 8 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} " \
Expand Down
4 changes: 4 additions & 0 deletions qubes/vm/standalonevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ def __init__(self, *args, **kwargs):
'volatile': {
'name': 'volatile',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': False,
'internal': True,
'rw': True,
'size': qubes.config.defaults['root_img_size'],
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,
'internal': True
}
Expand Down
4 changes: 4 additions & 0 deletions qubes/vm/templatevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ def __init__(self, *args, **kwargs):
'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
}
Expand Down

0 comments on commit 820539e

Please sign in to comment.