X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ofproto%2Fofproto-dpif.c;h=4fc90c67b57e4bc8067928fc9a1edb9754051196;hb=4a1b8f30e5956655b59200d673964b9f3f9ad711;hp=8c7164b2b201b74c883b9e5d745fbf770532701b;hpb=0f74f625166ed49d7623bd1a3216a1d73fdeb208;p=sliver-openvswitch.git diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 8c7164b2b..4fc90c67b 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -86,6 +86,8 @@ static struct rule_dpif *rule_dpif_lookup(struct ofproto_dpif *, static void rule_get_stats(struct rule *, uint64_t *packets, uint64_t *bytes); static void rule_invalidate(const struct rule_dpif *); +static tag_type rule_calculate_tag(const struct flow *, + const struct minimask *, uint32_t secret); struct ofbundle { struct hmap_node hmap_node; /* In struct ofproto's "bundles" hmap. */ @@ -388,14 +390,18 @@ struct table_dpif { enum revalidate_reason { REV_RECONFIGURE = 1, /* Switch configuration changed. */ REV_STP, /* Spanning tree protocol port status change. */ + REV_BOND, /* Bonding changed. */ REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/ REV_FLOW_TABLE, /* Flow table changed. */ + REV_MAC_LEARNING, /* Mac learning changed. */ REV_INCONSISTENCY /* Facet self-check failed. */ }; COVERAGE_DEFINE(rev_reconfigure); COVERAGE_DEFINE(rev_stp); +COVERAGE_DEFINE(rev_bond); COVERAGE_DEFINE(rev_port_toggled); COVERAGE_DEFINE(rev_flow_table); +COVERAGE_DEFINE(rev_mac_learning); COVERAGE_DEFINE(rev_inconsistency); /* Drop keys are odp flow keys which have drop flows installed in the kernel. @@ -764,8 +770,10 @@ type_run(const char *type) switch (backer->need_revalidate) { case REV_RECONFIGURE: COVERAGE_INC(rev_reconfigure); break; case REV_STP: COVERAGE_INC(rev_stp); break; + case REV_BOND: COVERAGE_INC(rev_bond); break; case REV_PORT_TOGGLED: COVERAGE_INC(rev_port_toggled); break; case REV_FLOW_TABLE: COVERAGE_INC(rev_flow_table); break; + case REV_MAC_LEARNING: COVERAGE_INC(rev_mac_learning); break; case REV_INCONSISTENCY: COVERAGE_INC(rev_inconsistency); break; } @@ -1497,7 +1505,9 @@ run(struct ofproto *ofproto_) if (mbridge_need_revalidate(ofproto->mbridge)) { ofproto->backer->need_revalidate = REV_RECONFIGURE; - mac_learning_flush(ofproto->ml, NULL); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); + mac_learning_flush(ofproto->ml); + ovs_rwlock_unlock(&ofproto->ml->rwlock); } /* Do not perform any periodic activity below required by 'ofproto' while @@ -1528,7 +1538,11 @@ run(struct ofproto *ofproto_) } stp_run(ofproto); - mac_learning_run(ofproto->ml, &ofproto->backer->revalidate_set); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); + if (mac_learning_run(ofproto->ml)) { + ofproto->backer->need_revalidate = REV_MAC_LEARNING; + } + ovs_rwlock_unlock(&ofproto->ml->rwlock); /* Check the consistency of a random facet, to aid debugging. */ if (time_msec() >= ofproto->consistency_rl @@ -1589,7 +1603,9 @@ wait(struct ofproto *ofproto_) if (ofproto->netflow) { netflow_wait(ofproto->netflow); } + ovs_rwlock_rdlock(&ofproto->ml->rwlock); mac_learning_wait(ofproto->ml); + ovs_rwlock_unlock(&ofproto->ml->rwlock); stp_wait(ofproto); if (ofproto->backer->need_revalidate) { /* Shouldn't happen, but if it does just go around again. */ @@ -2042,7 +2058,7 @@ set_stp(struct ofproto *ofproto_, const struct ofproto_stp_settings *s) set_stp_port(ofport, NULL); } - stp_destroy(ofproto->stp); + stp_unref(ofproto->stp); ofproto->stp = NULL; } @@ -2088,8 +2104,9 @@ update_stp_port_state(struct ofport_dpif *ofport) if (stp_learn_in_state(ofport->stp_state) != stp_learn_in_state(state)) { /* xxx Learning action flows should also be flushed. */ - mac_learning_flush(ofproto->ml, - &ofproto->backer->revalidate_set); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); + mac_learning_flush(ofproto->ml); + ovs_rwlock_unlock(&ofproto->ml->rwlock); } fwd_change = stp_forward_in_state(ofport->stp_state) != stp_forward_in_state(state); @@ -2194,7 +2211,9 @@ stp_run(struct ofproto_dpif *ofproto) } if (stp_check_and_reset_fdb_flush(ofproto->stp)) { - mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); + mac_learning_flush(ofproto->ml); + ovs_rwlock_unlock(&ofproto->ml->rwlock); } } } @@ -2351,6 +2370,7 @@ bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos) struct mac_entry *mac, *next_mac; ofproto->backer->need_revalidate = REV_RECONFIGURE; + ovs_rwlock_wrlock(&ml->rwlock); LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) { if (mac->port.p == bundle) { if (all_ofprotos) { @@ -2360,11 +2380,12 @@ bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos) if (o != ofproto) { struct mac_entry *e; - e = mac_learning_lookup(o->ml, mac->mac, mac->vlan, - NULL); + ovs_rwlock_wrlock(&o->ml->rwlock); + e = mac_learning_lookup(o->ml, mac->mac, mac->vlan); if (e) { mac_learning_expire(o->ml, e); } + ovs_rwlock_unlock(&o->ml->rwlock); } } } @@ -2372,6 +2393,7 @@ bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos) mac_learning_expire(ml, mac); } } + ovs_rwlock_unlock(&ml->rwlock); } static struct ofbundle * @@ -2715,6 +2737,7 @@ bundle_send_learning_packets(struct ofbundle *bundle) struct mac_entry *e; error = n_packets = n_errors = 0; + ovs_rwlock_rdlock(&ofproto->ml->rwlock); LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) { if (e->port.p != bundle) { struct ofpbuf *learning_packet; @@ -2737,6 +2760,7 @@ bundle_send_learning_packets(struct ofbundle *bundle) n_packets++; } } + ovs_rwlock_unlock(&ofproto->ml->rwlock); if (n_errors) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); @@ -2762,8 +2786,10 @@ bundle_run(struct ofbundle *bundle) bond_slave_set_may_enable(bundle->bond, port, port->may_enable); } - bond_run(bundle->bond, &bundle->ofproto->backer->revalidate_set, - lacp_status(bundle->lacp)); + if (bond_run(bundle->bond, lacp_status(bundle->lacp))) { + bundle->ofproto->backer->need_revalidate = REV_BOND; + } + if (bond_should_send_learning_packets(bundle->bond)) { bundle_send_learning_packets(bundle); } @@ -2829,9 +2855,11 @@ static int set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) { - mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set); + mac_learning_flush(ofproto->ml); } + ovs_rwlock_unlock(&ofproto->ml->rwlock); return 0; } @@ -2855,8 +2883,10 @@ set_mac_table_config(struct ofproto *ofproto_, unsigned int idle_time, size_t max_entries) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); mac_learning_set_idle_time(ofproto->ml, idle_time); mac_learning_set_max_entries(ofproto->ml, max_entries); + ovs_rwlock_unlock(&ofproto->ml->rwlock); } /* Ports. */ @@ -3799,15 +3829,20 @@ handle_miss_upcalls(struct dpif_backer *backer, struct dpif_upcall *upcalls, drop_key = drop_key_lookup(backer, upcall->key, upcall->key_len); if (!drop_key) { - drop_key = xmalloc(sizeof *drop_key); - drop_key->key = xmemdup(upcall->key, upcall->key_len); - drop_key->key_len = upcall->key_len; - - hmap_insert(&backer->drop_keys, &drop_key->hmap_node, - hash_bytes(drop_key->key, drop_key->key_len, 0)); - dpif_flow_put(backer->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY, - drop_key->key, drop_key->key_len, - NULL, 0, NULL, 0, NULL); + int ret; + ret = dpif_flow_put(backer->dpif, + DPIF_FP_CREATE | DPIF_FP_MODIFY, + upcall->key, upcall->key_len, + NULL, 0, NULL, 0, NULL); + + if (!ret) { + drop_key = xmalloc(sizeof *drop_key); + drop_key->key = xmemdup(upcall->key, upcall->key_len); + drop_key->key_len = upcall->key_len; + + hmap_insert(&backer->drop_keys, &drop_key->hmap_node, + hash_bytes(drop_key->key, drop_key->key_len, 0)); + } } continue; } @@ -4133,7 +4168,7 @@ expire(struct dpif_backer *backer) HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) { if (bundle->bond) { - bond_rebalance(bundle->bond, &backer->revalidate_set); + bond_rebalance(bundle->bond); } } } @@ -5525,7 +5560,7 @@ calculate_flow_tag(struct ofproto_dpif *ofproto, const struct flow *flow, /* Calculates the tag to use for 'flow' and mask 'mask' when it is inserted * into an OpenFlow table with the given 'basis'. */ -tag_type +static tag_type rule_calculate_tag(const struct flow *flow, const struct minimask *mask, uint32_t secret) { @@ -5757,10 +5792,14 @@ ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc, unixctl_command_reply_error(conn, "no such bridge"); return; } - mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); + mac_learning_flush(ofproto->ml); + ovs_rwlock_unlock(&ofproto->ml->rwlock); } else { HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { - mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set); + ovs_rwlock_wrlock(&ofproto->ml->rwlock); + mac_learning_flush(ofproto->ml); + ovs_rwlock_unlock(&ofproto->ml->rwlock); } } @@ -5789,6 +5828,7 @@ ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, } ds_put_cstr(&ds, " port VLAN MAC Age\n"); + ovs_rwlock_rdlock(&ofproto->ml->rwlock); LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) { struct ofbundle *bundle = e->port.p; char name[OFP_MAX_PORT_NAME_LEN]; @@ -5799,6 +5839,7 @@ ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, name, e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(ofproto->ml, e)); } + ovs_rwlock_unlock(&ofproto->ml->rwlock); unixctl_command_reply(conn, ds_cstr(&ds)); ds_destroy(&ds); }