Skip to content

Commit cf6575b

Browse files
authored
Sync master to feature branch (#6948)
2 parents 63addaf + 481913f commit cf6575b

16 files changed

Lines changed: 632 additions & 559 deletions

File tree

ocaml/forkexecd/lib/fe_stubs.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <limits.h>
2121
#include <sys/wait.h>
2222

23+
#include <caml/mlvalues.h>
24+
#include <caml/threads.h>
2325
#include <caml/fail.h>
2426
#include <caml/memory.h>
2527
#include <caml/unixsupport.h>
@@ -213,15 +215,15 @@ caml_safe_exec_with_helper(value args, value environment)
213215
}
214216

215217
// potentially slow section, release Ocaml engine
216-
caml_enter_blocking_section();
218+
caml_release_runtime_system();
217219

218220
safe_exec_result res;
219221
int err = safe_exec_with_helper(&res, c_args, c_envs);
220222

221223
free(c_envs);
222224
free(c_args);
223225

224-
caml_leave_blocking_section();
226+
caml_acquire_runtime_system();
225227

226228
// error, notify with an exception
227229
if (err != 0)
@@ -395,7 +397,7 @@ caml_pidwaiter_waitpid(value timeout_value, value pid_value)
395397
double timeout = timeout_value == Val_none ? 0 : Double_val(Some_val(timeout_value));
396398
pid_t pid = Int_val(pid_value);
397399

398-
caml_enter_blocking_section();
400+
caml_release_runtime_system();
399401

400402
bool timed_out = false;
401403
int err = 0;
@@ -407,7 +409,7 @@ caml_pidwaiter_waitpid(value timeout_value, value pid_value)
407409
timed_out = true;
408410
}
409411

410-
caml_leave_blocking_section();
412+
caml_acquire_runtime_system();
411413

412414
if (err)
413415
unix_error(err, "waitpid", Nothing);

ocaml/idl/datamodel_lifecycle.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ let prototyped_of_message = function
234234
| "PCI", "disable_dom0_access" ->
235235
Some "24.14.0"
236236
| "message", "destroy_all" ->
237-
Some "26.5.0-next"
237+
Some "26.6.0"
238238
| "message", "destroy_many" ->
239239
Some "22.19.0"
240240
| "VTPM", "set_contents" ->

