Commit 25573968 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

devlink: convert linecards dump to devlink_nl_instance_iter_dump()

Benefit from recently introduced instance iteration and convert
linecards .dumpit generic netlink callback to use it.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e994a75f
...@@ -167,6 +167,7 @@ extern const struct devlink_gen_cmd devl_gen_info; ...@@ -167,6 +167,7 @@ extern const struct devlink_gen_cmd devl_gen_info;
extern const struct devlink_gen_cmd devl_gen_trap; extern const struct devlink_gen_cmd devl_gen_trap;
extern const struct devlink_gen_cmd devl_gen_trap_group; extern const struct devlink_gen_cmd devl_gen_trap_group;
extern const struct devlink_gen_cmd devl_gen_trap_policer; extern const struct devlink_gen_cmd devl_gen_trap_policer;
extern const struct devlink_gen_cmd devl_gen_linecard;
/* Ports */ /* Ports */
int devlink_port_netdevice_event(struct notifier_block *nb, int devlink_port_netdevice_event(struct notifier_block *nb,
......
...@@ -2105,20 +2105,14 @@ static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, ...@@ -2105,20 +2105,14 @@ static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb,
return genlmsg_reply(msg, info); return genlmsg_reply(msg, info);
} }
static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, static int devlink_nl_cmd_linecard_get_dump_one(struct sk_buff *msg,
struct devlink *devlink,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
struct devlink_nl_dump_state *state = devlink_dump_state(cb); struct devlink_nl_dump_state *state = devlink_dump_state(cb);
struct devlink_linecard *linecard; struct devlink_linecard *linecard;
struct devlink *devlink;
int err;
devlink_dump_for_each_instance_get(msg, state, devlink) {
int idx = 0; int idx = 0;
int err = 0;
devl_lock(devlink);
if (!devl_is_registered(devlink))
goto next_devlink;
list_for_each_entry(linecard, &devlink->linecard_list, list) { list_for_each_entry(linecard, &devlink->linecard_list, list) {
if (idx < state->idx) { if (idx < state->idx) {
...@@ -2134,21 +2128,19 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, ...@@ -2134,21 +2128,19 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,
cb->extack); cb->extack);
mutex_unlock(&linecard->state_lock); mutex_unlock(&linecard->state_lock);
if (err) { if (err) {
devl_unlock(devlink);
devlink_put(devlink);
state->idx = idx; state->idx = idx;
goto out; break;
} }
idx++; idx++;
} }
next_devlink:
devl_unlock(devlink); return err;
devlink_put(devlink);
}
out:
return msg->len;
} }
const struct devlink_gen_cmd devl_gen_linecard = {
.dump_one = devlink_nl_cmd_linecard_get_dump_one,
};
static struct devlink_linecard_type * static struct devlink_linecard_type *
devlink_linecard_type_lookup(struct devlink_linecard *linecard, devlink_linecard_type_lookup(struct devlink_linecard *linecard,
const char *type) const char *type)
...@@ -9010,7 +9002,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { ...@@ -9010,7 +9002,7 @@ const struct genl_small_ops devlink_nl_ops[56] = {
{ {
.cmd = DEVLINK_CMD_LINECARD_GET, .cmd = DEVLINK_CMD_LINECARD_GET,
.doit = devlink_nl_cmd_linecard_get_doit, .doit = devlink_nl_cmd_linecard_get_doit,
.dumpit = devlink_nl_cmd_linecard_get_dumpit, .dumpit = devlink_nl_instance_iter_dump,
.internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD,
/* can be retrieved by unprivileged users */ /* can be retrieved by unprivileged users */
}, },
......
...@@ -191,6 +191,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = { ...@@ -191,6 +191,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = {
[DEVLINK_CMD_TRAP_GET] = &devl_gen_trap, [DEVLINK_CMD_TRAP_GET] = &devl_gen_trap,
[DEVLINK_CMD_TRAP_GROUP_GET] = &devl_gen_trap_group, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_gen_trap_group,
[DEVLINK_CMD_TRAP_POLICER_GET] = &devl_gen_trap_policer, [DEVLINK_CMD_TRAP_POLICER_GET] = &devl_gen_trap_policer,
[DEVLINK_CMD_LINECARD_GET] = &devl_gen_linecard,
[DEVLINK_CMD_SELFTESTS_GET] = &devl_gen_selftests, [DEVLINK_CMD_SELFTESTS_GET] = &devl_gen_selftests,
}; };
......
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