ovs-dpctl: Use datapath enumeration functions instead of guessing names.
authorBen Pfaff <blp@nicira.com>
Wed, 5 Jan 2011 23:33:09 +0000 (15:33 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 27 Jan 2011 17:27:48 +0000 (09:27 -0800)
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

index ff31fb8ec6338ecf23a85a5771ee352c416c246a..dc93d558ab3fa05a88412c8ec2ba63c0468b8a16 100644 (file)
@@ -402,21 +402,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);