@@ -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. *)
501512let 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
0 commit comments