mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
F #6029: Extend BACKUP state to include increment_flatten action
This prevents a race condition on when flatten and backup actions are triggered simultaneously.
This commit is contained in:
parent
a688801ef4
commit
e6c7c51c30
@ -884,6 +884,16 @@ void ImageManager::_increment_flatten(unique_ptr<image_msg_t> msg)
|
||||
int uid = image->get_uid();
|
||||
int gid = image->get_gid();
|
||||
|
||||
auto ids = image->get_running_ids();
|
||||
auto first = ids.cbegin();
|
||||
|
||||
int vm_id = -1;
|
||||
|
||||
if (first != ids.cend())
|
||||
{
|
||||
vm_id = *first;
|
||||
}
|
||||
|
||||
if (msg->status() == "SUCCESS")
|
||||
{
|
||||
auto& increments = image->increments();
|
||||
@ -945,6 +955,36 @@ void ImageManager::_increment_flatten(unique_ptr<image_msg_t> msg)
|
||||
|
||||
Quotas::ds_del(uid, gid, "as);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Update VM state to RUNNING/POWEROFF after increment_flatten */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
if ( vm_id == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualMachinePool* vmpool = Nebula::instance().get_vmpool();
|
||||
|
||||
if (auto vm = vmpool->get(vm_id))
|
||||
{
|
||||
switch(vm->get_lcm_state())
|
||||
{
|
||||
case VirtualMachine::BACKUP:
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
break;
|
||||
|
||||
case VirtualMachine::BACKUP_POWEROFF:
|
||||
vm->set_state(VirtualMachine::POWEROFF);
|
||||
vm->set_state(VirtualMachine::LCM_INIT);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -2870,10 +2870,9 @@ void LifeCycleManager::trigger_backup_success(int vid)
|
||||
|
||||
backups.last_backup_clear();
|
||||
|
||||
vmpool->update(vm.get());
|
||||
|
||||
if (delete_ids.size() > 0) // FULL & backups > keep_last
|
||||
if (delete_ids.size() > 0)
|
||||
{
|
||||
// FULL & backups > keep_last
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Removing backup snapshots:";
|
||||
@ -2885,15 +2884,29 @@ void LifeCycleManager::trigger_backup_success(int vid)
|
||||
|
||||
vm->log("LCM", Log::INFO, oss.str());
|
||||
}
|
||||
else if (keep_last > 0 && increments > keep_last) // INCREMENTAL & increments > keep_last
|
||||
else if (keep_last > 0 && increments > keep_last)
|
||||
{
|
||||
// INCREMENTAL & increments > keep_last
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Removing " << increments - keep_last << " backup increments";
|
||||
|
||||
vm->log("LCM", Log::INFO, oss.str());
|
||||
|
||||
//Rollback state to prevent backup operations while increment_flatten
|
||||
if ( vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
vm->set_state(VirtualMachine::BACKUP);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->set_state(VirtualMachine::ACTIVE);
|
||||
vm->set_state(VirtualMachine::BACKUP_POWEROFF);
|
||||
}
|
||||
}
|
||||
|
||||
vmpool->update(vm.get());
|
||||
|
||||
vm.reset();
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user