Whamcloud - gitweb
LU-5935 lnet: Fixes to make lnetctl function as expected.
[fs/lustre-release.git] / lnet / lnet / acceptor.c
index cf0a56a..c83843c 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -44,13 +44,9 @@ static int   accept_backlog = 127;
 static int   accept_timeout = 5;
 
 struct {
-        int                   pta_shutdown;
-        cfs_socket_t         *pta_sock;
-#ifdef __KERNEL__
-        cfs_completion_t      pta_signal;
-#else
-        cfs_mt_completion_t   pta_signal;
-#endif
+       int                     pta_shutdown;
+       cfs_socket_t            *pta_sock;
+       struct completion       pta_signal;
 } lnet_acceptor_state;
 
 int
@@ -68,12 +64,6 @@ lnet_accept_magic(__u32 magic, __u32 constant)
 
 #ifdef __KERNEL__
 
-#define cfs_mt_init_completion(c)     cfs_init_completion(c)
-#define cfs_mt_wait_for_completion(c) cfs_wait_for_completion(c)
-#define cfs_mt_complete(c)            cfs_complete(c)
-#define cfs_mt_fini_completion(c)     cfs_fini_completion(c)
-#define cfs_create_thread(func, a)    cfs_kernel_thread(func, a, 0)
-
 EXPORT_SYMBOL(lnet_acceptor_port);
 
 static char *accept = "secure";
