From af05a4c991e4f0e2a33743194b4e5e656e39eb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Wed, 4 Sep 2024 13:27:33 +0200 Subject: [PATCH] F #6524: Check free space on backup DS (#3214) (cherry picked from commit ccc8ccfc344fe5bd9a035167e848e287b46b12a1) --- src/rm/RequestManagerVirtualMachine.cc | 13 ++++++++++++- src/vm/VirtualMachineDisk.cc | 15 +++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index d714a354dd..c6326536d2 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -3956,6 +3956,7 @@ Request::ErrorCode VirtualMachineBackup::request_execute(RequestAttributes& att, Backups::Mode mode; int li_id; int bk_id = -1; + long long backup_size = 0; // ------------------------------------------------------------------------ // Get VM & Backup Information @@ -3964,7 +3965,7 @@ Request::ErrorCode VirtualMachineBackup::request_execute(RequestAttributes& att, { vm->get_permissions(vm_perms); - vm->backup_size(quota_tmpl); + backup_size = vm->backup_size(quota_tmpl); mode = vm->backups().mode(); li_id = vm->backups().last_increment_id(); @@ -4005,6 +4006,16 @@ Request::ErrorCode VirtualMachineBackup::request_execute(RequestAttributes& att, return ACTION; } + long long free_mb; + bool check_capacity = ds->get_avail_mb(free_mb); + + if (check_capacity && free_mb < backup_size) + { + att.resp_msg = "Not enough free space on target datastore"; + + return ACTION; + } + ds->get_permissions(ds_perms); } else diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index fd422f7761..3d61bc0487 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -1571,19 +1571,14 @@ long long VirtualMachineDisks::backup_size(Template &ds_quotas, bool do_volatile { long long size = 0; - for (const auto disk : *this) + vector ids; + backup_disk_ids(do_volatile, ids); + + for (int id : ids) { + auto disk = get_disk(id); long long disk_size = 0; - string type = disk->vector_value("TYPE"); - - one_util::toupper(type); - - if ((type == "SWAP") || ((type == "FS") && !do_volatile)) - { - continue; - } - disk->vector_value("SIZE", disk_size); size += disk_size;