Whamcloud - gitweb
LU-9679 general: add missing spaces to folded strings.
[fs/lustre-release.git] / lnet / lnet / acceptor.c
index 8230ceb..94d16fa 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2016, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -44,6 +44,7 @@ static struct {
        int                     pta_shutdown;
        struct socket           *pta_sock;
        struct completion       pta_signal;
+       struct net              *pta_ns;
 } lnet_acceptor_state = {
        .pta_shutdown = 1
 };
@@ -150,15 +151,15 @@ EXPORT_SYMBOL(lnet_connect_console_error);
 
 int
 lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
-           __u32 local_ip, __u32 peer_ip, int peer_port)
+           __u32 local_ip, __u32 peer_ip, int peer_port, struct net *ns)
 {
-       lnet_acceptor_connreq_t cr;
+       struct lnet_acceptor_connreq cr;
        struct socket           *sock;
        int                     rc;
        int                     port;
        int                     fatal;
 
-       CLASSERT(sizeof(cr) <= 16);             /* not too big to be on the stack */
+       BUILD_BUG_ON(sizeof(cr) > 16); /* not too big to be on the stack */
 
        for (port = LNET_ACCEPTOR_MAX_RESERVED_PORT;
             port >= LNET_ACCEPTOR_MIN_RESERVED_PORT;
@@ -167,31 +168,25 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
 
                rc = lnet_sock_connect(&sock, &fatal,
                                         local_ip, port,
-                                        peer_ip, peer_port);
+                                        peer_ip, peer_port, ns);
                if (rc != 0) {
                        if (fatal)
                                goto failed;
                        continue;
                }
 
-               CLASSERT(LNET_PROTO_ACCEPTOR_VERSION == 1);
+               BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
 
                cr.acr_magic   = LNET_PROTO_ACCEPTOR_MAGIC;
                cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
                cr.acr_nid     = peer_nid;
 
-               if (the_lnet.ln_testprotocompat != 0) {
+               if (the_lnet.ln_testprotocompat) {
                        /* single-shot proto check */
-                       lnet_net_lock(LNET_LOCK_EX);
-                       if ((the_lnet.ln_testprotocompat & 4) != 0) {
+                       if (test_and_clear_bit(2, &the_lnet.ln_testprotocompat))
                                cr.acr_version++;
-                               the_lnet.ln_testprotocompat &= ~4;
-                       }
-                       if ((the_lnet.ln_testprotocompat & 8) != 0) {
+                       if (test_and_clear_bit(3, &the_lnet.ln_testprotocompat))
                                cr.acr_magic = LNET_PROTO_MAGIC;
-                               the_lnet.ln_testprotocompat &= ~8;
-                       }
-                       lnet_net_unlock(LNET_LOCK_EX);
                }
 
                rc = lnet_sock_write(sock, &cr, sizeof(cr),
@@ -217,12 +212,12 @@ EXPORT_SYMBOL(lnet_connect);
 static int
 lnet_accept(struct socket *sock, __u32 magic)
 {
-       lnet_acceptor_connreq_t cr;
+       struct lnet_acceptor_connreq cr;
        __u32                   peer_ip;
        int                     peer_port;
        int                     rc;
        int                     flip;
-       lnet_ni_t              *ni;
+       struct lnet_ni *ni;
        char                   *str;
 
        LASSERT(sizeof(cr) <= 16);              /* not too big for the stack */
@@ -245,13 +240,12 @@ lnet_accept(struct socket *sock, __u32 magic)
                                               accept_timeout);
 
                        if (rc != 0)
-                               CERROR("Error sending magic+version in response"
-                                      "to LNET magic from %pI4h: %d\n",
+                               CERROR("Error sending magic+version in response to LNET magic from %pI4h: %d\n",
                                       &peer_ip, rc);
                        return -EPROTO;
                }
 
-               if (magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC))
+               if (lnet_accept_magic(magic, LNET_PROTO_TCP_MAGIC))
                        str = "'old' socknal/tcpnal";
                else
                        str = "unrecognised";
@@ -291,15 +285,14 @@ lnet_accept(struct socket *sock, __u32 magic)
                                       accept_timeout);
 
                if (rc != 0)
-                       CERROR("Error sending magic+version in response"
-                              "to version %d from %pI4h: %d\n",
+                       CERROR("Error sending magic+version in response to version %d from %pI4h: %d\n",
                               peer_version, &peer_ip, rc);
                return -EPROTO;
        }
 
        rc = lnet_sock_read(sock, &cr.acr_nid,
                              sizeof(cr) -
-                             offsetof(lnet_acceptor_connreq_t, acr_nid),
+                             offsetof(struct lnet_acceptor_connreq, acr_nid),
                              accept_timeout);
        if (rc != 0) {
                CERROR("Error %d reading connection request from "
@@ -354,7 +347,8 @@ lnet_acceptor(void *arg)
        cfs_block_allsigs();
 
        rc = lnet_sock_listen(&lnet_acceptor_state.pta_sock,
-                               0, accept_port, accept_backlog);
+                             0, accept_port, accept_backlog,
+                             lnet_acceptor_state.pta_ns);
        if (rc != 0) {
                if (rc == -EADDRINUSE)
                        LCONSOLE_ERROR_MSG(0x122, "Can't start acceptor on port"
@@ -478,13 +472,15 @@ lnet_acceptor_start(void)
 
        if (lnet_count_acceptor_nets() == 0)  /* not required */
                return 0;
-
+       if (current->nsproxy && current->nsproxy->net_ns)
+               lnet_acceptor_state.pta_ns = current->nsproxy->net_ns;
+       else
+               lnet_acceptor_state.pta_ns = &init_net;
        task = kthread_run(lnet_acceptor, (void *)(uintptr_t)secure,
                           "acceptor_%03ld", secure);
        if (IS_ERR(task)) {
                rc2 = PTR_ERR(task);
                CERROR("Can't start acceptor thread: %ld\n", rc2);
-
                return -ESRCH;
        }