[PATCH 24/39] staging/lustre/obdclass: fix wrong device put in case of race

From: Peng Tao
Date: Thu Nov 14 2013 - 11:41:06 EST


From: Mikhail Pershin <mike.pershin@xxxxxxxxx>

The ls_device_put() might be called from local_oid_storage_fini()
wrongly if mutex-protected check failed due to race

Lustre-change: http://review.whamcloud.com/6334
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3316
Signed-off-by: Mikhail Pershin <mike.pershin@xxxxxxxxx>
Reviewed-by: Fan Yong <fan.yong@xxxxxxxxx>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@xxxxxxxxx>
Reviewed-by: Oleg Drokin <oleg.drokin@xxxxxxxxx>
Signed-off-by: Peng Tao <bergwolf@xxxxxxxxx>
Signed-off-by: Andreas Dilger <andreas.dilger@xxxxxxxxx>
---
.../staging/lustre/lustre/obdclass/local_storage.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/local_storage.c b/drivers/staging/lustre/lustre/obdclass/local_storage.c
index 295bb7c..367d3fd 100644
--- a/drivers/staging/lustre/lustre/obdclass/local_storage.c
+++ b/drivers/staging/lustre/lustre/obdclass/local_storage.c
@@ -882,12 +882,15 @@ void local_oid_storage_fini(const struct lu_env *env,
ls = dt2ls_dev(los->los_dev);

mutex_lock(&ls->ls_los_mutex);
- if (atomic_read(&los->los_refcount) == 0) {
- if (los->los_obj)
- lu_object_put_nocache(env, &los->los_obj->do_lu);
- list_del(&los->los_list);
- OBD_FREE_PTR(los);
+ if (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);
+ list_del(&los->los_list);
+ OBD_FREE_PTR(los);
mutex_unlock(&ls->ls_los_mutex);
ls_device_put(env, ls);
}
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/