Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lnet / lnet / acceptor.c
index 717058c..008e8b7 100644 (file)
@@ -1,23 +1,37 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2005 Cluster File Systems, Inc.
+ * GPL HEADER START
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   Lustre is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   Lustre is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
@@ -147,35 +161,28 @@ lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
 
                 CLASSERT (LNET_PROTO_ACCEPTOR_VERSION == 1);
 
-                if (the_lnet.ln_ptlcompat != 2) {
-                        /* When portals compatibility is "strong", simply
-                         * connect (i.e. send no acceptor connection request).
-                         * Othewise send an acceptor connection request. I can
-                         * have no portals peers so everyone else should
-                         * understand my protocol. */
-                        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) {
-                                /* single-shot proto check */
-                                LNET_LOCK();
-                                if ((the_lnet.ln_testprotocompat & 4) != 0) {
-                                        cr.acr_version++;
-                                        the_lnet.ln_testprotocompat &= ~4;
-                                }
-                                if ((the_lnet.ln_testprotocompat & 8) != 0) {
-                                        cr.acr_magic = LNET_PROTO_MAGIC;
-                                        the_lnet.ln_testprotocompat &= ~8;
-                                }
-                                LNET_UNLOCK();
+                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) {
+                        /* single-shot proto check */
+                        LNET_LOCK();
+                        if ((the_lnet.ln_testprotocompat & 4) != 0) {
+                                cr.acr_version++;
+                                the_lnet.ln_testprotocompat &= ~4;
                         }
-
-                        rc = libcfs_sock_write(sock, &cr, sizeof(cr),
-                                               accept_timeout);
-                        if (rc != 0)
-                                goto failed_sock;
+                        if ((the_lnet.ln_testprotocompat & 8) != 0) {
+                                cr.acr_magic = LNET_PROTO_MAGIC;
+                                the_lnet.ln_testprotocompat &= ~8;
+                        }
+                        LNET_UNLOCK();
                 }
+
+                rc = libcfs_sock_write(sock, &cr, sizeof(cr),
+                                       accept_timeout);
+                if (rc != 0)
+                        goto failed_sock;
                 
                 *sockp = sock;
                 return 0;
@@ -200,7 +207,7 @@ lnet_accept_magic(__u32 magic, __u32 constant)
 }
 
 int
-lnet_accept(lnet_ni_t *blind_ni, cfs_socket_t *sock, __u32 magic)
+lnet_accept(cfs_socket_t *sock, __u32 magic)
 {
         lnet_acceptor_connreq_t cr;
         __u32                   peer_ip;
@@ -210,10 +217,6 @@ lnet_accept(lnet_ni_t *blind_ni, cfs_socket_t *sock, __u32 magic)
         lnet_ni_t              *ni;
         char                   *str;
 
-        /* CAVEAT EMPTOR: I may be called by an LND in any thread's context if
-         * I passed the new socket "blindly" to the single NI that needed an
-         * acceptor.  If so, blind_ni != NULL... */
-
         LASSERT (sizeof(cr) <= 16);             /* not too big for the stack */
         
         rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
@@ -323,25 +326,13 @@ lnet_accept(lnet_ni_t *blind_ni, cfs_socket_t *sock, __u32 magic)
                 return -EPERM;
         }
 
-        CDEBUG(D_NET, "Accept %s from %u.%u.%u.%u%s\n",
-               libcfs_nid2str(cr.acr_nid), HIPQUAD(peer_ip),
-               blind_ni == NULL ? "" : " (blind)");
-
-        if (blind_ni == NULL) {
-                /* called by the acceptor: call into the requested NI... */
-                rc = ni->ni_lnd->lnd_accept(ni, sock);
-        } else {
-                /* portals_compatible set and the (only) NI called me to verify
-                 * and skip the connection request... */
-                LASSERT (the_lnet.ln_ptlcompat != 0);
-                LASSERT (ni == blind_ni);
-                rc = 0;
-        }
+        CDEBUG(D_NET, "Accept %s from %u.%u.%u.%u\n",
+               libcfs_nid2str(cr.acr_nid), HIPQUAD(peer_ip));
 
+        rc = ni->ni_lnd->lnd_accept(ni, sock);
         lnet_ni_decref(ni);
         return rc;
 }
