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

devlink: remove reporter reference counting

As long as the reporter life time is protected by devlink instance
lock, the reference counting is no longer needed. Remove it.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 9f167327
...@@ -7269,7 +7269,6 @@ struct devlink_health_reporter { ...@@ -7269,7 +7269,6 @@ struct devlink_health_reporter {
u64 error_count; u64 error_count;
u64 recovery_count; u64 recovery_count;
u64 last_recovery_ts; u64 last_recovery_ts;
refcount_t refcount;
}; };
void * void *
...@@ -7328,7 +7327,6 @@ __devlink_health_reporter_create(struct devlink *devlink, ...@@ -7328,7 +7327,6 @@ __devlink_health_reporter_create(struct devlink *devlink,
reporter->auto_recover = !!ops->recover; reporter->auto_recover = !!ops->recover;
reporter->auto_dump = !!ops->dump; reporter->auto_dump = !!ops->dump;
mutex_init(&reporter->dump_lock); mutex_init(&reporter->dump_lock);
refcount_set(&reporter->refcount, 1);
return reporter; return reporter;
} }
...@@ -7435,13 +7433,6 @@ devlink_health_reporter_free(struct devlink_health_reporter *reporter) ...@@ -7435,13 +7433,6 @@ devlink_health_reporter_free(struct devlink_health_reporter *reporter)
kfree(reporter); kfree(reporter);
} }
static void
devlink_health_reporter_put(struct devlink_health_reporter *reporter)
{
if (refcount_dec_and_test(&reporter->refcount))
devlink_health_reporter_free(reporter);
}
/** /**
* devl_health_reporter_destroy - destroy devlink health reporter * devl_health_reporter_destroy - destroy devlink health reporter
* *
...@@ -7453,7 +7444,7 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter) ...@@ -7453,7 +7444,7 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter)
devl_assert_locked(reporter->devlink); devl_assert_locked(reporter->devlink);
list_del(&reporter->list); list_del(&reporter->list);
devlink_health_reporter_put(reporter); devlink_health_reporter_free(reporter);
} }
EXPORT_SYMBOL_GPL(devl_health_reporter_destroy); EXPORT_SYMBOL_GPL(devl_health_reporter_destroy);
...@@ -7697,7 +7688,6 @@ static struct devlink_health_reporter * ...@@ -7697,7 +7688,6 @@ static struct devlink_health_reporter *
devlink_health_reporter_get_from_attrs(struct devlink *devlink, devlink_health_reporter_get_from_attrs(struct devlink *devlink,
struct nlattr **attrs) struct nlattr **attrs)
{ {
struct devlink_health_reporter *reporter;
struct devlink_port *devlink_port; struct devlink_port *devlink_port;
char *reporter_name; char *reporter_name;
...@@ -7706,17 +7696,12 @@ devlink_health_reporter_get_from_attrs(struct devlink *devlink, ...@@ -7706,17 +7696,12 @@ devlink_health_reporter_get_from_attrs(struct devlink *devlink,
reporter_name = nla_data(attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]); reporter_name = nla_data(attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]);
devlink_port = devlink_port_get_from_attrs(devlink, attrs); devlink_port = devlink_port_get_from_attrs(devlink, attrs);
if (IS_ERR(devlink_port)) { if (IS_ERR(devlink_port))
reporter = devlink_health_reporter_find_by_name(devlink, reporter_name); return devlink_health_reporter_find_by_name(devlink,
if (reporter) reporter_name);
refcount_inc(&reporter->refcount); else
} else { return devlink_port_health_reporter_find_by_name(devlink_port,
reporter = devlink_port_health_reporter_find_by_name(devlink_port, reporter_name); reporter_name);
if (reporter)
refcount_inc(&reporter->refcount);
}
return reporter;
} }
static struct devlink_health_reporter * static struct devlink_health_reporter *
...@@ -7775,10 +7760,8 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, ...@@ -7775,10 +7760,8 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
return -EINVAL; return -EINVAL;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) { if (!msg)
err = -ENOMEM; return -ENOMEM;
goto out;
}
err = devlink_nl_health_reporter_fill(msg, reporter, err = devlink_nl_health_reporter_fill(msg, reporter,
DEVLINK_CMD_HEALTH_REPORTER_GET, DEVLINK_CMD_HEALTH_REPORTER_GET,
...@@ -7786,13 +7769,10 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, ...@@ -7786,13 +7769,10 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
0); 0);
if (err) { if (err) {
nlmsg_free(msg); nlmsg_free(msg);
goto out; return err;
} }
err = genlmsg_reply(msg, info); return genlmsg_reply(msg, info);
out:
devlink_health_reporter_put(reporter);
return err;
} }
static int static int
...@@ -7866,7 +7846,6 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, ...@@ -7866,7 +7846,6 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink *devlink = info->user_ptr[0];
struct devlink_health_reporter *reporter; struct devlink_health_reporter *reporter;
int err;
reporter = devlink_health_reporter_get_from_info(devlink, info); reporter = devlink_health_reporter_get_from_info(devlink, info);
if (!reporter) if (!reporter)
...@@ -7874,15 +7853,12 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, ...@@ -7874,15 +7853,12 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
if (!reporter->ops->recover && if (!reporter->ops->recover &&
(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] || (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] ||
info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])) { info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]))
err = -EOPNOTSUPP; return -EOPNOTSUPP;
goto out;
}
if (!reporter->ops->dump && if (!reporter->ops->dump &&
info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]) { info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP])
err = -EOPNOTSUPP; return -EOPNOTSUPP;
goto out;
}
if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]) if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD])
reporter->graceful_period = reporter->graceful_period =
...@@ -7896,11 +7872,7 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, ...@@ -7896,11 +7872,7 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
reporter->auto_dump = reporter->auto_dump =
nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]); nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]);
devlink_health_reporter_put(reporter);
return 0; return 0;
out:
devlink_health_reporter_put(reporter);
return err;
} }
static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb, static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
...@@ -7908,16 +7880,12 @@ static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb, ...@@ -7908,16 +7880,12 @@ static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink *devlink = info->user_ptr[0];
struct devlink_health_reporter *reporter; struct devlink_health_reporter *reporter;
int err;
reporter = devlink_health_reporter_get_from_info(devlink, info); reporter = devlink_health_reporter_get_from_info(devlink, info);
if (!reporter) if (!reporter)
return -EINVAL; return -EINVAL;
err = devlink_health_reporter_recover(reporter, NULL, info->extack); return devlink_health_reporter_recover(reporter, NULL, info->extack);
devlink_health_reporter_put(reporter);
return err;
} }
static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
...@@ -7932,36 +7900,27 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, ...@@ -7932,36 +7900,27 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
if (!reporter) if (!reporter)
return -EINVAL; return -EINVAL;
if (!reporter->ops->diagnose) { if (!reporter->ops->diagnose)
devlink_health_reporter_put(reporter);
return -EOPNOTSUPP; return -EOPNOTSUPP;
}
fmsg = devlink_fmsg_alloc(); fmsg = devlink_fmsg_alloc();
if (!fmsg) { if (!fmsg)
devlink_health_reporter_put(reporter);
return -ENOMEM; return -ENOMEM;
}
err = devlink_fmsg_obj_nest_start(fmsg); err = devlink_fmsg_obj_nest_start(fmsg);
if (err) if (err)
goto out; return err;
err = reporter->ops->diagnose(reporter, fmsg, info->extack); err = reporter->ops->diagnose(reporter, fmsg, info->extack);
if (err) if (err)
goto out; return err;
err = devlink_fmsg_obj_nest_end(fmsg); err = devlink_fmsg_obj_nest_end(fmsg);
if (err) if (err)
goto out; return err;
err = devlink_fmsg_snd(fmsg, info,
DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0);
out: return devlink_fmsg_snd(fmsg, info,
devlink_fmsg_free(fmsg); DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0);
devlink_health_reporter_put(reporter);
return err;
} }
static int static int
...@@ -7976,10 +7935,9 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, ...@@ -7976,10 +7935,9 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb,
if (!reporter) if (!reporter)
return -EINVAL; return -EINVAL;
if (!reporter->ops->dump) { if (!reporter->ops->dump)
err = -EOPNOTSUPP; return -EOPNOTSUPP;
goto out;
}
mutex_lock(&reporter->dump_lock); mutex_lock(&reporter->dump_lock);
if (!state->idx) { if (!state->idx) {
err = devlink_health_do_dump(reporter, NULL, cb->extack); err = devlink_health_do_dump(reporter, NULL, cb->extack);
...@@ -7997,8 +7955,6 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, ...@@ -7997,8 +7955,6 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb,
DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET); DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET);
unlock: unlock:
mutex_unlock(&reporter->dump_lock); mutex_unlock(&reporter->dump_lock);
out:
devlink_health_reporter_put(reporter);
return err; return err;
} }
...@@ -8013,15 +7969,12 @@ devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb, ...@@ -8013,15 +7969,12 @@ devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
if (!reporter) if (!reporter)
return -EINVAL; return -EINVAL;
if (!reporter->ops->dump) { if (!reporter->ops->dump)
devlink_health_reporter_put(reporter);
return -EOPNOTSUPP; return -EOPNOTSUPP;
}
mutex_lock(&reporter->dump_lock); mutex_lock(&reporter->dump_lock);
devlink_health_dump_clear(reporter); devlink_health_dump_clear(reporter);
mutex_unlock(&reporter->dump_lock); mutex_unlock(&reporter->dump_lock);
devlink_health_reporter_put(reporter);
return 0; return 0;
} }
...@@ -8030,21 +7983,15 @@ static int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb, ...@@ -8030,21 +7983,15 @@ static int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb,
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink *devlink = info->user_ptr[0];
struct devlink_health_reporter *reporter; struct devlink_health_reporter *reporter;
int err;
reporter = devlink_health_reporter_get_from_info(devlink, info); reporter = devlink_health_reporter_get_from_info(devlink, info);
if (!reporter) if (!reporter)
return -EINVAL; return -EINVAL;
if (!reporter->ops->test) { if (!reporter->ops->test)
devlink_health_reporter_put(reporter);
return -EOPNOTSUPP; return -EOPNOTSUPP;
}
err = reporter->ops->test(reporter, info->extack);
devlink_health_reporter_put(reporter); return reporter->ops->test(reporter, info->extack);
return err;
} }
struct devlink_stats { struct devlink_stats {
......
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