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. This can be implemented as a coroutine.
''' '''
raise self._not_implemented("import") raise self._not_implemented("import_data")
def import_data_end(self, success): def import_data_end(self, success):
''' End the data import operation. This may be used by pool ''' End the data import operation. This may be used by pool

View File

@ -264,12 +264,13 @@ class ReflinkVolume(qubes.storage.Volume):
try: # assume volume is not (cleanly) stopped ... try: # assume volume is not (cleanly) stopped ...
_resize_file(self._path_dirty, size) _resize_file(self._path_dirty, size)
self.size = size update = True
except FileNotFoundError: # ... but it actually is. except FileNotFoundError: # ... but it actually is.
_resize_file(self._path_clean, size) _resize_file(self._path_clean, size)
self.size = size update = False
return self
self.size = size
if update:
_update_loopdev_sizes(self._path_dirty) _update_loopdev_sizes(self._path_dirty)
return self return self
@ -279,6 +280,7 @@ class ReflinkVolume(qubes.storage.Volume):
'Cannot export: {} is not save_on_stop'.format(self.vid)) 'Cannot export: {} is not save_on_stop'.format(self.vid))
return self._path_clean return self._path_clean
@_unblock
def import_data(self): def import_data(self):
if not self.save_on_stop: if not self.save_on_stop:
raise NotImplementedError( raise NotImplementedError(
@ -286,23 +288,25 @@ class ReflinkVolume(qubes.storage.Volume):
_create_sparse_file(self._path_import, self.size) _create_sparse_file(self._path_import, self.size)
return self._path_import return self._path_import
def import_data_end(self, success): def _import_data_end(self, success):
if success: if success:
self._commit(self._path_import) self._commit(self._path_import)
else: else:
_remove_file(self._path_import) _remove_file(self._path_import)
return self return self
import_data_end = _unblock(_import_data_end)
@_unblock @_unblock
def import_volume(self, src_volume): def import_volume(self, src_volume):
if not self.save_on_stop: if not self.save_on_stop:
return self return self
try: try:
success = False
_copy_file(src_volume.export(), self._path_import) _copy_file(src_volume.export(), self._path_import)
except: success = True
self.import_data_end(False) finally:
raise self._import_data_end(success)
self.import_data_end(True)
return self return self
def _path_revision(self, number, timestamp=None): def _path_revision(self, number, timestamp=None):