-EXPORT_SYMBOL(lnet_accept);
         
 int
 lnet_acceptor(void *arg)
@@ -349,26 +340,13 @@ lnet_acceptor(void *arg)
        char           name[16];
        cfs_socket_t  *newsock;
        int            rc;
-        int            n_acceptor_nis;
        __u32          magic;
        __u32          peer_ip;
        int            peer_port;
-        lnet_ni_t     *blind_ni = NULL;
         int            secure = (int)((unsigned long)arg);
 
        LASSERT (lnet_acceptor_state.pta_sock == NULL);
 
-        if (the_lnet.ln_ptlcompat != 0) {
-                /* When portals_compatibility is enabled, peers may connect
-                 * without sending an acceptor connection request.  There is no
-                 * ambiguity about which network the peer wants to connect to
-                 * since there can only be 1 network, so I pass connections
-                 * "blindly" to it. */
-                n_acceptor_nis = lnet_count_acceptor_nis(&blind_ni);
-                LASSERT (n_acceptor_nis == 1);
-                LASSERT (blind_ni != NULL);
-        }
-
        snprintf(name, sizeof(name), "acceptor_%03d", accept_port);
        cfs_daemonize(name);
        cfs_block_allsigs();
@@ -387,9 +365,7 @@ lnet_acceptor(void *arg)
 
                lnet_acceptor_state.pta_sock = NULL;
         } else {
-                LCONSOLE(0, "Accept %s, port %d%s\n", 
-                         accept, accept_port,
-                         blind_ni == NULL ? "" : " (proto compatible)");
+                LCONSOLE(0, "Accept %s, port %d\n", accept, accept_port);
         }
         
        /* set init status and unblock parent */
@@ -399,7 +375,7 @@ lnet_acceptor(void *arg)
        if (rc != 0)
                return rc;
 
