Skip to content

Commit 735e5a4

Browse files
authored
Merge master into feature/pool-licensing (#6234)
No conflict $ git show commit 939a3da (HEAD -> private/changleli/pool-licensing, github/private/changleli/pool-licensing) Merge: 47df335 43d01ca Author: Changlei Li <[email protected]> Date: Fri Jan 17 13:53:31 2025 +0800 Merge remote-tracking branch 'github/master' into private/changleli/pool-licensing
2 parents 47df335 + 939a3da commit 735e5a4

File tree

81 files changed

+1248
-890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1248
-890
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ jobs:
2020
python-version: "3.x"
2121

2222
- name: Install build dependencies
23-
run: |
24-
pip install build
25-
sudo apt-get install ocaml dune libfindlib-ocaml-dev libdune-ocaml-dev libcmdliner-ocaml-dev
23+
run: pip install build
2624

2725
- name: Generate python package for XenAPI
2826
run: |
29-
./configure --xapi_version=${{ github.ref_name }}
27+
echo "export XAPI_VERSION=${{ github.ref_name }}" > config.mk
3028
make python
3129
3230
- name: Store python distribution artifacts

doc/content/design/coverage/index.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ revision: 2
88

99
We would like to add optional coverage profiling to existing [OCaml]
1010
projects in the context of [XenServer] and [XenAPI]. This article
11-
presents how we do it.
11+
presents how we do it.
1212

1313
Binaries instrumented for coverage profiling in the XenServer project
1414
need to run in an environment where several services act together as
@@ -21,7 +21,7 @@ isolation.
2121
To build binaries with coverage profiling, do:
2222

2323
./configure --enable-coverage
24-
make
24+
make
2525

2626
Binaries will log coverage data to `/tmp/bisect*.out` from which a
2727
coverage report can be generated in `coverage/`:
@@ -38,7 +38,7 @@ and logs during execution data to in-memory data structures. Before an
3838
instrumented binary terminates, it writes the logged data to a file.
3939
This data can then be analysed with the `bisect-ppx-report` tool, to
4040
produce a summary of annotated code that highlights what part of a
41-
codebase was executed.
41+
codebase was executed.
4242

4343
[BisectPPX] has several desirable properties:
4444

@@ -65,13 +65,13 @@ abstracted by OCamlfind (OCaml's library manager) and OCamlbuild
6565

6666
# build it with instrumentation from bisect_ppx
6767
ocamlbuild -use-ocamlfind -pkg bisect_ppx -pkg unix example.native
68-
68+
6969
# execute it - generates files ./bisect*.out
7070
./example.native
71-
71+
7272
# generate report
7373
bisect-ppx-report -I _build -html coverage bisect000*
74-
74+
7575
# view coverage/index.html
7676

7777
Summary:
@@ -86,7 +86,7 @@ will be instrumented during compilation. Behind the scenes `ocamlfind`
8686
makes sure that the compiler uses a preprocessing step that instruments
8787
the code.
8888

89-
## Signal Handling
89+
## Signal Handling
9090

9191
During execution the code instrumentation leads to the collection of
9292
data. This code registers a function with `at_exit` that writes the data
@@ -98,7 +98,7 @@ terminated by receiving the `TERM` signal, a signal handler must be
9898
installed:
9999

100100
let stop signal =
101-
printf "caught signal %d\n" signal;
101+
printf "caught signal %a\n" Debug.Pp.signal signal;
102102
exit 0
103103

104104
Sys.set_signal Sys.sigterm (Sys.Signal_handle stop)
@@ -149,8 +149,8 @@ environment variable. This can happen on the command line:
149149

150150
BISECT_FILE=/tmp/example ./example.native
151151

152-
In the context of XenServer we could do this in startup scripts.
153-
However, we added a bit of code
152+
In the context of XenServer we could do this in startup scripts.
153+
However, we added a bit of code
154154

155155
val Coverage.init: string -> unit
156156

@@ -176,12 +176,12 @@ Goals for instrumentation are:
176176

177177
* what files are instrumented should be obvious and easy to manage
178178
* instrumentation must be optional, yet easy to activate
179-
* avoid methods that require to keep several files in sync like multiple
179+
* avoid methods that require to keep several files in sync like multiple
180180
`_oasis` files
181181
* avoid separate Git branches for instrumented and non-instrumented
182182
code
183183

184-
In the ideal case, we could introduce a configuration switch
184+
In the ideal case, we could introduce a configuration switch
185185
`./configure --enable-coverage` that would prepare compilation for
186186
coverage instrumentation. While [Oasis] supports the creation of such
187187
switches, they cannot be used to control build dependencies like
@@ -196,7 +196,7 @@ rules in file `_tags.coverage` that cause files to be instrumented:
196196

197197
leads to the execution of this code during preparation:
198198

199-
coverage: _tags _tags.coverage
199+
coverage: _tags _tags.coverage
200200
test ! -f _tags.orig && mv _tags _tags.orig || true
201201
cat _tags.coverage _tags.orig > _tags
202202

@@ -207,7 +207,7 @@ could be tweaked to instrument only some files:
207207
<**/*.native>: pkg_bisect_ppx
208208

209209
When `make coverage` is not called, these rules are not active and
210-
hence, code is not instrumented for coverage. We believe that this
210+
hence, code is not instrumented for coverage. We believe that this
211211
solution to control instrumentation meets the goals from above. In
212212
particular, what files are instrumented and when is controlled by very
213213
few lines of declarative code that lives in the main repository of a
@@ -226,14 +226,14 @@ coverage analysis are:
226226
The `_oasis` file bundles the files under `profiling/` into an internal
227227
library which executables then depend on:
228228

229-
# Support files for profiling
229+
# Support files for profiling
230230
Library profiling
231231
CompiledObject: best
232232
Path: profiling
233233
Install: false
234234
Findlibname: profiling
235235
Modules: Coverage
236-
BuildDepends:
236+
BuildDepends:
237237

238238
Executable set_domain_uuid
239239
CompiledObject: best
@@ -243,16 +243,16 @@ library which executables then depend on:
243243
MainIs: set_domain_uuid.ml
244244
Install: false
245245
BuildDepends:
246-
xenctrl,
247-
uuidm,
246+
xenctrl,
247+
uuidm,
248248
cmdliner,
249249
profiling # <-- here
250250

251251
The `Makefile` target `coverage` primes the project for a profiling build:
252252

253253
# make coverage - prepares for building with coverage analysis
254254

255-
coverage: _tags _tags.coverage
255+
coverage: _tags _tags.coverage
256256
test ! -f _tags.orig && mv _tags _tags.orig || true
257257
cat _tags.coverage _tags.orig > _tags
258258

ocaml/database/database_test.ml

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ let name_label = "name__label"
1616

1717
let name_description = "name__description"
1818

19+
let failwith_fmt fmt = Printf.ksprintf failwith fmt
20+
1921
module Tests =
2022
functor
2123
(Client : Db_interface.DB_ACCESS)
@@ -111,7 +113,7 @@ functor
111113
; where_value= ""
112114
}
113115
in
114-
failwith (Printf.sprintf "%s <invalid table>" fn_name)
116+
failwith_fmt "%s <invalid table>" fn_name
115117
) ;
116118
Printf.printf
117119
"%s <valid table> <invalid return> <valid field> <valid value>\n"
@@ -126,11 +128,9 @@ functor
126128
; where_value= name
127129
}
128130
in
129-
failwith
130-
(Printf.sprintf
131-
"%s <valid table> <invalid return> <valid field> <valid value>"
132-
fn_name
133-
)
131+
failwith_fmt
132+
"%s <valid table> <invalid return> <valid field> <valid value>"
133+
fn_name
134134
) ;
135135
Printf.printf
136136
"%s <valid table> <valid return> <invalid field> <valid value>\n"
@@ -145,11 +145,9 @@ functor
145145
; where_value= ""
146146
}
147147
in
148-
failwith
149-
(Printf.sprintf
150-
"%s <valid table> <valid return> <invalid field> <valid value>"
151-
fn_name
152-
)
148+
failwith_fmt
149+
"%s <valid table> <valid return> <invalid field> <valid value>"
150+
fn_name
153151
)
154152

155153
(* Verify the ref_index contents are correct for a given [tblname] and [key] (uuid/ref) *)
@@ -168,10 +166,9 @@ functor
168166
| Some {Ref_index.name_label= name_label'; uuid; _ref} ->
169167
(* key should be either uuid or _ref *)
170168
if key <> uuid && key <> _ref then
171-
failwith
172-
(Printf.sprintf "check_ref_index %s key %s: got ref %s uuid %s"
173-
tblname key _ref uuid
174-
) ;
169+
failwith_fmt "check_ref_index %s key %s: got ref %s uuid %s" tblname
170+
key _ref uuid ;
171+
175172
let real_ref =
176173
if Client.is_valid_ref t key then
177174
key
@@ -183,14 +180,11 @@ functor
183180
with _ -> None
184181
in
185182
if name_label' <> real_name_label then
186-
failwith
187-
(Printf.sprintf
188-
"check_ref_index %s key %s: ref_index name_label = %s; db has \
189-
%s"
190-
tblname key
191-
(Option.value ~default:"None" name_label')
192-
(Option.value ~default:"None" real_name_label)
193-
)
183+
failwith_fmt
184+
"check_ref_index %s key %s: ref_index name_label = %s; db has %s"
185+
tblname key
186+
(Option.value ~default:"None" name_label')
187+
(Option.value ~default:"None" real_name_label)
194188

195189
open Db_cache_types
196190

@@ -226,11 +220,9 @@ functor
226220
in
227221
let bar_foos = Row.find "foos" bar_1 in
228222
if bar_foos <> Set ["foo:1"] then
229-
failwith
230-
(Printf.sprintf
231-
"check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s"
232-
(Schema.Value.marshal bar_foos)
233-
) ;
223+
failwith_fmt
224+
"check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s"
225+
(Schema.Value.marshal bar_foos) ;
234226
(* set foo.bars to [] *)
235227
(* let foo_1 = Table.find "foo:1" (TableSet.find "foo" (Database.tableset db)) in*)
236228
let db = set_field "foo" "foo:1" "bars" (Set []) db in
@@ -240,11 +232,8 @@ functor
240232
in
241233
let bar_foos = Row.find "foos" bar_1 in
242234
if bar_foos <> Set [] then
243-
failwith
244-
(Printf.sprintf
245-
"check_many_to_many: bar(bar:1).foos expected () got %s"
246-
(Schema.Value.marshal bar_foos)
247-
) ;
235+
failwith_fmt "check_many_to_many: bar(bar:1).foos expected () got %s"
236+
(Schema.Value.marshal bar_foos) ;
248237
(* add 'bar' to foo.bars *)
249238
let db = set_field "foo" "foo:1" "bars" (Set ["bar:1"]) db in
250239
(* check that 'bar.foos' includes 'foo' *)
@@ -253,11 +242,9 @@ functor
253242
in
254243
let bar_foos = Row.find "foos" bar_1 in
255244
if bar_foos <> Set ["foo:1"] then
256-
failwith
257-
(Printf.sprintf
258-
"check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s - 2"
259-
(Schema.Value.marshal bar_foos)
260-
) ;
245+
failwith_fmt
246+
"check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s - 2"
247+
(Schema.Value.marshal bar_foos) ;
261248
(* delete 'bar' *)
262249
let db = remove_row "bar" "bar:1" db in
263250
(* check that 'foo.bars' is empty *)
@@ -266,11 +253,8 @@ functor
266253
in
267254
let foo_bars = Row.find "bars" foo_1 in
268255
if foo_bars <> Set [] then
269-
failwith
270-
(Printf.sprintf
271-
"check_many_to_many: foo(foo:1).foos expected () got %s"
272-
(Schema.Value.marshal foo_bars)
273-
) ;
256+
failwith_fmt "check_many_to_many: foo(foo:1).foos expected () got %s"
257+
(Schema.Value.marshal foo_bars) ;
274258
()
275259

276260
let check_events t =
@@ -503,8 +487,7 @@ functor
503487
| None ->
504488
Printf.printf "Reference '%s' has no associated table\n" invalid_ref
505489
| Some t ->
506-
failwith
507-
(Printf.sprintf "Reference '%s' exists in table '%s'" invalid_ref t)
490+
failwith_fmt "Reference '%s' exists in table '%s'" invalid_ref t
508491
) ;
509492
Printf.printf "is_valid_ref <invalid_ref>\n" ;
510493
if Client.is_valid_ref t invalid_ref then
@@ -571,15 +554,25 @@ functor
571554
Printf.printf "db_get_by_uuid <valid uuid>\n" ;
572555
let r = Client.db_get_by_uuid t "VM" valid_uuid in
573556
if r <> valid_ref then
574-
failwith
575-
(Printf.sprintf "db_get_by_uuid <valid uuid>: got %s; expected %s" r
576-
valid_ref
577-
) ;
557+
failwith_fmt "db_get_by_uuid <valid uuid>: got %s; expected %s" r
558+
valid_ref ;
578559
Printf.printf "db_get_by_uuid <invalid uuid>\n" ;
579560
expect_missing_uuid "VM" invalid_uuid (fun () ->
580561
let (_ : string) = Client.db_get_by_uuid t "VM" invalid_uuid in
581562
failwith "db_get_by_uuid <invalid uuid>"
582563
) ;
564+
Printf.printf "db_get_by_uuid_opt <valid uuid>\n" ;
565+
let r = Client.db_get_by_uuid_opt t "VM" valid_uuid in
566+
( if r <> Some valid_ref then
567+
let rs = Option.value ~default:"None" r in
568+
failwith_fmt "db_get_by_uuid_opt <valid uuid>: got %s; expected %s" rs
569+
valid_ref
570+
) ;
571+
Printf.printf "db_get_by_uuid_opt <invalid uuid>\n" ;
572+
let r = Client.db_get_by_uuid_opt t "VM" invalid_uuid in
573+
if not (Option.is_none r) then
574+
failwith_fmt "db_get_by_uuid_opt <invalid uuid>: got %s; expected None"
575+
valid_ref ;
583576
Printf.printf "get_by_name_label <invalid name label>\n" ;
584577
if Client.db_get_by_name_label t "VM" invalid_name <> [] then
585578
failwith "db_get_by_name_label <invalid name label>" ;

ocaml/database/db_remote_cache_access_v1.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ module DBCacheRemoteListener = struct
102102
let s, e = unmarshall_db_get_by_uuid_args args in
103103
success
104104
(marshall_db_get_by_uuid_response (DBCache.db_get_by_uuid t s e))
105+
| "db_get_by_uuid_opt" ->
106+
let s, e = unmarshall_db_get_by_uuid_args args in
107+
success
108+
(marshall_db_get_by_uuid_opt_response
109+
(DBCache.db_get_by_uuid_opt t s e)
110+
)
105111
| "db_get_by_name_label" ->
106112
let s, e = unmarshall_db_get_by_name_label_args args in
107113
success

ocaml/database/db_remote_cache_access_v2.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ let process_rpc (req : Rpc.t) =
3636
Response.Read_field_where (DB.read_field_where t w)
3737
| Request.Db_get_by_uuid (a, b) ->
3838
Response.Db_get_by_uuid (DB.db_get_by_uuid t a b)
39+
| Request.Db_get_by_uuid_opt (a, b) ->
40+
Response.Db_get_by_uuid_opt (DB.db_get_by_uuid_opt t a b)
3941
| Request.Db_get_by_name_label (a, b) ->
4042
Response.Db_get_by_name_label (DB.db_get_by_name_label t a b)
4143
| Request.Create_row (a, b, c) ->

ocaml/database/db_rpc_client_v2.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ functor
7878
raise Remote_db_server_returned_bad_message
7979

8080
let db_get_by_uuid_opt _ t u =
81-
match process (Request.Db_get_by_uuid (t, u)) with
81+
match process (Request.Db_get_by_uuid_opt (t, u)) with
8282
| Response.Db_get_by_uuid_opt y ->
8383
y
8484
| _ ->

ocaml/database/db_rpc_common_v1.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ let unmarshall_db_get_by_uuid_args xml = unmarshall_2strings xml
192192

193193
let marshall_db_get_by_uuid_response s = XMLRPC.To.string s
194194

195+
let marshall_db_get_by_uuid_opt_response = marshall_stringopt
196+
195197
let unmarshall_db_get_by_uuid_response xml = XMLRPC.From.string xml
196198

197199
let unmarshall_db_get_by_uuid_opt_response xml = unmarshall_stringopt xml

ocaml/database/db_rpc_common_v2.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Request = struct
2323
| Find_refs_with_filter of string * Db_filter_types.expr
2424
| Read_field_where of Db_cache_types.where_record
2525
| Db_get_by_uuid of string * string
26+
| Db_get_by_uuid_opt of string * string
2627
| Db_get_by_name_label of string * string
2728
| Create_row of string * (string * string) list * string
2829
| Delete_row of string * string

0 commit comments

Comments
 (0)