const struct dpif_class dpif_netdev_class = {
"netdev",
+ NULL, /* init */
dpif_netdev_enumerate,
dpif_netdev_port_open_type,
dpif_netdev_open,
const struct dpif_class dpif_netlink_class = {
"system",
+ NULL, /* init */
dpif_netlink_enumerate,
NULL,
dpif_netlink_open,
* 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
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",
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;