Skip to content

Commit fc73538

Browse files
author
Konstantina Chremmou
committed
CA-233580: allow control domains to start on disabled hosts.
Also: allow operation start_on for control domains; ensure that a control domain won't start on a host different from its affinity. Signed-off-by: Konstantina Chremmou <[email protected]>
1 parent 445c124 commit fc73538

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

ocaml/xapi/message_forwarding.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
12101210
if Helpers.rolling_upgrade_in_progress ~__context
12111211
then Helpers.assert_host_has_highest_version_in_pool
12121212
~__context ~host ;
1213+
Xapi_vm_helpers.assert_matches_control_domain_affinity ~__context ~self:vm ~host;
12131214
(* Prevent VM start on a host that is evacuating *)
12141215
List.iter (fun op ->
12151216
match op with

ocaml/xapi/xapi_vm_helpers.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ let assert_enough_memory_available ~__context ~self ~host ~snapshot =
361361
Int64.to_string host_mem_available;
362362
]))
363363

364+
(* CA-233580: prevent starting a control domain on a host different from its affinity*)
365+
let assert_matches_control_domain_affinity ~__context ~self ~host =
366+
if Db.VM.get_is_control_domain ~__context ~self then
367+
match Db.VM.get_affinity ~__context ~self with
368+
| x when x = Ref.null || x = host -> ()
369+
| _ -> raise (Api_errors.Server_error (Api_errors.operation_not_allowed,
370+
["Cannot boot a control domain on a host different from its affinity"]))
371+
364372
(** Checks to see if a VM can boot on a particular host, throws an error if not.
365373
* Criteria:
366374
- The host must support the VM's required Virtual Hardware Platform version.
@@ -387,7 +395,10 @@ let assert_can_boot_here ~__context ~self ~host ~snapshot ?(do_sr_check=true) ?(
387395
debug "Checking whether VM %s can run on host %s" (Ref.string_of self) (Ref.string_of host);
388396
validate_basic_parameters ~__context ~self ~snapshot;
389397
assert_host_is_live ~__context ~host;
390-
assert_host_is_enabled ~__context ~host;
398+
assert_matches_control_domain_affinity ~__context ~self ~host;
399+
(* CA-233580: allow control domains to start on the host even if the latter is disabled *)
400+
if not (Db.VM.get_is_control_domain ~__context ~self) then
401+
assert_host_is_enabled ~__context ~host;
391402
(* Check the host can support the VM's required version of virtual hardware platform *)
392403
assert_hardware_platform_support ~__context ~vm:self ~host:(Helpers.LocalObject host);
393404
if do_sr_check then
@@ -499,6 +510,7 @@ let get_possible_hosts_for_vm ~__context ~vm ~snapshot =
499510
given [guest] can run on the given [host]. Returns true if and only if the
500511
guest can run on the host. *)
501512
let vm_can_run_on_host ~__context ~vm ~snapshot ~do_memory_check host =
513+
let is_control_domain = Db.VM.get_is_control_domain ~__context ~self:vm in
502514
let host_has_proper_version () =
503515
if Helpers.rolling_upgrade_in_progress ~__context
504516
then
@@ -516,7 +528,9 @@ let vm_can_run_on_host ~__context ~vm ~snapshot ~do_memory_check host =
516528
let host_evacuate_in_progress =
517529
try let _ = List.find (fun s -> snd s = `evacuate) (Db.Host.get_current_operations ~__context ~self:host) in false with _ -> true
518530
in
519-
try host_has_proper_version () && host_enabled () && host_live () && host_can_run_vm () && host_evacuate_in_progress
531+
try host_has_proper_version ()
532+
&& (is_control_domain || host_enabled ()) (*CA-233580: allow control domains to start on a disabled host*)
533+
&& host_live () && host_can_run_vm () && host_evacuate_in_progress
520534
with _ -> false
521535

522536

ocaml/xapi/xapi_vm_lifecycle.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ let check_operation_error ~__context ~vmr ~vmgmr ~ref ~clone_suspended_vm_enable
398398
&& op <> `changing_memory_limits
399399
&& op <> `changing_static_range
400400
&& op <> `start
401+
&& op <> `start_on
401402
&& op <> `changing_VCPUs
402403
&& op <> `destroy
403404
then Some (Api_errors.operation_not_allowed, ["This operation is not allowed on a control domain"])

0 commit comments

Comments
 (0)