diff options
author | Jiri Pirko <jpirko@redhat.com> | 2011-03-11 22:14:37 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-03-16 15:51:20 -0400 |
commit | e30bc066ab67a4c8abcb972227ffe7c576f06a86 (patch) | |
tree | 923689cd4ceade32c85d602a59b4e5feb320c300 /drivers/net/bonding | |
parent | 0bd80dad57d82676ee484fb1f9aa4c5e8b5bc469 (diff) |
bonding: wrap slave state work
transfers slave->state into slave->backup (that it's going to transfer
into bitfield. Introduce wrapper inlines to do the work with it.
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Reviewed-by: Nicolas de Pesloüan <nicolas.2p.debian@free.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding')
-rw-r--r-- | drivers/net/bonding/bond_3ad.c | 2 | ||||
-rw-r--r-- | drivers/net/bonding/bond_main.c | 36 | ||||
-rw-r--r-- | drivers/net/bonding/bond_sysfs.c | 2 | ||||
-rw-r--r-- | drivers/net/bonding/bonding.h | 31 |
4 files changed, 46 insertions, 25 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index a5d5d0b5b155..494bf960442d 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c | |||
@@ -246,7 +246,7 @@ static inline void __enable_port(struct port *port) | |||
246 | */ | 246 | */ |
247 | static inline int __port_is_enabled(struct port *port) | 247 | static inline int __port_is_enabled(struct port *port) |
248 | { | 248 | { |
249 | return port->slave->state == BOND_STATE_ACTIVE; | 249 | return bond_is_active_slave(port->slave); |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 00e9710caf7f..a3ea44997a2a 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
@@ -1863,7 +1863,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1863 | break; | 1863 | break; |
1864 | case BOND_MODE_TLB: | 1864 | case BOND_MODE_TLB: |
1865 | case BOND_MODE_ALB: | 1865 | case BOND_MODE_ALB: |
1866 | new_slave->state = BOND_STATE_ACTIVE; | 1866 | bond_set_active_slave(new_slave); |
1867 | bond_set_slave_inactive_flags(new_slave); | 1867 | bond_set_slave_inactive_flags(new_slave); |
1868 | bond_select_active_slave(bond); | 1868 | bond_select_active_slave(bond); |
1869 | break; | 1869 | break; |
@@ -1871,7 +1871,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1871 | pr_debug("This slave is always active in trunk mode\n"); | 1871 | pr_debug("This slave is always active in trunk mode\n"); |
1872 | 1872 | ||
1873 | /* always active in trunk mode */ | 1873 | /* always active in trunk mode */ |
1874 | new_slave->state = BOND_STATE_ACTIVE; | 1874 | bond_set_active_slave(new_slave); |
1875 | 1875 | ||
1876 | /* In trunking mode there is little meaning to curr_active_slave | 1876 | /* In trunking mode there is little meaning to curr_active_slave |
1877 | * anyway (it holds no special properties of the bond device), | 1877 | * anyway (it holds no special properties of the bond device), |
@@ -1909,7 +1909,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1909 | 1909 | ||
1910 | pr_info("%s: enslaving %s as a%s interface with a%s link.\n", | 1910 | pr_info("%s: enslaving %s as a%s interface with a%s link.\n", |
1911 | bond_dev->name, slave_dev->name, | 1911 | bond_dev->name, slave_dev->name, |
1912 | new_slave->state == BOND_STATE_ACTIVE ? "n active" : " backup", | 1912 | bond_is_active_slave(new_slave) ? "n active" : " backup", |
1913 | new_slave->link != BOND_LINK_DOWN ? "n up" : " down"); | 1913 | new_slave->link != BOND_LINK_DOWN ? "n up" : " down"); |
1914 | 1914 | ||
1915 | /* enslave is successful */ | 1915 | /* enslave is successful */ |
@@ -2007,7 +2007,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev) | |||
2007 | 2007 | ||
2008 | pr_info("%s: releasing %s interface %s\n", | 2008 | pr_info("%s: releasing %s interface %s\n", |
2009 | bond_dev->name, | 2009 | bond_dev->name, |
2010 | (slave->state == BOND_STATE_ACTIVE) ? "active" : "backup", | 2010 | bond_is_active_slave(slave) ? "active" : "backup", |
2011 | slave_dev->name); | 2011 | slave_dev->name); |
2012 | 2012 | ||
2013 | oldcurrent = bond->curr_active_slave; | 2013 | oldcurrent = bond->curr_active_slave; |
@@ -2348,7 +2348,7 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in | |||
2348 | res = 0; | 2348 | res = 0; |
2349 | strcpy(info->slave_name, slave->dev->name); | 2349 | strcpy(info->slave_name, slave->dev->name); |
2350 | info->link = slave->link; | 2350 | info->link = slave->link; |
2351 | info->state = slave->state; | 2351 | info->state = bond_slave_state(slave); |
2352 | info->link_failure_count = slave->link_failure_count; | 2352 | info->link_failure_count = slave->link_failure_count; |
2353 | break; | 2353 | break; |
2354 | } | 2354 | } |
@@ -2387,7 +2387,7 @@ static int bond_miimon_inspect(struct bonding *bond) | |||
2387 | bond->dev->name, | 2387 | bond->dev->name, |
2388 | (bond->params.mode == | 2388 | (bond->params.mode == |
2389 | BOND_MODE_ACTIVEBACKUP) ? | 2389 | BOND_MODE_ACTIVEBACKUP) ? |
2390 | ((slave->state == BOND_STATE_ACTIVE) ? | 2390 | (bond_is_active_slave(slave) ? |
2391 | "active " : "backup ") : "", | 2391 | "active " : "backup ") : "", |
2392 | slave->dev->name, | 2392 | slave->dev->name, |
2393 | bond->params.downdelay * bond->params.miimon); | 2393 | bond->params.downdelay * bond->params.miimon); |
@@ -2478,13 +2478,13 @@ static void bond_miimon_commit(struct bonding *bond) | |||
2478 | 2478 | ||
2479 | if (bond->params.mode == BOND_MODE_8023AD) { | 2479 | if (bond->params.mode == BOND_MODE_8023AD) { |
2480 | /* prevent it from being the active one */ | 2480 | /* prevent it from being the active one */ |
2481 | slave->state = BOND_STATE_BACKUP; | 2481 | bond_set_backup_slave(slave); |
2482 | } else if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { | 2482 | } else if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
2483 | /* make it immediately active */ | 2483 | /* make it immediately active */ |
2484 | slave->state = BOND_STATE_ACTIVE; | 2484 | bond_set_active_slave(slave); |
2485 | } else if (slave != bond->primary_slave) { | 2485 | } else if (slave != bond->primary_slave) { |
2486 | /* prevent it from being the active one */ | 2486 | /* prevent it from being the active one */ |
2487 | slave->state = BOND_STATE_BACKUP; | 2487 | bond_set_backup_slave(slave); |
2488 | } | 2488 | } |
2489 | 2489 | ||
2490 | bond_update_speed_duplex(slave); | 2490 | bond_update_speed_duplex(slave); |
@@ -2858,7 +2858,7 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack | |||
2858 | memcpy(&tip, arp_ptr, 4); | 2858 | memcpy(&tip, arp_ptr, 4); |
2859 | 2859 | ||
2860 | pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n", | 2860 | pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n", |
2861 | bond->dev->name, slave->dev->name, slave->state, | 2861 | bond->dev->name, slave->dev->name, bond_slave_state(slave), |
2862 | bond->params.arp_validate, slave_do_arp_validate(bond, slave), | 2862 | bond->params.arp_validate, slave_do_arp_validate(bond, slave), |
2863 | &sip, &tip); | 2863 | &sip, &tip); |
2864 | 2864 | ||
@@ -2870,7 +2870,7 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack | |||
2870 | * the active, through one switch, the router, then the other | 2870 | * the active, through one switch, the router, then the other |
2871 | * switch before reaching the backup. | 2871 | * switch before reaching the backup. |
2872 | */ | 2872 | */ |
2873 | if (slave->state == BOND_STATE_ACTIVE) | 2873 | if (bond_is_active_slave(slave)) |
2874 | bond_validate_arp(bond, slave, sip, tip); | 2874 | bond_validate_arp(bond, slave, sip, tip); |
2875 | else | 2875 | else |
2876 | bond_validate_arp(bond, slave, tip, sip); | 2876 | bond_validate_arp(bond, slave, tip, sip); |
@@ -2932,7 +2932,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work) | |||
2932 | slave->dev->last_rx + delta_in_ticks)) { | 2932 | slave->dev->last_rx + delta_in_ticks)) { |
2933 | 2933 | ||
2934 | slave->link = BOND_LINK_UP; | 2934 | slave->link = BOND_LINK_UP; |
2935 | slave->state = BOND_STATE_ACTIVE; | 2935 | bond_set_active_slave(slave); |
2936 | 2936 | ||
2937 | /* primary_slave has no meaning in round-robin | 2937 | /* primary_slave has no meaning in round-robin |
2938 | * mode. the window of a slave being up and | 2938 | * mode. the window of a slave being up and |
@@ -2965,7 +2965,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work) | |||
2965 | slave->dev->last_rx + 2 * delta_in_ticks)) { | 2965 | slave->dev->last_rx + 2 * delta_in_ticks)) { |
2966 | 2966 | ||
2967 | slave->link = BOND_LINK_DOWN; | 2967 | slave->link = BOND_LINK_DOWN; |
2968 | slave->state = BOND_STATE_BACKUP; | 2968 | bond_set_backup_slave(slave); |
2969 | 2969 | ||
2970 | if (slave->link_failure_count < UINT_MAX) | 2970 | if (slave->link_failure_count < UINT_MAX) |
2971 | slave->link_failure_count++; | 2971 | slave->link_failure_count++; |
@@ -3059,7 +3059,7 @@ static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) | |||
3059 | * gives each slave a chance to tx/rx traffic | 3059 | * gives each slave a chance to tx/rx traffic |
3060 | * before being taken out | 3060 | * before being taken out |
3061 | */ | 3061 | */ |
3062 | if (slave->state == BOND_STATE_BACKUP && | 3062 | if (!bond_is_active_slave(slave) && |
3063 | !bond->current_arp_slave && | 3063 | !bond->current_arp_slave && |
3064 | !time_in_range(jiffies, | 3064 | !time_in_range(jiffies, |
3065 | slave_last_rx(bond, slave) - delta_in_ticks, | 3065 | slave_last_rx(bond, slave) - delta_in_ticks, |
@@ -3076,7 +3076,7 @@ static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) | |||
3076 | * the bond has an IP address) | 3076 | * the bond has an IP address) |
3077 | */ | 3077 | */ |
3078 | trans_start = dev_trans_start(slave->dev); | 3078 | trans_start = dev_trans_start(slave->dev); |
3079 | if ((slave->state == BOND_STATE_ACTIVE) && | 3079 | if (bond_is_active_slave(slave) && |
3080 | (!time_in_range(jiffies, | 3080 | (!time_in_range(jiffies, |
3081 | trans_start - delta_in_ticks, | 3081 | trans_start - delta_in_ticks, |
3082 | trans_start + 2 * delta_in_ticks) || | 3082 | trans_start + 2 * delta_in_ticks) || |
@@ -4140,7 +4140,7 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev | |||
4140 | bond_for_each_slave_from(bond, slave, i, start_at) { | 4140 | bond_for_each_slave_from(bond, slave, i, start_at) { |
4141 | if (IS_UP(slave->dev) && | 4141 | if (IS_UP(slave->dev) && |
4142 | (slave->link == BOND_LINK_UP) && | 4142 | (slave->link == BOND_LINK_UP) && |
4143 | (slave->state == BOND_STATE_ACTIVE)) { | 4143 | bond_is_active_slave(slave)) { |
4144 | res = bond_dev_queue_xmit(bond, skb, slave->dev); | 4144 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
4145 | break; | 4145 | break; |
4146 | } | 4146 | } |
@@ -4217,7 +4217,7 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) | |||
4217 | bond_for_each_slave_from(bond, slave, i, start_at) { | 4217 | bond_for_each_slave_from(bond, slave, i, start_at) { |
4218 | if (IS_UP(slave->dev) && | 4218 | if (IS_UP(slave->dev) && |
4219 | (slave->link == BOND_LINK_UP) && | 4219 | (slave->link == BOND_LINK_UP) && |
4220 | (slave->state == BOND_STATE_ACTIVE)) { | 4220 | bond_is_active_slave(slave)) { |
4221 | res = bond_dev_queue_xmit(bond, skb, slave->dev); | 4221 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
4222 | break; | 4222 | break; |
4223 | } | 4223 | } |
@@ -4258,7 +4258,7 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev) | |||
4258 | bond_for_each_slave_from(bond, slave, i, start_at) { | 4258 | bond_for_each_slave_from(bond, slave, i, start_at) { |
4259 | if (IS_UP(slave->dev) && | 4259 | if (IS_UP(slave->dev) && |
4260 | (slave->link == BOND_LINK_UP) && | 4260 | (slave->link == BOND_LINK_UP) && |
4261 | (slave->state == BOND_STATE_ACTIVE)) { | 4261 | bond_is_active_slave(slave)) { |
4262 | if (tx_dev) { | 4262 | if (tx_dev) { |
4263 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | 4263 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
4264 | if (!skb2) { | 4264 | if (!skb2) { |
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 3a530eb9d104..c81b97cffaa3 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c | |||
@@ -1582,7 +1582,7 @@ static ssize_t bonding_store_slaves_active(struct device *d, | |||
1582 | } | 1582 | } |
1583 | 1583 | ||
1584 | bond_for_each_slave(bond, slave, i) { | 1584 | bond_for_each_slave(bond, slave, i) { |
1585 | if (slave->state == BOND_STATE_BACKUP) { | 1585 | if (!bond_is_active_slave(slave)) { |
1586 | if (new_value) | 1586 | if (new_value) |
1587 | slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE; | 1587 | slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE; |
1588 | else | 1588 | else |
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 049619f29144..63e9cf779389 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h | |||
@@ -55,7 +55,7 @@ | |||
55 | (((slave)->dev->flags & IFF_UP) && \ | 55 | (((slave)->dev->flags & IFF_UP) && \ |
56 | netif_running((slave)->dev) && \ | 56 | netif_running((slave)->dev) && \ |
57 | ((slave)->link == BOND_LINK_UP) && \ | 57 | ((slave)->link == BOND_LINK_UP) && \ |
58 | ((slave)->state == BOND_STATE_ACTIVE)) | 58 | bond_is_active_slave(slave)) |
59 | 59 | ||
60 | 60 | ||
61 | #define USES_PRIMARY(mode) \ | 61 | #define USES_PRIMARY(mode) \ |
@@ -192,7 +192,8 @@ struct slave { | |||
192 | unsigned long last_arp_rx; | 192 | unsigned long last_arp_rx; |
193 | s8 link; /* one of BOND_LINK_XXXX */ | 193 | s8 link; /* one of BOND_LINK_XXXX */ |
194 | s8 new_link; | 194 | s8 new_link; |
195 | s8 state; /* one of BOND_STATE_XXXX */ | 195 | u8 backup; /* indicates backup slave. Value corresponds with |
196 | BOND_STATE_ACTIVE and BOND_STATE_BACKUP */ | ||
196 | u32 original_mtu; | 197 | u32 original_mtu; |
197 | u32 link_failure_count; | 198 | u32 link_failure_count; |
198 | u8 perm_hwaddr[ETH_ALEN]; | 199 | u8 perm_hwaddr[ETH_ALEN]; |
@@ -304,6 +305,26 @@ static inline bool bond_is_lb(const struct bonding *bond) | |||
304 | bond->params.mode == BOND_MODE_ALB); | 305 | bond->params.mode == BOND_MODE_ALB); |
305 | } | 306 | } |
306 | 307 | ||
308 | static inline void bond_set_active_slave(struct slave *slave) | ||
309 | { | ||
310 | slave->backup = 0; | ||
311 | } | ||
312 | |||
313 | static inline void bond_set_backup_slave(struct slave *slave) | ||
314 | { | ||
315 | slave->backup = 1; | ||
316 | } | ||
317 | |||
318 | static inline int bond_slave_state(struct slave *slave) | ||
319 | { | ||
320 | return slave->backup; | ||
321 | } | ||
322 | |||
323 | static inline bool bond_is_active_slave(struct slave *slave) | ||
324 | { | ||
325 | return !bond_slave_state(slave); | ||
326 | } | ||
327 | |||
307 | #define BOND_PRI_RESELECT_ALWAYS 0 | 328 | #define BOND_PRI_RESELECT_ALWAYS 0 |
308 | #define BOND_PRI_RESELECT_BETTER 1 | 329 | #define BOND_PRI_RESELECT_BETTER 1 |
309 | #define BOND_PRI_RESELECT_FAILURE 2 | 330 | #define BOND_PRI_RESELECT_FAILURE 2 |
@@ -321,7 +342,7 @@ static inline bool bond_is_lb(const struct bonding *bond) | |||
321 | static inline int slave_do_arp_validate(struct bonding *bond, | 342 | static inline int slave_do_arp_validate(struct bonding *bond, |
322 | struct slave *slave) | 343 | struct slave *slave) |
323 | { | 344 | { |
324 | return bond->params.arp_validate & (1 << slave->state); | 345 | return bond->params.arp_validate & (1 << bond_slave_state(slave)); |
325 | } | 346 | } |
326 | 347 | ||
327 | static inline unsigned long slave_last_rx(struct bonding *bond, | 348 | static inline unsigned long slave_last_rx(struct bonding *bond, |
@@ -353,14 +374,14 @@ static inline void bond_set_slave_inactive_flags(struct slave *slave) | |||
353 | { | 374 | { |
354 | struct bonding *bond = netdev_priv(slave->dev->master); | 375 | struct bonding *bond = netdev_priv(slave->dev->master); |
355 | if (!bond_is_lb(bond)) | 376 | if (!bond_is_lb(bond)) |
356 | slave->state = BOND_STATE_BACKUP; | 377 | bond_set_backup_slave(slave); |
357 | if (!bond->params.all_slaves_active) | 378 | if (!bond->params.all_slaves_active) |
358 | slave->dev->priv_flags |= IFF_SLAVE_INACTIVE; | 379 | slave->dev->priv_flags |= IFF_SLAVE_INACTIVE; |
359 | } | 380 | } |
360 | 381 | ||
361 | static inline void bond_set_slave_active_flags(struct slave *slave) | 382 | static inline void bond_set_slave_active_flags(struct slave *slave) |
362 | { | 383 | { |
363 | slave->state = BOND_STATE_ACTIVE; | 384 | bond_set_active_slave(slave); |
364 | slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE; | 385 | slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE; |
365 | } | 386 | } |
366 | 387 | ||