LASSERT(max_bits >= cur_bits);
LASSERT(max_bits < 31);
- OBD_ALLOC_PTR(lh);
+ LIBCFS_ALLOC_PTR(lh);
if (!lh)
RETURN(NULL);
/* theta * 1000 */
__lustre_hash_set_theta(lh, 500, 2000);
- OBD_VMALLOC(lh->lh_buckets, sizeof(*lh->lh_buckets) << lh->lh_cur_bits);
+ LIBCFS_ALLOC(lh->lh_buckets, sizeof(*lh->lh_buckets) << lh->lh_cur_bits);
if (!lh->lh_buckets) {
- OBD_FREE_PTR(lh);
+ LIBCFS_FREE_PTR(lh);
RETURN(NULL);
}
LASSERT(atomic_read(&lh->lh_count) == 0);
write_unlock(&lh->lh_rwlock);
- OBD_VFREE(lh->lh_buckets, sizeof(*lh->lh_buckets) << lh->lh_cur_bits);
- OBD_FREE_PTR(lh);
+ LIBCFS_FREE(lh->lh_buckets, sizeof(*lh->lh_buckets) << lh->lh_cur_bits);
+ LIBCFS_FREE_PTR(lh);
EXIT;
}
EXPORT_SYMBOL(lustre_hash_exit);
LASSERT(!in_interrupt());
LASSERT(mask > 0);
- OBD_VMALLOC(rehash_buckets, sizeof(*rehash_buckets) << bits);
+ LIBCFS_ALLOC(rehash_buckets, sizeof(*rehash_buckets) << bits);
if (!rehash_buckets)
RETURN(-ENOMEM);
*/
theta = __lustre_hash_theta(lh);
if ((theta >= lh->lh_min_theta) && (theta <= lh->lh_max_theta)) {
- OBD_VFREE(rehash_buckets, sizeof(*rehash_buckets) << bits);
write_unlock(&lh->lh_rwlock);
+ LIBCFS_FREE(rehash_buckets, sizeof(*rehash_buckets) << bits);
RETURN(-EALREADY);
}
write_unlock(&lh_lhb->lhb_rwlock);
}
- OBD_VFREE(lh_buckets, sizeof(*lh_buckets) << lh_bits);
write_unlock(&lh->lh_rwlock);
+ LIBCFS_FREE(lh_buckets, sizeof(*lh_buckets) << lh_bits);
RETURN(0);
}
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);
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