dpif: New function dpif_id() for getting the datapath index.
authorBen Pfaff <blp@nicira.com>
Sat, 7 Mar 2009 00:37:01 +0000 (16:37 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 9 Mar 2009 17:20:47 +0000 (10:20 -0700)
Using this function instead of referring to the "minor" member directly
helps with abstraction.

lib/dpif.h
secchan/ofproto.c
utilities/dpctl.c
vswitchd/bridge.c

index 6067188e7d5b30a8073fd9716b5e831b39b5a1f7..f52b9acf6b24e04283dca1d39707f9aeb0301a69 100644 (file)
@@ -56,6 +56,7 @@ int dpif_open(const char *name, struct dpif *);
 int dpif_create(const char *name, struct dpif *);
 void dpif_close(struct dpif *);
 
+static inline unsigned int dpif_id(const struct dpif *dpif);
 int dpif_get_name(struct dpif *, char *name, size_t name_size);
 
 int dpif_delete(struct dpif *);
@@ -101,6 +102,12 @@ int dpif_snat_del_port(struct dpif *, uint16_t port);
 
 int dpif_recv(struct dpif *, struct ofpbuf **);
 void dpif_recv_wait(struct dpif *);
+
+static inline unsigned int
+dpif_id(const struct dpif *dpif)
+{
+    return dpif->minor;
+}
 \f
 struct dpifmon;
 
index 60d3c95dadc387be342619c5f0c3dd0cd99a9f49..962b59d4c8f07020f454d50daeadc25ee2c67b37 100644 (file)
@@ -625,7 +625,7 @@ ofproto_run(struct ofproto *p)
                  * spin from here on out. */
                 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
                 VLOG_ERR_RL(&rl, "dp%u: datapath was destroyed externally",
-                            p->dpif.minor);
+                            dpif_id(&p->dpif));
                 return ENODEV;
             }
             break;
index 1ba6580d3b136a7427aacd951b45bb2774e5b6d2..7aed03c151fae227a26787124446aea49f7b2eeb 100644 (file)
@@ -291,7 +291,7 @@ do_get_idx(const struct settings *s UNUSED, int argc UNUSED, char *argv[])
 {
     struct dpif dpif;
     run(dpif_open(argv[1], &dpif), "opening datapath");
-    printf("%u\n", dpif.minor);
+    printf("%u\n", dpif_id(&dpif));
     dpif_close(&dpif);
 }
 
@@ -450,7 +450,7 @@ show_dpif(struct dpif *dpif)
     size_t n_ports;
     size_t i;
 
-    printf("datapath %u:\n", dpif->minor);
+    printf("dp%u:\n", dpif_id(dpif));
     query_ports(dpif, &ports, &n_ports);
     for (i = 0; i < n_ports; i++) {
         printf("\tport %u: %s\n", ports[i].port, ports[i].devname);
index 6b54652bfcc225dfcd12818abfeb8077f80650eb..bc4ebb0205bce1fa34f06ad1efa833960d1e61ba 100644 (file)
@@ -166,7 +166,6 @@ struct bridge {
 
     /* Kernel datapath information. */
     struct dpif dpif;           /* Kernel datapath. */
-    int dp_idx;                 /* Kernel datapath index. */
     struct port_array ifaces;   /* Indexed by kernel datapath port number. */
 
     /* Bridge ports. */
@@ -376,8 +375,8 @@ bridge_reconfigure(void)
                 && strcmp(p->devname, br->name)) {
                 int retval = dpif_port_del(&br->dpif, p->port);
                 if (retval) {
-                    VLOG_ERR("failed to remove %s interface from nl:%d: %s",
-                             p->devname, br->dp_idx, strerror(retval));
+                    VLOG_ERR("failed to remove %s interface from dp%u: %s",
+                             p->devname, dpif_id(&br->dpif), strerror(retval));
                 }
             }
         }
