Skip to content

Commit 3163abc

Browse files
committed
CP-18860 re-factor is_mobile() into nomigrate() and nested_virt()
We want to create more predicates over the value of nomigrate and nested_virt without duplicating code. By exposing nomigrate and nested_virt this now becomes possible. Unit tests show that the semantics of is_mobile are unchanged. Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
1 parent 15ab3b9 commit 3163abc

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

ocaml/xapi/xapi_vm_lifecycle.ml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,28 @@ let check_protection_policy ~vmr ~op ~ref_str =
279279
* If the VM_metrics object does not exist, it implies the VM is not
280280
* running - in which case we use the current values from the database.
281281
**)
282-
let is_mobile ~__context vm strict =
283-
let metrics = Db.VM.get_metrics ~__context ~self:vm in
282+
283+
let nomigrate ~__context vm metrics =
284284
try
285-
let nomigrate = Db.VM_metrics.get_nomigrate ~__context ~self:metrics in
286-
let nested_virt = Db.VM_metrics.get_nested_virt ~__context ~self:metrics in
287-
(not nomigrate && not nested_virt) || not strict
285+
Db.VM_metrics.get_nomigrate ~__context ~self:metrics
288286
with _ ->
289-
(* No VM_metrics *)
290-
let not_true platformdata key =
291-
not @@ Vm_platform.is_true ~key ~platformdata ~default:false in
292-
let platform = Db.VM.get_platform ~__context ~self:vm in
293-
(not_true platform "nomigrate" && not_true platform "nested-virt") || not strict
287+
let platformdata = Db.VM.get_platform ~__context ~self:vm in
288+
let key = "nomigrate" in
289+
Vm_platform.is_true ~key ~platformdata ~default:false
290+
291+
let nested_virt ~__context vm metrics =
292+
try
293+
Db.VM_metrics.get_nested_virt ~__context ~self:metrics
294+
with _ ->
295+
let platformdata = Db.VM.get_platform ~__context ~self:vm in
296+
let key = "nested-virt" in
297+
Vm_platform.is_true ~key ~platformdata ~default:false
298+
299+
let is_mobile ~__context vm strict =
300+
let metrics = Db.VM.get_metrics ~__context ~self:vm in
301+
(not @@ nomigrate ~__context vm metrics
302+
&& not @@ nested_virt ~__context vm metrics)
303+
|| not strict
294304

295305

296306
(** Take an internal VM record and a proposed operation. Return None iff the operation
@@ -361,6 +371,18 @@ let check_operation_error ~__context ~vmr ~vmgmr ~ref ~clone_suspended_vm_enable
361371
| _ -> None
362372
) in
363373

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+
364386
(* Check if the VM is a control domain (eg domain 0). *)
365387
(* FIXME: Instead of special-casing for the control domain here, *)
366388
(* make use of the Helpers.ballooning_enabled_for_vm function. *)

0 commit comments

Comments
 (0)