diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-07-31 12:43:41 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-31 12:43:41 -0400 |
commit | 85e9ca333d03fbd56b9e123c8456f0d98e20faad (patch) | |
tree | 7bb15ada5f536950efa23ad60ea9eea60380ca1c /net/unix | |
parent | a300bec952127d9a15e666b391bb35c9aecb3002 (diff) | |
parent | 6e86841d05f371b5b9b86ce76c02aaee83352298 (diff) |
Merge branch 'linus' into timers/hpet
Diffstat (limited to 'net/unix')
-rw-r--r-- | net/unix/af_unix.c | 87 | ||||
-rw-r--r-- | net/unix/garbage.c | 18 |
2 files changed, 80 insertions, 25 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index e18cd3628db4..015606b54d9b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -8,8 +8,6 @@ | |||
8 | * as published by the Free Software Foundation; either version | 8 | * as published by the Free Software Foundation; either version |
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * Version: $Id: af_unix.c,v 1.133 2002/02/08 03:57:19 davem Exp $ | ||
12 | * | ||
13 | * Fixes: | 11 | * Fixes: |
14 | * Linus Torvalds : Assorted bug cures. | 12 | * Linus Torvalds : Assorted bug cures. |
15 | * Niibe Yutaka : async I/O support. | 13 | * Niibe Yutaka : async I/O support. |
@@ -169,6 +167,11 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk) | |||
169 | return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); | 167 | return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); |
170 | } | 168 | } |
171 | 169 | ||
170 | static inline int unix_recvq_full(struct sock const *sk) | ||
171 | { | ||
172 | return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog; | ||
173 | } | ||
174 | |||
172 | static struct sock *unix_peer_get(struct sock *s) | 175 | static struct sock *unix_peer_get(struct sock *s) |
173 | { | 176 | { |
174 | struct sock *peer; | 177 | struct sock *peer; |
@@ -224,7 +227,7 @@ static void __unix_remove_socket(struct sock *sk) | |||
224 | 227 | ||
225 | static void __unix_insert_socket(struct hlist_head *list, struct sock *sk) | 228 | static void __unix_insert_socket(struct hlist_head *list, struct sock *sk) |
226 | { | 229 | { |
227 | BUG_TRAP(sk_unhashed(sk)); | 230 | WARN_ON(!sk_unhashed(sk)); |
228 | sk_add_node(sk, list); | 231 | sk_add_node(sk, list); |
229 | } | 232 | } |
230 | 233 | ||
@@ -347,9 +350,9 @@ static void unix_sock_destructor(struct sock *sk) | |||
347 | 350 | ||
348 | skb_queue_purge(&sk->sk_receive_queue); | 351 | skb_queue_purge(&sk->sk_receive_queue); |
349 | 352 | ||
350 | BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc)); | 353 | WARN_ON(atomic_read(&sk->sk_wmem_alloc)); |
351 | BUG_TRAP(sk_unhashed(sk)); | 354 | WARN_ON(!sk_unhashed(sk)); |
352 | BUG_TRAP(!sk->sk_socket); | 355 | WARN_ON(sk->sk_socket); |
353 | if (!sock_flag(sk, SOCK_DEAD)) { | 356 | if (!sock_flag(sk, SOCK_DEAD)) { |
354 | printk("Attempt to release alive unix socket: %p\n", sk); | 357 | printk("Attempt to release alive unix socket: %p\n", sk); |
355 | return; | 358 | return; |
@@ -482,6 +485,8 @@ static int unix_socketpair(struct socket *, struct socket *); | |||
482 | static int unix_accept(struct socket *, struct socket *, int); | 485 | static int unix_accept(struct socket *, struct socket *, int); |
483 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); | 486 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); |
484 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); | 487 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); |
488 | static unsigned int unix_dgram_poll(struct file *, struct socket *, | ||
489 | poll_table *); | ||
485 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); | 490 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); |
486 | static int unix_shutdown(struct socket *, int); | 491 | static int unix_shutdown(struct socket *, int); |
487 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, | 492 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, |
@@ -527,7 +532,7 @@ static const struct proto_ops unix_dgram_ops = { | |||
527 | .socketpair = unix_socketpair, | 532 | .socketpair = unix_socketpair, |
528 | .accept = sock_no_accept, | 533 | .accept = sock_no_accept, |
529 | .getname = unix_getname, | 534 | .getname = unix_getname, |
530 | .poll = datagram_poll, | 535 | .poll = unix_dgram_poll, |
531 | .ioctl = unix_ioctl, | 536 | .ioctl = unix_ioctl, |
532 | .listen = sock_no_listen, | 537 | .listen = sock_no_listen, |
533 | .shutdown = unix_shutdown, | 538 | .shutdown = unix_shutdown, |
@@ -548,7 +553,7 @@ static const struct proto_ops unix_seqpacket_ops = { | |||
548 | .socketpair = unix_socketpair, | 553 | .socketpair = unix_socketpair, |
549 | .accept = unix_accept, | 554 | .accept = unix_accept, |
550 | .getname = unix_getname, | 555 | .getname = unix_getname, |
551 | .poll = datagram_poll, | 556 | .poll = unix_dgram_poll, |
552 | .ioctl = unix_ioctl, | 557 | .ioctl = unix_ioctl, |
553 | .listen = unix_listen, | 558 | .listen = unix_listen, |
554 | .shutdown = unix_shutdown, | 559 | .shutdown = unix_shutdown, |
@@ -598,7 +603,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock) | |||
598 | u->dentry = NULL; | 603 | u->dentry = NULL; |
599 | u->mnt = NULL; | 604 | u->mnt = NULL; |
600 | spin_lock_init(&u->lock); | 605 | spin_lock_init(&u->lock); |
601 | atomic_set(&u->inflight, 0); | 606 | atomic_long_set(&u->inflight, 0); |
602 | INIT_LIST_HEAD(&u->link); | 607 | INIT_LIST_HEAD(&u->link); |
603 | mutex_init(&u->readlock); /* single task reading lock */ | 608 | mutex_init(&u->readlock); /* single task reading lock */ |
604 | init_waitqueue_head(&u->peer_wait); | 609 | init_waitqueue_head(&u->peer_wait); |
@@ -983,8 +988,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo) | |||
983 | 988 | ||
984 | sched = !sock_flag(other, SOCK_DEAD) && | 989 | sched = !sock_flag(other, SOCK_DEAD) && |
985 | !(other->sk_shutdown & RCV_SHUTDOWN) && | 990 | !(other->sk_shutdown & RCV_SHUTDOWN) && |
986 | (skb_queue_len(&other->sk_receive_queue) > | 991 | unix_recvq_full(other); |
987 | other->sk_max_ack_backlog); | ||
988 | 992 | ||
989 | unix_state_unlock(other); | 993 | unix_state_unlock(other); |
990 | 994 | ||
@@ -1058,8 +1062,7 @@ restart: | |||
1058 | if (other->sk_state != TCP_LISTEN) | 1062 | if (other->sk_state != TCP_LISTEN) |
1059 | goto out_unlock; | 1063 | goto out_unlock; |
1060 | 1064 | ||
1061 | if (skb_queue_len(&other->sk_receive_queue) > | 1065 | if (unix_recvq_full(other)) { |
1062 | other->sk_max_ack_backlog) { | ||
1063 | err = -EAGAIN; | 1066 | err = -EAGAIN; |
1064 | if (!timeo) | 1067 | if (!timeo) |
1065 | goto out_unlock; | 1068 | goto out_unlock; |
@@ -1428,9 +1431,7 @@ restart: | |||
1428 | goto out_unlock; | 1431 | goto out_unlock; |
1429 | } | 1432 | } |
1430 | 1433 | ||
1431 | if (unix_peer(other) != sk && | 1434 | if (unix_peer(other) != sk && unix_recvq_full(other)) { |
1432 | (skb_queue_len(&other->sk_receive_queue) > | ||
1433 | other->sk_max_ack_backlog)) { | ||
1434 | if (!timeo) { | 1435 | if (!timeo) { |
1435 | err = -EAGAIN; | 1436 | err = -EAGAIN; |
1436 | goto out_unlock; | 1437 | goto out_unlock; |
@@ -1991,6 +1992,60 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl | |||
1991 | return mask; | 1992 | return mask; |
1992 | } | 1993 | } |
1993 | 1994 | ||
1995 | static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, | ||
1996 | poll_table *wait) | ||
1997 | { | ||
1998 | struct sock *sk = sock->sk, *other; | ||
1999 | unsigned int mask, writable; | ||
2000 | |||
2001 | poll_wait(file, sk->sk_sleep, wait); | ||
2002 | mask = 0; | ||
2003 | |||
2004 | /* exceptional events? */ | ||
2005 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) | ||
2006 | mask |= POLLERR; | ||
2007 | if (sk->sk_shutdown & RCV_SHUTDOWN) | ||
2008 | mask |= POLLRDHUP; | ||
2009 | if (sk->sk_shutdown == SHUTDOWN_MASK) | ||
2010 | mask |= POLLHUP; | ||
2011 | |||
2012 | /* readable? */ | ||
2013 | if (!skb_queue_empty(&sk->sk_receive_queue) || | ||
2014 | (sk->sk_shutdown & RCV_SHUTDOWN)) | ||
2015 | mask |= POLLIN | POLLRDNORM; | ||
2016 | |||
2017 | /* Connection-based need to check for termination and startup */ | ||
2018 | if (sk->sk_type == SOCK_SEQPACKET) { | ||
2019 | if (sk->sk_state == TCP_CLOSE) | ||
2020 | mask |= POLLHUP; | ||
2021 | /* connection hasn't started yet? */ | ||
2022 | if (sk->sk_state == TCP_SYN_SENT) | ||
2023 | return mask; | ||
2024 | } | ||
2025 | |||
2026 | /* writable? */ | ||
2027 | writable = unix_writable(sk); | ||
2028 | if (writable) { | ||
2029 | other = unix_peer_get(sk); | ||
2030 | if (other) { | ||
2031 | if (unix_peer(other) != sk) { | ||
2032 | poll_wait(file, &unix_sk(other)->peer_wait, | ||
2033 | wait); | ||
2034 | if (unix_recvq_full(other)) | ||
2035 | writable = 0; | ||
2036 | } | ||
2037 | |||
2038 | sock_put(other); | ||
2039 | } | ||
2040 | } | ||
2041 | |||
2042 | if (writable) | ||
2043 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; | ||
2044 | else | ||
2045 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | ||
2046 | |||
2047 | return mask; | ||
2048 | } | ||
1994 | 2049 | ||
1995 | #ifdef CONFIG_PROC_FS | 2050 | #ifdef CONFIG_PROC_FS |
1996 | static struct sock *first_unix_socket(int *i) | 2051 | static struct sock *first_unix_socket(int *i) |
diff --git a/net/unix/garbage.c b/net/unix/garbage.c index ebdff3d877a1..2a27b84f740b 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c | |||
@@ -127,7 +127,7 @@ void unix_inflight(struct file *fp) | |||
127 | if(s) { | 127 | if(s) { |
128 | struct unix_sock *u = unix_sk(s); | 128 | struct unix_sock *u = unix_sk(s); |
129 | spin_lock(&unix_gc_lock); | 129 | spin_lock(&unix_gc_lock); |
130 | if (atomic_inc_return(&u->inflight) == 1) { | 130 | if (atomic_long_inc_return(&u->inflight) == 1) { |
131 | BUG_ON(!list_empty(&u->link)); | 131 | BUG_ON(!list_empty(&u->link)); |
132 | list_add_tail(&u->link, &gc_inflight_list); | 132 | list_add_tail(&u->link, &gc_inflight_list); |
133 | } else { | 133 | } else { |
@@ -145,7 +145,7 @@ void unix_notinflight(struct file *fp) | |||
145 | struct unix_sock *u = unix_sk(s); | 145 | struct unix_sock *u = unix_sk(s); |
146 | spin_lock(&unix_gc_lock); | 146 | spin_lock(&unix_gc_lock); |
147 | BUG_ON(list_empty(&u->link)); | 147 | BUG_ON(list_empty(&u->link)); |
148 | if (atomic_dec_and_test(&u->inflight)) | 148 | if (atomic_long_dec_and_test(&u->inflight)) |
149 | list_del_init(&u->link); | 149 | list_del_init(&u->link); |
150 | unix_tot_inflight--; | 150 | unix_tot_inflight--; |
151 | spin_unlock(&unix_gc_lock); | 151 | spin_unlock(&unix_gc_lock); |
@@ -237,17 +237,17 @@ static void scan_children(struct sock *x, void (*func)(struct unix_sock *), | |||
237 | 237 | ||
238 | static void dec_inflight(struct unix_sock *usk) | 238 | static void dec_inflight(struct unix_sock *usk) |
239 | { | 239 | { |
240 | atomic_dec(&usk->inflight); | 240 | atomic_long_dec(&usk->inflight); |
241 | } | 241 | } |
242 | 242 | ||
243 | static void inc_inflight(struct unix_sock *usk) | 243 | static void inc_inflight(struct unix_sock *usk) |
244 | { | 244 | { |
245 | atomic_inc(&usk->inflight); | 245 | atomic_long_inc(&usk->inflight); |
246 | } | 246 | } |
247 | 247 | ||
248 | static void inc_inflight_move_tail(struct unix_sock *u) | 248 | static void inc_inflight_move_tail(struct unix_sock *u) |
249 | { | 249 | { |
250 | atomic_inc(&u->inflight); | 250 | atomic_long_inc(&u->inflight); |
251 | /* | 251 | /* |
252 | * If this is still a candidate, move it to the end of the | 252 | * If this is still a candidate, move it to the end of the |
253 | * list, so that it's checked even if it was already passed | 253 | * list, so that it's checked even if it was already passed |
@@ -288,11 +288,11 @@ void unix_gc(void) | |||
288 | * before the detach without atomicity guarantees. | 288 | * before the detach without atomicity guarantees. |
289 | */ | 289 | */ |
290 | list_for_each_entry_safe(u, next, &gc_inflight_list, link) { | 290 | list_for_each_entry_safe(u, next, &gc_inflight_list, link) { |
291 | int total_refs; | 291 | long total_refs; |
292 | int inflight_refs; | 292 | long inflight_refs; |
293 | 293 | ||
294 | total_refs = file_count(u->sk.sk_socket->file); | 294 | total_refs = file_count(u->sk.sk_socket->file); |
295 | inflight_refs = atomic_read(&u->inflight); | 295 | inflight_refs = atomic_long_read(&u->inflight); |
296 | 296 | ||
297 | BUG_ON(inflight_refs < 1); | 297 | BUG_ON(inflight_refs < 1); |
298 | BUG_ON(total_refs < inflight_refs); | 298 | BUG_ON(total_refs < inflight_refs); |
@@ -324,7 +324,7 @@ void unix_gc(void) | |||
324 | /* Move cursor to after the current position. */ | 324 | /* Move cursor to after the current position. */ |
325 | list_move(&cursor, &u->link); | 325 | list_move(&cursor, &u->link); |
326 | 326 | ||
327 | if (atomic_read(&u->inflight) > 0) { | 327 | if (atomic_long_read(&u->inflight) > 0) { |
328 | list_move_tail(&u->link, &gc_inflight_list); | 328 | list_move_tail(&u->link, &gc_inflight_list); |
329 | u->gc_candidate = 0; | 329 | u->gc_candidate = 0; |
330 | scan_children(&u->sk, inc_inflight_move_tail, NULL); | 330 | scan_children(&u->sk, inc_inflight_move_tail, NULL); |