storage/reflink: simplify volume.usage()
This commit is contained in:
parent
9f5d05bfde
commit
30b92f8845
@ -36,7 +36,6 @@ from contextlib import contextmanager, suppress
|
||||
|
||||
import qubes.storage
|
||||
|
||||
BLKSIZE = 512
|
||||
FICLONE = 1074041865 # defined in <linux/fs.h>
|
||||
LOOP_SET_CAPACITY = 0x4C07 # defined in <linux/loop.h>
|
||||
LOGGER = logging.getLogger('qubes.storage.reflink')
|
||||
@ -342,10 +341,9 @@ class ReflinkVolume(qubes.storage.Volume):
|
||||
''' Return volume disk usage from the VM's perspective. It is
|
||||
usually much lower from the host's perspective due to CoW.
|
||||
'''
|
||||
with suppress(FileNotFoundError):
|
||||
return _get_file_disk_usage(self._path_dirty)
|
||||
with suppress(FileNotFoundError):
|
||||
return _get_file_disk_usage(self._path_clean)
|
||||
for path in (self._path_dirty, self._path_clean):
|
||||
with suppress(FileNotFoundError):
|
||||
return os.stat(path).st_blocks * 512
|
||||
return 0
|
||||
|
||||
|
||||
@ -369,10 +367,6 @@ def _replace_file(dst):
|
||||
_remove_file(tmp.name)
|
||||
raise
|
||||
|
||||
def _get_file_disk_usage(path):
|
||||
''' Return real disk usage (not logical file size) of a file. '''
|
||||
return os.stat(path).st_blocks * BLKSIZE
|
||||
|
||||
def _fsync_dir(path):
|
||||
dir_fd = os.open(path, os.O_RDONLY | os.O_DIRECTORY)
|
||||
try:
|
||||
|
@ -62,15 +62,17 @@ class ReflinkMixin:
|
||||
|
||||
os.symlink(img_real, img_sym)
|
||||
reflink._create_sparse_file(img_real, size_initial)
|
||||
self.assertEqual(reflink._get_file_disk_usage(img_real), 0)
|
||||
self.assertEqual(os.stat(img_real).st_size, size_initial)
|
||||
stat = os.stat(img_real)
|
||||
self.assertEqual(stat.st_blocks, 0)
|
||||
self.assertEqual(stat.st_size, size_initial)
|
||||
|
||||
dev_from_real = setup_loopdev(img_real, cleanup_via=self.addCleanup)
|
||||
dev_from_sym = setup_loopdev(img_sym, cleanup_via=self.addCleanup)
|
||||
|
||||
reflink._resize_file(img_real, size_resized)
|
||||
self.assertEqual(reflink._get_file_disk_usage(img_real), 0)
|
||||
self.assertEqual(os.stat(img_real).st_size, size_resized)
|
||||
stat = os.stat(img_real)
|
||||
self.assertEqual(stat.st_blocks, 0)
|
||||
self.assertEqual(stat.st_size, size_resized)
|
||||
|
||||
reflink_update_loopdev_sizes(os.path.join(self.test_dir, 'unrelated'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user