From 47e89d84b6f78ae30ff1d10302662d9434f0c443 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Sun, 27 Mar 2016 22:30:33 +0200 Subject: [PATCH] XenStorage.format_disk_dev returns now BlockDevice --- qubes/storage/__init__.py | 16 +++++++-------- qubes/storage/xen.py | 41 ++++++++++----------------------------- 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 4ddbe34b..bcbdb0d9 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -101,8 +101,7 @@ class Storage(object): def other_dev_config(self): if self.modules_img is not None: - return self.format_disk_dev(self.modules_img, self.modules_dev, - rw=self.modules_img_rw) + return BlockDevice(self.modules_img, 'kernel', rw=False) elif self.drive is not None: (drive_type, drive_domain, drive_path) = self.drive.split(":") if drive_type == 'hd': @@ -114,19 +113,18 @@ class Storage(object): drive_domain = None return self.format_disk_dev(drive_path, - self.modules_dev, - rw=rw, - devtype=drive_type, - domain=drive_domain) + 'other', + rw=rw, + devtype=drive_type, + domain=drive_domain) else: return '' - def format_disk_dev(self, path, vdev, script=None, rw=True, devtype='disk', - domain=None): + def format_disk_dev(self, path, name, script=None, rw=True, devtype='disk', + domain=None): raise NotImplementedError() - @property def kernels_dir(self): '''Directory where kernel resides. diff --git a/qubes/storage/xen.py b/qubes/storage/xen.py index 57c0ff66..097bc705 100644 --- a/qubes/storage/xen.py +++ b/qubes/storage/xen.py @@ -31,12 +31,11 @@ import os.path import re import subprocess -import lxml.etree - import qubes import qubes.config import qubes.storage import qubes.vm.templatevm +from qubes.devices import BlockDevice class XenStorage(qubes.storage.Storage): @@ -92,39 +91,19 @@ class XenStorage(qubes.storage.Storage): '''Path to the volatile image''' return self.abspath(qubes.config.vm_files['volatile_img']) + def format_disk_dev(self, path, name, script=None, rw=True, devtype='disk', + domain=None): - def format_disk_dev(self, path, vdev, script=None, rw=True, devtype='disk', - domain=None): - if path is None: - return '' - - element = lxml.etree.Element('disk') - element.set('type', 'block') - element.set('device', devtype) - - element.append(lxml.etree.Element('driver', name='phy')) - element.append(lxml.etree.Element('source', dev=path)) - element.append(lxml.etree.Element('target', dev=vdev)) - - if not rw: - element.append(lxml.etree.Element('readonly')) - if domain is not None: - # XXX vm.name? - element.append(lxml.etree.Element('domain', name=domain)) - if script: - element.append(lxml.etree.Element('script', path=script)) - - # TODO return element - return lxml.etree.tostring(element) - + return BlockDevice(path, name, script, rw, domain, devtype) def root_dev_config(self): + dev_name = 'root' if isinstance(self.vm, qubes.vm.templatevm.TemplateVM): return self.format_disk_dev( '{root}:{rootcow}'.format( root=self.root_img, rootcow=self.rootcow_img), - self.root_dev, + dev_name, script='block-origin') elif self.vm.hvm and hasattr(self.vm, 'template'): @@ -137,7 +116,7 @@ class XenStorage(qubes.storage.Storage): '{root}:{volatile}'.format( root=self.vm.template.storage.root_img, volatile=self.volatile_img), - self.root_dev, + dev_name, script='block-snapshot') elif hasattr(self.vm, 'template'): @@ -154,14 +133,14 @@ class XenStorage(qubes.storage.Storage): else: # standalone qube - return self.format_disk_dev(self.root_img, self.root_dev) + return self.format_disk_dev(self.root_img, dev_name) def private_dev_config(self): - return self.format_disk_dev(self.private_img, self.private_dev) + return self.format_disk_dev(self.private_img, 'private') def volatile_dev_config(self): - return self.format_disk_dev(self.volatile_img, self.volatile_dev) + return self.format_disk_dev(self.volatile_img, 'volatile') def create_on_disk_private_img(self, source_template=None):