From c1bab3d0944aa8d42596962d28bd5109ec9a0dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 10 Feb 2016 17:02:36 +0100 Subject: [PATCH] storage: reset_volatile_storage doesn't need source_template parameter It shouldn't touch anything not already known to the VM object. --- qubes/storage/__init__.py | 16 ++++++++-------- qubes/storage/xen.py | 27 ++++++++++++--------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index dc0b0b2d..5fa98721 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -219,7 +219,7 @@ class Storage(object): os.mkdir(self.vm.dir_path) self.create_on_disk_private_img(source_template) self.create_on_disk_root_img(source_template) - self.reset_volatile_storage(source_template) + self.reset_volatile_storage() os.umask(old_umask) @@ -285,14 +285,14 @@ class Storage(object): shutil.rmtree(self.vm.dir_path) - def reset_volatile_storage(self, source_template=None): - if source_template is None: - source_template = self.vm.template - + def reset_volatile_storage(self): # Re-create only for template based VMs - if source_template is not None and self.volatile_img: - if os.path.exists(self.volatile_img): - os.remove(self.volatile_img) + try: + if self.vm.template is not None and self.volatile_img: + if os.path.exists(self.volatile_img): + os.remove(self.volatile_img) + except AttributeError: # self.vm.template + pass # For StandaloneVM create it only if not already exists # (eg after backup-restore) diff --git a/qubes/storage/xen.py b/qubes/storage/xen.py index 8bb6697f..703e643f 100644 --- a/qubes/storage/xen.py +++ b/qubes/storage/xen.py @@ -226,23 +226,19 @@ class XenStorage(qubes.storage.Storage): os.umask(old_umask) - def reset_volatile_storage(self, source_template=None): - if source_template is None: - source_template = self.vm.template + def reset_volatile_storage(self): + try: + # no template set, in any way (Standalone VM, Template VM) + if self.vm.template is None: + raise AttributeError - if source_template is not None: - # template-based VM with only one device-mapper layer - + # template-based HVM with only one device-mapper layer - # volatile.img used as upper layer on root.img, no root-cow.img # intermediate layer - - # XXX marmarek says this is either always true or always false; - # rootcow_img got smashed in 35cb82 (#1573) - # this may have remain after HVM check - # this probably should have happen anyway - if not source_template.storage.rootcow_img: + if self.vm.hvm: if os.path.exists(self.volatile_img): if self.vm.debug: - if os.path.getmtime(source_template.storage.root_img) \ + if os.path.getmtime(self.vm.template.storage.root_img) \ > os.path.getmtime(self.volatile_img): self.vm.log.warning( 'Template have changed, resetting root.img') @@ -258,16 +254,17 @@ class XenStorage(qubes.storage.Storage): # FIXME stat on f_root; with open() ... f_volatile = open(self.volatile_img, "w") - f_root = open(source_template.storage.root_img, "r") + f_root = open(self.vm.template.storage.root_img, "r") # make empty sparse file of the same size as root.img f_root.seek(0, os.SEEK_END) f_volatile.truncate(f_root.tell()) f_volatile.close() f_root.close() return # XXX why is that? super() does not run + except AttributeError: # self.vm.template + pass - super(XenStorage, self).reset_volatile_storage( - source_template=source_template) + super(XenStorage, self).reset_volatile_storage() def prepare_for_vm_startup(self):