Merge remote-tracking branch 'origin/pr/239'

* origin/pr/239:
  storage: fix NotImplementedError message for import_data()
  storage/reflink: make resize()/import_volume() more readable
  storage/reflink: unblock import_data() and import_data_end()
This commit is contained in:
Marek Marczykowski-Górecki 2018-10-29 23:00:04 +01:00
commit b9a18a819c
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 14 additions and 10 deletions

View File

@ -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

View File

@ -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):
@ -279,6 +280,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,23 +288,25 @@ 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:
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):