@@ -113,25 +103,24 @@ lnet_connect_console_error (int rc, lnet_nid_t peer_nid,
         switch (rc) {
         /* "normal" errors */
         case -ECONNREFUSED:
-                CDEBUG(D_NETERROR, "Connection to %s at host %u.%u.%u.%u "
-                       "on port %d was refused: "
-                       "check that Lustre is running on that node.\n",
-                       libcfs_nid2str(peer_nid),
-                       HIPQUAD(peer_ip), peer_port);
+                CNETERR("Connection to %s at host %u.%u.%u.%u on port %d was "
+                        "refused: check that Lustre is running on that node.\n",
+                        libcfs_nid2str(peer_nid),
+                        HIPQUAD(peer_ip), peer_port);
                 break;
         case -EHOSTUNREACH:
         case -ENETUNREACH:
-                CDEBUG(D_NETERROR, "Connection to %s at host %u.%u.%u.%u "
-                       "was unreachable: the network or that node may "
-                       "be down, or Lustre may be misconfigured.\n",
-                       libcfs_nid2str(peer_nid), HIPQUAD(peer_ip));
+                CNETERR("Connection to %s at host %u.%u.%u.%u "
+                        "was unreachable: the network or that node may "
+                        "be down, or Lustre may be misconfigured.\n",
+                        libcfs_nid2str(peer_nid), HIPQUAD(peer_ip));
                 break;
         case -ETIMEDOUT:
-                CDEBUG(D_NETERROR, "Connection to %s at host %u.%u.%u.%u on "
-                       "port %d took too long: that node may be hung "
-                       "or experiencing high load.\n",
-                       libcfs_nid2str(peer_nid),
-                       HIPQUAD(peer_ip), peer_port);
+                CNETERR("Connection to %s at host %u.%u.%u.%u on "
+                        "port %d took too long: that node may be hung "
+                        "or experiencing high load.\n",
+                        libcfs_nid2str(peer_nid),
+                        HIPQUAD(peer_ip), peer_port);
                 break;
         case -ECONNRESET:
                 LCONSOLE_ERROR_MSG(0x11b, "Connection to %s at host %u.%u.%u.%u"
@@ -199,7 +188,7 @@ lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
 
                 if (the_lnet.ln_testprotocompat != 0) {
                         /* single-shot proto check */
-                        LNET_LOCK();
+                       lnet_net_lock(LNET_LOCK_EX);
                         if ((the_lnet.ln_testprotocompat & 4) != 0) {
                                 cr.acr_version++;
                                 the_lnet.ln_testprotocompat &= ~4;
@@ -208,7 +197,7 @@ lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
                                 cr.acr_magic = LNET_PROTO_MAGIC;
                                 the_lnet.ln_testprotocompat &= ~8;
                         }
-                        LNET_UNLOCK();
+                       lnet_net_unlock(LNET_LOCK_EX);
                 }
 
                 rc = libcfs_sock_write(sock, &cr, sizeof(cr),
@@ -400,7 +389,6 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
 int
 lnet_acceptor(void *arg)
 {
-        char           name[16];
         cfs_socket_t  *newsock;
         int            rc;
         __u32          magic;
@@ -410,8 +398,6 @@ lnet_acceptor(void *arg)
 
         LASSERT (lnet_acceptor_state.pta_sock == NULL);
 
-        snprintf(name, sizeof(name), "acceptor_%03d", accept_port);
-        cfs_daemonize(name);
         cfs_block_allsigs();
 
         rc = libcfs_sock_listen(&lnet_acceptor_state.pta_sock,
@@ -431,9 +417,9 @@ lnet_acceptor(void *arg)
                 LCONSOLE(0, "Accept %s, port %d\n", accept_type, accept_port);
         }
 
-        /* set init status and unblock parent */
-        lnet_acceptor_state.pta_shutdown = rc;
-        cfs_mt_complete(&lnet_acceptor_state.pta_signal);
+       /* set init status and unblock parent */
+       lnet_acceptor_state.pta_shutdown = rc;
+       complete(&lnet_acceptor_state.pta_signal);
 
         if (rc != 0)
                 return rc;
@@ -489,11 +475,11 @@ lnet_acceptor(void *arg)
         libcfs_sock_release(lnet_acceptor_state.pta_sock);
         lnet_acceptor_state.pta_sock = NULL;
 
-        LCONSOLE(0, "Acceptor stopping\n");
+        CDEBUG(D_NET, "Acceptor stopping\n");
 
-        /* unblock lnet_acceptor_stop() */
-        cfs_mt_complete(&lnet_acceptor_state.pta_signal);
-        return 0;
+       /* unblock lnet_acceptor_stop() */
+       complete(&lnet_acceptor_state.pta_signal);
+       return 0;
 }
 
 static inline int
@@ -517,6 +503,7 @@ accept2secure(const char *acc, long *sec)
 int
 lnet_acceptor_start(void)
 {
+       struct task_struct *task;
         int  rc;
         long rc2;
         long secure;
@@ -533,59 +520,61 @@ lnet_acceptor_start(void)
                 return 0;
 #endif
 
-        cfs_mt_init_completion(&lnet_acceptor_state.pta_signal);
-        rc = accept2secure(accept_type, &secure);
-        if (rc <= 0) {
-                cfs_mt_fini_completion(&lnet_acceptor_state.pta_signal);
-                return rc;
-        }
+       init_completion(&lnet_acceptor_state.pta_signal);
+       rc = accept2secure(accept_type, &secure);
+       if (rc <= 0) {
+               fini_completion(&lnet_acceptor_state.pta_signal);
+               return rc;
+       }
 
-        if (lnet_count_acceptor_nis() == 0)  /* not required */
-                return 0;
+       if (lnet_count_acceptor_nis() == 0)  /* not required */
+               return 0;
 
-        rc2 = cfs_create_thread(lnet_acceptor, (void *)(ulong_ptr_t)secure);
-        if (rc2 < 0) {
-                CERROR("Can't start acceptor thread: %d\n", rc);
-                cfs_mt_fini_completion(&lnet_acceptor_state.pta_signal);
+       task = kthread_run(lnet_acceptor, (void *)(ulong_ptr_t)secure,
+                          "acceptor_%03ld", secure);
+       if (IS_ERR(task)) {
+               rc2 = PTR_ERR(task);
+               CERROR("Can't start acceptor thread: %ld\n", rc2);
+               fini_completion(&lnet_acceptor_state.pta_signal);
 
-                return -ESRCH;
-        }
+               return -ESRCH;
+       }
 
-        /* wait for acceptor to startup */
-        cfs_mt_wait_for_completion(&lnet_acceptor_state.pta_signal);
+       /* wait for acceptor to startup */
+       wait_for_completion(&lnet_acceptor_state.pta_signal);
 
-        if (!lnet_acceptor_state.pta_shutdown) {
-                /* started OK */
-                LASSERT (lnet_acceptor_state.pta_sock != NULL);
-                return 0;
-        }
+       if (!lnet_acceptor_state.pta_shutdown) {
+               /* started OK */
+               LASSERT(lnet_acceptor_state.pta_sock != NULL);
+               return 0;
+       }
 
-        LASSERT (lnet_acceptor_state.pta_sock == NULL);
-        cfs_mt_fini_completion(&lnet_acceptor_state.pta_signal);
+       LASSERT(lnet_acceptor_state.pta_sock == NULL);
+       fini_completion(&lnet_acceptor_state.pta_signal);
 
-        return -ENETDOWN;
+       return -ENETDOWN;
 }
 
 void
 lnet_acceptor_stop(void)
 {
-        if (lnet_acceptor_state.pta_sock == NULL) /* not running */
-                return;
+       if (lnet_acceptor_state.pta_sock == NULL) /* not running */
+               return;
 
-        lnet_acceptor_state.pta_shutdown = 1;
-        libcfs_sock_abort_accept(lnet_acceptor_state.pta_sock);
+       lnet_acceptor_state.pta_shutdown = 1;
+       libcfs_sock_abort_accept(lnet_acceptor_state.pta_sock);
 
-        /* block until acceptor signals exit */
-        cfs_mt_wait_for_completion(&lnet_acceptor_state.pta_signal);
+       /* block until acceptor signals exit */
+       wait_for_completion(&lnet_acceptor_state.pta_signal);
 
-        cfs_mt_fini_completion(&lnet_acceptor_state.pta_signal);
+       fini_completion(&lnet_acceptor_state.pta_signal);
 }
 
 #else /* single-threaded user-space */
 int
 lnet_acceptor_start(void)
 {
-        return 0;
+       return 0;
 }
 
 void