Skip to content

Commit a0bdcc5

Browse files
Eran Ben Elishadavem330
authored andcommitted
devlink: Add health reporter create/destroy functionality
Devlink health reporter is an instance for reporting, diagnosing and recovering from run time errors discovered by the reporters. Define it's data structure and supported operations. In addition, expose devlink API to create and destroy a reporter. Each devlink instance will hold it's own reporters list. As part of the allocation, driver shall provide a set of callbacks which will be used by devlink in order to handle health reports and user commands related to this reporter. In addition, driver is entitled to provide some priv pointer, which can be fetched from the reporter by devlink_health_reporter_priv function. For each reporter, devlink will hold a metadata of statistics, dump msg and status. For passing dumps and diagnose data to the user-space, it will use devlink fmsg API. Signed-off-by: Eran Ben Elisha <eranbe@mellanox.com> Reviewed-by: Moshe Shemesh <moshe@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1db64e8 commit a0bdcc5

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

‎include/net/devlink.h‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct devlink {
3030
struct list_head param_list;
3131
struct list_head region_list;
3232
u32 snapshot_id;
33+
struct list_head reporter_list;
3334
struct devlink_dpipe_headers *dpipe_headers;
3435
const struct devlink_ops *ops;
3536
struct device *dev;
@@ -449,6 +450,27 @@ struct devlink_info_req;
449450
typedef void devlink_snapshot_data_dest_t(const void *data);
450451

451452
struct devlink_fmsg;
453+
struct devlink_health_reporter;
454+
455+
/**
456+
* struct devlink_health_reporter_ops - Reporter operations
457+
* @name: reporter name
458+
* @recover: callback to recover from reported error
459+
* if priv_ctx is NULL, run a full recover
460+
* @dump: callback to dump an object
461+
* if priv_ctx is NULL, run a full dump
462+
* @diagnose: callback to diagnose the current status
463+
*/
464+
465+
struct devlink_health_reporter_ops {
466+
char *name;
467+
int (*recover)(struct devlink_health_reporter *reporter,
468+
void *priv_ctx);
469+
int (*dump)(struct devlink_health_reporter *reporter,
470+
struct devlink_fmsg *fmsg, void *priv_ctx);
471+
int (*diagnose)(struct devlink_health_reporter *reporter,
472+
struct devlink_fmsg *fmsg);
473+
};
452474

453475
struct devlink_ops {
454476
int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
@@ -672,6 +694,17 @@ int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
672694
int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
673695
const void *value, u16 value_len);
674696

697+
struct devlink_health_reporter *
698+
devlink_health_reporter_create(struct devlink *devlink,
699+
const struct devlink_health_reporter_ops *ops,
700+
u64 graceful_period, bool auto_recover,
701+
void *priv);
702+
void
703+
devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
704+
705+
void *
706+
devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
707+
675708
#else
676709

677710
static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
@@ -1120,6 +1153,26 @@ devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
11201153
{
11211154
return 0;
11221155
}
1156+
1157+
static inline struct devlink_health_reporter *
1158+
devlink_health_reporter_create(struct devlink *devlink,
1159+
const struct devlink_health_reporter_ops *ops,
1160+
u64 graceful_period, bool auto_recover,
1161+
void *priv)
1162+
{
1163+
return NULL;
1164+
}
1165+
1166+
static inline void
1167+
devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
1168+
{
1169+
}
1170+
1171+
static inline void *
1172+
devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
1173+
{
1174+
return NULL;
1175+
}
11231176
#endif
11241177

11251178
#if IS_REACHABLE(CONFIG_NET_DEVLINK)

‎net/core/devlink.c‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,6 +4362,97 @@ static int devlink_fmsg_snd(struct devlink_fmsg *fmsg,
43624362
return err;
43634363
}
43644364

4365+
struct devlink_health_reporter {
4366+
struct list_head list;
4367+
void *priv;
4368+
const struct devlink_health_reporter_ops *ops;
4369+
struct devlink *devlink;
4370+
u64 graceful_period;
4371+
bool auto_recover;
4372+
u8 health_state;
4373+
};
4374+
4375+
void *
4376+
devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
4377+
{
4378+
return reporter->priv;
4379+
}
4380+
EXPORT_SYMBOL_GPL(devlink_health_reporter_priv);
4381+
4382+
static struct devlink_health_reporter *
4383+
devlink_health_reporter_find_by_name(struct devlink *devlink,
4384+
const char *reporter_name)
4385+
{
4386+
struct devlink_health_reporter *reporter;
4387+
4388+
list_for_each_entry(reporter, &devlink->reporter_list, list)
4389+
if (!strcmp(reporter->ops->name, reporter_name))
4390+
return reporter;
4391+
return NULL;
4392+
}
4393+
4394+
/**
4395+
* devlink_health_reporter_create - create devlink health reporter
4396+
*
4397+
* @devlink: devlink
4398+
* @ops: ops
4399+
* @graceful_period: to avoid recovery loops, in msecs
4400+
* @auto_recover: auto recover when error occurs
4401+
* @priv: priv
4402+
*/
4403+
struct devlink_health_reporter *
4404+
devlink_health_reporter_create(struct devlink *devlink,
4405+
const struct devlink_health_reporter_ops *ops,
4406+
u64 graceful_period, bool auto_recover,
4407+
void *priv)
4408+
{
4409+
struct devlink_health_reporter *reporter;
4410+
4411+
mutex_lock(&devlink->lock);
4412+
if (devlink_health_reporter_find_by_name(devlink, ops->name)) {
4413+
reporter = ERR_PTR(-EEXIST);
4414+
goto unlock;
4415+
}
4416+
4417+
if (WARN_ON(auto_recover && !ops->recover) ||
4418+
WARN_ON(graceful_period && !ops->recover)) {
4419+
reporter = ERR_PTR(-EINVAL);
4420+
goto unlock;
4421+
}
4422+
4423+
reporter = kzalloc(sizeof(*reporter), GFP_KERNEL);
4424+
if (!reporter) {
4425+
reporter = ERR_PTR(-ENOMEM);
4426+
goto unlock;
4427+
}
4428+
4429+
reporter->priv = priv;
4430+
reporter->ops = ops;
4431+
reporter->devlink = devlink;
4432+
reporter->graceful_period = graceful_period;
4433+
reporter->auto_recover = auto_recover;
4434+
list_add_tail(&reporter->list, &devlink->reporter_list);
4435+
unlock:
4436+
mutex_unlock(&devlink->lock);
4437+
return reporter;
4438+
}
4439+
EXPORT_SYMBOL_GPL(devlink_health_reporter_create);
4440+
4441+
/**
4442+
* devlink_health_reporter_destroy - destroy devlink health reporter
4443+
*
4444+
* @reporter: devlink health reporter to destroy
4445+
*/
4446+
void
4447+
devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
4448+
{
4449+
mutex_lock(&reporter->devlink->lock);
4450+
list_del(&reporter->list);
4451+
mutex_unlock(&reporter->devlink->lock);
4452+
kfree(reporter);
4453+
}
4454+
EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
4455+
43654456
static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
43664457
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
43674458
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
@@ -4670,6 +4761,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
46704761
INIT_LIST_HEAD(&devlink->resource_list);
46714762
INIT_LIST_HEAD(&devlink->param_list);
46724763
INIT_LIST_HEAD(&devlink->region_list);
4764+
INIT_LIST_HEAD(&devlink->reporter_list);
46734765
mutex_init(&devlink->lock);
46744766
return devlink;
46754767
}

0 commit comments

Comments
 (0)