From: Ben Pfaff Date: Sat, 7 Mar 2009 00:37:01 +0000 (-0800) Subject: dpif: New function dpif_id() for getting the datapath index. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=431e057e8621e45370d37ea6968f1ccdfd5a4ae4;p=openvswitch dpif: New function dpif_id() for getting the datapath index. Using this function instead of referring to the "minor" member directly helps with abstraction. --- diff --git a/lib/dpif.h b/lib/dpif.h index 6067188e..f52b9acf 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -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; +} struct dpifmon; diff --git a/secchan/ofproto.c b/secchan/ofproto.c index 60d3c95d..962b59d4 100644 --- a/secchan/ofproto.c +++ b/secchan/ofproto.c @@ -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; diff --git a/utilities/dpctl.c b/utilities/dpctl.c index 1ba6580d..7aed03c1 100644 --- a/utilities/dpctl.c +++ b/utilities/dpctl.c @@ -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); diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 6b54652b..bc4ebb02 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -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);