diff mbox series

[net-next,5/7] devlink: Add devlink health port reporters API

Message ID 1593702493-15323-6-git-send-email-moshe@mellanox.com
State Changes Requested
Delegated to: David Miller
Headers show
Series Add devlink-health support for devlink ports | expand

Commit Message

Moshe Shemesh July 2, 2020, 3:08 p.m. UTC
From: Vladyslav Tarasiuk <vladyslavt@mellanox.com>

In order to use new devlink port health reporters infrastructure, add
corresponding constructor and destructor functions.

Signed-off-by: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
---
 include/net/devlink.h |  9 +++++++++
 net/core/devlink.c    | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

Comments

Jakub Kicinski July 2, 2020, 4:40 p.m. UTC | #1
On Thu,  2 Jul 2020 18:08:11 +0300 Moshe Shemesh wrote:
> From: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
> 
> In order to use new devlink port health reporters infrastructure, add
> corresponding constructor and destructor functions.
> 
> Signed-off-by: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
> Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
> Reviewed-by: Jiri Pirko <jiri@mellanox.com>

net/core/devlink.c:5361: warning: Function parameter or member 'port' not described in 'devlink_port_health_reporter_create'
net/core/devlink.c:5361: warning: Excess function parameter 'devlink_port' description in 'devlink_port_health_reporter_create'
net/core/devlink.c:5462: warning: Excess function parameter 'port' description in 'devlink_port_health_reporter_destroy'
Moshe Shemesh July 2, 2020, 5:48 p.m. UTC | #2
On 7/2/2020 7:40 PM, Jakub Kicinski wrote:
> On Thu,  2 Jul 2020 18:08:11 +0300 Moshe Shemesh wrote:
>> From: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
>>
>> In order to use new devlink port health reporters infrastructure, add
>> corresponding constructor and destructor functions.
>>
>> Signed-off-by: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
>> Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
>> Reviewed-by: Jiri Pirko <jiri@mellanox.com>
> net/core/devlink.c:5361: warning: Function parameter or member 'port' not described in 'devlink_port_health_reporter_create'
> net/core/devlink.c:5361: warning: Excess function parameter 'devlink_port' description in 'devlink_port_health_reporter_create'
> net/core/devlink.c:5462: warning: Excess function parameter 'port' description in 'devlink_port_health_reporter_destroy'


I will resend with a fix. Thanks.
diff mbox series

Patch

diff --git a/include/net/devlink.h b/include/net/devlink.h
index d3ac152..2082062 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -1336,9 +1336,18 @@  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 *
+devlink_port_health_reporter_create(struct devlink_port *port,
+				    const struct devlink_health_reporter_ops *ops,
+				    u64 graceful_period, void *priv);
+
 void
 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
 
+void
+devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
+
 void *
 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
 int devlink_health_report(struct devlink_health_reporter *reporter,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 8aedd20..e0bb045 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -5346,6 +5346,42 @@  struct devlink_health_reporter {
 }
 
 /**
+ *	devlink_port_health_reporter_create - create devlink health reporter for
+ *	                                      specified port instance
+ *
+ *	@devlink_port: devlink_port
+ *	@ops: ops
+ *	@graceful_period: to avoid recovery loops, in msecs
+ *	@priv: priv
+ */
+struct devlink_health_reporter *
+devlink_port_health_reporter_create(struct devlink_port *port,
+				    const struct devlink_health_reporter_ops *ops,
+				    u64 graceful_period, void *priv)
+{
+	struct devlink_health_reporter *reporter;
+
+	mutex_lock(&port->reporters_lock);
+	if (__devlink_health_reporter_find_by_name(&port->reporter_list,
+						   &port->reporters_lock, ops->name)) {
+		reporter = ERR_PTR(-EEXIST);
+		goto unlock;
+	}
+
+	reporter = __devlink_health_reporter_create(port->devlink, ops,
+						    graceful_period, priv);
+	if (IS_ERR(reporter))
+		goto unlock;
+
+	reporter->devlink_port = port;
+	list_add_tail(&reporter->list, &port->reporter_list);
+unlock:
+	mutex_unlock(&port->reporters_lock);
+	return reporter;
+}
+EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create);
+
+/**
  *	devlink_health_reporter_create - create devlink health reporter
  *
  *	@devlink: devlink
@@ -5415,6 +5451,21 @@  struct devlink_health_reporter *
 }
 EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
 
+/**
+ *	devlink_port_health_reporter_destroy - destroy devlink port health reporter
+ *
+ *	@port: devlink_port which should contain specified reporter
+ *	@reporter: devlink health reporter to destroy
+ */
+void
+devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter)
+{
+	mutex_lock(&reporter->devlink_port->reporters_lock);
+	__devlink_health_reporter_destroy(reporter);
+	mutex_unlock(&reporter->devlink_port->reporters_lock);
+}
+EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy);
+
 static int
 devlink_nl_health_reporter_fill(struct sk_buff *msg,
 				struct devlink *devlink,