Merge tag 'v3.10.107' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / unix / af_unix.c
index 4b18115c0543cc4d29b7bd9bfffdf84993808815..a14c213ea4270f6b2795afd3af7a40f13feb0360 100644 (file)
 #include <linux/mount.h>
 #include <net/checksum.h>
 #include <linux/security.h>
+#include <linux/freezer.h>
+
+
+#include <linux/uio.h>
+#include <linux/blkdev.h>
+#include <linux/compat.h>
+#include <linux/rtc.h>
+#include <asm/kmap_types.h>
+#include <linux/device.h>
+
 
 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
 EXPORT_SYMBOL_GPL(unix_socket_table);
@@ -134,6 +144,17 @@ static struct hlist_head *unix_sockets_unbound(void *addr)
 
 #define UNIX_ABSTRACT(sk)      (unix_sk(sk)->addr->hash < UNIX_HASH_SIZE)
 
+
+//for aee interface start
+#define __UNIX_SOCKET_OUTPUT_BUF_SIZE__   3500
+static struct proc_dir_entry *gunix_socket_track_aee_entry = NULL;
+#define UNIX_SOCK_TRACK_AEE_PROCNAME "driver/usktrk_aee"
+#define UNIX_SOCK_TRACK_PROC_AEE_SIZE 3072
+
+static volatile unsigned int unix_sock_track_stop_flag = 0;
+#define unix_peer(sk) (unix_sk(sk)->peer)
+
+
 #ifdef CONFIG_SECURITY_NETWORK
 static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb)
 {
@@ -166,7 +187,7 @@ static inline unsigned int unix_hash_fold(__wsum n)
        return hash&(UNIX_HASH_SIZE-1);
 }
 
-#define unix_peer(sk) (unix_sk(sk)->peer)
+
 
 static inline int unix_our_peer(struct sock *sk, struct sock *osk)
 {
@@ -476,7 +497,9 @@ static void unix_sock_destructor(struct sock *sk)
        WARN_ON(!sk_unhashed(sk));
        WARN_ON(sk->sk_socket);
        if (!sock_flag(sk, SOCK_DEAD)) {
-               printk(KERN_INFO "Attempt to release alive unix socket: %p\n", sk);
+               #ifdef CONFIG_MTK_NET_LOGGING 
+               printk(KERN_INFO "[mtk_net][unix]Attempt to release alive unix socket: %p\n", sk);
+               #endif
                return;
        }
 
@@ -487,10 +510,10 @@ static void unix_sock_destructor(struct sock *sk)
        local_bh_disable();
        sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
        local_bh_enable();
-#ifdef UNIX_REFCNT_DEBUG
-       printk(KERN_DEBUG "UNIX %p is destroyed, %ld are still alive.\n", sk,
+    #ifdef UNIX_REFCNT_DEBUG
+       printk(KERN_DEBUG "[mtk_net][unix]UNIX %p is destroyed, %ld are still alive.\n", sk,
                atomic_long_read(&unix_nr_socks));
-#endif
+    #endif
 }
 
 static void unix_release_sock(struct sock *sk, int embrion)
@@ -612,6 +635,7 @@ out_unlock:
        unix_state_unlock(sk);
        put_pid(old_pid);
 out:
+   
        return err;
 }
 
@@ -1053,6 +1077,7 @@ out_put:
        if (err)
                path_put(&path);
 out:
        return err;
 }
 
@@ -1092,6 +1117,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
        int err;
 
        if (addr->sa_family != AF_UNSPEC) {
+     
                err = unix_mkname(sunaddr, alen, &hash);
                if (err < 0)
                        goto out;
@@ -1148,12 +1174,21 @@ restart:
                unix_peer(sk) = other;
                unix_state_double_unlock(sk, other);
        }
+       
+#ifdef CONFIG_MTK_NET_LOGGING 
+    if((SOCK_INODE(sock)!= NULL) && (sunaddr != NULL) && (other->sk_socket != NULL) && (SOCK_INODE(other->sk_socket) != NULL))
+    {
+              printk(KERN_INFO "[mtk_net][socket]unix_dgram_connect[%lu]:connect [%s] other[%lu]\n",SOCK_INODE(sock)->i_ino,sunaddr->sun_path,SOCK_INODE(other->sk_socket)->i_ino);
+         }
+#endif 
+            
        return 0;
 
 out_unlock:
        unix_state_double_unlock(sk, other);
        sock_put(other);
 out:
