storage/file: get volume size from the actual image file size

Don't realy on a volume configuration only, it's easy to miss updating
it. Specifically, import_volume() function didn't updated the size based
on the source volume.
The size that the actual VM sees is based on the
file size, and so is the filesystem inside. Outdated size property can
lead to a data loss if the user perform an action based on a incorrect
assumption - like extending size, which actually will shrink the volume.

Fixes QubesOS/qubes-issues#4821
This commit is contained in:
Marek Marczykowski-Górecki 2019-10-31 01:37:06 +01:00
父節點 598d059c57
當前提交 dd037f4663
沒有發現已知的金鑰在資料庫的簽署中
GPG 金鑰 ID: 063938BA42CFA724

查看文件

@ -28,6 +28,7 @@ import os
import os.path
import re
import subprocess
from contextlib import suppress
import qubes.storage
@ -394,6 +395,17 @@ class FileVolume(qubes.storage.Volume):
iso_date = qubes.storage.isodate(seconds).split('.', 1)[0]
return {'old': iso_date}
@property
def size(self):
with suppress(FileNotFoundError):
self._size = os.path.getsize(self.path)
return self._size
@size.setter
def size(self, _):
raise qubes.storage.StoragePoolException(
"You shouldn't use volume size setter, use resize method instead")
@property
def usage(self):
''' Returns the actualy used space '''