aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bonding.h
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/bonding.h
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/bonding.h')
-rw-r--r--drivers/net/bonding/bonding.h71
1 files changed, 40 insertions, 31 deletions
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 42d1c6599cba..cfd9b493f5b0 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -71,6 +71,28 @@
71 set_fs(fs); \ 71 set_fs(fs); \
72 res; }) 72 res; })
73 73
74/* slave list primitives */
75#define bond_to_slave(ptr) list_entry(ptr, struct slave, list)
76
77/* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */
78#define bond_first_slave(bond) \
79 list_first_entry_or_null(&(bond)->slave_list, struct slave, list)
80#define bond_last_slave(bond) \
81 (list_empty(&(bond)->slave_list) ? NULL : \
82 bond_to_slave((bond)->slave_list.prev))
83
84#define bond_is_first_slave(bond, pos) ((pos)->list.prev == &(bond)->slave_list)
85#define bond_is_last_slave(bond, pos) ((pos)->list.next == &(bond)->slave_list)
86
87/* Since bond_first/last_slave can return NULL, these can return NULL too */
88#define bond_next_slave(bond, pos) \
89 (bond_is_last_slave(bond, pos) ? bond_first_slave(bond) : \
90 bond_to_slave((pos)->list.next))
91
92#define bond_prev_slave(bond, pos) \
93 (bond_is_first_slave(bond, pos) ? bond_last_slave(bond) : \
94 bond_to_slave((pos)->list.prev))
95
74/** 96/**
75 * bond_for_each_slave_from - iterate the slaves list from a starting point 97 * bond_for_each_slave_from - iterate the slaves list from a starting point
76 * @bond: the bond holding this list. 98 * @bond: the bond holding this list.
@@ -80,37 +102,29 @@
80 * 102 *
81 * Caller must hold bond->lock 103 * Caller must hold bond->lock
82 */ 104 */
83#define bond_for_each_slave_from(bond, pos, cnt, start) \ 105#define bond_for_each_slave_from(bond, pos, cnt, start) \
84 for (cnt = 0, pos = start; \ 106 for (cnt = 0, pos = start; pos && cnt < (bond)->slave_cnt; \
85 cnt < (bond)->slave_cnt; \ 107 cnt++, pos = bond_next_slave(bond, pos))
86 cnt++, pos = (pos)->next)
87 108
88/** 109/**
89 * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point 110 * bond_for_each_slave - iterate over all slaves
90 * @bond: the bond holding this list. 111 * @bond: the bond holding this list
91 * @pos: current slave. 112 * @pos: current slave
92 * @cnt: counter for number max of moves
93 * @start: start point.
94 * @stop: stop point.
95 * 113 *
96 * Caller must hold bond->lock 114 * Caller must hold bond->lock
97 */ 115 */
98#define bond_for_each_slave_from_to(bond, pos, cnt, start, stop) \ 116#define bond_for_each_slave(bond, pos) \
99 for (cnt = 0, pos = start; \ 117 list_for_each_entry(pos, &(bond)->slave_list, list)
100 ((cnt < (bond)->slave_cnt) && (pos != (stop)->next)); \
101 cnt++, pos = (pos)->next)
102 118
103/** 119/**
104 * bond_for_each_slave - iterate the slaves list from head 120 * bond_for_each_slave_reverse - iterate in reverse from a given position
105 * @bond: the bond holding this list. 121 * @bond: the bond holding this list
106 * @pos: current slave. 122 * @pos: slave to continue from
107 * @cnt: counter for max number of moves
108 * 123 *
109 * Caller must hold bond->lock 124 * Caller must hold bond->lock
110 */ 125 */
111#define bond_for_each_slave(bond, pos, cnt) \ 126#define bond_for_each_slave_continue_reverse(bond, pos) \
112 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave) 127 list_for_each_entry_continue_reverse(pos, &(bond)->slave_list, list)
113
114 128
115#ifdef CONFIG_NET_POLL_CONTROLLER 129#ifdef CONFIG_NET_POLL_CONTROLLER
116extern atomic_t netpoll_block_tx; 130extern atomic_t netpoll_block_tx;
@@ -174,8 +188,7 @@ struct vlan_entry {
174 188
175struct slave { 189struct slave {
176 struct net_device *dev; /* first - useful for panic debug */ 190 struct net_device *dev; /* first - useful for panic debug */
177 struct slave *next; 191 struct list_head list;
178 struct slave *prev;
179 struct bonding *bond; /* our master */ 192 struct bonding *bond; /* our master */
180 int delay; 193 int delay;
181 unsigned long jiffies; 194 unsigned long jiffies;
@@ -215,7 +228,7 @@ struct slave {
215 */ 228 */
216struct bonding { 229struct bonding {
217 struct net_device *dev; /* first - useful for panic debug */ 230 struct net_device *dev; /* first - useful for panic debug */
218 struct slave *first_slave; 231 struct list_head slave_list;
219 struct slave *curr_active_slave; 232 struct slave *curr_active_slave;
220 struct slave *current_arp_slave; 233 struct slave *current_arp_slave;
221 struct slave *primary_slave; 234 struct slave *primary_slave;
@@ -270,13 +283,10 @@ static inline struct slave *bond_get_slave_by_dev(struct bonding *bond,
270 struct net_device *slave_dev) 283 struct net_device *slave_dev)
271{ 284{
272 struct slave *slave = NULL; 285 struct slave *slave = NULL;
273 int i;
274 286
275 bond_for_each_slave(bond, slave, i) { 287 bond_for_each_slave(bond, slave)
276 if (slave->dev == slave_dev) { 288 if (slave->dev == slave_dev)
277 return slave; 289 return slave;
278 }
279 }
280 290
281 return NULL; 291 return NULL;
282} 292}
@@ -477,10 +487,9 @@ static inline void bond_destroy_proc_dir(struct bond_net *bn)
477static inline struct slave *bond_slave_has_mac(struct bonding *bond, 487static inline struct slave *bond_slave_has_mac(struct bonding *bond,
478 const u8 *mac) 488 const u8 *mac)
479{ 489{
480 int i = 0;
481 struct slave *tmp; 490 struct slave *tmp;
482 491
483 bond_for_each_slave(bond, tmp, i) 492 bond_for_each_slave(bond, tmp)
484 if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr)) 493 if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
485 return tmp; 494 return tmp;
486 495