---
generator/generator | 35 ++++++++++++++++++++++++++++++++++-
lib/internal.h | 1 +
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/generator/generator b/generator/generator
index be37fd1..f665475 100755
--- a/generator/generator
+++ b/generator/generator
@@ -2209,7 +2209,40 @@ let generate_lib_states_c () =
pr " default:\n";
pr " abort (); /* Should never happen, but keeps GCC happy. */\n";
pr " }\n";
- pr "}\n"
+ pr "}\n";
+ pr "\n";
+
+ pr "/* Map a state group to its parent group. */\n";
+ pr "enum state_group\n";
+ pr "nbd_internal_state_group_parent (enum state_group group)\n";
+ pr "{\n";
+ pr " switch (group) {\n";
+ pr " case GROUP_TOP:\n";
+ pr " return GROUP_TOP;\n";
+ let rec loop prefix = function
+ | [] -> ()
+ | State _ :: rest ->
+ loop prefix rest
+ | Group (name, group) :: rest ->
+ let enum =
+ "GROUP" ^ String.concat "" (List.map ((^) "_")
prefix) ^ "_" ^ name in
+ pr " case %s:\n" enum;
+ if prefix = [] then
+ pr " return GROUP_TOP;\n"
+ else (
+ let parent = "GROUP" ^ String.concat "" (List.map ((^)
"_") prefix) in
+ pr " return %s;\n" parent
+ );
+ loop (prefix @ [name]) group;
+ loop prefix rest
+ in
+ loop [] state_machine;
+ pr " default:\n";
+ pr " abort (); /* Should never happen, but keeps GCC happy. */\n";
+ pr " }\n";
+ pr "};\n"
+
+
(*----------------------------------------------------------------------*)
diff --git a/lib/internal.h b/lib/internal.h
index 3f2b729..1f742da 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -273,6 +273,7 @@ extern int nbd_internal_run (struct nbd_handle *h, struct
nbd_connection *conn,
enum external_event ev);
extern const char *nbd_internal_state_short_string (enum state state);
extern enum state_group nbd_internal_state_group (enum state state);
+extern enum state_group nbd_internal_state_group_parent (enum state_group group);
/* utils.c */
extern void nbd_internal_hexdump (const void *data, size_t len, FILE *fp);
--
2.21.0