]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Worked around a race condition in vm-uninstall.
authorMatthias Goergens <matthias.goergens@citrix.com>
Tue, 12 Oct 2010 10:59:05 +0000 (11:59 +0100)
committerMatthias Goergens <matthias.goergens@citrix.com>
Tue, 12 Oct 2010 10:59:05 +0000 (11:59 +0100)
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 <matthias.goergens@citrix.com>
ocaml/xapi/xapi_vm.ml

index e8829875c5f467088aa9c60cd4a60f9d750de54a..19b800a6e291b38f8d2c080cdef5672f34f8825c 100644 (file)
@@ -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 =