From 35cb82cd2b03dab7fb5bdd83c65342dfa5a38a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 6 Jan 2016 03:43:32 +0100 Subject: [PATCH] storage: use root-cow.img for HVM template, to support reverting changes We still can't support running HVM template and its VMs simultaneously (easily), but still, have root-cow.img handled for HVM template, to allow qvm-revert-template-changes. Fixes QubesOS/qubes-issues#1573 --- core-modules/01QubesHVm.py | 2 -- core-modules/02QubesTemplateHVm.py | 14 +++++++++++--- core/storage/xen.py | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core-modules/01QubesHVm.py b/core-modules/01QubesHVm.py index deb2deb8..2a6e9f04 100644 --- a/core-modules/01QubesHVm.py +++ b/core-modules/01QubesHVm.py @@ -100,8 +100,6 @@ class QubesHVm(QubesResizableVm): (not 'xml_element' in kwargs or kwargs['xml_element'].get('guiagent_installed') is None): self.services['meminfo-writer'] = False - self.storage.rootcow_img = None - @property def type(self): return "HVM" diff --git a/core-modules/02QubesTemplateHVm.py b/core-modules/02QubesTemplateHVm.py index d1d6e459..6452a8eb 100644 --- a/core-modules/02QubesTemplateHVm.py +++ b/core-modules/02QubesTemplateHVm.py @@ -29,7 +29,7 @@ import stat import sys import re -from qubes.qubes import QubesHVm,register_qubes_vm_class,dry_run +from qubes.qubes import QubesHVm,register_qubes_vm_class,dry_run,vmm from qubes.qubes import QubesException,QubesVmCollection from qubes.qubes import system_path,defaults @@ -96,7 +96,15 @@ class QubesTemplateHVm(QubesHVm): def commit_changes (self, verbose = False): self.log.debug('commit_changes()') - # nothing to do as long as root-cow.img is unused - pass + if not vmm.offline_mode: + assert not self.is_running(), "Attempt to commit changes on running Template VM!" + + if verbose: + print >> sys.stderr, "--> Commiting template updates... COW: {0}...".format (self.rootcow_img) + + if dry_run: + return + + self.storage.commit_template_changes() register_qubes_vm_class(QubesTemplateHVm) diff --git a/core/storage/xen.py b/core/storage/xen.py index d2e1ebde..3edf0f22 100644 --- a/core/storage/xen.py +++ b/core/storage/xen.py @@ -70,9 +70,12 @@ class XenStorage(QubesVmStorage): "{root}:{rootcow}".format( root=self.root_img, rootcow=self.rootcow_img), "block-origin", self.root_dev, True) - elif self.vm.template and not self.vm.template.storage.rootcow_img: - # HVM template-based VM - template doesn't have own - # root-cow.img, only one device-mapper layer + elif self.vm.template and not hasattr(self.vm, 'kernel'): + # HVM template-based VM - only one device-mapper layer, in dom0 ( + # root+volatile) + # HVM detection based on 'kernel' property is massive hack, + # but taken from assumption that VM needs Qubes-specific kernel ( + # actually initramfs) to assemble the second layer of device-mapper return self.format_disk_dev( "{root}:{volatile}".format( root=self.vm.template.storage.root_img,