Commit 491a2487 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

devlink: introduce couple of dumpit callbacks for split ops

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.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/20230803111340.1074067-8-jiri@resnulli.usSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d61aedcf
...@@ -217,17 +217,18 @@ int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info) ...@@ -217,17 +217,18 @@ int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info)
} }
static int static int
devlink_nl_cmd_get_dump_one(struct sk_buff *msg, struct devlink *devlink, devlink_nl_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
return devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW, return devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, NLM_F_MULTI); cb->nlh->nlmsg_seq, NLM_F_MULTI);
} }
const struct devlink_cmd devl_cmd_get = { int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
.dump_one = devlink_nl_cmd_get_dump_one, {
}; return devlink_nl_dumpit(msg, cb, devlink_nl_get_dump_one);
}
static void devlink_reload_failed_set(struct devlink *devlink, static void devlink_reload_failed_set(struct devlink *devlink,
bool reload_failed) bool reload_failed)
...@@ -826,8 +827,8 @@ int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info) ...@@ -826,8 +827,8 @@ int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info)
} }
static int static int
devlink_nl_cmd_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink, devlink_nl_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
int err; int err;
...@@ -840,9 +841,10 @@ devlink_nl_cmd_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink, ...@@ -840,9 +841,10 @@ devlink_nl_cmd_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
return err; return err;
} }
const struct devlink_cmd devl_cmd_info_get = { int devlink_nl_info_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
.dump_one = devlink_nl_cmd_info_get_dump_one, {
}; return devlink_nl_dumpit(msg, cb, devlink_nl_info_get_dump_one);
}
static int devlink_nl_flash_update_fill(struct sk_buff *msg, static int devlink_nl_flash_update_fill(struct sk_buff *msg,
struct devlink *devlink, struct devlink *devlink,
......
...@@ -114,9 +114,12 @@ struct devlink_nl_dump_state { ...@@ -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 { struct devlink_cmd {
int (*dump_one)(struct sk_buff *msg, struct devlink *devlink, devlink_nl_dump_one_func_t *dump_one;
struct netlink_callback *cb);
}; };
extern const struct genl_small_ops devlink_nl_small_ops[56]; 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); ...@@ -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_unregister(struct devlink *devlink);
void devlink_notify_register(struct devlink *devlink); void devlink_notify_register(struct devlink *devlink);
int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
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 * static inline struct devlink_nl_dump_state *
devlink_dump_state(struct netlink_callback *cb) devlink_dump_state(struct netlink_callback *cb)
...@@ -149,7 +153,6 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) ...@@ -149,7 +153,6 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
} }
/* Commands */ /* 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_port_get;
extern const struct devlink_cmd devl_cmd_sb_get; extern const struct devlink_cmd devl_cmd_sb_get;
extern const struct devlink_cmd devl_cmd_sb_pool_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; ...@@ -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_sb_tc_pool_bind_get;
extern const struct devlink_cmd devl_cmd_param_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_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_health_reporter_get;
extern const struct devlink_cmd devl_cmd_trap_get; extern const struct devlink_cmd devl_cmd_trap_get;
extern const struct devlink_cmd devl_cmd_trap_group_get; extern const struct devlink_cmd devl_cmd_trap_group_get;
...@@ -215,10 +217,13 @@ devlink_rate_node_get_from_info(struct devlink *devlink, ...@@ -215,10 +217,13 @@ devlink_rate_node_get_from_info(struct devlink *devlink,
struct genl_info *info); struct genl_info *info);
/* Devlink nl cmds */ /* Devlink nl cmds */
int devlink_nl_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_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_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_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_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_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_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_get_doit(struct sk_buff *skb, struct genl_info *info);
int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info);
......
...@@ -6283,7 +6283,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { ...@@ -6283,7 +6283,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
.cmd = DEVLINK_CMD_GET, .cmd = DEVLINK_CMD_GET,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
.doit = devlink_nl_get_doit, .doit = devlink_nl_get_doit,
.dumpit = devlink_nl_instance_iter_dumpit, .dumpit = devlink_nl_get_dumpit,
/* can be retrieved by unprivileged users */ /* can be retrieved by unprivileged users */
}, },
{ {
...@@ -6537,7 +6537,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = { ...@@ -6537,7 +6537,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
.cmd = DEVLINK_CMD_INFO_GET, .cmd = DEVLINK_CMD_INFO_GET,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
.doit = devlink_nl_info_get_doit, .doit = devlink_nl_info_get_doit,
.dumpit = devlink_nl_instance_iter_dumpit, .dumpit = devlink_nl_info_get_dumpit,
/* can be retrieved by unprivileged users */ /* can be retrieved by unprivileged users */
}, },
{ {
......
...@@ -178,7 +178,6 @@ static void devlink_nl_post_doit(const struct genl_split_ops *ops, ...@@ -178,7 +178,6 @@ static void devlink_nl_post_doit(const struct genl_split_ops *ops,
} }
static const struct devlink_cmd *devl_cmds[] = { static const struct devlink_cmd *devl_cmds[] = {
[DEVLINK_CMD_GET] = &devl_cmd_get,
[DEVLINK_CMD_PORT_GET] = &devl_cmd_port_get, [DEVLINK_CMD_PORT_GET] = &devl_cmd_port_get,
[DEVLINK_CMD_SB_GET] = &devl_cmd_sb_get, [DEVLINK_CMD_SB_GET] = &devl_cmd_sb_get,
[DEVLINK_CMD_SB_POOL_GET] = &devl_cmd_sb_pool_get, [DEVLINK_CMD_SB_POOL_GET] = &devl_cmd_sb_pool_get,
...@@ -186,7 +185,6 @@ static const struct devlink_cmd *devl_cmds[] = { ...@@ -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_SB_TC_POOL_BIND_GET] = &devl_cmd_sb_tc_pool_bind_get,
[DEVLINK_CMD_PARAM_GET] = &devl_cmd_param_get, [DEVLINK_CMD_PARAM_GET] = &devl_cmd_param_get,
[DEVLINK_CMD_REGION_GET] = &devl_cmd_region_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_HEALTH_REPORTER_GET] = &devl_cmd_health_reporter_get,
[DEVLINK_CMD_TRAP_GET] = &devl_cmd_trap_get, [DEVLINK_CMD_TRAP_GET] = &devl_cmd_trap_get,
[DEVLINK_CMD_TRAP_GROUP_GET] = &devl_cmd_trap_group_get, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_cmd_trap_group_get,
...@@ -196,23 +194,19 @@ static const struct devlink_cmd *devl_cmds[] = { ...@@ -196,23 +194,19 @@ static const struct devlink_cmd *devl_cmds[] = {
[DEVLINK_CMD_SELFTESTS_GET] = &devl_cmd_selftests_get, [DEVLINK_CMD_SELFTESTS_GET] = &devl_cmd_selftests_get,
}; };
int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
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); struct devlink_nl_dump_state *state = devlink_dump_state(cb);
const struct devlink_cmd *cmd;
struct devlink *devlink; struct devlink *devlink;
int err = 0; int err = 0;
cmd = devl_cmds[info->op.cmd];
while ((devlink = devlinks_xa_find_get(sock_net(msg->sk), while ((devlink = devlinks_xa_find_get(sock_net(msg->sk),
&state->instance))) { &state->instance))) {
devl_lock(devlink); devl_lock(devlink);
if (devl_is_registered(devlink)) if (devl_is_registered(devlink))
err = cmd->dump_one(msg, devlink, cb); err = dump_one(msg, devlink, cb);
else else
err = 0; err = 0;
...@@ -233,6 +227,15 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, ...@@ -233,6 +227,15 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg,
return msg->len; 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 = { struct genl_family devlink_nl_family __ro_after_init = {
.name = DEVLINK_GENL_NAME, .name = DEVLINK_GENL_NAME,
.version = DEVLINK_GENL_VERSION, .version = DEVLINK_GENL_VERSION,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment