From 458804418f3c24706db7ad9a46f791e59f008a7d Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Tue, 14 May 2013 16:17:30 +0400 Subject: [PATCH] LU-3316 obdclass: fix wrong device put in case of race The ls_device_put() might be called from local_oid_storage_fini() wrongly if mutex-protected check failed due to race Signed-off-by: Mikhail Pershin Change-Id: Ia2707d5db84b6bb6e9a5558c08b03028de8b9d50 Reviewed-on: http://review.whamcloud.com/6334 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- lustre/obdclass/local_storage.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lustre/obdclass/local_storage.c b/lustre/obdclass/local_storage.c index 7f41304..2799aba 100644 --- a/lustre/obdclass/local_storage.c +++ b/lustre/obdclass/local_storage.c @@ -894,12 +894,15 @@ void local_oid_storage_fini(const struct lu_env *env, ls = dt2ls_dev(los->los_dev); mutex_lock(&ls->ls_los_mutex); - if (cfs_atomic_read(&los->los_refcount) == 0) { - if (los->los_obj) - lu_object_put_nocache(env, &los->los_obj->do_lu); - cfs_list_del(&los->los_list); - OBD_FREE_PTR(los); + if (cfs_atomic_read(&los->los_refcount) > 0) { + mutex_unlock(&ls->ls_los_mutex); + return; } + + if (los->los_obj) + lu_object_put_nocache(env, &los->los_obj->do_lu); + cfs_list_del(&los->los_list); + OBD_FREE_PTR(los); mutex_unlock(&ls->ls_los_mutex); ls_device_put(env, ls); } -- 1.8.3.1