ocaml/idl/ocaml_backend/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
(libraries
55
astring
66
cmdliner
7+
fmt
8+
ptime.clock
79
uuidm
810
xapi-consts
911
xapi-datamodel

ocaml/idl/ocaml_backend/gen_rbac.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ let internal_role_local_root = "_local_root_"
3434

3535
(* the output of this function is used as input by the automatic tests *)
3636
let writer_csv static_permissions_roles =
37-
Printf.sprintf "%s,PERMISSION/ROLE,%s\n"
38-
(let t = Debug.gettimestring () in
39-
String.sub t 0 (String.length t - 1)
40-
)
37+
let now =
38+
let now = Ptime_clock.now () in
39+
let str = Fmt.str "%a" Ptime.(pp_rfc3339 ~frac_s:3 ~tz_offset_s:0 ()) now in
40+
(* remove separators between Year, Month, and Day; to keep old logging format *)
41+
Astring.String.filter (function '-' -> false | _ -> true) str
42+
in
43+
Printf.sprintf "%s,PERMISSION/ROLE,%s\n" now
4144
(* role titles are ordered by roles in roles_all *)
4245
(List.fold_left (fun rr r -> rr ^ r ^ ",") "" Datamodel_roles.roles_all)
4346
^ List.fold_left

ocaml/libs/log/debug.ml

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@ let tasks : task ThreadLocalTable.t = ThreadLocalTable.make ()
7474
let names : string ThreadLocalTable.t = ThreadLocalTable.make ()
7575

7676
let gettimestring () =
77-
let time = Unix.gettimeofday () in
78-
let tm = Unix.gmtime time in
79-
let msec = time -. floor time in
80-
Printf.sprintf "%d%.2d%.2dT%.2d:%.2d:%.2d.%.3dZ|" (1900 + tm.Unix.tm_year)
81-
(tm.Unix.tm_mon + 1) tm.Unix.tm_mday tm.Unix.tm_hour tm.Unix.tm_min
82-
tm.Unix.tm_sec
83-
(int_of_float (1000.0 *. msec))
77+
let now = Ptime_clock.now () in
78+
Fmt.str "%a|" Ptime.(pp_rfc3339 ~frac_s:3 ~tz_offset_s:0 ()) now
8479

8580
(** [escape str] efficiently escapes non-printable characters and in addition
8681
the backslash character. The function is efficient in the sense that it will
@@ -216,20 +211,14 @@ let init_logs () =
216211
calling [output_log] too often. *)
217212
Logs.set_level (Some Logs.Warning)
218213

219-
let rec split_c c str =
220-
try
221-
let i = String.index str c in
222-
String.sub str 0 i
223-
:: split_c c (String.sub str (i + 1) (String.length str - i - 1))
224-
with Not_found -> [str]
225-
226214
let log_backtrace_exn ?(level = Syslog.Err) ?(msg = "error") exn bt =
227-
(* We already got the backtrace in the `bt` argument when called from with_thread_associated.
228-
Log that, and remove `exn` from the backtraces table.
229-
If with_backtraces was not nested then looking at `bt` is the only way to get
230-
a proper backtrace, otherwise exiting from `with_backtraces` would've removed the backtrace
231-
from the thread-local backtraces table, and we'd always just log a message complaining about
232-
with_backtraces not being called, which is not true because it was.
215+
(* We already got the backtrace in the `bt` argument when called from
216+
with_thread_associated. Log that, and remove `exn` from the backtraces
217+
table. If with_backtraces was not nested then looking at `bt` is the only
218+
way to get a proper backtrace, otherwise exiting from `with_backtraces`
219+
would've removed the backtrace from the thread-local backtraces table, and
220+
we'd always just log a message complaining about with_backtraces not being
221+
called, which is not true because it was.
233222
*)
234223
let bt' = Backtrace.remove exn in
235224
(* bt could be empty, but bt' would contain a non-empty warning, so compare 'bt' here *)
@@ -239,7 +228,7 @@ let log_backtrace_exn ?(level = Syslog.Err) ?(msg = "error") exn bt =
239228
else
240229
bt
241230
in
242-
let all = split_c '\n' Backtrace.(to_string_hum bt) in
231+
let all = String.split_on_char '\n' Backtrace.(to_string_hum bt) in
243232
(* Write to the log line at a time *)
244233
output_log "backtrace" level msg
245234
(Printf.sprintf "Raised %s" (Printexc.to_string exn)) ;

ocaml/libs/log/debug.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ val with_thread_named : string -> ('a -> 'b) -> 'a -> 'b
3131

3232
module type BRAND = sig val name : string end
3333

34-
val gettimestring : unit -> string
35-
(** The current time of day in a format suitable for logging *)
36-
3734
val set_facility : Syslog.facility -> unit
3835
(** Set the syslog facility that will be used by this program. *)
3936

ocaml/libs/log/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
fmt
1010
mtime
1111
logs
12+
ptime
13+
ptime.clock
1214
threads.posix
1315
xapi-backtrace
1416
unix

ocaml/libs/vhd/vhd_format_lwt/odirect_stubs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CAMLprim value stub_openfile_direct(value filename, value rw, value perm){
3636

3737
const char *filename_c = strdup(String_val(filename));
3838

39-
caml_release_runtime_system();
39+
int perm_c = Int_val(perm);
4040
int flags = 0;
4141
#if defined(O_DIRECT)
4242
flags |= O_DIRECT;
@@ -46,7 +46,8 @@ CAMLprim value stub_openfile_direct(value filename, value rw, value perm){
4646
} else {
4747
flags |= O_RDONLY;
4848
}
49-
fd = open(filename_c, flags, Int_val(perm));
49+
caml_release_runtime_system();
50+
fd = open(filename_c, flags, perm_c);
5051
caml_acquire_runtime_system();
5152

5253
free((void*)filename_c);

ocaml/libs/xapi-stdext/lib/xapi-stdext-std/listext.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ module List = struct
8686
in
8787
loop [] l
8888

89+
let try_map_collect f l =
90+
let rec loop acc = function
91+
| [] ->
92+
Ok (List.rev acc)
93+
| x :: xs -> (
94+
match f x with
95+
| Ok r ->
96+
loop (r :: acc) xs
97+
| Error e ->
98+
Error (List.rev acc, e)
99+
)
100+
in
101+
loop [] l
102+
89103
let take n list =
90104
let rec loop i acc = function
91105
| x :: xs when i < n ->

ocaml/libs/xapi-stdext/lib/xapi-stdext-std/listext.mli

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ module List : sig
4040
(** [last l] returns the last element of [l] or None if [l] is empty *)
4141

4242
val try_map : ('a -> ('b, 'c) result) -> 'a list -> ('b list, 'c) result
43-
(** [try_map f l] applies [f] to all elements of [l] in turn. Returns the
44-
first [Error] result encountered or, if no errors were produced, returns
45-
all the [Ok] results. *)
43+
(** [try_map f l] applies [f] to elements of [l] in turn. Returns the first
44+
[Error] result encountered or, if no errors were produced, returns all
45+
the [Ok] results. *)
46+
47+
val try_map_collect :
48+
('a -> ('b, 'c) result) -> 'a list -> ('b list, 'b list * 'c) result
49+
(** [try_map_collect f l] applies [f] to elements of [l] in turn. Returns all
50+
the [Ok] results, and the first [Error] result encountered, if it is
51+
encountered. *)
4652

4753
val rev_mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
4854
(** [rev_map f l] gives the same result as {!Stdlib.List.rev}[ (]

0 commit comments

Comments
 (0)