aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_sysfs.c
diff options
context:
space:
mode:
authorAndy Gospodarek <andy@greyhouse.net>2010-06-02 04:40:18 -0400
committerDavid S. Miller <davem@davemloft.net>2010-06-05 05:23:17 -0400
commitbb1d912323d5dd50e1079e389f4e964be14f0ae3 (patch)
tree7d20fff2e63bc6add251a56625110257d3ccc45f /drivers/net/bonding/bond_sysfs.c
parentebd8e4977a87cb81d93c62a9bff0102a9713722f (diff)
bonding: allow user-controlled output slave selection
v2: changed bonding module version, modified to apply on top of changes from previous patch in series, and updated documentation to elaborate on multiqueue awareness that now exists in bonding driver. This patch give the user the ability to control the output slave for round-robin and active-backup bonding. Similar functionality was discussed in the past, but Jay Vosburgh indicated he would rather see a feature like this added to existing modes rather than creating a completely new mode. Jay's thoughts as well as Neil's input surrounding some of the issues with the first implementation pushed us toward a design that relied on the queue_mapping rather than skb marks. Round-robin and active-backup modes were chosen as the first users of this slave selection as they seemed like the most logical choices when considering a multi-switch environment. Round-robin mode works without any modification, but active-backup does require inclusion of the first patch in this series and setting the 'all_slaves_active' flag. This will allow reception of unicast traffic on any of the backup interfaces. This was tested with IPv4-based filters as well as VLAN-based filters with good results. More information as well as a configuration example is available in the patch to Documentation/networking/bonding.txt. Signed-off-by: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding/bond_sysfs.c')
-rw-r--r--drivers/net/bonding/bond_sysfs.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 066311a5e084..f9a034361a8e 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -1412,6 +1412,121 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d,
1412static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); 1412static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
1413 1413
1414/* 1414/*
1415 * Show the queue_ids of the slaves in the current bond.
1416 */
1417static ssize_t bonding_show_queue_id(struct device *d,
1418 struct device_attribute *attr,
1419 char *buf)
1420{
1421 struct slave *slave;
1422 int i, res = 0;
1423 struct bonding *bond = to_bond(d);
1424
1425 if (!rtnl_trylock())
1426 return restart_syscall();
1427
1428 read_lock(&bond->lock);
1429 bond_for_each_slave(bond, slave, i) {
1430 if (res > (PAGE_SIZE - 6)) {
1431 /* not enough space for another interface name */
1432 if ((PAGE_SIZE - res) > 10)
1433 res = PAGE_SIZE - 10;
1434 res += sprintf(buf + res, "++more++ ");
1435 break;
1436 }
1437 res += sprintf(buf + res, "%s:%d ",
1438 slave->dev->name, slave->queue_id);
1439 }
1440 read_unlock(&bond->lock);
1441 if (res)
1442 buf[res-1] = '\n'; /* eat the leftover space */
1443 rtnl_unlock();
1444 return res;
1445}
1446
1447/*
1448 * Set the queue_ids of the slaves in the current bond. The bond
1449 * interface must be enslaved for this to work.
1450 */
1451static ssize_t bonding_store_queue_id(struct device *d,
1452 struct device_attribute *attr,
1453 const char *buffer, size_t count)
1454{
1455 struct slave *slave, *update_slave;
1456 struct bonding *bond = to_bond(d);
1457 u16 qid;
1458 int i, ret = count;
1459 char *delim;
1460 struct net_device *sdev = NULL;
1461
1462 if (!rtnl_trylock())
1463 return restart_syscall();
1464
1465 /* delim will point to queue id if successful */
1466 delim = strchr(buffer, ':');
1467 if (!delim)
1468 goto err_no_cmd;
1469
1470 /*
1471 * Terminate string that points to device name and bump it
1472 * up one, so we can read the queue id there.
1473 */
1474 *delim = '\0';
1475 if (sscanf(++delim, "%hd\n", &qid) != 1)
1476 goto err_no_cmd;
1477
1478 /* Check buffer length, valid ifname and queue id */
1479 if (strlen(buffer) > IFNAMSIZ ||
1480 !dev_valid_name(buffer) ||
1481 qid > bond->params.tx_queues)
1482 goto err_no_cmd;
1483
1484 /* Get the pointer to that interface if it exists */
1485 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1486 if (!sdev)
1487 goto err_no_cmd;
1488
1489 read_lock(&bond->lock);
1490
1491 /* Search for thes slave and check for duplicate qids */
1492 update_slave = NULL;
1493 bond_for_each_slave(bond, slave, i) {
1494 if (sdev == slave->dev)
1495 /*
1496 * We don't need to check the matching
1497 * slave for dups, since we're overwriting it
1498 */
1499 update_slave = slave;
1500 else if (qid && qid == slave->queue_id) {
1501 goto err_no_cmd_unlock;
1502 }
1503 }
1504
1505 if (!update_slave)
1506 goto err_no_cmd_unlock;
1507
1508 /* Actually set the qids for the slave */
1509 update_slave->queue_id = qid;
1510
1511 read_unlock(&bond->lock);
1512out:
1513 rtnl_unlock();
1514 return ret;
1515
1516err_no_cmd_unlock:
1517 read_unlock(&bond->lock);
1518err_no_cmd:
1519 pr_info("invalid input for queue_id set for %s.\n",
1520 bond->dev->name);
1521 ret = -EPERM;
1522 goto out;
1523}
1524
1525static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1526 bonding_store_queue_id);
1527
1528
1529/*
1415 * Show and set the all_slaves_active flag. 1530 * Show and set the all_slaves_active flag.
1416 */ 1531 */
1417static ssize_t bonding_show_slaves_active(struct device *d, 1532static ssize_t bonding_show_slaves_active(struct device *d,
@@ -1489,6 +1604,7 @@ static struct attribute *per_bond_attrs[] = {
1489 &dev_attr_ad_actor_key.attr, 1604 &dev_attr_ad_actor_key.attr,
1490 &dev_attr_ad_partner_key.attr, 1605 &dev_attr_ad_partner_key.attr,
1491 &dev_attr_ad_partner_mac.attr, 1606 &dev_attr_ad_partner_mac.attr,
1607 &dev_attr_queue_id.attr,
1492 &dev_attr_all_slaves_active.attr, 1608 &dev_attr_all_slaves_active.attr,
1493 NULL, 1609 NULL,
1494}; 1610};