Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
67882eb
Rewrite fail function to support format and argument
freddy77 Apr 26, 2024
4ec1170
Use fail instead of failwith if possible
freddy77 Apr 27, 2024
8f7f7a0
Compute exe variable just once
freddy77 Apr 24, 2024
2eb5251
Fix file descriptor leak in case safe_close_and_exec fails
freddy77 Apr 26, 2024
3dcd8df
Use /proc/self instead of /proc/%d and pid if possible
freddy77 Apr 27, 2024
e8f9090
tracing: add missing locks on read
edwintorok Apr 29, 2024
75131fb
tracing: replace global ref with Atomic
edwintorok Apr 29, 2024
7a350e6
CP-48195: Set `Tracing.observe` default to `false`
GabrielBuica Apr 23, 2024
0a3b936
CP-48195: Add unit tests for `tracing` library.
GabrielBuica May 2, 2024
a0c84e5
CP-48195: Remove code duplication.
GabrielBuica Apr 30, 2024
43e26f3
CP-48195: Tracing -- Move `create`\`set`\`destroy`\...
GabrielBuica May 2, 2024
c1bd0e3
CP-48027: Corosync upgrade add `cluster_stack_version` datamodel change
Vincent-lau Apr 18, 2024
f90a96e
CP-48027: Unittest file change for cluster_interface
Vincent-lau Apr 18, 2024
9d20179
CP-48027: Add FIST point to allow Corosync2 cluster
Vincent-lau Apr 17, 2024
d00c393
CP-48027: Add feature flag for corosync3
Vincent-lau Apr 17, 2024
26712bb
Add option to disable fileserver in XAPI conf
benjamreis May 2, 2024
7574a4f
CA-392930: Fixed exception handling which prevents the user from revi…
May 15, 2024
88f0b83
Added Debug profiles to the Powershell project.
May 15, 2024
5b86ed8
Avoids calling Unix.readlink twice
freddy77 Apr 28, 2024
c6ec81b
Merge pull request #5608 from xcp-ng/disable-fileserver-option
psafont May 16, 2024
db31267
CA-392836,CA-392847: Lost the power state on suspended VM import
minglumlu May 15, 2024
011b286
Merge pull request #5636 from kc284/master
May 17, 2024
7666f7e
CP-49029: Instrument `xapi_session.ml` with tracing
GabrielBuica May 7, 2024
772b6cb
Merge pull request #5567 from Vincent-lau/private/shul2/corosync3-basic
Vincent-lau May 20, 2024
a0a1e72
Merge pull request #5632 from minglumlu/private/mingl/CA-392836
robhoes May 21, 2024
43e710b
CP-49635: Add FIST point for corosync upgrade
Vincent-lau May 21, 2024
9a816d1
CP-49429 add IPv6 support for winbind/KDC
May 17, 2024
a1fbd85
CP-49429 store KDC in xapi as URI
May 21, 2024
568323b
Merge pull request #5612 from GabrielBuica/private/dbuica/CP-48195-tr…
psafont May 22, 2024
09d0a3e
Merge pull request #5596 from freddy77/leak_fd
robhoes May 22, 2024
d127cdd
Merge pull request #5647 from Vincent-lau/private/shul2/corosync3-upg…
Vincent-lau May 22, 2024
84c8f1c
CA-391381: Avoid errors for Partial Callables in observer.py
snwoods Apr 6, 2024
340c068
xapi-tracing: bind its test to the package
psafont May 24, 2024
adefd02
opam: generate xapi-tracing with dune
psafont May 24, 2024
67bce1e
opam: generate xapi-tracing-export with dune
psafont May 24, 2024
fe975bc
opam: generate rrdd-plugin with dune
psafont May 24, 2024
4264ed3
opam: generate xapi-rrd-transport-utils with dune
psafont May 24, 2024
468a0f7
opam: generate xapi-rrdd with dune
psafont May 24, 2024
74595dd
opam: drop xapi-rrd-transport
psafont May 24, 2024
64f3c92
opam: drop xen-api-sdk
psafont May 24, 2024
72dbbf3
Merge pull request #5651 from psafont/test-tracing
psafont May 24, 2024
cc4a203
Merge pull request #5638 from snwoods/private/stevenwo/CA-391381
bernhardkaindl May 24, 2024
e35eeb2
Revert "CP-47660 define anti-affinity feature"
LunfanZhang May 28, 2024
c0e5dc4
Remove CVM and relevant test cases (#5655)
minglumlu May 30, 2024
09158bc
Merge pull request #5654 from LunfanZhang/private/luzhan/CP-49668
robhoes May 30, 2024
b5a2f96
Merge branch 'master' into private/mingl/merge_master_to_feature
minglumlu May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
77 changes: 69 additions & 8 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
(name xml-light2)
)

