From 803efa76ff5f46e80d421d842ebc10fbd090f63e Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Tue, 21 Jun 2016 12:48:57 +0200 Subject: [PATCH] Merge FilePool._resize_loop_device() with resize() --- qubes/storage/file.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/qubes/storage/file.py b/qubes/storage/file.py index 24b63a59..2d9254d3 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -107,7 +107,18 @@ class FilePool(Pool): with open(path, 'a+b') as fd: fd.truncate(size) - self._resize_loop_device(path) + p = subprocess.Popen( + ['sudo', 'losetup', '--associated', path], + stdout=subprocess.PIPE) + result = p.communicate() + + m = re.match(r'^(/dev/loop\d+):\s', result[0]) + if m is not None: + loop_dev = m.group(1) + + # resize loop device + subprocess.check_call(['sudo', 'losetup', '--set-capacity', loop_dev + ]) def remove(self, volume): if volume.volume_type in ['read-write', 'volatile']: @@ -128,23 +139,6 @@ class FilePool(Pool): return volume - @staticmethod - def _resize_loop_device(path): - ''' Sets the loop device capacity ''' - # find loop device if any - p = subprocess.Popen( - ['sudo', 'losetup', '--associated', path], - stdout=subprocess.PIPE) - result = p.communicate() - - m = re.match(r'^(/dev/loop\d+):\s', result[0]) - if m is not None: - loop_dev = m.group(1) - - # resize loop device - subprocess.check_call(['sudo', 'losetup', '--set-capacity', - loop_dev]) - def commit_template_changes(self, volume): if volume.volume_type != 'origin': return volume