Whamcloud - gitweb
- fixed typo in a comment.
[fs/lustre-release.git] / lnet / lnet / lib-me.c
index 9665b4f..fb72c6d 100644 (file)
@@ -5,9 +5,8 @@
  * Match Entry management routines
  *
  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
- *  Copyright (c) 2001-2002 Sandia National Laboratories
  *
- *   This file is part of Lustre, http://www.sf.net/projects/lustre/
+ *   This file is part of Lustre, http://www.lustre.org
  *
  *   Lustre is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#ifndef __KERNEL__
-# include <stdio.h>
-#else
-# define DEBUG_SUBSYSTEM S_PORTALS
-# include <linux/kp30.h>
-#endif
+#define DEBUG_SUBSYSTEM S_LNET
 
-#include <portals/lib-p30.h>
+#include <lnet/lib-lnet.h>
 
 int
-lib_api_me_attach(nal_t *apinal,
-                  ptl_pt_index_t portal,
-                  ptl_process_id_t match_id, 
-                  ptl_match_bits_t match_bits, 
-                  ptl_match_bits_t ignore_bits,
-                  ptl_unlink_t unlink, ptl_ins_pos_t pos,
-                  ptl_handle_me_t *handle)
+LNetMEAttach(unsigned int portal,
+             lnet_process_id_t match_id, 
+             __u64 match_bits, __u64 ignore_bits,
+             lnet_unlink_t unlink, lnet_ins_pos_t pos, 
+             lnet_handle_me_t *handle)
 {
-        lib_nal_t    *nal = apinal->nal_data;
-        lib_ni_t     *ni = &nal->libnal_ni;
-        lib_ptl_t    *tbl = &ni->ni_portals;
-        lib_me_t     *me;
-        unsigned long flags;
-
-        if (portal >= tbl->size)
-                return PTL_PT_INDEX_INVALID;
+        lnet_me_t     *me;
 
-        /* Should check for valid matchid, but not yet */
+        LASSERT (the_lnet.ln_init);
+        LASSERT (the_lnet.ln_refcount > 0);
+        
+        if (portal >= the_lnet.ln_nportals)
+                return -EINVAL;
 
-        me = lib_me_alloc (nal);
+        me = lnet_me_alloc();
         if (me == NULL)
-                return PTL_NO_SPACE;
+                return -ENOMEM;
 
-        LIB_LOCK(nal, flags);
+        LNET_LOCK();
 
-        me->match_id = match_id;
-        me->match_bits = match_bits;
-        me->ignore_bits = ignore_bits;
-        me->unlink = unlink;
-        me->md = NULL;
+        me->me_portal = portal;
+        me->me_match_id = match_id;
+        me->me_match_bits = match_bits;
+        me->me_ignore_bits = ignore_bits;
+        me->me_unlink = unlink;
+        me->me_md = NULL;
 
-        lib_initialise_handle (nal, &me->me_lh, PTL_COOKIE_TYPE_ME);
+        lnet_initialise_handle (&me->me_lh, LNET_COOKIE_TYPE_ME);
 
-        if (pos == PTL_INS_AFTER)
-                list_add_tail(&me->me_list, &(tbl->tbl[portal]));
+        if (pos == LNET_INS_AFTER)
+                list_add_tail(&me->me_list, &(the_lnet.ln_portals[portal].ptl_ml));
         else
-                list_add(&me->me_list, &(tbl->tbl[portal]));
+                list_add(&me->me_list, &(the_lnet.ln_portals[portal].ptl_ml));
 
-        ptl_me2handle(handle, nal, me);
+        lnet_me2handle(handle, me);
 
-        LIB_UNLOCK(nal, flags);
+        LNET_UNLOCK();
 
-        return PTL_OK;
+        return 0;
 }
 
