Skip to content

Commit f81d86b

Browse files
committed
CP-18860 check memory range before VM.start when using nested virt
When using nested_virtualisation, the VM cannot use a dynamic memory range. We can detect this only before the VM starts and not when the memory is set because there many path can lead to this situation: (1) set memory range (ok), set nested_virt - now illegal (2) set nested_virt (ok), set memory range - now illegal Hence, we accept that nested virt and memory range can be in an inconsistent state temporarily but check before the VM is started. Signed-off-by: Christian Lindig <christian.lindig@citrix.com> CP-18860 use xapi_vm_memory_constraints This commits changes the implementation to use the xapi_vm_memory_constraints module to check memory constraints when a VM uses nested_virt. Previously a new error message and custom check was used. Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
1 parent 3163abc commit f81d86b

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

ocaml/idl/datamodel.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ let _ =
511511
~doc:"You attempted an operation which would have resulted in duplicate keys in the database." ();
512512
error Api_errors.location_not_unique ["SR"; "location"]
513513
~doc:"A VDI with the specified location already exists within the SR" ();
514+
error Api_errors.memory_constraint_violation ["constraint"]
515+
~doc:"The dynamic memory range does not satisfy the following constraint." ();
514516

515517
(* Session errors *)
516518
error Api_errors.session_authentication_failed []

ocaml/xapi/xapi_vm_lifecycle.ml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -371,18 +371,6 @@ let check_operation_error ~__context ~vmr ~vmgmr ~ref ~clone_suspended_vm_enable
371371
| _ -> None
372372
) in
373373

374-
(* CP-18860: can't set dynamic mem range when using nested virt *)
375-
let current_error = check current_error (fun () ->
376-
match op with
377-
| `changing_dynamic_range ->
378-
let metrics = Db.VM.get_metrics ~__context ~self:ref in
379-
if nested_virt ~__context ref metrics then
380-
Some (Api_errors.vm_cant_use_dyn_memory, [ref_str])
381-
else
382-
None
383-
| _ -> None
384-
) in
385-
386374
(* Check if the VM is a control domain (eg domain 0). *)
387375
(* FIXME: Instead of special-casing for the control domain here, *)
388376
(* make use of the Helpers.ballooning_enabled_for_vm function. *)

ocaml/xapi/xapi_vm_memory_constraints.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,22 @@ module Vm_memory_constraints : T = struct
5151

5252
include Vm_memory_constraints.Vm_memory_constraints
5353

54+
let order_constraint =
55+
"Memory limits must satisfy: \
56+
static_min ≤ dynamic_min ≤ dynamic_max ≤ static_max"
57+
let equality_constraint =
58+
"Memory limits must satisfy: \
59+
static_min ≤ dynamic_min = dynamic_max = static_max"
60+
5461
let assert_valid ~constraints =
5562
if not (are_valid ~constraints)
5663
then raise (Api_errors.Server_error (
57-
Api_errors.memory_constraint_violation,
58-
["Memory limits must satisfy: \
59-
static_min ≤ dynamic_min ≤ dynamic_max ≤ static_max"]))
64+
Api_errors.memory_constraint_violation, [order_constraint]))
6065

6166
let assert_valid_and_pinned_at_static_max ~constraints =
6267
if not (are_valid_and_pinned_at_static_max ~constraints)
6368
then raise (Api_errors.Server_error (
64-
Api_errors.memory_constraint_violation,
65-
["Memory limits must satisfy: \
66-
static_min ≤ dynamic_min = dynamic_max = static_max"]))
69+
Api_errors.memory_constraint_violation, [equality_constraint]))
6770

6871
let assert_valid_for_current_context ~__context ~vm ~constraints =
6972
let is_control_domain = Db.VM.get_is_control_domain ~__context ~self:vm in

ocaml/xapi/xapi_xenops.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,16 @@ module MD = struct
708708
(* CA-55754: temporarily disable msitranslate when GPU is passed through. *)
709709
let pci_msitranslate =
710710
if vm.API.vM_VGPUs <> [] then false else pci_msitranslate in
711+
712+
(* CP-18860: check memory limits if using nested_virt *)
713+
if Vm_platform.is_true ~key:"nested-virt" ~platformdata ~default:false
714+
then
715+
begin
716+
let module C = Xapi_vm_memory_constraints.Vm_memory_constraints in
717+
let c = C.get ~__context ~vm_ref:vmref in
718+
C.assert_valid_and_pinned_at_static_max c
719+
end;
720+
711721
{
712722
id = vm.API.vM_uuid;
713723
name = vm.API.vM_name_label;

0 commit comments

Comments
 (0)