- lib_nal_t *nal = apinal->nal_data;
- lib_me_t *current_me;
- lib_me_t *new_me;
- unsigned long flags;
-
- new_me = lib_me_alloc (nal);
- if (new_me == NULL)
- return PTL_NO_SPACE;
-
- LIB_LOCK(nal, flags);
-
- current_me = ptl_handle2me(current_meh, nal);
- if (current_me == NULL) {
- lib_me_free (nal, new_me);
-
- LIB_UNLOCK(nal, flags);
- return PTL_ME_INVALID;
- }
-
- 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;
-
- lib_initialise_handle (nal, &new_me->me_lh, PTL_COOKIE_TYPE_ME);
-
- if (pos == PTL_INS_AFTER)
- list_add_tail(&new_me->me_list, ¤t_me->me_list);
- else
- list_add(&new_me->me_list, ¤t_me->me_list);
-
- ptl_me2handle(handle, nal, new_me);
-
- LIB_UNLOCK(nal, flags);
-
- return PTL_OK;
+ struct lnet_match_table *mtable;
+ struct lnet_me *me;
+ struct list_head *head;
+
+ LASSERT(the_lnet.ln_refcount > 0);
+
+ if ((int)portal >= the_lnet.ln_nportals)
+ 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 ERR_PTR(-EPERM);
+
+ 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_bits = match_bits;
+ me->me_ignore_bits = ignore_bits;
+ me->me_unlink = unlink;
+ me->me_md = NULL;
+
+ me->me_cpt = mtable->mt_cpt;
+
+ if (ignore_bits != 0)
+ head = &mtable->mt_mhash[LNET_MT_HASH_IGNORE];
+ else
+ head = lnet_mt_match_head(mtable, match_id, match_bits);
+
+ me->me_pos = head - &mtable->mt_mhash[0];
+ if (pos == LNET_INS_AFTER || pos == LNET_INS_LOCAL)
+ list_add_tail(&me->me_list, head);
+ else
+ list_add(&me->me_list, head);
+
+ lnet_res_unlock(mtable->mt_cpt);
+ return me;