[ovs-dev] [connectibity_seq 1/4] connectivity: Add wrappers to connectivity related operations.
Alex Wang
alexw at nicira.com
Tue Feb 3 18:13:13 UTC 2015
This commit refines the connectivity module by defining wrappers
for each related operation.
Signed-off-by: Alex Wang <alexw at nicira.com>
---
lib/bfd.c | 2 +-
lib/cfm.c | 2 +-
lib/connectivity.c | 45 ++++++++++++++++++++++++++++++++++-----------
lib/connectivity.h | 4 +++-
lib/lacp.c | 4 ++--
lib/netdev-provider.h | 11 +++++------
lib/rstp-state-machines.c | 4 ++--
lib/rstp.c | 2 +-
lib/stp.c | 6 +++---
ofproto/bond.c | 6 +++---
ofproto/ofproto-dpif.c | 2 +-
ofproto/ofproto.c | 4 ++--
vswitchd/bridge.c | 6 +++---
13 files changed, 61 insertions(+), 37 deletions(-)
diff --git a/lib/bfd.c b/lib/bfd.c
index 3db1d57..86378d4 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -1198,7 +1198,7 @@ bfd_decay_update(struct bfd * bfd) OVS_REQUIRES(mutex)
static void
bfd_status_changed(struct bfd *bfd) OVS_REQUIRES(mutex)
{
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
bfd->status_changed = true;
}
diff --git a/lib/cfm.c b/lib/cfm.c
index 23c1c6f..fa0503c 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -338,7 +338,7 @@ cfm_init(void)
static void
cfm_status_changed(struct cfm *cfm) OVS_REQUIRES(mutex)
{
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
cfm->status_changed = true;
}
diff --git a/lib/connectivity.c b/lib/connectivity.c
index c80b5f1..59f8a39 100644
--- a/lib/connectivity.c
+++ b/lib/connectivity.c
@@ -15,22 +15,21 @@
*/
#include <config.h>
+
#include "connectivity.h"
#include "ovs-thread.h"
#include "seq.h"
-static struct seq *connectivity_seq;
-
/* Provides a global seq for connectivity changes.
*
- * Connectivity monitoring modules should call seq_change() on the returned
- * object whenever the status of a port changes, whether the cause is local or
- * remote.
- *
- * Clients can seq_wait() on this object for changes to netdev flags, features,
- * ethernet addresses, carrier changes, and bfd/cfm/lacp/stp status. */
-struct seq *
-connectivity_seq_get(void)
+ * Connectivity monitoring modules should use the public functions in this
+ * module to report, check or wait on link/port status change.
+ * */
+static struct seq *connectivity_seq;
+
+/* Runs only once to initialize 'connectivity_seq'. */
+static void
+connectivity_seq_init(void)
{
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
@@ -38,6 +37,30 @@ connectivity_seq_get(void)
connectivity_seq = seq_create();
ovsthread_once_done(&once);
}
+}
+
+/* Reads and returns the current 'connectivity_seq' value. */
+uint64_t
+connectivity_seq_read(void)
+{
+ connectivity_seq_init();
- return connectivity_seq;
+ return seq_read(connectivity_seq);
+}
+
+/* Changes the 'connectivity_seq'. */
+void
+connectivity_seq_change(void)
+{
+ connectivity_seq_init();
+ seq_change(connectivity_seq);
+}
+
+/* Wakes the caller up when 'connectivity_seq''s sequence number
+ * changes from 'value'. */
+void
+connectivity_seq_wait(uint64_t value)
+{
+ connectivity_seq_init();
+ seq_wait(connectivity_seq, value);
}
diff --git a/lib/connectivity.h b/lib/connectivity.h
index 123e886..f00f960 100644
--- a/lib/connectivity.h
+++ b/lib/connectivity.h
@@ -20,6 +20,8 @@
#include <stdint.h>
/* For tracking connectivity changes globally. */
-struct seq *connectivity_seq_get(void);
+uint64_t connectivity_seq_read(void);
+void connectivity_seq_change(void);
+void connectivity_seq_wait(uint64_t value);
#endif /* connectivity.h */
diff --git a/lib/lacp.c b/lib/lacp.c
index 6f52652..219355a 100644
--- a/lib/lacp.c
+++ b/lib/lacp.c
@@ -528,7 +528,7 @@ lacp_run(struct lacp *lacp, lacp_send_pdu *send_pdu) OVS_EXCLUDED(mutex)
slave_set_defaulted(slave);
}
if (slave->status != old_status) {
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
}
}
@@ -561,7 +561,7 @@ lacp_run(struct lacp *lacp, lacp_send_pdu *send_pdu) OVS_EXCLUDED(mutex)
: LACP_SLOW_TIME_TX);
timer_set_duration(&slave->tx, duration);
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
}
lacp_unlock();
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 3fdc732..6c94c7f 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -64,7 +64,7 @@ static void
netdev_change_seq_changed(const struct netdev *netdev_)
{
struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
netdev->change_seq++;
if (!netdev->change_seq) {
netdev->change_seq++;
@@ -187,11 +187,10 @@ struct netdev *netdev_rxq_get_netdev(const struct netdev_rxq *);
* ==========================
*
* Minimally, implementations are required to report changes to netdev flags,
- * features, ethernet address or carrier through connectivity_seq. Changes to
- * other properties are allowed to cause notification through this interface,
- * although implementations should try to avoid this. connectivity_seq_get()
- * can be used to acquire a reference to the struct seq. The interface is
- * described in detail in seq.h. */
+ * features, ethernet address or carrier through connectivity_seq_*()
+ * interfaces. Changes to other properties are allowed to cause notification
+ * through these interfaces, although implementations should try to avoid this.
+ * Please check connectivity.h for detailed description. */
struct netdev_class {
/* Type of netdevs in this class, e.g. "system", "tap", "gre", etc.
*
diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
index 3202018..6d187b2 100644
--- a/lib/rstp-state-machines.c
+++ b/lib/rstp-state-machines.c
@@ -220,7 +220,7 @@ move_rstp__(struct rstp *rstp)
}
}
num_iterations++;
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
if (num_iterations >= MAX_RSTP_ITERATIONS) {
VLOG_ERR("%s: move_rstp() reached the iteration safeguard limit!",
@@ -402,7 +402,7 @@ updt_roles_tree__(struct rstp *r)
/* no break */
}
}
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
static void
diff --git a/lib/rstp.c b/lib/rstp.c
index 3b314b4..3d41c2b 100644
--- a/lib/rstp.c
+++ b/lib/rstp.c
@@ -1130,7 +1130,7 @@ rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
if (state != p->rstp_state && !p->state_changed) {
p->state_changed = true;
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
p->rstp_state = state;
}
diff --git a/lib/stp.c b/lib/stp.c
index 1e88cba..232c2bb 100644
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -1158,7 +1158,7 @@ stp_configuration_update(struct stp *stp) OVS_REQUIRES(mutex)
{
stp_root_selection(stp);
stp_designated_port_selection(stp);
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
static bool
@@ -1289,7 +1289,7 @@ stp_set_port_state(struct stp_port *p, enum stp_state state)
if (p < p->stp->first_changed_port) {
p->stp->first_changed_port = p;
}
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
p->state = state;
}
@@ -1308,7 +1308,7 @@ stp_topology_change_detection(struct stp *stp) OVS_REQUIRES(mutex)
}
stp->fdb_needs_flush = true;
stp->topology_change_detected = true;
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
VLOG_INFO_RL(&rl, "%s: detected topology change.", stp->name);
}
diff --git a/ofproto/bond.c b/ofproto/bond.c
index c4b3a3a..44c427c 100644
--- a/ofproto/bond.c
+++ b/ofproto/bond.c
@@ -493,7 +493,7 @@ bond_active_slave_changed(struct bond *bond)
netdev_get_etheraddr(bond->active_slave->netdev, mac);
memcpy(bond->active_slave_mac, mac, sizeof bond->active_slave_mac);
bond->active_slave_changed = true;
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
static void
@@ -639,7 +639,7 @@ bond_run(struct bond *bond, enum lacp_status lacp_status)
/* Enable slaves based on link status and LACP feedback. */
HMAP_FOR_EACH (slave, hmap_node, &bond->slaves) {
bond_link_status_update(slave);
- slave->change_seq = seq_read(connectivity_seq_get());
+ slave->change_seq = connectivity_seq_read();
}
if (!bond->active_slave || !bond->active_slave->enabled) {
bond_choose_active_slave(bond);
@@ -664,7 +664,7 @@ bond_wait(struct bond *bond)
poll_timer_wait_until(slave->delay_expires);
}
- seq_wait(connectivity_seq_get(), slave->change_seq);
+ connectivity_seq_wait(slave->change_seq);
}
if (bond->bond_revalidate) {
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 1b4ad12..37e6ef9 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1529,7 +1529,7 @@ run(struct ofproto *ofproto_)
dpif_ipfix_run(ofproto->ipfix);
}
- new_seq = seq_read(connectivity_seq_get());
+ new_seq = connectivity_seq_read();
if (ofproto->change_seq != new_seq) {
struct ofport_dpif *ofport;
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index b3909ad..1af6552 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1596,7 +1596,7 @@ ofproto_run(struct ofproto *p)
}
}
- new_seq = seq_read(connectivity_seq_get());
+ new_seq = connectivity_seq_read();
if (new_seq != p->change_seq) {
struct sset devnames;
const char *devname;
@@ -1638,7 +1638,7 @@ ofproto_wait(struct ofproto *p)
if (p->ofproto_class->port_poll_wait) {
p->ofproto_class->port_poll_wait(p);
}
- seq_wait(connectivity_seq_get(), p->change_seq);
+ connectivity_seq_wait(p->change_seq);
connmgr_wait(p->connmgr);
}
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 4d84732..f52987e 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -598,7 +598,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
bridge_destroy(br);
} else {
/* Trigger storing datapath version. */
- seq_change(connectivity_seq_get());
+ connectivity_seq_change();
}
}
}
@@ -2717,7 +2717,7 @@ run_status_update(void)
/* Rate limit the update. Do not start a new update if the
* previous one is not done. */
- seq = seq_read(connectivity_seq_get());
+ seq = connectivity_seq_read();
if (seq != connectivity_seqno || status_txn_try_again) {
struct bridge *br;
@@ -2784,7 +2784,7 @@ status_update_wait(void)
} else if (status_txn_try_again) {
poll_timer_wait_until(time_msec() + STATUS_CHECK_AGAIN_MSEC);
} else {
- seq_wait(connectivity_seq_get(), connectivity_seqno);
+ connectivity_seq_wait(connectivity_seqno);
}
}
--
1.7.9.5
More information about the dev
mailing list