Whamcloud - gitweb
LU-502 don't allow to kill service threads by OOM killer.
[fs/lustre-release.git] / lnet / include / lnet / lib-lnet.h
index 5332664..33f780d 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -88,11 +88,18 @@ static inline int lnet_md_unlinkable (lnet_libmd_t *md)
                 lnet_md_exhausted(md));
 }
 
+static inline unsigned int
+lnet_match_to_hash(lnet_process_id_t id, __u64 mbits)
+{
+        mbits += id.nid + id.pid;
+        return cfs_hash_long((unsigned long)mbits, LNET_PORTAL_HASH_BITS);
+}
+
 #ifdef __KERNEL__
-#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)
+#define LNET_LOCK()        cfs_spin_lock(&the_lnet.ln_lock)
+#define LNET_UNLOCK()      cfs_spin_unlock(&the_lnet.ln_lock)
+#define LNET_MUTEX_DOWN(m) cfs_mutex_down(m)
+#define LNET_MUTEX_UP(m)   cfs_mutex_up(m)
 #else
 # ifndef HAVE_LIBPTHREAD
 #define LNET_SINGLE_THREADED_LOCK(l)            \
@@ -134,11 +141,11 @@ lnet_freelist_alloc (lnet_freelist_t *fl)
         /* ALWAYS called with liblock held */
         lnet_freeobj_t *o;
 
-        if (list_empty (&fl->fl_list))
+        if (cfs_list_empty (&fl->fl_list))
                 return (NULL);
 
-        o = list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);
-        list_del (&o->fo_list);
+        o = cfs_list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);
+        cfs_list_del (&o->fo_list);
         return ((void *)&o->fo_contents);
 }
 
@@ -146,9 +153,9 @@ static inline void
 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);
+        lnet_freeobj_t *o = cfs_list_entry (obj, lnet_freeobj_t, fo_contents);
 
-        list_add (&o->fo_list, &fl->fl_list);
+        cfs_list_add (&o->fo_list, &fl->fl_list);
 }
 
 
@@ -330,13 +337,13 @@ lnet_msg_alloc(void)
 
         LIBCFS_ALLOC(msg, sizeof(*msg));
 
-        if (msg != NULL) {
-                /* NULL pointers, clear flags etc */
-                memset (msg, 0, sizeof (*msg));
+        /* no need to zero, LIBCFS_ALLOC does for us */
+
 #ifdef CRAY_XT3
+        if (msg != NULL) {
                 msg->msg_ev.uid = LNET_UID_ANY;
-#endif
         }
+#endif
         return (msg);
 }
 
@@ -429,6 +436,62 @@ lnet_handle2me (lnet_handle_me_t *handle)
         return (lh_entry (lh, lnet_me_t, me_lh));
 }
 
+static inline int
+lnet_portal_is_lazy(lnet_portal_t *ptl)
+{
+        return !!(ptl->ptl_options & LNET_PTL_LAZY);
+}
+
+static inline int
+lnet_portal_is_unique(lnet_portal_t *ptl)
+{
+        return !!(ptl->ptl_options & LNET_PTL_MATCH_UNIQUE); 
+}
+
+static inline int
+lnet_portal_is_wildcard(lnet_portal_t *ptl)
+{
+        return !!(ptl->ptl_options & LNET_PTL_MATCH_WILDCARD);
+}
+
+static inline void
+lnet_portal_setopt(lnet_portal_t *ptl, int opt)
+{
+        ptl->ptl_options |= opt;
+}
+
+static inline void
+lnet_portal_unsetopt(lnet_portal_t *ptl, int opt)
+{
+        ptl->ptl_options &= ~opt;
+}
+
+static inline int
+lnet_match_is_unique(lnet_process_id_t match_id,
+                     __u64 match_bits, __u64 ignore_bits)
+{
+        return ignore_bits == 0 &&
+               match_id.nid != LNET_NID_ANY &&
+               match_id.pid != LNET_PID_ANY;
+}
+
+static inline cfs_list_t *
+lnet_portal_me_head(int index, lnet_process_id_t id, __u64 mbits)
+{
+        lnet_portal_t *ptl = &the_lnet.ln_portals[index];
+
+        if (lnet_portal_is_wildcard(ptl)) {
+                return &ptl->ptl_mlist;
+        } else if (lnet_portal_is_unique(ptl)) {
+                LASSERT (ptl->ptl_mhash != NULL);
+                return &ptl->ptl_mhash[lnet_match_to_hash(id, mbits)];
+        }
+        return NULL;
+}
+
+cfs_list_t *lnet_portal_mhash_alloc(void);
+void lnet_portal_mhash_free(cfs_list_t *mhash);
+
 static inline void
 lnet_peer_addref_locked(lnet_peer_t *lp)
 {
@@ -474,7 +537,7 @@ lnet_ni_decref_locked(lnet_ni_t *ni)
         LASSERT (ni->ni_refcount > 0);
         ni->ni_refcount--;
         if (ni->ni_refcount == 0)
-                list_add_tail(&ni->ni_list, &the_lnet.ln_zombie_nis);
+                cfs_list_add_tail(&ni->ni_list, &the_lnet.ln_zombie_nis);
 }
 
 static inline void
@@ -485,7 +548,7 @@ lnet_ni_decref(lnet_ni_t *ni)
         LNET_UNLOCK();
 }
 
-static inline struct list_head *
+static inline cfs_list_t *
 lnet_nid2peerhash (lnet_nid_t nid)
 {
         unsigned int idx = LNET_NIDADDR(nid) % LNET_PEER_HASHSIZE;
@@ -674,9 +737,6 @@ void lnet_get_tunables(void);
 int lnet_peers_start_down(void);
 int lnet_peer_buffer_credits(lnet_ni_t *ni);
 
-extern int router_ping_timeout;
-extern int dead_router_check_interval;
-extern int live_router_check_interval;
 int lnet_router_checker_start(void);
 void lnet_router_checker_stop(void);
 void lnet_swap_pinginfo(lnet_ping_info_t *info);
@@ -689,7 +749,7 @@ int lnet_ping(lnet_process_id_t id, int timeout_ms,
 
 int lnet_parse_ip2nets (char **networksp, char *ip2nets);
 int lnet_parse_routes (char *route_str, int *im_a_router);
-int lnet_parse_networks (struct list_head *nilist, char *networks);
+int lnet_parse_networks (cfs_list_t *nilist, char *networks);
 
 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid);
 lnet_peer_t *lnet_find_peer_locked (lnet_nid_t nid);