+     
        return err;
 }
 
@@ -1336,8 +1371,17 @@ restart:
        __skb_queue_tail(&other->sk_receive_queue, skb);
        spin_unlock(&other->sk_receive_queue.lock);
        unix_state_unlock(other);
+       
+       #ifdef CONFIG_MTK_NET_LOGGING 
+       if((SOCK_INODE(sock)!= NULL) && (sunaddr != NULL) && (other->sk_socket != NULL) && (SOCK_INODE(other->sk_socket) != NULL))
+  {
+         printk(KERN_INFO "[mtk_net][socket]unix_stream_connect[%lu ]: connect [%s] other[%lu] \n",SOCK_INODE(sock)->i_ino,sunaddr->sun_path,SOCK_INODE(other->sk_socket)->i_ino);
+       }
+  #endif 
+
        other->sk_data_ready(other, 0);
        sock_put(other);
+       
        return 0;
 
 out_unlock:
@@ -1350,6 +1394,7 @@ out:
                unix_release_sock(newsk, 0);
        if (other)
                sock_put(other);
+    
        return err;
 }
 
@@ -1401,7 +1446,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
        /* If socket state is TCP_LISTEN it cannot change (for now...),
         * so that no locks are necessary.
         */
-
+    
        skb = skb_recv_datagram(sk, 0, flags&O_NONBLOCK, &err);
        if (!skb) {
                /* This means receive shutdown. */
@@ -1420,9 +1465,11 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
        unix_sock_inherit_flags(sock, newsock);
        sock_graft(tsk, newsock);
        unix_state_unlock(tsk);
+    
        return 0;
 
 out:
+    
        return err;
 }
 
@@ -1719,7 +1766,12 @@ restart_locked:
                        goto out_unlock;
        }
 
-       if (unlikely(unix_peer(other) != sk && unix_recvq_full(other))) {
+       /* other == sk && unix_peer(other) != sk if
+        * - unix_peer(sk) == NULL, destination address bound to sk
+        * - unix_peer(sk) == sk by time of get but disconnected before lock
+        */
+       if (other != sk &&
+           unlikely(unix_peer(other) != sk && unix_recvq_full(other))) {
                if (timeo) {
                        timeo = unix_wait_for_peer(other, timeo);
 
@@ -1761,6 +1813,7 @@ restart_locked:
        other->sk_data_ready(other, len);
        sock_put(other);
        scm_destroy(siocb->scm);
+    
        return len;
 
 out_unlock:
@@ -1773,6 +1826,7 @@ out:
        if (other)
                sock_put(other);
        scm_destroy(siocb->scm);
+      
        return err;
 }
 
@@ -1792,6 +1846,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
 
        if (NULL == siocb->scm)
                siocb->scm = &tmp_scm;
+               
        wait_for_unix_gc();
        err = scm_send(sock, msg, siocb->scm, false);
        if (err < 0)
@@ -1835,6 +1890,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
 
                skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT,
                                          &err);
+               
 
                if (skb == NULL)
                        goto out_err;
@@ -1868,7 +1924,33 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
 
                if (sock_flag(other, SOCK_DEAD) ||
                    (other->sk_shutdown & RCV_SHUTDOWN))
+               {
+                    if( other->sk_socket )
+                    {
+                        if(sk->sk_socket)
+                        {
+                
+                         #ifdef CONFIG_MTK_NET_LOGGING 
+                         printk(KERN_INFO " [mtk_net][unix]: sendmsg[%lu:%lu]:peer close\n" ,SOCK_INODE(sk->sk_socket)->i_ino,SOCK_INODE(other->sk_socket)->i_ino);
+                                        #endif
+                        }
+                        else{
+                                           #ifdef CONFIG_MTK_NET_LOGGING 
+                                       printk(KERN_INFO " [mtk_net][unix]: sendmsg[null:%lu]:peer close\n" ,SOCK_INODE(other->sk_socket)->i_ino);
+                                       #endif
+                        }        
+
+                   }
+                   else        
+                                       {
+                                               #ifdef CONFIG_MTK_NET_LOGGING   
+                                       printk(KERN_INFO " [mtk_net][unix]: sendmsg:peer close \n" );
+                                       #endif
+                               }
+                               
+          
                        goto pipe_err_free;
+               }
 
                maybe_add_creds(skb, sock, other);
                skb_queue_tail(&other->sk_receive_queue, skb);
@@ -1894,6 +1976,7 @@ pipe_err:
 out_err:
        scm_destroy(siocb->scm);
        siocb->scm = NULL;
+        
        return sent ? : err;
 }
 
