From 68d5ca93e10ffd4a64e4621453dd22d370f48b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 26 Apr 2017 01:07:27 +0200 Subject: [PATCH] storage: have QubesVM() handle vm.dir_path, also on clone and rename Keep it uniform - QubesVM() object is responsible for handling vm.dir_path, Storage() is responsible for handling disk volumes (which may live in that directory QubesOS/qubes-issues#2256 --- qubes/storage/__init__.py | 17 ----------------- qubes/vm/qubesvm.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 8d2b7a1b..33d76b33 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -370,23 +370,10 @@ class Storage(object): def clone(self, src_vm): ''' Clone volumes from the specified vm ''' - src_path = src_vm.dir_path - msg = "Source path {!s} does not exist".format(src_path) - assert os.path.exists(src_path), msg - - dst_path = self.vm.dir_path - msg = "Destination {!s} already exists".format(dst_path) - assert not os.path.exists(dst_path), msg - os.mkdir(dst_path) - # clone/import functions may be either synchronous or asynchronous # in the later case, we need to wait for them to finish clone_op = {} - msg = "Cloning directory: {!s} to {!s}" - msg = msg.format(src_path, dst_path) - self.log.info(msg) - self.vm.volumes = {} with VmCreationManager(self.vm): for name, config in self.vm.volume_config.items(): @@ -439,10 +426,6 @@ class Storage(object): def rename(self, old_name, new_name): ''' Notify the pools that the domain was renamed ''' volumes = self.vm.volumes - vm = self.vm - old_dir_path = os.path.join(os.path.dirname(vm.dir_path), old_name) - new_dir_path = os.path.join(os.path.dirname(vm.dir_path), new_name) - os.rename(old_dir_path, new_dir_path) for name, volume in volumes.items(): pool = self.get_pool(volume) volumes[name] = pool.rename(volume, old_name, new_name) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index b0c5a5f1..23c0ece1 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -753,6 +753,10 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): # pylint: disable=unused-argument self.init_log() + old_dir_path = os.path.join(os.path.dirname(self.dir_path), oldvalue) + new_dir_path = os.path.join(os.path.dirname(self.dir_path), newvalue) + os.rename(old_dir_path, new_dir_path) + self.storage.rename(oldvalue, newvalue) if self._libvirt_domain is not None: @@ -1288,6 +1292,12 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): raise qubes.exc.QubesVMNotHaltedError( self, 'Cannot clone a running domain {!r}'.format(self.name)) + msg = "Destination {!s} already exists".format(self.dir_path) + assert not os.path.exists(self.dir_path), msg + + self.log.info('Creating directory: {0}'.format(self.dir_path)) + os.makedirs(self.dir_path, mode=0o775) + if pool or pools: # pylint: disable=attribute-defined-outside-init self.volume_config = _patch_volume_config(self.volume_config, pool,