From f2f89c7b0c8d31d33bab54763fb55f6169825423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 12 Jul 2017 10:43:48 +0200 Subject: [PATCH] storage: do not use deepcopy on volume configs There may be Pool or Volume object references, which is intentional to keep them as is - not copy whole Pool/Volume objects. --- qubes/storage/__init__.py | 1 + qubes/vm/appvm.py | 4 ++-- qubes/vm/dispvm.py | 4 +--- qubes/vm/qubesvm.py | 4 +--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 63ce351b..b15e9c0e 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -349,6 +349,7 @@ class Storage(object): if hasattr(vm, 'volume_config'): for name, conf in self.vm.volume_config.items(): + conf = conf.copy() if 'source' in conf: template = getattr(vm, 'template', None) if template: diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index 8d22e5db..e8d63e40 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -93,7 +93,7 @@ class AppVM(qubes.vm.qubesvm.QubesVM): # in case the template vm has more volumes add them to own # config if name not in self.volume_config: - self.volume_config[name] = copy.deepcopy(config) + self.volume_config[name] = config.copy() if 'vid' in self.volume_config[name]: del self.volume_config[name]['vid'] @@ -123,7 +123,7 @@ class AppVM(qubes.vm.qubesvm.QubesVM): for volume_name, conf in self.default_volume_config.items(): if conf.get('snap_on_start', False) and \ conf.get('source', None) is None: - config = copy.deepcopy(conf) + config = conf.copy() template_volume = newvalue.volumes[volume_name] self.volume_config[volume_name] = \ self.config_volume_from_source( diff --git a/qubes/vm/dispvm.py b/qubes/vm/dispvm.py index 97d67d49..c9d129e2 100644 --- a/qubes/vm/dispvm.py +++ b/qubes/vm/dispvm.py @@ -21,8 +21,6 @@ ''' A disposable vm implementation ''' -import copy - import qubes.vm.qubesvm import qubes.vm.appvm import qubes.config @@ -89,7 +87,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM): # in case the template vm has more volumes add them to own # config if name not in self.volume_config: - self.volume_config[name] = copy.deepcopy(config) + self.volume_config[name] = config.copy() if 'vid' in self.volume_config[name]: del self.volume_config[name]['vid'] diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 5699d554..797dd442 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -24,7 +24,6 @@ from __future__ import absolute_import import asyncio -import copy import base64 import datetime import os @@ -1799,8 +1798,7 @@ def _clean_volume_config(config): common_attributes = ['name', 'pool', 'size', 'revisions_to_keep', 'rw', 'snap_on_start', 'save_on_stop', 'source'] - config_copy = copy.deepcopy(config) - return {k: v for k, v in config_copy.items() if k in common_attributes} + return {k: v for k, v in config.items() if k in common_attributes} def _patch_pool_config(config, pool=None, pools=None):