backup: check if there is enough disk space available to restore

Avoid failing restore after potentially lengthy processing - check
available space first.

This will be even more important after adding waiting for free space -
then if there won't be enough free space, the process will deadlock.

QubesOS/qubes-issues#4791
This commit is contained in:
Marek Marczykowski-Górecki 2021-01-05 03:33:21 +01:00
parent 16ff6d0552
commit 10d4381c14
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -1871,6 +1871,22 @@ class BackupRestore(object):
self.log.error('Failed to resize volume %s of VM %s to %d: %s',
volume.name, vm.name, size, err)
def check_disk_space(self):
"""
Check if there is enough disk space to restore the backup.
Currently it checks only for the space in temporary directory,
not the target storage pools.
:return:
"""
statvfs = os.statvfs(self.tmpdir)
# require 1GB in /var/tmp
if statvfs.f_frsize * statvfs.f_bavail < 1024 ** 3:
raise QubesException("Too little space in {}, needs at least 1GB".
format(self.tmpdir))
def restore_do(self, restore_info):
'''
@ -1887,6 +1903,8 @@ class BackupRestore(object):
if self.header_data.version == 1:
raise NotImplementedError('Backup format version 1 not supported')
self.check_disk_space()
restore_info = self.restore_info_verify(restore_info)
self._restore_vms_metadata(restore_info)