Skip to content

Commit 50bb4c8

Browse files
authored
Merge pull request #282 from lindig/CP-18289
CP-18289 add booleans to VM state: nomigrate, nested_virt
2 parents 6317b6f + 10e4264 commit 50bb4c8

File tree

5 files changed

+150
-2
lines changed

5 files changed

+150
-2
lines changed

lib/platform.ml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(*
2+
* Copyright (C) Citrix Systems Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published
6+
* by the Free Software Foundation; version 2.1 only. with the special
7+
* exception on linking described in file LICENSE.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*)
14+
15+
16+
type platformdata = (string * string) list
17+
18+
let is_valid ~key ~platformdata =
19+
(not (List.mem_assoc key platformdata)) ||
20+
(match List.assoc key platformdata |> String.lowercase with
21+
| "true" | "1" | "false" | "0" -> true
22+
| v -> false
23+
)
24+
25+
let is_true ~key ~platformdata ~default =
26+
try
27+
match List.assoc key platformdata |> String.lowercase with
28+
| "true" | "1" -> true
29+
| "false" | "0" -> false
30+
| _ -> default (* Check for validity using is_valid if required *)
31+
with Not_found ->
32+
default
33+
34+

lib/platform.mli

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(*
2+
* Copyright (C) Citrix Systems Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published
6+
* by the Free Software Foundation; version 2.1 only. with the special
7+
* exception on linking described in file LICENSE.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*)
14+
15+
(* This module defines interpretation of boolean platform values. It
16+
* matches the interpretation implemented in XenAPI for these values.
17+
*)
18+
19+
type platformdata = (string * string) list
20+
21+
(** [is_valid key platformdata] returns true if:
22+
* 1. The key is _not_ in platformdata (absence of key is valid) or
23+
* 2. The key is in platformdata, associated with a booleanish value *)
24+
val is_valid: key:string -> platformdata:platformdata -> bool
25+
26+
(** [is_true key platformdata default] returns true, if the platformdata
27+
* contains a value for key that is "true" or "1". It returns false, if
28+
* a value "0" or "false" exists. If the key doesn't exist or contains
29+
* none of the values above, [default] is returned.
30+
*)
31+
val is_true:
32+
key:string ->
33+
platformdata:platformdata ->
34+
default:bool ->
35+
bool
36+

lib/xenops_utils.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ let halted_vm = {
548548
last_start_time = 0.;
549549
shadow_multiplier_target = 1.;
550550
hvm = false;
551+
nomigrate=false;
552+
nested_virt=false;
551553
}
552554

553555
let unplugged_pci = {

xc/xenops_server_xen.ml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,25 @@ module VmExtra = struct
8484
build_info: Domain.build_info option;
8585
ty: Vm.builder_info option;
8686
last_start_time: float;
87+
nomigrate: bool; (* platform:nomigrate at boot time *)
88+
nested_virt: bool (* platform:nested_virt at boot time *)
8789
} with rpc
8890

91+
let default_persistent_t =
92+
{ build_info = None
93+
; ty = None
94+
; last_start_time = 0.0
95+
; nomigrate = false
96+
; nested_virt = false
97+
}
98+
99+
(* override rpc code generated for persistent_t. It is important that
100+
* this code is before the declaration of type t because otherwise
101+
* the rpc code for type t won't use it. *)
102+
let persistent_t_of_rpc rpc =
103+
Rpc.struct_extend rpc (rpc_of_persistent_t default_persistent_t)
104+
|> persistent_t_of_rpc
105+
89106
type non_persistent_t = {
90107
create_info: Domain.create_info;
91108
vcpu_max: int;
@@ -759,6 +776,8 @@ module VM = struct
759776
(* Earlier than the PV drivers update time, therefore
760777
any cached PV driver information will be kept. *)
761778
last_start_time = 0.;
779+
nomigrate = false;
780+
nested_virt = false
762781
} |> VmExtra.rpc_of_persistent_t |> Jsonrpc.to_string
763782

764783
let mkints n =
@@ -855,7 +874,19 @@ module VM = struct
855874
x.VmExtra.persistent, x.VmExtra.non_persistent
856875
| None -> begin
857876
debug "VM = %s; has no stored domain-level configuration, regenerating" vm.Vm.id;
858-
let persistent = { VmExtra.build_info = None; ty = None; last_start_time = Unix.gettimeofday ()} in
877+
let persistent =
878+
{ VmExtra.build_info = None
879+
; ty = None
880+
; last_start_time = Unix.gettimeofday ()
881+
; nomigrate = Platform.is_true
882+
~key:"nomigrate"
883+
~platformdata:vm.Xenops_interface.Vm.platformdata
884+
~default:false
885+
; nested_virt=Platform.is_true
886+
~key:"nested_virt"
887+
~platformdata:vm.Xenops_interface.Vm.platformdata
888+
~default:false
889+
} in
859890
let non_persistent = generate_non_persistent_state xc xs vm in
860891
persistent, non_persistent
861892
end in
@@ -1638,6 +1669,14 @@ module VM = struct
16381669
end;
16391670
hvm = di.Xenctrl.hvm_guest;
16401671
shadow_multiplier_target = shadow_multiplier_target;
1672+
nomigrate = begin match vme with
1673+
| None -> false
1674+
| Some x -> x.VmExtra.persistent.VmExtra.nomigrate
1675+
end;
1676+
nested_virt = begin match vme with
1677+
| None -> false
1678+
| Some x -> x.VmExtra.persistent.VmExtra.nested_virt
1679+
end
16411680
}
16421681
)
16431682

