From 973c83cedd402a6260c74d191449680e3a8a75da Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Tue, 5 Apr 2016 20:04:20 +0200 Subject: [PATCH] Move most resize logic to XenPool --- qubes/storage/xen.py | 12 ++++++------ qubes/vm/qubesvm.py | 33 ++++++++------------------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/qubes/storage/xen.py b/qubes/storage/xen.py index a50cd23f..ada83f50 100644 --- a/qubes/storage/xen.py +++ b/qubes/storage/xen.py @@ -85,16 +85,16 @@ class XenPool(Pool): elif _type in ['read-write', 'volatile']: path = volume.path - if size <= volume.size: - raise StoragePoolException('Can not shring volume %s' % - volume.name) - with open(path, 'a+b') as fd: fd.truncate(size) + self._resize_loop_device(path) + + def _resize_loop_device(self, path): # find loop device if any - p = subprocess.Popen(['sudo', 'losetup', '--associated', path], - stdout=subprocess.PIPE) + p = subprocess.Popen( + ['sudo', 'losetup', '--associated', path], + stdout=subprocess.PIPE) result = p.communicate() m = re.match(r'^(/dev/loop\d+):\s', result[0]) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 91be2f7d..974e7ed8 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1064,11 +1064,11 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): def resize_private_img(self, size): '''Resize private image.''' - if size >= self.get_private_img_sz(): - raise qubes.exc.QubesValueError('Cannot shrink private.img') + warnings.warn( + "resize_private_img is deprecated, use volumes[name].resize()", + DeprecationWarning) - # resize the image - self.storage.resize_private_img(size) + self.volumes['private'].resize(size) # and then the filesystem # FIXME move this to qubes.storage.xen.XenVMStorage @@ -1084,29 +1084,12 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): if retcode != 0: raise qubes.exc.QubesException('resize2fs failed') - - # TODO move to storage def resize_root_img(self, size, allow_start=False): - if hasattr(self, 'template'): - raise qubes.exc.QubesVMError(self, - 'Cannot resize root.img of template based qube. Resize the' - ' root.img of the template instead.') + warnings.warn( + "resize_root_img is deprecated, use volumes[name].resize()", + DeprecationWarning) - # TODO self.is_halted - if self.is_running(): - raise qubes.exc.QubesVMNotHaltedError(self, - 'Cannot resize root.img of a running qube') - - if size < self.get_root_img_sz(): - raise qubes.exc.QubesValueError( - 'For your own safety, shrinking of root.img is disabled. If you' - ' really know what you are doing, use `truncate` manually.') - - with open(self.root_img, 'a+b') as fd: - fd.truncate(size) - - if False: #self.hvm: - return + self.volumes['root'].resize(size) if not allow_start: raise qubes.exc.QubesException(