From 2c9839c143bbc8c6612f56351dae8d57111aee37 Mon Sep 17 00:00:00 2001 From: "sfeldma@cumulusnetworks.com" Date: Tue, 17 Dec 2013 21:30:09 -0800 Subject: bonding: add num_grat_arp attribute netlink support Add IFLA_BOND_NUM_PEER_NOTIF to allow get/set of bonding parameter num_grat_arp via netlink. Bonding parameter num_unsol_na is synonymous with num_grat_arp, so add only one netlink attribute to represent both bonding parameters. Signed-off-by: Scott Feldman Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index e161c9c..07123a0 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -37,6 +37,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 }, [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 }, [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 }, + [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 }, }; static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) @@ -204,6 +205,14 @@ static int bond_changelink(struct net_device *bond_dev, if (err) return err; } + if (data[IFLA_BOND_NUM_PEER_NOTIF]) { + int num_peer_notif = + nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]); + + err = bond_option_num_peer_notif_set(bond, num_peer_notif); + if (err) + return err; + } return 0; } @@ -237,6 +246,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */ nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */ + nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */ 0; } @@ -317,6 +327,10 @@ static int bond_fill_info(struct sk_buff *skb, bond->params.resend_igmp)) goto nla_put_failure; + if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF, + bond->params.num_peer_notif)) + goto nla_put_failure; + return 0; nla_put_failure: diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index 1ed7dff..01a9669 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -576,3 +576,9 @@ int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp) return 0; } + +int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif) +{ + bond->params.num_peer_notif = num_peer_notif; + return 0; +} diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index f5c1a54..7efa33a 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -790,8 +790,25 @@ static ssize_t bonding_store_num_peer_notif(struct device *d, const char *buf, size_t count) { struct bonding *bond = to_bond(d); - int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); - return err ? err : count; + u8 new_value; + int ret; + + ret = kstrtou8(buf, 10, &new_value); + if (!ret) { + pr_err("%s: invalid value %s specified.\n", + bond->dev->name, buf); + return ret; + } + + if (!rtnl_trylock()) + return restart_syscall(); + + ret = bond_option_num_peer_notif_set(bond, new_value); + if (!ret) + ret = count; + + rtnl_unlock(); + return ret; } static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, bonding_show_num_peer_notif, bonding_store_num_peer_notif); diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index c70ad9f..73538b7 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h @@ -461,6 +461,7 @@ int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac); int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy); int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp); +int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif); struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); struct net_device *bond_option_active_slave_get(struct bonding *bond); diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 6e275d5..bfe3d3b 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -344,6 +344,7 @@ enum { IFLA_BOND_FAIL_OVER_MAC, IFLA_BOND_XMIT_HASH_POLICY, IFLA_BOND_RESEND_IGMP, + IFLA_BOND_NUM_PEER_NOTIF, __IFLA_BOND_MAX, }; -- cgit v0.10.2 From 1cc0b1e30c662d84a89690f42826cf49e2278b97 Mon Sep 17 00:00:00 2001 From: "sfeldma@cumulusnetworks.com" Date: Tue, 17 Dec 2013 21:30:16 -0800 Subject: bonding: add all_slaves_active attribute netlink support Add IFLA_BOND_ALL_SLAVES_ACTIVE to allow get/set of bonding parameter all_slaves_active via netlink. Signed-off-by: Scott Feldman Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index 07123a0..5175215 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -38,6 +38,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 }, [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 }, [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 }, + [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 }, }; static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) @@ -213,6 +214,15 @@ static int bond_changelink(struct net_device *bond_dev, if (err) return err; } + if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) { + int all_slaves_active = + nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]); + + err = bond_option_all_slaves_active_set(bond, + all_slaves_active); + if (err) + return err; + } return 0; } @@ -247,6 +257,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */ nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */ + nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */ 0; } @@ -331,6 +342,10 @@ static int bond_fill_info(struct sk_buff *skb, bond->params.num_peer_notif)) goto nla_put_failure; + if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE, + bond->params.all_slaves_active)) + goto nla_put_failure; + return 0; nla_put_failure: diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index 01a9669..cbd8322 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -582,3 +582,32 @@ int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif) bond->params.num_peer_notif = num_peer_notif; return 0; } + +int bond_option_all_slaves_active_set(struct bonding *bond, + int all_slaves_active) +{ + struct list_head *iter; + struct slave *slave; + + if (all_slaves_active == bond->params.all_slaves_active) + return 0; + + if ((all_slaves_active == 0) || (all_slaves_active == 1)) { + bond->params.all_slaves_active = all_slaves_active; + } else { + pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", + bond->dev->name, all_slaves_active); + return -EINVAL; + } + + bond_for_each_slave(bond, slave, iter) { + if (!bond_is_active_slave(slave)) { + if (all_slaves_active) + slave->inactive = 0; + else + slave->inactive = 1; + } + } + + return 0; +} diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 7efa33a..9a37125 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -1290,41 +1290,21 @@ static ssize_t bonding_store_slaves_active(struct device *d, const char *buf, size_t count) { struct bonding *bond = to_bond(d); - int new_value, ret = count; - struct list_head *iter; - struct slave *slave; - - if (!rtnl_trylock()) - return restart_syscall(); + int new_value, ret; if (sscanf(buf, "%d", &new_value) != 1) { pr_err("%s: no all_slaves_active value specified.\n", bond->dev->name); - ret = -EINVAL; - goto out; + return -EINVAL; } - if (new_value == bond->params.all_slaves_active) - goto out; + if (!rtnl_trylock()) + return restart_syscall(); - if ((new_value == 0) || (new_value == 1)) { - bond->params.all_slaves_active = new_value; - } else { - pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", - bond->dev->name, new_value); - ret = -EINVAL; - goto out; - } + ret = bond_option_all_slaves_active_set(bond, new_value); + if (!ret) + ret = count; - bond_for_each_slave(bond, slave, iter) { - if (!bond_is_active_slave(slave)) { - if (new_value) - slave->inactive = 0; - else - slave->inactive = 1; - } - } -out: rtnl_unlock(); return ret; } diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 73538b7..3701e7d 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h @@ -462,6 +462,8 @@ int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy); int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp); int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif); +int bond_option_all_slaves_active_set(struct bonding *bond, + int all_slaves_active); struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); struct net_device *bond_option_active_slave_get(struct bonding *bond); diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index bfe3d3b..93e9c1b 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -345,6 +345,7 @@ enum { IFLA_BOND_XMIT_HASH_POLICY, IFLA_BOND_RESEND_IGMP, IFLA_BOND_NUM_PEER_NOTIF, + IFLA_BOND_ALL_SLAVES_ACTIVE, __IFLA_BOND_MAX, }; -- cgit v0.10.2 From 7d1010082785b2020b1e2e1211b76209976a33df Mon Sep 17 00:00:00 2001 From: "sfeldma@cumulusnetworks.com" Date: Tue, 17 Dec 2013 21:30:23 -0800 Subject: bonding: add min_links attribute netlink support Add IFLA_BOND_MIN_LINKS to allow get/set of bonding parameter min_links via netlink. Signed-off-by: Scott Feldman Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index 5175215..ac9a10c 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -39,6 +39,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 }, [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 }, [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 }, + [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 }, }; static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) @@ -223,6 +224,14 @@ static int bond_changelink(struct net_device *bond_dev, if (err) return err; } + if (data[IFLA_BOND_MIN_LINKS]) { + int min_links = + nla_get_u32(data[IFLA_BOND_MIN_LINKS]); + + err = bond_option_min_links_set(bond, min_links); + if (err) + return err; + } return 0; } @@ -258,6 +267,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */ nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */ nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */ + nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */ 0; } @@ -346,6 +356,10 @@ static int bond_fill_info(struct sk_buff *skb, bond->params.all_slaves_active)) goto nla_put_failure; + if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS, + bond->params.min_links)) + goto nla_put_failure; + return 0; nla_put_failure: diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index cbd8322..da49ac4 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -611,3 +611,12 @@ int bond_option_all_slaves_active_set(struct bonding *bond, return 0; } + +int bond_option_min_links_set(struct bonding *bond, int min_links) +{ + pr_info("%s: Setting min links value to %u\n", + bond->dev->name, min_links); + bond->params.min_links = min_links; + + return 0; +} diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 9a37125..359adda 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -722,10 +722,15 @@ static ssize_t bonding_store_min_links(struct device *d, return ret; } - pr_info("%s: Setting min links value to %u\n", - bond->dev->name, new_value); - bond->params.min_links = new_value; - return count; + if (!rtnl_trylock()) + return restart_syscall(); + + ret = bond_option_min_links_set(bond, new_value); + if (!ret) + ret = count; + + rtnl_unlock(); + return ret; } static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, bonding_show_min_links, bonding_store_min_links); diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 3701e7d..7d7ad1c 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h @@ -464,6 +464,7 @@ int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp); int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif); int bond_option_all_slaves_active_set(struct bonding *bond, int all_slaves_active); +int bond_option_min_links_set(struct bonding *bond, int min_links); struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); struct net_device *bond_option_active_slave_get(struct bonding *bond); diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 93e9c1b..c7a0f89 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -346,6 +346,7 @@ enum { IFLA_BOND_RESEND_IGMP, IFLA_BOND_NUM_PEER_NOTIF, IFLA_BOND_ALL_SLAVES_ACTIVE, + IFLA_BOND_MIN_LINKS, __IFLA_BOND_MAX, }; -- cgit v0.10.2 From 8d836d092ed7b77d13ac1108399165ee7de7463f Mon Sep 17 00:00:00 2001 From: "sfeldma@cumulusnetworks.com" Date: Tue, 17 Dec 2013 21:30:30 -0800 Subject: bonding: add lp_interval attribute netlink support Add IFLA_BOND_LP_INTERVAL to allow get/set of bonding parameter lp_interval via netlink. Signed-off-by: Scott Feldman Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index ac9a10c..6c8339b 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -40,6 +40,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 }, [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 }, [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 }, + [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 }, }; static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) @@ -232,6 +233,14 @@ static int bond_changelink(struct net_device *bond_dev, if (err) return err; } + if (data[IFLA_BOND_LP_INTERVAL]) { + int lp_interval = + nla_get_u32(data[IFLA_BOND_LP_INTERVAL]); + + err = bond_option_lp_interval_set(bond, lp_interval); + if (err) + return err; + } return 0; } @@ -268,6 +277,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */ nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */ + nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */ 0; } @@ -360,6 +370,10 @@ static int bond_fill_info(struct sk_buff *skb, bond->params.min_links)) goto nla_put_failure; + if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL, + bond->params.lp_interval)) + goto nla_put_failure; + return 0; nla_put_failure: diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index da49ac4..e313a8f 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -620,3 +620,16 @@ int bond_option_min_links_set(struct bonding *bond, int min_links) return 0; } + +int bond_option_lp_interval_set(struct bonding *bond, int lp_interval) +{ + if (lp_interval <= 0) { + pr_err("%s: lp_interval must be between 1 and %d\n", + bond->dev->name, INT_MAX); + return -EINVAL; + } + + bond->params.lp_interval = lp_interval; + + return 0; +} diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 359adda..c4cdbf6 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -1369,24 +1369,22 @@ static ssize_t bonding_store_lp_interval(struct device *d, const char *buf, size_t count) { struct bonding *bond = to_bond(d); - int new_value, ret = count; + int new_value, ret; if (sscanf(buf, "%d", &new_value) != 1) { pr_err("%s: no lp interval value specified.\n", bond->dev->name); - ret = -EINVAL; - goto out; + return -EINVAL; } - if (new_value <= 0) { - pr_err ("%s: lp_interval must be between 1 and %d\n", - bond->dev->name, INT_MAX); - ret = -EINVAL; - goto out; - } + if (!rtnl_trylock()) + return restart_syscall(); - bond->params.lp_interval = new_value; -out: + ret = bond_option_lp_interval_set(bond, new_value); + if (!ret) + ret = count; + + rtnl_unlock(); return ret; } diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 7d7ad1c..0a1a69e 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h @@ -465,6 +465,7 @@ int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif); int bond_option_all_slaves_active_set(struct bonding *bond, int all_slaves_active); int bond_option_min_links_set(struct bonding *bond, int min_links); +int bond_option_lp_interval_set(struct bonding *bond, int min_links); struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); struct net_device *bond_option_active_slave_get(struct bonding *bond); diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index c7a0f89..4825ae7 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -347,6 +347,7 @@ enum { IFLA_BOND_NUM_PEER_NOTIF, IFLA_BOND_ALL_SLAVES_ACTIVE, IFLA_BOND_MIN_LINKS, + IFLA_BOND_LP_INTERVAL, __IFLA_BOND_MAX, }; -- cgit v0.10.2 From c13ab3ff176eab78b6ee93817484584af5807cf2 Mon Sep 17 00:00:00 2001 From: "sfeldma@cumulusnetworks.com" Date: Tue, 17 Dec 2013 21:30:37 -0800 Subject: bonding: add packets_per_slave attribute netlink support Add IFLA_BOND_PACKETS_PER_SLAVE to allow get/set of bonding parameter packets_per_slave via netlink. Signed-off-by: Scott Feldman Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index 6c8339b..84acd144 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "bonding.h" static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { @@ -41,6 +42,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 }, [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 }, [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 }, + [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 }, }; static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) @@ -241,6 +243,15 @@ static int bond_changelink(struct net_device *bond_dev, if (err) return err; } + if (data[IFLA_BOND_PACKETS_PER_SLAVE]) { + int packets_per_slave = + nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]); + + err = bond_option_packets_per_slave_set(bond, + packets_per_slave); + if (err) + return err; + } return 0; } @@ -278,6 +289,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */ + nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */ 0; } @@ -287,6 +299,7 @@ static int bond_fill_info(struct sk_buff *skb, struct bonding *bond = netdev_priv(bond_dev); struct net_device *slave_dev = bond_option_active_slave_get(bond); struct nlattr *targets; + unsigned int packets_per_slave; int i, targets_added; if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode)) @@ -374,6 +387,14 @@ static int bond_fill_info(struct sk_buff *skb, bond->params.lp_interval)) goto nla_put_failure; + packets_per_slave = bond->params.packets_per_slave; + if (packets_per_slave > 1) + packets_per_slave = reciprocal_value(packets_per_slave); + + if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE, + packets_per_slave)) + goto nla_put_failure; + return 0; nla_put_failure: diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index e313a8f..f8a2cd8 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "bonding.h" static bool bond_mode_is_valid(int mode) @@ -633,3 +634,25 @@ int bond_option_lp_interval_set(struct bonding *bond, int lp_interval) return 0; } + +int bond_option_packets_per_slave_set(struct bonding *bond, + int packets_per_slave) +{ + if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) { + pr_err("%s: packets_per_slave must be between 0 and %u\n", + bond->dev->name, USHRT_MAX); + return -EINVAL; + } + + if (bond->params.mode != BOND_MODE_ROUNDROBIN) + pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n", + bond->dev->name); + + if (packets_per_slave > 1) + bond->params.packets_per_slave = + reciprocal_value(packets_per_slave); + else + bond->params.packets_per_slave = packets_per_slave; + + return 0; +} diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index c4cdbf6..a0a3476f 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -1409,28 +1409,22 @@ static ssize_t bonding_store_packets_per_slave(struct device *d, const char *buf, size_t count) { struct bonding *bond = to_bond(d); - int new_value, ret = count; + int new_value, ret; if (sscanf(buf, "%d", &new_value) != 1) { pr_err("%s: no packets_per_slave value specified.\n", bond->dev->name); - ret = -EINVAL; - goto out; - } - if (new_value < 0 || new_value > USHRT_MAX) { - pr_err("%s: packets_per_slave must be between 0 and %u\n", - bond->dev->name, USHRT_MAX); - ret = -EINVAL; - goto out; + return -EINVAL; } - if (bond->params.mode != BOND_MODE_ROUNDROBIN) - pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n", - bond->dev->name); - if (new_value > 1) - bond->params.packets_per_slave = reciprocal_value(new_value); - else - bond->params.packets_per_slave = new_value; -out: + + if (!rtnl_trylock()) + return restart_syscall(); + + ret = bond_option_packets_per_slave_set(bond, new_value); + if (!ret) + ret = count; + + rtnl_unlock(); return ret; } diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 0a1a69e..5886f07 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h @@ -466,6 +466,8 @@ int bond_option_all_slaves_active_set(struct bonding *bond, int all_slaves_active); int bond_option_min_links_set(struct bonding *bond, int min_links); int bond_option_lp_interval_set(struct bonding *bond, int min_links); +int bond_option_packets_per_slave_set(struct bonding *bond, + int packets_per_slave); struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); struct net_device *bond_option_active_slave_get(struct bonding *bond); diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 4825ae7..8fbc7ca 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -348,6 +348,7 @@ enum { IFLA_BOND_ALL_SLAVES_ACTIVE, IFLA_BOND_MIN_LINKS, IFLA_BOND_LP_INTERVAL, + IFLA_BOND_PACKETS_PER_SLAVE, __IFLA_BOND_MAX, }; -- cgit v0.10.2