X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=vswitchd%2Fbridge.c;h=e35f34d6b1171a37b9ae081c56056f761e49852b;hb=88bf179aa3f3fa89822edcd9b882e0f06d39bf08;hp=db85856cc1e863839fc113402fa62eee99190813;hpb=b71273f60dbb2315330874809595048ce3c6ac68;p=sliver-openvswitch.git diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index db85856cc..e35f34d6b 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -252,6 +252,7 @@ static bool iface_is_internal(const struct ovsrec_interface *iface, static const char *iface_get_type(const struct ovsrec_interface *, const struct ovsrec_bridge *); static void iface_destroy(struct iface *); +static void iface_destroy__(struct iface *); static struct iface *iface_lookup(const struct bridge *, const char *name); static struct iface *iface_find(const char *name); static struct iface *iface_from_ofp_port(const struct bridge *, @@ -667,6 +668,9 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) struct ofproto_port ofproto_port; struct ofproto_port_dump dump; + struct sset ofproto_ports; + struct port *port, *port_next; + /* List of "ofp_port"s to delete. We make a list instead of deleting them * right away because ofproto implementations aren't necessarily able to * iterate through a changing list of ports in an entirely robust way. */ @@ -676,11 +680,21 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) del = NULL; n = allocated = 0; + sset_init(&ofproto_ports); + /* Main task: Iterate over the ports in 'br->ofproto' and remove the ports + * that are not configured in the database. (This commonly happens when + * ports have been deleted, e.g. with "ovs-vsctl del-port".) + * + * Side tasks: Reconfigure the ports that are still in 'br'. Delete ports + * that have the wrong OpenFlow port number (and arrange to add them back + * with the correct OpenFlow port number). */ OFPROTO_PORT_FOR_EACH (&ofproto_port, &dump, br->ofproto) { ofp_port_t requested_ofp_port; struct iface *iface; + sset_add(&ofproto_ports, ofproto_port.name); + iface = iface_lookup(br, ofproto_port.name); if (!iface) { /* No such iface is configured, so we should delete this @@ -746,11 +760,37 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) iface_destroy(iface); del = add_ofp_port(ofproto_port.ofp_port, del, &n, &allocated); } - for (i = 0; i < n; i++) { ofproto_port_del(br->ofproto, del[i]); } free(del); + + /* Iterate over this module's idea of interfaces in 'br'. Remove any ports + * that we didn't see when we iterated through the datapath, i.e. ports + * that disappeared underneath use. This is an unusual situation, but it + * can happen in some cases: + * + * - An admin runs a command like "ovs-dpctl del-port" (which is a bad + * idea but could happen). + * + * - The port represented a device that disappeared, e.g. a tuntap + * device destroyed via "tunctl -d", a physical Ethernet device + * whose module was just unloaded via "rmmod", or a virtual NIC for a + * VM whose VM was just terminated. */ + HMAP_FOR_EACH_SAFE (port, port_next, hmap_node, &br->ports) { + struct iface *iface, *iface_next; + + LIST_FOR_EACH_SAFE (iface, iface_next, port_elem, &port->ifaces) { + if (!sset_contains(&ofproto_ports, iface->name)) { + iface_destroy__(iface); + } + } + + if (list_is_empty(&port->ifaces)) { + port_destroy(port); + } + } + sset_destroy(&ofproto_ports); } static void @@ -839,15 +879,16 @@ port_configure(struct port *port) s.vlan_mode = PORT_VLAN_NATIVE_UNTAGGED; } else { /* This "can't happen" because ovsdb-server should prevent it. */ - VLOG_ERR("unknown VLAN mode %s", cfg->vlan_mode); + VLOG_WARN("port %s: unknown VLAN mode %s, falling " + "back to trunk mode", port->name, cfg->vlan_mode); s.vlan_mode = PORT_VLAN_TRUNK; } } else { if (s.vlan >= 0) { s.vlan_mode = PORT_VLAN_ACCESS; if (cfg->n_trunks) { - VLOG_ERR("port %s: ignoring trunks in favor of implicit vlan", - port->name); + VLOG_WARN("port %s: ignoring trunks in favor of implicit vlan", + port->name); } } else { s.vlan_mode = PORT_VLAN_TRUNK; @@ -1446,8 +1487,7 @@ iface_do_create(const struct bridge *br, VLOG_INFO("bridge %s: added interface %s on port %d", br->name, iface_cfg->name, *ofp_portp); - if ((port_cfg->vlan_mode && !strcmp(port_cfg->vlan_mode, "splinter")) - || iface_is_internal(iface_cfg, br->cfg)) { + if (port_cfg->vlan_mode && !strcmp(port_cfg->vlan_mode, "splinter")) { netdev_turn_flags_on(netdev, NETDEV_UP, NULL); } @@ -1836,9 +1876,13 @@ iface_refresh_cfm_stats(struct iface *iface) { const struct ovsrec_interface *cfg = iface->cfg; struct ofproto_cfm_status status; + int error; - if (!ofproto_port_get_cfm_status(iface->port->bridge->ofproto, - iface->ofp_port, &status)) { + error = ofproto_port_get_cfm_status(iface->port->bridge->ofproto, + iface->ofp_port, &status); + if (error < 0) { + /* Do nothing if there is no status change since last update. */ + } else if (error > 0) { ovsrec_interface_set_cfm_fault(cfg, NULL, 0); ovsrec_interface_set_cfm_fault_status(cfg, NULL, 0); ovsrec_interface_set_cfm_remote_opstate(cfg, NULL); @@ -2246,9 +2290,11 @@ instant_stats_run(void) iface_refresh_cfm_stats(iface); smap_init(&smap); - ofproto_port_get_bfd_status(br->ofproto, iface->ofp_port, - &smap); - ovsrec_interface_set_bfd_status(iface->cfg, &smap); + error = ofproto_port_get_bfd_status(br->ofproto, iface->ofp_port, + &smap); + if (error >= 0) { + ovsrec_interface_set_bfd_status(iface->cfg, &smap); + } smap_destroy(&smap); } } @@ -3145,8 +3191,6 @@ bridge_configure_dp_desc(struct bridge *br) /* Port functions. */ -static void iface_destroy__(struct iface *); - static struct port * port_create(struct bridge *br, const struct ovsrec_port *cfg) { @@ -3650,8 +3694,8 @@ iface_configure_qos(struct iface *iface, const struct ovsrec_qos *qos) } if (iface->ofp_port != OFPP_NONE) { - const struct ofproto_port_queue *port_queues = queues_buf.data; - size_t n_queues = queues_buf.size / sizeof *port_queues; + const struct ofproto_port_queue *port_queues = ofpbuf_data(&queues_buf); + size_t n_queues = ofpbuf_size(&queues_buf) / sizeof *port_queues; ofproto_port_set_queues(iface->port->bridge->ofproto, iface->ofp_port, port_queues, n_queues);