core: disks handling cleanup, fix them for TemplateHVM

Move rootcow_img to storage class, remove clean_volatile_img. And most
importantly - set source_template in QubesHVm.create_on_disk.
This commit is contained in:
Marek Marczykowski-Górecki 2015-02-09 06:02:20 +01:00
parent 2def43517a
commit adfc4e0ac9
5 changed files with 29 additions and 23 deletions

View File

@ -45,16 +45,6 @@ class QubesTemplateVm(QubesVm):
os.path.join(system_path["qubes_templates_dir"], self.name)
attrs_config['label']['default'] = defaults["template_label"]
# New attributes
# Image for template changes
attrs_config['rootcow_img'] = {
'func': lambda x: os.path.join(self.dir_path, vm_files["rootcow_img"]) }
# Clean image for root-cow and swap (AppVM side)
# TODO: not used anymore - clean up when all references removed
attrs_config['clean_volatile_img'] = {
'func': lambda x: os.path.join(self.dir_path, vm_files["clean_volatile_img"]) }
return attrs_config
def __init__(self, **kwargs):
@ -77,6 +67,9 @@ class QubesTemplateVm(QubesVm):
def get_firewall_defaults(self):
return { "rules": list(), "allow": False, "allowDns": False, "allowIcmp": False, "allowYumProxy": True }
def rootcow_img(self):
return self.storage.rootcow_img
def clone_disk_files(self, src_vm, verbose):
if dry_run:
return
@ -86,14 +79,6 @@ class QubesTemplateVm(QubesVm):
# Create root-cow.img
self.commit_changes(verbose=verbose)
def post_rename(self, old_name):
super(QubesTemplateVm, self).post_rename(old_name)
old_dirpath = os.path.join(os.path.dirname(self.dir_path), old_name)
# TODO: clean_volatile_img not used anymore
self.clean_volatile_img = self.clean_volatile_img.replace(old_dirpath, self.dir_path)
self.rootcow_img = self.rootcow_img.replace(old_dirpath, self.dir_path)
def commit_changes (self, verbose = False):
if not vmm.offline_mode:

View File

@ -198,6 +198,9 @@ class QubesHVm(QubesVm):
if dry_run:
return
if source_template is None:
source_template = self.template
# create empty disk
self.storage.private_img_size = defaults["hvm_private_img_size"]
self.storage.root_img_size = defaults["hvm_disk_size"]

View File

@ -70,6 +70,9 @@ class QubesTemplateHVm(QubesHVm):
def is_appvm(self):
return False
def rootcow_img(self):
return self.storage.rootcow_img
@classmethod
def is_template_compatible(cls, template):
if template is None:

View File

@ -87,7 +87,6 @@ vm_files = {
'root_img': 'root.img',
'rootcow_img': 'root-cow.img',
'volatile_img': 'volatile.img',
'clean_volatile_img': 'clean-volatile.img.tar',
'private_img': 'private.img',
'kernels_subdir': 'kernels',
'firewall_conf': 'firewall.xml',

View File

@ -29,7 +29,8 @@ import sys
import re
from qubes.storage import QubesVmStorage
from qubes.qubes import QubesException
from qubes.qubes import QubesException, vm_files
class QubesXenVmStorage(QubesVmStorage):
"""
@ -44,6 +45,11 @@ class QubesXenVmStorage(QubesVmStorage):
self.volatile_dev = "xvdc"
self.modules_dev = "xvdd"
if self.vm.is_template():
self.rootcow_img = os.path.join(self.vmdir, vm_files["rootcow_img"])
else:
self.rootcow_img = None
def _format_disk_dev(self, path, script, vdev, rw=True, type="disk", domain=None):
if path is None:
return ''
@ -134,6 +140,16 @@ class QubesXenVmStorage(QubesVmStorage):
f_root = open (self.root_img, "a+b")
f_root.truncate (self.root_img_size)
f_root.close ()
if self.vm.is_template():
self.commit_template_changes()
def rename(self, old_name, new_name):
super(QubesXenVmStorage, self).rename(old_name, new_name)
old_dirpath = os.path.join(os.path.dirname(self.vmdir), old_name)
if self.rootcow_img:
self.rootcow_img = self.rootcow_img.replace(old_dirpath,
self.vmdir)
def resize_private_img(self, size):
f_private = open (self.private_img, "a+b")
@ -154,11 +170,11 @@ class QubesXenVmStorage(QubesVmStorage):
def commit_template_changes(self):
assert self.vm.is_template()
# TODO: move rootcow_img to this class; the same for vm.is_outdated()
if os.path.exists (self.vm.rootcow_img):
os.rename (self.vm.rootcow_img, self.vm.rootcow_img + '.old')
if os.path.exists (self.rootcow_img):
os.rename (self.rootcow_img, self.rootcow_img + '.old')
old_umask = os.umask(002)
f_cow = open (self.vm.rootcow_img, "w")
f_cow = open (self.rootcow_img, "w")
f_root = open (self.root_img, "r")
f_root.seek(0, os.SEEK_END)
f_cow.truncate (f_root.tell()) # make empty sparse file of the same size as root.img