diff options
author | Jason Eastman <eastman.jason.linux@gmail.com> | 2015-04-22 02:56:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-04-23 13:15:20 -0400 |
commit | d1ab39f17f8653021620d0355ee1cd24d7442a4f (patch) | |
tree | ba0bcff457b4e570c2dae0b7792e6fc00518debc /net/unix/garbage.c | |
parent | 37a06a87f20d93c2cec3db9aaf0360a322b703dd (diff) |
net: unix: garbage: fixed several comment and whitespace style issues
fixed several comment and whitespace style issues
Signed-off-by: Jason Eastman <eastman.jason.linux@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/unix/garbage.c')
-rw-r--r-- | net/unix/garbage.c | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/net/unix/garbage.c b/net/unix/garbage.c index 99f7012b23b9..a73a226f2d33 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c | |||
@@ -95,39 +95,36 @@ static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait); | |||
95 | 95 | ||
96 | unsigned int unix_tot_inflight; | 96 | unsigned int unix_tot_inflight; |
97 | 97 | ||
98 | |||
99 | struct sock *unix_get_socket(struct file *filp) | 98 | struct sock *unix_get_socket(struct file *filp) |
100 | { | 99 | { |
101 | struct sock *u_sock = NULL; | 100 | struct sock *u_sock = NULL; |
102 | struct inode *inode = file_inode(filp); | 101 | struct inode *inode = file_inode(filp); |
103 | 102 | ||
104 | /* | 103 | /* Socket ? */ |
105 | * Socket ? | ||
106 | */ | ||
107 | if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) { | 104 | if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) { |
108 | struct socket *sock = SOCKET_I(inode); | 105 | struct socket *sock = SOCKET_I(inode); |
109 | struct sock *s = sock->sk; | 106 | struct sock *s = sock->sk; |
110 | 107 | ||
111 | /* | 108 | /* PF_UNIX ? */ |
112 | * PF_UNIX ? | ||
113 | */ | ||
114 | if (s && sock->ops && sock->ops->family == PF_UNIX) | 109 | if (s && sock->ops && sock->ops->family == PF_UNIX) |
115 | u_sock = s; | 110 | u_sock = s; |
116 | } | 111 | } |
117 | return u_sock; | 112 | return u_sock; |
118 | } | 113 | } |
119 | 114 | ||
120 | /* | 115 | /* Keep the number of times in flight count for the file |
121 | * Keep the number of times in flight count for the file | 116 | * descriptor if it is for an AF_UNIX socket. |
122 | * descriptor if it is for an AF_UNIX socket. | ||
123 | */ | 117 | */ |
124 | 118 | ||
125 | void unix_inflight(struct file *fp) | 119 | void unix_inflight(struct file *fp) |
126 | { | 120 | { |
127 | struct sock *s = unix_get_socket(fp); | 121 | struct sock *s = unix_get_socket(fp); |
122 | |||
128 | if (s) { | 123 | if (s) { |
129 | struct unix_sock *u = unix_sk(s); | 124 | struct unix_sock *u = unix_sk(s); |
125 | |||
130 | spin_lock(&unix_gc_lock); | 126 | spin_lock(&unix_gc_lock); |
127 | |||
131 | if (atomic_long_inc_return(&u->inflight) == 1) { | 128 | if (atomic_long_inc_return(&u->inflight) == 1) { |
132 | BUG_ON(!list_empty(&u->link)); | 129 | BUG_ON(!list_empty(&u->link)); |
133 | list_add_tail(&u->link, &gc_inflight_list); | 130 | list_add_tail(&u->link, &gc_inflight_list); |
@@ -142,10 +139,13 @@ void unix_inflight(struct file *fp) | |||
142 | void unix_notinflight(struct file *fp) | 139 | void unix_notinflight(struct file *fp) |
143 | { | 140 | { |
144 | struct sock *s = unix_get_socket(fp); | 141 | struct sock *s = unix_get_socket(fp); |
142 | |||
145 | if (s) { | 143 | if (s) { |
146 | struct unix_sock *u = unix_sk(s); | 144 | struct unix_sock *u = unix_sk(s); |
145 | |||
147 | spin_lock(&unix_gc_lock); | 146 | spin_lock(&unix_gc_lock); |
148 | BUG_ON(list_empty(&u->link)); | 147 | BUG_ON(list_empty(&u->link)); |
148 | |||
149 | if (atomic_long_dec_and_test(&u->inflight)) | 149 | if (atomic_long_dec_and_test(&u->inflight)) |
150 | list_del_init(&u->link); | 150 | list_del_init(&u->link); |
151 | unix_tot_inflight--; | 151 | unix_tot_inflight--; |
@@ -161,32 +161,27 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *), | |||
161 | 161 | ||
162 | spin_lock(&x->sk_receive_queue.lock); | 162 | spin_lock(&x->sk_receive_queue.lock); |
163 | skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { | 163 | skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { |
164 | /* | 164 | /* Do we have file descriptors ? */ |
165 | * Do we have file descriptors ? | ||
166 | */ | ||
167 | if (UNIXCB(skb).fp) { | 165 | if (UNIXCB(skb).fp) { |
168 | bool hit = false; | 166 | bool hit = false; |
169 | /* | 167 | /* Process the descriptors of this socket */ |
170 | * Process the descriptors of this socket | ||
171 | */ | ||
172 | int nfd = UNIXCB(skb).fp->count; | 168 | int nfd = UNIXCB(skb).fp->count; |
173 | struct file **fp = UNIXCB(skb).fp->fp; | 169 | struct file **fp = UNIXCB(skb).fp->fp; |
170 | |||
174 | while (nfd--) { | 171 | while (nfd--) { |
175 | /* | 172 | /* Get the socket the fd matches if it indeed does so */ |
176 | * Get the socket the fd matches | ||
177 | * if it indeed does so | ||
178 | */ | ||
179 | struct sock *sk = unix_get_socket(*fp++); | 173 | struct sock *sk = unix_get_socket(*fp++); |
174 | |||
180 | if (sk) { | 175 | if (sk) { |
181 | struct unix_sock *u = unix_sk(sk); | 176 | struct unix_sock *u = unix_sk(sk); |
182 | 177 | ||
183 | /* | 178 | /* Ignore non-candidates, they could |
184 | * Ignore non-candidates, they could | ||
185 | * have been added to the queues after | 179 | * have been added to the queues after |
186 | * starting the garbage collection | 180 | * starting the garbage collection |
187 | */ | 181 | */ |
188 | if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) { | 182 | if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) { |
189 | hit = true; | 183 | hit = true; |
184 | |||
190 | func(u); | 185 | func(u); |
191 | } | 186 | } |
192 | } | 187 | } |
@@ -203,24 +198,22 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *), | |||
203 | static void scan_children(struct sock *x, void (*func)(struct unix_sock *), | 198 | static void scan_children(struct sock *x, void (*func)(struct unix_sock *), |
204 | struct sk_buff_head *hitlist) | 199 | struct sk_buff_head *hitlist) |
205 | { | 200 | { |
206 | if (x->sk_state != TCP_LISTEN) | 201 | if (x->sk_state != TCP_LISTEN) { |
207 | scan_inflight(x, func, hitlist); | 202 | scan_inflight(x, func, hitlist); |
208 | else { | 203 | } else { |
209 | struct sk_buff *skb; | 204 | struct sk_buff *skb; |
210 | struct sk_buff *next; | 205 | struct sk_buff *next; |
211 | struct unix_sock *u; | 206 | struct unix_sock *u; |
212 | LIST_HEAD(embryos); | 207 | LIST_HEAD(embryos); |
213 | 208 | ||
214 | /* | 209 | /* For a listening socket collect the queued embryos |
215 | * For a listening socket collect the queued embryos | ||
216 | * and perform a scan on them as well. | 210 | * and perform a scan on them as well. |
217 | */ | 211 | */ |
218 | spin_lock(&x->sk_receive_queue.lock); | 212 | spin_lock(&x->sk_receive_queue.lock); |
219 | skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { | 213 | skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { |
220 | u = unix_sk(skb->sk); | 214 | u = unix_sk(skb->sk); |
221 | 215 | ||
222 | /* | 216 | /* An embryo cannot be in-flight, so it's safe |
223 | * An embryo cannot be in-flight, so it's safe | ||
224 | * to use the list link. | 217 | * to use the list link. |
225 | */ | 218 | */ |
226 | BUG_ON(!list_empty(&u->link)); | 219 | BUG_ON(!list_empty(&u->link)); |
@@ -249,8 +242,7 @@ static void inc_inflight(struct unix_sock *usk) | |||
249 | static void inc_inflight_move_tail(struct unix_sock *u) | 242 | static void inc_inflight_move_tail(struct unix_sock *u) |
250 | { | 243 | { |
251 | atomic_long_inc(&u->inflight); | 244 | atomic_long_inc(&u->inflight); |
252 | /* | 245 | /* If this still might be part of a cycle, move it to the end |
253 | * If this still might be part of a cycle, move it to the end | ||
254 | * of the list, so that it's checked even if it was already | 246 | * of the list, so that it's checked even if it was already |
255 | * passed over | 247 | * passed over |
256 | */ | 248 | */ |
@@ -263,8 +255,7 @@ static bool gc_in_progress; | |||
263 | 255 | ||
264 | void wait_for_unix_gc(void) | 256 | void wait_for_unix_gc(void) |
265 | { | 257 | { |
266 | /* | 258 | /* If number of inflight sockets is insane, |
267 | * If number of inflight sockets is insane, | ||
268 | * force a garbage collect right now. | 259 | * force a garbage collect right now. |
269 | */ | 260 | */ |
270 | if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress) | 261 | if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress) |
@@ -288,8 +279,7 @@ void unix_gc(void) | |||
288 | goto out; | 279 | goto out; |
289 | 280 | ||
290 | gc_in_progress = true; | 281 | gc_in_progress = true; |
291 | /* | 282 | /* First, select candidates for garbage collection. Only |
292 | * First, select candidates for garbage collection. Only | ||
293 | * in-flight sockets are considered, and from those only ones | 283 | * in-flight sockets are considered, and from those only ones |
294 | * which don't have any external reference. | 284 | * which don't have any external reference. |
295 | * | 285 | * |
@@ -320,15 +310,13 @@ void unix_gc(void) | |||
320 | } | 310 | } |
321 | } | 311 | } |
322 | 312 | ||
323 | /* | 313 | /* Now remove all internal in-flight reference to children of |
324 | * Now remove all internal in-flight reference to children of | ||
325 | * the candidates. | 314 | * the candidates. |
326 | */ | 315 | */ |
327 | list_for_each_entry(u, &gc_candidates, link) | 316 | list_for_each_entry(u, &gc_candidates, link) |
328 | scan_children(&u->sk, dec_inflight, NULL); | 317 | scan_children(&u->sk, dec_inflight, NULL); |
329 | 318 | ||
330 | /* | 319 | /* Restore the references for children of all candidates, |
331 | * Restore the references for children of all candidates, | ||
332 | * which have remaining references. Do this recursively, so | 320 | * which have remaining references. Do this recursively, so |
333 | * only those remain, which form cyclic references. | 321 | * only those remain, which form cyclic references. |
334 | * | 322 | * |
@@ -350,8 +338,7 @@ void unix_gc(void) | |||
350 | } | 338 | } |
351 | list_del(&cursor); | 339 | list_del(&cursor); |
352 | 340 | ||
353 | /* | 341 | /* not_cycle_list contains those sockets which do not make up a |
354 | * not_cycle_list contains those sockets which do not make up a | ||
355 | * cycle. Restore these to the inflight list. | 342 | * cycle. Restore these to the inflight list. |
356 | */ | 343 | */ |
357 | while (!list_empty(¬_cycle_list)) { | 344 | while (!list_empty(¬_cycle_list)) { |
@@ -360,8 +347,7 @@ void unix_gc(void) | |||
360 | list_move_tail(&u->link, &gc_inflight_list); | 347 | list_move_tail(&u->link, &gc_inflight_list); |
361 | } | 348 | } |
362 | 349 | ||
363 | /* | 350 | /* Now gc_candidates contains only garbage. Restore original |
364 | * Now gc_candidates contains only garbage. Restore original | ||
365 | * inflight counters for these as well, and remove the skbuffs | 351 | * inflight counters for these as well, and remove the skbuffs |
366 | * which are creating the cycle(s). | 352 | * which are creating the cycle(s). |
367 | */ | 353 | */ |