xl/xenops_server_xenlight.ml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ module VmExtra = struct
236236
build_info: Domain.build_info option;
237237
ty: Vm.builder_info option;
238238
last_start_time: float;
239+
nomigrate: bool; (* platform:nomigrate at boot time *)
240+
nested_virt: bool (* platform:nested_virt at boot time *)
239241
} with rpc
240242

241243
type non_persistent_t = {
@@ -256,6 +258,19 @@ module VmExtra = struct
256258
persistent: persistent_t;
257259
non_persistent: non_persistent_t;
258260
} with rpc
261+
262+
let default_persistent_t =
263+
{ build_info = None
264+
; ty = None
265+
; last_start_time = 0.0
266+
; nomigrate = false
267+
; nested_virt = false
268+
}
269+
270+
(* override rpc code generated for persistent_t *)
271+
let persistent_t_of_rpc rpc =
272+
Rpc.struct_extend rpc (rpc_of_persistent_t default_persistent_t)
273+
|> persistent_t_of_rpc
259274
end
260275

261276
module DB = struct
@@ -1793,6 +1808,8 @@ module VM = struct
17931808
(* Earlier than the PV drivers update time, therefore
17941809
any cached PV driver information will be kept. *)
17951810
last_start_time = 0.;
1811+
nomigrate = false;
1812+
nested_virt = false
17961813
} |> VmExtra.rpc_of_persistent_t |> Jsonrpc.to_string
17971814

17981815
(* Could use fold_left to get the same value, but that would necessarily go through the whole list everytime, instead of the first n items, only. *)
@@ -2087,7 +2104,19 @@ module VM = struct
20872104
x.VmExtra.persistent, x.VmExtra.non_persistent
20882105
| None -> begin
20892106
debug "VM = %s; has no stored domain-level configuration, regenerating" vm.Vm.id;
2090-
let persistent = { VmExtra.build_info = None; ty = None; last_start_time = Unix.gettimeofday () } in
2107+
let persistent =
2108+
{ VmExtra.build_info = None
2109+
; ty = None
2110+
; last_start_time = Unix.gettimeofday ()
2111+
; nomigrate = Platform.is_true
2112+
~key:"nomigrate"
2113+
~platformdata:vm.Xenops_interface.Vm.platformdata
2114+
~default:false
2115+
; nested_virt=Platform.is_true
2116+
~key:"nested_virt"
2117+
~platformdata:vm.Xenops_interface.Vm.platformdata
2118+
~default:false
2119+
} in
20912120
let non_persistent = generate_non_persistent_state xs vm in
20922121
persistent, non_persistent
20932122
end in
@@ -2682,6 +2711,14 @@ module VM = struct
26822711
end;
26832712
shadow_multiplier_target = shadow_multiplier_target;
26842713
hvm;
2714+
nomigrate = begin match vme with
2715+
| None -> false
2716+
| Some x -> x.VmExtra.persistent.VmExtra.nomigrate
2717+
end;
2718+
nested_virt = begin match vme with
2719+
| None -> false
2720+
| Some x -> x.VmExtra.persistent.VmExtra.nested_virt
2721+
end
26852722
}
26862723
)
26872724

0 commit comments

Comments
 (0)