[ovs-dev] [netlink v5 34/61] ovs-dpctl: Use datapath enumeration functions instead of guessing names.

Ben Pfaff blp at nicira.com
Thu Jan 27 00:23:17 UTC 2011


I'm planning to get rid of userspace knowledge of ODP_MAX and this change
gets rid of one user of it.

Reviewed by Justin Pettit.
---
 utilities/ovs-dpctl.c |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index fab6577..31b15e8 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -404,21 +404,37 @@ do_show(int argc, char *argv[])
             }
         }
     } else {
-        unsigned int i;
-        for (i = 0; i < ODP_MAX; i++) {
-            char name[128];
-            struct dpif *dpif;
-            int error;
-
-            sprintf(name, "dp%u", i);
-            error = parsed_dpif_open(name, false, &dpif);
-            if (!error) {
-                show_dpif(dpif);
-            } else if (error != ENODEV) {
-                ovs_error(error, "opening datapath %s failed", name);
+        struct svec types;
+        const char *type;
+        size_t i;
+
+        svec_init(&types);
+        dp_enumerate_types(&types);
+        SVEC_FOR_EACH (i, type, &types) {
+            struct svec names;
+            const char *name;
+            size_t j;
+
+            svec_init(&names);
+            if (dp_enumerate_names(type, &names)) {
                 failure = true;
+                continue;
+            }
+            SVEC_FOR_EACH (j, name, &names) {
+                struct dpif *dpif;
+                int error;
+
+                error = dpif_open(name, type, &dpif);
+                if (!error) {
+                    show_dpif(dpif);
+                } else {
+                    ovs_error(error, "opening datapath %s failed", name);
+                    failure = true;
+                }
             }
+            svec_destroy(&names);
         }
+        svec_destroy(&types);
     }
     if (failure) {
         exit(EXIT_FAILURE);
-- 
1.7.1





More information about the dev mailing list