From 820539e909a4162bf5493aa2138b0c54f4fae2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 1 Jul 2017 20:47:08 +0200 Subject: [PATCH] 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 --- qubes/storage/__init__.py | 30 +++++++++++------------------- qubes/vm/appvm.py | 4 ++++ qubes/vm/dispvm.py | 4 ++++ qubes/vm/qubesvm.py | 13 +++++-------- qubes/vm/standalonevm.py | 4 ++++ qubes/vm/templatevm.py | 4 ++++ 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 5cd647bee..26598f852 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -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) diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index 74ddc28e1..b818c9955 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -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 } diff --git a/qubes/vm/dispvm.py b/qubes/vm/dispvm.py index ff8e39d5c..8586627bf 100644 --- a/qubes/vm/dispvm.py +++ b/qubes/vm/dispvm.py @@ -61,6 +61,8 @@ 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'], @@ -68,6 +70,8 @@ def __init__(self, *args, **kwargs): 'kernel': { 'name': 'kernel', 'pool': 'linux-kernel', + 'snap_on_start': False, + 'save_on_stop': False, 'rw': False, 'internal': True } diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index a96288dd9..2c0ea4412 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -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} " \ diff --git a/qubes/vm/standalonevm.py b/qubes/vm/standalonevm.py index ef3b59d16..7aab434d8 100644 --- a/qubes/vm/standalonevm.py +++ b/qubes/vm/standalonevm.py @@ -51,6 +51,8 @@ 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'], @@ -58,6 +60,8 @@ def __init__(self, *args, **kwargs): 'kernel': { 'name': 'kernel', 'pool': 'linux-kernel', + 'snap_on_start': False, + 'save_on_stop': False, 'rw': False, 'internal': True } diff --git a/qubes/vm/templatevm.py b/qubes/vm/templatevm.py index 7be3e0a20..8cd075280 100644 --- a/qubes/vm/templatevm.py +++ b/qubes/vm/templatevm.py @@ -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 }