From fabd8119b49520652de469d71c944adc8008b24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 26 Jun 2017 11:59:53 +0200 Subject: [PATCH] storage: volume.import_volume now expect create()d volume This is much more logical for *import*_volume function. QubesOS/qubes-issues#2256 --- qubes/storage/__init__.py | 19 ++++++++----------- qubes/storage/file.py | 1 + qubes/storage/lvm.py | 3 ++- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 47507969..22123b81 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -177,7 +177,11 @@ class Volume(object): def import_volume(self, src_volume): ''' Imports data from a different volume (possibly in a different - pool ''' + pool. + + The needs to be create()d first. + + This can be implemented as a coroutine. ''' # pylint: disable=unused-argument raise self._not_implemented("import_volume") @@ -448,16 +452,9 @@ class Storage(object): dst_pool = self.vm.app.get_pool(config['pool']) dst = dst_pool.init_volume(self.vm, config) src_volume = src_vm.volumes[name] - src_pool = src_volume.pool - if dst_pool == src_pool: - msg = "Cloning volume {!s} from vm {!s}" - self.vm.log.info(msg.format(src_volume.name, src_vm.name)) - clone_op_ret = dst_pool.clone(src_volume, dst) - else: - msg = "Importing volume {!s} from vm {!s}" - self.vm.log.info(msg.format(src_volume.name, src_vm.name)) - clone_op_ret = dst_pool.import_volume( - dst_pool, dst, src_pool, src_volume) + msg = "Importing volume {!s} from vm {!s}" + self.vm.log.info(msg.format(src_volume.name, src_vm.name)) + clone_op_ret = dst.import_volume(src_volume) # clone/import functions may be either synchronous or asynchronous # in the later case, we need to wait for them to finish diff --git a/qubes/storage/file.py b/qubes/storage/file.py index eb999c09..5b352254 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -261,6 +261,7 @@ class FileVolume(qubes.storage.Volume): msg = msg.format(src_volume, self) assert not src_volume.snap_on_start, msg if self.save_on_stop: + _remove_if_exists(self.path) copy_file(src_volume.export(), self.path) return self diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index 8c1ca86b..77f94d0c 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -310,10 +310,11 @@ class ThinVolume(qubes.storage.Volume): # pylint: disable=line-too-long if isinstance(src_volume.pool, ThinPool) and \ src_volume.pool.thin_pool == self.pool.thin_pool: # NOQA + cmd = ['remove', self.vid] + qubes_lvm(cmd, self.log) cmd = ['clone', str(src_volume), str(self)] qubes_lvm(cmd, self.log) else: - self.create() src_path = src_volume.export() cmd = ['sudo', 'dd', 'if=' + src_path, 'of=/dev/' + self.vid, 'conv=sparse']