[ovs-dev] [PATCH 5/8] vswitchd: Cache interface carrier when bonding.

Ethan Jackson ethan at nicira.com
Sun Jan 30 23:58:12 UTC 2011


This commit caches each interface's carrier status when bonding is
enabled.  This allows port_update_bond_compat() to be called less
often, and will prove useful in future patches.
---
 vswitchd/bridge.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 2e7d189..b6f8523 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -106,6 +106,7 @@ struct iface {
     int dp_ifidx;               /* Index within kernel datapath. */
     struct netdev *netdev;      /* Network device. */
     bool enabled;               /* May be chosen for flows? */
+    bool up;                    /* Is the interface up? */
     const char *type;           /* Usually same as cfg->type. */
     struct cfm *cfm;            /* Connectivity Fault Management */
     const struct ovsrec_interface *cfg;
@@ -709,6 +710,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
                 if (iface) {
                     iface->netdev = netdev;
                     iface->enabled = netdev_get_carrier(iface->netdev);
+                    iface->up = iface->enabled;
                 }
             } else if (iface && iface->netdev) {
                 struct shash args;
@@ -2151,10 +2153,11 @@ choose_output_iface(const struct port *port, const uint8_t *dl_src,
 }
 
 static void
-bond_link_status_update(struct iface *iface, bool carrier)
+bond_link_status_update(struct iface *iface)
 {
     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
     struct port *port = iface->port;
+    bool carrier = iface->up;
 
     if ((carrier == iface->enabled) == (iface->delay_expires == LLONG_MAX)) {
         /* Nothing to do. */
@@ -2310,8 +2313,10 @@ bond_run(struct bridge *br)
                     if (iface) {
                         bool up = netdev_get_carrier(iface->netdev);
 
-                        bond_link_status_update(iface, up);
-                        port_update_bond_compat(port);
+                        if (up != iface->up) {
+                            port_update_bond_compat(port);
+                        }
+                        iface->up = up;
                     }
                     free(devname);
                 }
@@ -2323,8 +2328,10 @@ bond_run(struct bridge *br)
                         struct iface *iface = port->ifaces[j];
                         bool up = netdev_get_miimon(iface->netdev);
 
-                        bond_link_status_update(iface, up);
-                        port_update_bond_compat(port);
+                        if (up != iface->up) {
+                            port_update_bond_compat(port);
+                        }
+                        iface->up = up;
                     }
                     port->bond_miimon_next_update = time_msec() +
                         port->bond_miimon_interval;
@@ -2332,6 +2339,10 @@ bond_run(struct bridge *br)
             }
 
             for (j = 0; j < port->n_ifaces; j++) {
+                bond_link_status_update(port->ifaces[j]);
+            }
+
+            for (j = 0; j < port->n_ifaces; j++) {
                 struct iface *iface = port->ifaces[j];
                 if (time_msec() >= iface->delay_expires) {
                     bond_enable_slave(iface, !iface->enabled);
-- 
1.7.2





More information about the dev mailing list