RETURN(NULL);
strncpy(lh->lh_name, name, sizeof(lh->lh_name));
+ lh->lh_name[sizeof(lh->lh_name) - 1] = '\0';
atomic_set(&lh->lh_rehash_count, 0);
atomic_set(&lh->lh_count, 0);
rwlock_init(&lh->lh_rwlock);
write_unlock(&lhb->lhb_rwlock);
}
- OBD_VFREE(lh->lh_buckets, sizeof(*lh->lh_buckets) << lh->lh_cur_bits);
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);
EXIT;
}
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
int lustre_hash_debug_header(char *str, int size)
{
return snprintf(str, size,
- "%-36s%6s%6s%6s%6s%6s%6s%6s%7s%6s%s\n",
+ "%-*s%6s%6s%6s%6s%6s%6s%6s%7s%6s%s\n", LUSTRE_MAX_HASH_NAME,
"name", "cur", "min", "max", "theta", "t-min", "t-max",
"flags", "rehash", "count", " distribution");
}
read_lock(&lh->lh_rwlock);
theta = __lustre_hash_theta(lh);
- c += snprintf(str + c, size - c, "%-36s ", lh->lh_name);
+ c += snprintf(str + c, size - c, "%-*s ",
+ LUSTRE_MAX_HASH_NAME, lh->lh_name);
c += snprintf(str + c, size - c, "%5d ", 1 << lh->lh_cur_bits);
c += snprintf(str + c, size - c, "%5d ", 1 << lh->lh_min_bits);
c += snprintf(str + c, size - c, "%5d ", 1 << lh->lh_max_bits);