From: Fan Yong Date: Sat, 11 Feb 2012 01:26:29 +0000 (+0800) Subject: LU-1013 obdclass: lu_object_find miss to unlink object from LRU X-Git-Tag: 2.1.56~36 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=b9ccecd1453c5c76fe135048c39f149c241650c6 LU-1013 obdclass: lu_object_find miss to unlink object from LRU There is race condition between lu_object_find and lu_object_put. For the case of two threads trying to find some object with the same FID concurrently, and the object is not allocated in memory yet, if the first thread adds the object into LRU list before the second thread re-searching object hash table for inserting the new object created by itself, then the second thread will find the object created by the first thread. Under such case, the second thread should unlink the object from LRU. Signed-off-by: Fan Yong Change-Id: Iadec96c27d5285f8b859b0060a6f611e87585789 Reviewed-on: http://review.whamcloud.com/2134 Tested-by: Hudson Reviewed-by: Bobi Jam Reviewed-by: Alex Zhuravlev Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index 2ad22f0..7e40191 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -619,7 +619,7 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env, cfs_hash_bd_lock(hs, &bd, 1); shadow = htable_lookup(s, &bd, f, waiter, &version); - if (likely(shadow == NULL)) { + if (shadow == NULL) { struct lu_site_bkt_data *bkt; bkt = cfs_hash_bd_extra_get(hs, &bd); @@ -627,12 +627,14 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env, bkt->lsb_busy++; cfs_hash_bd_unlock(hs, &bd, 1); return o; + } else { + if (!cfs_list_empty(&shadow->lo_header->loh_lru)) + cfs_list_del_init(&shadow->lo_header->loh_lru); + lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_RACE); + cfs_hash_bd_unlock(hs, &bd, 1); + lu_object_free(env, o); + return shadow; } - - lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_RACE); - cfs_hash_bd_unlock(hs, &bd, 1); - lu_object_free(env, o); - return shadow; } /**