Introduce a new module - "library".
This module manages the set of libraries available to OVS, currently
only dpdk.
Instead of dedicated "dpdk_init" and "dpdk_status" commands from the
bridge module, have a generic method that can also be extended for it.

The legacy "dpdk-init=true" method is preserved for backward
compatibility.

To see the available libraries to add:
ovs-appctl library/list

Signed-off-by: Eli Britstein <[email protected]>
---
 lib/automake.mk         |   3 +
 lib/library-provider.h  |  25 ++++++++
 lib/library.c           | 123 ++++++++++++++++++++++++++++++++++++++++
 lib/library.h           |  18 ++++++
 vswitchd/bridge.c       |  18 ++++++
 vswitchd/ovs-vswitchd.c |   2 +
 6 files changed, 189 insertions(+)
 create mode 100644 lib/library-provider.h
 create mode 100644 lib/library.c
 create mode 100644 lib/library.h

diff --git a/lib/automake.mk b/lib/automake.mk
index 78d6e6516..6c9362f77 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -188,6 +188,9 @@ lib_libopenvswitch_la_SOURCES = \
        lib/learn.h \
        lib/learning-switch.c \
        lib/learning-switch.h \
+       lib/library.c \
+       lib/library.h \
+       lib/library-provider.h \
        lib/lockfile.c \
        lib/lockfile.h \
        lib/mac-learning.c \
diff --git a/lib/library-provider.h b/lib/library-provider.h
new file mode 100644
index 000000000..930421e38
--- /dev/null
+++ b/lib/library-provider.h
@@ -0,0 +1,25 @@
+
+#ifndef LIBRARY_PROVIDER_H
+#define LIBRARY_PROVIDER_H 1
+
+struct ovsrec_library;
+struct smap;
+
+struct library_class {
+    const char *name;
+
+/* ## ------------------- ## */
+/* ## Top-Level Functions ## */
+/* ## ------------------- ## */
+
+    /* Called when the library provider is registered, typically at program
+     * startup.  Returning an error from this function will prevent any network
+     * device in this class from being opened.
+     *
+     * This function may be set to null if a network device class needs no
+     * initialization at registration time. */
+    void (*init)(const struct smap *cfg);
+    void (*status)(const struct ovsrec_library *lib);
+};
+
+#endif /* LIBRARY_PROVIDER_H */
diff --git a/lib/library.c b/lib/library.c
new file mode 100644
index 000000000..ad6657bbb
--- /dev/null
+++ b/lib/library.c
@@ -0,0 +1,123 @@
+/* NVIDIA */
+
+#include <config.h>
+
+#include <errno.h>
+
+#include "cmap.h"
+#include "hash.h"
+#include "library.h"
+#include "library-provider.h"
+#include "openvswitch/dynamic-string.h"
+#include "openvswitch/vlog.h"
+#include "ovs-thread.h"
+#include "unixctl.h"
+#include "util.h"
+#include "vswitch-idl.h"
+
+VLOG_DEFINE_THIS_MODULE(library);
+
+struct library_registered_class {
+    struct cmap_node cmap_node; /* In 'library_classes', by class->name. */
+    const struct library_class *class;
+};
+
+static struct ovs_mutex library_class_mutex = OVS_MUTEX_INITIALIZER;
+
+/* Contains 'struct library_registered_class'es. */
+static struct cmap library_classes = CMAP_INITIALIZER;
+
+static struct library_registered_class *
+library_lookup_class(const char *name)
+{
+    struct library_registered_class *rc;
+
+    CMAP_FOR_EACH_WITH_HASH (rc, cmap_node, hash_string(name, 0),
+                             &library_classes) {
+        if (!strcmp(name, rc->class->name)) {
+            return rc;
+        }
+    }
+    return NULL;
+}
+
+/* Initializes and registers a new library provider. */
+OVS_UNUSED
+static int
+library_register_one(const struct library_class *new_class)
+    OVS_EXCLUDED(library_class_mutex)
+{
+    int error = 0;
+
+    ovs_mutex_lock(&library_class_mutex);
+    if (library_lookup_class(new_class->name)) {
+        VLOG_WARN("attempted to register duplicate library provider: %s",
+                   new_class->name);
+        error = EEXIST;
+    } else {
+        struct library_registered_class *rc;
+
+        rc = xmalloc(sizeof *rc);
+        rc->class = new_class;
+        cmap_insert(&library_classes, &rc->cmap_node,
+                    hash_string(new_class->name, 0));
+    }
+    ovs_mutex_unlock(&library_class_mutex);
+
+    return error;
+}
+
+static void
+library_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
+             const char *argv[] OVS_UNUSED,
+             void *aux OVS_UNUSED)
+{
+    struct ds reply = DS_EMPTY_INITIALIZER;
+    struct library_registered_class *rc;
+
+    CMAP_FOR_EACH (rc, cmap_node, &library_classes) {
+        ds_put_format(&reply, "- %s\n", rc->class->name);
+    }
+    unixctl_command_reply(conn, ds_cstr(&reply));
+    ds_destroy(&reply);
+}
+
+void
+library_register(void)
+{
+    unixctl_command_register("library/list", "",
+                             0, 0, library_list,
+                             NULL);
+}
+
+void
+library_init(const char *name, const struct smap *cfg)
+{
+    struct library_registered_class *rc;
+
+    rc = library_lookup_class(name);
+    if (!rc) {
+        VLOG_WARN_ONCE("Unkown library '%s'", name);
+        return;
+    }
+
+    if (!rc->class->init) {
+        return;
+    }
+
+    rc->class->init(cfg);
+}
+
+void
+library_status(const struct ovsrec_library *lib_cfg)
+{
+    struct library_registered_class *rc;
+
+    rc = library_lookup_class(lib_cfg->name);
+    if (!rc) {
+        VLOG_WARN_ONCE("Unkown library '%s'", lib_cfg->name);
+        return;
+    }
+
+    rc->class->status(lib_cfg);
+}
diff --git a/lib/library.h b/lib/library.h
new file mode 100644
index 000000000..b1f804cb5
--- /dev/null
+++ b/lib/library.h
@@ -0,0 +1,18 @@
+/* NVIDIA */
+
+#ifndef LIBRARY_H
+#define LIBRARY_H 1
+
+struct ovsrec_library;
+struct smap;
+
+void
+library_register(void);
+
+void
+library_init(const char *name, const struct smap *cfg);
+
+void
+library_status(const struct ovsrec_library *lib_cfg);
+
+#endif /* LIBRARY_H */
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 4294caf8a..9df3f4115 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -35,6 +35,7 @@
 #include "if-notifier.h"
 #include "jsonrpc.h"
 #include "lacp.h"
