Skip to content

Commit f0b01f6

Browse files
committed
use dirty file instead of clean file
1 parent ee41bc0 commit f0b01f6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

qubes/storage/reflink.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ def __init__(self, *args, **kwargs):
176176
self._path_precache = self._path_vid + "-precache.img"
177177
self._path_dirty = self._path_vid + "-dirty.img"
178178
self._path_import = self._path_vid + "-import.img"
179-
self.path = (
180-
self._path_clean if self.snapshots_disabled else self._path_dirty
181-
)
179+
self.path = self._path_dirty
182180

183181
@contextmanager
184182
def _update_precache(self):
@@ -270,6 +268,9 @@ def start(self): # pylint: disable=invalid-overridden-method
270268
if self.snapshots_disabled:
271269
self._prune_revisions(keep=0)
272270
_remove_file(self._path_precache)
271+
if not self.is_dirty():
272+
_rename_file(self._path_clean, self._path_dirty)
273+
273274
return self
274275
if not self.is_dirty():
275276
if self.snap_on_start:
@@ -291,7 +292,9 @@ def start(self): # pylint: disable=invalid-overridden-method
291292
@_coroutinized
292293
def stop(self): # pylint: disable=invalid-overridden-method
293294
if self.is_dirty():
294-
if not self.snapshots_disabled:
295+
if self.snapshots_disabled:
296+
_rename_file(self._path_dirty, self._path_clean)
297+
else:
295298
self._commit(self._path_dirty)
296299
elif not self.save_on_stop:
297300
if not self.snap_on_start:

qubes/tests/storage_reflink.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,17 @@ def test_120_private_snapshots_disabled(self):
364364
self.assertEqual(volume.pool, self.pool.name)
365365
volume._copy_file = unittest.mock.Mock()
366366
self.loop.run_until_complete(volume.create())
367+
self.loop.run_until_complete(volume.start())
367368
self.assertEqual(
368369
volume.block_device().path,
369-
"/var/tmp/test-reflink-units-on-btrfs/appvms/test-inst-appvm/private.img",
370+
"/var/tmp/test-reflink-units-on-btrfs/appvms/test-inst-appvm/private-dirty.img",
370371
)
371-
self.assertFalse(os.path.exists(volume._path_dirty))
372+
self.assertFalse(os.path.exists(volume._path_clean))
372373
self.assertFalse(os.path.exists(volume._path_precache))
373374
self.loop.run_until_complete(volume.stop())
375+
self.assertFalse(os.path.exists(volume._path_dirty))
376+
self.assertTrue(os.path.exists(volume._path_clean))
377+
self.assertFalse(os.path.exists(volume._path_precache))
374378
self.loop.run_until_complete(volume.remove())
375379
volume._copy_file.assert_not_called()
376380

0 commit comments

Comments
 (0)