aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_3ad.c
diff options
context:
space:
mode:
authornikolay@redhat.com <nikolay@redhat.com>2013-08-01 10:54:47 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-01 19:42:01 -0400
commitdec1e90e8c7157a527faad95023d96dbc114fbac (patch)
treee25bbe042e4f2e525c08bac512e22bb43c619b0b /drivers/net/bonding/bond_3ad.c
parent439677d766ba9095e5afc4a30147f65bc363b6e7 (diff)
bonding: convert to list API and replace bond's custom list
This patch aims to remove struct bonding's first_slave and struct slave's next and prev pointers, and replace them with the standard Linux list API. The old macros are converted to list API as well and some new primitives are available now. The checks if there're slaves that used slave_cnt have been replaced by the list_empty macro. Also a few small style fixes, changing longest -> shortest line in local variable declarations, leaving an empty line before return and removing unnecessary brackets. This is the first step to gradual RCU conversion. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding/bond_3ad.c')
-rw-r--r--drivers/net/bonding/bond_3ad.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 390061d09693..7d46fa832c1f 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -143,10 +143,9 @@ static inline struct bonding *__get_bond_by_port(struct port *port)
143 */ 143 */
144static inline struct port *__get_first_port(struct bonding *bond) 144static inline struct port *__get_first_port(struct bonding *bond)
145{ 145{
146 if (bond->slave_cnt == 0) 146 struct slave *first_slave = bond_first_slave(bond);
147 return NULL;
148 147
149 return &(SLAVE_AD_INFO(bond->first_slave).port); 148 return first_slave ? &(SLAVE_AD_INFO(first_slave).port) : NULL;
150} 149}
151 150
152/** 151/**
@@ -159,13 +158,16 @@ static inline struct port *__get_first_port(struct bonding *bond)
159static inline struct port *__get_next_port(struct port *port) 158static inline struct port *__get_next_port(struct port *port)
160{ 159{
161 struct bonding *bond = __get_bond_by_port(port); 160 struct bonding *bond = __get_bond_by_port(port);
162 struct slave *slave = port->slave; 161 struct slave *slave = port->slave, *slave_next;
163 162
164 // If there's no bond for this port, or this is the last slave 163 // If there's no bond for this port, or this is the last slave
165 if ((bond == NULL) || (slave->next == bond->first_slave)) 164 if (bond == NULL)
165 return NULL;
166 slave_next = bond_next_slave(bond, slave);
167 if (!slave_next || bond_is_first_slave(bond, slave_next))
166 return NULL; 168 return NULL;
167 169
168 return &(SLAVE_AD_INFO(slave->next).port); 170 return &(SLAVE_AD_INFO(slave_next).port);
169} 171}
170 172
171/** 173/**
@@ -178,12 +180,14 @@ static inline struct port *__get_next_port(struct port *port)
178static inline struct aggregator *__get_first_agg(struct port *port) 180static inline struct aggregator *__get_first_agg(struct port *port)
179{ 181{
180 struct bonding *bond = __get_bond_by_port(port); 182 struct bonding *bond = __get_bond_by_port(port);
183 struct slave *first_slave;
181 184
182 // If there's no bond for this port, or bond has no slaves 185 // If there's no bond for this port, or bond has no slaves
183 if ((bond == NULL) || (bond->slave_cnt == 0)) 186 if (bond == NULL)
184 return NULL; 187 return NULL;
188 first_slave = bond_first_slave(bond);
185 189
186 return &(SLAVE_AD_INFO(bond->first_slave).aggregator); 190 return first_slave ? &(SLAVE_AD_INFO(first_slave).aggregator) : NULL;
187} 191}
188 192
189/** 193/**
@@ -195,14 +199,17 @@ static inline struct aggregator *__get_first_agg(struct port *port)
195 */ 199 */
196static inline struct aggregator *__get_next_agg(struct aggregator *aggregator) 200static inline struct aggregator *__get_next_agg(struct aggregator *aggregator)
197{ 201{
198 struct slave *slave = aggregator->slave; 202 struct slave *slave = aggregator->slave, *slave_next;
199 struct bonding *bond = bond_get_bond_by_slave(slave); 203 struct bonding *bond = bond_get_bond_by_slave(slave);
200 204
201 // If there's no bond for this aggregator, or this is the last slave 205 // If there's no bond for this aggregator, or this is the last slave
202 if ((bond == NULL) || (slave->next == bond->first_slave)) 206 if (bond == NULL)
207 return NULL;
208 slave_next = bond_next_slave(bond, slave);
209 if (!slave_next || bond_is_first_slave(bond, slave_next))
203 return NULL; 210 return NULL;
204 211
205 return &(SLAVE_AD_INFO(slave->next).aggregator); 212 return &(SLAVE_AD_INFO(slave_next).aggregator);
206} 213}
207 214
208/* 215/*
@@ -2110,7 +2117,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2110 read_lock(&bond->lock); 2117 read_lock(&bond->lock);
2111 2118
2112 //check if there are any slaves 2119 //check if there are any slaves
2113 if (bond->slave_cnt == 0) 2120 if (list_empty(&bond->slave_list))
2114 goto re_arm; 2121 goto re_arm;
2115 2122
2116 // check if agg_select_timer timer after initialize is timed out 2123 // check if agg_select_timer timer after initialize is timed out
@@ -2336,8 +2343,12 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
2336int bond_3ad_set_carrier(struct bonding *bond) 2343int bond_3ad_set_carrier(struct bonding *bond)
2337{ 2344{
2338 struct aggregator *active; 2345 struct aggregator *active;
2346 struct slave *first_slave;
2339 2347
2340 active = __get_active_agg(&(SLAVE_AD_INFO(bond->first_slave).aggregator)); 2348 first_slave = bond_first_slave(bond);
2349 if (!first_slave)
2350 return 0;
2351 active = __get_active_agg(&(SLAVE_AD_INFO(first_slave).aggregator));
2341 if (active) { 2352 if (active) {
2342 /* are enough slaves available to consider link up? */ 2353 /* are enough slaves available to consider link up? */
2343 if (active->num_of_ports < bond->params.min_links) { 2354 if (active->num_of_ports < bond->params.min_links) {
@@ -2432,7 +2443,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2432 2443
2433 slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg); 2444 slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg);
2434 2445
2435 bond_for_each_slave(bond, slave, i) { 2446 bond_for_each_slave(bond, slave) {
2436 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; 2447 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
2437 2448
2438 if (agg && (agg->aggregator_identifier == agg_id)) { 2449 if (agg && (agg->aggregator_identifier == agg_id)) {
@@ -2501,7 +2512,6 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
2501 */ 2512 */
2502void bond_3ad_update_lacp_rate(struct bonding *bond) 2513void bond_3ad_update_lacp_rate(struct bonding *bond)
2503{ 2514{
2504 int i;
2505 struct slave *slave; 2515 struct slave *slave;
2506 struct port *port = NULL; 2516 struct port *port = NULL;
2507 int lacp_fast; 2517 int lacp_fast;
@@ -2509,7 +2519,7 @@ void bond_3ad_update_lacp_rate(struct bonding *bond)
2509 write_lock_bh(&bond->lock); 2519 write_lock_bh(&bond->lock);
2510 lacp_fast = bond->params.lacp_fast; 2520 lacp_fast = bond->params.lacp_fast;
2511 2521
2512 bond_for_each_slave(bond, slave, i) { 2522 bond_for_each_slave(bond, slave) {
2513 port = &(SLAVE_AD_INFO(slave).port); 2523 port = &(SLAVE_AD_INFO(slave).port);
2514 if (port->slave == NULL) 2524 if (port->slave == NULL)
2515 continue; 2525 continue;