Skip to content

Commit

Permalink
F OpenNebula#6524: Check free space on backup DS (OpenNebula#3214)
Browse files Browse the repository at this point in the history
  • Loading branch information
paczerny authored Sep 4, 2024
1 parent c8c66b1 commit ccc8ccf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 12 additions & 1 deletion src/rm/RequestManagerVirtualMachine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/vm/VirtualMachineDisk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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;
Expand Down

0 comments on commit ccc8ccf

Please sign in to comment.