diff options
author | Rémi Denis-Courmont <remi.denis-courmont@nokia.com> | 2009-11-18 13:08:26 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-11-18 13:08:26 -0500 |
commit | eeb74a9d45f781ec6f47b9e0a75a6a427b53f165 (patch) | |
tree | e996e55e190f6003e33b4fbe41600ff8528a100b /net/phonet | |
parent | d90310243fd750240755e217c5faa13e24f41536 (diff) |
Phonet: convert devices list to RCU
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/phonet')
-rw-r--r-- | net/phonet/pn_dev.c | 63 | ||||
-rw-r--r-- | net/phonet/pn_netlink.c | 6 |
2 files changed, 44 insertions, 25 deletions
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c index d5ad7947d771..d87388c94b00 100644 --- a/net/phonet/pn_dev.c +++ b/net/phonet/pn_dev.c | |||
@@ -61,7 +61,8 @@ static struct phonet_device *__phonet_device_alloc(struct net_device *dev) | |||
61 | pnd->netdev = dev; | 61 | pnd->netdev = dev; |
62 | bitmap_zero(pnd->addrs, 64); | 62 | bitmap_zero(pnd->addrs, 64); |
63 | 63 | ||
64 | list_add(&pnd->list, &pndevs->list); | 64 | BUG_ON(!mutex_is_locked(&pndevs->lock)); |
65 | list_add_rcu(&pnd->list, &pndevs->list); | ||
65 | return pnd; | 66 | return pnd; |
66 | } | 67 | } |
67 | 68 | ||
@@ -70,6 +71,7 @@ static struct phonet_device *__phonet_get(struct net_device *dev) | |||
70 | struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); | 71 | struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); |
71 | struct phonet_device *pnd; | 72 | struct phonet_device *pnd; |
72 | 73 | ||
74 | BUG_ON(!mutex_is_locked(&pndevs->lock)); | ||
73 | list_for_each_entry(pnd, &pndevs->list, list) { | 75 | list_for_each_entry(pnd, &pndevs->list, list) { |
74 | if (pnd->netdev == dev) | 76 | if (pnd->netdev == dev) |
75 | return pnd; | 77 | return pnd; |
@@ -77,6 +79,18 @@ static struct phonet_device *__phonet_get(struct net_device *dev) | |||
77 | return NULL; | 79 | return NULL; |
78 | } | 80 | } |
79 | 81 | ||
82 | static struct phonet_device *__phonet_get_rcu(struct net_device *dev) | ||
83 | { | ||
84 | struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); | ||
85 | struct phonet_device *pnd; | ||
86 | |||
87 | list_for_each_entry_rcu(pnd, &pndevs->list, list) { | ||
88 | if (pnd->netdev == dev) | ||
89 | return pnd; | ||
90 | } | ||
91 | return NULL; | ||
92 | } | ||
93 | |||
80 | static void phonet_device_destroy(struct net_device *dev) | 94 | static void phonet_device_destroy(struct net_device *dev) |
81 | { | 95 | { |
82 | struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); | 96 | struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); |
@@ -84,11 +98,11 @@ static void phonet_device_destroy(struct net_device *dev) | |||
84 | 98 | ||
85 | ASSERT_RTNL(); | 99 | ASSERT_RTNL(); |
86 | 100 | ||
87 | spin_lock_bh(&pndevs->lock); | 101 | mutex_lock(&pndevs->lock); |
88 | pnd = __phonet_get(dev); | 102 | pnd = __phonet_get(dev); |
89 | if (pnd) | 103 | if (pnd) |
90 | list_del(&pnd->list); | 104 | list_del_rcu(&pnd->list); |
91 | spin_unlock_bh(&pndevs->lock); | 105 | mutex_unlock(&pndevs->lock); |
92 | 106 | ||
93 | if (pnd) { | 107 | if (pnd) { |
94 | u8 addr; | 108 | u8 addr; |
@@ -106,8 +120,8 @@ struct net_device *phonet_device_get(struct net *net) | |||
106 | struct phonet_device *pnd; | 120 | struct phonet_device *pnd; |
107 | struct net_device *dev = NULL; | 121 | struct net_device *dev = NULL; |
108 | 122 | ||
109 | spin_lock_bh(&pndevs->lock); | 123 | rcu_read_lock(); |
110 | list_for_each_entry(pnd, &pndevs->list, list) { | 124 | list_for_each_entry_rcu(pnd, &pndevs->list, list) { |
111 | dev = pnd->netdev; | 125 | dev = pnd->netdev; |
112 | BUG_ON(!dev); | 126 | BUG_ON(!dev); |
113 | 127 | ||
@@ -118,7 +132,7 @@ struct net_device *phonet_device_get(struct net *net) | |||
118 | } | 132 | } |
119 | if (dev) | 133 | if (dev) |
120 | dev_hold(dev); | 134 | dev_hold(dev); |
121 | spin_unlock_bh(&pndevs->lock); | 135 | rcu_read_unlock(); |
122 | return dev; | 136 | return dev; |
123 | } | 137 | } |
124 | 138 | ||
@@ -128,7 +142,7 @@ int phonet_address_add(struct net_device *dev, u8 addr) | |||
128 | struct phonet_device *pnd; | 142 | struct phonet_device *pnd; |
129 | int err = 0; | 143 | int err = 0; |
130 | 144 | ||
131 | spin_lock_bh(&pndevs->lock); | 145 | mutex_lock(&pndevs->lock); |
132 | /* Find or create Phonet-specific device data */ | 146 | /* Find or create Phonet-specific device data */ |
133 | pnd = __phonet_get(dev); | 147 | pnd = __phonet_get(dev); |
134 | if (pnd == NULL) | 148 | if (pnd == NULL) |
@@ -137,7 +151,7 @@ int phonet_address_add(struct net_device *dev, u8 addr) | |||
137 | err = -ENOMEM; | 151 | err = -ENOMEM; |
138 | else if (test_and_set_bit(addr >> 2, pnd->addrs)) | 152 | else if (test_and_set_bit(addr >> 2, pnd->addrs)) |
139 | err = -EEXIST; | 153 | err = -EEXIST; |
140 | spin_unlock_bh(&pndevs->lock); | 154 | mutex_unlock(&pndevs->lock); |
141 | return err; | 155 | return err; |
142 | } | 156 | } |
143 | 157 | ||
@@ -147,27 +161,32 @@ int phonet_address_del(struct net_device *dev, u8 addr) | |||
147 | struct phonet_device *pnd; | 161 | struct phonet_device *pnd; |
148 | int err = 0; | 162 | int err = 0; |
149 | 163 | ||
150 | spin_lock_bh(&pndevs->lock); | 164 | mutex_lock(&pndevs->lock); |
151 | pnd = __phonet_get(dev); | 165 | pnd = __phonet_get(dev); |
152 | if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs)) | 166 | if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs)) { |
153 | err = -EADDRNOTAVAIL; | 167 | err = -EADDRNOTAVAIL; |
154 | else if (bitmap_empty(pnd->addrs, 64)) { | 168 | pnd = NULL; |
155 | list_del(&pnd->list); | 169 | } else if (bitmap_empty(pnd->addrs, 64)) |
170 | list_del_rcu(&pnd->list); | ||
171 | else | ||
172 | pnd = NULL; | ||
173 | mutex_unlock(&pndevs->lock); | ||
174 | |||
175 | if (pnd) { | ||
176 | synchronize_rcu(); | ||
156 | kfree(pnd); | 177 | kfree(pnd); |
157 | } | 178 | } |
158 | spin_unlock_bh(&pndevs->lock); | ||
159 | return err; | 179 | return err; |
160 | } | 180 | } |
161 | 181 | ||
162 | /* Gets a source address toward a destination, through a interface. */ | 182 | /* Gets a source address toward a destination, through a interface. */ |
163 | u8 phonet_address_get(struct net_device *dev, u8 daddr) | 183 | u8 phonet_address_get(struct net_device *dev, u8 daddr) |
164 | { | 184 | { |
165 | struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); | ||
166 | struct phonet_device *pnd; | 185 | struct phonet_device *pnd; |
167 | u8 saddr; | 186 | u8 saddr; |
168 | 187 | ||
169 | spin_lock_bh(&pndevs->lock); | 188 | rcu_read_lock(); |
170 | pnd = __phonet_get(dev); | 189 | pnd = __phonet_get_rcu(dev); |
171 | if (pnd) { | 190 | if (pnd) { |
172 | BUG_ON(bitmap_empty(pnd->addrs, 64)); | 191 | BUG_ON(bitmap_empty(pnd->addrs, 64)); |
173 | 192 | ||
@@ -178,7 +197,7 @@ u8 phonet_address_get(struct net_device *dev, u8 daddr) | |||
178 | saddr = find_first_bit(pnd->addrs, 64) << 2; | 197 | saddr = find_first_bit(pnd->addrs, 64) << 2; |
179 | } else | 198 | } else |
180 | saddr = PN_NO_ADDR; | 199 | saddr = PN_NO_ADDR; |
181 | spin_unlock_bh(&pndevs->lock); | 200 | rcu_read_unlock(); |
182 | 201 | ||
183 | if (saddr == PN_NO_ADDR) { | 202 | if (saddr == PN_NO_ADDR) { |
184 | /* Fallback to another device */ | 203 | /* Fallback to another device */ |
@@ -200,8 +219,8 @@ int phonet_address_lookup(struct net *net, u8 addr) | |||
200 | struct phonet_device *pnd; | 219 | struct phonet_device *pnd; |
201 | int err = -EADDRNOTAVAIL; | 220 | int err = -EADDRNOTAVAIL; |
202 | 221 | ||
203 | spin_lock_bh(&pndevs->lock); | 222 | rcu_read_lock(); |
204 | list_for_each_entry(pnd, &pndevs->list, list) { | 223 | list_for_each_entry_rcu(pnd, &pndevs->list, list) { |
205 | /* Don't allow unregistering devices! */ | 224 | /* Don't allow unregistering devices! */ |
206 | if ((pnd->netdev->reg_state != NETREG_REGISTERED) || | 225 | if ((pnd->netdev->reg_state != NETREG_REGISTERED) || |
207 | ((pnd->netdev->flags & IFF_UP)) != IFF_UP) | 226 | ((pnd->netdev->flags & IFF_UP)) != IFF_UP) |
@@ -213,7 +232,7 @@ int phonet_address_lookup(struct net *net, u8 addr) | |||
213 | } | 232 | } |
214 | } | 233 | } |
215 | found: | 234 | found: |
216 | spin_unlock_bh(&pndevs->lock); | 235 | rcu_read_unlock(); |
217 | return err; | 236 | return err; |
218 | } | 237 | } |
219 | 238 | ||
@@ -304,7 +323,7 @@ static int phonet_init_net(struct net *net) | |||
304 | } | 323 | } |
305 | 324 | ||
306 | INIT_LIST_HEAD(&pnn->pndevs.list); | 325 | INIT_LIST_HEAD(&pnn->pndevs.list); |
307 | spin_lock_init(&pnn->pndevs.lock); | 326 | mutex_init(&pnn->pndevs.lock); |
308 | mutex_init(&pnn->routes.lock); | 327 | mutex_init(&pnn->routes.lock); |
309 | net_assign_generic(net, phonet_net_id, pnn); | 328 | net_assign_generic(net, phonet_net_id, pnn); |
310 | return 0; | 329 | return 0; |
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c index 609e509b369b..2e6c7eb8e76a 100644 --- a/net/phonet/pn_netlink.c +++ b/net/phonet/pn_netlink.c | |||
@@ -131,8 +131,8 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) | |||
131 | int addr_idx = 0, addr_start_idx = cb->args[1]; | 131 | int addr_idx = 0, addr_start_idx = cb->args[1]; |
132 | 132 | ||
133 | pndevs = phonet_device_list(sock_net(skb->sk)); | 133 | pndevs = phonet_device_list(sock_net(skb->sk)); |
134 | spin_lock_bh(&pndevs->lock); | 134 | rcu_read_lock(); |
135 | list_for_each_entry(pnd, &pndevs->list, list) { | 135 | list_for_each_entry_rcu(pnd, &pndevs->list, list) { |
136 | u8 addr; | 136 | u8 addr; |
137 | 137 | ||
138 | if (dev_idx > dev_start_idx) | 138 | if (dev_idx > dev_start_idx) |
@@ -154,7 +154,7 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) | |||
154 | } | 154 | } |
155 | 155 | ||
156 | out: | 156 | out: |
157 | spin_unlock_bh(&pndevs->lock); | 157 | rcu_read_unlock(); |
158 | cb->args[0] = dev_idx; | 158 | cb->args[0] = dev_idx; |
159 | cb->args[1] = addr_idx; | 159 | cb->args[1] = addr_idx; |
160 | 160 | ||