Whamcloud - gitweb
i=liang,b=13065:
[fs/lustre-release.git] / lnet / include / lnet / lib-lnet.h
index 700059c..87a29c7 100644 (file)
@@ -1,7 +1,39 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * lib-lnet.h
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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.
+ *
+ * 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
+ * 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/include/lnet/lib-lnet.h
  *
  * Top level include for library side routines
  */
@@ -19,8 +51,8 @@
 #error Unsupported Operating System
 #endif
 
+#include <libcfs/libcfs.h>
 #include <lnet/types.h>
-#include <libcfs/kp30.h>
 #include <lnet/lnet.h>
 #include <lnet/lib-types.h>
 
@@ -28,11 +60,11 @@ extern lnet_t  the_lnet;                        /* THE network */
 
 static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh)
 {
-        return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_NONE.wh_interface_cookie &&
-                wh->wh_object_cookie == LNET_WIRE_HANDLE_NONE.wh_object_cookie);
+        return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
+                wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE);
 }
 
-static inline int lnet_md_exhausted (lnet_libmd_t *md) 
+static inline int lnet_md_exhausted (lnet_libmd_t *md)
 {
         return (md->md_threshold == 0 ||
                 ((md->md_options & LNET_MD_MAX_SIZE) != 0 &&
@@ -57,8 +89,8 @@ static inline int lnet_md_unlinkable (lnet_libmd_t *md)
 }
 
 #ifdef __KERNEL__
-#define LNET_LOCK()        spin_lock(&the_lnet.ln_lock)                 
-#define LNET_UNLOCK()      spin_unlock(&the_lnet.ln_lock)               
+#define LNET_LOCK()        spin_lock(&the_lnet.ln_lock)
+#define LNET_UNLOCK()      spin_unlock(&the_lnet.ln_lock)
 #define LNET_MUTEX_DOWN(m) mutex_down(m)
 #define LNET_MUTEX_UP(m)   mutex_up(m)
 #else
@@ -104,7 +136,7 @@ lnet_freelist_alloc (lnet_freelist_t *fl)
 
         if (list_empty (&fl->fl_list))
                 return (NULL);
-        
+
         o = list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);
         list_del (&o->fo_list);
         return ((void *)&o->fo_contents);
@@ -115,7 +147,7 @@ lnet_freelist_free (lnet_freelist_t *fl, void *obj)
 {
         /* ALWAYS called with liblock held */
         lnet_freeobj_t *o = list_entry (obj, lnet_freeobj_t, fo_contents);
-        
+
         list_add (&o->fo_list, &fl->fl_list);
 }
 
@@ -125,7 +157,7 @@ lnet_eq_alloc (void)
 {
         /* NEVER called with liblock held */
         lnet_eq_t     *eq;
-        
+
         LNET_LOCK();
         eq = (lnet_eq_t *)lnet_freelist_alloc(&the_lnet.ln_free_eqs);
         LNET_UNLOCK();
@@ -145,11 +177,14 @@ lnet_md_alloc (lnet_md_t *umd)
 {
         /* NEVER called with liblock held */
         lnet_libmd_t  *md;
-        
+
         LNET_LOCK();
         md = (lnet_libmd_t *)lnet_freelist_alloc(&the_lnet.ln_free_mds);
         LNET_UNLOCK();
 
+        if (md != NULL)
+                CFS_INIT_LIST_HEAD(&md->md_list);
+
         return (md);
 }
 
@@ -165,11 +200,11 @@ lnet_me_alloc (void)
 {
         /* NEVER called with liblock held */
         lnet_me_t     *me;
-        
+
         LNET_LOCK();
         me = (lnet_me_t *)lnet_freelist_alloc(&the_lnet.ln_free_mes);
         LNET_UNLOCK();
-        
+
         return (me);
 }
 
@@ -185,7 +220,7 @@ lnet_msg_alloc (void)
 {
         /* NEVER called with liblock held */
         lnet_msg_t    *msg;
-        
+
         LNET_LOCK();
         msg = (lnet_msg_t *)lnet_freelist_alloc(&the_lnet.ln_free_msgs);
         LNET_UNLOCK();
@@ -232,7 +267,7 @@ lnet_md_alloc (lnet_md_t *umd)
 {
         /* NEVER called with liblock held */
         lnet_libmd_t *md;
-        int           size;
+        unsigned int  size;
         unsigned int  niov;
 
         if ((umd->options & LNET_MD_KIOV) != 0) {
@@ -250,16 +285,17 @@ lnet_md_alloc (lnet_md_t *umd)
                 /* Set here in case of early free */
                 md->md_options = umd->options;
                 md->md_niov = niov;
+                CFS_INIT_LIST_HEAD(&md->md_list);
         }
-        
+
         return (md);
 }
 
-static inline void 
+static inline void
 lnet_md_free (lnet_libmd_t *md)
 {
         /* ALWAYS called with liblock held */
-        int       size;
+        unsigned int  size;
 
         if ((md->md_options & LNET_MD_KIOV) != 0)
                 size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);
@@ -279,7 +315,7 @@ lnet_me_alloc (void)
         return (me);
 }
 
-static inline void 
+static inline void
 lnet_me_free(lnet_me_t *me)
 {
         /* ALWAYS called with liblock held */
@@ -304,7 +340,7 @@ lnet_msg_alloc(void)
         return (msg);
 }
 
-static inline void 
+static inline void
 lnet_msg_free(lnet_msg_t *msg)
 {
         /* ALWAYS called with liblock held */
@@ -321,7 +357,7 @@ static inline void
 lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq)
 {
         if (eq == NULL) {
-                *handle = LNET_EQ_NONE;
+                LNetInvalidateHandle(handle);
                 return;
         }
 
@@ -332,7 +368,7 @@ static inline lnet_eq_t *
 lnet_handle2eq (lnet_handle_eq_t *handle)
 {
         /* ALWAYS called with liblock held */
-        lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie, 
+        lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,
                                                   LNET_COOKIE_TYPE_EQ);
         if (lh == NULL)
                 return (NULL);
@@ -363,10 +399,10 @@ lnet_wire_handle2md (lnet_handle_wire_t *wh)
 {
         /* ALWAYS called with liblock held */
         lnet_libhandle_t *lh;
-        
+
         if (wh->wh_interface_cookie != the_lnet.ln_interface_cookie)
                 return (NULL);
-        
+
         lh = lnet_lookup_cookie(wh->wh_object_cookie,
                                 LNET_COOKIE_TYPE_MD);
         if (lh == NULL)
@@ -418,14 +454,14 @@ lnet_isrouter(lnet_peer_t *lp)
 }
 
 static inline void
-lnet_ni_addref_locked(lnet_ni_t *ni) 
+lnet_ni_addref_locked(lnet_ni_t *ni)
 {
         LASSERT (ni->ni_refcount > 0);
         ni->ni_refcount++;
 }
 
 static inline void
-lnet_ni_addref(lnet_ni_t *ni) 
+lnet_ni_addref(lnet_ni_t *ni)
 {
         LNET_LOCK();
         lnet_ni_addref_locked(ni);
@@ -449,40 +485,10 @@ lnet_ni_decref(lnet_ni_t *ni)
         LNET_UNLOCK();
 }
 
-static inline lnet_nid_t
-lnet_ptlcompat_srcnid(lnet_nid_t src, lnet_nid_t dst)
-{
-        /* Give myself a portals srcnid if I'm sending to portals */
-        if (the_lnet.ln_ptlcompat > 0 &&   
-            LNET_NIDNET(dst) == 0)
-                return LNET_MKNID(0, LNET_NIDADDR(src));
-        
-        return src;
-}
-
-static inline int
-lnet_ptlcompat_matchnid(lnet_nid_t lnet_nid, lnet_nid_t ptl_nid) 
-{
-        return ((ptl_nid == lnet_nid) ||
-                (the_lnet.ln_ptlcompat > 0 &&
-                 LNET_NIDNET(ptl_nid) == 0 &&
-                 LNET_NETTYP(LNET_NIDNET(lnet_nid)) != LOLND &&
-                 LNET_NIDADDR(ptl_nid) == LNET_NIDADDR(lnet_nid)));
-}
-
-static inline int
-lnet_ptlcompat_matchnet(__u32 lnet_net, __u32 ptl_net) 
-{
-        return ((ptl_net == lnet_net) ||
-                (the_lnet.ln_ptlcompat > 0 &&
-                 ptl_net == 0 &&
-                 LNET_NETTYP(lnet_net) != LOLND));
-}
-
 static inline struct list_head *
 lnet_nid2peerhash (lnet_nid_t nid)
 {
-       unsigned int idx = LNET_NIDADDR(nid) % LNET_PEER_HASHSIZE;
+        unsigned int idx = LNET_NIDADDR(nid) % LNET_PEER_HASHSIZE;
 
         return &the_lnet.ln_peer_hash[idx];
 }
@@ -520,7 +526,7 @@ lnet_set_msg_uid(lnet_ni_t *ni, lnet_msg_t *msg, lnet_uid_t uid)
 extern lnet_ni_t *lnet_nid2ni_locked (lnet_nid_t nid);
 extern lnet_ni_t *lnet_net2ni_locked (__u32 net);
 static inline lnet_ni_t *
-lnet_net2ni (__u32 net) 
+lnet_net2ni (__u32 net)
 {
         lnet_ni_t *ni;
 
@@ -532,11 +538,12 @@ lnet_net2ni (__u32 net)
 }
 
 int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, time_t when);
+void lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, time_t when);
 int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid);
 int lnet_check_routes(void);
 int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
 void lnet_destroy_routes(void);
