Skip to content

Commit 35455e2

Browse files
Eran Ben Elishadavem330
authored andcommitted
devlink: Add health dump {get,clear} commands
Add devlink health dump commands, in order to run an dump operation over a specific reporter. The supported operations are dump_get in order to get last saved dump (if not exist, dump now) and dump_clear to clear last saved dump. It is expected from driver's callback for diagnose command to fill it via the devlink fmsg API. Devlink will parse it and convert it to netlink nla API in order to pass it to the user. Signed-off-by: Eran Ben Elisha <[email protected]> Reviewed-by: Moshe Shemesh <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fca42a2 commit 35455e2

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

include/uapi/linux/devlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ enum devlink_command {
100100
DEVLINK_CMD_HEALTH_REPORTER_SET,
101101
DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
102102
DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE,
103+
DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
104+
DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
103105

104106
/* add new commands above here */
105107
__DEVLINK_CMD_MAX,

net/core/devlink.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4791,6 +4791,53 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
47914791
return err;
47924792
}
47934793

4794+
static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb,
4795+
struct genl_info *info)
4796+
{
4797+
struct devlink *devlink = info->user_ptr[0];
4798+
struct devlink_health_reporter *reporter;
4799+
int err;
4800+
4801+
reporter = devlink_health_reporter_get_from_info(devlink, info);
4802+
if (!reporter)
4803+
return -EINVAL;
4804+
4805+
if (!reporter->ops->dump)
4806+
return -EOPNOTSUPP;
4807+
4808+
mutex_lock(&reporter->dump_lock);
4809+
err = devlink_health_do_dump(reporter, NULL);
4810+
if (err)
4811+
goto out;
4812+
4813+
err = devlink_fmsg_snd(reporter->dump_fmsg, info,
4814+
DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET, 0);
4815+
4816+
out:
4817+
mutex_unlock(&reporter->dump_lock);
4818+
return err;
4819+
}
4820+
4821+
static int
4822+
devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
4823+
struct genl_info *info)
4824+
{
4825+
struct devlink *devlink = info->user_ptr[0];
4826+
struct devlink_health_reporter *reporter;
4827+
4828+
reporter = devlink_health_reporter_get_from_info(devlink, info);
4829+
if (!reporter)
4830+
return -EINVAL;
4831+
4832+
if (!reporter->ops->dump)
4833+
return -EOPNOTSUPP;
4834+
4835+
mutex_lock(&reporter->dump_lock);
4836+
devlink_health_dump_clear(reporter);
4837+
mutex_unlock(&reporter->dump_lock);
4838+
return 0;
4839+
}
4840+
47944841
static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
47954842
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
47964843
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
@@ -5091,6 +5138,22 @@ static const struct genl_ops devlink_nl_ops[] = {
50915138
.flags = GENL_ADMIN_PERM,
50925139
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
50935140
},
5141+
{
5142+
.cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
5143+
.doit = devlink_nl_cmd_health_reporter_dump_get_doit,
5144+
.policy = devlink_nl_policy,
5145+
.flags = GENL_ADMIN_PERM,
5146+
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5147+
DEVLINK_NL_FLAG_NO_LOCK,
5148+
},
5149+
{
5150+
.cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
5151+
.doit = devlink_nl_cmd_health_reporter_dump_clear_doit,
5152+
.policy = devlink_nl_policy,
5153+
.flags = GENL_ADMIN_PERM,
5154+
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5155+
DEVLINK_NL_FLAG_NO_LOCK,
5156+
},
50945157
};
50955158

50965159
static struct genl_family devlink_nl_family __ro_after_init = {

0 commit comments

Comments
 (0)