Whamcloud - gitweb
- added a comment on a Darwin quirk.
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd.c
index aece49f..360f905 100644 (file)
@@ -1,26 +1,44 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
- *   Author: Zach Brown <zab@zabbo.net>
- *   Author: Peter J. Braam <braam@clusterfs.com>
- *   Author: Phil Schwan <phil@clusterfs.com>
- *   Author: Eric Barton <eric@bartonsoftware.com>
+ * GPL HEADER START
  *
- *   This file is part of Portals, http://www.sf.net/projects/sandiaportals/
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   Portals 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.
  *
- *   Portals 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 Portals; 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.
+ *
+ * lnet/klnds/socklnd/socklnd.c
+ *
+ * Author: Zach Brown <zab@zabbo.net>
+ * Author: Peter J. Braam <braam@clusterfs.com>
+ * Author: Phil Schwan <phil@clusterfs.com>
+ * Author: Eric Barton <eric@bartonsoftware.com>
  */
 
 #include "socklnd.h"
@@ -211,12 +229,20 @@ ksocknal_unlink_peer_locked (ksock_peer_t *peer)
 {
         int                i;
         __u32              ip;
+        ksock_interface_t *iface;
 
         for (i = 0; i < peer->ksnp_n_passive_ips; i++) {
                 LASSERT (i < LNET_MAX_INTERFACES);
                 ip = peer->ksnp_passive_ips[i];
 
-                ksocknal_ip2iface(peer->ksnp_ni, ip)->ksni_npeers--;
+                iface = ksocknal_ip2iface(peer->ksnp_ni, ip);
+                /* All IPs in peer->ksnp_passive_ips[] come from the
+                 * interface list, therefore the call must succeed. */
+                LASSERT (iface != NULL);
+
+                CDEBUG(D_NET, "peer=%p iface=%p ksni_nroutes=%d\n",
+                       peer, iface, iface->ksni_nroutes);
+                iface->ksni_npeers--;
         }
 
         LASSERT (list_empty(&peer->ksnp_conns));
@@ -1037,7 +1063,9 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
         conn->ksnc_peer = NULL;
         conn->ksnc_route = NULL;
         conn->ksnc_sock = sock;
-        atomic_set (&conn->ksnc_sock_refcount, 1); /* 1 ref for conn */
+        /* 2 ref, 1 for conn, another extra ref prevents socket
+         * being closed before establishment of connection */
+        atomic_set (&conn->ksnc_sock_refcount, 2);
         conn->ksnc_type = type;
         ksocknal_lib_save_callback(sock, conn);
         atomic_set (&conn->ksnc_conn_refcount, 1); /* 1 ref for me */
@@ -1154,7 +1182,7 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
                 goto failed_2;
         }
 
-        if (peer->ksnp_proto == NULL) { 
+        if (peer->ksnp_proto == NULL) {
                 /* Never connected before.
                  * NB recv_hello may have returned EPROTO to signal my peer
                  * wants a different protocol than the one I asked for.
@@ -1328,6 +1356,7 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
                 ksocknal_connsock_decref(conn);
         }
 
+        ksocknal_connsock_decref(conn);
         ksocknal_conn_decref(conn);
         return rc;
 
@@ -1477,6 +1506,41 @@ ksocknal_peer_failed (ksock_peer_t *peer)
 }
 
 void
+ksocknal_finalize_zcreq(ksock_conn_t *conn)
+{
+        ksock_peer_t     *peer = conn->ksnc_peer;
+        ksock_tx_t       *tx;
+        ksock_tx_t       *tmp;
+        CFS_LIST_HEAD    (zlist);
+
+        /* NB safe to finalize TXs because closing of socket will
+         * abort all buffered data */
+        LASSERT (conn->ksnc_sock == NULL);
+
+        spin_lock(&peer->ksnp_lock);
+
+        list_for_each_entry_safe(tx, tmp, &peer->ksnp_zc_req_list, tx_zc_list) {
+                if (tx->tx_conn != conn)
+                        continue;
+
+                LASSERT (tx->tx_msg.ksm_zc_req_cookie != 0);
+
+                tx->tx_msg.ksm_zc_req_cookie = 0;
+                list_del(&tx->tx_zc_list);
+                list_add(&tx->tx_zc_list, &zlist);
+        }
+
+        spin_unlock(&peer->ksnp_lock);
+
+        while (!list_empty(&zlist)) {
+                tx = list_entry(zlist.next, ksock_tx_t, tx_zc_list);
+
+                list_del(&tx->tx_zc_list);
+                ksocknal_tx_decref(tx);
+        }
+}
+
+void
 ksocknal_terminate_conn (ksock_conn_t *conn)
 {
         /* This gets called by the reaper (guaranteed thread context) to
@@ -1486,22 +1550,19 @@ ksocknal_terminate_conn (ksock_conn_t *conn)
         ksock_peer_t     *peer = conn->ksnc_peer;
         ksock_sched_t    *sched = conn->ksnc_scheduler;
         int               failed = 0;
-        struct list_head *tmp;
-        struct list_head *nxt;
-        ksock_tx_t       *tx;
-        LIST_HEAD        (zlist);
 
         LASSERT(conn->ksnc_closing);
 
         /* wake up the scheduler to "send" all remaining packets to /dev/null */
         spin_lock_bh (&sched->kss_lock);
 
+        /* a closing conn is always ready to tx */
+        conn->ksnc_tx_ready = 1;
+
         if (!conn->ksnc_tx_scheduled &&
             !list_empty(&conn->ksnc_tx_queue)){
                 list_add_tail (&conn->ksnc_tx_list,
                                &sched->kss_tx_conns);
-                /* a closing conn is always ready to tx */
-                conn->ksnc_tx_ready = 1;
                 conn->ksnc_tx_scheduled = 1;
                 /* extra ref for scheduler */
                 ksocknal_conn_addref(conn);
@@ -1511,30 +1572,6 @@ ksocknal_terminate_conn (ksock_conn_t *conn)
 
         spin_unlock_bh (&sched->kss_lock);
 
-        spin_lock(&peer->ksnp_lock);
-
-        list_for_each_safe(tmp, nxt, &peer->ksnp_zc_req_list) {
-                tx = list_entry(tmp, ksock_tx_t, tx_zc_list);
-
-                if (tx->tx_conn != conn)
-                        continue;
-
-                LASSERT (tx->tx_msg.ksm_zc_req_cookie != 0);
-
-                tx->tx_msg.ksm_zc_req_cookie = 0;
-                list_del(&tx->tx_zc_list);
-                list_add(&tx->tx_zc_list, &zlist);
-        }
-
-        spin_unlock(&peer->ksnp_lock);
-
-        list_for_each_safe(tmp, nxt, &zlist) {
-                tx = list_entry(tmp, ksock_tx_t, tx_zc_list);
-
-                list_del(&tx->tx_zc_list);
-                ksocknal_tx_decref(tx);
-        }
-
         /* serialise with callbacks */
         write_lock_bh (&ksocknal_data.ksnd_global_lock);
 
@@ -2568,7 +2605,7 @@ ksocknal_module_init (void)
         return 0;
 }
 
-MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
+MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
 MODULE_DESCRIPTION("Kernel TCP Socket LND v2.0.0");
 MODULE_LICENSE("GPL");