]> git.baikalelectronics.ru Git - kernel.git/commitdiff
devlink: Add devlink health port reporters API
authorVladyslav Tarasiuk <vladyslavt@mellanox.com>
Fri, 10 Jul 2020 12:25:11 +0000 (15:25 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 Jul 2020 21:32:02 +0000 (14:32 -0700)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/devlink.h
net/core/devlink.c

index bb1139752405b72e14d3366704dfd90f239e3238..913e8679ae35a5f8e29404db0b11845291049492 100644 (file)
@@ -1338,9 +1338,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,
index b4a231ca7135226cc51fabb960b90b3f3015fd00..20a83aace64208996cafb752d25cb594ef319376 100644 (file)
@@ -5371,6 +5371,42 @@ __devlink_health_reporter_create(struct devlink *devlink,
        return reporter;
 }
 
+/**
+ *     devlink_port_health_reporter_create - create devlink health reporter for
+ *                                           specified port instance
+ *
+ *     @port: devlink_port which should contain the new reporter
+ *     @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
  *
@@ -5441,6 +5477,20 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
 }
 EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
 
+/**
+ *     devlink_port_health_reporter_destroy - destroy devlink port health 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,