From 10d4381c14c13a81fd23879310bf6a423723d207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 5 Jan 2021 03:33:21 +0100 Subject: [PATCH] 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 --- qubesadmin/backup/restore.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/qubesadmin/backup/restore.py b/qubesadmin/backup/restore.py index 4996454..fc3aee1 100644 --- a/qubesadmin/backup/restore.py +++ b/qubesadmin/backup/restore.py @@ -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)