[ovs-dev] [PATCH v4 1/2] netdev-dpdk: add dpdk support to the if-notifier API

Eelco Chaudron echaudro at redhat.com
Thu Oct 31 12:12:46 UTC 2019


This patch adds support for DPDK to notify link layer changes trough
the if_notifier_xxx() APIs.

Signed-off-by: Eelco Chaudron <echaudro at redhat.com>
---
 lib/automake.mk        |    4 ++
 lib/if-notifier-dpdk.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/if-notifier-dpdk.h |   46 +++++++++++++++++++++++++++
 lib/if-notifier.c      |   21 +++++++++++-
 4 files changed, 149 insertions(+), 4 deletions(-)
 create mode 100644 lib/if-notifier-dpdk.c
 create mode 100644 lib/if-notifier-dpdk.h

diff --git a/lib/automake.mk b/lib/automake.mk
index 17b36b4..add04e7 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -395,6 +395,7 @@ lib_libopenvswitch_la_SOURCES += \
 	lib/dpif-netlink-rtnl.h \
 	lib/if-notifier.c \
 	lib/if-notifier.h \
+	lib/if-notifier-dpdk.h \
 	lib/netdev-linux.c \
 	lib/netdev-linux.h \
 	lib/netdev-linux-private.h \
@@ -426,7 +427,8 @@ if DPDK_NETDEV
 lib_libopenvswitch_la_SOURCES += \
 	lib/dpdk.c \
 	lib/netdev-dpdk.c \
-	lib/netdev-offload-dpdk.c
+	lib/netdev-offload-dpdk.c \
+	lib/if-notifier-dpdk.c
 else
 lib_libopenvswitch_la_SOURCES += \
 	lib/dpdk-stub.c
diff --git a/lib/if-notifier-dpdk.c b/lib/if-notifier-dpdk.c
new file mode 100644
index 0000000..145e0e4
--- /dev/null
+++ b/lib/if-notifier-dpdk.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <config.h>
+
+#include "if-notifier-dpdk.h"
+#include "ovs-thread.h"
+#include "openvswitch/list.h"
+
+static struct ovs_mutex dpdk_notifiers_mutex = OVS_MUTEX_INITIALIZER;
+static struct ovs_list dpdk_all_notifiers OVS_GUARDED_BY(dpdk_notifiers_mutex) \
+    = OVS_LIST_INITIALIZER(&dpdk_all_notifiers);
+
+struct dpdk_notifier {
+    struct ovs_list node;
+    dpdk_notify_func *cb;
+    void *aux;
+};
+
+struct dpdk_notifier *
+dpdk_notifier_create(dpdk_notify_func *cb, void *aux)
+{
+    struct dpdk_notifier *new = xmalloc(sizeof *new);
+
+    ovs_mutex_lock(&dpdk_notifiers_mutex);
+
+    new->cb = cb;
+    new->aux = aux;
+    ovs_list_push_back(&dpdk_all_notifiers, &new->node);
+
+    ovs_mutex_unlock(&dpdk_notifiers_mutex);
+
+    return new;
+}
+
+void
+dpdk_notifier_destroy(struct dpdk_notifier *notifier)
+{
+    if (!notifier) {
+        return;
+    }
+
+    ovs_mutex_lock(&dpdk_notifiers_mutex);
+
+    ovs_list_remove(&notifier->node);
+    free(notifier);
+
+    ovs_mutex_unlock(&dpdk_notifiers_mutex);
+}
+
+void
+dpdk_notifierr_report_link(void)
+{
+    struct dpdk_notifier *notifier;
+
+    ovs_mutex_lock(&dpdk_notifiers_mutex);
+
+    LIST_FOR_EACH (notifier, node, &dpdk_all_notifiers) {
+        if (!notifier->cb) {
+            continue;
+        }
+
+        notifier->cb(notifier->aux);
+    }
+
+    ovs_mutex_unlock(&dpdk_notifiers_mutex);
+}
+
+
diff --git a/lib/if-notifier-dpdk.h b/lib/if-notifier-dpdk.h
new file mode 100644
index 0000000..19cf36e
--- /dev/null
+++ b/lib/if-notifier-dpdk.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IF_NOTIFIER_DPDK_H
+#define IF_NOTIFIER_DPDK_H 1
+
+typedef void dpdk_notify_func(void *aux);
+
+struct dpdk_notifier;
+
+#ifdef DPDK_NETDEV
+
+struct dpdk_notifier *dpdk_notifier_create(dpdk_notify_func *cb, void *aux);
+void dpdk_notifier_destroy(struct dpdk_notifier *notifier);
+void dpdk_notifierr_report_link(void);
+
+#else
+
+static inline struct dpdk_notifier *dpdk_notifier_create(
+    dpdk_notify_func *cb OVS_UNUSED, void *aux OVS_UNUSED)
+{
+    return NULL;
+}
+
+static inline void dpdk_notifier_destroy(
+    struct dpdk_notifier *notifier OVS_UNUSED)
+{
+}
+
+#endif
+
+
+#endif /* if-notifier-dpdk.h */
diff --git a/lib/if-notifier.c b/lib/if-notifier.c
index 9a64f9b..4ecd559 100644
--- a/lib/if-notifier.c
+++ b/lib/if-notifier.c
@@ -18,9 +18,11 @@
 #include "if-notifier.h"
 #include "rtnetlink.h"
 #include "util.h"
+#include "if-notifier-dpdk.h"
 
 struct if_notifier {
-    struct nln_notifier *notifier;
+    struct nln_notifier *nl_notifier;
+    struct dpdk_notifier *dpdk_notifier;
     if_notify_func *cb;
     void *aux;
 };
@@ -33,6 +35,15 @@ if_notifier_cb(const struct rtnetlink_change *change OVS_UNUSED, void *aux)
     notifier->cb(notifier->aux);
 }
 
+static void
+dpdk_if_notifier_cb(void *aux)
+{
+    struct if_notifier *notifier;
+    notifier = aux;
+    notifier->cb(notifier->aux);
+}
+
+
 struct if_notifier *
 if_notifier_create(if_notify_func *cb, void *aux)
 {
@@ -40,7 +51,10 @@ if_notifier_create(if_notify_func *cb, void *aux)
     notifier = xmalloc(sizeof *notifier);
     notifier->cb = cb;
     notifier->aux = aux;
-    notifier->notifier = rtnetlink_notifier_create(if_notifier_cb, notifier);
+    notifier->nl_notifier = rtnetlink_notifier_create(if_notifier_cb,
+                                                      notifier);
+    notifier->dpdk_notifier = dpdk_notifier_create(dpdk_if_notifier_cb,
+                                                   notifier);
     return notifier;
 }
 
@@ -48,7 +62,8 @@ void
 if_notifier_destroy(struct if_notifier *notifier)
 {
     if (notifier) {
-        rtnetlink_notifier_destroy(notifier->notifier);
+        rtnetlink_notifier_destroy(notifier->nl_notifier);
+        dpdk_notifier_destroy(notifier->dpdk_notifier);
         free(notifier);
     }
 }



More information about the dev mailing list