Skip to content

Commit 7febc10

Browse files
author
Jon Ludlam
authored
Merge pull request #149 from jonludlam/updates2
Add Updates, Scheduler and Task_server
2 parents 7060017 + ee72ba8 commit 7febc10

19 files changed

+1950
-126
lines changed

_oasis

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ Library xcp
1515
CSources: syslog_stubs.c
1616
BuildDepends: cmdliner, uri, re, cohttp, xmlm, unix, ppx_sexp_conv, sexplib, ppx_deriving_rpc, rpclib, rpclib.xml, threads, message_switch (>= 0.11.0), message_switch.unix, fd-send-recv, xcp-inventory, xapi-backtrace
1717

18+
Library xcp_updates
19+
CompiledObject: best
20+
Path: lib
21+
Findlibname: updates
22+
Findlibparent: xcp
23+
Modules: Updates, Task_server, Scheduler
24+
1825
Library xcp_storage
1926
CompiledObject: best
2027
Path: storage
@@ -84,10 +91,10 @@ Executable lib_test
8491
MainIs: test.ml
8592
Custom: true
8693
Install: false
87-
BuildDepends: lwt, lwt.unix, xcp, xcp.xen, threads, rpclib, oUnit
94+
BuildDepends: lwt, lwt.unix, xcp, xcp.xen, threads, rpclib, oUnit, xcp.updates
8895

8996
Test lib_test
90-
Command: ./test.native
97+
Command: ./test.native -runner sequential
9198
Run: true
9299

93100
Executable example

