dpif-netdev: enumerate dpif belonging to the right class
authorDaniele Di Proietto <ddiproietto@vmware.com>
Thu, 12 Jun 2014 23:37:33 +0000 (16:37 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 12 Jun 2014 23:54:12 +0000 (16:54 -0700)
Since dpif_netdev_enumerate() is used for "netdev" and "dummy" class, it
incorrectly lists dpif-netdevs as "dummy" and vice versa.
This patches address the issue by changing the dpif-provider interface: a
dpif_class parameter is passed to the 'enumerate' call to match the right class.

Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/dpif-linux.c
lib/dpif-netdev.c
lib/dpif-provider.h
lib/dpif.c

index 63e66f3..afe9340 100644 (file)
@@ -195,7 +195,8 @@ dpif_linux_cast(const struct dpif *dpif)
 }
 
 static int
-dpif_linux_enumerate(struct sset *all_dps)
+dpif_linux_enumerate(struct sset *all_dps,
+                     const struct dpif_class *dpif_class OVS_UNUSED)
 {
     struct nl_dump dump;
     uint64_t reply_stub[NL_DUMP_BUFSIZE / 8];
index d4627b2..6c281fe 100644 (file)
@@ -360,12 +360,19 @@ get_dp_netdev(const struct dpif *dpif)
 }
 
 static int
-dpif_netdev_enumerate(struct sset *all_dps)
+dpif_netdev_enumerate(struct sset *all_dps,
+                      const struct dpif_class *dpif_class)
 {
     struct shash_node *node;
 
     ovs_mutex_lock(&dp_netdev_mutex);
     SHASH_FOR_EACH(node, &dp_netdevs) {
+        struct dp_netdev *dp = node->data;
+        if (dpif_class != dp->class) {
+            /* 'dp_netdevs' contains both "netdev" and "dummy" dpifs.
+             * If the class doesn't match, skip this dpif. */
+             continue;
+        }
         sset_add(all_dps, node->name);
     }
     ovs_mutex_unlock(&dp_netdev_mutex);
index d0b2eaf..b762ac0 100644 (file)
@@ -89,16 +89,17 @@ struct dpif_class {
      * the type assumed if no type is specified when opening a dpif. */
     const char *type;
 
-    /* Enumerates the names of all known created datapaths, if possible, into
-     * 'all_dps'.  The caller has already initialized 'all_dps' and other dpif
-     * classes might already have added names to it.
+    /* 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
+     * names to it.
      *
      * This is used by the vswitch at startup, so that it can delete any
      * datapaths that are not configured.
      *
      * Some kinds of datapaths might not be practically enumerable, in which
      * case this function may be a null pointer. */
-    int (*enumerate)(struct sset *all_dps);
+    int (*enumerate)(struct sset *all_dps, const struct dpif_class *dpif_class);
 
     /* Returns the type to pass to netdev_open() when a dpif of class
      * 'dpif_class' has a port of type 'type', for a few special cases
index ac73be1..cace47b 100644 (file)
@@ -272,7 +272,9 @@ dp_enumerate_names(const char *type, struct sset *names)
     }
 
     dpif_class = registered_class->dpif_class;
-    error = dpif_class->enumerate ? dpif_class->enumerate(names) : 0;
+    error = (dpif_class->enumerate
+             ? dpif_class->enumerate(names, dpif_class)
+             : 0);
     if (error) {
         VLOG_WARN("failed to enumerate %s datapaths: %s", dpif_class->type,
                    ovs_strerror(error));