Whamcloud - gitweb
LU-12889 lnet: Do not assume peers are MR capable
[fs/lustre-release.git] / lnet / lnet / lib-me.c
index 1a1d9b1..1ec83db 100644 (file)
  * \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 LNetMEInsert(),
- * 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,
             __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,16 +78,16 @@ 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;
+               return ERR_PTR(-ENOMEM);
 
        lnet_res_lock(mtable->mt_cpt);
 
@@ -102,8 +98,8 @@ LNetMEAttach(unsigned int portal,
        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,97 +111,12 @@ 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);
 
 /**
- * Create and a match entry and insert it before or after the ME pointed to by
- * \a current_meh. The new ME is empty, i.e. not associated with a memory
- * descriptor. LNetMDAttach() can be used to attach a MD to an empty ME.
- *
- * This function is identical to LNetMEAttach() except for the position
- * where the new ME is inserted.
- *
- * \param current_meh A handle for a ME. The new ME will be inserted
- * immediately before or immediately after this ME.
- * \param match_id,match_bits,ignore_bits,unlink,pos,handle See the discussion
- * for LNetMEAttach().
- *
- * \retval 0      On success.
- * \retval -ENOMEM If new ME object cannot be allocated.
- * \retval -ENOENT If \a current_meh does not point to a valid match entry.
- */
-int
-LNetMEInsert(struct lnet_handle_me current_meh,
-            struct lnet_process_id match_id,
-            __u64 match_bits, __u64 ignore_bits,
-            enum lnet_unlink unlink, enum lnet_ins_pos pos,
-            struct lnet_handle_me *handle)
-{
-       struct lnet_me          *current_me;
-       struct lnet_me          *new_me;
-       struct lnet_portal      *ptl;
-       int                     cpt;
-
-       LASSERT(the_lnet.ln_refcount > 0);
-
-       if (pos == LNET_INS_LOCAL)
-               return -EPERM;
-
-       new_me = lnet_me_alloc();
-       if (new_me == NULL)
-               return -ENOMEM;
-
-       cpt = lnet_cpt_of_cookie(current_meh.cookie);
-
-       lnet_res_lock(cpt);
-
-       current_me = lnet_handle2me(&current_meh);
-       if (current_me == NULL) {
-               lnet_me_free(new_me);
-
-               lnet_res_unlock(cpt);
-               return -ENOENT;
-       }
-
-       LASSERT(current_me->me_portal < the_lnet.ln_nportals);
-
-       ptl = the_lnet.ln_portals[current_me->me_portal];
-       if (lnet_ptl_is_unique(ptl)) {
-               /* nosense to insertion on unique portal */
-               lnet_me_free(new_me);
-               lnet_res_unlock(cpt);
-               return -EPERM;
-       }
-
-       new_me->me_pos = current_me->me_pos;
-       new_me->me_portal = current_me->me_portal;
-       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;
-
-       lnet_res_lh_initialize(the_lnet.ln_me_containers[cpt], &new_me->me_lh);
-
-       if (pos == LNET_INS_AFTER)
-               list_add(&new_me->me_list, &current_me->me_list);
-       else
-               list_add_tail(&new_me->me_list, &current_me->me_list);
-
-       lnet_me2handle(handle, new_me);
-
-       lnet_res_unlock(cpt);
-
-       return 0;
-}
-EXPORT_SYMBOL(LNetMEInsert);
-
-/**
  * Unlink a match entry from its match list.
  *
  * This operation also releases any resources associated with the ME. If a
@@ -219,25 +130,18 @@ EXPORT_SYMBOL(LNetMEInsert);
  * \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)
+void
+LNetMEUnlink(struct lnet_me *me)
 {
-       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);
+       cpt = me->me_cpt;
        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;
@@ -250,7 +154,6 @@ LNetMEUnlink(struct lnet_handle_me meh)
        lnet_me_unlink(me);
 
        lnet_res_unlock(cpt);
-       return 0;
 }
 EXPORT_SYMBOL(LNetMEUnlink);
 
@@ -268,7 +171,6 @@ lnet_me_unlink(struct lnet_me *me)
                lnet_md_unlink(md);
        }
 
-       lnet_res_lh_invalidate(&me->me_lh);
        lnet_me_free(me);
 }