_tags

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 84bd6ed57b3561ce9ac6edd2793b3d1b)
2+
# DO NOT EDIT (digest: 602453b3fb6b3d0b87012f531fd91c7d)
33
# Ignore VCS directories, you can use the same kind of rule outside
44
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
@@ -34,6 +34,8 @@ true: annot, bin_annot
3434
"lib/syslog_stubs.c": pkg_xapi-backtrace
3535
"lib/syslog_stubs.c": pkg_xcp-inventory
3636
"lib/syslog_stubs.c": pkg_xmlm
37+
# Library xcp_updates
38+
"lib/xcp_updates.cmxs": use_xcp_updates
3739
# Library xcp_storage
3840
"storage/xcp_storage.cmxs": use_xcp_storage
3941
# Executable storage_test
@@ -242,6 +244,7 @@ true: annot, bin_annot
242244
<lib_test/test.{native,byte}>: pkg_xcp-inventory
243245
<lib_test/test.{native,byte}>: pkg_xmlm
244246
<lib_test/test.{native,byte}>: use_xcp
247+
<lib_test/test.{native,byte}>: use_xcp_updates
245248
<lib_test/test.{native,byte}>: use_xcp_xen
246249
<lib_test/*.ml{,i,y}>: pkg_cmdliner
247250
<lib_test/*.ml{,i,y}>: pkg_cohttp
@@ -264,6 +267,7 @@ true: annot, bin_annot
264267
<lib_test/*.ml{,i,y}>: pkg_xcp-inventory
265268
<lib_test/*.ml{,i,y}>: pkg_xmlm
266269
<lib_test/*.ml{,i,y}>: use_xcp
270+
<lib_test/*.ml{,i,y}>: use_xcp_updates
267271
<lib_test/*.ml{,i,y}>: use_xcp_xen
268272
<lib_test/test.{native,byte}>: custom
269273
# Executable example

lib/META

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: d61b4e5a5c0d213787a9ffd3db8cee24)
2+
# DO NOT EDIT (digest: 8768846be18e97edf6faf163a4fb6e66)
33
version = "1.2.0"
44
description =
55
"Interface definitions and common boilerplate for the xapi toolstack"
@@ -34,6 +34,17 @@ package "v6" (
3434
exists_if = "xapi_v6.cma"
3535
)
3636

37+
package "updates" (
38+
version = "1.2.0"
39+
description =
40+
"Interface definitions and common boilerplate for the xapi toolstack"
41+
archive(byte) = "xcp_updates.cma"
42+
archive(byte, plugin) = "xcp_updates.cma"
43+
archive(native) = "xcp_updates.cmxa"
44+
archive(native, plugin) = "xcp_updates.cmxs"
45+
exists_if = "xcp_updates.cma"
46+
)
47+
3748
package "storage" (
3849
version = "1.2.0"
3950
description =

lib/debug.ml

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,32 @@ module Cache = struct
3838
let invalidate t =
3939
Mutex.execute t.m
4040
(fun () ->
41-
t.item <- None;
41+
t.item <- None;
4242
)
4343

4444
let get t =
4545
Mutex.execute t.m
4646
(fun () ->
47-
match t.item with
48-
| Some x -> x
49-
| None ->
50-
let x = t.fn () in
51-
t.item <- Some x;
52-
x
47+
match t.item with
48+
| Some x -> x
49+
| None ->
50+
let x = t.fn () in
51+
t.item <- Some x;
52+
x
5353
)
5454
end
5555

5656
let hostname = Cache.make
57-
(fun () ->
58-
let h = Unix.gethostname () in
59-
Backtrace.set_my_name (Filename.basename(Sys.argv.(0)) ^ " @ " ^ h);
60-
h
61-
)
57+
(fun () ->
58+
let h = Unix.gethostname () in
59+
Backtrace.set_my_name (Filename.basename(Sys.argv.(0)) ^ " @ " ^ h);
60+
h
61+
)
6262

6363
let invalidate_hostname_cache () = Cache.invalidate hostname
6464

6565
let get_thread_id () =
66-
try Thread.id (Thread.self ()) with _ -> -1
66+
try Thread.id (Thread.self ()) with _ -> -1
6767

6868
module ThreadLocalTable = struct
6969
type 'a t = {
@@ -83,14 +83,15 @@ module ThreadLocalTable = struct
8383
let remove t =
8484
let id = get_thread_id () in
8585
Mutex.execute t.m (fun () -> Hashtbl.remove t.tbl id)
86-
86+
8787
let find t =
8888
let id = get_thread_id () in
8989
Mutex.execute t.m (fun () ->
90-
if Hashtbl.mem t.tbl id
91-
then Some (Hashtbl.find t.tbl id)
92-
else None
93-
)
90+
try
91+
Some (Hashtbl.find t.tbl id)
92+
with
93+
| _ -> None
94+
)
9495
end
9596

9697
let names = ThreadLocalTable.make ()
@@ -127,21 +128,21 @@ let loglevel = ref default_loglevel
127128

128129
let disabled_modules () =
129130
Mutex.execute loglevel_m (fun () ->
130-
Hashtbl.fold (fun key _ acc -> key :: acc) logging_disabled_for []
131-
)
131+
Hashtbl.fold (fun key _ acc -> key :: acc) logging_disabled_for []
132+
)
132133

133134
let is_disabled brand level =
134135
Mutex.execute loglevel_m (fun () ->
135-
Syslog.is_masked ~threshold:!loglevel level ||
136+
Syslog.is_masked ~threshold:!loglevel level ||
136137
Hashtbl.mem logging_disabled_for (brand, level)
137-
)
138+
)
138139

139140
let reset_levels () =
140141
Mutex.execute loglevel_m (fun () ->
141-
loglevel := default_loglevel;
142-
Hashtbl.clear logging_disabled_for
143-
)
144-
142+
loglevel := default_loglevel;
143+
Hashtbl.clear logging_disabled_for
144+
)
145+
145146

146147
let facility = ref Syslog.Daemon
147148
let facility_m = Mutex.create ()
@@ -196,9 +197,9 @@ let with_thread_named name f x =
196197
raise e
197198

198199
module StringSet = Set.Make(struct type t=string let compare=Pervasives.compare end)
199-
let debug_keys = ref StringSet.empty
200+
let debug_keys = ref StringSet.empty
200201
let get_all_debug_keys () =
201-
StringSet.fold (fun key keys -> key::keys) !debug_keys []
202+
StringSet.fold (fun key keys -> key::keys) !debug_keys []
202203

203204
let dkmutex = Mutex.create ()
204205

@@ -209,78 +210,78 @@ end
209210
let all_levels = [Syslog.Debug; Syslog.Info; Syslog.Warning; Syslog.Err]
210211

211212
let add_to_stoplist brand level =
212-
Hashtbl.replace logging_disabled_for (brand, level) ()
213+
Hashtbl.replace logging_disabled_for (brand, level) ()
213214

214215
let remove_from_stoplist brand level =
215-
Hashtbl.remove logging_disabled_for (brand, level)
216+
Hashtbl.remove logging_disabled_for (brand, level)
216217

217218
let disable ?level brand =
218-
let levels = match level with
219-
| None -> all_levels
220-
| Some l -> [l]
221-
in
222-
Mutex.execute loglevel_m (fun () ->
223-
List.iter (add_to_stoplist brand) levels
224-
)
219+
let levels = match level with
220+
| None -> all_levels
221+
| Some l -> [l]
222+
in
223+
Mutex.execute loglevel_m (fun () ->
224+
List.iter (add_to_stoplist brand) levels
225+
)
225226

226227
let enable ?level brand =
227-
let levels = match level with
228-
| None -> all_levels
229-
| Some l -> [l]
230-
in
231-
Mutex.execute loglevel_m (fun () ->
232-
List.iter (remove_from_stoplist brand) levels
233-
)
228+
let levels = match level with
229+
| None -> all_levels
230+
| Some l -> [l]
231+
in
232+
Mutex.execute loglevel_m (fun () ->
233+
List.iter (remove_from_stoplist brand) levels
234+
)
234235

235236
let set_level level =
236-
Mutex.execute loglevel_m (fun () ->
237-
loglevel := level
238-
)
237+
Mutex.execute loglevel_m (fun () ->
238+
loglevel := level
239+
)
239240

240241
module type DEBUG = sig
241-
val debug : ('a, unit, string, unit) format4 -> 'a
242+
val debug : ('a, unit, string, unit) format4 -> 'a
242243

243-
val warn : ('a, unit, string, unit) format4 -> 'a
244+
val warn : ('a, unit, string, unit) format4 -> 'a
244245

245-
val info : ('a, unit, string, unit) format4 -> 'a
246+
val info : ('a, unit, string, unit) format4 -> 'a
246247

247-
val error : ('a, unit, string, unit) format4 -> 'a
248+
val error : ('a, unit, string, unit) format4 -> 'a
248249

249-
val audit : ?raw:bool -> ('a, unit, string, string) format4 -> 'a
250+
val audit : ?raw:bool -> ('a, unit, string, string) format4 -> 'a
250251

251-
val log_backtrace : unit -> unit
252+
val log_backtrace : unit -> unit
252253

253-
val log_and_ignore_exn : (unit -> unit) -> unit
254+
val log_and_ignore_exn : (unit -> unit) -> unit
254255
end
255256

256257
module Make = functor(Brand: BRAND) -> struct
257258
let _ =
258-
Mutex.execute dkmutex (fun () ->
259-
debug_keys := StringSet.add Brand.name !debug_keys)
260-
261-
let output level priority (fmt: ('a, unit, string, 'b) format4) =
262-
Printf.kprintf
263-
(fun s ->
264-
if not(is_disabled Brand.name level)
265-
then output_log Brand.name level priority s
266-
) fmt
267-
268-
let debug fmt = output Syslog.Debug "debug" fmt
269-
let warn fmt = output Syslog.Warning "warn" fmt
270-
let info fmt = output Syslog.Info "info" fmt
271-
let error fmt = output Syslog.Err "error" fmt
272-
let audit ?(raw=false) (fmt: ('a, unit, string, 'b) format4) =
273-
Printf.kprintf
274-
(fun s ->
275-
let msg = if raw then s else format true Brand.name "audit" s in
276-
Syslog.log Syslog.Local6 Syslog.Info msg;
277-
msg
278-
) fmt
279-
280-
let log_backtrace () =
281-
let backtrace = Printexc.get_backtrace () in
282-
debug "%s" (String.escaped backtrace)
283-
284-
let log_and_ignore_exn f =
285-
try f () with _ -> log_backtrace ()
259+
Mutex.execute dkmutex (fun () ->
260+
debug_keys := StringSet.add Brand.name !debug_keys)
261+
262+
let output level priority (fmt: ('a, unit, string, 'b) format4) =
263+
Printf.kprintf
264+
(fun s ->
265+
if not(is_disabled Brand.name level)
266+
then output_log Brand.name level priority s
267+
) fmt
268+
269+
let debug fmt = output Syslog.Debug "debug" fmt
270+
let warn fmt = output Syslog.Warning "warn" fmt
271+
let info fmt = output Syslog.Info "info" fmt
272+
let error fmt = output Syslog.Err "error" fmt
273+
let audit ?(raw=false) (fmt: ('a, unit, string, 'b) format4) =
274+
Printf.kprintf
275+
(fun s ->
276+
let msg = if raw then s else format true Brand.name "audit" s in
277+
Syslog.log Syslog.Local6 Syslog.Info msg;
278+
msg
279+
) fmt
280+
281+
let log_backtrace () =
282+
let backtrace = Printexc.get_backtrace () in
283+
debug "%s" (String.escaped backtrace)
284+
285+
let log_and_ignore_exn f =
286+
try f () with _ -> log_backtrace ()
286287
end

0 commit comments

Comments
 (0)