From 7c123fb75debf2a212411396cb09730cd7f267bf Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 9 May 2020 00:37:43 +0200 Subject: [PATCH] B #1662: Do not end poweroff/suspend records --- src/dm/DispatchManagerActions.cc | 269 ++++++++----------------------- src/lcm/LifeCycleStates.cc | 46 ++---- 2 files changed, 83 insertions(+), 232 deletions(-) diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 04c9b585ce..56cb08909e 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -1311,6 +1311,34 @@ int DispatchManager::delete_vm_db(VirtualMachine * vm, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +static void close_cp_history(VirtualMachinePool *vmpool, VirtualMachine *vm, + VMActions::Action action, const RequestAttributes& ra) +{ + time_t the_time = time(0); + + vm->set_running_etime(the_time); + + vm->set_etime(the_time); + + VMActions::Action current = vm->get_action(); + + vm->set_action(action, ra.uid, ra.gid, ra.req_id); + + vmpool->update_history(vm); + + vm->cp_history(); + + vm->set_internal_action(current); + + vm->set_stime(the_time); + + vm->set_running_stime(the_time); + + vmpool->insert_history(vm); +} + +/* -------------------------------------------------------------------------- */ + int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl, const RequestAttributes& ra, string & err) { @@ -1373,32 +1401,10 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl, return -1; } + close_cp_history(vmpool, vm, VMActions::DISK_ATTACH_ACTION, ra); + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ) { - time_t the_time = time(0); - - // Close current history record - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - vm->set_action(VMActions::DISK_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id); - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); - - //----------------------------------------------- - vmm->trigger(VMMAction::ATTACH, vid); } else @@ -1460,35 +1466,11 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra, vm->set_resched(false); + close_cp_history(vmpool, vm, VMActions::DISK_DETACH_ACTION, ra); + if ( vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING ) { - time_t the_time = time(0); - - // Close current history record - - vm->set_vm_info(); - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - vm->set_action(VMActions::DISK_DETACH_ACTION, ra.uid, ra.gid, ra.req_id); - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); - - //--------------------------------------------------- - vm->set_state(VirtualMachine::HOTPLUG); vmm->trigger(VMMAction::DETACH, vid); @@ -1758,39 +1740,21 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl, return -1; } + VMActions::Action action; + + if ( tmpl->get("NIC") != 0 ) + { + action = VMActions::NIC_ATTACH_ACTION; + } + else + { + action = VMActions::ALIAS_ATTACH_ACTION; + } + + close_cp_history(vmpool, vm, action, ra); + if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC) { - time_t the_time = time(0); - - // Close current history record - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - if ( tmpl->get("NIC") != 0 ) - { - vm->set_action(VMActions::NIC_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id); - } - else - { - vm->set_action(VMActions::ALIAS_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id); - } - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); - - //----------------------------------------------- - vmm->trigger(VMMAction::ATTACH_NIC, vid); } else @@ -1853,47 +1817,23 @@ int DispatchManager::detach_nic(int vid, int nic_id, const RequestAttributes& ra return -1; } - bool cold_attach = false; + VMActions::Action action; - if ( vm->hasHistory() ) + if ( !vm->get_nic(nic_id)->is_alias() ) { - cold_attach = vmm->is_cold_nic_attach(vm->get_vmm_mad()); + action = VMActions::NIC_DETACH_ACTION; + } + else + { + action = VMActions::ALIAS_DETACH_ACTION; } - if ((vm->get_state() == VirtualMachine::ACTIVE && - vm->get_lcm_state() == VirtualMachine::RUNNING ) || cold_attach) + close_cp_history(vmpool, vm, action, ra); + + if ((vm->get_state() == VirtualMachine::ACTIVE && + vm->get_lcm_state() == VirtualMachine::RUNNING ) || + vmm->is_cold_nic_attach(vm->get_vmm_mad())) { - time_t the_time = time(0); - - // Close current history record - - vm->set_vm_info(); - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - if ( !vm->get_nic(nic_id)->is_alias() ) - { - vm->set_action(VMActions::NIC_DETACH_ACTION, ra.uid, ra.gid, ra.req_id); - } - else - { - vm->set_action(VMActions::ALIAS_DETACH_ACTION, ra.uid, ra.gid, ra.req_id); - } - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); - vm->set_state(VirtualMachine::HOTPLUG_NIC); vm->set_resched(false); @@ -1902,8 +1842,6 @@ int DispatchManager::detach_nic(int vid, int nic_id, const RequestAttributes& ra vm->unlock(); - //--------------------------------------------------- - vmm->trigger(VMMAction::DETACH_NIC, vid); } else @@ -1929,7 +1867,6 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, int& snap_id, const RequestAttributes& ra, string& error_str) { ostringstream oss; - time_t the_time; VirtualMachine * vm = vmpool->get(vid); @@ -1993,6 +1930,8 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, default: break; } + close_cp_history(vmpool, vm, VMActions::DISK_SNAPSHOT_CREATE_ACTION, ra); + switch (state) { case VirtualMachine::POWEROFF: @@ -2001,28 +1940,6 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, break; case VirtualMachine::ACTIVE: - the_time = time(0); - - // Close current history record - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - vm->set_action(VMActions::DISK_SNAPSHOT_CREATE_ACTION, ra.uid, ra.gid, - ra.req_id); - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); vmm->trigger(VMMAction::DISK_SNAPSHOT_CREATE, vid); break; @@ -2094,6 +2011,8 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, return -1; } + close_cp_history(vmpool, vm, VMActions::DISK_SNAPSHOT_REVERT_ACTION, ra); + switch (state) { case VirtualMachine::POWEROFF: @@ -2124,13 +2043,13 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, const RequestAttributes& ra, string& error_str) { - ostringstream oss; - time_t the_time; VirtualMachine * vm = vmpool->get(vid); if ( vm == nullptr ) { + ostringstream oss; + oss << "Could not delete disk snapshot from VM " << vid << ", VM does not exist"; error_str = oss.str(); @@ -2147,6 +2066,8 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, (state !=VirtualMachine::SUSPENDED|| lstate !=VirtualMachine::LCM_INIT)&& (state !=VirtualMachine::ACTIVE || lstate !=VirtualMachine::RUNNING)) { + ostringstream oss; + oss << "Could not delete disk snapshot from VM " << vid << ", wrong state " << vm->state_str() << "."; error_str = oss.str(); @@ -2200,39 +2121,9 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, default: break; } - switch (state) - { - case VirtualMachine::ACTIVE: - the_time = time(0); + close_cp_history(vmpool, vm, VMActions::DISK_SNAPSHOT_DELETE_ACTION, ra); - // Close current history record - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - vm->set_action(VMActions::DISK_SNAPSHOT_DELETE_ACTION, ra.uid, ra.gid, - ra.req_id); - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); - - case VirtualMachine::POWEROFF: - case VirtualMachine::SUSPENDED: - tm->trigger(TMAction::SNAPSHOT_DELETE, vid); - break; - - default: break; - } + tm->trigger(TMAction::SNAPSHOT_DELETE, vid); vmpool->update(vm); @@ -2248,7 +2139,6 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, const RequestAttributes& ra, string& error_str) { ostringstream oss; - time_t the_time; VirtualMachine * vm = vmpool->get(vid); @@ -2310,6 +2200,8 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, default: break; } + close_cp_history(vmpool, vm, VMActions::DISK_RESIZE_ACTION, ra); + switch (state) { case VirtualMachine::POWEROFF: @@ -2318,29 +2210,6 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, break; case VirtualMachine::ACTIVE: - the_time = time(0); - - // Close current history record - - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - - vm->set_action(VMActions::DISK_RESIZE_ACTION, ra.uid, ra.gid, - ra.req_id); - - vmpool->update_history(vm); - - // Open a new history record - - vm->cp_history(); - - vm->set_stime(the_time); - - vm->set_running_stime(the_time); - - vmpool->insert_history(vm); - vmm->trigger(VMMAction::DISK_RESIZE, vid); break; diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 99cf575598..e167dfaf28 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -137,8 +137,6 @@ void LifeCycleManager::save_success_action(int vid) } else if (vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND) { - time_t the_time = time(0); - //---------------------------------------------------- // SUSPENDED STATE //---------------------------------------------------- @@ -150,10 +148,6 @@ void LifeCycleManager::save_success_action(int vid) vm->reset_info(); - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - vm->set_vm_info(); vmpool->update_history(vm); @@ -306,6 +300,16 @@ void LifeCycleManager::deploy_success_action(int vid) vm->get_lcm_state() == VirtualMachine::BOOT_UNDEPLOY_FAILURE || vm->get_lcm_state() == VirtualMachine::BOOT_FAILURE ) { + if ( vm->get_lcm_state() == VirtualMachine::BOOT_SUSPENDED || + vm->get_lcm_state() == VirtualMachine::BOOT_POWEROFF ) + { + vm->set_previous_etime(time(0)); + + vm->set_previous_running_etime(time(0)); + + vmpool->update_previous_history(vm); + } + vm->set_state(VirtualMachine::RUNNING); vm->clear_action(); @@ -337,8 +341,6 @@ void LifeCycleManager::deploy_failure_action(int vid) return; } - time_t the_time = time(0); - if ( vm->get_lcm_state() == VirtualMachine::MIGRATE ) { HostShareCapacity sr; @@ -404,24 +406,16 @@ void LifeCycleManager::deploy_failure_action(int vid) } else if (vm->get_lcm_state() == VirtualMachine::BOOT_POWEROFF) { - vm->set_etime(the_time); - vm->set_running_etime(the_time); - vm->set_state(VirtualMachine::POWEROFF); vm->set_state(VirtualMachine::LCM_INIT); - vmpool->update_history(vm); vmpool->update(vm); } else if (vm->get_lcm_state() == VirtualMachine::BOOT_SUSPENDED) { - vm->set_etime(the_time); - vm->set_running_etime(the_time); - vm->set_state(VirtualMachine::SUSPENDED); vm->set_state(VirtualMachine::LCM_INIT); - vmpool->update_history(vm); vmpool->update(vm); } else if (vm->get_lcm_state() == VirtualMachine::BOOT_STOPPED) @@ -504,8 +498,6 @@ void LifeCycleManager::shutdown_success_action(int vid) vm->set_running_etime(the_time); - vm->set_etime(the_time); - vm->set_vm_info(); vmpool->update_history(vm); @@ -700,8 +692,6 @@ void LifeCycleManager::prolog_success_action(int vid) vm->reset_info(); - vm->set_etime(the_time); - vm->set_prolog_etime(the_time); vm->set_vm_info(); @@ -1043,8 +1033,6 @@ void LifeCycleManager::monitor_suspend_action(int vid) { VirtualMachine * vm; - time_t the_time = time(0); - vm = vmpool->get(vid); if ( vm == nullptr ) @@ -1072,10 +1060,6 @@ void LifeCycleManager::monitor_suspend_action(int vid) vm->reset_info(); - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - vm->set_vm_info(); vm->set_internal_action(VMActions::MONITOR_ACTION); @@ -1152,8 +1136,6 @@ void LifeCycleManager::monitor_poweroff_action(int vid) vm->log("LCM",Log::INFO,"VM running but monitor state is POWEROFF"); - time_t the_time = time(0); - if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) ) { vm->delete_snapshots(); @@ -1165,10 +1147,6 @@ void LifeCycleManager::monitor_poweroff_action(int vid) vm->set_state(VirtualMachine::SHUTDOWN_POWEROFF); - vm->set_running_etime(the_time); - - vm->set_etime(the_time); - vm->set_vm_info(); vm->set_internal_action(VMActions::MONITOR_ACTION); @@ -1219,6 +1197,10 @@ void LifeCycleManager::monitor_poweron_action(int vid) vm->set_state(VirtualMachine::RUNNING); + vm->set_etime(the_time); + + vmpool->update_history(vm); + vm->cp_history(); vm->set_stime(the_time);