Whamcloud - gitweb
LU-1840 ldlm: fix mutex leak in ldlm_resource_get
authorPeng Tao <tao.peng@emc.com>
Thu, 6 Sep 2012 03:08:51 +0000 (11:08 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 5 Nov 2012 18:40:35 +0000 (13:40 -0500)
We created resource with lr_lvb_mutex locked. Need to drop
it before returning.

Signed-off-by: Peng Tao <tao.peng@emc.com>
Change-Id: Id81f792605d864b9d3236498f063d6c003d8cd77
Reviewed-on: http://review.whamcloud.com/3883
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Fan Yong <yong.fan@whamcloud.com>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/ldlm/ldlm_resource.c

index bb916b6..ec8bc22 100644 (file)
@@ -1079,8 +1079,10 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
                 /* someone won the race and added the resource before */
                 cfs_hash_bd_unlock(ns->ns_rs_hash, &bd, 1);
                 /* clean lu_ref for failed resource */
-                lu_ref_fini(&res->lr_reference);
-                OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
+               lu_ref_fini(&res->lr_reference);
+               /* We have taken lr_lvb_mutex. Drop it. */
+               cfs_mutex_unlock(&res->lr_lvb_mutex);
+               OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
 
                 res = cfs_hlist_entry(hnode, struct ldlm_resource, lr_hash);
                 /* synchronize WRT resource creation */
@@ -1104,11 +1106,12 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
                 if (rc)
                         CERROR("lvbo_init failed for resource "
                                LPU64": rc %d\n", name->name[0], rc);
-                /* we create resource with locked lr_lvb_mutex */
-                cfs_mutex_unlock(&res->lr_lvb_mutex);
-        }
+       }
 
-        return res;
+       /* we create resource with locked lr_lvb_mutex */
+       cfs_mutex_unlock(&res->lr_lvb_mutex);
+
+       return res;
 }
 EXPORT_SYMBOL(ldlm_resource_get);