aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2011-12-29 19:54:11 -0500
committerDavid S. Miller <davem@davemloft.net>2011-12-30 16:45:45 -0500
commit885ee74d5d3058e4a904671ed7929c9540c95fa5 (patch)
tree83420dadda4c863a7bcebedf291f4d7009ffbb5f /net/unix
parent257b529876cb45ec791eaa89e3d2ee0d16b49383 (diff)
af_unix: Move CINQ/COUTQ code to helpers
Currently tcp diag reports rqlen and wqlen values similar to how the CINQ/COUTQ iotcls do. To make unix diag report these values in the same way move the respective code into helpers. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e1b9358a211d..7cc3d7b23d1c 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2065,6 +2065,36 @@ static int unix_shutdown(struct socket *sock, int mode)
2065 return 0; 2065 return 0;
2066} 2066}
2067 2067
2068long unix_inq_len(struct sock *sk)
2069{
2070 struct sk_buff *skb;
2071 long amount = 0;
2072
2073 if (sk->sk_state == TCP_LISTEN)
2074 return -EINVAL;
2075
2076 spin_lock(&sk->sk_receive_queue.lock);
2077 if (sk->sk_type == SOCK_STREAM ||
2078 sk->sk_type == SOCK_SEQPACKET) {
2079 skb_queue_walk(&sk->sk_receive_queue, skb)
2080 amount += skb->len;
2081 } else {
2082 skb = skb_peek(&sk->sk_receive_queue);
2083 if (skb)
2084 amount = skb->len;
2085 }
2086 spin_unlock(&sk->sk_receive_queue.lock);
2087
2088 return amount;
2089}
2090EXPORT_SYMBOL_GPL(unix_inq_len);
2091
2092long unix_outq_len(struct sock *sk)
2093{
2094 return sk_wmem_alloc_get(sk);
2095}
2096EXPORT_SYMBOL_GPL(unix_outq_len);
2097
2068static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 2098static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2069{ 2099{
2070 struct sock *sk = sock->sk; 2100 struct sock *sk = sock->sk;
@@ -2073,33 +2103,16 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2073 2103
2074 switch (cmd) { 2104 switch (cmd) {
2075 case SIOCOUTQ: 2105 case SIOCOUTQ:
2076 amount = sk_wmem_alloc_get(sk); 2106 amount = unix_outq_len(sk);
2077 err = put_user(amount, (int __user *)arg); 2107 err = put_user(amount, (int __user *)arg);
2078 break; 2108 break;
2079 case SIOCINQ: 2109 case SIOCINQ:
2080 { 2110 amount = unix_inq_len(sk);
2081 struct sk_buff *skb; 2111 if (amount < 0)
2082 2112 err = amount;
2083 if (sk->sk_state == TCP_LISTEN) { 2113 else
2084 err = -EINVAL;
2085 break;
2086 }
2087
2088 spin_lock(&sk->sk_receive_queue.lock);
2089 if (sk->sk_type == SOCK_STREAM ||
2090 sk->sk_type == SOCK_SEQPACKET) {
2091 skb_queue_walk(&sk->sk_receive_queue, skb)
2092 amount += skb->len;
2093 } else {
2094 skb = skb_peek(&sk->sk_receive_queue);
2095 if (skb)
2096 amount = skb->len;
2097 }
2098 spin_unlock(&sk->sk_receive_queue.lock);
2099 err = put_user(amount, (int __user *)arg); 2114 err = put_user(amount, (int __user *)arg);
2100 break; 2115 break;
2101 }
2102
2103 default: 2116 default:
2104 err = -ENOIOCTLCMD; 2117 err = -ENOIOCTLCMD;
2105 break; 2118 break;