# HG changeset patch # User David Scott # Date 1270118733 -3600 # Node ID 261d6bc80bba15972fb1d4410c2a72bf6dd28d4f # Parent 453a340d8fb0ebdf82af49b03dabd4ad0236fdab CA-38698: unify notions of HA "protected-ness". This should unblock (eg) attempts to make a best-effort VM non-agile by adding a local disk. Previously some of the code used ha_always_run = true while other parts of the code used ha_always_run = true && ha_restart_priority <> best-effort. Signed-off-by: David Scott diff -r 453a340d8fb0 -r 261d6bc80bba ocaml/xapi/helpers.ml --- a/ocaml/xapi/helpers.ml Thu Apr 01 11:43:39 2010 +0100 +++ b/ocaml/xapi/helpers.ml Thu Apr 01 11:45:33 2010 +0100 @@ -611,9 +611,14 @@ then bisect f mid upper else bisect f lower mid -(* Returns true if the specified VM is "protected" by xHA *) -let is_xha_protected ~__context ~self = Db.VM.get_ha_always_run ~__context ~self -let is_xha_protected_r record = record.API.vM_ha_always_run +(* All non best-effort VMs with always_run set should be kept running at all costs *) +let vm_should_always_run always_run restart_priority = + always_run && (restart_priority <> Constants.ha_restart_best_effort) + +(* Returns true if the specified VM is "protected" (non best-effort) by xHA *) +let is_xha_protected ~__context ~self = + vm_should_always_run (Db.VM.get_ha_always_run ~__context ~self) (Db.VM.get_ha_restart_priority ~__context ~self) +let is_xha_protected_r record = vm_should_always_run record.API.vM_ha_always_run record.API.vM_ha_restart_priority open Listext diff -r 453a340d8fb0 -r 261d6bc80bba ocaml/xapi/xapi_ha_vm_failover.ml --- a/ocaml/xapi/xapi_ha_vm_failover.ml Thu Apr 01 11:43:39 2010 +0100 +++ b/ocaml/xapi/xapi_ha_vm_failover.ml Thu Apr 01 11:45:33 2010 +0100 @@ -14,14 +14,10 @@ module D = Debug.Debugger(struct let name="xapi_ha_vm_failover" end) open D -(* All non best-effort VMs with always_run set should be kept running at all costs *) -let vm_should_always_run always_run restart_priority = - always_run && (restart_priority <> Constants.ha_restart_best_effort) - (* Return a list of (ref, record) pairs for all VMs which are marked as always_run *) let all_protected_vms ~__context = let vms = Db.VM.get_all_records ~__context in - List.filter (fun (_, vm_rec) -> vm_should_always_run vm_rec.API.vM_ha_always_run vm_rec.API.vM_ha_restart_priority) vms + List.filter (fun (_, vm_rec) -> Helpers.vm_should_always_run vm_rec.API.vM_ha_always_run vm_rec.API.vM_ha_restart_priority) vms (* Comparison function which can be used to sort a list of VM ref, record by restart_priority *) let by_restart_priority (vm_ref1,vm_rec1) (vm_ref2,vm_rec2) = diff -r 453a340d8fb0 -r 261d6bc80bba ocaml/xapi/xapi_ha_vm_failover.mli --- a/ocaml/xapi/xapi_ha_vm_failover.mli Thu Apr 01 11:43:39 2010 +0100 +++ b/ocaml/xapi/xapi_ha_vm_failover.mli Thu Apr 01 11:45:33 2010 +0100 @@ -15,9 +15,6 @@ * @group High Availability (HA) *) -(** True if the VM is set to always run *) -val vm_should_always_run : bool -> string -> bool - val all_protected_vms : __context:Context.t -> (API.ref_VM * API.vM_t) list (** Take a set of live VMs and attempt to restart all protected VMs which have failed *) diff -r 453a340d8fb0 -r 261d6bc80bba ocaml/xapi/xapi_host.ml --- a/ocaml/xapi/xapi_host.ml Thu Apr 01 11:43:39 2010 +0100 +++ b/ocaml/xapi/xapi_host.ml Thu Apr 01 11:45:33 2010 +0100 @@ -241,7 +241,7 @@ let pool = Helpers.get_pool ~__context in let protected_vms, unprotected_vms = if Db.Pool.get_ha_enabled ~__context ~self:pool - then List.partition (fun (vm, record) -> Xapi_ha_vm_failover.vm_should_always_run record.API.vM_ha_always_run record.API.vM_ha_restart_priority) all_user_vms + then List.partition (fun (vm, record) -> Helpers.vm_should_always_run record.API.vM_ha_always_run record.API.vM_ha_restart_priority) all_user_vms else all_user_vms, [] in List.iter (fun (vm, _) -> Hashtbl.replace plans vm (Error (Api_errors.host_not_enough_free_memory, [ Ref.string_of vm ]))) unprotected_vms; let migratable_vms, unmigratable_vms = List.partition (fun (vm, record) -> diff -r 453a340d8fb0 -r 261d6bc80bba ocaml/xapi/xapi_pool.ml --- a/ocaml/xapi/xapi_pool.ml Thu Apr 01 11:43:39 2010 +0100 +++ b/ocaml/xapi/xapi_pool.ml Thu Apr 01 11:45:33 2010 +0100 @@ -963,7 +963,7 @@ if not(List.mem pri valid_priorities) then raise (Api_errors.Server_error(Api_errors.invalid_value, [ "ha_restart_priority"; pri ]))) configuration; - let protected_vms = List.map fst (List.filter (fun (vm, priority) -> Xapi_ha_vm_failover.vm_should_always_run true priority) configuration) in + let protected_vms = List.map fst (List.filter (fun (vm, priority) -> Helpers.vm_should_always_run true priority) configuration) in let protected_vms = List.map (fun vm -> vm, Db.VM.get_record ~__context ~self:vm) protected_vms in Xapi_ha_vm_failover.compute_max_host_failures_to_tolerate ~__context ~protected_vms () diff -r 453a340d8fb0 -r 261d6bc80bba ocaml/xapi/xapi_vm.ml --- a/ocaml/xapi/xapi_vm.ml Thu Apr 01 11:43:39 2010 +0100 +++ b/ocaml/xapi/xapi_vm.ml Thu Apr 01 11:45:33 2010 +0100 @@ -189,7 +189,7 @@ let pool = Helpers.get_pool ~__context in let always_run = Db.VM.get_ha_always_run ~__context ~self:vm in let priority = Db.VM.get_ha_restart_priority ~__context ~self:vm in - if Db.Pool.get_ha_enabled ~__context ~self:pool && (Xapi_ha_vm_failover.vm_should_always_run always_run priority) + if Db.Pool.get_ha_enabled ~__context ~self:pool && (Helpers.vm_should_always_run always_run priority) then raise (Api_errors.Server_error(Api_errors.vm_is_protected, [ Ref.string_of vm ])) let pause_already_locked ~__context ~vm =