tools: ynl-gen: use enum names in op strmap more carefully
authorJakub Kicinski <kuba@kernel.org>
Wed, 7 Jun 2023 20:23:54 +0000 (13:23 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 8 Jun 2023 21:01:10 +0000 (14:01 -0700)
In preparation for supporting families which use different msg
ids to and from the kernel - make sure the ids in op strmap
are correct. The map is expected to be used mostly for notifications,
don't generate a separate map for the "to kernel" direction.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/generated/fou-user.c
tools/net/ynl/lib/nlspec.py
tools/net/ynl/ynl-gen-c.py

index c99b5d4..a0f33bb 100644 (file)
@@ -16,7 +16,6 @@
 
 /* Enums */
 static const char * const fou_op_strmap[] = {
-       [FOU_CMD_UNSPEC] = "unspec",
        [FOU_CMD_ADD] = "add",
        [FOU_CMD_DEL] = "del",
        [FOU_CMD_GET] = "get",
index ada22b0..bd5da8a 100644 (file)
@@ -442,6 +442,10 @@ class SpecFamily(SpecElement):
             else:
                 raise Exception("Can't parse directional ops")
 
+            if req_val == req_val_next:
+                req_val = None
+            if rsp_val == rsp_val_next:
+                rsp_val = None
             op = self.new_operation(elem, req_val, rsp_val)
             req_val = req_val_next
             rsp_val = rsp_val_next
index c073407..8a0abf9 100755 (executable)
@@ -1220,7 +1220,11 @@ def put_op_name(family, cw):
     map_name = f'{family.name}_op_strmap'
     cw.block_start(line=f"static const char * const {map_name}[] =")
     for op_name, op in family.msgs.items():
-        cw.p(f'[{op.enum_name}] = "{op_name}",')
+        if op.rsp_value:
+            if op.req_value == op.rsp_value:
+                cw.p(f'[{op.enum_name}] = "{op_name}",')
+            else:
+                cw.p(f'[{op.rsp_value}] = "{op_name}",')
     cw.block_end(line=';')
     cw.nl()