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