-int
-lib_api_me_insert(nal_t *apinal,
-                  ptl_handle_me_t *current_meh,
-                  ptl_process_id_t match_id, 
-                  ptl_match_bits_t match_bits, 
-                  ptl_match_bits_t ignore_bits,
-                  ptl_unlink_t unlink, ptl_ins_pos_t pos,
-                  ptl_handle_me_t *handle)
+int 
+LNetMEInsert(lnet_handle_me_t current_meh, 
+             lnet_process_id_t match_id, 
+             __u64 match_bits, __u64 ignore_bits,
+             lnet_unlink_t unlink, lnet_ins_pos_t pos,
+             lnet_handle_me_t *handle)
 {
-        lib_nal_t    *nal = apinal->nal_data;
-        lib_me_t     *current_me;
-        lib_me_t     *new_me;
-        unsigned long flags;
+        lnet_me_t     *current_me;
+        lnet_me_t     *new_me;
 
-        new_me = lib_me_alloc (nal);
+        LASSERT (the_lnet.ln_init);        
+        LASSERT (the_lnet.ln_refcount > 0);
+        
+        new_me = lnet_me_alloc();
         if (new_me == NULL)
-                return PTL_NO_SPACE;
-
-        /* Should check for valid matchid, but not yet */
+                return -ENOMEM;
 
-        LIB_LOCK(nal, flags);
+        LNET_LOCK();
 
-        current_me = ptl_handle2me(current_meh, nal);
+        current_me = lnet_handle2me(&current_meh);
         if (current_me == NULL) {
-                lib_me_free (nal, new_me);
+                lnet_me_free (new_me);
 
-                LIB_UNLOCK(nal, flags);
-                return PTL_ME_INVALID;
+                LNET_UNLOCK();
+                return -ENOENT;
         }
 
-        new_me->match_id = match_id;
-        new_me->match_bits = match_bits;
-        new_me->ignore_bits = ignore_bits;
-        new_me->unlink = unlink;
-        new_me->md = NULL;
+        new_me->me_match_id = match_id;
+        new_me->me_match_bits = match_bits;
+        new_me->me_ignore_bits = ignore_bits;
+        new_me->me_unlink = unlink;
+        new_me->me_md = NULL;
 
-        lib_initialise_handle (nal, &new_me->me_lh, PTL_COOKIE_TYPE_ME);
+        lnet_initialise_handle (&new_me->me_lh, LNET_COOKIE_TYPE_ME);
 
-        if (pos == PTL_INS_AFTER)
+        if (pos == LNET_INS_AFTER)
                 list_add_tail(&new_me->me_list, &current_me->me_list);
         else
                 list_add(&new_me->me_list, &current_me->me_list);
 
-        ptl_me2handle(handle, nal, new_me);
+        lnet_me2handle(handle, new_me);
 
-        LIB_UNLOCK(nal, flags);
+        LNET_UNLOCK();
 
-        return PTL_OK;
+        return 0;
 }
 
 int
-lib_api_me_unlink (nal_t *apinal, ptl_handle_me_t *meh)
+LNetMEUnlink(lnet_handle_me_t meh)
 {
-        lib_nal_t    *nal = apinal->nal_data;
-        unsigned long flags;
-        lib_me_t     *me;
+        lnet_me_t     *me;
         int           rc;
 
-        LIB_LOCK(nal, flags);
+        LASSERT (the_lnet.ln_init);        
+        LASSERT (the_lnet.ln_refcount > 0);
+        
+        LNET_LOCK();
 
-        me = ptl_handle2me(meh, nal);
+        me = lnet_handle2me(&meh);
         if (me == NULL) {
-                rc = PTL_ME_INVALID;
+                rc = -ENOENT;
         } else {
-                lib_me_unlink(nal, me);
-                rc = PTL_OK;
+                lnet_me_unlink(me);
+                rc = 0;
         }
 
-        LIB_UNLOCK(nal, flags);
+        LNET_UNLOCK();
 
         return (rc);
 }
 
-/* call with state_lock please */
-void 
-lib_me_unlink(lib_nal_t *nal, lib_me_t *me)
+/* call with LNET_LOCK please */
+void
+lnet_me_unlink(lnet_me_t *me)
 {
         list_del (&me->me_list);
 
-        if (me->md) {
-                me->md->me = NULL;
-                lib_md_unlink(nal, me->md);
+        if (me->me_md) {
+                me->me_md->md_me = NULL;
+                lnet_md_unlink(me->me_md);
         }
 
-        lib_invalidate_handle (nal, &me->me_lh);
-        lib_me_free(nal, me);
+        lnet_invalidate_handle (&me->me_lh);
+        lnet_me_free(me);
 }
 
 #if 0
-static void 
-lib_me_dump(lib_nal_t *nal, lib_me_t * me)
+static void
+lib_me_dump(lnet_me_t *me)
 {
-        CWARN("Match Entry %p ("LPX64")\n", me, 
+        CWARN("Match Entry %p ("LPX64")\n", me,
               me->me_lh.lh_cookie);
 
         CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
-              me->match_bits, me->ignore_bits);
+              me->me_match_bits, me->me_ignore_bits);
 
         CWARN("\tMD\t= %p\n", me->md);
         CWARN("\tprev\t= %p\n",
-              list_entry(me->me_list.prev, lib_me_t, me_list));
+              list_entry(me->me_list.prev, lnet_me_t, me_list));
         CWARN("\tnext\t= %p\n",
-              list_entry(me->me_list.next, lib_me_t, me_list));
+              list_entry(me->me_list.next, lnet_me_t, me_list));
 }
 #endif