-       while (lnet_acceptor_state.pta_shutdown == 0) {
+       while (!lnet_acceptor_state.pta_shutdown) {
                
                rc = libcfs_sock_accept(&newsock, lnet_acceptor_state.pta_sock);
                if (rc != 0) {
@@ -423,18 +399,6 @@ lnet_acceptor(void *arg)
                         goto failed;
                 }
 
-                if (blind_ni != NULL) {
-                        rc = blind_ni->ni_lnd->lnd_accept(blind_ni, newsock);
-                        if (rc != 0) {
-                                CERROR("NI %s refused 'blind' connection from "
-                                       "%u.%u.%u.%u\n", 
-                                       libcfs_nid2str(blind_ni->ni_nid), 
-                                       HIPQUAD(peer_ip));
-                                goto failed;
-                        }
-                        continue;
-                }
-                
                rc = libcfs_sock_read(newsock, &magic, sizeof(magic),
                                      accept_timeout);
                if (rc != 0) {
@@ -443,7 +407,7 @@ lnet_acceptor(void *arg)
                        goto failed;
                }
 
-                rc = lnet_accept(NULL, newsock, magic);
+                rc = lnet_accept(newsock, magic);
                 if (rc != 0)
                         goto failed;
                 
@@ -456,10 +420,7 @@ lnet_acceptor(void *arg)
        libcfs_sock_release(lnet_acceptor_state.pta_sock);
         lnet_acceptor_state.pta_sock = NULL;
 
-        if (blind_ni != NULL)
-                lnet_ni_decref(blind_ni);
-
-        LCONSOLE(0,"Acceptor stopping\n");
+        LCONSOLE(0, "Acceptor stopping\n");
        
        /* unblock lnet_acceptor_stop() */
        mutex_up(&lnet_acceptor_state.pta_signal);
@@ -487,7 +448,7 @@ lnet_acceptor_start(void)
                 return -EINVAL;
         }
        
-       if (lnet_count_acceptor_nis(NULL) == 0)  /* not required */
+       if (lnet_count_acceptor_nis() == 0)  /* not required */
                return 0;
        
        pid = cfs_kernel_thread(lnet_acceptor, (void *)secure, 0);
@@ -498,7 +459,7 @@ lnet_acceptor_start(void)
 
        mutex_down(&lnet_acceptor_state.pta_signal); /* wait for acceptor to startup */
 
-       if (lnet_acceptor_state.pta_shutdown == 0) {
+       if (!lnet_acceptor_state.pta_shutdown) {
                 /* started OK */
                 LASSERT (lnet_acceptor_state.pta_sock != NULL);
                return 0;
@@ -574,7 +535,7 @@ lnet_parse_string_tunable(char **value, char *name, char *dflt)
 }
 
 int
-lnet_get_tunables()
+lnet_acceptor_get_tunables()
 {
         int rc;
         rc = lnet_parse_string_tunable(&accept_type, "LNET_ACCEPT", "secure");
@@ -691,9 +652,9 @@ int
 lnet_acceptor(void *arg)
 {
         char           name[16];
-        int secure = (int)((unsigned long)arg);
-        int rc;
-        int newsock;
+        int            secure = (int)((unsigned long)arg);
+        int            rc;
+        int            newsock;
         __u32          peer_ip;
         int            peer_port;
         __u32          magic;
@@ -725,7 +686,7 @@ lnet_acceptor(void *arg)
         if (rc != 0)
                 return rc;
 
-        while (lnet_acceptor_state.pta_shutdown == 0) {
+        while (!lnet_acceptor_state.pta_shutdown) {
 
                 rc = libcfs_sock_accept(&newsock, lnet_acceptor_state.pta_sock,
                                         &peer_ip, &peer_port);
@@ -733,7 +694,7 @@ lnet_acceptor(void *arg)
                         continue;
 
                 /* maybe we're waken up with libcfs_sock_abort_accept() */
-                if ( lnet_acceptor_state.pta_shutdown ) {
+                if (lnet_acceptor_state.pta_shutdown) {
                         close(newsock);
                         break;
                 }
@@ -780,14 +741,14 @@ lnet_acceptor_start(void)
         long   secure;
         int rc;
 
+        rc = lnet_acceptor_get_tunables();
+        if (rc != 0)
+                return rc;
+
         /* Do nothing if we're liblustre clients */
-        if (the_lnet.ln_pid & LNET_PID_USERFLAG)
+        if ((the_lnet.ln_pid & LNET_PID_USERFLAG) != 0)
                 return 0;
-        
-        rc = lnet_get_tunables();
-        if ( rc !=0 )
-                return rc;
-                
+                        
         cfs_init_completion(&lnet_acceptor_state.pta_completion);
 
         if (!strcmp(accept_type, "secure")) {
@@ -795,6 +756,7 @@ lnet_acceptor_start(void)
         } else if (!strcmp(accept_type, "all")) {
                 secure = 0;
         } else if (!strcmp(accept_type, "none")) {
+                skip_waiting_for_completion = 1;
                 return 0;
         } else {
                 LCONSOLE_ERROR ("Can't parse 'accept_type=\"%s\"'\n", accept_type);
@@ -802,13 +764,13 @@ lnet_acceptor_start(void)
                 return -EINVAL;
         }
 
-        if (lnet_count_acceptor_nis(NULL) == 0) { /* not required */
+        if (lnet_count_acceptor_nis() == 0) { /* not required */
                 skip_waiting_for_completion = 1;
                 return 0;
         }
 
         rc = cfs_create_thread(lnet_acceptor, (void *)secure);
-        if (rc) {
+        if (rc != 0) {
                 CERROR("Can't start acceptor thread: %d\n", rc);
                 cfs_fini_completion(&lnet_acceptor_state.pta_completion);
                 return rc;
@@ -817,7 +779,7 @@ lnet_acceptor_start(void)
         /* wait for acceptor to startup */
         cfs_wait_for_completion(&lnet_acceptor_state.pta_completion);
 
-        if (lnet_acceptor_state.pta_shutdown == 0)
+        if (!lnet_acceptor_state.pta_shutdown)
                 return 0;
         
         cfs_fini_completion(&lnet_acceptor_state.pta_completion);
@@ -828,10 +790,10 @@ void
 lnet_acceptor_stop(void)
 {
         /* Do nothing if we're liblustre clients */
-        if (the_lnet.ln_pid & LNET_PID_USERFLAG)
+        if ((the_lnet.ln_pid & LNET_PID_USERFLAG) != 0)
                 return;
 
-        if ( !skip_waiting_for_completion ) {
+        if (!skip_waiting_for_completion) {
                 lnet_acceptor_state.pta_shutdown = 1;
                 libcfs_sock_abort_accept(accept_port);