Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/375'
Browse files Browse the repository at this point in the history
* origin/pr/375:
  Fix line lengths
  Return better error messages from file pool
  Fix bugs found by Rusty Bird
  Fix export locking
  Re-add dirty check in case qubesd is restarted
  File volumes are started NAND exported
  file pool: snapshotting dirty volume not supported
  Always snapshot in the FILE pool
  • Loading branch information
marmarek committed Nov 26, 2020
2 parents b3bb65d + 542fee1 commit 7ab1703
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions qubes/storage/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ def included_in(self, app):
class FileVolume(qubes.storage.Volume):
''' Parent class for the xen volumes implementation which expects a
`target_dir` param on initialization. '''
_marker_running = object()
_marker_exported = object()

def __init__(self, dir_path, **kwargs):
self.dir_path = dir_path
assert self.dir_path, "dir_path not specified"
self._revisions_to_keep = 0
self._export_lock = None
super().__init__(**kwargs)

if self.snap_on_start:
Expand Down Expand Up @@ -265,10 +268,22 @@ def commit(self):
return self

def export(self):
# FIXME: this should rather return snapshot(self.path, self.path_cow)
# if domain is running
if self._export_lock is not None:
assert self._export_lock is FileVolume._marker_running, \
'nested calls to export()'
raise qubes.storage.StoragePoolException(
'file pool cannot export running volumes')
if self.is_dirty():
raise qubes.storage.StoragePoolException(
'file pool cannot export dirty volumes')
self._export_lock = FileVolume._marker_exported
return self.path

def export_end(self, path):
assert self._export_lock is not FileVolume._marker_running, \
'ending an export on a running volume?'
self._export_lock = None

@asyncio.coroutine
def import_volume(self, src_volume):
if src_volume.snap_on_start:
Expand Down Expand Up @@ -311,6 +326,12 @@ def reset(self):
return self

def start(self):
if self._export_lock is not None:
assert self._export_lock is FileVolume._marker_exported, \
'nested calls to start()'
raise qubes.storage.StoragePoolException(
'file pool cannot start a VM with an exported volume')
self._export_lock = FileVolume._marker_running
if not self.save_on_stop and not self.snap_on_start:
self.reset()
else:
Expand All @@ -328,12 +349,15 @@ def start(self):
return self

def stop(self):
assert self._export_lock is not FileVolume._marker_exported, \
'trying to stop exported file volume?'
if self.save_on_stop:
self.commit()
elif self.snap_on_start:
_remove_if_exists(self.path_cow)
else:
_remove_if_exists(self.path)
self._export_lock = None
return self

@property
Expand Down

0 comments on commit 7ab1703

Please sign in to comment.