Whamcloud - gitweb
LU-6002 lnet: startup acceptor thread dynamically
[fs/lustre-release.git] / lnet / lnet / acceptor.c
index 9bdac05..6bb9f85 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -43,11 +43,13 @@ static int   accept_port    = 988;
 static int   accept_backlog = 127;
 static int   accept_timeout = 5;
 
-struct {
+static struct {
        int                     pta_shutdown;
        cfs_socket_t            *pta_sock;
        struct completion       pta_signal;
-} lnet_acceptor_state;
+} lnet_acceptor_state = {
+       .pta_shutdown = 1
+};
 
 int
 lnet_acceptor_port(void)
@@ -79,7 +81,7 @@ CFS_MODULE_PARM(accept_timeout, "i", int, 0644,
 
 static char *accept_type = NULL;
 
-int
+static int
 lnet_acceptor_get_tunables(void)
 {
         /* Userland acceptor uses 'accept_type' instead of 'accept', due to
@@ -259,7 +261,7 @@ lnet_acceptor_get_tunables()
 
 /* Below is the code common for both kernel and MT user-space */
 
-int
+static int
 lnet_accept(cfs_socket_t *sock, __u32 magic)
 {
         lnet_acceptor_connreq_t cr;
@@ -386,7 +388,7 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
         return rc;
 }
 
-int
+static int
 lnet_acceptor(void *arg)
 {
         cfs_socket_t  *newsock;
@@ -503,10 +505,15 @@ accept2secure(const char *acc, long *sec)
 int
 lnet_acceptor_start(void)
 {
+       struct task_struct *task;
         int  rc;
         long rc2;
         long secure;
 
+       /* if acceptor is already running return immediately */
+       if (!lnet_acceptor_state.pta_shutdown)
+               return 0;
+
         LASSERT (lnet_acceptor_state.pta_sock == NULL);
 
         rc = lnet_acceptor_get_tunables();
@@ -529,10 +536,10 @@ lnet_acceptor_start(void)
        if (lnet_count_acceptor_nis() == 0)  /* not required */
                return 0;
 
-       rc2 = PTR_ERR(kthread_run(lnet_acceptor,
-                                 (void *)(ulong_ptr_t)secure,
-                                 "acceptor_%03ld", secure));
-       if (IS_ERR_VALUE(rc2)) {
+       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);
 
@@ -557,7 +564,7 @@ lnet_acceptor_start(void)
 void
 lnet_acceptor_stop(void)
 {
-       if (lnet_acceptor_state.pta_sock == NULL) /* not running */
+       if (lnet_acceptor_state.pta_shutdown) /* not running */
                return;
 
        lnet_acceptor_state.pta_shutdown = 1;