tools: ynl-gen: consider dump ops without a do "type-consistent"

If the type for the response to do and dump are the same we don't
generate it twice. This is called "type_consistent" in the generator.
Consider operations which only have dump to also be consistent.
This removes unnecessary "_dump" from the names. There's a number
of GET ops in classic Netlink which only have dump handlers.

Make sure we output the "onesided" types, normally if the type
is consistent we only output it when we render the do structures.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20250410014658.782120-11-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski
2025-04-09 18:46:55 -07:00
parent 7e8ba0c7de
commit e8025e72aa

View File

@@ -1212,6 +1212,7 @@ class RenderInfo:
# 'do' and 'dump' response parsing is identical
self.type_consistent = True
self.type_oneside = False
if op_mode != 'do' and 'dump' in op:
if 'do' in op:
if ('reply' in op['do']) != ('reply' in op["dump"]):
@@ -1219,7 +1220,8 @@ class RenderInfo:
elif 'reply' in op['do'] and op["do"]["reply"] != op["dump"]["reply"]:
self.type_consistent = False
else:
self.type_consistent = False
self.type_consistent = True
self.type_oneside = True
self.attr_set = attr_set
if not self.attr_set:
@@ -1516,7 +1518,9 @@ def op_prefix(ri, direction, deref=False):
suffix += f"{direction_to_suffix[direction]}"
else:
if direction == 'request':
suffix += '_req_dump'
suffix += '_req'
if not ri.type_oneside:
suffix += '_dump'
else:
if ri.type_consistent:
if deref:
@@ -1995,7 +1999,7 @@ def _print_type(ri, direction, struct):
if not direction and ri.type_name_conflict:
suffix += '_'
if ri.op_mode == 'dump':
if ri.op_mode == 'dump' and not ri.type_oneside:
suffix += '_dump'
ri.cw.block_start(line=f"struct {ri.family.c_name}{suffix}")
@@ -2979,7 +2983,7 @@ def main():
ri = RenderInfo(cw, parsed, args.mode, op, 'dump')
print_req_type(ri)
print_req_type_helpers(ri)
if not ri.type_consistent:
if not ri.type_consistent or ri.type_oneside:
print_rsp_type(ri)
print_wrapped_type(ri)
print_dump_prototype(ri)
@@ -3057,7 +3061,7 @@ def main():
if 'dump' in op:
cw.p(f"/* {op.enum_name} - dump */")
ri = RenderInfo(cw, parsed, args.mode, op, "dump")
if not ri.type_consistent:
if not ri.type_consistent or ri.type_oneside:
parse_rsp_msg(ri, deref=True)
print_req_free(ri)
print_dump_type_free(ri)