-int lnet_get_route(int idx, __u32 *net, __u32 *hops, 
+int lnet_get_route(int idx, __u32 *net, __u32 *hops,
                    lnet_nid_t *gateway, __u32 *alive);
 void lnet_proc_init(void);
 void lnet_proc_fini(void);
@@ -548,6 +555,7 @@ lnet_remotenet_t *lnet_find_net_locked (__u32 net);
 int lnet_islocalnid(lnet_nid_t nid);
 int lnet_islocalnet(__u32 net);
 
+void lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev);
 void lnet_enq_event_locked(lnet_eq_t *eq, lnet_event_t *ev);
 void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
                     unsigned int offset, unsigned int len);
@@ -572,25 +580,25 @@ int lnet_extract_iov (int dst_niov, struct iovec *dst,
                       unsigned int offset, unsigned int len);
 
 unsigned int lnet_kiov_nob (unsigned int niov, lnet_kiov_t *iov);
-int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst, 
+int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
                       int src_niov, lnet_kiov_t *src,
                       unsigned int offset, unsigned int len);
 
-void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, 
-                        unsigned int doffset, 
-                        unsigned int nsiov, struct iovec *siov, 
+void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov,
+                        unsigned int doffset,
+                        unsigned int nsiov, struct iovec *siov,
                         unsigned int soffset, unsigned int nob);
