Skip to content

Commit aa5e3fa

Browse files
committed
Merge pull request xapi-project#1730 from djs55/pool.conf
pool.conf: always use the path from the config file
2 parents 0e82615 + f3ba43c commit aa5e3fa

File tree

10 files changed

+129
-117
lines changed

10 files changed

+129
-117
lines changed

ocaml/idl/ocaml_backend/OMakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ SERVER_OBJS = ../../database/escaping locking_helpers \
103103
../datamodel ../datamodel_utils ../datamodel_values \
104104
gen_client ocaml_syntax ocaml_utils taskHelper exnHelper \
105105
server_helpers session_check context \
106-
../../pool_role_shared \
107106
../../xapi/pool_role \
108107
../../xapi/xapi_inventory \
109108
../../xapi/hashtbl_xml \

ocaml/idl/ocaml_backend/context.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ let preauth ~__context =
104104
Internal -> false
105105
| Http (req,s) -> is_unix_socket s
106106

107-
let initial =
107+
let get_initial () =
108108
{ session_id = None;
109109
task_id = Ref.of_string "initial_task";
110110
task_in_database = false;
@@ -161,7 +161,7 @@ let make_dbg http_other_config task_name task_id =
161161

162162
(** constructors *)
163163

164-
let from_forwarded_task ?(__context=initial) ?(http_other_config=[]) ?session_id ?(origin=Internal) task_id =
164+
let from_forwarded_task ?(__context=get_initial ()) ?(http_other_config=[]) ?session_id ?(origin=Internal) task_id =
165165
let task_name =
166166
if Ref.is_dummy task_id
167167
then Ref.name_of_dummy task_id
@@ -181,7 +181,7 @@ let from_forwarded_task ?(__context=initial) ?(http_other_config=[]) ?session_id
181181
dbg = dbg;
182182
}
183183

184-
let make ?(__context=initial) ?(http_other_config=[]) ?(quiet=false) ?subtask_of ?session_id ?(database=default_database ()) ?(task_in_database=false) ?task_description ?(origin=Internal) task_name =
184+
let make ?(__context=get_initial ()) ?(http_other_config=[]) ?(quiet=false) ?subtask_of ?session_id ?(database=default_database ()) ?(task_in_database=false) ?task_description ?(origin=Internal) task_name =
185185
let task_id, task_uuid =
186186
if task_in_database
187187
then !__make_task ~__context ~http_other_config ?description:task_description ?session_id ?subtask_of task_name

ocaml/idl/ocaml_backend/context.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ type origin =
2121

2222
(** {6 Constructors} *)
2323

24-
(** [initial] is the initial context. *)
25-
val initial : t
26-
2724
(** [make ~__context ~subtask_of ~database ~session_id ~task_in_database ~task_description ~origin name] creates a new context.
2825
[__context] is the calling context,
2926
[http_other_config] are extra bits of context picked up from HTTP headers,

ocaml/pool_role_shared.ml

Lines changed: 0 additions & 89 deletions
This file was deleted.

ocaml/test/suite.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let start_server handlers =
5959

6060
let harness_init () =
6161
Printexc.record_backtrace true;
62-
Pool_role_shared.set_pool_role_for_test ();
62+
Pool_role.set_pool_role_for_test ();
6363
Xapi.register_callback_fns ();
6464
start_server handlers
6565

ocaml/xapi/balloon.ml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414
open Stringext
15+
open Pervasiveext
1516
open Printf
1617
open Xenstore
1718

@@ -38,3 +39,30 @@ let parse_proc_xen_balloon () =
3839
(key, Some (Int64.of_string stripped))) keys
3940

4041

42+
let _proc_meminfo = "/proc/meminfo"
43+
44+
let parse_meminfo () =
45+
let ic = open_in _proc_meminfo in
46+
finally
47+
(fun () ->
48+
let table = ref [] in
49+
begin
50+
try
51+
while true do
52+
let line = input_line ic in
53+
match Stringext.String.split ' ' line with
54+
| key :: value :: "kB" :: [] ->
55+
table := (key, Int64.(mul (of_string value) 1024L)) :: !table
56+
| _ -> ()
57+
done
58+
with End_of_file -> ()
59+
end;
60+
!table
61+
) (fun () -> close_in ic)
62+
63+
let _memtotal = "MemTotal:"
64+
let get_memtotal () =
65+
let table = parse_meminfo () in
66+
if List.mem_assoc _memtotal table
67+
then Some (List.assoc _memtotal table)
68+
else None

ocaml/xapi/balloon.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ val _current_allocation : string
1616
val _requested_target : string
1717
val _low_mem_balloon : string
1818
val _high_mem_balloon : string
19+
20+
val get_memtotal: unit -> int64 option

ocaml/xapi/create_misc.ml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,25 @@ type host_info = {
4444
}
4545

