Browse Source

Move most resize logic to XenPool

Bahtiar `kalkin-` Gadimov 8 years ago
parent
commit
973c83cedd
2 changed files with 14 additions and 31 deletions
  1. 6 6
      qubes/storage/xen.py
  2. 8 25
      qubes/vm/qubesvm.py

+ 6 - 6
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])

+ 8 - 25
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.')
-
-        # 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)
+        warnings.warn(
+            "resize_root_img is deprecated, use volumes[name].resize()",
+            DeprecationWarning)
 
-        if False: #self.hvm:
-            return
+        self.volumes['root'].resize(size)
 
         if not allow_start:
             raise qubes.exc.QubesException(