Skip to content

Commit

Permalink
storeage/reflink: unlock size getter
Browse files Browse the repository at this point in the history
Don't update _size in the getter, so it can be unlocked (which is
helpful for QubesOS/qubes-issues#5935).

!!! If cherry-picking for release4.0, also adjust import_data() to !!!
!!! use self.size (no underscore) instead of self._get_size()      !!!

(cherry picked from commit a1b5262)
  • Loading branch information
rustybird authored and marmarek committed Oct 22, 2020
1 parent 5aa9954 commit 16f597a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions qubes/storage/reflink.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def start(self):
# Preferably use the size of a leftover image, in case
# the volume was previously resized - but then a crash
# prevented qubes.xml serialization of the new size.
_create_sparse_file(self._path_dirty, self._get_size())
_create_sparse_file(self._path_dirty, self.size)
return self

@_coroutinized
Expand All @@ -227,7 +227,7 @@ def stop(self):
self._commit(self._path_dirty)
else:
if not self.snap_on_start:
self._get_size() # preserve manual resize of image
self._size = self.size # preserve manual resize of image
_remove_file(self._path_dirty)
_remove_file(self._path_clean)
return self
Expand Down Expand Up @@ -298,7 +298,7 @@ def import_data(self):
if not self.save_on_stop:
raise NotImplementedError(
'Cannot import_data: {} is not save_on_stop'.format(self.vid))
_create_sparse_file(self._path_import, self._get_size())
_create_sparse_file(self._path_import, self.size)
return self._path_import

def _import_data_end(self, success):
Expand Down Expand Up @@ -339,15 +339,13 @@ def revisions(self):
return collections.OrderedDict(sorted(items,
key=lambda item: int(item[0])))

def _get_size(self):
@property
def size(self):
for path in (self._path_dirty, self._path_clean):
with suppress(FileNotFoundError):
self._size = os.path.getsize(path)
break
return os.path.getsize(path)
return self._size

size = property(_locked(_get_size))

@property
def usage(self):
''' Return volume disk usage from the VM's perspective. It is
Expand Down

0 comments on commit 16f597a

Please sign in to comment.