Skip to content

Commit 61f90f1

Browse files
committed
CA-226028 support vm-start --force for memory limits under nested-virt
This commit moves the memory limit check into VM.start where it can be overridden using --force. Signed-off-by: Christian Lindig <[email protected]>
1 parent 79bc6b3 commit 61f90f1

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

ocaml/xapi/xapi_vm.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ let unpause ~__context ~vm =
221221
let set_xenstore_data ~__context ~self ~value =
222222
Xapi_xenops.set_xenstore_data ~__context ~self value
223223

224+
(* CP-18860: check memory limits if using nested_virt on start *)
225+
let assert_memory_constraints ~__context ~vm platformdata =
226+
if Vm_platform.is_true ~key:"nested-virt" ~platformdata ~default:false
227+
then
228+
begin
229+
let module C = Xapi_vm_memory_constraints.Vm_memory_constraints in
230+
let c = C.get ~__context ~vm_ref:vm in
231+
C.assert_valid_and_pinned_at_static_max c
232+
end
233+
224234
(* Note: it is important that we use the pool-internal API call, VM.atomic_set_resident_on, to set resident_on and clear
225235
scheduled_to_be_resident_on atomically. This prevents concurrent API calls on the master from accounting for the
226236
same VM twice during memory calculations to determine whether a given VM can start on a particular host..
@@ -234,6 +244,9 @@ let start ~__context ~vm ~start_paused ~force =
234244
debug "Setting ha_always_run on vm=%s as true during VM.start" (Ref.string_of vm)
235245
end;
236246

247+
if not force then
248+
assert_memory_constraints ~__context ~vm vmr.API.vM_platform;
249+
237250
(* Check to see if we're using any restricted platform kvs. This raises
238251
an exception if so *)
239252
Vm_platform.check_restricted_flags ~__context vmr.API.vM_platform;

ocaml/xapi/xapi_xenops.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,6 @@ module MD = struct
735735
let pci_msitranslate =
736736
if vm.API.vM_VGPUs <> [] then false else pci_msitranslate in
737737

738-
(* CP-18860: check memory limits if using nested_virt *)
739-
if Vm_platform.is_true ~key:"nested-virt" ~platformdata ~default:false
740-
then
741-
begin
742-
let module C = Xapi_vm_memory_constraints.Vm_memory_constraints in
743-
let c = C.get ~__context ~vm_ref:vmref in
744-
C.assert_valid_and_pinned_at_static_max c
745-
end;
746-
747738
{
748739
id = vm.API.vM_uuid;
749740
name = vm.API.vM_name_label;

0 commit comments

Comments
 (0)