@@ -2035,6 +2118,7 @@ out_free:
 out_unlock:
        mutex_unlock(&u->readlock);
 out:
+      
        return err;
 }
 
@@ -2060,7 +2144,7 @@ static long unix_stream_data_wait(struct sock *sk, long timeo,
 
                set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
                unix_state_unlock(sk);
-               timeo = schedule_timeout(timeo);
+               timeo = freezable_schedule_timeout(timeo);
                unix_state_lock(sk);
 
                if (sock_flag(sk, SOCK_DEAD))
@@ -2090,6 +2174,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
        int err = 0;
        long timeo;
        int skip;
+       struct sock * other = unix_peer(sk);
 
        err = -EINVAL;
        if (sk->sk_state != TCP_ESTABLISHED)
@@ -2137,8 +2222,27 @@ again:
                        if (err)
                                goto unlock;
                        if (sk->sk_shutdown & RCV_SHUTDOWN)
+                       {
+                            if(sk && sk->sk_socket )
+                            {
+                                  if(other && other->sk_socket ){
+                                       #ifdef CONFIG_MTK_NET_LOGGING 
+                                       
+                     printk(KERN_INFO " [mtk_net][unix]: recvmsg[%lu:%lu]:exit read due to peer shutdown  \n" ,SOCK_INODE(sk->sk_socket)->i_ino,SOCK_INODE(other->sk_socket)->i_ino);
+                                  #endif
+                                  }else{                                  
+                                       #ifdef CONFIG_MTK_NET_LOGGING                              
+                     printk(KERN_INFO "[mtk_net][unix]: recvmsg[%lu:null]:exit read due to peer shutdown  \n" ,SOCK_INODE(sk->sk_socket)->i_ino);
+                     #endif
+                                  }
+                                }
+                           else{       
+                                       #ifdef CONFIG_MTK_NET_LOGGING 
+                                  printk(KERN_INFO " [mtk_net][unix]: recvmsg: exit read due to peer shutdown \n" );
+                                  #endif
+                           }
                                goto unlock;
-
+                       }
                        unix_state_unlock(sk);
                        err = -EAGAIN;
                        if (!timeo)
@@ -2146,6 +2250,28 @@ again:
                        mutex_unlock(&u->readlock);
 
                        timeo = unix_stream_data_wait(sk, timeo, last);
+                        if (!timeo)
+                        {
+                            if(sk && sk->sk_socket )
+                            {
+                                if(other && other->sk_socket ){
+                                       #ifdef CONFIG_MTK_NET_LOGGING 
+                     printk(KERN_INFO " [mtk_net][unix]: recvmsg[%lu:%lu]:exit read due to timeout  \n" ,SOCK_INODE(sk->sk_socket)->i_ino,SOCK_INODE(other->sk_socket)->i_ino);
+                                  #endif
+                                  }else{                                  
+                                       #ifdef CONFIG_MTK_NET_LOGGING                              
+                     printk(KERN_INFO " [mtk_net][unix]: recvmsg[%lu:null]:exit read due to timeout  \n" ,SOCK_INODE(sk->sk_socket)->i_ino);
+                     #endif
+                                   }                     
+                          }
+                          else 
+                                       {
+                                               #ifdef CONFIG_MTK_NET_LOGGING   
+                                 printk(KERN_INFO " [mtk_net][unix]: recvmsg:exit read due to timeout \n" );
+                                 #endif
+                               }
+                                 
+                        }
 
                        if (signal_pending(current)) {
                                err = sock_intr_errno(timeo);
@@ -2241,6 +2367,7 @@ again:
        mutex_unlock(&u->readlock);
        scm_recv(sock, msg, siocb->scm, flags);
 out:
+  
        return copied ? : err;
 }
 
@@ -2409,12 +2536,17 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
                        mask |= POLLHUP;
                /* connection hasn't started yet? */
                if (sk->sk_state == TCP_SYN_SENT)
+    {
+        
                        return mask;
-       }
+         }
+  }
 
        /* No write status requested, avoid expensive OUT tests. */
        if (!(poll_requested_events(wait) & (POLLWRBAND|POLLWRNORM|POLLOUT)))
+  {     
                return mask;
+  }
 
        writable = unix_writable(sk);
        if (writable) {