Skip to content

Commit 12bd0dc

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 buffer descriptors 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]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8a66704 commit 12bd0dc

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

include/uapi/linux/devlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ enum devlink_command {
9393
DEVLINK_CMD_HEALTH_REPORTER_SET,
9494
DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
9595
DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE,
96+
DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
97+
DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
9698

9799
/* add new commands above here */
98100
__DEVLINK_CMD_MAX,

net/core/devlink.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,6 +4544,65 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
45444544
return err;
45454545
}
45464546

4547+
static void
4548+
devlink_health_dump_clear(struct devlink_health_reporter *reporter)
4549+
{
4550+
reporter->dump_avail = false;
4551+
reporter->dump_ts = 0;
4552+
devlink_health_buffers_reset(reporter->dump_buffers_array,
4553+
DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size));
4554+
}
4555+
4556+
static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb,
4557+
struct genl_info *info)
4558+
{
4559+
struct devlink *devlink = info->user_ptr[0];
4560+
struct devlink_health_reporter *reporter;
4561+
u64 num_of_buffers;
4562+
int err;
4563+
4564+
reporter = devlink_health_reporter_get_from_info(devlink, info);
4565+
if (!reporter)
4566+
return -EINVAL;
4567+
4568+
if (!reporter->ops->dump)
4569+
return -EOPNOTSUPP;
4570+
4571+
num_of_buffers =
4572+
DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size);
4573+
4574+
mutex_lock(&reporter->dump_lock);
4575+
err = devlink_health_do_dump(reporter, NULL);
4576+
if (err)
4577+
goto out;
4578+
4579+
err = devlink_health_buffer_snd(info,
4580+
DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
4581+
0, reporter->dump_buffers_array,
4582+
num_of_buffers);
4583+
4584+
out:
4585+
mutex_unlock(&reporter->dump_lock);
4586+
return err;
4587+
}
4588+
4589+
static int
4590+
devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
4591+
struct genl_info *info)
4592+
{
4593+
struct devlink *devlink = info->user_ptr[0];
4594+
struct devlink_health_reporter *reporter;
4595+
4596+
reporter = devlink_health_reporter_get_from_info(devlink, info);
4597+
if (!reporter)
4598+
return -EINVAL;
4599+
4600+
mutex_lock(&reporter->dump_lock);
4601+
devlink_health_dump_clear(reporter);
4602+
mutex_unlock(&reporter->dump_lock);
4603+
return 0;
4604+
}
4605+
45474606
static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
45484607
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
45494608
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
@@ -4821,6 +4880,22 @@ static const struct genl_ops devlink_nl_ops[] = {
48214880
.flags = GENL_ADMIN_PERM,
48224881
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
48234882
},
4883+
{
4884+
.cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
4885+
.doit = devlink_nl_cmd_health_reporter_dump_get_doit,
4886+
.policy = devlink_nl_policy,
4887+
.flags = GENL_ADMIN_PERM,
4888+
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4889+
DEVLINK_NL_FLAG_NO_LOCK,
4890+
},
4891+
{
4892+
.cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
4893+
.doit = devlink_nl_cmd_health_reporter_dump_clear_doit,
4894+
.policy = devlink_nl_policy,
4895+
.flags = GENL_ADMIN_PERM,
4896+
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4897+
DEVLINK_NL_FLAG_NO_LOCK,
4898+
},
48244899
};
48254900

48264901
static struct genl_family devlink_nl_family __ro_after_init = {

0 commit comments

Comments
 (0)