From e22b5cfcb5e06ad101fc7fc668997d8b5b375362 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Tue, 12 Oct 2010 11:59:05 +0100 Subject: [PATCH] Worked around a race condition in vm-uninstall. VM.hard_shutdown now checks for an exception that signals an invalid power state, i.e. if the VM is already halted. See the Jira-ticket CA-44120 for more details. Signed-off-by: Matthias Goergens --- ocaml/xapi/xapi_vm.ml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ocaml/xapi/xapi_vm.ml b/ocaml/xapi/xapi_vm.ml index e8829875..19b800a6 100644 --- a/ocaml/xapi/xapi_vm.ml +++ b/ocaml/xapi/xapi_vm.ml @@ -623,10 +623,21 @@ let hard_reboot ~__context ~vm = (** VM.hard_shutdown entrypoint *) let hard_shutdown ~__context ~vm = - let action = Db.VM.get_actions_after_shutdown ~__context ~self:vm in - record_shutdown_details ~__context ~vm Xal.Halted "external" action; - let args = { TwoPhase.__context=__context; vm=vm; api_call_name="VM.hard_shutdown"; clean=false } in - retry_on_conflict args (of_action action) + try + let action = Db.VM.get_actions_after_shutdown ~__context ~self:vm in + record_shutdown_details ~__context ~vm Xal.Halted "external" action; + let args = { TwoPhase.__context=__context; vm=vm; api_call_name="VM.hard_shutdown"; clean=false } in + retry_on_conflict args (of_action action) + with + | Api_errors.Server_error(code, _) as e + when code = Api_errors.vm_bad_power_state -> + (* ToDo: How do you test directly if the VM is already shut-down? + I hope we are not masking bugs here. + *) + debug ("hard_shutdown: VM_BAD_POWER_STATE raised, and caught. Probably it was already halted.") + | e -> + (debug ("hard_shutdown: caught any exception besides VM_BAD_POWER_STATE, re-raising."); + raise e) (** VM.clean_reboot entrypoint *) let clean_reboot ~__context ~vm = -- 2.39.5