Skip to content

Commit

Permalink
backup: check if there is enough disk space available to restore
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marmarek committed Jan 5, 2021
1 parent 16ff6d0 commit 10d4381
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qubesadmin/backup/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,22 @@ def _handle_volume_size(self, vm, volume, size):
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):
'''
Expand All @@ -1887,6 +1903,8 @@ def restore_do(self, restore_info):
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)
Expand Down

0 comments on commit 10d4381

Please sign in to comment.