devlink: use spec to generate split ops
Subsystems (4)
Jiri Pirko
maintainerv3 cover devlink: use spec to generate split ops
From: Jiri Pirko <[email protected]>
This is an outcome of the discussion in the following thread:
https://lore.kernel.org/netdev/[email protected]/
It serves as a dependency on the linked selector patchset.
There is an existing spec for devlink used for userspace part generation. There are two commands supported there.
This patchset extends the spec so kernel split ops code could be generated from it.
---v2->v3:
- reordered a bit to avoid build break, small changes to fix that
- see individual patches for changelogv1->v2:
- see individual patches for changelog
Jiri Pirko (12):
netlink: specs: add dump-strict flag for dont-validate property ynl-gen-c.py: filter rendering of validate field values for split ops ynl-gen-c.py: allow directional model for kernel mode ynl-gen-c.py: render netlink policies static for split ops
devlink: rename devlink_nl_ops to devlink_nl_small_ops
devlink: rename couple of doit netlink callbacks to match generated
names
devlink: introduce couple of dumpit callbacks for split ops
devlink: un-static devlink_nl_pre/post_doit()
netlink: specs: devlink: add info-get dump op
devlink: add split ops generated according to spec
devlink: include the generated netlink header
devlink: use generated split ops and remove duplicated commands from
small ops
Documentation/netlink/genetlink-c.yaml | 2 +- Documentation/netlink/genetlink-legacy.yaml | 2 +- Documentation/netlink/genetlink.yaml | 2 +- Documentation/netlink/specs/devlink.yaml | 14 ++++- net/devlink/Makefile | 2 +- net/devlink/dev.c | 26 ++++----- net/devlink/devl_internal.h | 20 +++---- net/devlink/leftover.c | 16 +----- net/devlink/netlink.c | 35 ++++++------ net/devlink/netlink_gen.c | 59 +++++++++++++++++++++ net/devlink/netlink_gen.h | 29 ++++++++++ tools/net/ynl/generated/devlink-user.c | 53 ++++++++++++++++++ tools/net/ynl/generated/devlink-user.h | 10 ++++ tools/net/ynl/ynl-gen-c.py | 20 +++++-- 14 files changed, 230 insertions(+), 60 deletions(-) create mode 100644 net/devlink/netlink_gen.c create mode 100644 net/devlink/netlink_gen.h
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 1/12 netlink: specs: add dump-strict flag for dont-validate property
From: Jiri Pirko <[email protected]>
Allow user to specify GENL_DONT_VALIDATE_DUMP_STRICT flag for validation and add this flag to netlink spec schema.
---v1->v2:
- new patch
--- Documentation/netlink/genetlink-c.yaml | 2 +- Documentation/netlink/genetlink-legacy.yaml | 2 +- Documentation/netlink/genetlink.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Documentation/netlink/genetlink-c.yaml +1 -1
@@ -274,7 +274,7 @@ properties: description: Kernel attribute validation flags. type: array items: - enum: [ strict, dump ] + enum: [ strict, dump, dump-strict ] do: &subop-type description: Main command handler. type: object
Documentation/netlink/genetlink-legacy.yaml +1 -1
@@ -321,7 +321,7 @@ properties: description: Kernel attribute validation flags. type: array items: - enum: [ strict, dump ] + enum: [ strict, dump, dump-strict ] # Start genetlink-legacy fixed-header: *fixed-header # End genetlink-legacy
Documentation/netlink/genetlink.yaml +1 -1
@@ -243,7 +243,7 @@ properties: description: Kernel attribute validation flags. type: array items: - enum: [ strict, dump ] + enum: [ strict, dump, dump-strict ] do: &subop-type description: Main command handler. type: object
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 2/12 ynl-gen-c.py: filter rendering of validate field values for split ops
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
For split ops, do and dump has different meaningful values in validate field.
Fix the rendering to allow the values per op type as follows:
do: strict
dump: dump, strict-dump
---v1->v2:
- consider strict-dump flag newly added by the previous patch
- re-phrased the commit message, altered the patch subject a bit
--- tools/net/ynl/ynl-gen-c.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +9 -1
@@ -1988,9 +1988,17 @@ def print_kernel_op_table(family, cw): cw.block_start() members = [('cmd', op.enum_name)] if 'dont-validate' in op: + dont_validate = [] + for x in op['dont-validate']: + if op_mode == 'do' and x in ['dump', 'dump-strict']: + continue + if op_mode == "dump" and x == 'strict': + continue + dont_validate.append(x) + members.append(('validate', ' | '.join([c_upper('genl-dont-validate-' + x) - for x in op['dont-validate']])), ) + for x in dont_validate])), ) name = c_lower(f"{family.name}-nl-{op_name}-{op_mode}it") if 'pre' in op[op_mode]: members.append((cb_names[op_mode]['pre'], c_lower(op[op_mode]['pre'])))
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 3/12 ynl-gen-c.py: allow directional model for kernel mode
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Directional model limitation is only applicable for uapi mode. For kernel mode, the code is generated correctly using right cmd values for do/dump requests. Lift the limitation.
---v2->v3:
- fixed double space issuev1->v2:
- re-phrased the patch description
--- tools/net/ynl/ynl-gen-c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +1 -1
@@ -2317,7 +2317,7 @@ def main(): return supported_models = ['unified'] - if args.mode == 'user': + if args.mode in ['user', 'kernel']: supported_models += ['directional'] if parsed.msg_id_model not in supported_models: print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 4/12 ynl-gen-c.py: render netlink policies static for split ops
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
When policies are rendered for split ops, they are consumed in the same file. No need to expose them for user outside, make them static.
---v1->v2:
- new patch
--- tools/net/ynl/ynl-gen-c.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/net/ynl/ynl-gen-c.py +6 -2
@@ -1843,13 +1843,13 @@ def print_ntf_type_free(ri): def print_req_policy_fwd(cw, struct, ri=None, terminate=True): - if terminate and ri and kernel_can_gen_family_struct(struct.family): + if terminate and ri and policy_should_be_static(struct.family): return if terminate: prefix = 'extern ' else: - if kernel_can_gen_family_struct(struct.family) and ri: + if ri and policy_should_be_static(struct.family): prefix = 'static ' else: prefix = ''
@@ -1877,6 +1877,10 @@ def kernel_can_gen_family_struct(family): return family.proto == 'genetlink' +def policy_should_be_static(family): + return family.kernel_policy == 'split' or kernel_can_gen_family_struct(family) + + def print_kernel_op_table_fwd(family, cw, terminate): exported = not kernel_can_gen_family_struct(family)
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 5/12 devlink: rename devlink_nl_ops to devlink_nl_small_ops
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In order to avoid name collision with the generated split ops array which is going to be introduced as a follow-up patch, rename the existing ops array to devlink_nl_small_ops.
--- net/devlink/devl_internal.h | 2 +- net/devlink/leftover.c | 2 +- net/devlink/netlink.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
net/devlink/devl_internal.h +1 -1
@@ -119,7 +119,7 @@ struct devlink_cmd { struct netlink_callback *cb); }; -extern const struct genl_small_ops devlink_nl_ops[56 ]; +extern const struct genl_small_ops devlink_nl_small_ops[56 ];struct devlink *devlink_get_from_attrs_lock (struct net *net,struct nlattr **attrs);
net/devlink/leftover.c +1 -1
@@ -6278,7 +6278,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb,return devlink_trap_policer_set (devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_ops[56 ] = { +const struct genl_small_ops devlink_nl_small_ops[56 ] = { { .cmd =DEVLINK_CMD_GET , .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP ,
net/devlink/netlink.c +2 -2
@@ -243,8 +243,8 @@ struct genl_family devlink_nl_family __ro_after_init = { .pre_doit = devlink_nl_pre_doit, .post_doit = devlink_nl_post_doit, .module = THIS_MODULE, - .small_ops = devlink_nl_ops, - .n_small_ops = ARRAY_SIZE(devlink_nl_ops), + .small_ops = devlink_nl_small_ops, + .n_small_ops = ARRAY_SIZE(devlink_nl_small_ops), .resv_start_op = DEVLINK_CMD_SELFTESTS_RUN + 1, .mcgrps = devlink_nl_mcgrps, .n_mcgrps = ARRAY_SIZE(devlink_nl_mcgrps),
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 6/12 devlink: rename couple of doit netlink callbacks to match generated names
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
The generated names of the doit netlink callback are missing "cmd" in their names. Change names to be ready to switch to generated split ops header.
---v2->v3:
- added temporary prototypes to devl_internal.h
- moved the patch before "devlink: add split ops generated according to spec" in order to fix the build breakage
--- net/devlink/dev.c | 4 ++-- net/devlink/devl_internal.h | 4 ++-- net/devlink/leftover.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
net/devlink/dev.c +2 -2
@@ -196,7 +196,7 @@ void devlink_notify(struct devlink *devlink, enum devlink_command cmd) msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } -int devlink_nl_cmd_get_doit (struct sk_buff *skb,struct genl_info *info) +int devlink_nl_get_doit (struct sk_buff *skb,struct genl_info *info) {struct devlink *devlink = info->user_ptr[0 ];struct sk_buff *msg;
@@ -804,7 +804,7 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,return err; } -int devlink_nl_cmd_info_get_doit (struct sk_buff *skb,struct genl_info *info) +int devlink_nl_info_get_doit (struct sk_buff *skb,struct genl_info *info) {struct devlink *devlink = info->user_ptr[0 ];struct sk_buff *msg;
net/devlink/devl_internal.h +2 -2
@@ -214,11 +214,11 @@ struct devlink_rate * devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info);/* Devlink nl cmds */ -int devlink_nl_cmd_get_doit (struct sk_buff *skb,struct genl_info *info); +int devlink_nl_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_reload (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_eswitch_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_eswitch_set_doit (struct sk_buff *skb,struct genl_info *info); -int devlink_nl_cmd_info_get_doit (struct sk_buff *skb,struct genl_info *info); +int devlink_nl_info_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_flash_update (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_selftests_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_selftests_run (struct sk_buff *skb,struct genl_info *info);
net/devlink/leftover.c +2 -2
@@ -6282,7 +6282,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_get_doit, + .doit = devlink_nl_get_doit, .dumpit = devlink_nl_instance_iter_dumpit, /* can be retrieved by unprivileged users */ },
@@ -6536,7 +6536,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { { .cmd = DEVLINK_CMD_INFO_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_info_get_doit, + .doit = devlink_nl_info_get_doit, .dumpit = devlink_nl_instance_iter_dumpit, /* can be retrieved by unprivileged users */ },
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 7/12 devlink: introduce couple of dumpit callbacks for split ops
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Introduce couple of dumpit callbacks for generated split ops. Have them as a thin wrapper around iteration function and allow to pass dump_one() function pointer directly without need to store in devlink_cmd structs.
---v2->v3:
- fixed double empty line issue
- added temporary prototypes to devl_internal.h
- moved the patch before "devlink: add split ops generated according to spec" in order to fix the build breakagev1->v2:
- fixed typo in patch subject
--- net/devlink/dev.c | 22 ++++++++++++---------- net/devlink/devl_internal.h | 17 +++++++++++------ net/devlink/leftover.c | 4 ++-- net/devlink/netlink.c | 21 ++++++++++++--------- 4 files changed, 37 insertions(+), 27 deletions(-)
net/devlink/dev.c +12 -10
@@ -217,17 +217,18 @@ int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info) }static int -devlink_nl_cmd_get_dump_one (struct sk_buff *msg,struct devlink *devlink, -struct netlink_callback *cb) +devlink_nl_get_dump_one (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {return devlink_nl_fill (msg, devlink,DEVLINK_CMD_NEW ,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NLM_F_MULTI ); } -const struct devlink_cmd devl_cmd_get = { - .dump_one = devlink_nl_cmd_get_dump_one, -}; +int devlink_nl_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) +{ +return devlink_nl_dumpit (msg, cb, devlink_nl_get_dump_one); +}static void devlink_reload_failed_set (struct devlink *devlink,bool reload_failed)
@@ -826,8 +827,8 @@ int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info) }static int -devlink_nl_cmd_info_get_dump_one (struct sk_buff *msg,struct devlink *devlink, -struct netlink_callback *cb) +devlink_nl_info_get_dump_one (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {int err;
@@ -840,9 +841,10 @@ devlink_nl_cmd_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,return err; } -const struct devlink_cmd devl_cmd_info_get = { - .dump_one = devlink_nl_cmd_info_get_dump_one, -}; +int devlink_nl_info_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) +{ +return devlink_nl_dumpit (msg, cb, devlink_nl_info_get_dump_one); +} static int devlink_nl_flash_update_fill(struct sk_buff *msg, struct devlink *devlink,
net/devlink/devl_internal.h +11 -6
@@ -114,9 +114,12 @@ struct devlink_nl_dump_state { }; }; +typedef int devlink_nl_dump_one_func_t (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb); +struct devlink_cmd { -int (*dump_one)(struct sk_buff *msg,struct devlink *devlink, -struct netlink_callback *cb); +devlink_nl_dump_one_func_t *dump_one; };extern const struct genl_small_ops devlink_nl_small_ops[56 ];
@@ -127,8 +130,9 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);void devlink_notify_unregister (struct devlink *devlink);void devlink_notify_register (struct devlink *devlink); -int devlink_nl_instance_iter_dumpit (struct sk_buff *msg, -struct netlink_callback *cb); +int devlink_nl_dumpit (struct sk_buff *msg,struct netlink_callback *cb, +devlink_nl_dump_one_func_t *dump_one); +int devlink_nl_instance_iter_dumpit (struct sk_buff *msg,struct netlink_callback *cb);static inline struct devlink_nl_dump_state *devlink_dump_state (struct netlink_callback *cb)
@@ -149,7 +153,6 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) }/* Commands */ -extern const struct devlink_cmd devl_cmd_get;extern const struct devlink_cmd devl_cmd_port_get;extern const struct devlink_cmd devl_cmd_sb_get;extern const struct devlink_cmd devl_cmd_sb_pool_get;
@@ -157,7 +160,6 @@ extern const struct devlink_cmd devl_cmd_sb_port_pool_get;extern const struct devlink_cmd devl_cmd_sb_tc_pool_bind_get;extern const struct devlink_cmd devl_cmd_param_get;extern const struct devlink_cmd devl_cmd_region_get; -extern const struct devlink_cmd devl_cmd_info_get;extern const struct devlink_cmd devl_cmd_health_reporter_get;extern const struct devlink_cmd devl_cmd_trap_get;extern const struct devlink_cmd devl_cmd_trap_group_get;
@@ -215,10 +217,13 @@ devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info);/* Devlink nl cmds */ int devlink_nl_get_doit (struct sk_buff *skb,struct genl_info *info); +int devlink_nl_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int devlink_nl_cmd_reload (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_eswitch_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_eswitch_set_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_info_get_doit (struct sk_buff *skb,struct genl_info *info); +int devlink_nl_info_get_dumpit (struct sk_buff *skb, +struct netlink_callback *cb);int devlink_nl_cmd_flash_update (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_selftests_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_selftests_run (struct sk_buff *skb,struct genl_info *info);
net/devlink/leftover.c +2 -2
@@ -6283,7 +6283,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, + .dumpit = devlink_nl_get_dumpit, /* can be retrieved by unprivileged users */ }, {
@@ -6537,7 +6537,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { .cmd = DEVLINK_CMD_INFO_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_info_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, + .dumpit = devlink_nl_info_get_dumpit, /* can be retrieved by unprivileged users */ }, {
net/devlink/netlink.c +12 -9
@@ -178,7 +178,6 @@ static void devlink_nl_post_doit(const struct genl_split_ops *ops, }static const struct devlink_cmd *devl_cmds[] = { - [DEVLINK_CMD_GET ] = &devl_cmd_get, [DEVLINK_CMD_PORT_GET ] = &devl_cmd_port_get, [DEVLINK_CMD_SB_GET ] = &devl_cmd_sb_get, [DEVLINK_CMD_SB_POOL_GET ] = &devl_cmd_sb_pool_get,
@@ -186,7 +185,6 @@ static const struct devlink_cmd *devl_cmds[] = { [DEVLINK_CMD_SB_TC_POOL_BIND_GET] = &devl_cmd_sb_tc_pool_bind_get, [DEVLINK_CMD_PARAM_GET] = &devl_cmd_param_get, [DEVLINK_CMD_REGION_GET] = &devl_cmd_region_get, - [DEVLINK_CMD_INFO_GET] = &devl_cmd_info_get, [DEVLINK_CMD_HEALTH_REPORTER_GET] = &devl_cmd_health_reporter_get, [DEVLINK_CMD_TRAP_GET] = &devl_cmd_trap_get, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_cmd_trap_group_get,
@@ -196,23 +194,19 @@ static const struct devlink_cmd *devl_cmds[] = { [DEVLINK_CMD_SELFTESTS_GET] = &devl_cmd_selftests_get, }; -int devlink_nl_instance_iter_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +int devlink_nl_dumpit (struct sk_buff *msg,struct netlink_callback *cb, +devlink_nl_dump_one_func_t *dump_one) { -const struct genl_dumpit_info *info =genl_dumpit_info (cb);struct devlink_nl_dump_state *state =devlink_dump_state (cb); -const struct devlink_cmd *cmd;struct devlink *devlink;int err =0 ; - cmd = devl_cmds[info->op.cmd]; -while ((devlink =devlinks_xa_find_get (sock_net (msg->sk), &state->instance))) {devl_lock (devlink);if (devl_is_registered (devlink)) - err = cmd->dump_one (msg, devlink, cb); + err =dump_one (msg, devlink, cb);else err =0 ;
@@ -233,6 +227,15 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg,return msg->len; } +int devlink_nl_instance_iter_dumpit (struct sk_buff *msg, +struct netlink_callback *cb) +{ +const struct genl_dumpit_info *info =genl_dumpit_info (cb); +const struct devlink_cmd *cmd = devl_cmds[info->op.cmd]; + +return devlink_nl_dumpit (msg, cb, cmd->dump_one); +} +struct genl_family devlink_nl_family__ro_after_init = { .name =DEVLINK_GENL_NAME , .version =DEVLINK_GENL_VERSION ,
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 8/12 devlink: un-static devlink_nl_pre/post_doit()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
To be prepared for the follow-up generated split ops addition, make the functions devlink_nl_pre_doit() and devlink_nl_post_doit() usable outside of netlink.c. Introduce temporary prototypes which are going to be removed once the generated header will be included.
---v2->v3:
- new patch, split from "devlink: include the generated netlink header"
--- net/devlink/devl_internal.h | 4 ++++ net/devlink/netlink.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-)
net/devlink/devl_internal.h +4 -0
@@ -216,6 +216,10 @@ struct devlink_rate * devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info);/* Devlink nl cmds */ +int devlink_nl_pre_doit (const struct genl_split_ops *ops, +struct sk_buff *skb,struct genl_info *info); +void devlink_nl_post_doit (const struct genl_split_ops *ops, +struct sk_buff *skb,struct genl_info *info);int devlink_nl_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int devlink_nl_cmd_reload (struct sk_buff *skb,struct genl_info *info);
net/devlink/netlink.c +4 -4
@@ -109,8 +109,8 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)return ERR_PTR (-ENODEV ); } -static int devlink_nl_pre_doit (const struct genl_split_ops *ops, -struct sk_buff *skb,struct genl_info *info) +int devlink_nl_pre_doit (const struct genl_split_ops *ops, +struct sk_buff *skb,struct genl_info *info) {struct devlink_linecard *linecard;struct devlink_port *devlink_port;
@@ -167,8 +167,8 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops,return err; } -static void devlink_nl_post_doit (const struct genl_split_ops *ops, -struct sk_buff *skb,struct genl_info *info) +void devlink_nl_post_doit (const struct genl_split_ops *ops, +struct sk_buff *skb,struct genl_info *info) {struct devlink *devlink;
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 9/12 netlink: specs: devlink: add info-get dump op
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add missing dump op for info-get command and re-generate related devlink-user.[ch] code.
---v1->v2:
- new patch, spec split from the next one, adding forgotten changes in devlink-user.[ch] code
--- Documentation/netlink/specs/devlink.yaml | 4 +- tools/net/ynl/generated/devlink-user.c | 53 ++++++++++++++++++++++++ tools/net/ynl/generated/devlink-user.h | 10 +++++ 3 files changed, 66 insertions(+), 1 deletion(-)
Documentation/netlink/specs/devlink.yaml +3 -1
@@ -194,7 +194,7 @@ operations: request: value: 51 attributes: *dev-id-attrs - reply: + reply: &info-get-reply value: 51 attributes: - bus-name
@@ -204,3 +204,5 @@ operations: - info-version-fixed - info-version-running - info-version-stored + dump: + reply: *info-get-reply
tools/net/ynl/generated/devlink-user.c +53 -0
59 lines not on this page · raw message
tools/net/ynl/generated/devlink-user.h +10 -0
@@ -207,4 +207,14 @@ void devlink_info_get_rsp_free(struct devlink_info_get_rsp *rsp);struct devlink_info_get_rsp *devlink_info_get (struct ynl_sock *ys,struct devlink_info_get_req *req); +/* DEVLINK_CMD_INFO_GET - dump */ +struct devlink_info_get_list { +struct devlink_info_get_list *next; +struct devlink_info_get_rsp obj __attribute__ ((aligned (8 ))); +}; + +void devlink_info_get_list_free (struct devlink_info_get_list *rsp); + +struct devlink_info_get_list *devlink_info_get_dump (struct ynl_sock *ys); +#endif /* _LINUX_DEVLINK_GEN_H */
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 10/12 devlink: add split ops generated according to spec
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Improve the existing devlink spec in order to serve as a source for generation of valid devlink split ops for the existing commands. Add the generated sources.
Node that the policies are narrowed down only to the attributes that are actually parsed. The dont-validate-strict parsing policy makes sure that other possibly passed garbage attributes from userspace are ignored during validation.
---v2->v3:
- un-static devlink_nl_pre/post_doit() to fix the build v1->v2:
- fixed "for" typo
- added note to patch description about narrowing down the policy
- moved info-get dump op addition to a separate patch
- regenerated files according to static policies change
--- Documentation/netlink/specs/devlink.yaml | 10 ++++ net/devlink/Makefile | 2 +- net/devlink/netlink_gen.c | 59 ++++++++++++++++++++++++ net/devlink/netlink_gen.h | 29 ++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 net/devlink/netlink_gen.c create mode 100644 net/devlink/netlink_gen.h
Documentation/netlink/specs/devlink.yaml +10 -0
@@ -165,8 +165,13 @@ operations: name: get doc: Get devlink instances. attribute-set: devlink + dont-validate: + - strict + - dump do: + pre: devlink-nl-pre-doit + post: devlink-nl-post-doit request: value: 1 attributes: &dev-id-attrs
@@ -189,8 +194,13 @@ operations: name: info-get doc: Get device information, like driver name, hardware and firmware versions etc. attribute-set: devlink + dont-validate: + - strict + - dump do: + pre: devlink-nl-pre-doit + post: devlink-nl-post-doit request: value: 51 attributes: *dev-id-attrs
net/devlink/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y := leftover.o core.o netlink.o dev.o health.o +obj-y := leftover.o core.o netlink.o netlink_gen.o dev.o health.o
net/devlink/netlink_gen.c new file +59 -0
59 lines not on this page · raw message
net/devlink/netlink_gen.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/devlink.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_DEVLINK_GEN_H +#define _LINUX_DEVLINK_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <uapi/linux/devlink.h> + +/* Ops table for devlink */ +extern const struct genl_split_ops devlink_nl_ops[4 ]; + +int devlink_nl_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +void +devlink_nl_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); + +int devlink_nl_get_doit (struct sk_buff *skb,struct genl_info *info); +int devlink_nl_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int devlink_nl_info_get_doit (struct sk_buff *skb,struct genl_info *info); +int devlink_nl_info_get_dumpit (struct sk_buff *skb, +struct netlink_callback *cb); + +#endif /* _LINUX_DEVLINK_GEN_H */
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 11/12 devlink: include the generated netlink header
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Put the newly added generated header to the include list. Remove the duplicated temporary function prototypes.
---v2->v3:
- moved un-static devlink_nl_pre/post_doit() a separate new patch
- added removal of the temporary function prototypes
--- net/devlink/devl_internal.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
net/devlink/devl_internal.h +2 -9
@@ -12,6 +12,8 @@#include <net/devlink.h> #include <net/net_namespace.h> +#include "netlink_gen.h" +#define DEVLINK_REGISTERED XA_MARK_1#define DEVLINK_RELOAD_STATS_ARRAY_SIZE \
@@ -216,18 +218,9 @@ struct devlink_rate * devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info);/* Devlink nl cmds */ -int devlink_nl_pre_doit (const struct genl_split_ops *ops, -struct sk_buff *skb,struct genl_info *info); -void devlink_nl_post_doit (const struct genl_split_ops *ops, -struct sk_buff *skb,struct genl_info *info); -int devlink_nl_get_doit (struct sk_buff *skb,struct genl_info *info); -int devlink_nl_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int devlink_nl_cmd_reload (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_eswitch_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_eswitch_set_doit (struct sk_buff *skb,struct genl_info *info); -int devlink_nl_info_get_doit (struct sk_buff *skb,struct genl_info *info); -int devlink_nl_info_get_dumpit (struct sk_buff *skb, -struct netlink_callback *cb);int devlink_nl_cmd_flash_update (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_selftests_get_doit (struct sk_buff *skb,struct genl_info *info);int devlink_nl_cmd_selftests_run (struct sk_buff *skb,struct genl_info *info);
Signature · 1 line
2.41.0
Jiri Pirko
maintainerPATCH v3 12/12 devlink: use generated split ops and remove duplicated commands from small ops
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Do the switch and use generated split ops for get and info_get commands. Remove those from small ops array.
--- net/devlink/devl_internal.h | 2 +- net/devlink/leftover.c | 16 +--------------- net/devlink/netlink.c | 2 ++ 3 files changed, 4 insertions(+), 16 deletions(-)
net/devlink/devl_internal.h +1 -1
@@ -124,7 +124,7 @@ struct devlink_cmd {devlink_nl_dump_one_func_t *dump_one; }; -extern const struct genl_small_ops devlink_nl_small_ops[56 ]; +extern const struct genl_small_ops devlink_nl_small_ops[54 ];struct devlink *devlink_get_from_attrs_lock (struct net *net,struct nlattr **attrs);
net/devlink/leftover.c +1 -15
@@ -6278,14 +6278,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb,return devlink_trap_policer_set (devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_small_ops[56 ] = { - { - .cmd =DEVLINK_CMD_GET , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , - .doit = devlink_nl_get_doit, - .dumpit = devlink_nl_get_dumpit, -/* can be retrieved by unprivileged users */ - }, +const struct genl_small_ops devlink_nl_small_ops[54 ] = { { .cmd =DEVLINK_CMD_PORT_GET , .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP ,
@@ -6533,13 +6526,6 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { .dumpit = devlink_nl_cmd_region_read_dumpit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_INFO_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_info_get_doit, - .dumpit = devlink_nl_info_get_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/devlink/netlink.c +2 -0
@@ -248,6 +248,8 @@ struct genl_family devlink_nl_family __ro_after_init = { .module = THIS_MODULE, .small_ops = devlink_nl_small_ops, .n_small_ops = ARRAY_SIZE(devlink_nl_small_ops), + .split_ops = devlink_nl_ops, + .n_split_ops = ARRAY_SIZE(devlink_nl_ops), .resv_start_op = DEVLINK_CMD_SELFTESTS_RUN + 1, .mcgrps = devlink_nl_mcgrps, .n_mcgrps = ARRAY_SIZE(devlink_nl_mcgrps),
Signature · 1 line
2.41.0
Quoted 9 lines · On Thu, 3 Aug 2023 13:13:28 +0200 Jiri Pirko wrote:
This is an outcome of the discussion in the following thread:
https://lore.kernel.org/netdev/[email protected]/
It serves as a dependency on the linked selector patchset.There is an existing spec for devlink used for userspace part generation. There are two commands supported there.
This patchset extends the spec so kernel split ops code could be generated from it.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 3 Aug 2023 13:13:28 +0200 you wrote:
From: Jiri Pirko <[email protected]>
This is an outcome of the discussion in the following thread:
https://lore.kernel.org/netdev/[email protected]/
It serves as a dependency on the linked selector patchset.There is an existing spec for devlink used for userspace part generation. There are two commands supported there.
[...]
Here is the summary with links:
- [net-next,v3,01/12] netlink: specs: add dump-strict flag for dont-validate property
https://git.kernel.org/netdev/net-next/c/78c96d7b7c9a - [net-next,v3,02/12] ynl-gen-c.py: filter rendering of validate field values for split ops https://git.kernel.org/netdev/net-next/c/dc7b81a828db - [net-next,v3,03/12] ynl-gen-c.py: allow directional model for kernel mode https://git.kernel.org/netdev/net-next/c/eab7be688b44 - [net-next,v3,04/12] ynl-gen-c.py: render netlink policies static for split ops https://git.kernel.org/netdev/net-next/c/fa8ba3502ade - [net-next,v3,05/12] devlink: rename devlink_nl_ops to devlink_nl_small_ops https://git.kernel.org/netdev/net-next/c/ba0f66c95fa6 - [net-next,v3,06/12] devlink: rename couple of doit netlink callbacks to match generated names https://git.kernel.org/netdev/net-next/c/d61aedcf628e - [net-next,v3,07/12] devlink: introduce couple of dumpit callbacks for split ops https://git.kernel.org/netdev/net-next/c/491a24872a64 - [net-next,v3,08/12] devlink: un-static devlink_nl_pre/post_doit() https://git.kernel.org/netdev/net-next/c/8300dce542e4 - [net-next,v3,09/12] netlink: specs: devlink: add info-get dump op https://git.kernel.org/netdev/net-next/c/759f661012d1 - [net-next,v3,10/12] devlink: add split ops generated according to spec https://git.kernel.org/netdev/net-next/c/6b7c486cae81 - [net-next,v3,11/12] devlink: include the generated netlink header https://git.kernel.org/netdev/net-next/c/b2551b1517d8 - [net-next,v3,12/12] devlink: use generated split ops and remove duplicated commands from small ops https://git.kernel.org/netdev/net-next/c/6e067d0cab68
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html