Whamcloud - gitweb
LU-56 lnet: Granulate LNet lock
[fs/lustre-release.git] / lnet / lnet / lib-md.c
index 87b2613..dbb007e 100644 (file)
@@ -40,7 +40,7 @@
 
 #include <lnet/lib-lnet.h>
 
-/* must be called with LNET_LOCK held */
+/* must be called with lnet_res_lock held */
 void
 lnet_md_unlink(lnet_libmd_t *md)
 {
@@ -53,8 +53,8 @@ lnet_md_unlink(lnet_libmd_t *md)
                 /* Disassociate from ME (if any), and unlink it if it was created
                  * with LNET_UNLINK */
                 if (me != NULL) {
-                        md->md_me = NULL;
-                        me->me_md = NULL;
+                       /* detach MD from portal */
+                       lnet_ptl_detach_md(me, md);
                         if (me->me_unlink == LNET_UNLINK)
                                 lnet_me_unlink(me);
                 }
@@ -196,7 +196,7 @@ lnet_md_link(lnet_libmd_t *md, lnet_handle_eq_t eq_handle)
        return 0;
 }
 
-/* must be called with LNET_LOCK held */
+/* must be called with lnet_res_lock held */
 void
 lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd)
 {
@@ -263,6 +263,8 @@ int
 LNetMDAttach(lnet_handle_me_t meh, lnet_md_t umd,
              lnet_unlink_t unlink, lnet_handle_md_t *handle)
 {
+       CFS_LIST_HEAD   (matches);
+       CFS_LIST_HEAD   (drops);
         lnet_me_t     *me;
         lnet_libmd_t  *md;
         int            rc;
@@ -284,7 +286,7 @@ LNetMDAttach(lnet_handle_me_t meh, lnet_md_t umd,
 
        rc = lnet_md_build(md, &umd, unlink);
 
-       LNET_LOCK();
+       lnet_res_lock();
        if (rc != 0)
                goto failed;
 
@@ -299,23 +301,23 @@ LNetMDAttach(lnet_handle_me_t meh, lnet_md_t umd,
        if (rc != 0)
                goto failed;
 
-       the_lnet.ln_portals[me->me_portal]->ptl_ml_version++;
-
-       me->me_md = md;
-       md->md_me = me;
+       /* attach this MD to portal of ME and check if it matches any
+        * blocked msgs on this portal */
+       lnet_ptl_attach_md(me, md, &matches, &drops);
 
        lnet_md2handle(handle, md);
 
-       /* check if this MD matches any blocked msgs */
-       lnet_match_blocked_msg(md);   /* expects LNET_LOCK held */
+       lnet_res_unlock();
+
+       lnet_drop_delayed_msg_list(&drops, "Bad match");
+       lnet_recv_delayed_msg_list(&matches);
 
-       LNET_UNLOCK();
        return 0;
 
  failed:
        lnet_md_free_locked(md);
 
-       LNET_UNLOCK();
+       lnet_res_unlock();
        return rc;
 }
 
@@ -358,7 +360,7 @@ LNetMDBind(lnet_md_t umd, lnet_unlink_t unlink, lnet_handle_md_t *handle)
 
        rc = lnet_md_build(md, &umd, unlink);
 
-       LNET_LOCK();
+       lnet_res_lock();
        if (rc != 0)
                goto failed;
 
@@ -368,13 +370,13 @@ LNetMDBind(lnet_md_t umd, lnet_unlink_t unlink, lnet_handle_md_t *handle)
 
        lnet_md2handle(handle, md);
 
-       LNET_UNLOCK();
+       lnet_res_unlock();
        return 0;
 
  failed:
        lnet_md_free_locked(md);
 
-       LNET_UNLOCK();
+       lnet_res_unlock();
        return rc;
 }
 
@@ -416,11 +418,11 @@ LNetMDUnlink (lnet_handle_md_t mdh)
         LASSERT (the_lnet.ln_init);
         LASSERT (the_lnet.ln_refcount > 0);
 
-        LNET_LOCK();
+       lnet_res_lock();
 
-        md = lnet_handle2md(&mdh);
-        if (md == NULL) {
-                LNET_UNLOCK();
+       md = lnet_handle2md(&mdh);
+       if (md == NULL) {
+               lnet_res_unlock();
                 return -ENOENT;
         }
 
@@ -436,6 +438,6 @@ LNetMDUnlink (lnet_handle_md_t mdh)
 
         lnet_md_unlink(md);
 
-        LNET_UNLOCK();
-        return 0;
+       lnet_res_unlock();
+       return 0;
 }