(package
(name xen-api-sdk)
)

(package
(name xen-api-client-lwt)
)
Expand Down Expand Up @@ -65,10 +61,37 @@

(package
(name xapi-tracing)
(depends
ocaml
dune
(alcotest :with-test)
re
uri
(uuid :with-test)
(xapi-log :version)
(xapi-stdext-threads :version)
)
(synopsis "Allows to instrument code to generate tracing information")
(description "This library provides modules to allow gathering runtime traces.")
)

(package
(name xapi-tracing-export)
(depends
ocaml
cohttp-posix
dune
cohttp
rpclib
(xapi-log :version)
(xapi-open-uri :version)
(xapi-stdext-threads :version)
(xapi-stdext-unix :version)
(xapi-tracing :version)
(zstd :version)
)
(synopsis "Export traces in multiple protocols and formats")
(description "This library export traces is able to push traces to http endpoints or generate compressed tarballs in the filesystem.")
)

(package
Expand All @@ -93,18 +116,56 @@

(package
(name rrdd-plugin)
(synopsis "A plugin library for the xapi performance monitoring daemon")
(description "This library allows one to expose a datasource which can then be sampled by the performance monitoring daemon.")
(depends
ocaml
astring
rpclib
(xapi-forkexecd :version)
(xapi-stdext-pervasives :version)
(xapi-stdext-std :version)
(xapi-stdext-threads :version)
(xapi-stdext-unix :version)
(xapi-idl :version)
xenstore_transport
)
)

(package
(name xapi-rrdd)
(synopsis "Performance monitoring daemon for xapi")
(description "This daemon monitors 'datasources' i.e. time-varying values such as performance counters and records the samples in RRD archives. These archives can be used to examine historical performance trends.")
(depends
(ocaml (>= "4.02.0"))
dune-build-info
astring
(gzip :version)
(http-lib :version)
inotify
io-page
mtime
ppx_deriving_rpc
rpclib
systemd
(ezxenstore :version)
(uuid :version)
(xapi-backtrace :version)
(xapi-idl :version)
(xapi-rrd :version)
(xapi-stdext-threads :version)
)
)

(package
(name xapi-rrd-transport-utils)
)

(package
(name xapi-rrd-transport)
(synopsis "Shared-memory protocols for exposing performance counters")
(description "VMs running on a Xen host can use this library to expose performance counters which can be sampled by the xapi performance monitoring daemon.")
(authors "John Else")
(depends
ocaml
cmdliner
)
)

(package
Expand Down
7 changes: 6 additions & 1 deletion ocaml/forkexecd/lib/forkhelpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ let safe_close_and_exec ?tracing ?env stdin stdout stderr
let fds_to_close = ref [] in

let add_fd_to_close_list fd = fds_to_close := fd :: !fds_to_close in
(* let remove_fd_from_close_list fd = fds_to_close := List.filter (fun fd' -> fd' <> fd) !fds_to_close in *)
let remove_fd_from_close_list fd =
fds_to_close := List.filter (fun fd' -> fd' <> fd) !fds_to_close
in
let close_fds () = List.iter (fun fd -> Unix.close fd) !fds_to_close in

add_fd_to_close_list sock ;

finally
(fun () ->
let maybe_add_id_to_fd_map id_to_fd_map (uuid, fd, v) =
Expand Down Expand Up @@ -290,6 +294,7 @@ let safe_close_and_exec ?tracing ?env stdin stdout stderr
Fecomms.write_raw_rpc ?tracing sock Fe.Exec ;
match Fecomms.read_raw_rpc ?tracing sock with
| Ok (Fe.Execed pid) ->
remove_fd_from_close_list sock ;
(sock, pid)
| Ok status ->
let msg =
Expand Down
113 changes: 69 additions & 44 deletions ocaml/forkexecd/test/fe_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ let min_fds = 7

let max_fds = 1024 - 13 (* fe daemon has a bunch for its own use *)

let fail x =
Xapi_stdext_unix.Unixext.write_string_to_file "/tmp/fe-test.log" x ;
Printf.fprintf stderr "%s\n" x ;
assert false

let fail fmt = Format.ksprintf fail fmt

let all_combinations fds =
let y =
{
Expand Down Expand Up @@ -68,8 +75,26 @@ let shuffle x =
done ;
Array.to_list arr

let fds_fold f init =
let path = "/proc/self/fd" in
(* get rid of the fd used to read the directory *)
Array.fold_right
(fun fd_num acc ->
try
let link = Unix.readlink (Filename.concat path fd_num) in
f fd_num link acc
with _ -> acc
)
(Sys.readdir path) init

let fd_list () = fds_fold (fun fd_num link l -> (fd_num, link) :: l) []

let fd_count () = fds_fold (fun _ _ n -> n + 1) 0

let irrelevant_strings = ["irrelevant"; "not"; "important"]

let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ())

let one fds x =
(*Printf.fprintf stderr "named_fds = %d\n" x.named_fds;
Printf.fprintf stderr "extra = %d\n" x.extra;*)
Expand All @@ -82,7 +107,6 @@ let one fds x =
let number_of_extra = x.extra in
let other_names = make_names number_of_extra in

let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ()) in
let table =
(fun x -> List.combine x (List.map (fun _ -> fd) x)) (names @ other_names)
in
Expand All @@ -107,7 +131,6 @@ let one fds x =

let test_delay () =
let start = Unix.gettimeofday () in
let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ()) in
let args = ["sleep"] in
(* Need to have fractional part because some internal usage split integer
and fractional and do computation.
Expand All @@ -117,7 +140,7 @@ let test_delay () =
let timeout = 1.7 in
try
Forkhelpers.execute_command_get_output ~timeout exe args |> ignore ;
failwith "Failed to timeout"
fail "Failed to timeout"
with
| Forkhelpers.Subprocess_timeout ->
let elapsed = Unix.gettimeofday () -. start in
Expand All @@ -127,39 +150,25 @@ let test_delay () =
if elapsed > timeout +. 0.2 then
failwith "Excessive time elapsed"
| e ->
failwith
(Printf.sprintf "Failed with unexpected exception: %s"
(Printexc.to_string e)
)
fail "Failed with unexpected exception: %s" (Printexc.to_string e)

let test_notimeout () =
let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ()) in
let args = ["sleep"] in
try
Forkhelpers.execute_command_get_output exe args |> ignore ;
()
with e ->
failwith
(Printf.sprintf "Failed with unexpected exception: %s"
(Printexc.to_string e)
)

let fail x =
Xapi_stdext_unix.Unixext.write_string_to_file "/tmp/fe-test.log" x ;
Printf.fprintf stderr "%s\n" x ;
assert false
with e -> fail "Failed with unexpected exception: %s" (Printexc.to_string e)

let expect expected s =
if s <> expected ^ "\n" then
fail (Printf.sprintf "output %s expected %s" s expected)
fail "output %s expected %s" s expected

let test_exitcode () =
let run_expect cmd expected =
try Forkhelpers.execute_command_get_output cmd [] |> ignore
with Forkhelpers.Spawn_internal_error (_, _, Unix.WEXITED n) ->
if n <> expected then
fail
(Printf.sprintf "%s exited with code %d, expected %d" cmd n expected)
fail "%s exited with code %d, expected %d" cmd n expected
in
run_expect "/bin/false" 1 ;
run_expect "/bin/xe-fe-test-no-command" 127 ;
Expand All @@ -168,7 +177,6 @@ let test_exitcode () =
Printf.printf "\nCompleted exitcode tests\n"

let test_output () =
let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ()) in
let expected_out = "output string" in
let expected_err = "error string" in
let args = ["echo"; expected_out; expected_err] in
Expand All @@ -178,7 +186,6 @@ let test_output () =
print_endline "Completed output tests"

