From 0a1f3d0a4464035347974e5b5267e0011e238fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 29 Jul 2013 03:51:39 +0200 Subject: [PATCH] core: split VM images handling to separate class This will ease handling different types of VMM (which can require different image types, location etc). --- core-modules/000QubesVm.py | 185 +++-------------------------- core-modules/003QubesTemplateVm.py | 69 +---------- core/Makefile | 2 + core/qubes.py | 5 + core/storage/Makefile | 21 ++++ core/storage/__init__.py | 182 ++++++++++++++++++++++++++++ core/storage/xen.py | 154 ++++++++++++++++++++++++ rpm_spec/core-dom0.spec | 3 + 8 files changed, 386 insertions(+), 235 deletions(-) create mode 100644 core/storage/Makefile create mode 100644 core/storage/__init__.py create mode 100644 core/storage/xen.py diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index ac5976c0..95e037a5 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -347,6 +347,12 @@ class QubesVm(object): else: assert self.root_img is not None, "Missing root_img for standalone VM!" + self.storage = defaults["storage_class"](self) + if hasattr(self, 'kernels_dir'): + self.storage.modules_img = os.path.join(self.kernels_dir, + "modules.img") + self.storage.modules_img_rw = self.kernel is None + # fire hooks for hook in self.hooks_init: hook(self) @@ -854,33 +860,17 @@ class QubesVm(object): return qubes.qubesutils.get_disk_usage(self.private_img) def get_private_img_sz(self): - if not os.path.exists(self.private_img): - return 0 - - return os.path.getsize(self.private_img) + return self.storage.get_private_img_sz() def resize_private_img(self, size): assert size >= self.get_private_img_sz(), "Cannot shrink private.img" - f_private = open (self.private_img, "a+b") - f_private.truncate (size) - f_private.close () + # resize the image + self.storage.resize_private_img(size) + # and then the filesystem retcode = 0 if self.is_running(): - # find loop device - p = subprocess.Popen (["sudo", "losetup", "--associated", self.private_img], - stdout=subprocess.PIPE) - result = p.communicate() - m = re.match(r"^(/dev/loop\d+):\s", result[0]) - if m is None: - raise QubesException("ERROR: Cannot find loop device!") - - loop_dev = m.group(1) - - # resize loop device - subprocess.check_call(["sudo", "losetup", "--set-capacity", loop_dev]) - retcode = self.run("while [ \"`blockdev --getsize64 /dev/xvdb`\" -lt {0} ]; do ".format(size) + "head /dev/xvdb > /dev/null; sleep 0.2; done; resize2fs /dev/xvdb", user="root", wait=True) if retcode != 0: @@ -983,23 +973,6 @@ class QubesVm(object): for hook in self.hooks_create_xenstore_entries: hook(self, xid=xid) - def _format_disk_dev(self, path, script, vdev, rw=True, type="disk", domain=None): - template = " \n" \ - " \n" \ - " \n" \ - " \n" \ - "{params}" \ - " \n" - params = "" - if not rw: - params += " \n" - if domain: - params += " \n" % domain - if script: - params += "