Skip to content

Commit 93c5b97

Browse files
committed
CA-409510: Give a warning if atoms nested incorrectly
This is a stopgap until we add compile-time constraints on the nesting, by for example using a polymorphic variant. Signed-off-by: Steven Woods <[email protected]>
1 parent cedf836 commit 93c5b97

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,9 +1920,11 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
19201920
debug "Ignoring error during best-effort operation: %s"
19211921
(Printexc.to_string e)
19221922
)
1923-
| Parallel (_id, description, atoms) ->
1923+
| Parallel (_id, description, atoms) as atom ->
1924+
check_nesting atom ;
19241925
parallel_atomic ~progress_callback ~description ~nested:false atoms t
1925-
| Nested_parallel (_id, description, atoms) ->
1926+
| Nested_parallel (_id, description, atoms) as atom ->
1927+
check_nesting atom ;
19261928
parallel_atomic ~progress_callback ~description ~nested:true atoms t
19271929
| Serial (_, _, atoms) ->
19281930
List.iter (Fun.flip (perform_atomic ~progress_callback) t) atoms
@@ -2352,6 +2354,30 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
23522354
debug "VM.soft_reset %s" id ;
23532355
B.VM.soft_reset t (VM_DB.read_exn id)
23542356

2357+
and check_nesting atom =
2358+
let msg_prefix = "Nested atomics error" in
2359+
let rec check_nesting_inner found_parallel found_nested = function
2360+
| Parallel (_, _, rem) -> (
2361+
if found_parallel then (
2362+
warn "%s: Two or more Parallel atoms found, use Nested_parallel for the inner atom" msg_prefix;
2363+
true
2364+
) else
2365+
List.exists (check_nesting_inner true found_nested) rem
2366+
)
2367+
| Nested_parallel (_, _, rem) -> (
2368+
if found_nested then (
2369+
warn "%s: Two or more Nested_parallel atoms found, there should only be one layer of nesting" msg_prefix ;
2370+
true
2371+
) else
2372+
List.exists (check_nesting_inner found_parallel true) rem
2373+
)
2374+
| Serial (_, _, rem) -> (
2375+
List.exists (check_nesting_inner found_parallel found_nested) rem
2376+
)
2377+
| _ -> false
2378+
in
2379+
ignore @@ check_nesting_inner false false atom
2380+
23552381
and parallel_atomic ~progress_callback ~description ~nested atoms t =
23562382
(* parallel_id is a unused unique name prefix for a parallel worker queue *)
23572383
let redirector =

0 commit comments

Comments
 (0)