Skip to content

Commit 6258405

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 6258405

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 32 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,34 @@ 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
2363+
"%s: Two or more Parallel atoms found, use Nested_parallel for the \
2364+
inner atom"
2365+
msg_prefix ;
2366+
true
2367+
) else
2368+
List.exists (check_nesting_inner true found_nested) rem
2369+
| Nested_parallel (_, _, rem) ->
2370+
if found_nested then (
2371+
warn
2372+
"%s: Two or more Nested_parallel atoms found, there should only be \
2373+
one layer of nesting"
2374+
msg_prefix ;
2375+
true
2376+
) else
2377+
List.exists (check_nesting_inner found_parallel true) rem
2378+
| Serial (_, _, rem) ->
2379+
List.exists (check_nesting_inner found_parallel found_nested) rem
2380+
| _ ->
2381+
false
2382+
in
2383+
ignore @@ check_nesting_inner false false atom
2384+
23552385
and parallel_atomic ~progress_callback ~description ~nested atoms t =
23562386
(* parallel_id is a unused unique name prefix for a parallel worker queue *)
23572387
let redirector =

0 commit comments

Comments
 (0)