Commit c57544b3 authored by Vladyslav Tarasiuk's avatar Vladyslav Tarasiuk Committed by David S. Miller

devlink: Refactor devlink health reporter constructor

Prepare a common routine in devlink_health_reporter_create() for usage
in similar functions for devlink port health reporters.
Signed-off-by: default avatarVladyslav Tarasiuk <vladyslavt@mellanox.com>
Reviewed-by: default avatarMoshe Shemesh <moshe@mellanox.com>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d6c7fc0c
...@@ -5321,6 +5321,31 @@ devlink_health_reporter_find_by_name(struct devlink *devlink, ...@@ -5321,6 +5321,31 @@ devlink_health_reporter_find_by_name(struct devlink *devlink,
return NULL; return NULL;
} }
static struct devlink_health_reporter *
__devlink_health_reporter_create(struct devlink *devlink,
const struct devlink_health_reporter_ops *ops,
u64 graceful_period, void *priv)
{
struct devlink_health_reporter *reporter;
if (WARN_ON(graceful_period && !ops->recover))
return ERR_PTR(-EINVAL);
reporter = kzalloc(sizeof(*reporter), GFP_KERNEL);
if (!reporter)
return ERR_PTR(-ENOMEM);
reporter->priv = priv;
reporter->ops = ops;
reporter->devlink = devlink;
reporter->graceful_period = graceful_period;
reporter->auto_recover = !!ops->recover;
reporter->auto_dump = !!ops->dump;
mutex_init(&reporter->dump_lock);
refcount_set(&reporter->refcount, 1);
return reporter;
}
/** /**
* devlink_health_reporter_create - create devlink health reporter * devlink_health_reporter_create - create devlink health reporter
* *
...@@ -5342,25 +5367,11 @@ devlink_health_reporter_create(struct devlink *devlink, ...@@ -5342,25 +5367,11 @@ devlink_health_reporter_create(struct devlink *devlink,
goto unlock; goto unlock;
} }
if (WARN_ON(graceful_period && !ops->recover)) { reporter = __devlink_health_reporter_create(devlink, ops,
reporter = ERR_PTR(-EINVAL); graceful_period, priv);
if (IS_ERR(reporter))
goto unlock; goto unlock;
}
reporter = kzalloc(sizeof(*reporter), GFP_KERNEL);
if (!reporter) {
reporter = ERR_PTR(-ENOMEM);
goto unlock;
}
reporter->priv = priv;
reporter->ops = ops;
reporter->devlink = devlink;
reporter->graceful_period = graceful_period;
reporter->auto_recover = !!ops->recover;
reporter->auto_dump = !!ops->dump;
mutex_init(&reporter->dump_lock);
refcount_set(&reporter->refcount, 1);
list_add_tail(&reporter->list, &devlink->reporter_list); list_add_tail(&reporter->list, &devlink->reporter_list);
unlock: unlock:
mutex_unlock(&devlink->reporters_lock); mutex_unlock(&devlink->reporters_lock);
......
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