From 988627c778a40705a7a263476d80c378c6b16ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 18 Oct 2012 14:48:52 +0200 Subject: [PATCH 1/2] Bug #1561: All LCM & DM actions check the VM state --- src/lcm/LifeCycleActions.cc | 35 ++--- src/lcm/LifeCycleStates.cc | 252 ++++++++++++++++++++++++------------ 2 files changed, 186 insertions(+), 101 deletions(-) diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index c71d3afdc8..a0a94ec3b6 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -567,18 +567,18 @@ void LifeCycleManager::delete_action(int vid) return; } - VirtualMachine::LcmState state = vm->get_lcm_state(); - - if ((state == VirtualMachine::LCM_INIT) || - (state == VirtualMachine::CLEANUP)) + if ( vm->get_state() == VirtualMachine::ACTIVE && + (vm->get_lcm_state() != VirtualMachine::LCM_INIT && + vm->get_lcm_state() != VirtualMachine::CLEANUP)) { - vm->unlock(); - return; + clean_up_vm(vm); + + dm->trigger(DispatchManager::DONE,vid); + } + else + { + vm->log("LCM", Log::ERROR, "delete_action, VM in a wrong state."); } - - clean_up_vm(vm); - - dm->trigger(DispatchManager::DONE,vid); vm->unlock(); @@ -602,16 +602,17 @@ void LifeCycleManager::clean_action(int vid) return; } - VirtualMachine::LcmState state = vm->get_lcm_state(); - if ((state == VirtualMachine::LCM_INIT) || - (state == VirtualMachine::CLEANUP)) + if ( vm->get_state() == VirtualMachine::ACTIVE && + (vm->get_lcm_state() != VirtualMachine::LCM_INIT && + vm->get_lcm_state() != VirtualMachine::CLEANUP)) { - vm->unlock(); - return; + clean_up_vm(vm); + } + else + { + vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state."); } - - clean_up_vm(vm); vm->unlock(); } diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index bd37bdae0a..c52696518b 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -221,6 +221,10 @@ void LifeCycleManager::save_failure_action(int vid) vmm->trigger(VirtualMachineManager::POLL,vid); } + else + { + vm->log("LCM",Log::ERROR,"save_failure_action, VM in a wrong state"); + } vm->unlock(); } @@ -266,12 +270,23 @@ void LifeCycleManager::deploy_success_action(int vid) hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk); } + // TODO: BOOT_SUSPENDED & BOOT_STOPPED states + else if ( vm->get_state() == VirtualMachine::BOOT || + vm->get_state() == VirtualMachine::BOOT_POWEROFF || + vm->get_state() == VirtualMachine::BOOT_UNKNOWN /* || + vm->get_state() == VirtualMachine::BOOT_SUSPENDED || + vm->get_state() == VirtualMachine::BOOT_STOPPED */ ) + { + vm->set_state(VirtualMachine::RUNNING); - vm->set_state(VirtualMachine::RUNNING); + vmpool->update(vm); - vmpool->update(vm); - - vm->log("LCM", Log::INFO, "New VM state is RUNNING"); + vm->log("LCM", Log::INFO, "New VM state is RUNNING"); + } + else + { + vm->log("LCM",Log::ERROR,"deploy_success_action, VM in a wrong state"); + } vm->unlock(); } @@ -373,6 +388,10 @@ void LifeCycleManager::deploy_failure_action(int vid) vm->log("LCM", Log::INFO, "Fail to boot VM. New VM state is POWEROFF"); } + else + { + vm->log("LCM",Log::ERROR,"deploy_failure_action, VM in a wrong state"); + } vm->unlock(); } @@ -462,20 +481,28 @@ void LifeCycleManager::shutdown_failure_action(int vid) return; } - //---------------------------------------------------- - // RUNNING STATE FROM SHUTDOWN - //---------------------------------------------------- + if ( vm->get_lcm_state() == VirtualMachine::SHUTDOWN || + vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF ) + { + //---------------------------------------------------- + // RUNNING STATE FROM SHUTDOWN + //---------------------------------------------------- - vm->set_state(VirtualMachine::RUNNING); + vm->set_state(VirtualMachine::RUNNING); - vmpool->update(vm); + vmpool->update(vm); - vm->log("LCM", Log::INFO, "Fail to shutdown VM." - " Assuming that the VM is still RUNNING (will poll VM)."); + vm->log("LCM", Log::INFO, "Fail to shutdown VM." + " Assuming that the VM is still RUNNING (will poll VM)."); - //---------------------------------------------------- + //---------------------------------------------------- - vmm->trigger(VirtualMachineManager::POLL,vid); + vmm->trigger(VirtualMachineManager::POLL,vid); + } + else + { + vm->log("LCM",Log::ERROR,"shutdown_failure_action, VM in a wrong state"); + } vm->unlock(); } @@ -560,6 +587,8 @@ void LifeCycleManager::prolog_failure_action(int vid) return; } + // TODO: done in branch bug-1210 + vm->set_prolog_etime(the_time); failure_action(vm); @@ -660,12 +689,17 @@ void LifeCycleManager::epilog_failure_action(int vid) dm->trigger(DispatchManager::RESUBMIT, vid); } - else + else if ( vm->get_lcm_state() == VirtualMachine::EPILOG_STOP || + vm->get_lcm_state() == VirtualMachine::EPILOG ) { vm->set_epilog_etime(the_time); failure_action(vm); } + else + { + vm->log("LCM",Log::ERROR,"epilog_failure_action, VM in a wrong state"); + } vm->unlock(); @@ -689,27 +723,34 @@ void LifeCycleManager::cancel_success_action(int vid) return; } - //---------------------------------------------------- - // EPILOG STATE - //---------------------------------------------------- + if ( vm->get_lcm_state() == VirtualMachine::CANCEL ) + { + //---------------------------------------------------- + // EPILOG STATE + //---------------------------------------------------- - vm->set_state(VirtualMachine::EPILOG); + vm->set_state(VirtualMachine::EPILOG); - vmpool->update(vm); + vmpool->update(vm); - vm->set_reason(History::CANCEL); + vm->set_reason(History::CANCEL); - vm->set_epilog_stime(the_time); + vm->set_epilog_stime(the_time); - vm->set_running_etime(the_time); + vm->set_running_etime(the_time); - vmpool->update_history(vm); + vmpool->update_history(vm); - vm->log("LCM", Log::INFO, "New VM state is EPILOG"); + vm->log("LCM", Log::INFO, "New VM state is EPILOG"); - //---------------------------------------------------- + //---------------------------------------------------- - tm->trigger(TransferManager::EPILOG,vid); + tm->trigger(TransferManager::EPILOG,vid); + } + else + { + vm->log("LCM",Log::ERROR,"cancel_success_action, VM in a wrong state"); + } vm->unlock(); } @@ -731,20 +772,27 @@ void LifeCycleManager::cancel_failure_action(int vid) return; } - //---------------------------------------------------- - // RUNNING STATE FROM CANCEL - //---------------------------------------------------- + if ( vm->get_lcm_state() == VirtualMachine::CANCEL ) + { + //---------------------------------------------------- + // RUNNING STATE FROM CANCEL + //---------------------------------------------------- - vm->set_state(VirtualMachine::RUNNING); + vm->set_state(VirtualMachine::RUNNING); - vmpool->update(vm); + vmpool->update(vm); - vm->log("LCM", Log::INFO, "Fail to cancel VM." - " Assuming that the VM is still RUNNING (will poll VM)."); + vm->log("LCM", Log::INFO, "Fail to cancel VM." + " Assuming that the VM is still RUNNING (will poll VM)."); - //---------------------------------------------------- + //---------------------------------------------------- - vmm->trigger(VirtualMachineManager::POLL,vid); + vmm->trigger(VirtualMachineManager::POLL,vid); + } + else + { + vm->log("LCM",Log::ERROR,"cancel_failure_action, VM in a wrong state"); + } vm->unlock(); } @@ -765,9 +813,17 @@ void LifeCycleManager::monitor_failure_action(int vid) return; } - vm->set_running_etime(the_time); + if ( vm->get_lcm_state() == VirtualMachine::RUNNING || + vm->get_lcm_state() == VirtualMachine::UNKNOWN ) + { + vm->set_running_etime(the_time); - failure_action(vm); + failure_action(vm); + } + else + { + vm->log("LCM",Log::ERROR,"monitor_failure_action, VM in a wrong state"); + } vm->unlock(); } @@ -792,35 +848,43 @@ void LifeCycleManager::monitor_suspend_action(int vid) return; } - //---------------------------------------------------- - // SAVE_SUSPEND STATE - //---------------------------------------------------- + if ( vm->get_lcm_state() == VirtualMachine::RUNNING || + vm->get_lcm_state() == VirtualMachine::UNKNOWN ) + { + //---------------------------------------------------- + // SAVE_SUSPEND STATE + //---------------------------------------------------- - vm->set_state(VirtualMachine::SAVE_SUSPEND); + vm->set_state(VirtualMachine::SAVE_SUSPEND); - vm->set_resched(false); + vm->set_resched(false); - vmpool->update(vm); + vmpool->update(vm); - vm->set_running_etime(the_time); + vm->set_running_etime(the_time); - vm->set_etime(the_time); + vm->set_etime(the_time); - vm->set_vm_info(); + vm->set_vm_info(); - vm->set_reason(History::STOP_RESUME); + vm->set_reason(History::STOP_RESUME); - vmpool->update_history(vm); + vmpool->update_history(vm); - vm->get_requirements(cpu,mem,disk); + vm->get_requirements(cpu,mem,disk); - hpool->del_capacity(vm->get_hid(),cpu,mem,disk); + hpool->del_capacity(vm->get_hid(),cpu,mem,disk); - vm->log("LCM", Log::INFO, "VM is suspended."); + vm->log("LCM", Log::INFO, "VM is suspended."); - //---------------------------------------------------- + //---------------------------------------------------- - dm->trigger(DispatchManager::SUSPEND_SUCCESS,vid); + dm->trigger(DispatchManager::SUSPEND_SUCCESS,vid); + } + else + { + vm->log("LCM",Log::ERROR,"monitor_suspend_action, VM in a wrong state"); + } vm->unlock(); } @@ -839,19 +903,24 @@ void LifeCycleManager::monitor_done_action(int vid) return; } - //---------------------------------------------------- - // UNKNWON STATE - //---------------------------------------------------- + if ( vm->get_lcm_state() == VirtualMachine::RUNNING ) + { + //---------------------------------------------------- + // UNKNWON STATE + //---------------------------------------------------- - vm->set_state(VirtualMachine::UNKNOWN); + vm->set_state(VirtualMachine::UNKNOWN); - vm->set_resched(false); + vm->set_resched(false); - vmpool->update(vm); + vmpool->update(vm); - vm->log("LCM", Log::INFO, "New VM state is UNKNOWN"); - - //---------------------------------------------------- + vm->log("LCM", Log::INFO, "New VM state is UNKNOWN"); + } + else if ( vm->get_lcm_state() != VirtualMachine::UNKNOWN ) + { + vm->log("LCM",Log::ERROR,"monitor_done_action, VM in a wrong state"); + } vm->unlock(); } @@ -909,11 +978,18 @@ void LifeCycleManager::attach_success_action(int vid) return; } - vm->clear_attach_disk(); + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ) + { + vm->clear_attach_disk(); - vm->set_state(VirtualMachine::RUNNING); + vm->set_state(VirtualMachine::RUNNING); - vmpool->update(vm); + vmpool->update(vm); + } + else + { + vm->log("LCM",Log::ERROR,"attach_success_action, VM in a wrong state"); + } vm->unlock(); } @@ -936,33 +1012,41 @@ void LifeCycleManager::attach_failure_action(int vid) return; } - disk = vm->delete_attach_disk(); - uid = vm->get_uid(); - gid = vm->get_gid(); - - vm->set_state(VirtualMachine::RUNNING); - - vmpool->update(vm); - - vm->unlock(); - - if ( disk != 0 ) + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ) { - Nebula& nd = Nebula::instance(); - ImageManager* imagem = nd.get_imagem(); + disk = vm->delete_attach_disk(); + uid = vm->get_uid(); + gid = vm->get_gid(); - Template tmpl; - int image_id; + vm->set_state(VirtualMachine::RUNNING); - tmpl.set(disk); + vmpool->update(vm); - Quotas::quota_del(Quotas::IMAGE, uid, gid, &tmpl); + vm->unlock(); - if ( disk->vector_value("IMAGE_ID", image_id) == 0 ) + if ( disk != 0 ) { - imagem->release_image(image_id, false); + Nebula& nd = Nebula::instance(); + ImageManager* imagem = nd.get_imagem(); + + Template tmpl; + int image_id; + + tmpl.set(disk); + + Quotas::quota_del(Quotas::IMAGE, uid, gid, &tmpl); + + if ( disk->vector_value("IMAGE_ID", image_id) == 0 ) + { + imagem->release_image(image_id, false); + } } } + else + { + vm->log("LCM",Log::ERROR,"attach_failure_action, VM in a wrong state"); + vm->unlock(); + } } /* -------------------------------------------------------------------------- */ From 2969a60da4a461d92e677457d6151f81d409da5b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 19 Oct 2012 00:25:20 +0200 Subject: [PATCH 2/2] bug #1561: Removed pending TODO's --- src/lcm/LifeCycleStates.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index c52696518b..a620171fb0 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -270,12 +270,11 @@ void LifeCycleManager::deploy_success_action(int vid) hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk); } - // TODO: BOOT_SUSPENDED & BOOT_STOPPED states else if ( vm->get_state() == VirtualMachine::BOOT || vm->get_state() == VirtualMachine::BOOT_POWEROFF || - vm->get_state() == VirtualMachine::BOOT_UNKNOWN /* || - vm->get_state() == VirtualMachine::BOOT_SUSPENDED || - vm->get_state() == VirtualMachine::BOOT_STOPPED */ ) + vm->get_state() == VirtualMachine::BOOT_UNKNOWN || + vm->get_state() == VirtualMachine::BOOT_SUSPENDED|| + vm->get_state() == VirtualMachine::BOOT_STOPPED ) { vm->set_state(VirtualMachine::RUNNING); @@ -587,8 +586,6 @@ void LifeCycleManager::prolog_failure_action(int vid) return; } - // TODO: done in branch bug-1210 - vm->set_prolog_etime(the_time); failure_action(vm);