Move most resize logic to XenPool
This commit is contained in:
parent
bdfb85ac19
commit
973c83cedd
@ -85,16 +85,16 @@ class XenPool(Pool):
|
|||||||
elif _type in ['read-write', 'volatile']:
|
elif _type in ['read-write', 'volatile']:
|
||||||
path = volume.path
|
path = volume.path
|
||||||
|
|
||||||
if size <= volume.size:
|
|
||||||
raise StoragePoolException('Can not shring volume %s' %
|
|
||||||
volume.name)
|
|
||||||
|
|
||||||
with open(path, 'a+b') as fd:
|
with open(path, 'a+b') as fd:
|
||||||
fd.truncate(size)
|
fd.truncate(size)
|
||||||
|
|
||||||
|
self._resize_loop_device(path)
|
||||||
|
|
||||||
|
def _resize_loop_device(self, path):
|
||||||
# find loop device if any
|
# find loop device if any
|
||||||
p = subprocess.Popen(['sudo', 'losetup', '--associated', path],
|
p = subprocess.Popen(
|
||||||
stdout=subprocess.PIPE)
|
['sudo', 'losetup', '--associated', path],
|
||||||
|
stdout=subprocess.PIPE)
|
||||||
result = p.communicate()
|
result = p.communicate()
|
||||||
|
|
||||||
m = re.match(r'^(/dev/loop\d+):\s', result[0])
|
m = re.match(r'^(/dev/loop\d+):\s', result[0])
|
||||||
|
@ -1064,11 +1064,11 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
|||||||
def resize_private_img(self, size):
|
def resize_private_img(self, size):
|
||||||
'''Resize private image.'''
|
'''Resize private image.'''
|
||||||
|
|
||||||
if size >= self.get_private_img_sz():
|
warnings.warn(
|
||||||
raise qubes.exc.QubesValueError('Cannot shrink private.img')
|
"resize_private_img is deprecated, use volumes[name].resize()",
|
||||||
|
DeprecationWarning)
|
||||||
|
|
||||||
# resize the image
|
self.volumes['private'].resize(size)
|
||||||
self.storage.resize_private_img(size)
|
|
||||||
|
|
||||||
# and then the filesystem
|
# and then the filesystem
|
||||||
# FIXME move this to qubes.storage.xen.XenVMStorage
|
# 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:
|
if retcode != 0:
|
||||||
raise qubes.exc.QubesException('resize2fs failed')
|
raise qubes.exc.QubesException('resize2fs failed')
|
||||||
|
|
||||||
|
|
||||||
# TODO move to storage
|
|
||||||
def resize_root_img(self, size, allow_start=False):
|
def resize_root_img(self, size, allow_start=False):
|
||||||
if hasattr(self, 'template'):
|
warnings.warn(
|
||||||
raise qubes.exc.QubesVMError(self,
|
"resize_root_img is deprecated, use volumes[name].resize()",
|
||||||
'Cannot resize root.img of template based qube. Resize the'
|
DeprecationWarning)
|
||||||
' root.img of the template instead.')
|
|
||||||
|
|
||||||
# TODO self.is_halted
|
self.volumes['root'].resize(size)
|
||||||
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
|
|
||||||
|
|
||||||
if not allow_start:
|
if not allow_start:
|
||||||
raise qubes.exc.QubesException(
|
raise qubes.exc.QubesException(
|
||||||
|
Loading…
Reference in New Issue
Block a user