Whamcloud - gitweb
LU-8106 lnet: Do not drop message when shutting down LNet
[fs/lustre-release.git] / lnet / lnet / lib-socket.c
index 80ca9a7..83d6790 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -35,6 +35,9 @@
  */
 #define DEBUG_SUBSYSTEM S_LNET
 
+#ifdef HAVE_COMPAT_RDMA
+#include <linux/compat-2.6.h>
+#endif
 #include <linux/if.h>
 #include <linux/in.h>
 #include <linux/net.h>
@@ -89,8 +92,8 @@ lnet_sock_ioctl(int cmd, unsigned long arg)
        sock_filp = sock_alloc_file(sock, 0);
 # endif
 #endif
-       if (!sock_filp) {
-               rc = -ENOMEM;
+       if (IS_ERR(sock_filp)) {
+               rc = PTR_ERR(sock_filp);
                sock_release(sock);
                goto out;
        }
@@ -554,6 +557,13 @@ lnet_sock_listen(struct socket **sockp,
        return rc;
 }
 
+#ifndef HAVE_SK_SLEEP
+static inline wait_queue_head_t *sk_sleep(struct sock *sk)
+{
+       return sk->sk_sleep;
+}
+#endif
+
 int
 lnet_sock_accept(struct socket **newsockp, struct socket *sock)
 {
@@ -561,8 +571,6 @@ lnet_sock_accept(struct socket **newsockp, struct socket *sock)
        struct socket *newsock;
        int            rc;
 
-       init_waitqueue_entry(&wait, current);
-
        /* XXX this should add a ref to sock->ops->owner, if
         * TCP could be a module */
        rc = sock_create_lite(PF_PACKET, sock->type, IPPROTO_TCP, &newsock);
@@ -572,18 +580,18 @@ lnet_sock_accept(struct socket **newsockp, struct socket *sock)
        }
 
        newsock->ops = sock->ops;
-       add_wait_queue(sk_sleep(sock->sk), &wait);
 
        rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
        if (rc == -EAGAIN) {
                /* Nothing ready, so wait for activity */
+               init_waitqueue_entry(&wait, current);
+               add_wait_queue(sk_sleep(sock->sk), &wait);
+               set_current_state(TASK_INTERRUPTIBLE);
                schedule();
+               remove_wait_queue(sk_sleep(sock->sk), &wait);
                rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
        }
 
-       remove_wait_queue(sk_sleep(sock->sk), &wait);
-       set_current_state(TASK_RUNNING);
-
        if (rc != 0)
                goto failed;