summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniele Di Proietto <diproiettod@vmware.com>2015-04-10 19:09:49 +0100
committerEthan Jackson <ethan@nicira.com>2015-04-14 12:30:11 -0700
commitc8973eb634a8efff7593d2a2c160e2b8c09a8c3f (patch)
tree0264a0f63d26b57faa8f1977259eedd92ff4c938 /lib
parent55e3ca97d1cb8ee7de496381ef48ff248f527787 (diff)
downloadopenvswitch-c8973eb634a8efff7593d2a2c160e2b8c09a8c3f.tar.gz
dpif-provider: Add class init function.
This init function is called when the dpif class is registered. It will be used by following commits Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Acked-by: Ethan Jackson <ethan@nicira.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dpif-netdev.c1
-rw-r--r--lib/dpif-netlink.c1
-rw-r--r--lib/dpif-provider.h8
-rw-r--r--lib/dpif.c8
4 files changed, 18 insertions, 0 deletions
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 5ac98e8b9..54e941aa5 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -3353,6 +3353,7 @@ dp_netdev_execute_actions(struct dp_netdev_pmd_thread *pmd,
const struct dpif_class dpif_netdev_class = {
"netdev",
+ NULL, /* init */
dpif_netdev_enumerate,
dpif_netdev_port_open_type,
dpif_netdev_open,
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 93fd8a451..ef9d31871 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -2274,6 +2274,7 @@ dpif_netlink_get_datapath_version(void)
const struct dpif_class dpif_netlink_class = {
"system",
+ NULL, /* init */
dpif_netlink_enumerate,
NULL,
dpif_netlink_open,
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index 7b4878eb5..28ea86f48 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -90,6 +90,14 @@ struct dpif_class {
* the type assumed if no type is specified when opening a dpif. */
const char *type;
+ /* Called when the dpif provider is registered, typically at program
+ * startup. Returning an error from this function will prevent any
+ * datapath with this class from being created.
+ *
+ * This function may be set to null if a datapath class needs no
+ * initialization at registration time. */
+ int (*init)(void);
+
/* Enumerates the names of all known created datapaths (of class
* 'dpif_class'), if possible, into 'all_dps'. The caller has already
* initialized 'all_dps' and other dpif classes might already have added
diff --git a/lib/dpif.c b/lib/dpif.c
index ee71774a7..b8f30a503 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -135,6 +135,7 @@ static int
dp_register_provider__(const struct dpif_class *new_class)
{
struct registered_dpif_class *registered_class;
+ int error;
if (sset_contains(&dpif_blacklist, new_class->type)) {
VLOG_DBG("attempted to register blacklisted provider: %s",
@@ -148,6 +149,13 @@ dp_register_provider__(const struct dpif_class *new_class)
return EEXIST;
}
+ error = new_class->init ? new_class->init() : 0;
+ if (error) {
+ VLOG_WARN("failed to initialize %s datapath class: %s",
+ new_class->type, ovs_strerror(error));
+ return error;
+ }
+
registered_class = xmalloc(sizeof *registered_class);
registered_class->dpif_class = new_class;
registered_class->refcount = 0;