-void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, 
+void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov,
                          unsigned int iovoffset,
-                         unsigned int nkiov, lnet_kiov_t *kiov, 
+                         unsigned int nkiov, lnet_kiov_t *kiov,
                          unsigned int kiovoffset, unsigned int nob);
-void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, 
+void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov,
                          unsigned int kiovoffset,
-                         unsigned int niov, struct iovec *iov, 
+                         unsigned int niov, struct iovec *iov,
                          unsigned int iovoffset, unsigned int nob);
-void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, 
-                          unsigned int doffset, 
-                          unsigned int nskiov, lnet_kiov_t *skiov, 
+void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov,
+                          unsigned int doffset,
+                          unsigned int nskiov, lnet_kiov_t *skiov,
                           unsigned int soffset, unsigned int nob);
 
 static inline void
@@ -647,16 +655,24 @@ int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
                  __u32 local_ip, __u32 peer_ip, int peer_port);
 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
                                 __u32 peer_ip, int port);
-int lnet_count_acceptor_nis(lnet_ni_t **first_ni);
-int lnet_accept(lnet_ni_t *blind_ni, cfs_socket_t *sock, __u32 magic);
+int lnet_count_acceptor_nis(void);
 int lnet_acceptor_timeout(void);
 int lnet_acceptor_port(void);
+#else
+void lnet_router_checker(void);
+#endif
+
+#ifdef HAVE_LIBPTHREAD
+int lnet_count_acceptor_nis(void);
+int lnet_acceptor_port(void);
 #endif
 
 int lnet_acceptor_start(void);
 void lnet_acceptor_stop(void);
 
+void lnet_get_tunables(void);
 int lnet_peers_start_down(void);
+int lnet_peer_buffer_credits(lnet_ni_t *ni);
 int lnet_router_checker_start(void);
 void lnet_router_checker_stop(void);
 
@@ -676,4 +692,23 @@ void lnet_destroy_peer_table(void);
 int lnet_create_peer_table(void);
 void lnet_debug_peer(lnet_nid_t nid);
 
+#ifndef __KERNEL__
+static inline int
+lnet_parse_int_tunable(int *value, char *name)
+{
+        char    *env = getenv(name);
+        char    *end;
+
+        if (env == NULL)
+                return 0;
+
+        *value = strtoull(env, &end, 0);
+        if (*end == 0)
+                return 0;
+
+        CERROR("Can't parse tunable %s=%s\n", name, env);
+        return -EINVAL;
+}
+#endif
+
 #endif