Skip to content

Commit 8b43206

Browse files
authored
xapi_vm_migrate: Fix reservations not being cleared on halted VMs (#6648)
Cross-pool migrations set `scheduled_to_be_resident_on` to the destination host, reserving memory and vGPUs. If the VM is still halted when migration is finished, the field is not cleared on the destination, preserving the reservations even though they're not necessarily going to be used anytime soon. Call `force_state_reset_keep_current_operations` in `pool_migrate_complete` on the destination to clear the reservations among other things at the end of the migration. This fixes an issue when VMs migrated across pools in a halted state would take up memory in xapi's view (but not in RRD's view), which is not intuitive and could prevent further migrations from claiming enough free memory on the host. --- I've tested this manually, confirming that migrating halted and running VMs works as designed, with the `scheduled_to_be_resident_on` field cleared at the end of the migration (in the first case it's because of the fix, in the second one it's because the VM is actually started on the host)
2 parents 6c16a2f + afe8e1b commit 8b43206

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ let pool_migrate_complete ~__context ~vm ~host:_ =
489489
~value:`restart_device_model ;
490490
let dbg = Context.string_of_task __context in
491491
let queue_name = Xapi_xenops_queue.queue_of_vm ~__context ~self:vm in
492+
(* Reset the state, which will update allowed operations, clear reservations
493+
for halted VMs, disconnect devices *)
494+
let power_state = Db.VM.get_power_state ~__context ~self:vm in
495+
Xapi_vm_lifecycle.force_state_reset_keep_current_operations ~__context
496+
~self:vm ~value:power_state ;
492497
if Xapi_xenops.vm_exists_in_xenopsd queue_name dbg id then (
493498
remove_stale_pcis ~__context ~vm ;
494499
Xapi_xenops.set_resident_on ~__context ~self:vm ;

0 commit comments

Comments
 (0)