bond: Choose slaves randomly.
authorEthan Jackson <ethan@nicira.com>
Sat, 2 Apr 2011 00:37:56 +0000 (17:37 -0700)
committerEthan Jackson <ethan@nicira.com>
Mon, 4 Apr 2011 19:32:22 +0000 (12:32 -0700)
When the bonding library encounters a flow it hasn't seen before,
it assigns it to the active slave and waits for load balancing to
move it to a more appropriate place.  This commit causes it to
first attempt a random slave.

lib/bond.c

index e27d5f4..ccd8a07 100644 (file)
@@ -1379,9 +1379,11 @@ choose_output_slave(const struct bond *bond, const struct flow *flow,
     case BM_TCP:
         e = lookup_bond_entry(bond, flow, vlan);
         if (!e->slave || !e->slave->enabled) {
-            /* XXX select interface properly.  The current interface selection
-             * is only good for testing the rebalancing code. */
-            e->slave = bond->active_slave;
+            e->slave = CONTAINER_OF(hmap_random_node(&bond->slaves),
+                                    struct bond_slave, hmap_node);
+            if (!e->slave->enabled) {
+                e->slave = bond->active_slave;
+            }
             e->tag = tag_create_random();
         }
         return e->slave;