bridge: Eliminate bond_rebalance_port() dependency on DP_MAX_PORTS.
authorBen Pfaff <blp@nicira.com>
Mon, 13 Dec 2010 19:12:37 +0000 (11:12 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 13 Dec 2010 22:26:18 +0000 (14:26 -0800)
There's no reason to allocate the bals[] array on the stack here, since
this is not on any fast-path.

As an alternative, we could limit the number of interfaces on a single
bond to some reasonable maximum, such as 8 or 32, but this commit's change
is simpler.

vswitchd/bridge.c

index 6691746..69241da 100644 (file)
@@ -2943,7 +2943,7 @@ bond_shift_load(struct slave_balance *from, struct slave_balance *to,
 static void
 bond_rebalance_port(struct port *port)
 {
-    struct slave_balance bals[DP_MAX_PORTS];
+    struct slave_balance *bals;
     size_t n_bals;
     struct bond_entry *hashes[BOND_MASK + 1];
     struct slave_balance *b, *from, *to;
@@ -2961,6 +2961,7 @@ bond_rebalance_port(struct port *port)
      * become contiguous in memory, and then we point each 'hashes' members of
      * a slave_balance structure to the start of a contiguous group. */
     n_bals = port->n_ifaces;
+    bals = xmalloc(n_bals * sizeof *bals);
     for (b = bals; b < &bals[n_bals]; b++) {
         b->iface = port->ifaces[b - bals];
         b->tx_bytes = 0;
@@ -2990,7 +2991,7 @@ bond_rebalance_port(struct port *port)
     while (!bals[n_bals - 1].iface->enabled) {
         n_bals--;
         if (!n_bals) {
-            return;
+            goto exit;
         }
     }
 
@@ -3082,6 +3083,9 @@ bond_rebalance_port(struct port *port)
     for (e = &port->bond_hash[0]; e <= &port->bond_hash[BOND_MASK]; e++) {
         e->tx_bytes /= 2;
     }
+
+exit:
+    free(bals);
 }
 
 static void