4646
let read_localhost_info () =
47-
let xen_verstring =
47+
let xen_verstring, total_memory_mib =
4848
try
4949
let xc = Xenctrl.interface_open () in
5050
let v = Xenctrl.version xc in
5151
Xenctrl.interface_close xc;
5252
let open Xenctrl in
53-
Printf.sprintf "%d.%d%s" v.major v.minor v.extra
53+
let xen_verstring = Printf.sprintf "%d.%d%s" v.major v.minor v.extra in
54+
let total_memory_mib =
55+
let open Xenops_client in
56+
Client.HOST.get_total_memory_mib "read_localhost_info" in
57+
xen_verstring, total_memory_mib
5458
with e ->
5559
if Pool_role.is_unit_test ()
56-
then "0.0.0"
60+
then "0.0.0", 0L
5761
else begin
5862
warn "Failed to read xen version";
59-
"unknown"
63+
match Balloon.get_memtotal () with
64+
| None -> "unknown", 0L
65+
| Some x -> "unknown", Int64.(div x (mul 1024L 1024L))
6066
end
6167
and linux_verstring =
6268
let verstring = ref "" in
@@ -69,21 +75,21 @@ let read_localhost_info () =
6975
let me = Helpers.get_localhost_uuid () in
7076
let lookup_inventory_nofail k = try Some (Xapi_inventory.lookup k) with _ -> None in
7177
let this_host_name = Helpers.get_hostname() in
72-
let total_memory_mib =
73-
let open Xenops_client in
74-
Client.HOST.get_total_memory_mib "read_localhost_info" in
75-
76-
let dom0_static_max =
77-
(* Query the balloon driver to determine how much memory is available for domain 0. *)
78-
(* We cannot ask XenControl for this information, since for domain 0, the value of *)
79-
(* max_memory_pages is hard-wired to the maximum native integer value ("infinity"). *)
80-
let map = Balloon.parse_proc_xen_balloon () in
81-
let lookup = fun x -> Opt.unbox (List.assoc x map) in
82-
let keys = [Balloon._low_mem_balloon; Balloon._high_mem_balloon; Balloon._current_allocation] in
83-
let values = List.map lookup keys in
84-
let result = List.fold_left Int64.add 0L values in
85-
Int64.mul 1024L result in
8678

79+
let dom0_static_max =
80+
try
81+
(* Query the balloon driver to determine how much memory is available for domain 0. *)
82+
(* We cannot ask XenControl for this information, since for domain 0, the value of *)
83+
(* max_memory_pages is hard-wired to the maximum native integer value ("infinity"). *)
84+
let map = Balloon.parse_proc_xen_balloon () in
85+
let lookup = fun x -> Opt.unbox (List.assoc x map) in
86+
let keys = [Balloon._low_mem_balloon; Balloon._high_mem_balloon; Balloon._current_allocation] in
87+
let values = List.map lookup keys in
88+
let result = List.fold_left Int64.add 0L values in
89+
Int64.mul 1024L result
90+
with e ->
91+
info "Failed to query balloon driver, assuming target = static_max";
92+
Int64.(mul total_memory_mib (mul 1024L 1024L)) in
8793
{
8894
name_label=this_host_name;
8995
xen_verstring=xen_verstring;

ocaml/xapi/pool_role.ml

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,79 @@
1515
* @group Pool Management
1616
*)
1717

18+
open Stringext
1819
open Threadext
1920

20-
include Pool_role_shared
21+
module D=Debug.Make(struct let name="pool_role" end)
22+
open D
23+
24+
(** The role of this node *)
25+
type t =
26+
| Master
27+
| Slave of string (* IP address *)
28+
| Broken
29+
30+
let role = ref None
31+
let role_unit_tests = ref false
32+
let role_m = Mutex.create ()
33+
34+
let set_pool_role_for_test () =
35+
Mutex.execute role_m (fun _ -> role := Some Master;
36+
role_unit_tests := true)
37+
38+
let is_unit_test () =
39+
Mutex.execute role_m (fun _ -> !role_unit_tests)
40+
41+
let string_of = function
42+
| Master -> "master"
43+
| Slave x -> "slave:" ^ x
44+
| Broken -> "broken"
45+
46+
let read_pool_role () =
47+
try
48+
let s = String.strip String.isspace
49+
(Unixext.string_of_file !Xapi_globs.pool_config_file) in
50+
match String.split ~limit:2 ':' s with
51+
| [ "master" ] -> Master
52+
| [ "slave"; m_ip ] -> Slave m_ip
53+
| [ "broken" ] -> Broken
54+
| _ -> failwith "cannot parse pool_role from pool config file"
55+
with _ ->
56+
(* If exec name is suite.opt, we're running as unit tests *)
57+
if "xapi" <> Filename.basename Sys.executable_name
58+
then (debug "Executable name is not 'xapi', so we must be running \
59+
in unit-test mode; setting pool-role to 'Master'";
60+
Master)
61+
else (error "Failed to read pool role from %s" !Xapi_globs.pool_config_file;
62+
Broken)
63+
64+
let get_role () =
65+
Mutex.execute role_m (fun _ ->
66+
match !role with
67+
| Some x -> x
68+
| None ->
69+
let r = read_pool_role () in
70+
role := Some r;
71+
r
72+
)
73+
74+
let is_master () = get_role () = Master
75+
76+
let is_slave () = match get_role () with
77+
| Slave _ -> true
78+
| _ -> false
79+
80+
let is_broken () = get_role () = Broken
81+
82+
exception This_host_is_a_master
83+
exception This_host_is_broken
84+
85+
let get_master_address () = match get_role () with
86+
| Slave ip -> ip
87+
| Master -> raise This_host_is_a_master
88+
| Broken -> raise This_host_is_broken
2189

2290
let set_role r =
23-
filename := !Xapi_globs.pool_config_file;
2491
let old_role = get_role () in
2592
Mutex.execute role_m
2693
(fun () ->

ocaml/xapi/pool_role.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ val is_broken: unit -> bool
3434
(** Returns true if this is a unit test *)
3535
val is_unit_test: unit -> bool
3636

37+
val set_pool_role_for_test: unit -> unit
38+
3739
exception This_host_is_a_master
3840
exception This_host_is_broken
3941

0 commit comments

Comments
 (0)