let test_input () =
let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ()) in
let input = "input string" in
let args = ["replay"] in
let out, _ =
Expand All @@ -187,6 +194,38 @@ let test_input () =
expect input out ;
print_endline "Completed input tests"

(* This test tests a failure inside Forkhelpers.safe_close_and_exec.
Although the exact way of this reproduction is never supposed to
happen in the real world, an internal failure could happen for instance
if forkexecd daemon is restarted for a moment, so make sure we are
able to detect and handle these cases *)
let test_internal_failure_error () =
let initial_fd_count = fd_count () in
let leak_fd_detect () =
let current_fd_count = fd_count () in
if current_fd_count <> initial_fd_count then
fail "File descriptor leak detected initially %d files, now %d"
initial_fd_count current_fd_count
in
(* this weird function will open and close "num" file descriptors
and returns the last (now closed) of them, mainly to get an invalid
file descriptor with some closed one before *)
let rec waste_fds num =
let fd = Unix.openfile "/dev/null" [Unix.O_WRONLY] 0o0 in
let ret = if num = 0 then fd else waste_fds (num - 1) in
Unix.close fd ; ret
in
let fd = waste_fds 20 in
let args = ["sleep"] in
try
Forkhelpers.safe_close_and_exec None (Some fd) None [] exe args |> ignore ;
fail "Expected an exception"
with
| Fd_send_recv.Unix_error _ ->
leak_fd_detect ()
| e ->
fail "Failed with unexpected exception: %s" (Printexc.to_string e)

