Skip to content

Commit 38c7337

Browse files
committed
Merge pull request xapi-project#1740 from djs55/more-fixes
xenserver-core: allow startup without xen
2 parents 7cd86cd + a9dfb18 commit 38c7337

File tree

2 files changed

+48
-79
lines changed

2 files changed

+48
-79
lines changed

ocaml/xapi/create_misc.ml

Lines changed: 34 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ and ensure_domain_zero_guest_metrics_record ~__context ~domain_zero_ref (host_in
156156
begin
157157
debug "Domain 0 record does not have associated guest metrics record. Creating now";
158158
let metrics_ref = Ref.make() in
159-
create_domain_zero_guest_metrics_record ~__context ~domain_zero_metrics_ref:metrics_ref ~memory_constraints:(create_domain_zero_default_memory_constraints host_info)
159+
create_domain_zero_guest_metrics_record ~__context ~domain_zero_metrics_ref:metrics_ref ~memory_constraints:(create_domain_zero_memory_constraints host_info)
160160
~vcpus:(calculate_domain_zero_vcpu_count ~__context);
161161
Db.VM.set_metrics ~__context ~self:domain_zero_ref ~value:metrics_ref
162162
end
@@ -168,7 +168,7 @@ and ensure_domain_zero_shadow_record ~__context ~domain_zero_ref : unit =
168168

169169
and create_domain_zero_record ~__context ~domain_zero_ref (host_info: host_info) : unit =
170170
(* Determine domain 0 memory constraints. *)
171-
let memory = create_domain_zero_default_memory_constraints host_info in
171+
let memory = create_domain_zero_memory_constraints host_info in
172172
(* Determine information about the host machine. *)
173173
let domarch =
174174
let i = Int64.of_nativeint (Int64.to_nativeint 0xffffffffL) in
@@ -255,71 +255,25 @@ and create_domain_zero_guest_metrics_record ~__context ~domain_zero_metrics_ref
255255
~last_updated: Date.never
256256
~other_config:[];
257257

258-
and create_domain_zero_default_memory_constraints host_info : Vm_memory_constraints.t =
259-
let static_min, static_max = calculate_domain_zero_memory_static_range host_info in
260-
try
261-
(* Look up the current domain zero record in xenopsd *)
262-
let open Xenops_interface in
263-
let open Xenops_client in
264-
let vm, state = Client.VM.stat "dbsync" host_info.dom0_uuid in
265-
{
266-
static_min = static_min;
267-
static_max = vm.Vm.memory_static_max;
268-
dynamic_min = state.Vm.memory_target;
269-
dynamic_max = state.Vm.memory_target;
270-
target = state.Vm.memory_target;
271-
}
272-
with _ ->
273-
let target = static_min +++ (Int64.(mul 100L (mul 1024L 1024L))) in
274-
let target = if target > static_max then static_max else target in
275-
{
276-
static_min = static_min;
277-
dynamic_min = target;
278-
target = target;
279-
dynamic_max = target;
280-
static_max = static_max;
281-
}
282-
283258
and update_domain_zero_record ~__context ~domain_zero_ref (host_info: host_info) : unit =
284-
(* Fetch existing memory constraints for domain 0. *)
285-
let constraints = Vm_memory_constraints.get ~__context ~vm_ref:domain_zero_ref in
286-
(* Generate new memory constraints from the old constraints. *)
287-
let constraints = update_domain_zero_memory_constraints host_info constraints in
259+
let constraints = create_domain_zero_memory_constraints host_info in
288260
(* Write the updated memory constraints to the database. *)
289261
Vm_memory_constraints.set ~__context ~vm_ref:domain_zero_ref ~constraints
290262

291-
and update_domain_zero_memory_constraints (host_info: host_info) (constraints: Vm_memory_constraints.t) : Vm_memory_constraints.t =
292-
let static_min, static_max = calculate_domain_zero_memory_static_range host_info in
293-
let constraints = {constraints with
294-
static_min = static_min;
295-
static_max = static_max;} in
296-
match Vm_memory_constraints.transform constraints with
297-
| None ->
298-
(* The existing constraints are invalid, and cannot be transformed *)
299-
(* into valid constraints. Reset the constraints to their defaults. *)
300-
create_domain_zero_default_memory_constraints host_info
301-
| Some constraints ->
302-
constraints
303-
304-
(** Calculates the range of memory to which domain 0 is constrained, in bytes. *)
305-
and calculate_domain_zero_memory_static_range (host_info: host_info) : int64 * int64 =
306-
307-
(** Calculates the minimum amount of memory needed by domain 0, in bytes. *)
308-
let calculate_domain_zero_memory_static_min () =
309-
(* Base our calculation on the total amount of host memory. *)
310-
let host_total_memory_mib = host_info.total_memory_mib in
311-
let minimum = 200L in (* lower hard limit *)
312-
let intercept = 126L in (* [domain 0 memory] when [total host memory] = 0 *)
313-
let gradient = 21.0 /. 1024.0 in (* d [domain 0 memory] / d [total host memory] *)
314-
let result = Int64.add (Int64.of_float (gradient *. (Int64.to_float host_total_memory_mib))) intercept in
315-
let result = if result < minimum then minimum else result in
316-
Int64.(mul result (mul 1024L 1024L)) in
317-
318-
(* static_min must not be greater than static_max *)
319-
let static_min = calculate_domain_zero_memory_static_min () in
320-
let static_max = host_info.dom0_static_max in
321-
let static_min = minimum static_min static_max in
322-
static_min, static_max
263+
and create_domain_zero_memory_constraints (host_info: host_info) : Vm_memory_constraints.t =
264+
match Memory_client.Client.get_domain_zero_policy "create_misc" with
265+
| Memory_interface.Fixed_size x ->
266+
{
267+
static_min = x; static_max = x;
268+
dynamic_min = x; dynamic_max = x;
269+
target = x;
270+
}
271+
| Memory_interface.Auto_balloon(low, high) ->
272+
{
273+
static_min = low; static_max = high;
274+
dynamic_min = low; dynamic_max = high;
275+
target = high;
276+
}
323277

324278
and calculate_domain_zero_vcpu_count ~__context : int =
325279
List.length (Db.Host.get_host_CPUs ~__context ~self:(Helpers.get_localhost ~__context))
@@ -540,18 +494,23 @@ let create_chipset_info ~__context =
540494
let host = Helpers.get_localhost ~__context in
541495
let current_info = Db.Host.get_chipset_info ~__context ~self:host in
542496
let iommu =
543-
let open Xenops_client in
544-
let dbg = Context.string_of_task __context in
545-
let xen_dmesg = Client.HOST.get_console_data dbg in
546-
if String.has_substr xen_dmesg "I/O virtualisation enabled" then
547-
"true"
548-
else if String.has_substr xen_dmesg "I/O virtualisation disabled" then
549-
"false"
550-
else if List.mem_assoc "iommu" current_info then
551-
List.assoc "iommu" current_info
552-
else
553-
"false"
554-
in
497+
try
498+
let xc = Xenctrl.interface_open () in
499+
Xenctrl.interface_close xc;
500+
let open Xenops_client in
501+
let dbg = Context.string_of_task __context in
502+
let xen_dmesg = Client.HOST.get_console_data dbg in
503+
if String.has_substr xen_dmesg "I/O virtualisation enabled" then
504+
"true"
505+
else if String.has_substr xen_dmesg "I/O virtualisation disabled" then
506+
"false"
507+
else if List.mem_assoc "iommu" current_info then
508+
List.assoc "iommu" current_info
509+
else
510+
"false"
511+
with _ ->
512+
warn "Not running on xen; assuming I/O vierualization disabled";
513+
"false" in
555514
let info = ["iommu", iommu] in
556515
Db.Host.set_chipset_info ~__context ~self:host ~value:info
557516

ocaml/xapi/dbsync_slave.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ let refresh_localhost_info ~__context info =
121121
let record_host_memory_properties ~__context =
122122
let self = !Xapi_globs.localhost_ref in
123123
let total_memory_bytes =
124-
let open Xenops_client in
125-
let dbg = Context.string_of_task __context in
126-
let mib = Client.HOST.get_total_memory_mib dbg in
127-
Int64.mul 1024L (Int64.mul 1024L mib) in
124+
try
125+
let xc = Xenctrl.interface_open () in
126+
Xenctrl.interface_close xc; (* we're on xen *)
127+
let open Xenops_client in
128+
let dbg = Context.string_of_task __context in
129+
let mib = Client.HOST.get_total_memory_mib dbg in
130+
Int64.mul 1024L (Int64.mul 1024L mib)
131+
with _ ->
132+
warn "Failed to detect xen, querying /proc/meminfo";
133+
begin match Balloon.get_memtotal () with
134+
| None -> 0L
135+
| Some x -> Int64.(div x (mul 1024L 1024L))
136+
end in
137+
128138
let metrics = Db.Host.get_metrics ~__context ~self in
129139
Db.Host_metrics.set_memory_total ~__context ~self:metrics ~value:total_memory_bytes;
130140
let boot_memory_file = Xapi_globs.initial_host_free_memory_file in

0 commit comments

Comments
 (0)