tools: ynl-gen: stop generating common notification handlers

Common notification handler was supposed to be a way for the user
to parse the notifications from a socket synchronously.
I don't think we'll end up using it, ynl_ntf_check() works for
all known use cases.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2023-06-08 14:11:55 -07:00
parent 7234415b8f
commit f2ba1e5e22

View File

@ -1810,70 +1810,6 @@ def print_ntf_type_free(ri):
ri.cw.nl()
def print_ntf_parse_prototype(family, cw, suffix=';'):
cw.write_func_prot('struct ynl_ntf_base_type *', f"{family['name']}_ntf_parse",
['struct ynl_sock *ys'], suffix=suffix)
def print_ntf_type_parse(family, cw, ku_mode):
print_ntf_parse_prototype(family, cw, suffix='')
cw.block_start()
cw.write_func_lvar(['struct genlmsghdr *genlh;',
'struct nlmsghdr *nlh;',
'struct ynl_parse_arg yarg = { .ys = ys, };',
'struct ynl_ntf_base_type *rsp;',
'int len, err;',
'mnl_cb_t parse;'])
cw.p('len = mnl_socket_recvfrom(ys->sock, ys->rx_buf, MNL_SOCKET_BUFFER_SIZE);')
cw.p('if (len < (ssize_t)(sizeof(*nlh) + sizeof(*genlh)))')
cw.p('return NULL;')
cw.nl()
cw.p('nlh = (struct nlmsghdr *)ys->rx_buf;')
cw.p('genlh = mnl_nlmsg_get_payload(nlh);')
cw.nl()
cw.block_start(line='switch (genlh->cmd)')
for ntf_op in sorted(family.all_notify.keys()):
op = family.ops[ntf_op]
ri = RenderInfo(cw, family, ku_mode, op, ntf_op, "notify")
for ntf in op['notify']['cmds']:
cw.p(f"case {ntf.enum_name}:")
cw.p(f"rsp = calloc(1, sizeof({type_name(ri, 'notify')}));")
cw.p(f"parse = {op_prefix(ri, 'reply', deref=True)}_parse;")
cw.p(f"yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
cw.p(f"rsp->free = (void *){op_prefix(ri, 'notify')}_free;")
cw.p('break;')
for op_name, op in family.ops.items():
if 'event' not in op:
continue
ri = RenderInfo(cw, family, ku_mode, op, op_name, "event")
cw.p(f"case {op.enum_name}:")
cw.p(f"rsp = calloc(1, sizeof({type_name(ri, 'event')}));")
cw.p(f"parse = {op_prefix(ri, 'reply', deref=True)}_parse;")
cw.p(f"yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
cw.p(f"rsp->free = (void *){op_prefix(ri, 'notify')}_free;")
cw.p('break;')
cw.p('default:')
cw.p('ynl_error_unknown_notification(ys, genlh->cmd);')
cw.p('return NULL;')
cw.block_end()
cw.nl()
cw.p('yarg.data = rsp->data;')
cw.nl()
cw.p(f"err = {cw.nlib.parse_cb_run('parse', '&yarg', True)};")
cw.p('if (err < 0)')
cw.p('goto err_free;')
cw.nl()
cw.p('rsp->family = nlh->nlmsg_type;')
cw.p('rsp->cmd = genlh->cmd;')
cw.p('return rsp;')
cw.nl()
cw.p('err_free:')
cw.p('free(rsp);')
cw.p('return NULL;')
cw.block_end()
cw.nl()
def print_req_policy_fwd(cw, struct, ri=None, terminate=True):
if terminate and ri and kernel_can_gen_family_struct(struct.family):
return
@ -2513,10 +2449,6 @@ def main():
print_rsp_type(ri)
cw.nl()
print_wrapped_type(ri)
if parsed.has_notifications():
cw.p('/* --------------- Common notification parsing --------------- */')
print_ntf_parse_prototype(parsed, cw)
cw.nl()
else:
cw.p('/* Enums */')
@ -2580,11 +2512,6 @@ def main():
ri = RenderInfo(cw, parsed, args.mode, op, op_name, "event")
print_ntf_type_free(ri)
if parsed.has_notifications():
cw.p('/* --------------- Common notification parsing --------------- */')
print_ntf_type_parse(parsed, cw, args.mode)
cw.nl()
render_user_family(parsed, cw, False)