From ee9d5e3c684eaee2396128707020c441f9f8ca06 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 23 Jul 2026 23:32:22 +0200 Subject: [PATCH] M #-: Fix host capacity accounting for datastore-only migrations Only add or remove host capacity during migrations when the VM changes hosts. Datastore-only migrations keep the existing host allocation, to prevent removing the VM from the host VM collection. (cherry picked from commit 23aba3ee8144c420d6b29bc15e99c560336fed0e) --- src/lcm/LifeCycleActions.cc | 24 ++++++++++++++++++------ src/lcm/LifeCycleStates.cc | 5 ++++- src/rm/api/VirtualMachineAPI.cc | 3 ++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 615c4b8cb3..7f6d8824b6 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -272,7 +272,10 @@ void LifeCycleManager::trigger_migrate(int vid, const RequestAttributes& ra, vm->get_capacity(sr); - hpool->add_capacity(vm->get_hid(), sr); + if ( vm->get_hid() != vm->get_previous_hid() ) + { + hpool->add_capacity(vm->get_hid(), sr); + } vm->set_stime(the_time); @@ -346,10 +349,10 @@ void LifeCycleManager::trigger_migrate(int vid, const RequestAttributes& ra, vm->get_capacity(sr); - hpool->add_capacity(vm->get_hid(), sr); - if ( vm->get_hid() != vm->get_previous_hid() ) { + hpool->add_capacity(vm->get_hid(), sr); + hpool->del_capacity(vm->get_previous_hid(), sr); vm->release_previous_vnc_port(); @@ -418,7 +421,10 @@ void LifeCycleManager::trigger_live_migrate(int vid, const RequestAttributes& ra vm->get_capacity(sr); - hpool->add_capacity(vm->get_hid(), sr); + if ( vm->get_hid() != vm->get_previous_hid() ) + { + hpool->add_capacity(vm->get_hid(), sr); + } vm->set_stime(time(0)); @@ -1254,7 +1260,10 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose, vm->set_previous_vm_info(); vm->set_previous_running_etime(the_time); - hpool->del_capacity(vm->get_previous_hid(), sr); + if ( vm->get_hid() != vm->get_previous_hid() ) + { + hpool->del_capacity(vm->get_previous_hid(), sr); + } vmpool->update_previous_history(vm); @@ -1277,7 +1286,10 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose, vm->set_previous_vm_info(); vm->set_previous_running_etime(the_time); - hpool->del_capacity(vm->get_previous_hid(), sr); + if ( vm->get_hid() != vm->get_previous_hid() ) + { + hpool->del_capacity(vm->get_previous_hid(), sr); + } vmpool->update_previous_history(vm); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 0c91decc47..26139755ea 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -334,7 +334,10 @@ void LifeCycleManager::trigger_deploy_success(int vid) vm->get_capacity(sr); - hpool->del_capacity(vm->get_previous_hid(), sr); + if ( vm->get_hid() != vm->get_previous_hid() ) + { + hpool->del_capacity(vm->get_previous_hid(), sr); + } vm->set_state(VirtualMachine::RUNNING); diff --git a/src/rm/api/VirtualMachineAPI.cc b/src/rm/api/VirtualMachineAPI.cc index 3eb1f723aa..cbe33a86d2 100644 --- a/src/rm/api/VirtualMachineAPI.cc +++ b/src/rm/api/VirtualMachineAPI.cc @@ -1009,7 +1009,8 @@ Request::ErrorCode VirtualMachineAPI::migrate(int vid, } // Check the host has enough capacity - if (check_host(hid, enforce, vm.get(), att.resp_msg) == false) + if (c_hid != hid && + check_host(hid, enforce, vm.get(), att.resp_msg) == false) { return Request::ACTION; }