From 425d9937692bc6f7ebbc4a277f0eeb51c8be17c9 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Mon, 29 Oct 2018 20:21:39 +0000 Subject: [PATCH 1/3] storage/reflink: unblock import_data() and import_data_end() --- qubes/storage/reflink.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qubes/storage/reflink.py b/qubes/storage/reflink.py index 3f250011..262573ec 100644 --- a/qubes/storage/reflink.py +++ b/qubes/storage/reflink.py @@ -279,6 +279,7 @@ class ReflinkVolume(qubes.storage.Volume): 'Cannot export: {} is not save_on_stop'.format(self.vid)) return self._path_clean + @_unblock def import_data(self): if not self.save_on_stop: raise NotImplementedError( @@ -286,13 +287,15 @@ class ReflinkVolume(qubes.storage.Volume): _create_sparse_file(self._path_import, self.size) return self._path_import - def import_data_end(self, success): + def _import_data_end(self, success): if success: self._commit(self._path_import) else: _remove_file(self._path_import) return self + import_data_end = _unblock(_import_data_end) + @_unblock def import_volume(self, src_volume): if not self.save_on_stop: @@ -300,9 +303,9 @@ class ReflinkVolume(qubes.storage.Volume): try: _copy_file(src_volume.export(), self._path_import) except: - self.import_data_end(False) + self._import_data_end(False) raise - self.import_data_end(True) + self._import_data_end(True) return self def _path_revision(self, number, timestamp=None): From 73db2751b8590aa71b494b3e69374ab05f3d065d Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Mon, 29 Oct 2018 20:21:41 +0000 Subject: [PATCH 2/3] storage/reflink: make resize()/import_volume() more readable --- qubes/storage/reflink.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qubes/storage/reflink.py b/qubes/storage/reflink.py index 262573ec..fd4d4ee5 100644 --- a/qubes/storage/reflink.py +++ b/qubes/storage/reflink.py @@ -264,13 +264,14 @@ class ReflinkVolume(qubes.storage.Volume): try: # assume volume is not (cleanly) stopped ... _resize_file(self._path_dirty, size) - self.size = size + update = True except FileNotFoundError: # ... but it actually is. _resize_file(self._path_clean, size) - self.size = size - return self + update = False - _update_loopdev_sizes(self._path_dirty) + self.size = size + if update: + _update_loopdev_sizes(self._path_dirty) return self def export(self): @@ -301,11 +302,11 @@ class ReflinkVolume(qubes.storage.Volume): if not self.save_on_stop: return self try: + success = False _copy_file(src_volume.export(), self._path_import) - except: - self._import_data_end(False) - raise - self._import_data_end(True) + success = True + finally: + self._import_data_end(success) return self def _path_revision(self, number, timestamp=None): From 7e4812a525a2a87c0b97f1098e1546943e03885a Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Mon, 29 Oct 2018 20:21:42 +0000 Subject: [PATCH 3/3] storage: fix NotImplementedError message for import_data() --- qubes/storage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 2a6afaa3..5613ba67 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -201,7 +201,7 @@ class Volume: This can be implemented as a coroutine. ''' - raise self._not_implemented("import") + raise self._not_implemented("import_data") def import_data_end(self, success): ''' End the data import operation. This may be used by pool