@@ -408,13 +407,13 @@ bridge_reconfigure(void)
                 int error = dpif_port_add(&br->dpif, if_name, next_port_no++);
                 if (error != EEXIST) {
                     if (next_port_no >= 256) {
-                        VLOG_ERR("ran out of valid port numbers on nl:%d",
-                                 br->dp_idx);
+                        VLOG_ERR("ran out of valid port numbers on dp%u",
+                                 dpif_id(&br->dpif));
                         goto out;
                     }
                     if (error) {
-                        VLOG_ERR("failed to add %s interface to nl:%d: %s",
-                                 if_name, br->dp_idx, strerror(error));
+                        VLOG_ERR("failed to add %s interface to dp%u: %s",
+                                 if_name, dpif_id(&br->dpif), strerror(error));
                     }
                     break;
                 }
@@ -432,12 +431,12 @@ bridge_reconfigure(void)
             for (j = 0; j < port->n_ifaces; ) {
                 struct iface *iface = port->ifaces[j];
                 if (iface->dp_ifidx < 0) {
-                    VLOG_ERR("%s interface not in nl:%d, dropping",
-                             iface->name, br->dp_idx);
+                    VLOG_ERR("%s interface not in dp%u, dropping",
+                             iface->name, dpif_id(&br->dpif));
                     iface_destroy(iface);
                 } else {
-                    VLOG_DBG("datapath nl:%d has interface %s on port %d",
-                             br->dp_idx, iface->name, iface->dp_ifidx);
+                    VLOG_DBG("dp%u has interface %s on port %d",
+                             dpif_id(&br->dpif), iface->name, iface->dp_ifidx);
                     j++;
                 }
                 if (!strcmp(iface->name, br->name)) {
@@ -648,8 +647,7 @@ bridge_create(const char *name)
 
     list_push_back(&all_bridges, &br->node);
 
-    br->dp_idx = br->dpif.minor;
-    VLOG_INFO("created bridge %s with dp_idx %d", br->name, br->dp_idx);
+    VLOG_INFO("created bridge %s on dp%u", br->name, dpif_id(&br->dpif));
 
     return br;
 }
@@ -691,18 +689,18 @@ static void
 bridge_destroy(struct bridge *br)
 {
     if (br) {
+        int error;
+
         while (br->n_ports > 0) {
             port_destroy(br->ports[br->n_ports - 1]);
         }
         list_remove(&br->node);
-        if (br->dp_idx >= 0) {
-            int retval = dpif_delete(&br->dpif);
-            if (retval && retval != ENOENT) {
-                VLOG_ERR("failed to delete datapath nl:%d: %s",
-                         br->dp_idx, strerror(retval));
-            }
-            dpif_close(&br->dpif);
+        error = dpif_delete(&br->dpif);
+        if (error && error != ENOENT) {
+            VLOG_ERR("failed to delete dp%u: %s",
+                     dpif_id(&br->dpif), strerror(error));
         }
+        dpif_close(&br->dpif);
         ofproto_destroy(br->ofproto);
         rconn_destroy(br->rconn);
         rconn_packet_counter_destroy(br->txqlen);
@@ -1087,11 +1085,11 @@ bridge_fetch_dp_ifaces(struct bridge *br)
         struct iface *iface = iface_lookup(br, p->devname);
         if (iface) {
             if (iface->dp_ifidx >= 0) {
-                VLOG_WARN("datapath nl:%d reported interface %s twice",
-                          br->dp_idx, p->devname);
+                VLOG_WARN("dp%u reported interface %s twice",
+                          dpif_id(&br->dpif), p->devname);
             } else if (iface_from_dp_ifidx(br, p->port)) {
-                VLOG_WARN("datapath nl:%d reported interface %"PRIu16" twice",
-                          br->dp_idx, p->port);
+                VLOG_WARN("dp%u reported interface %"PRIu16" twice",
+                          dpif_id(&br->dpif), p->port);
             } else {
                 uint16_t ofp_port = p->port == ODPP_LOCAL ? OFPP_LOCAL : p->port;
                 port_array_set(&br->ifaces, ofp_port, iface);