let master fds =
Printf.printf "\nPerforming timeout tests\n%!" ;
test_delay () ;
Expand All @@ -196,6 +235,8 @@ let master fds =
Printf.printf "\nPerforming input/output tests\n%!" ;
test_output () ;
test_input () ;
Printf.printf "\nPerforming internal failure test\n%!" ;
test_internal_failure_error () ;
let combinations = shuffle (all_combinations fds) in
Printf.printf "Starting %d tests\n%!" (List.length combinations) ;
let i = ref 0 in
Expand All @@ -215,28 +256,14 @@ let master fds =

let slave = function
| [] ->
failwith "Error, at least one fd expected"
fail "Error, at least one fd expected"
| total_fds :: rest ->
let total_fds = int_of_string total_fds in
let fds =
List.filter (fun x -> not (List.mem x irrelevant_strings)) rest
in
(* Check that these fds are present *)
let pid = Unix.getpid () in
let path = Printf.sprintf "/proc/%d/fd" pid in
let raw =
List.filter (* get rid of the fd used to read the directory *)
(fun x ->
try
ignore (Unix.readlink (Filename.concat path x)) ;
true
with _ -> false
)
(Array.to_list (Sys.readdir path))
in
let pairs =
List.map (fun x -> (x, Unix.readlink (Filename.concat path x))) raw
in
let pairs = fd_list () in
(* Filter any of stdin,stdout,stderr which have been mapped to /dev/null *)
let filtered =
List.filter
Expand All @@ -257,18 +284,16 @@ let slave = function
List.iter
(fun fd ->
if not (List.mem fd (List.map fst filtered)) then
fail (Printf.sprintf "fd %s not in /proc/%d/fd [ %s ]" fd pid ls)
fail "fd %s not in /proc/self/fd [ %s ]" fd ls
)
fds ;
(* Check that we have the expected number *)
(*
Printf.fprintf stderr "%s %d\n" total_fds (List.length present - 1)
*)
if total_fds <> List.length filtered then
fail
(Printf.sprintf "Expected %d fds; /proc/%d/fd has %d: %s" total_fds
pid (List.length filtered) ls
)
fail "Expected %d fds; /proc/self/fd has %d: %s" total_fds
(List.length filtered) ls

let sleep () = Unix.sleep 3 ; Printf.printf "Ok\n"

Expand Down
6 changes: 6 additions & 0 deletions ocaml/idl/datamodel_cluster.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ let t =
(Some (VString Constants.default_smapiv3_cluster_stack))
"Simply the string 'corosync'. No other cluster stacks are \
currently supported"
; field ~qualifier:StaticRO ~lifecycle ~ty:Int "cluster_stack_version"
~default_value:(Some (VInt 2L))
"Version of cluster stack, not writable via the API. Defaulting to \
2 for backwards compatibility when upgrading from a cluster \
without this field, which means it is necessarily running version \
2 of corosync, the only cluster stack supported so far."
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool "is_quorate"
~default_value:(Some (VBool false))
"Whether the cluster stack thinks the cluster is quorate"
Expand Down
2 changes: 1 addition & 1 deletion ocaml/idl/schematest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
(* BEWARE: if this changes, check that schema has been bumped accordingly in
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)

let last_known_schema_hash = "8c3cb4546e7dc9e8d9d05c8194d8a3d6"
let last_known_schema_hash = "2b8b5b107eb465e97d35a68274ac18ef"

let current_schema_hash : string =
let open Datamodel_types in
Expand Down
6 changes: 6 additions & 0 deletions ocaml/libs/tracing/dune
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
zstd)
(preprocess
(pps ppx_deriving_rpc)))

(test
(name test_tracing)
(modules test_tracing)
(package xapi-tracing)
(libraries tracing alcotest uuid))
Loading