Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright(c) 2004-2005 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | * The full GNU General Public License is included in this distribution in the |
| 20 | * file called LICENSE. |
| 21 | * |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 22 | */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 25 | #include <linux/device.h> |
| 26 | #include <linux/sysdev.h> |
| 27 | #include <linux/fs.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/string.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/inetdevice.h> |
| 32 | #include <linux/in.h> |
| 33 | #include <linux/sysfs.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 34 | #include <linux/ctype.h> |
| 35 | #include <linux/inet.h> |
| 36 | #include <linux/rtnetlink.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 37 | #include <net/net_namespace.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 38 | |
| 39 | /* #define BONDING_DEBUG 1 */ |
| 40 | #include "bonding.h" |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 41 | #define to_dev(obj) container_of(obj,struct device,kobj) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 42 | #define to_bond(cd) ((struct bonding *)(to_net_dev(cd)->priv)) |
| 43 | |
| 44 | /*---------------------------- Declarations -------------------------------*/ |
| 45 | |
| 46 | |
| 47 | extern struct list_head bond_dev_list; |
| 48 | extern struct bond_params bonding_defaults; |
| 49 | extern struct bond_parm_tbl bond_mode_tbl[]; |
| 50 | extern struct bond_parm_tbl bond_lacp_tbl[]; |
| 51 | extern struct bond_parm_tbl xmit_hashtype_tbl[]; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 52 | extern struct bond_parm_tbl arp_validate_tbl[]; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 53 | |
| 54 | static int expected_refcount = -1; |
| 55 | static struct class *netdev_class; |
| 56 | /*--------------------------- Data Structures -----------------------------*/ |
| 57 | |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 58 | /* Bonding sysfs lock. Why can't we just use the subsystem lock? |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 59 | * Because kobject_register tries to acquire the subsystem lock. If |
| 60 | * we already hold the lock (which we would if the user was creating |
| 61 | * a new bond through the sysfs interface), we deadlock. |
| 62 | * This lock is only needed when deleting a bond - we need to make sure |
| 63 | * that we don't collide with an ongoing ioctl. |
| 64 | */ |
| 65 | |
| 66 | struct rw_semaphore bonding_rwsem; |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | /*------------------------------ Functions --------------------------------*/ |
| 72 | |
| 73 | /* |
| 74 | * "show" function for the bond_masters attribute. |
| 75 | * The class parameter is ignored. |
| 76 | */ |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 77 | static ssize_t bonding_show_bonds(struct class *cls, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 78 | { |
| 79 | int res = 0; |
| 80 | struct bonding *bond; |
| 81 | |
| 82 | down_read(&(bonding_rwsem)); |
| 83 | |
| 84 | list_for_each_entry(bond, &bond_dev_list, bond_list) { |
| 85 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 86 | /* not enough space for another interface name */ |
| 87 | if ((PAGE_SIZE - res) > 10) |
| 88 | res = PAGE_SIZE - 10; |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 89 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 90 | break; |
| 91 | } |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 92 | res += sprintf(buf + res, "%s ", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 93 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame^] | 94 | if (res) |
| 95 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 96 | up_read(&(bonding_rwsem)); |
| 97 | return res; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * "store" function for the bond_masters attribute. This is what |
| 102 | * creates and deletes entire bonds. |
| 103 | * |
| 104 | * The class parameter is ignored. |
| 105 | * |
| 106 | */ |
| 107 | |
| 108 | static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t count) |
| 109 | { |
| 110 | char command[IFNAMSIZ + 1] = {0, }; |
| 111 | char *ifname; |
| 112 | int res = count; |
| 113 | struct bonding *bond; |
| 114 | struct bonding *nxt; |
| 115 | |
| 116 | down_write(&(bonding_rwsem)); |
| 117 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 118 | ifname = command + 1; |
| 119 | if ((strlen(command) <= 1) || |
| 120 | !dev_valid_name(ifname)) |
| 121 | goto err_no_cmd; |
| 122 | |
| 123 | if (command[0] == '+') { |
| 124 | |
| 125 | /* Check to see if the bond already exists. */ |
| 126 | list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) |
| 127 | if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) { |
| 128 | printk(KERN_ERR DRV_NAME |
| 129 | ": cannot add bond %s; it already exists\n", |
| 130 | ifname); |
| 131 | res = -EPERM; |
| 132 | goto out; |
| 133 | } |
| 134 | |
| 135 | printk(KERN_INFO DRV_NAME |
| 136 | ": %s is being created...\n", ifname); |
| 137 | if (bond_create(ifname, &bonding_defaults, &bond)) { |
| 138 | printk(KERN_INFO DRV_NAME |
| 139 | ": %s interface already exists. Bond creation failed.\n", |
| 140 | ifname); |
| 141 | res = -EPERM; |
| 142 | } |
| 143 | goto out; |
| 144 | } |
| 145 | |
| 146 | if (command[0] == '-') { |
| 147 | list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) |
| 148 | if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) { |
| 149 | rtnl_lock(); |
| 150 | /* check the ref count on the bond's kobject. |
| 151 | * If it's > expected, then there's a file open, |
| 152 | * and we have to fail. |
| 153 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 154 | if (atomic_read(&bond->dev->dev.kobj.kref.refcount) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 155 | > expected_refcount){ |
| 156 | rtnl_unlock(); |
| 157 | printk(KERN_INFO DRV_NAME |
| 158 | ": Unable remove bond %s due to open references.\n", |
| 159 | ifname); |
| 160 | res = -EPERM; |
| 161 | goto out; |
| 162 | } |
| 163 | printk(KERN_INFO DRV_NAME |
| 164 | ": %s is being deleted...\n", |
| 165 | bond->dev->name); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 166 | bond_destroy(bond); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 167 | rtnl_unlock(); |
| 168 | goto out; |
| 169 | } |
| 170 | |
| 171 | printk(KERN_ERR DRV_NAME |
| 172 | ": unable to delete non-existent bond %s\n", ifname); |
| 173 | res = -ENODEV; |
| 174 | goto out; |
| 175 | } |
| 176 | |
| 177 | err_no_cmd: |
| 178 | printk(KERN_ERR DRV_NAME |
| 179 | ": no command found in bonding_masters. Use +ifname or -ifname.\n"); |
| 180 | res = -EPERM; |
| 181 | |
| 182 | /* Always return either count or an error. If you return 0, you'll |
| 183 | * get called forever, which is bad. |
| 184 | */ |
| 185 | out: |
| 186 | up_write(&(bonding_rwsem)); |
| 187 | return res; |
| 188 | } |
| 189 | /* class attribute for bond_masters file. This ends up in /sys/class/net */ |
| 190 | static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO, |
| 191 | bonding_show_bonds, bonding_store_bonds); |
| 192 | |
| 193 | int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave) |
| 194 | { |
| 195 | char linkname[IFNAMSIZ+7]; |
| 196 | int ret = 0; |
| 197 | |
| 198 | /* first, create a link from the slave back to the master */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 199 | ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj), |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 200 | "master"); |
| 201 | if (ret) |
| 202 | return ret; |
| 203 | /* next, create a link from the master to the slave */ |
| 204 | sprintf(linkname,"slave_%s",slave->name); |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 205 | ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj), |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 206 | linkname); |
| 207 | return ret; |
| 208 | |
| 209 | } |
| 210 | |
| 211 | void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave) |
| 212 | { |
| 213 | char linkname[IFNAMSIZ+7]; |
| 214 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 215 | sysfs_remove_link(&(slave->dev.kobj), "master"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 216 | sprintf(linkname,"slave_%s",slave->name); |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 217 | sysfs_remove_link(&(master->dev.kobj), linkname); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | /* |
| 222 | * Show the slaves in the current bond. |
| 223 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 224 | static ssize_t bonding_show_slaves(struct device *d, |
| 225 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 226 | { |
| 227 | struct slave *slave; |
| 228 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 229 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 230 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 231 | read_lock(&bond->lock); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 232 | bond_for_each_slave(bond, slave, i) { |
| 233 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 234 | /* not enough space for another interface name */ |
| 235 | if ((PAGE_SIZE - res) > 10) |
| 236 | res = PAGE_SIZE - 10; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 237 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | res += sprintf(buf + res, "%s ", slave->dev->name); |
| 241 | } |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 242 | read_unlock(&bond->lock); |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame^] | 243 | if (res) |
| 244 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 245 | return res; |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Set the slaves in the current bond. The bond interface must be |
| 250 | * up for this to succeed. |
| 251 | * This function is largely the same flow as bonding_update_bonds(). |
| 252 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 253 | static ssize_t bonding_store_slaves(struct device *d, |
| 254 | struct device_attribute *attr, |
| 255 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 256 | { |
| 257 | char command[IFNAMSIZ + 1] = { 0, }; |
| 258 | char *ifname; |
| 259 | int i, res, found, ret = count; |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 260 | u32 original_mtu; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 261 | struct slave *slave; |
Luiz Fernando Capitulino | 3418db7 | 2006-02-01 00:54:34 -0800 | [diff] [blame] | 262 | struct net_device *dev = NULL; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 263 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 264 | |
| 265 | /* Quick sanity check -- is the bond interface up? */ |
| 266 | if (!(bond->dev->flags & IFF_UP)) { |
Moni Shoua | 6b1bf09 | 2007-10-09 19:43:40 -0700 | [diff] [blame] | 267 | printk(KERN_WARNING DRV_NAME |
| 268 | ": %s: doing slave updates when interface is down.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 269 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* Note: We can't hold bond->lock here, as bond_create grabs it. */ |
| 273 | |
| 274 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 275 | ifname = command + 1; |
| 276 | if ((strlen(command) <= 1) || |
| 277 | !dev_valid_name(ifname)) |
| 278 | goto err_no_cmd; |
| 279 | |
| 280 | if (command[0] == '+') { |
| 281 | |
| 282 | /* Got a slave name in ifname. Is it already in the list? */ |
| 283 | found = 0; |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 284 | read_lock(&bond->lock); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 285 | bond_for_each_slave(bond, slave, i) |
| 286 | if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 287 | printk(KERN_ERR DRV_NAME |
| 288 | ": %s: Interface %s is already enslaved!\n", |
| 289 | bond->dev->name, ifname); |
| 290 | ret = -EPERM; |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 291 | read_unlock(&bond->lock); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 292 | goto out; |
| 293 | } |
| 294 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 295 | read_unlock(&bond->lock); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 296 | printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n", |
| 297 | bond->dev->name, ifname); |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 298 | dev = dev_get_by_name(&init_net, ifname); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 299 | if (!dev) { |
| 300 | printk(KERN_INFO DRV_NAME |
| 301 | ": %s: Interface %s does not exist!\n", |
| 302 | bond->dev->name, ifname); |
| 303 | ret = -EPERM; |
| 304 | goto out; |
| 305 | } |
| 306 | else |
| 307 | dev_put(dev); |
| 308 | |
| 309 | if (dev->flags & IFF_UP) { |
| 310 | printk(KERN_ERR DRV_NAME |
| 311 | ": %s: Error: Unable to enslave %s " |
| 312 | "because it is already up.\n", |
| 313 | bond->dev->name, dev->name); |
| 314 | ret = -EPERM; |
| 315 | goto out; |
| 316 | } |
| 317 | /* If this is the first slave, then we need to set |
| 318 | the master's hardware address to be the same as the |
| 319 | slave's. */ |
| 320 | if (!(*((u32 *) & (bond->dev->dev_addr[0])))) { |
| 321 | memcpy(bond->dev->dev_addr, dev->dev_addr, |
| 322 | dev->addr_len); |
| 323 | } |
| 324 | |
| 325 | /* Set the slave's MTU to match the bond */ |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 326 | original_mtu = dev->mtu; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 327 | if (dev->mtu != bond->dev->mtu) { |
| 328 | if (dev->change_mtu) { |
| 329 | res = dev->change_mtu(dev, |
| 330 | bond->dev->mtu); |
| 331 | if (res) { |
| 332 | ret = res; |
| 333 | goto out; |
| 334 | } |
| 335 | } else { |
| 336 | dev->mtu = bond->dev->mtu; |
| 337 | } |
| 338 | } |
| 339 | rtnl_lock(); |
| 340 | res = bond_enslave(bond->dev, dev); |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 341 | bond_for_each_slave(bond, slave, i) |
| 342 | if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) |
| 343 | slave->original_mtu = original_mtu; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 344 | rtnl_unlock(); |
| 345 | if (res) { |
| 346 | ret = res; |
| 347 | } |
| 348 | goto out; |
| 349 | } |
| 350 | |
| 351 | if (command[0] == '-') { |
| 352 | dev = NULL; |
| 353 | bond_for_each_slave(bond, slave, i) |
| 354 | if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 355 | dev = slave->dev; |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 356 | original_mtu = slave->original_mtu; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 357 | break; |
| 358 | } |
| 359 | if (dev) { |
| 360 | printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n", |
| 361 | bond->dev->name, dev->name); |
| 362 | rtnl_lock(); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 363 | if (bond->setup_by_slave) |
| 364 | res = bond_release_and_destroy(bond->dev, dev); |
| 365 | else |
| 366 | res = bond_release(bond->dev, dev); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 367 | rtnl_unlock(); |
| 368 | if (res) { |
| 369 | ret = res; |
| 370 | goto out; |
| 371 | } |
| 372 | /* set the slave MTU to the default */ |
| 373 | if (dev->change_mtu) { |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 374 | dev->change_mtu(dev, original_mtu); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 375 | } else { |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 376 | dev->mtu = original_mtu; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | else { |
| 380 | printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n", |
| 381 | ifname, bond->dev->name); |
| 382 | ret = -ENODEV; |
| 383 | } |
| 384 | goto out; |
| 385 | } |
| 386 | |
| 387 | err_no_cmd: |
| 388 | printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name); |
| 389 | ret = -EPERM; |
| 390 | |
| 391 | out: |
| 392 | return ret; |
| 393 | } |
| 394 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 395 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 396 | |
| 397 | /* |
| 398 | * Show and set the bonding mode. The bond interface must be down to |
| 399 | * change the mode. |
| 400 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 401 | static ssize_t bonding_show_mode(struct device *d, |
| 402 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 403 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 404 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 405 | |
| 406 | return sprintf(buf, "%s %d\n", |
| 407 | bond_mode_tbl[bond->params.mode].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 408 | bond->params.mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 411 | static ssize_t bonding_store_mode(struct device *d, |
| 412 | struct device_attribute *attr, |
| 413 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 414 | { |
| 415 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 416 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 417 | |
| 418 | if (bond->dev->flags & IFF_UP) { |
| 419 | printk(KERN_ERR DRV_NAME |
| 420 | ": unable to update mode of %s because interface is up.\n", |
| 421 | bond->dev->name); |
| 422 | ret = -EPERM; |
| 423 | goto out; |
| 424 | } |
| 425 | |
| 426 | new_value = bond_parse_parm((char *)buf, bond_mode_tbl); |
| 427 | if (new_value < 0) { |
| 428 | printk(KERN_ERR DRV_NAME |
| 429 | ": %s: Ignoring invalid mode value %.*s.\n", |
| 430 | bond->dev->name, |
| 431 | (int)strlen(buf) - 1, buf); |
| 432 | ret = -EINVAL; |
| 433 | goto out; |
| 434 | } else { |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 435 | if (bond->params.mode == BOND_MODE_8023AD) |
| 436 | bond_unset_master_3ad_flags(bond); |
| 437 | |
| 438 | if (bond->params.mode == BOND_MODE_ALB) |
| 439 | bond_unset_master_alb_flags(bond); |
| 440 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 441 | bond->params.mode = new_value; |
| 442 | bond_set_mode_ops(bond, bond->params.mode); |
| 443 | printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n", |
| 444 | bond->dev->name, bond_mode_tbl[new_value].modename, new_value); |
| 445 | } |
| 446 | out: |
| 447 | return ret; |
| 448 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 449 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 450 | |
| 451 | /* |
| 452 | * Show and set the bonding transmit hash method. The bond interface must be down to |
| 453 | * change the xmit hash policy. |
| 454 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 455 | static ssize_t bonding_show_xmit_hash(struct device *d, |
| 456 | struct device_attribute *attr, |
| 457 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 458 | { |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 459 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 460 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 461 | |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 462 | if ((bond->params.mode == BOND_MODE_XOR) || |
| 463 | (bond->params.mode == BOND_MODE_8023AD)) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 464 | count = sprintf(buf, "%s %d\n", |
| 465 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 466 | bond->params.xmit_policy); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | return count; |
| 470 | } |
| 471 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 472 | static ssize_t bonding_store_xmit_hash(struct device *d, |
| 473 | struct device_attribute *attr, |
| 474 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 475 | { |
| 476 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 477 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 478 | |
| 479 | if (bond->dev->flags & IFF_UP) { |
| 480 | printk(KERN_ERR DRV_NAME |
| 481 | "%s: Interface is up. Unable to update xmit policy.\n", |
| 482 | bond->dev->name); |
| 483 | ret = -EPERM; |
| 484 | goto out; |
| 485 | } |
| 486 | |
| 487 | if ((bond->params.mode != BOND_MODE_XOR) && |
| 488 | (bond->params.mode != BOND_MODE_8023AD)) { |
| 489 | printk(KERN_ERR DRV_NAME |
| 490 | "%s: Transmit hash policy is irrelevant in this mode.\n", |
| 491 | bond->dev->name); |
| 492 | ret = -EPERM; |
| 493 | goto out; |
| 494 | } |
| 495 | |
| 496 | new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl); |
| 497 | if (new_value < 0) { |
| 498 | printk(KERN_ERR DRV_NAME |
| 499 | ": %s: Ignoring invalid xmit hash policy value %.*s.\n", |
| 500 | bond->dev->name, |
| 501 | (int)strlen(buf) - 1, buf); |
| 502 | ret = -EINVAL; |
| 503 | goto out; |
| 504 | } else { |
| 505 | bond->params.xmit_policy = new_value; |
| 506 | bond_set_mode_ops(bond, bond->params.mode); |
| 507 | printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n", |
| 508 | bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value); |
| 509 | } |
| 510 | out: |
| 511 | return ret; |
| 512 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 513 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 514 | |
| 515 | /* |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 516 | * Show and set arp_validate. |
| 517 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 518 | static ssize_t bonding_show_arp_validate(struct device *d, |
| 519 | struct device_attribute *attr, |
| 520 | char *buf) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 521 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 522 | struct bonding *bond = to_bond(d); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 523 | |
| 524 | return sprintf(buf, "%s %d\n", |
| 525 | arp_validate_tbl[bond->params.arp_validate].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 526 | bond->params.arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 529 | static ssize_t bonding_store_arp_validate(struct device *d, |
| 530 | struct device_attribute *attr, |
| 531 | const char *buf, size_t count) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 532 | { |
| 533 | int new_value; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 534 | struct bonding *bond = to_bond(d); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 535 | |
| 536 | new_value = bond_parse_parm((char *)buf, arp_validate_tbl); |
| 537 | if (new_value < 0) { |
| 538 | printk(KERN_ERR DRV_NAME |
| 539 | ": %s: Ignoring invalid arp_validate value %s\n", |
| 540 | bond->dev->name, buf); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) { |
| 544 | printk(KERN_ERR DRV_NAME |
| 545 | ": %s: arp_validate only supported in active-backup mode.\n", |
| 546 | bond->dev->name); |
| 547 | return -EINVAL; |
| 548 | } |
| 549 | printk(KERN_INFO DRV_NAME ": %s: setting arp_validate to %s (%d).\n", |
| 550 | bond->dev->name, arp_validate_tbl[new_value].modename, |
| 551 | new_value); |
| 552 | |
| 553 | if (!bond->params.arp_validate && new_value) { |
| 554 | bond_register_arp(bond); |
| 555 | } else if (bond->params.arp_validate && !new_value) { |
| 556 | bond_unregister_arp(bond); |
| 557 | } |
| 558 | |
| 559 | bond->params.arp_validate = new_value; |
| 560 | |
| 561 | return count; |
| 562 | } |
| 563 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 564 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, bonding_store_arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 565 | |
| 566 | /* |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 567 | * Show and store fail_over_mac. User only allowed to change the |
| 568 | * value when there are no slaves. |
| 569 | */ |
| 570 | static ssize_t bonding_show_fail_over_mac(struct device *d, struct device_attribute *attr, char *buf) |
| 571 | { |
| 572 | struct bonding *bond = to_bond(d); |
| 573 | |
| 574 | return sprintf(buf, "%d\n", bond->params.fail_over_mac) + 1; |
| 575 | } |
| 576 | |
| 577 | static ssize_t bonding_store_fail_over_mac(struct device *d, struct device_attribute *attr, const char *buf, size_t count) |
| 578 | { |
| 579 | int new_value; |
| 580 | int ret = count; |
| 581 | struct bonding *bond = to_bond(d); |
| 582 | |
| 583 | if (bond->slave_cnt != 0) { |
| 584 | printk(KERN_ERR DRV_NAME |
| 585 | ": %s: Can't alter fail_over_mac with slaves in bond.\n", |
| 586 | bond->dev->name); |
| 587 | ret = -EPERM; |
| 588 | goto out; |
| 589 | } |
| 590 | |
| 591 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 592 | printk(KERN_ERR DRV_NAME |
| 593 | ": %s: no fail_over_mac value specified.\n", |
| 594 | bond->dev->name); |
| 595 | ret = -EINVAL; |
| 596 | goto out; |
| 597 | } |
| 598 | |
| 599 | if ((new_value == 0) || (new_value == 1)) { |
| 600 | bond->params.fail_over_mac = new_value; |
| 601 | printk(KERN_INFO DRV_NAME ": %s: Setting fail_over_mac to %d.\n", |
| 602 | bond->dev->name, new_value); |
| 603 | } else { |
| 604 | printk(KERN_INFO DRV_NAME |
| 605 | ": %s: Ignoring invalid fail_over_mac value %d.\n", |
| 606 | bond->dev->name, new_value); |
| 607 | } |
| 608 | out: |
| 609 | return ret; |
| 610 | } |
| 611 | |
| 612 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, bonding_show_fail_over_mac, bonding_store_fail_over_mac); |
| 613 | |
| 614 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 615 | * Show and set the arp timer interval. There are two tricky bits |
| 616 | * here. First, if ARP monitoring is activated, then we must disable |
| 617 | * MII monitoring. Second, if the ARP timer isn't running, we must |
| 618 | * start it. |
| 619 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 620 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 621 | struct device_attribute *attr, |
| 622 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 623 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 624 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 625 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 626 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 629 | static ssize_t bonding_store_arp_interval(struct device *d, |
| 630 | struct device_attribute *attr, |
| 631 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 632 | { |
| 633 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 634 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 635 | |
| 636 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 637 | printk(KERN_ERR DRV_NAME |
| 638 | ": %s: no arp_interval value specified.\n", |
| 639 | bond->dev->name); |
| 640 | ret = -EINVAL; |
| 641 | goto out; |
| 642 | } |
| 643 | if (new_value < 0) { |
| 644 | printk(KERN_ERR DRV_NAME |
| 645 | ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n", |
| 646 | bond->dev->name, new_value, INT_MAX); |
| 647 | ret = -EINVAL; |
| 648 | goto out; |
| 649 | } |
| 650 | |
| 651 | printk(KERN_INFO DRV_NAME |
| 652 | ": %s: Setting ARP monitoring interval to %d.\n", |
| 653 | bond->dev->name, new_value); |
| 654 | bond->params.arp_interval = new_value; |
| 655 | if (bond->params.miimon) { |
| 656 | printk(KERN_INFO DRV_NAME |
| 657 | ": %s: ARP monitoring cannot be used with MII monitoring. " |
| 658 | "%s Disabling MII monitoring.\n", |
| 659 | bond->dev->name, bond->dev->name); |
| 660 | bond->params.miimon = 0; |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 661 | if (delayed_work_pending(&bond->mii_work)) { |
| 662 | cancel_delayed_work(&bond->mii_work); |
| 663 | flush_workqueue(bond->wq); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | if (!bond->params.arp_targets[0]) { |
| 667 | printk(KERN_INFO DRV_NAME |
| 668 | ": %s: ARP monitoring has been set up, " |
| 669 | "but no ARP targets have been specified.\n", |
| 670 | bond->dev->name); |
| 671 | } |
| 672 | if (bond->dev->flags & IFF_UP) { |
| 673 | /* If the interface is up, we may need to fire off |
| 674 | * the ARP timer. If the interface is down, the |
| 675 | * timer will get fired off when the open function |
| 676 | * is called. |
| 677 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 678 | if (!delayed_work_pending(&bond->arp_work)) { |
| 679 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) |
| 680 | INIT_DELAYED_WORK(&bond->arp_work, |
| 681 | bond_activebackup_arp_mon); |
| 682 | else |
| 683 | INIT_DELAYED_WORK(&bond->arp_work, |
| 684 | bond_loadbalance_arp_mon); |
| 685 | |
| 686 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
| 690 | out: |
| 691 | return ret; |
| 692 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 693 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 694 | |
| 695 | /* |
| 696 | * Show and set the arp targets. |
| 697 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 698 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 699 | struct device_attribute *attr, |
| 700 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 701 | { |
| 702 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 703 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 704 | |
| 705 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 706 | if (bond->params.arp_targets[i]) |
| 707 | res += sprintf(buf + res, "%u.%u.%u.%u ", |
| 708 | NIPQUAD(bond->params.arp_targets[i])); |
| 709 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame^] | 710 | if (res) |
| 711 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 712 | return res; |
| 713 | } |
| 714 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 715 | static ssize_t bonding_store_arp_targets(struct device *d, |
| 716 | struct device_attribute *attr, |
| 717 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 718 | { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 719 | __be32 newtarget; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 720 | int i = 0, done = 0, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 721 | struct bonding *bond = to_bond(d); |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 722 | __be32 *targets; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 723 | |
| 724 | targets = bond->params.arp_targets; |
| 725 | newtarget = in_aton(buf + 1); |
| 726 | /* look for adds */ |
| 727 | if (buf[0] == '+') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 728 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 729 | printk(KERN_ERR DRV_NAME |
| 730 | ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n", |
| 731 | bond->dev->name, NIPQUAD(newtarget)); |
| 732 | ret = -EINVAL; |
| 733 | goto out; |
| 734 | } |
| 735 | /* look for an empty slot to put the target in, and check for dupes */ |
| 736 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
| 737 | if (targets[i] == newtarget) { /* duplicate */ |
| 738 | printk(KERN_ERR DRV_NAME |
| 739 | ": %s: ARP target %u.%u.%u.%u is already present\n", |
| 740 | bond->dev->name, NIPQUAD(newtarget)); |
| 741 | if (done) |
| 742 | targets[i] = 0; |
| 743 | ret = -EINVAL; |
| 744 | goto out; |
| 745 | } |
| 746 | if (targets[i] == 0 && !done) { |
| 747 | printk(KERN_INFO DRV_NAME |
| 748 | ": %s: adding ARP target %d.%d.%d.%d.\n", |
| 749 | bond->dev->name, NIPQUAD(newtarget)); |
| 750 | done = 1; |
| 751 | targets[i] = newtarget; |
| 752 | } |
| 753 | } |
| 754 | if (!done) { |
| 755 | printk(KERN_ERR DRV_NAME |
| 756 | ": %s: ARP target table is full!\n", |
| 757 | bond->dev->name); |
| 758 | ret = -EINVAL; |
| 759 | goto out; |
| 760 | } |
| 761 | |
| 762 | } |
| 763 | else if (buf[0] == '-') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 764 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 765 | printk(KERN_ERR DRV_NAME |
| 766 | ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n", |
| 767 | bond->dev->name, NIPQUAD(newtarget)); |
| 768 | ret = -EINVAL; |
| 769 | goto out; |
| 770 | } |
| 771 | |
| 772 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
| 773 | if (targets[i] == newtarget) { |
| 774 | printk(KERN_INFO DRV_NAME |
| 775 | ": %s: removing ARP target %d.%d.%d.%d.\n", |
| 776 | bond->dev->name, NIPQUAD(newtarget)); |
| 777 | targets[i] = 0; |
| 778 | done = 1; |
| 779 | } |
| 780 | } |
| 781 | if (!done) { |
| 782 | printk(KERN_INFO DRV_NAME |
| 783 | ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n", |
| 784 | bond->dev->name, NIPQUAD(newtarget)); |
| 785 | ret = -EINVAL; |
| 786 | goto out; |
| 787 | } |
| 788 | } |
| 789 | else { |
| 790 | printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 791 | bond->dev->name); |
| 792 | ret = -EPERM; |
| 793 | goto out; |
| 794 | } |
| 795 | |
| 796 | out: |
| 797 | return ret; |
| 798 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 799 | 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] | 800 | |
| 801 | /* |
| 802 | * Show and set the up and down delays. These must be multiples of the |
| 803 | * MII monitoring value, and are stored internally as the multiplier. |
| 804 | * Thus, we must translate to MS for the real world. |
| 805 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 806 | static ssize_t bonding_show_downdelay(struct device *d, |
| 807 | struct device_attribute *attr, |
| 808 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 809 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 810 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 811 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 812 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 815 | static ssize_t bonding_store_downdelay(struct device *d, |
| 816 | struct device_attribute *attr, |
| 817 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 818 | { |
| 819 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 820 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 821 | |
| 822 | if (!(bond->params.miimon)) { |
| 823 | printk(KERN_ERR DRV_NAME |
| 824 | ": %s: Unable to set down delay as MII monitoring is disabled\n", |
| 825 | bond->dev->name); |
| 826 | ret = -EPERM; |
| 827 | goto out; |
| 828 | } |
| 829 | |
| 830 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 831 | printk(KERN_ERR DRV_NAME |
| 832 | ": %s: no down delay value specified.\n", |
| 833 | bond->dev->name); |
| 834 | ret = -EINVAL; |
| 835 | goto out; |
| 836 | } |
| 837 | if (new_value < 0) { |
| 838 | printk(KERN_ERR DRV_NAME |
| 839 | ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
| 840 | bond->dev->name, new_value, 1, INT_MAX); |
| 841 | ret = -EINVAL; |
| 842 | goto out; |
| 843 | } else { |
| 844 | if ((new_value % bond->params.miimon) != 0) { |
| 845 | printk(KERN_WARNING DRV_NAME |
| 846 | ": %s: Warning: down delay (%d) is not a multiple " |
| 847 | "of miimon (%d), delay rounded to %d ms\n", |
| 848 | bond->dev->name, new_value, bond->params.miimon, |
| 849 | (new_value / bond->params.miimon) * |
| 850 | bond->params.miimon); |
| 851 | } |
| 852 | bond->params.downdelay = new_value / bond->params.miimon; |
| 853 | printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n", |
| 854 | bond->dev->name, bond->params.downdelay * bond->params.miimon); |
| 855 | |
| 856 | } |
| 857 | |
| 858 | out: |
| 859 | return ret; |
| 860 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 861 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 862 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 863 | static ssize_t bonding_show_updelay(struct device *d, |
| 864 | struct device_attribute *attr, |
| 865 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 866 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 867 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 868 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 869 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 870 | |
| 871 | } |
| 872 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 873 | static ssize_t bonding_store_updelay(struct device *d, |
| 874 | struct device_attribute *attr, |
| 875 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 876 | { |
| 877 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 878 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 879 | |
| 880 | if (!(bond->params.miimon)) { |
| 881 | printk(KERN_ERR DRV_NAME |
| 882 | ": %s: Unable to set up delay as MII monitoring is disabled\n", |
| 883 | bond->dev->name); |
| 884 | ret = -EPERM; |
| 885 | goto out; |
| 886 | } |
| 887 | |
| 888 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 889 | printk(KERN_ERR DRV_NAME |
| 890 | ": %s: no up delay value specified.\n", |
| 891 | bond->dev->name); |
| 892 | ret = -EINVAL; |
| 893 | goto out; |
| 894 | } |
| 895 | if (new_value < 0) { |
| 896 | printk(KERN_ERR DRV_NAME |
| 897 | ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
| 898 | bond->dev->name, new_value, 1, INT_MAX); |
| 899 | ret = -EINVAL; |
| 900 | goto out; |
| 901 | } else { |
| 902 | if ((new_value % bond->params.miimon) != 0) { |
| 903 | printk(KERN_WARNING DRV_NAME |
| 904 | ": %s: Warning: up delay (%d) is not a multiple " |
| 905 | "of miimon (%d), updelay rounded to %d ms\n", |
| 906 | bond->dev->name, new_value, bond->params.miimon, |
| 907 | (new_value / bond->params.miimon) * |
| 908 | bond->params.miimon); |
| 909 | } |
| 910 | bond->params.updelay = new_value / bond->params.miimon; |
| 911 | printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n", |
| 912 | bond->dev->name, bond->params.updelay * bond->params.miimon); |
| 913 | |
| 914 | } |
| 915 | |
| 916 | out: |
| 917 | return ret; |
| 918 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 919 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 920 | |
| 921 | /* |
| 922 | * Show and set the LACP interval. Interface must be down, and the mode |
| 923 | * must be set to 802.3ad mode. |
| 924 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 925 | static ssize_t bonding_show_lacp(struct device *d, |
| 926 | struct device_attribute *attr, |
| 927 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 928 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 929 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 930 | |
| 931 | return sprintf(buf, "%s %d\n", |
| 932 | bond_lacp_tbl[bond->params.lacp_fast].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 933 | bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 934 | } |
| 935 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 936 | static ssize_t bonding_store_lacp(struct device *d, |
| 937 | struct device_attribute *attr, |
| 938 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 939 | { |
| 940 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 941 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 942 | |
| 943 | if (bond->dev->flags & IFF_UP) { |
| 944 | printk(KERN_ERR DRV_NAME |
| 945 | ": %s: Unable to update LACP rate because interface is up.\n", |
| 946 | bond->dev->name); |
| 947 | ret = -EPERM; |
| 948 | goto out; |
| 949 | } |
| 950 | |
| 951 | if (bond->params.mode != BOND_MODE_8023AD) { |
| 952 | printk(KERN_ERR DRV_NAME |
| 953 | ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
| 954 | bond->dev->name); |
| 955 | ret = -EPERM; |
| 956 | goto out; |
| 957 | } |
| 958 | |
| 959 | new_value = bond_parse_parm((char *)buf, bond_lacp_tbl); |
| 960 | |
| 961 | if ((new_value == 1) || (new_value == 0)) { |
| 962 | bond->params.lacp_fast = new_value; |
| 963 | printk(KERN_INFO DRV_NAME |
| 964 | ": %s: Setting LACP rate to %s (%d).\n", |
| 965 | bond->dev->name, bond_lacp_tbl[new_value].modename, new_value); |
| 966 | } else { |
| 967 | printk(KERN_ERR DRV_NAME |
| 968 | ": %s: Ignoring invalid LACP rate value %.*s.\n", |
| 969 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 970 | ret = -EINVAL; |
| 971 | } |
| 972 | out: |
| 973 | return ret; |
| 974 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 975 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 976 | |
| 977 | /* |
| 978 | * Show and set the MII monitor interval. There are two tricky bits |
| 979 | * here. First, if MII monitoring is activated, then we must disable |
| 980 | * ARP monitoring. Second, if the timer isn't running, we must |
| 981 | * start it. |
| 982 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 983 | static ssize_t bonding_show_miimon(struct device *d, |
| 984 | struct device_attribute *attr, |
| 985 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 986 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 987 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 988 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 989 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 990 | } |
| 991 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 992 | static ssize_t bonding_store_miimon(struct device *d, |
| 993 | struct device_attribute *attr, |
| 994 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 995 | { |
| 996 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 997 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 998 | |
| 999 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1000 | printk(KERN_ERR DRV_NAME |
| 1001 | ": %s: no miimon value specified.\n", |
| 1002 | bond->dev->name); |
| 1003 | ret = -EINVAL; |
| 1004 | goto out; |
| 1005 | } |
| 1006 | if (new_value < 0) { |
| 1007 | printk(KERN_ERR DRV_NAME |
| 1008 | ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n", |
| 1009 | bond->dev->name, new_value, 1, INT_MAX); |
| 1010 | ret = -EINVAL; |
| 1011 | goto out; |
| 1012 | } else { |
| 1013 | printk(KERN_INFO DRV_NAME |
| 1014 | ": %s: Setting MII monitoring interval to %d.\n", |
| 1015 | bond->dev->name, new_value); |
| 1016 | bond->params.miimon = new_value; |
| 1017 | if(bond->params.updelay) |
| 1018 | printk(KERN_INFO DRV_NAME |
| 1019 | ": %s: Note: Updating updelay (to %d) " |
| 1020 | "since it is a multiple of the miimon value.\n", |
| 1021 | bond->dev->name, |
| 1022 | bond->params.updelay * bond->params.miimon); |
| 1023 | if(bond->params.downdelay) |
| 1024 | printk(KERN_INFO DRV_NAME |
| 1025 | ": %s: Note: Updating downdelay (to %d) " |
| 1026 | "since it is a multiple of the miimon value.\n", |
| 1027 | bond->dev->name, |
| 1028 | bond->params.downdelay * bond->params.miimon); |
| 1029 | if (bond->params.arp_interval) { |
| 1030 | printk(KERN_INFO DRV_NAME |
| 1031 | ": %s: MII monitoring cannot be used with " |
| 1032 | "ARP monitoring. Disabling ARP monitoring...\n", |
| 1033 | bond->dev->name); |
| 1034 | bond->params.arp_interval = 0; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 1035 | if (bond->params.arp_validate) { |
| 1036 | bond_unregister_arp(bond); |
| 1037 | bond->params.arp_validate = |
| 1038 | BOND_ARP_VALIDATE_NONE; |
| 1039 | } |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 1040 | if (delayed_work_pending(&bond->arp_work)) { |
| 1041 | cancel_delayed_work(&bond->arp_work); |
| 1042 | flush_workqueue(bond->wq); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | if (bond->dev->flags & IFF_UP) { |
| 1047 | /* If the interface is up, we may need to fire off |
| 1048 | * the MII timer. If the interface is down, the |
| 1049 | * timer will get fired off when the open function |
| 1050 | * is called. |
| 1051 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 1052 | if (!delayed_work_pending(&bond->mii_work)) { |
| 1053 | INIT_DELAYED_WORK(&bond->mii_work, |
| 1054 | bond_mii_monitor); |
| 1055 | queue_delayed_work(bond->wq, |
| 1056 | &bond->mii_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | out: |
| 1061 | return ret; |
| 1062 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1063 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1064 | |
| 1065 | /* |
| 1066 | * Show and set the primary slave. The store function is much |
| 1067 | * simpler than bonding_store_slaves function because it only needs to |
| 1068 | * handle one interface name. |
| 1069 | * The bond must be a mode that supports a primary for this be |
| 1070 | * set. |
| 1071 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1072 | static ssize_t bonding_show_primary(struct device *d, |
| 1073 | struct device_attribute *attr, |
| 1074 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1075 | { |
| 1076 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1077 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1078 | |
| 1079 | if (bond->primary_slave) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1080 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1081 | |
| 1082 | return count; |
| 1083 | } |
| 1084 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1085 | static ssize_t bonding_store_primary(struct device *d, |
| 1086 | struct device_attribute *attr, |
| 1087 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1088 | { |
| 1089 | int i; |
| 1090 | struct slave *slave; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1091 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1092 | |
| 1093 | write_lock_bh(&bond->lock); |
| 1094 | if (!USES_PRIMARY(bond->params.mode)) { |
| 1095 | printk(KERN_INFO DRV_NAME |
| 1096 | ": %s: Unable to set primary slave; %s is in mode %d\n", |
| 1097 | bond->dev->name, bond->dev->name, bond->params.mode); |
| 1098 | } else { |
| 1099 | bond_for_each_slave(bond, slave, i) { |
| 1100 | if (strnicmp |
| 1101 | (slave->dev->name, buf, |
| 1102 | strlen(slave->dev->name)) == 0) { |
| 1103 | printk(KERN_INFO DRV_NAME |
| 1104 | ": %s: Setting %s as primary slave.\n", |
| 1105 | bond->dev->name, slave->dev->name); |
| 1106 | bond->primary_slave = slave; |
| 1107 | bond_select_active_slave(bond); |
| 1108 | goto out; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | /* if we got here, then we didn't match the name of any slave */ |
| 1113 | |
| 1114 | if (strlen(buf) == 0 || buf[0] == '\n') { |
| 1115 | printk(KERN_INFO DRV_NAME |
| 1116 | ": %s: Setting primary slave to None.\n", |
| 1117 | bond->dev->name); |
Luiz Fernando Capitulino | 3418db7 | 2006-02-01 00:54:34 -0800 | [diff] [blame] | 1118 | bond->primary_slave = NULL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1119 | bond_select_active_slave(bond); |
| 1120 | } else { |
| 1121 | printk(KERN_INFO DRV_NAME |
| 1122 | ": %s: Unable to set %.*s as primary slave as it is not a slave.\n", |
| 1123 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 1124 | } |
| 1125 | } |
| 1126 | out: |
| 1127 | write_unlock_bh(&bond->lock); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1128 | |
| 1129 | rtnl_unlock(); |
| 1130 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1131 | return count; |
| 1132 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1133 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1134 | |
| 1135 | /* |
| 1136 | * Show and set the use_carrier flag. |
| 1137 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1138 | static ssize_t bonding_show_carrier(struct device *d, |
| 1139 | struct device_attribute *attr, |
| 1140 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1141 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1142 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1143 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1144 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1147 | static ssize_t bonding_store_carrier(struct device *d, |
| 1148 | struct device_attribute *attr, |
| 1149 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1150 | { |
| 1151 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1152 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1153 | |
| 1154 | |
| 1155 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1156 | printk(KERN_ERR DRV_NAME |
| 1157 | ": %s: no use_carrier value specified.\n", |
| 1158 | bond->dev->name); |
| 1159 | ret = -EINVAL; |
| 1160 | goto out; |
| 1161 | } |
| 1162 | if ((new_value == 0) || (new_value == 1)) { |
| 1163 | bond->params.use_carrier = new_value; |
| 1164 | printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n", |
| 1165 | bond->dev->name, new_value); |
| 1166 | } else { |
| 1167 | printk(KERN_INFO DRV_NAME |
| 1168 | ": %s: Ignoring invalid use_carrier value %d.\n", |
| 1169 | bond->dev->name, new_value); |
| 1170 | } |
| 1171 | out: |
| 1172 | return count; |
| 1173 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1174 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1175 | |
| 1176 | |
| 1177 | /* |
| 1178 | * Show and set currently active_slave. |
| 1179 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1180 | static ssize_t bonding_show_active_slave(struct device *d, |
| 1181 | struct device_attribute *attr, |
| 1182 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1183 | { |
| 1184 | struct slave *curr; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1185 | struct bonding *bond = to_bond(d); |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 1186 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1187 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1188 | read_lock(&bond->curr_slave_lock); |
| 1189 | curr = bond->curr_active_slave; |
| 1190 | read_unlock(&bond->curr_slave_lock); |
| 1191 | |
| 1192 | if (USES_PRIMARY(bond->params.mode) && curr) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1193 | count = sprintf(buf, "%s\n", curr->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1194 | return count; |
| 1195 | } |
| 1196 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1197 | static ssize_t bonding_store_active_slave(struct device *d, |
| 1198 | struct device_attribute *attr, |
| 1199 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1200 | { |
| 1201 | int i; |
| 1202 | struct slave *slave; |
| 1203 | struct slave *old_active = NULL; |
| 1204 | struct slave *new_active = NULL; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1205 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1206 | |
Jay Vosburgh | 1466a21 | 2007-11-06 13:33:28 -0800 | [diff] [blame] | 1207 | rtnl_lock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1208 | write_lock_bh(&bond->lock); |
Jay Vosburgh | 1466a21 | 2007-11-06 13:33:28 -0800 | [diff] [blame] | 1209 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1210 | if (!USES_PRIMARY(bond->params.mode)) { |
| 1211 | printk(KERN_INFO DRV_NAME |
| 1212 | ": %s: Unable to change active slave; %s is in mode %d\n", |
| 1213 | bond->dev->name, bond->dev->name, bond->params.mode); |
| 1214 | } else { |
| 1215 | bond_for_each_slave(bond, slave, i) { |
| 1216 | if (strnicmp |
| 1217 | (slave->dev->name, buf, |
| 1218 | strlen(slave->dev->name)) == 0) { |
| 1219 | old_active = bond->curr_active_slave; |
| 1220 | new_active = slave; |
Jay Vosburgh | a50d8de | 2006-09-22 21:53:25 -0700 | [diff] [blame] | 1221 | if (new_active == old_active) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1222 | /* do nothing */ |
| 1223 | printk(KERN_INFO DRV_NAME |
| 1224 | ": %s: %s is already the current active slave.\n", |
| 1225 | bond->dev->name, slave->dev->name); |
| 1226 | goto out; |
| 1227 | } |
| 1228 | else { |
| 1229 | if ((new_active) && |
| 1230 | (old_active) && |
| 1231 | (new_active->link == BOND_LINK_UP) && |
| 1232 | IS_UP(new_active->dev)) { |
| 1233 | printk(KERN_INFO DRV_NAME |
| 1234 | ": %s: Setting %s as active slave.\n", |
| 1235 | bond->dev->name, slave->dev->name); |
| 1236 | bond_change_active_slave(bond, new_active); |
| 1237 | } |
| 1238 | else { |
| 1239 | printk(KERN_INFO DRV_NAME |
| 1240 | ": %s: Could not set %s as active slave; " |
| 1241 | "either %s is down or the link is down.\n", |
| 1242 | bond->dev->name, slave->dev->name, |
| 1243 | slave->dev->name); |
| 1244 | } |
| 1245 | goto out; |
| 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /* if we got here, then we didn't match the name of any slave */ |
| 1251 | |
| 1252 | if (strlen(buf) == 0 || buf[0] == '\n') { |
| 1253 | printk(KERN_INFO DRV_NAME |
| 1254 | ": %s: Setting active slave to None.\n", |
| 1255 | bond->dev->name); |
Luiz Fernando Capitulino | 3418db7 | 2006-02-01 00:54:34 -0800 | [diff] [blame] | 1256 | bond->primary_slave = NULL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1257 | bond_select_active_slave(bond); |
| 1258 | } else { |
| 1259 | printk(KERN_INFO DRV_NAME |
| 1260 | ": %s: Unable to set %.*s as active slave as it is not a slave.\n", |
| 1261 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 1262 | } |
| 1263 | } |
| 1264 | out: |
| 1265 | write_unlock_bh(&bond->lock); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1266 | rtnl_unlock(); |
| 1267 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1268 | return count; |
| 1269 | |
| 1270 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1271 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1272 | |
| 1273 | |
| 1274 | /* |
| 1275 | * Show link status of the bond interface. |
| 1276 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1277 | static ssize_t bonding_show_mii_status(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 | struct slave *curr; |
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 | read_lock(&bond->curr_slave_lock); |
| 1285 | curr = bond->curr_active_slave; |
| 1286 | read_unlock(&bond->curr_slave_lock); |
| 1287 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1288 | return sprintf(buf, "%s\n", (curr) ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1289 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1290 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1291 | |
| 1292 | |
| 1293 | /* |
| 1294 | * Show current 802.3ad aggregator ID. |
| 1295 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1296 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 1297 | struct device_attribute *attr, |
| 1298 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1299 | { |
| 1300 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1301 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1302 | |
| 1303 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1304 | struct ad_info ad_info; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1305 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1306 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1307 | |
| 1308 | return count; |
| 1309 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1310 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1311 | |
| 1312 | |
| 1313 | /* |
| 1314 | * Show number of active 802.3ad ports. |
| 1315 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1316 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 1317 | struct device_attribute *attr, |
| 1318 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1319 | { |
| 1320 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1321 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1322 | |
| 1323 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1324 | struct ad_info ad_info; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1325 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1326 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1327 | |
| 1328 | return count; |
| 1329 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1330 | 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] | 1331 | |
| 1332 | |
| 1333 | /* |
| 1334 | * Show current 802.3ad actor key. |
| 1335 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1336 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 1337 | struct device_attribute *attr, |
| 1338 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1339 | { |
| 1340 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1341 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1342 | |
| 1343 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1344 | struct ad_info ad_info; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1345 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1346 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1347 | |
| 1348 | return count; |
| 1349 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1350 | 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] | 1351 | |
| 1352 | |
| 1353 | /* |
| 1354 | * Show current 802.3ad partner key. |
| 1355 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1356 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 1357 | struct device_attribute *attr, |
| 1358 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1359 | { |
| 1360 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1361 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1362 | |
| 1363 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1364 | struct ad_info ad_info; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1365 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1366 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1367 | |
| 1368 | return count; |
| 1369 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1370 | 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] | 1371 | |
| 1372 | |
| 1373 | /* |
| 1374 | * Show current 802.3ad partner mac. |
| 1375 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1376 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 1377 | struct device_attribute *attr, |
| 1378 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1379 | { |
| 1380 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1381 | struct bonding *bond = to_bond(d); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1382 | DECLARE_MAC_BUF(mac); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1383 | |
| 1384 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1385 | struct ad_info ad_info; |
| 1386 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1387 | count = sprintf(buf,"%s\n", |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1388 | print_mac(mac, ad_info.partner_system)); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1389 | } |
| 1390 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1391 | |
| 1392 | return count; |
| 1393 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1394 | 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] | 1395 | |
| 1396 | |
| 1397 | |
| 1398 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1399 | &dev_attr_slaves.attr, |
| 1400 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1401 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1402 | &dev_attr_arp_validate.attr, |
| 1403 | &dev_attr_arp_interval.attr, |
| 1404 | &dev_attr_arp_ip_target.attr, |
| 1405 | &dev_attr_downdelay.attr, |
| 1406 | &dev_attr_updelay.attr, |
| 1407 | &dev_attr_lacp_rate.attr, |
| 1408 | &dev_attr_xmit_hash_policy.attr, |
| 1409 | &dev_attr_miimon.attr, |
| 1410 | &dev_attr_primary.attr, |
| 1411 | &dev_attr_use_carrier.attr, |
| 1412 | &dev_attr_active_slave.attr, |
| 1413 | &dev_attr_mii_status.attr, |
| 1414 | &dev_attr_ad_aggregator.attr, |
| 1415 | &dev_attr_ad_num_ports.attr, |
| 1416 | &dev_attr_ad_actor_key.attr, |
| 1417 | &dev_attr_ad_partner_key.attr, |
| 1418 | &dev_attr_ad_partner_mac.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1419 | NULL, |
| 1420 | }; |
| 1421 | |
| 1422 | static struct attribute_group bonding_group = { |
| 1423 | .name = "bonding", |
| 1424 | .attrs = per_bond_attrs, |
| 1425 | }; |
| 1426 | |
| 1427 | /* |
| 1428 | * Initialize sysfs. This sets up the bonding_masters file in |
| 1429 | * /sys/class/net. |
| 1430 | */ |
| 1431 | int bond_create_sysfs(void) |
| 1432 | { |
| 1433 | int ret = 0; |
| 1434 | struct bonding *firstbond; |
| 1435 | |
| 1436 | init_rwsem(&bonding_rwsem); |
| 1437 | |
| 1438 | /* get the netdev class pointer */ |
| 1439 | firstbond = container_of(bond_dev_list.next, struct bonding, bond_list); |
| 1440 | if (!firstbond) |
| 1441 | return -ENODEV; |
| 1442 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1443 | netdev_class = firstbond->dev->dev.class; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1444 | if (!netdev_class) |
| 1445 | return -ENODEV; |
| 1446 | |
| 1447 | ret = class_create_file(netdev_class, &class_attr_bonding_masters); |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1448 | /* |
| 1449 | * Permit multiple loads of the module by ignoring failures to |
| 1450 | * create the bonding_masters sysfs file. Bonding devices |
| 1451 | * created by second or subsequent loads of the module will |
| 1452 | * not be listed in, or controllable by, bonding_masters, but |
| 1453 | * will have the usual "bonding" sysfs directory. |
| 1454 | * |
| 1455 | * This is done to preserve backwards compatibility for |
| 1456 | * initscripts/sysconfig, which load bonding multiple times to |
| 1457 | * configure multiple bonding devices. |
| 1458 | */ |
| 1459 | if (ret == -EEXIST) { |
| 1460 | netdev_class = NULL; |
| 1461 | return 0; |
| 1462 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1463 | |
| 1464 | return ret; |
| 1465 | |
| 1466 | } |
| 1467 | |
| 1468 | /* |
| 1469 | * Remove /sys/class/net/bonding_masters. |
| 1470 | */ |
| 1471 | void bond_destroy_sysfs(void) |
| 1472 | { |
| 1473 | if (netdev_class) |
| 1474 | class_remove_file(netdev_class, &class_attr_bonding_masters); |
| 1475 | } |
| 1476 | |
| 1477 | /* |
| 1478 | * Initialize sysfs for each bond. This sets up and registers |
| 1479 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 1480 | */ |
| 1481 | int bond_create_sysfs_entry(struct bonding *bond) |
| 1482 | { |
| 1483 | struct net_device *dev = bond->dev; |
| 1484 | int err; |
| 1485 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1486 | err = sysfs_create_group(&(dev->dev.kobj), &bonding_group); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1487 | if (err) { |
| 1488 | printk(KERN_EMERG "eek! didn't create group!\n"); |
| 1489 | } |
| 1490 | |
| 1491 | if (expected_refcount < 1) |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1492 | expected_refcount = atomic_read(&bond->dev->dev.kobj.kref.refcount); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1493 | |
| 1494 | return err; |
| 1495 | } |
| 1496 | /* |
| 1497 | * Remove sysfs entries for each bond. |
| 1498 | */ |
| 1499 | void bond_destroy_sysfs_entry(struct bonding *bond) |
| 1500 | { |
| 1501 | struct net_device *dev = bond->dev; |
| 1502 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1503 | sysfs_remove_group(&(dev->dev.kobj), &bonding_group); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1504 | } |
| 1505 | |