From b874534409ab56f2f5615cb2b4ffc667c91cb866 Mon Sep 17 00:00:00 2001 From: liangzhen Date: Wed, 15 Jul 2009 04:15:10 +0000 Subject: [PATCH] Branch HEAD ordering write_lock to avoid deadlock b=19518 i=adilger i=zhenyu.xu --- lustre/obdclass/class_hash.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lustre/obdclass/class_hash.c b/lustre/obdclass/class_hash.c index 6940f0d..5370a4e 100644 --- a/lustre/obdclass/class_hash.c +++ b/lustre/obdclass/class_hash.c @@ -652,7 +652,7 @@ void lustre_hash_rehash_key(lustre_hash_t *lh, void *old_key, void *new_key, lustre_hash_bucket_t *old_lhb; lustre_hash_bucket_t *new_lhb; unsigned i; - int j; + unsigned j; ENTRY; __lustre_hash_key_validate(lh, new_key, hnode); @@ -668,8 +668,17 @@ void lustre_hash_rehash_key(lustre_hash_t *lh, void *old_key, void *new_key, new_lhb = &lh->lh_buckets[j]; LASSERT(j <= lh->lh_cur_mask); - write_lock(&old_lhb->lhb_rwlock); - write_lock(&new_lhb->lhb_rwlock); + if (i < j) { /* write_lock ordering */ + write_lock(&old_lhb->lhb_rwlock); + write_lock(&new_lhb->lhb_rwlock); + } else if (i > j) { + write_lock(&new_lhb->lhb_rwlock); + write_lock(&old_lhb->lhb_rwlock); + } else { /* do nothing */ + read_unlock(&lh->lh_rwlock); + EXIT; + return; + } /* * Migrate item between hash buckets without calling -- 1.8.3.1