+#include "library.h"
 #include "mac-learning.h"
 #include "mcast-snooping.h"
 #include "netdev.h"
@@ -263,6 +264,7 @@ static uint64_t last_ifaces_changed;
 #define BRIDGE_CONTROLLER_PACKET_QUEUE_MIN_SIZE 1
 #define BRIDGE_CONTROLLER_PACKET_QUEUE_MAX_SIZE 512
 
+static void libraries_config(const struct ovsrec_open_vswitch *);
 static void add_del_bridges(const struct ovsrec_open_vswitch *);
 static void bridge_run__(void);
 static void bridge_create(const struct ovsrec_bridge *);
@@ -896,6 +898,8 @@ bridge_reconfigure(const struct ovsrec_open_vswitch 
*ovs_cfg)
         smap_get_bool(&ovs_cfg->other_config, "explicit-sampled-drops",
                       OFPROTO_EXPLICIT_SAMPLED_DROPS_DEFAULT));
 
+    libraries_config(ovs_cfg);
+
     /* Destroy "struct bridge"s, "struct port"s, and "struct iface"s according
      * to 'ovs_cfg', with only very minimal configuration otherwise.
      *
@@ -2154,6 +2158,20 @@ add_del_bridges(const struct ovsrec_open_vswitch *cfg)
     shash_destroy(&new_br);
 }
 
+static void
+libraries_config(const struct ovsrec_open_vswitch *cfg)
+{
+    size_t i;
+
+    /* Collect new libraries' names. */
+    for (i = 0; i < cfg->n_libraries; i++) {
+        const struct ovsrec_library *lib_cfg = cfg->libraries[i];
+
+        library_init(lib_cfg->name, &lib_cfg->config);
+        library_status(lib_cfg);
+    }
+}
+
 /* Configures 'netdev' based on the "options" column in 'iface_cfg'.
  * Returns 0 if successful, otherwise a positive errno value. */
 static int
diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c
index 6d90c73b8..f9fa3d554 100644
--- a/vswitchd/ovs-vswitchd.c
+++ b/vswitchd/ovs-vswitchd.c
@@ -33,6 +33,7 @@
 #include "dpif.h"
 #include "dummy.h"
 #include "fatal-signal.h"
+#include "lib/library.h"
 #include "memory.h"
 #include "netdev.h"
 #include "openflow/openflow.h"
@@ -120,6 +121,7 @@ main(int argc, char *argv[])
     unixctl_command_register("exit", "[--cleanup]", 0, 1,
                              ovs_vswitchd_exit, NULL);
 
+    library_register();
     bridge_init(remote);
     free(remote);
 
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to