diff options
author | Jiri Pirko <jpirko@redhat.com> | 2010-05-18 01:46:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-06-02 06:39:42 -0400 |
commit | f9f3545e1e5de3d3f5376ae6c522aedb1205f4e1 (patch) | |
tree | 190d929aa39cce0f969da6528d16c8aefb25cc0d /drivers/net/bonding/bond_sysfs.c | |
parent | 3dd90905e08655aa7754f08ebe8b1f44e2793074 (diff) |
bonding: make bonding_store_slaves simpler
This patch makes bonding_store_slaves function nicer and easier to understand.
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding/bond_sysfs.c')
-rw-r--r-- | drivers/net/bonding/bond_sysfs.c | 66 |
1 files changed, 25 insertions, 41 deletions
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 79114386e686..a4cbaf78ad1c 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c | |||
@@ -211,7 +211,8 @@ static ssize_t bonding_show_slaves(struct device *d, | |||
211 | /* | 211 | /* |
212 | * Set the slaves in the current bond. The bond interface must be | 212 | * Set the slaves in the current bond. The bond interface must be |
213 | * up for this to succeed. | 213 | * up for this to succeed. |
214 | * This function is largely the same flow as bonding_update_bonds(). | 214 | * This is supposed to be only thin wrapper for bond_enslave and bond_release. |
215 | * All hard work should be done there. | ||
215 | */ | 216 | */ |
216 | static ssize_t bonding_store_slaves(struct device *d, | 217 | static ssize_t bonding_store_slaves(struct device *d, |
217 | struct device_attribute *attr, | 218 | struct device_attribute *attr, |
@@ -219,9 +220,8 @@ static ssize_t bonding_store_slaves(struct device *d, | |||
219 | { | 220 | { |
220 | char command[IFNAMSIZ + 1] = { 0, }; | 221 | char command[IFNAMSIZ + 1] = { 0, }; |
221 | char *ifname; | 222 | char *ifname; |
222 | int i, res, ret = count; | 223 | int res, ret = count; |
223 | struct slave *slave; | 224 | struct net_device *dev; |
224 | struct net_device *dev = NULL; | ||
225 | struct bonding *bond = to_bond(d); | 225 | struct bonding *bond = to_bond(d); |
226 | 226 | ||
227 | /* Quick sanity check -- is the bond interface up? */ | 227 | /* Quick sanity check -- is the bond interface up? */ |
@@ -230,8 +230,6 @@ static ssize_t bonding_store_slaves(struct device *d, | |||
230 | bond->dev->name); | 230 | bond->dev->name); |
231 | } | 231 | } |
232 | 232 | ||
233 | /* Note: We can't hold bond->lock here, as bond_create grabs it. */ | ||
234 | |||
235 | if (!rtnl_trylock()) | 233 | if (!rtnl_trylock()) |
236 | return restart_syscall(); | 234 | return restart_syscall(); |
237 | 235 | ||
@@ -241,19 +239,17 @@ static ssize_t bonding_store_slaves(struct device *d, | |||
241 | !dev_valid_name(ifname)) | 239 | !dev_valid_name(ifname)) |
242 | goto err_no_cmd; | 240 | goto err_no_cmd; |
243 | 241 | ||
244 | if (command[0] == '+') { | 242 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
245 | 243 | if (!dev) { | |
246 | /* Got a slave name in ifname. */ | 244 | pr_info("%s: Interface %s does not exist!\n", |
247 | 245 | bond->dev->name, ifname); | |
248 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); | 246 | ret = -ENODEV; |
249 | if (!dev) { | 247 | goto out; |
250 | pr_info("%s: Interface %s does not exist!\n", | 248 | } |
251 | bond->dev->name, ifname); | ||
252 | ret = -ENODEV; | ||
253 | goto out; | ||
254 | } | ||
255 | 249 | ||
256 | pr_info("%s: Adding slave %s.\n", bond->dev->name, ifname); | 250 | switch (command[0]) { |
251 | case '+': | ||
252 | pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name); | ||
257 | 253 | ||
258 | /* If this is the first slave, then we need to set | 254 | /* If this is the first slave, then we need to set |
259 | the master's hardware address to be the same as the | 255 | the master's hardware address to be the same as the |
@@ -263,33 +259,21 @@ static ssize_t bonding_store_slaves(struct device *d, | |||
263 | dev->addr_len); | 259 | dev->addr_len); |
264 | 260 | ||
265 | res = bond_enslave(bond->dev, dev); | 261 | res = bond_enslave(bond->dev, dev); |
266 | if (res) | 262 | break; |
267 | ret = res; | ||
268 | 263 | ||
269 | goto out; | 264 | case '-': |
270 | } | 265 | pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name); |
266 | res = bond_release(bond->dev, dev); | ||
267 | break; | ||
271 | 268 | ||
272 | if (command[0] == '-') { | 269 | default: |
273 | dev = NULL; | 270 | goto err_no_cmd; |
274 | bond_for_each_slave(bond, slave, i) | ||
275 | if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | ||
276 | dev = slave->dev; | ||
277 | break; | ||
278 | } | ||
279 | if (dev) { | ||
280 | pr_info("%s: Removing slave %s\n", | ||
281 | bond->dev->name, dev->name); | ||
282 | res = bond_release(bond->dev, dev); | ||
283 | if (res) | ||
284 | ret = res; | ||
285 | } else { | ||
286 | pr_err("unable to remove non-existent slave %s for bond %s.\n", | ||
287 | ifname, bond->dev->name); | ||
288 | ret = -ENODEV; | ||
289 | } | ||
290 | goto out; | ||
291 | } | 271 | } |
292 | 272 | ||
273 | if (res) | ||
274 | ret = res; | ||
275 | goto out; | ||
276 | |||
293 | err_no_cmd: | 277 | err_no_cmd: |
294 | pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n", | 278 | pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n", |
295 | bond->dev->name); | 279 | bond->dev->name); |