Skip to content

Commit d27a118

Browse files
authored
CA-411319: Concurrent VM.assert_can_migrate failure (#6476)
When the customers open "Migrate VM Wizard" on XenCenter, XenCenter will call `VM.assert_can_migrate` to check each host in each pool connected to XenCenter if the VM can be migrated to it. The API `VM.assert_can_migrate` then calls `VM.export_metadata`. `VM.export_metadata` will lock VM. During this time, other `VM.export_metadata` requests will fail as they can't get VM lock. The solution is to add retry when failing to lock VM.
2 parents 4f2f185 + fadf706 commit d27a118

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ocaml/xapi/export.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,15 @@ open Http
713713
open Client
714714

715715
let lock_vm ~__context ~vm ~task_id op =
716-
(* Note slight race here because we haven't got the master lock *)
717-
Xapi_vm_lifecycle.assert_operation_valid ~__context ~self:vm ~op ~strict:true ;
718-
(* ... small race lives here ... *)
719-
Db.VM.add_to_current_operations ~__context ~self:vm ~key:task_id ~value:op ;
720-
Xapi_vm_lifecycle.update_allowed_operations ~__context ~self:vm
716+
Helpers.retry ~__context ~doc:task_id ~policy:Helpers.Policy.fail_quickly
717+
(fun () ->
718+
(* Note slight race here because we haven't got the master lock *)
719+
Xapi_vm_lifecycle.assert_operation_valid ~__context ~self:vm ~op
720+
~strict:true ;
721+
(* ... small race lives here ... *)
722+
Db.VM.add_to_current_operations ~__context ~self:vm ~key:task_id ~value:op ;
723+
Xapi_vm_lifecycle.update_allowed_operations ~__context ~self:vm
724+
)
721725

722726
let unlock_vm ~__context ~vm ~task_id =
723727
Db.VM.remove_from_current_operations ~__context ~self:vm ~key:task_id ;

0 commit comments

Comments
 (0)