Whamcloud - gitweb
LU-10391 lnet: switch to large lnet_processid for matching
[fs/lustre-release.git] / lnet / lnet / lib-me.c
index 578e353..8d7c9ee 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lnet/lnet/lib-me.c
  *
  * \param pos Indicates whether the new ME should be prepended or
  * appended to the match list. Allowed constants: LNET_INS_BEFORE,
  * LNET_INS_AFTER.
- * \param handle On successful returns, a handle to the newly created ME
- * object is saved here. This handle can be used later in LNetMEUnlink(),
- * or LNetMDAttach() functions.
  *
- * \retval 0      On success.
- * \retval -EINVAL If \a portal is invalid.
- * \retval -ENOMEM If new ME object cannot be allocated.
+ * \retval A handle to the newly created ME is returned on success
+ * \retval ERR_PTR(-EINVAL) If \a portal is invalid.
+ * \retval ERR_PTR(-ENOMEM) If new ME object cannot be allocated.
  */
-int
+struct lnet_me *
 LNetMEAttach(unsigned int portal,
-            struct lnet_process_id match_id,
+            struct lnet_processid *match_id,
             __u64 match_bits, __u64 ignore_bits,
-            enum lnet_unlink unlink, enum lnet_ins_pos pos,
-            struct lnet_handle_me *handle)
+            enum lnet_unlink unlink, enum lnet_ins_pos pos)
 {
        struct lnet_match_table *mtable;
        struct lnet_me          *me;
@@ -82,28 +77,31 @@ LNetMEAttach(unsigned int portal,
        LASSERT(the_lnet.ln_refcount > 0);
 
        if ((int)portal >= the_lnet.ln_nportals)
-               return -EINVAL;
+               return ERR_PTR(-EINVAL);
 
        mtable = lnet_mt_of_attach(portal, match_id,
                                   match_bits, ignore_bits, pos);
        if (mtable == NULL) /* can't match portal type */
-               return -EPERM;
+               return ERR_PTR(-EPERM);
 
-       me = lnet_me_alloc();
-       if (me == NULL)
-               return -ENOMEM;
+       me = kmem_cache_zalloc(lnet_mes_cachep, GFP_NOFS);
+       if (me == NULL) {
+               CDEBUG(D_MALLOC, "failed to allocate 'me'\n");
+               return ERR_PTR(-ENOMEM);
+       }
+       CDEBUG(D_MALLOC, "slab-alloced 'me' at %p.\n", me);
 
        lnet_res_lock(mtable->mt_cpt);
 
        me->me_portal = portal;
-       me->me_match_id = match_id;
+       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;
 
-       lnet_res_lh_initialize(the_lnet.ln_me_containers[mtable->mt_cpt],
-                              &me->me_lh);
+       me->me_cpt = mtable->mt_cpt;
+
        if (ignore_bits != 0)
                head = &mtable->mt_mhash[LNET_MT_HASH_IGNORE];
        else
@@ -115,62 +113,11 @@ LNetMEAttach(unsigned int portal,
        else
                list_add(&me->me_list, head);
 
-       lnet_me2handle(handle, me);
-
        lnet_res_unlock(mtable->mt_cpt);
-       return 0;
+       return me;
 }
 EXPORT_SYMBOL(LNetMEAttach);
 
-/**
- * Unlink a match entry from its match list.
- *
- * This operation also releases any resources associated with the ME. If a
- * memory descriptor is attached to the ME, then it will be unlinked as well
- * and an unlink event will be generated. It is an error to use the ME handle
- * after calling LNetMEUnlink().
- *
- * \param meh A handle for the ME to be unlinked.
- *
- * \retval 0      On success.
- * \retval -ENOENT If \a meh does not point to a valid ME.
- * \see LNetMDUnlink() for the discussion on delivering unlink event.
- */
-int
-LNetMEUnlink(struct lnet_handle_me meh)
-{
-       struct lnet_me *me;
-       struct lnet_libmd *md;
-       struct lnet_event ev;
-       int cpt;
-
-       LASSERT(the_lnet.ln_refcount > 0);
-
-       cpt = lnet_cpt_of_cookie(meh.cookie);
-       lnet_res_lock(cpt);
-
-       me = lnet_handle2me(&meh);
-       if (me == NULL) {
-               lnet_res_unlock(cpt);
-               return -ENOENT;
-       }
-
-       md = me->me_md;
-       if (md != NULL) {
-               md->md_flags |= LNET_MD_FLAG_ABORTED;
-               if (md->md_eq != NULL && md->md_refcount == 0) {
-                       lnet_build_unlink_event(md, &ev);
-                       lnet_eq_enqueue_event(md->md_eq, &ev);
-               }
-       }
-
-       lnet_me_unlink(me);
-
-       lnet_res_unlock(cpt);
-       return 0;
-}
-EXPORT_SYMBOL(LNetMEUnlink);
-
 /* call with lnet_res_lock please */
 void
 lnet_me_unlink(struct lnet_me *me)
@@ -185,8 +132,8 @@ lnet_me_unlink(struct lnet_me *me)
                lnet_md_unlink(md);
        }
 
-       lnet_res_lh_invalidate(&me->me_lh);
-       lnet_me_free(me);
+       CDEBUG(D_MALLOC, "slab-freed 'me' at %p.\n", me);
+       kmem_cache_free(lnet_mes_cachep, me);
 }
 
 #if 0