Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2004-2005 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 21 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 22 | |
| 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 27 | #include <linux/device.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 28 | #include <linux/sched.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 29 | #include <linux/fs.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/inetdevice.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/sysfs.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 36 | #include <linux/ctype.h> |
| 37 | #include <linux/inet.h> |
| 38 | #include <linux/rtnetlink.h> |
Stephen Hemminger | 5c5129b | 2009-06-12 19:02:51 +0000 | [diff] [blame] | 39 | #include <linux/etherdevice.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 40 | #include <net/net_namespace.h> |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 41 | #include <net/netns/generic.h> |
| 42 | #include <linux/nsproxy.h> |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 43 | #include <linux/reciprocal_div.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 44 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 45 | #include "bonding.h" |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 46 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 47 | #define to_dev(obj) container_of(obj, struct device, kobj) |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 48 | #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 49 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 50 | /* |
| 51 | * "show" function for the bond_masters attribute. |
| 52 | * The class parameter is ignored. |
| 53 | */ |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 54 | static ssize_t bonding_show_bonds(struct class *cls, |
| 55 | struct class_attribute *attr, |
| 56 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 57 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 58 | struct bond_net *bn = |
| 59 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 60 | int res = 0; |
| 61 | struct bonding *bond; |
| 62 | |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 63 | rtnl_lock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 64 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 65 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 66 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 67 | /* not enough space for another interface name */ |
| 68 | if ((PAGE_SIZE - res) > 10) |
| 69 | res = PAGE_SIZE - 10; |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 70 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 71 | break; |
| 72 | } |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 73 | res += sprintf(buf + res, "%s ", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 74 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 75 | if (res) |
| 76 | buf[res-1] = '\n'; /* eat the leftover space */ |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 77 | |
| 78 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 79 | return res; |
| 80 | } |
| 81 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 82 | static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname) |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 83 | { |
| 84 | struct bonding *bond; |
| 85 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 86 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 87 | if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) |
| 88 | return bond->dev; |
| 89 | } |
| 90 | return NULL; |
| 91 | } |
| 92 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 93 | /* |
| 94 | * "store" function for the bond_masters attribute. This is what |
| 95 | * creates and deletes entire bonds. |
| 96 | * |
| 97 | * The class parameter is ignored. |
| 98 | * |
| 99 | */ |
| 100 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 101 | static ssize_t bonding_store_bonds(struct class *cls, |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 102 | struct class_attribute *attr, |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 103 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 104 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 105 | struct bond_net *bn = |
| 106 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 107 | char command[IFNAMSIZ + 1] = {0, }; |
| 108 | char *ifname; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 109 | int rv, res = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 110 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 111 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 112 | ifname = command + 1; |
| 113 | if ((strlen(command) <= 1) || |
| 114 | !dev_valid_name(ifname)) |
| 115 | goto err_no_cmd; |
| 116 | |
| 117 | if (command[0] == '+') { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 118 | pr_info("%s is being created...\n", ifname); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 119 | rv = bond_create(bn->net, ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 120 | if (rv) { |
Phil Oester | 5f86cad1 | 2011-03-14 06:22:06 +0000 | [diff] [blame] | 121 | if (rv == -EEXIST) |
| 122 | pr_info("%s already exists.\n", ifname); |
| 123 | else |
| 124 | pr_info("%s creation failed.\n", ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 125 | res = rv; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 126 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 127 | } else if (command[0] == '-') { |
| 128 | struct net_device *bond_dev; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 129 | |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 130 | rtnl_lock(); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 131 | bond_dev = bond_get_by_name(bn, ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 132 | if (bond_dev) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 133 | pr_info("%s is being deleted...\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 134 | unregister_netdevice(bond_dev); |
| 135 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 136 | pr_err("unable to delete non-existent %s\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 137 | res = -ENODEV; |
| 138 | } |
| 139 | rtnl_unlock(); |
| 140 | } else |
| 141 | goto err_no_cmd; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 142 | |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 143 | /* Always return either count or an error. If you return 0, you'll |
| 144 | * get called forever, which is bad. |
| 145 | */ |
| 146 | return res; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 147 | |
| 148 | err_no_cmd: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 149 | pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n"); |
Jay Vosburgh | c4ebc66 | 2008-05-02 17:49:38 -0700 | [diff] [blame] | 150 | return -EPERM; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 151 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 152 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 153 | /* class attribute for bond_masters file. This ends up in /sys/class/net */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 154 | static const struct class_attribute class_attr_bonding_masters = { |
| 155 | .attr = { |
| 156 | .name = "bonding_masters", |
| 157 | .mode = S_IWUSR | S_IRUGO, |
| 158 | }, |
| 159 | .show = bonding_show_bonds, |
| 160 | .store = bonding_store_bonds, |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 161 | }; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 162 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 163 | /* |
| 164 | * Show the slaves in the current bond. |
| 165 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 166 | static ssize_t bonding_show_slaves(struct device *d, |
| 167 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 168 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 169 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 170 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 171 | struct slave *slave; |
| 172 | int res = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 173 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 174 | if (!rtnl_trylock()) |
| 175 | return restart_syscall(); |
| 176 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 177 | bond_for_each_slave(bond, slave, iter) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 178 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 179 | /* not enough space for another interface name */ |
| 180 | if ((PAGE_SIZE - res) > 10) |
| 181 | res = PAGE_SIZE - 10; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 182 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 183 | break; |
| 184 | } |
| 185 | res += sprintf(buf + res, "%s ", slave->dev->name); |
| 186 | } |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 187 | |
| 188 | rtnl_unlock(); |
| 189 | |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 190 | if (res) |
| 191 | buf[res-1] = '\n'; /* eat the leftover space */ |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 192 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 193 | return res; |
| 194 | } |
| 195 | |
| 196 | /* |
Veaceslav Falico | d6641cc | 2013-05-28 01:26:13 +0000 | [diff] [blame] | 197 | * Set the slaves in the current bond. |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 198 | * This is supposed to be only thin wrapper for bond_enslave and bond_release. |
| 199 | * All hard work should be done there. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 200 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 201 | static ssize_t bonding_store_slaves(struct device *d, |
| 202 | struct device_attribute *attr, |
| 203 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 204 | { |
| 205 | char command[IFNAMSIZ + 1] = { 0, }; |
| 206 | char *ifname; |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 207 | int res, ret = count; |
| 208 | struct net_device *dev; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 209 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 210 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 211 | if (!rtnl_trylock()) |
| 212 | return restart_syscall(); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 213 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 214 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 215 | ifname = command + 1; |
| 216 | if ((strlen(command) <= 1) || |
| 217 | !dev_valid_name(ifname)) |
| 218 | goto err_no_cmd; |
| 219 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 220 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 221 | if (!dev) { |
| 222 | pr_info("%s: Interface %s does not exist!\n", |
| 223 | bond->dev->name, ifname); |
| 224 | ret = -ENODEV; |
| 225 | goto out; |
| 226 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 227 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 228 | switch (command[0]) { |
| 229 | case '+': |
| 230 | pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 231 | res = bond_enslave(bond->dev, dev); |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 232 | break; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 233 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 234 | case '-': |
| 235 | pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name); |
| 236 | res = bond_release(bond->dev, dev); |
| 237 | break; |
| 238 | |
| 239 | default: |
| 240 | goto err_no_cmd; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 243 | if (res) |
| 244 | ret = res; |
| 245 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 246 | |
| 247 | err_no_cmd: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 248 | pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n", |
| 249 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 250 | ret = -EPERM; |
| 251 | |
| 252 | out: |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 253 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 254 | return ret; |
| 255 | } |
| 256 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 257 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, |
| 258 | bonding_store_slaves); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * Show and set the bonding mode. The bond interface must be down to |
| 262 | * change the mode. |
| 263 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 264 | static ssize_t bonding_show_mode(struct device *d, |
| 265 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 266 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 267 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 268 | |
| 269 | return sprintf(buf, "%s %d\n", |
| 270 | bond_mode_tbl[bond->params.mode].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 271 | bond->params.mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 274 | static ssize_t bonding_store_mode(struct device *d, |
| 275 | struct device_attribute *attr, |
| 276 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 277 | { |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 278 | int new_value, ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 279 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 280 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 281 | new_value = bond_parse_parm(buf, bond_mode_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 282 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 283 | pr_err("%s: Ignoring invalid mode value %.*s.\n", |
| 284 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 285 | return -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 286 | } |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 287 | if (!rtnl_trylock()) |
| 288 | return restart_syscall(); |
| 289 | |
| 290 | ret = bond_option_mode_set(bond, new_value); |
| 291 | if (!ret) { |
| 292 | pr_info("%s: setting mode to %s (%d).\n", |
| 293 | bond->dev->name, bond_mode_tbl[new_value].modename, |
| 294 | new_value); |
| 295 | ret = count; |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 296 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 297 | |
nikolay@redhat.com | ea6836d | 2013-05-18 01:18:28 +0000 | [diff] [blame] | 298 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 299 | return ret; |
| 300 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 301 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
| 302 | bonding_show_mode, bonding_store_mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 303 | |
| 304 | /* |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 305 | * Show and set the bonding transmit hash method. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 306 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 307 | static ssize_t bonding_show_xmit_hash(struct device *d, |
| 308 | struct device_attribute *attr, |
| 309 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 310 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 311 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 312 | |
Wagner Ferenc | 8e4b932 | 2007-12-06 23:40:32 -0800 | [diff] [blame] | 313 | return sprintf(buf, "%s %d\n", |
| 314 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, |
| 315 | bond->params.xmit_policy); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 318 | static ssize_t bonding_store_xmit_hash(struct device *d, |
| 319 | struct device_attribute *attr, |
| 320 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 321 | { |
| 322 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 323 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 324 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 325 | new_value = bond_parse_parm(buf, xmit_hashtype_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 326 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 327 | pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 328 | bond->dev->name, |
| 329 | (int)strlen(buf) - 1, buf); |
| 330 | ret = -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 331 | } else { |
| 332 | bond->params.xmit_policy = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 333 | pr_info("%s: setting xmit hash policy to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 334 | bond->dev->name, |
| 335 | xmit_hashtype_tbl[new_value].modename, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 336 | } |
Nikolay Aleksandrov | 53edee2 | 2013-05-24 00:59:47 +0000 | [diff] [blame] | 337 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 338 | return ret; |
| 339 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 340 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
| 341 | bonding_show_xmit_hash, bonding_store_xmit_hash); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 342 | |
| 343 | /* |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 344 | * Show and set arp_validate. |
| 345 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 346 | static ssize_t bonding_show_arp_validate(struct device *d, |
| 347 | struct device_attribute *attr, |
| 348 | char *buf) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 349 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 350 | struct bonding *bond = to_bond(d); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 351 | |
| 352 | return sprintf(buf, "%s %d\n", |
| 353 | arp_validate_tbl[bond->params.arp_validate].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 354 | bond->params.arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 357 | static ssize_t bonding_store_arp_validate(struct device *d, |
| 358 | struct device_attribute *attr, |
| 359 | const char *buf, size_t count) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 360 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 361 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 362 | int new_value, ret = count; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 363 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 364 | if (!rtnl_trylock()) |
| 365 | return restart_syscall(); |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 366 | new_value = bond_parse_parm(buf, arp_validate_tbl); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 367 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 368 | pr_err("%s: Ignoring invalid arp_validate value %s\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 369 | bond->dev->name, buf); |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 370 | ret = -EINVAL; |
| 371 | goto out; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 372 | } |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 373 | if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 374 | pr_err("%s: arp_validate only supported in active-backup mode.\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 375 | bond->dev->name); |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 376 | ret = -EINVAL; |
| 377 | goto out; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 378 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 379 | pr_info("%s: setting arp_validate to %s (%d).\n", |
| 380 | bond->dev->name, arp_validate_tbl[new_value].modename, |
| 381 | new_value); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 382 | |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 383 | if (bond->dev->flags & IFF_UP) { |
| 384 | if (!new_value) |
| 385 | bond->recv_probe = NULL; |
| 386 | else if (bond->params.arp_interval) |
| 387 | bond->recv_probe = bond_arp_rcv; |
| 388 | } |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 389 | bond->params.arp_validate = new_value; |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 390 | out: |
| 391 | rtnl_unlock(); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 392 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 393 | return ret; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 396 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
| 397 | bonding_store_arp_validate); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 398 | /* |
| 399 | * Show and set arp_all_targets. |
| 400 | */ |
| 401 | static ssize_t bonding_show_arp_all_targets(struct device *d, |
| 402 | struct device_attribute *attr, |
| 403 | char *buf) |
| 404 | { |
| 405 | struct bonding *bond = to_bond(d); |
| 406 | int value = bond->params.arp_all_targets; |
| 407 | |
| 408 | return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename, |
| 409 | value); |
| 410 | } |
| 411 | |
| 412 | static ssize_t bonding_store_arp_all_targets(struct device *d, |
| 413 | struct device_attribute *attr, |
| 414 | const char *buf, size_t count) |
| 415 | { |
| 416 | struct bonding *bond = to_bond(d); |
| 417 | int new_value; |
| 418 | |
| 419 | new_value = bond_parse_parm(buf, arp_all_targets_tbl); |
| 420 | if (new_value < 0) { |
| 421 | pr_err("%s: Ignoring invalid arp_all_targets value %s\n", |
| 422 | bond->dev->name, buf); |
| 423 | return -EINVAL; |
| 424 | } |
| 425 | pr_info("%s: setting arp_all_targets to %s (%d).\n", |
| 426 | bond->dev->name, arp_all_targets_tbl[new_value].modename, |
| 427 | new_value); |
| 428 | |
| 429 | bond->params.arp_all_targets = new_value; |
| 430 | |
| 431 | return count; |
| 432 | } |
| 433 | |
| 434 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, |
| 435 | bonding_show_arp_all_targets, bonding_store_arp_all_targets); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 436 | |
| 437 | /* |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 438 | * Show and store fail_over_mac. User only allowed to change the |
| 439 | * value when there are no slaves. |
| 440 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 441 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
| 442 | struct device_attribute *attr, |
| 443 | char *buf) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 444 | { |
| 445 | struct bonding *bond = to_bond(d); |
| 446 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 447 | return sprintf(buf, "%s %d\n", |
| 448 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, |
| 449 | bond->params.fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 452 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
| 453 | struct device_attribute *attr, |
| 454 | const char *buf, size_t count) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 455 | { |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 456 | int new_value, ret = count; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 457 | struct bonding *bond = to_bond(d); |
| 458 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 459 | if (!rtnl_trylock()) |
| 460 | return restart_syscall(); |
| 461 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 462 | if (bond_has_slaves(bond)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 463 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 464 | bond->dev->name); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 465 | ret = -EPERM; |
| 466 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 469 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
| 470 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 471 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 472 | bond->dev->name, buf); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 473 | ret = -EINVAL; |
| 474 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 477 | bond->params.fail_over_mac = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 478 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", |
| 479 | bond->dev->name, fail_over_mac_tbl[new_value].modename, |
| 480 | new_value); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 481 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 482 | out: |
| 483 | rtnl_unlock(); |
| 484 | return ret; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 487 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
| 488 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 489 | |
| 490 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 491 | * Show and set the arp timer interval. There are two tricky bits |
| 492 | * here. First, if ARP monitoring is activated, then we must disable |
| 493 | * MII monitoring. Second, if the ARP timer isn't running, we must |
| 494 | * start it. |
| 495 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 496 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 497 | struct device_attribute *attr, |
| 498 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 499 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 500 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 501 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 502 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 505 | static ssize_t bonding_store_arp_interval(struct device *d, |
| 506 | struct device_attribute *attr, |
| 507 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 508 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 509 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 510 | int new_value, ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 511 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 512 | if (!rtnl_trylock()) |
| 513 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 514 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 515 | pr_err("%s: no arp_interval value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 516 | bond->dev->name); |
| 517 | ret = -EINVAL; |
| 518 | goto out; |
| 519 | } |
| 520 | if (new_value < 0) { |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 521 | pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 522 | bond->dev->name, new_value, INT_MAX); |
| 523 | ret = -EINVAL; |
| 524 | goto out; |
| 525 | } |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 526 | if (BOND_NO_USES_ARP(bond->params.mode)) { |
Veaceslav Falico | ec9f1d1 | 2013-11-12 15:37:40 +0100 | [diff] [blame] | 527 | pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n", |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 528 | bond->dev->name, bond->dev->name); |
| 529 | ret = -EINVAL; |
| 530 | goto out; |
| 531 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 532 | pr_info("%s: Setting ARP monitoring interval to %d.\n", |
| 533 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 534 | bond->params.arp_interval = new_value; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 535 | if (new_value) { |
| 536 | if (bond->params.miimon) { |
| 537 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", |
| 538 | bond->dev->name, bond->dev->name); |
| 539 | bond->params.miimon = 0; |
| 540 | } |
| 541 | if (!bond->params.arp_targets[0]) |
| 542 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", |
| 543 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 544 | } |
| 545 | if (bond->dev->flags & IFF_UP) { |
| 546 | /* If the interface is up, we may need to fire off |
| 547 | * the ARP timer. If the interface is down, the |
| 548 | * timer will get fired off when the open function |
| 549 | * is called. |
| 550 | */ |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 551 | if (!new_value) { |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 552 | if (bond->params.arp_validate) |
| 553 | bond->recv_probe = NULL; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 554 | cancel_delayed_work_sync(&bond->arp_work); |
| 555 | } else { |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 556 | /* arp_validate can be set only in active-backup mode */ |
| 557 | if (bond->params.arp_validate) |
| 558 | bond->recv_probe = bond_arp_rcv; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 559 | cancel_delayed_work_sync(&bond->mii_work); |
| 560 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 561 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 562 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 563 | out: |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 564 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 565 | return ret; |
| 566 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 567 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
| 568 | bonding_show_arp_interval, bonding_store_arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 569 | |
| 570 | /* |
| 571 | * Show and set the arp targets. |
| 572 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 573 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 574 | struct device_attribute *attr, |
| 575 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 576 | { |
| 577 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 578 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 579 | |
| 580 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 581 | if (bond->params.arp_targets[i]) |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 582 | res += sprintf(buf + res, "%pI4 ", |
| 583 | &bond->params.arp_targets[i]); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 584 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 585 | if (res) |
| 586 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 587 | return res; |
| 588 | } |
| 589 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 590 | static ssize_t bonding_store_arp_targets(struct device *d, |
| 591 | struct device_attribute *attr, |
| 592 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 593 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 594 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 595 | struct list_head *iter; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 596 | struct slave *slave; |
| 597 | __be32 newtarget, *targets; |
| 598 | unsigned long *targets_rx; |
| 599 | int ind, i, j, ret = -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 600 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 601 | if (!rtnl_trylock()) |
| 602 | return restart_syscall(); |
| 603 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 604 | targets = bond->params.arp_targets; |
Wang Weidong | f9de11a | 2013-11-15 10:34:30 -0500 | [diff] [blame] | 605 | if (!in4_pton(buf + 1, -1, (u8 *)&newtarget, -1, NULL) || |
| 606 | IS_IP_TARGET_UNUSABLE_ADDRESS(newtarget)) { |
| 607 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
| 608 | bond->dev->name, &newtarget); |
| 609 | goto out; |
| 610 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 611 | /* look for adds */ |
| 612 | if (buf[0] == '+') { |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 613 | if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */ |
| 614 | pr_err("%s: ARP target %pI4 is already present\n", |
| 615 | bond->dev->name, &newtarget); |
| 616 | goto out; |
| 617 | } |
| 618 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 619 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 620 | if (ind == -1) { |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 621 | pr_err("%s: ARP target table is full!\n", |
| 622 | bond->dev->name); |
| 623 | goto out; |
| 624 | } |
| 625 | |
| 626 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, |
| 627 | &newtarget); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 628 | /* not to race with bond_arp_rcv */ |
| 629 | write_lock_bh(&bond->lock); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 630 | bond_for_each_slave(bond, slave, iter) |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 631 | slave->target_last_arp_rx[ind] = jiffies; |
| 632 | targets[ind] = newtarget; |
| 633 | write_unlock_bh(&bond->lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 634 | } else if (buf[0] == '-') { |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 635 | ind = bond_get_targets_ip(targets, newtarget); |
| 636 | if (ind == -1) { |
| 637 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 638 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 639 | goto out; |
| 640 | } |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 641 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 642 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
| 643 | pr_warn("%s: removing last arp target with arp_interval on\n", |
| 644 | bond->dev->name); |
| 645 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 646 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, |
| 647 | &newtarget); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 648 | |
| 649 | write_lock_bh(&bond->lock); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 650 | bond_for_each_slave(bond, slave, iter) { |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 651 | targets_rx = slave->target_last_arp_rx; |
| 652 | j = ind; |
| 653 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) |
| 654 | targets_rx[j] = targets_rx[j+1]; |
| 655 | targets_rx[j] = 0; |
| 656 | } |
| 657 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 658 | targets[i] = targets[i+1]; |
| 659 | targets[i] = 0; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 660 | write_unlock_bh(&bond->lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 661 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 662 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 663 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 664 | ret = -EPERM; |
| 665 | goto out; |
| 666 | } |
| 667 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 668 | ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 669 | out: |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 670 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 671 | return ret; |
| 672 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 673 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * Show and set the up and down delays. These must be multiples of the |
| 677 | * MII monitoring value, and are stored internally as the multiplier. |
| 678 | * Thus, we must translate to MS for the real world. |
| 679 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 680 | static ssize_t bonding_show_downdelay(struct device *d, |
| 681 | struct device_attribute *attr, |
| 682 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 683 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 684 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 685 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 686 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 687 | } |
| 688 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 689 | static ssize_t bonding_store_downdelay(struct device *d, |
| 690 | struct device_attribute *attr, |
| 691 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 692 | { |
| 693 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 694 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 695 | |
Nikolay Aleksandrov | b869ccf | 2013-11-13 17:07:46 +0100 | [diff] [blame] | 696 | if (!rtnl_trylock()) |
| 697 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 698 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 699 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 700 | bond->dev->name); |
| 701 | ret = -EPERM; |
| 702 | goto out; |
| 703 | } |
| 704 | |
| 705 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 706 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 707 | ret = -EINVAL; |
| 708 | goto out; |
| 709 | } |
| 710 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 711 | pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 712 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 713 | ret = -EINVAL; |
| 714 | goto out; |
| 715 | } else { |
| 716 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 717 | pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 718 | bond->dev->name, new_value, |
| 719 | bond->params.miimon, |
| 720 | (new_value / bond->params.miimon) * |
| 721 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 722 | } |
| 723 | bond->params.downdelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 724 | pr_info("%s: Setting down delay to %d.\n", |
| 725 | bond->dev->name, |
| 726 | bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 727 | |
| 728 | } |
| 729 | |
| 730 | out: |
Nikolay Aleksandrov | b869ccf | 2013-11-13 17:07:46 +0100 | [diff] [blame] | 731 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 732 | return ret; |
| 733 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 734 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
| 735 | bonding_show_downdelay, bonding_store_downdelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 736 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 737 | static ssize_t bonding_show_updelay(struct device *d, |
| 738 | struct device_attribute *attr, |
| 739 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 740 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 741 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 742 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 743 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 744 | |
| 745 | } |
| 746 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 747 | static ssize_t bonding_store_updelay(struct device *d, |
| 748 | struct device_attribute *attr, |
| 749 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 750 | { |
| 751 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 752 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 753 | |
Nikolay Aleksandrov | b869ccf | 2013-11-13 17:07:46 +0100 | [diff] [blame] | 754 | if (!rtnl_trylock()) |
| 755 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 756 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 757 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 758 | bond->dev->name); |
| 759 | ret = -EPERM; |
| 760 | goto out; |
| 761 | } |
| 762 | |
| 763 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 764 | pr_err("%s: no up delay value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 765 | bond->dev->name); |
| 766 | ret = -EINVAL; |
| 767 | goto out; |
| 768 | } |
| 769 | if (new_value < 0) { |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 770 | pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n", |
| 771 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 772 | ret = -EINVAL; |
| 773 | goto out; |
| 774 | } else { |
| 775 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 776 | pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 777 | bond->dev->name, new_value, |
| 778 | bond->params.miimon, |
| 779 | (new_value / bond->params.miimon) * |
| 780 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 781 | } |
| 782 | bond->params.updelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 783 | pr_info("%s: Setting up delay to %d.\n", |
| 784 | bond->dev->name, |
| 785 | bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | out: |
Nikolay Aleksandrov | b869ccf | 2013-11-13 17:07:46 +0100 | [diff] [blame] | 789 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 790 | return ret; |
| 791 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 792 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
| 793 | bonding_show_updelay, bonding_store_updelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 794 | |
| 795 | /* |
| 796 | * Show and set the LACP interval. Interface must be down, and the mode |
| 797 | * must be set to 802.3ad mode. |
| 798 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 799 | static ssize_t bonding_show_lacp(struct device *d, |
| 800 | struct device_attribute *attr, |
| 801 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 802 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 803 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 804 | |
| 805 | return sprintf(buf, "%s %d\n", |
| 806 | bond_lacp_tbl[bond->params.lacp_fast].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 807 | bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 808 | } |
| 809 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 810 | static ssize_t bonding_store_lacp(struct device *d, |
| 811 | struct device_attribute *attr, |
| 812 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 813 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 814 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 815 | int new_value, ret = count; |
| 816 | |
| 817 | if (!rtnl_trylock()) |
| 818 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 819 | |
| 820 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 821 | pr_err("%s: Unable to update LACP rate because interface is up.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 822 | bond->dev->name); |
| 823 | ret = -EPERM; |
| 824 | goto out; |
| 825 | } |
| 826 | |
| 827 | if (bond->params.mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 828 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 829 | bond->dev->name); |
| 830 | ret = -EPERM; |
| 831 | goto out; |
| 832 | } |
| 833 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 834 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 835 | |
| 836 | if ((new_value == 1) || (new_value == 0)) { |
| 837 | bond->params.lacp_fast = new_value; |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 838 | bond_3ad_update_lacp_rate(bond); |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 839 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 840 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
| 841 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 842 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 843 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 844 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 845 | ret = -EINVAL; |
| 846 | } |
| 847 | out: |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 848 | rtnl_unlock(); |
| 849 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 850 | return ret; |
| 851 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 852 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
| 853 | bonding_show_lacp, bonding_store_lacp); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 854 | |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 855 | static ssize_t bonding_show_min_links(struct device *d, |
| 856 | struct device_attribute *attr, |
| 857 | char *buf) |
| 858 | { |
| 859 | struct bonding *bond = to_bond(d); |
| 860 | |
| 861 | return sprintf(buf, "%d\n", bond->params.min_links); |
| 862 | } |
| 863 | |
| 864 | static ssize_t bonding_store_min_links(struct device *d, |
| 865 | struct device_attribute *attr, |
| 866 | const char *buf, size_t count) |
| 867 | { |
| 868 | struct bonding *bond = to_bond(d); |
| 869 | int ret; |
| 870 | unsigned int new_value; |
| 871 | |
| 872 | ret = kstrtouint(buf, 0, &new_value); |
| 873 | if (ret < 0) { |
| 874 | pr_err("%s: Ignoring invalid min links value %s.\n", |
| 875 | bond->dev->name, buf); |
| 876 | return ret; |
| 877 | } |
| 878 | |
| 879 | pr_info("%s: Setting min links value to %u\n", |
| 880 | bond->dev->name, new_value); |
| 881 | bond->params.min_links = new_value; |
| 882 | return count; |
| 883 | } |
| 884 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, |
| 885 | bonding_show_min_links, bonding_store_min_links); |
| 886 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 887 | static ssize_t bonding_show_ad_select(struct device *d, |
| 888 | struct device_attribute *attr, |
| 889 | char *buf) |
| 890 | { |
| 891 | struct bonding *bond = to_bond(d); |
| 892 | |
| 893 | return sprintf(buf, "%s %d\n", |
| 894 | ad_select_tbl[bond->params.ad_select].modename, |
| 895 | bond->params.ad_select); |
| 896 | } |
| 897 | |
| 898 | |
| 899 | static ssize_t bonding_store_ad_select(struct device *d, |
| 900 | struct device_attribute *attr, |
| 901 | const char *buf, size_t count) |
| 902 | { |
| 903 | int new_value, ret = count; |
| 904 | struct bonding *bond = to_bond(d); |
| 905 | |
| 906 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 907 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
| 908 | bond->dev->name); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 909 | ret = -EPERM; |
| 910 | goto out; |
| 911 | } |
| 912 | |
| 913 | new_value = bond_parse_parm(buf, ad_select_tbl); |
| 914 | |
| 915 | if (new_value != -1) { |
| 916 | bond->params.ad_select = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 917 | pr_info("%s: Setting ad_select to %s (%d).\n", |
| 918 | bond->dev->name, ad_select_tbl[new_value].modename, |
| 919 | new_value); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 920 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 921 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 922 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 923 | ret = -EINVAL; |
| 924 | } |
| 925 | out: |
| 926 | return ret; |
| 927 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 928 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
| 929 | bonding_show_ad_select, bonding_store_ad_select); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 930 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 931 | /* |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 932 | * Show and set the number of peer notifications to send after a failover event. |
| 933 | */ |
| 934 | static ssize_t bonding_show_num_peer_notif(struct device *d, |
| 935 | struct device_attribute *attr, |
| 936 | char *buf) |
| 937 | { |
| 938 | struct bonding *bond = to_bond(d); |
| 939 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); |
| 940 | } |
| 941 | |
| 942 | static ssize_t bonding_store_num_peer_notif(struct device *d, |
| 943 | struct device_attribute *attr, |
| 944 | const char *buf, size_t count) |
| 945 | { |
| 946 | struct bonding *bond = to_bond(d); |
| 947 | int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); |
| 948 | return err ? err : count; |
| 949 | } |
| 950 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, |
| 951 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 952 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, |
| 953 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 954 | |
| 955 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 956 | * Show and set the MII monitor interval. There are two tricky bits |
| 957 | * here. First, if MII monitoring is activated, then we must disable |
| 958 | * ARP monitoring. Second, if the timer isn't running, we must |
| 959 | * start it. |
| 960 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 961 | static ssize_t bonding_show_miimon(struct device *d, |
| 962 | struct device_attribute *attr, |
| 963 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 964 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 965 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 966 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 967 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 968 | } |
| 969 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 970 | static ssize_t bonding_store_miimon(struct device *d, |
| 971 | struct device_attribute *attr, |
| 972 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 973 | { |
| 974 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 975 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 976 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 977 | if (!rtnl_trylock()) |
| 978 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 979 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 980 | pr_err("%s: no miimon value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 981 | bond->dev->name); |
| 982 | ret = -EINVAL; |
| 983 | goto out; |
| 984 | } |
| 985 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 986 | pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n", |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 987 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 988 | ret = -EINVAL; |
| 989 | goto out; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 990 | } |
| 991 | pr_info("%s: Setting MII monitoring interval to %d.\n", |
| 992 | bond->dev->name, new_value); |
| 993 | bond->params.miimon = new_value; |
| 994 | if (bond->params.updelay) |
| 995 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", |
| 996 | bond->dev->name, |
| 997 | bond->params.updelay * bond->params.miimon); |
| 998 | if (bond->params.downdelay) |
| 999 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", |
| 1000 | bond->dev->name, |
| 1001 | bond->params.downdelay * bond->params.miimon); |
| 1002 | if (new_value && bond->params.arp_interval) { |
| 1003 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
| 1004 | bond->dev->name); |
| 1005 | bond->params.arp_interval = 0; |
| 1006 | if (bond->params.arp_validate) |
| 1007 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 1008 | } |
| 1009 | if (bond->dev->flags & IFF_UP) { |
| 1010 | /* If the interface is up, we may need to fire off |
| 1011 | * the MII timer. If the interface is down, the |
| 1012 | * timer will get fired off when the open function |
| 1013 | * is called. |
| 1014 | */ |
| 1015 | if (!new_value) { |
| 1016 | cancel_delayed_work_sync(&bond->mii_work); |
| 1017 | } else { |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1018 | cancel_delayed_work_sync(&bond->arp_work); |
| 1019 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | out: |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1023 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1024 | return ret; |
| 1025 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1026 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
| 1027 | bonding_show_miimon, bonding_store_miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1028 | |
| 1029 | /* |
| 1030 | * Show and set the primary slave. The store function is much |
| 1031 | * simpler than bonding_store_slaves function because it only needs to |
| 1032 | * handle one interface name. |
| 1033 | * The bond must be a mode that supports a primary for this be |
| 1034 | * set. |
| 1035 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1036 | static ssize_t bonding_show_primary(struct device *d, |
| 1037 | struct device_attribute *attr, |
| 1038 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1039 | { |
| 1040 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1041 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1042 | |
| 1043 | if (bond->primary_slave) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1044 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1045 | |
| 1046 | return count; |
| 1047 | } |
| 1048 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1049 | static ssize_t bonding_store_primary(struct device *d, |
| 1050 | struct device_attribute *attr, |
| 1051 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1052 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1053 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1054 | struct list_head *iter; |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1055 | char ifname[IFNAMSIZ]; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1056 | struct slave *slave; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1057 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1058 | if (!rtnl_trylock()) |
| 1059 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1060 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1061 | read_lock(&bond->lock); |
| 1062 | write_lock_bh(&bond->curr_slave_lock); |
| 1063 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1064 | if (!USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1065 | pr_info("%s: Unable to set primary slave; %s is in mode %d\n", |
| 1066 | bond->dev->name, bond->dev->name, bond->params.mode); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1067 | goto out; |
| 1068 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1069 | |
nikolay@redhat.com | eb6e98a | 2012-10-31 04:42:51 +0000 | [diff] [blame] | 1070 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1071 | |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1072 | /* check to see if we are clearing primary */ |
| 1073 | if (!strlen(ifname) || buf[0] == '\n') { |
| 1074 | pr_info("%s: Setting primary slave to None.\n", |
| 1075 | bond->dev->name); |
| 1076 | bond->primary_slave = NULL; |
Milos Vyletel | eb492f7 | 2013-01-29 09:59:00 +0000 | [diff] [blame] | 1077 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1078 | bond_select_active_slave(bond); |
| 1079 | goto out; |
| 1080 | } |
| 1081 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1082 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1083 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1084 | pr_info("%s: Setting %s as primary slave.\n", |
| 1085 | bond->dev->name, slave->dev->name); |
| 1086 | bond->primary_slave = slave; |
| 1087 | strcpy(bond->params.primary, slave->dev->name); |
| 1088 | bond_select_active_slave(bond); |
| 1089 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1090 | } |
| 1091 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1092 | |
Weiping Pan | 8a93664 | 2012-06-10 23:00:20 +0000 | [diff] [blame] | 1093 | strncpy(bond->params.primary, ifname, IFNAMSIZ); |
| 1094 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 1095 | |
| 1096 | pr_info("%s: Recording %s as primary, " |
| 1097 | "but it has not been enslaved to %s yet.\n", |
| 1098 | bond->dev->name, ifname, bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1099 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1100 | write_unlock_bh(&bond->curr_slave_lock); |
| 1101 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1102 | unblock_netpoll_tx(); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1103 | rtnl_unlock(); |
| 1104 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1105 | return count; |
| 1106 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1107 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
| 1108 | bonding_show_primary, bonding_store_primary); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1109 | |
| 1110 | /* |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1111 | * Show and set the primary_reselect flag. |
| 1112 | */ |
| 1113 | static ssize_t bonding_show_primary_reselect(struct device *d, |
| 1114 | struct device_attribute *attr, |
| 1115 | char *buf) |
| 1116 | { |
| 1117 | struct bonding *bond = to_bond(d); |
| 1118 | |
| 1119 | return sprintf(buf, "%s %d\n", |
| 1120 | pri_reselect_tbl[bond->params.primary_reselect].modename, |
| 1121 | bond->params.primary_reselect); |
| 1122 | } |
| 1123 | |
| 1124 | static ssize_t bonding_store_primary_reselect(struct device *d, |
| 1125 | struct device_attribute *attr, |
| 1126 | const char *buf, size_t count) |
| 1127 | { |
| 1128 | int new_value, ret = count; |
| 1129 | struct bonding *bond = to_bond(d); |
| 1130 | |
| 1131 | if (!rtnl_trylock()) |
| 1132 | return restart_syscall(); |
| 1133 | |
| 1134 | new_value = bond_parse_parm(buf, pri_reselect_tbl); |
| 1135 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1136 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1137 | bond->dev->name, |
| 1138 | (int) strlen(buf) - 1, buf); |
| 1139 | ret = -EINVAL; |
| 1140 | goto out; |
| 1141 | } |
| 1142 | |
| 1143 | bond->params.primary_reselect = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1144 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1145 | bond->dev->name, pri_reselect_tbl[new_value].modename, |
| 1146 | new_value); |
| 1147 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1148 | block_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1149 | read_lock(&bond->lock); |
| 1150 | write_lock_bh(&bond->curr_slave_lock); |
| 1151 | bond_select_active_slave(bond); |
| 1152 | write_unlock_bh(&bond->curr_slave_lock); |
| 1153 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1154 | unblock_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1155 | out: |
| 1156 | rtnl_unlock(); |
| 1157 | return ret; |
| 1158 | } |
| 1159 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
| 1160 | bonding_show_primary_reselect, |
| 1161 | bonding_store_primary_reselect); |
| 1162 | |
| 1163 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1164 | * Show and set the use_carrier flag. |
| 1165 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1166 | static ssize_t bonding_show_carrier(struct device *d, |
| 1167 | struct device_attribute *attr, |
| 1168 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1169 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1170 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1171 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1172 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1175 | static ssize_t bonding_store_carrier(struct device *d, |
| 1176 | struct device_attribute *attr, |
| 1177 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1178 | { |
| 1179 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1180 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1181 | |
| 1182 | |
| 1183 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1184 | pr_err("%s: no use_carrier value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1185 | bond->dev->name); |
| 1186 | ret = -EINVAL; |
| 1187 | goto out; |
| 1188 | } |
| 1189 | if ((new_value == 0) || (new_value == 1)) { |
| 1190 | bond->params.use_carrier = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1191 | pr_info("%s: Setting use_carrier to %d.\n", |
| 1192 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1193 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1194 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
| 1195 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1196 | } |
| 1197 | out: |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1198 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1199 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1200 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
| 1201 | bonding_show_carrier, bonding_store_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1202 | |
| 1203 | |
| 1204 | /* |
| 1205 | * Show and set currently active_slave. |
| 1206 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1207 | static ssize_t bonding_show_active_slave(struct device *d, |
| 1208 | struct device_attribute *attr, |
| 1209 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1210 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1211 | struct bonding *bond = to_bond(d); |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 1212 | struct net_device *slave_dev; |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 1213 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1214 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1215 | rcu_read_lock(); |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 1216 | slave_dev = bond_option_active_slave_get_rcu(bond); |
| 1217 | if (slave_dev) |
| 1218 | count = sprintf(buf, "%s\n", slave_dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1219 | rcu_read_unlock(); |
| 1220 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1221 | return count; |
| 1222 | } |
| 1223 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1224 | static ssize_t bonding_store_active_slave(struct device *d, |
| 1225 | struct device_attribute *attr, |
| 1226 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1227 | { |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1228 | int ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1229 | struct bonding *bond = to_bond(d); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1230 | char ifname[IFNAMSIZ]; |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1231 | struct net_device *dev; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1232 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1233 | if (!rtnl_trylock()) |
| 1234 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1235 | |
nikolay@redhat.com | c84e159 | 2012-10-31 06:03:52 +0000 | [diff] [blame] | 1236 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1237 | if (!strlen(ifname) || buf[0] == '\n') { |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1238 | dev = NULL; |
| 1239 | } else { |
| 1240 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 1241 | if (!dev) { |
| 1242 | ret = -ENODEV; |
| 1243 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1244 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1245 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1246 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1247 | ret = bond_option_active_slave_set(bond, dev); |
| 1248 | if (!ret) |
| 1249 | ret = count; |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1250 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1251 | out: |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1252 | rtnl_unlock(); |
| 1253 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1254 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1255 | |
| 1256 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1257 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
| 1258 | bonding_show_active_slave, bonding_store_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1259 | |
| 1260 | |
| 1261 | /* |
| 1262 | * Show link status of the bond interface. |
| 1263 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1264 | static ssize_t bonding_show_mii_status(struct device *d, |
| 1265 | struct device_attribute *attr, |
| 1266 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1267 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1268 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1269 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1270 | return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1271 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1272 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1273 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1274 | /* |
| 1275 | * Show current 802.3ad aggregator ID. |
| 1276 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1277 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 1278 | struct device_attribute *attr, |
| 1279 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1280 | { |
| 1281 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1282 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1283 | |
| 1284 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1285 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1286 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1287 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1288 | ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1289 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1290 | |
| 1291 | return count; |
| 1292 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1293 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1294 | |
| 1295 | |
| 1296 | /* |
| 1297 | * Show number of active 802.3ad ports. |
| 1298 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1299 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 1300 | struct device_attribute *attr, |
| 1301 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1302 | { |
| 1303 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1304 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1305 | |
| 1306 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1307 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1308 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1309 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1310 | ? 0 : ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1311 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1312 | |
| 1313 | return count; |
| 1314 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1315 | static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1316 | |
| 1317 | |
| 1318 | /* |
| 1319 | * Show current 802.3ad actor key. |
| 1320 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1321 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 1322 | struct device_attribute *attr, |
| 1323 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1324 | { |
| 1325 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1326 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1327 | |
| 1328 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1329 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1330 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1331 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1332 | ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1333 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1334 | |
| 1335 | return count; |
| 1336 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1337 | static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1338 | |
| 1339 | |
| 1340 | /* |
| 1341 | * Show current 802.3ad partner key. |
| 1342 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1343 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 1344 | struct device_attribute *attr, |
| 1345 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1346 | { |
| 1347 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1348 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1349 | |
| 1350 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1351 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1352 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1353 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1354 | ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1355 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1356 | |
| 1357 | return count; |
| 1358 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1359 | static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1360 | |
| 1361 | |
| 1362 | /* |
| 1363 | * Show current 802.3ad partner mac. |
| 1364 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1365 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 1366 | struct device_attribute *attr, |
| 1367 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1368 | { |
| 1369 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1370 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1371 | |
| 1372 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1373 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1374 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1375 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1376 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1377 | |
| 1378 | return count; |
| 1379 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1380 | static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1381 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1382 | /* |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1383 | * Show the queue_ids of the slaves in the current bond. |
| 1384 | */ |
| 1385 | static ssize_t bonding_show_queue_id(struct device *d, |
| 1386 | struct device_attribute *attr, |
| 1387 | char *buf) |
| 1388 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1389 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1390 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1391 | struct slave *slave; |
| 1392 | int res = 0; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1393 | |
| 1394 | if (!rtnl_trylock()) |
| 1395 | return restart_syscall(); |
| 1396 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1397 | bond_for_each_slave(bond, slave, iter) { |
Nicolas de Pesloüan | 7923668 | 2010-07-14 18:24:54 -0700 | [diff] [blame] | 1398 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 1399 | /* not enough space for another interface_name:queue_id pair */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1400 | if ((PAGE_SIZE - res) > 10) |
| 1401 | res = PAGE_SIZE - 10; |
| 1402 | res += sprintf(buf + res, "++more++ "); |
| 1403 | break; |
| 1404 | } |
| 1405 | res += sprintf(buf + res, "%s:%d ", |
| 1406 | slave->dev->name, slave->queue_id); |
| 1407 | } |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1408 | if (res) |
| 1409 | buf[res-1] = '\n'; /* eat the leftover space */ |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1410 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1411 | rtnl_unlock(); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1412 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1413 | return res; |
| 1414 | } |
| 1415 | |
| 1416 | /* |
| 1417 | * Set the queue_ids of the slaves in the current bond. The bond |
| 1418 | * interface must be enslaved for this to work. |
| 1419 | */ |
| 1420 | static ssize_t bonding_store_queue_id(struct device *d, |
| 1421 | struct device_attribute *attr, |
| 1422 | const char *buffer, size_t count) |
| 1423 | { |
| 1424 | struct slave *slave, *update_slave; |
| 1425 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1426 | struct list_head *iter; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1427 | u16 qid; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1428 | int ret = count; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1429 | char *delim; |
| 1430 | struct net_device *sdev = NULL; |
| 1431 | |
| 1432 | if (!rtnl_trylock()) |
| 1433 | return restart_syscall(); |
| 1434 | |
| 1435 | /* delim will point to queue id if successful */ |
| 1436 | delim = strchr(buffer, ':'); |
| 1437 | if (!delim) |
| 1438 | goto err_no_cmd; |
| 1439 | |
| 1440 | /* |
| 1441 | * Terminate string that points to device name and bump it |
| 1442 | * up one, so we can read the queue id there. |
| 1443 | */ |
| 1444 | *delim = '\0'; |
| 1445 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1446 | goto err_no_cmd; |
| 1447 | |
| 1448 | /* Check buffer length, valid ifname and queue id */ |
| 1449 | if (strlen(buffer) > IFNAMSIZ || |
| 1450 | !dev_valid_name(buffer) || |
Jiri Pirko | 8a540ff | 2012-07-20 02:28:50 +0000 | [diff] [blame] | 1451 | qid > bond->dev->real_num_tx_queues) |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1452 | goto err_no_cmd; |
| 1453 | |
| 1454 | /* Get the pointer to that interface if it exists */ |
| 1455 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); |
| 1456 | if (!sdev) |
| 1457 | goto err_no_cmd; |
| 1458 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1459 | /* Search for thes slave and check for duplicate qids */ |
| 1460 | update_slave = NULL; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1461 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1462 | if (sdev == slave->dev) |
| 1463 | /* |
| 1464 | * We don't need to check the matching |
| 1465 | * slave for dups, since we're overwriting it |
| 1466 | */ |
| 1467 | update_slave = slave; |
| 1468 | else if (qid && qid == slave->queue_id) { |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1469 | goto err_no_cmd; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | if (!update_slave) |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1474 | goto err_no_cmd; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1475 | |
| 1476 | /* Actually set the qids for the slave */ |
| 1477 | update_slave->queue_id = qid; |
| 1478 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1479 | out: |
| 1480 | rtnl_unlock(); |
| 1481 | return ret; |
| 1482 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1483 | err_no_cmd: |
| 1484 | pr_info("invalid input for queue_id set for %s.\n", |
| 1485 | bond->dev->name); |
| 1486 | ret = -EPERM; |
| 1487 | goto out; |
| 1488 | } |
| 1489 | |
| 1490 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
| 1491 | bonding_store_queue_id); |
| 1492 | |
| 1493 | |
| 1494 | /* |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1495 | * Show and set the all_slaves_active flag. |
| 1496 | */ |
| 1497 | static ssize_t bonding_show_slaves_active(struct device *d, |
| 1498 | struct device_attribute *attr, |
| 1499 | char *buf) |
| 1500 | { |
| 1501 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1502 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1503 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); |
| 1504 | } |
| 1505 | |
| 1506 | static ssize_t bonding_store_slaves_active(struct device *d, |
| 1507 | struct device_attribute *attr, |
| 1508 | const char *buf, size_t count) |
| 1509 | { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1510 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1511 | int new_value, ret = count; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1512 | struct list_head *iter; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1513 | struct slave *slave; |
| 1514 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1515 | if (!rtnl_trylock()) |
| 1516 | return restart_syscall(); |
| 1517 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1518 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1519 | pr_err("%s: no all_slaves_active value specified.\n", |
| 1520 | bond->dev->name); |
| 1521 | ret = -EINVAL; |
| 1522 | goto out; |
| 1523 | } |
| 1524 | |
| 1525 | if (new_value == bond->params.all_slaves_active) |
| 1526 | goto out; |
| 1527 | |
| 1528 | if ((new_value == 0) || (new_value == 1)) { |
| 1529 | bond->params.all_slaves_active = new_value; |
| 1530 | } else { |
| 1531 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", |
| 1532 | bond->dev->name, new_value); |
| 1533 | ret = -EINVAL; |
| 1534 | goto out; |
| 1535 | } |
| 1536 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1537 | bond_for_each_slave(bond, slave, iter) { |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1538 | if (!bond_is_active_slave(slave)) { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1539 | if (new_value) |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1540 | slave->inactive = 0; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1541 | else |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1542 | slave->inactive = 1; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | out: |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1546 | rtnl_unlock(); |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1547 | return ret; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1548 | } |
| 1549 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
| 1550 | bonding_show_slaves_active, bonding_store_slaves_active); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1551 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1552 | /* |
| 1553 | * Show and set the number of IGMP membership reports to send on link failure |
| 1554 | */ |
| 1555 | static ssize_t bonding_show_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1556 | struct device_attribute *attr, |
| 1557 | char *buf) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1558 | { |
| 1559 | struct bonding *bond = to_bond(d); |
| 1560 | |
| 1561 | return sprintf(buf, "%d\n", bond->params.resend_igmp); |
| 1562 | } |
| 1563 | |
| 1564 | static ssize_t bonding_store_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1565 | struct device_attribute *attr, |
| 1566 | const char *buf, size_t count) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1567 | { |
| 1568 | int new_value, ret = count; |
| 1569 | struct bonding *bond = to_bond(d); |
| 1570 | |
| 1571 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1572 | pr_err("%s: no resend_igmp value specified.\n", |
| 1573 | bond->dev->name); |
| 1574 | ret = -EINVAL; |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1578 | if (new_value < 0 || new_value > 255) { |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1579 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
| 1580 | bond->dev->name, new_value); |
| 1581 | ret = -EINVAL; |
| 1582 | goto out; |
| 1583 | } |
| 1584 | |
| 1585 | pr_info("%s: Setting resend_igmp to %d.\n", |
| 1586 | bond->dev->name, new_value); |
| 1587 | bond->params.resend_igmp = new_value; |
| 1588 | out: |
| 1589 | return ret; |
| 1590 | } |
| 1591 | |
| 1592 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
| 1593 | bonding_show_resend_igmp, bonding_store_resend_igmp); |
| 1594 | |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1595 | |
| 1596 | static ssize_t bonding_show_lp_interval(struct device *d, |
| 1597 | struct device_attribute *attr, |
| 1598 | char *buf) |
| 1599 | { |
| 1600 | struct bonding *bond = to_bond(d); |
| 1601 | return sprintf(buf, "%d\n", bond->params.lp_interval); |
| 1602 | } |
| 1603 | |
| 1604 | static ssize_t bonding_store_lp_interval(struct device *d, |
| 1605 | struct device_attribute *attr, |
| 1606 | const char *buf, size_t count) |
| 1607 | { |
| 1608 | struct bonding *bond = to_bond(d); |
| 1609 | int new_value, ret = count; |
| 1610 | |
| 1611 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1612 | pr_err("%s: no lp interval value specified.\n", |
| 1613 | bond->dev->name); |
| 1614 | ret = -EINVAL; |
| 1615 | goto out; |
| 1616 | } |
| 1617 | |
| 1618 | if (new_value <= 0) { |
| 1619 | pr_err ("%s: lp_interval must be between 1 and %d\n", |
| 1620 | bond->dev->name, INT_MAX); |
| 1621 | ret = -EINVAL; |
| 1622 | goto out; |
| 1623 | } |
| 1624 | |
| 1625 | bond->params.lp_interval = new_value; |
| 1626 | out: |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, |
| 1631 | bonding_show_lp_interval, bonding_store_lp_interval); |
| 1632 | |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1633 | static ssize_t bonding_show_packets_per_slave(struct device *d, |
| 1634 | struct device_attribute *attr, |
| 1635 | char *buf) |
| 1636 | { |
| 1637 | struct bonding *bond = to_bond(d); |
Nikolay Aleksandrov | a752a8b | 2013-12-05 11:36:58 +0100 | [diff] [blame^] | 1638 | unsigned int packets_per_slave = bond->params.packets_per_slave; |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1639 | |
| 1640 | if (packets_per_slave > 1) |
| 1641 | packets_per_slave = reciprocal_value(packets_per_slave); |
| 1642 | |
Nikolay Aleksandrov | a752a8b | 2013-12-05 11:36:58 +0100 | [diff] [blame^] | 1643 | return sprintf(buf, "%u\n", packets_per_slave); |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | static ssize_t bonding_store_packets_per_slave(struct device *d, |
| 1647 | struct device_attribute *attr, |
| 1648 | const char *buf, size_t count) |
| 1649 | { |
| 1650 | struct bonding *bond = to_bond(d); |
| 1651 | int new_value, ret = count; |
| 1652 | |
| 1653 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1654 | pr_err("%s: no packets_per_slave value specified.\n", |
| 1655 | bond->dev->name); |
| 1656 | ret = -EINVAL; |
| 1657 | goto out; |
| 1658 | } |
| 1659 | if (new_value < 0 || new_value > USHRT_MAX) { |
| 1660 | pr_err("%s: packets_per_slave must be between 0 and %u\n", |
| 1661 | bond->dev->name, USHRT_MAX); |
| 1662 | ret = -EINVAL; |
| 1663 | goto out; |
| 1664 | } |
| 1665 | if (bond->params.mode != BOND_MODE_ROUNDROBIN) |
| 1666 | pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n", |
| 1667 | bond->dev->name); |
| 1668 | if (new_value > 1) |
| 1669 | bond->params.packets_per_slave = reciprocal_value(new_value); |
| 1670 | else |
| 1671 | bond->params.packets_per_slave = new_value; |
| 1672 | out: |
| 1673 | return ret; |
| 1674 | } |
| 1675 | |
| 1676 | static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR, |
| 1677 | bonding_show_packets_per_slave, |
| 1678 | bonding_store_packets_per_slave); |
| 1679 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1680 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1681 | &dev_attr_slaves.attr, |
| 1682 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1683 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1684 | &dev_attr_arp_validate.attr, |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 1685 | &dev_attr_arp_all_targets.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1686 | &dev_attr_arp_interval.attr, |
| 1687 | &dev_attr_arp_ip_target.attr, |
| 1688 | &dev_attr_downdelay.attr, |
| 1689 | &dev_attr_updelay.attr, |
| 1690 | &dev_attr_lacp_rate.attr, |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1691 | &dev_attr_ad_select.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1692 | &dev_attr_xmit_hash_policy.attr, |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1693 | &dev_attr_num_grat_arp.attr, |
| 1694 | &dev_attr_num_unsol_na.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1695 | &dev_attr_miimon.attr, |
| 1696 | &dev_attr_primary.attr, |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1697 | &dev_attr_primary_reselect.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1698 | &dev_attr_use_carrier.attr, |
| 1699 | &dev_attr_active_slave.attr, |
| 1700 | &dev_attr_mii_status.attr, |
| 1701 | &dev_attr_ad_aggregator.attr, |
| 1702 | &dev_attr_ad_num_ports.attr, |
| 1703 | &dev_attr_ad_actor_key.attr, |
| 1704 | &dev_attr_ad_partner_key.attr, |
| 1705 | &dev_attr_ad_partner_mac.attr, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1706 | &dev_attr_queue_id.attr, |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1707 | &dev_attr_all_slaves_active.attr, |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1708 | &dev_attr_resend_igmp.attr, |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 1709 | &dev_attr_min_links.attr, |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1710 | &dev_attr_lp_interval.attr, |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1711 | &dev_attr_packets_per_slave.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1712 | NULL, |
| 1713 | }; |
| 1714 | |
| 1715 | static struct attribute_group bonding_group = { |
| 1716 | .name = "bonding", |
| 1717 | .attrs = per_bond_attrs, |
| 1718 | }; |
| 1719 | |
| 1720 | /* |
| 1721 | * Initialize sysfs. This sets up the bonding_masters file in |
| 1722 | * /sys/class/net. |
| 1723 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1724 | int bond_create_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1725 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1726 | int ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1727 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1728 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
Eric W. Biederman | 01718e3 | 2011-10-21 22:43:07 +0000 | [diff] [blame] | 1729 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1730 | |
Tejun Heo | 58292cbe | 2013-09-11 22:29:04 -0400 | [diff] [blame] | 1731 | ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, |
| 1732 | bn->net); |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1733 | /* |
| 1734 | * Permit multiple loads of the module by ignoring failures to |
| 1735 | * create the bonding_masters sysfs file. Bonding devices |
| 1736 | * created by second or subsequent loads of the module will |
| 1737 | * not be listed in, or controllable by, bonding_masters, but |
| 1738 | * will have the usual "bonding" sysfs directory. |
| 1739 | * |
| 1740 | * This is done to preserve backwards compatibility for |
| 1741 | * initscripts/sysconfig, which load bonding multiple times to |
| 1742 | * configure multiple bonding devices. |
| 1743 | */ |
| 1744 | if (ret == -EEXIST) { |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1745 | /* Is someone being kinky and naming a device bonding_master? */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1746 | if (__dev_get_by_name(bn->net, |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1747 | class_attr_bonding_masters.attr.name)) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1748 | pr_err("network device named %s already exists in sysfs", |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1749 | class_attr_bonding_masters.attr.name); |
Stephen Hemminger | 130aa61 | 2009-06-11 05:46:04 -0700 | [diff] [blame] | 1750 | ret = 0; |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1751 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1752 | |
| 1753 | return ret; |
| 1754 | |
| 1755 | } |
| 1756 | |
| 1757 | /* |
| 1758 | * Remove /sys/class/net/bonding_masters. |
| 1759 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1760 | void bond_destroy_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1761 | { |
Tejun Heo | 58292cbe | 2013-09-11 22:29:04 -0400 | [diff] [blame] | 1762 | netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | /* |
| 1766 | * Initialize sysfs for each bond. This sets up and registers |
| 1767 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 1768 | */ |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1769 | void bond_prepare_sysfs_group(struct bonding *bond) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1770 | { |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1771 | bond->dev->sysfs_groups[0] = &bonding_group; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1772 | } |
| 1773 | |