void
cfs_hash_bd_add_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd,
- cfs_hlist_node_t *hnode)
+ cfs_hlist_node_t *hnode)
{
- int rc;
+ int rc;
- rc = hs->hs_hops->hop_hnode_add(hs, bd, hnode);
- cfs_hash_bd_dep_record(hs, bd, rc);
- bd->bd_bucket->hsb_version++;
- if (unlikely(bd->bd_bucket->hsb_version == 0))
- bd->bd_bucket->hsb_version++;
- bd->bd_bucket->hsb_count++;
+ rc = hs->hs_hops->hop_hnode_add(hs, bd, hnode);
+ cfs_hash_bd_dep_record(hs, bd, rc);
+ bd->bd_bucket->hsb_version++;
+ if (unlikely(bd->bd_bucket->hsb_version == 0))
+ bd->bd_bucket->hsb_version++;
+ bd->bd_bucket->hsb_count++;
- if (cfs_hash_with_counter(hs))
- cfs_atomic_inc(&hs->hs_count);
- if (!cfs_hash_with_no_itemref(hs))
- cfs_hash_get(hs, hnode);
+ if (cfs_hash_with_counter(hs))
+ atomic_inc(&hs->hs_count);
+ if (!cfs_hash_with_no_itemref(hs))
+ cfs_hash_get(hs, hnode);
}
EXPORT_SYMBOL(cfs_hash_bd_add_locked);
void
cfs_hash_bd_del_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd,
- cfs_hlist_node_t *hnode)
+ cfs_hlist_node_t *hnode)
{
- hs->hs_hops->hop_hnode_del(hs, bd, hnode);
+ hs->hs_hops->hop_hnode_del(hs, bd, hnode);
- LASSERT(bd->bd_bucket->hsb_count > 0);
- bd->bd_bucket->hsb_count--;
- bd->bd_bucket->hsb_version++;
- if (unlikely(bd->bd_bucket->hsb_version == 0))
- bd->bd_bucket->hsb_version++;
+ LASSERT(bd->bd_bucket->hsb_count > 0);
+ bd->bd_bucket->hsb_count--;
+ bd->bd_bucket->hsb_version++;
+ if (unlikely(bd->bd_bucket->hsb_version == 0))
+ bd->bd_bucket->hsb_version++;
- if (cfs_hash_with_counter(hs)) {
- LASSERT(cfs_atomic_read(&hs->hs_count) > 0);
- cfs_atomic_dec(&hs->hs_count);
- }
- if (!cfs_hash_with_no_itemref(hs))
- cfs_hash_put_locked(hs, hnode);
+ if (cfs_hash_with_counter(hs)) {
+ LASSERT(atomic_read(&hs->hs_count) > 0);
+ atomic_dec(&hs->hs_count);
+ }
+ if (!cfs_hash_with_no_itemref(hs))
+ cfs_hash_put_locked(hs, hnode);
}
EXPORT_SYMBOL(cfs_hash_bd_del_locked);
spin_lock(&hs->hs_dep_lock);
while (hs->hs_dep_bits != 0) {
spin_unlock(&hs->hs_dep_lock);
- cfs_cond_resched();
+ cond_resched();
spin_lock(&hs->hs_dep_lock);
}
spin_unlock(&hs->hs_dep_lock);
if (hs == NULL)
RETURN(NULL);
- strncpy(hs->hs_name, name, len);
- hs->hs_name[len - 1] = '\0';
- hs->hs_flags = flags;
+ strncpy(hs->hs_name, name, len);
+ hs->hs_name[len - 1] = '\0';
+ hs->hs_flags = flags;
- cfs_atomic_set(&hs->hs_refcount, 1);
- cfs_atomic_set(&hs->hs_count, 0);
+ atomic_set(&hs->hs_refcount, 1);
+ atomic_set(&hs->hs_count, 0);
- cfs_hash_lock_setup(hs);
- cfs_hash_hlist_setup(hs);
+ cfs_hash_lock_setup(hs);
+ cfs_hash_hlist_setup(hs);
hs->hs_cur_bits = (__u8)cur_bits;
hs->hs_min_bits = (__u8)cur_bits;
cfs_hash_exit(hs, hnode);
}
}
- LASSERT(bd.bd_bucket->hsb_count == 0);
- cfs_hash_bd_unlock(hs, &bd, 1);
- cfs_cond_resched();
- }
+ LASSERT(bd.bd_bucket->hsb_count == 0);
+ cfs_hash_bd_unlock(hs, &bd, 1);
+ cond_resched();
+ }
- LASSERT(cfs_atomic_read(&hs->hs_count) == 0);
+ LASSERT(atomic_read(&hs->hs_count) == 0);
- cfs_hash_buckets_free(hs->hs_buckets, cfs_hash_bkt_size(hs),
- 0, CFS_HASH_NBKT(hs));
- i = cfs_hash_with_bigname(hs) ?
- CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN;
- LIBCFS_FREE(hs, offsetof(cfs_hash_t, hs_name[i]));
+ cfs_hash_buckets_free(hs->hs_buckets, cfs_hash_bkt_size(hs),
+ 0, CFS_HASH_NBKT(hs));
+ i = cfs_hash_with_bigname(hs) ?
+ CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN;
+ LIBCFS_FREE(hs, offsetof(cfs_hash_t, hs_name[i]));
- EXIT;
+ EXIT;
}
cfs_hash_t *cfs_hash_getref(cfs_hash_t *hs)
{
- if (cfs_atomic_inc_not_zero(&hs->hs_refcount))
- return hs;
- return NULL;
+ if (atomic_inc_not_zero(&hs->hs_refcount))
+ return hs;
+ return NULL;
}
EXPORT_SYMBOL(cfs_hash_getref);
void cfs_hash_putref(cfs_hash_t *hs)
{
- if (cfs_atomic_dec_and_test(&hs->hs_refcount))
- cfs_hash_destroy(hs);
+ if (atomic_dec_and_test(&hs->hs_refcount))
+ cfs_hash_destroy(hs);
}
EXPORT_SYMBOL(cfs_hash_putref);
static inline int
cfs_hash_rehash_inline(cfs_hash_t *hs)
{
- return !cfs_hash_with_nblk_change(hs) &&
- cfs_atomic_read(&hs->hs_count) < CFS_HASH_LOOP_HOG;
+ return !cfs_hash_with_nblk_change(hs) &&
+ atomic_read(&hs->hs_count) < CFS_HASH_LOOP_HOG;
}
/**
static void
cfs_hash_for_each_exit(cfs_hash_t *hs)
{
- int remained;
- int bits;
+ int remained;
+ int bits;
- if (!cfs_hash_with_rehash(hs))
- return;
- cfs_hash_lock(hs, 1);
- remained = --hs->hs_iterators;
- bits = cfs_hash_rehash_bits(hs);
- cfs_hash_unlock(hs, 1);
- /* NB: it's race on cfs_has_t::hs_iterating, see above */
- if (remained == 0)
- hs->hs_iterating = 0;
- if (bits > 0) {
- cfs_hash_rehash(hs, cfs_atomic_read(&hs->hs_count) <
- CFS_HASH_LOOP_HOG);
- }
+ if (!cfs_hash_with_rehash(hs))
+ return;
+ cfs_hash_lock(hs, 1);
+ remained = --hs->hs_iterators;
+ bits = cfs_hash_rehash_bits(hs);
+ cfs_hash_unlock(hs, 1);
+ /* NB: it's race on cfs_has_t::hs_iterating, see above */
+ if (remained == 0)
+ hs->hs_iterating = 0;
+ if (bits > 0) {
+ cfs_hash_rehash(hs, atomic_read(&hs->hs_count) <
+ CFS_HASH_LOOP_HOG);
+ }
}
/**
cfs_hash_bd_unlock(hs, &bd, excl);
if (loop < CFS_HASH_LOOP_HOG)
continue;
- loop = 0;
- cfs_hash_unlock(hs, 0);
- cfs_cond_resched();
- cfs_hash_lock(hs, 0);
- }
+ loop = 0;
+ cfs_hash_unlock(hs, 0);
+ cond_resched();
+ cfs_hash_lock(hs, 0);
+ }
out:
cfs_hash_unlock(hs, 0);
__u64
cfs_hash_size_get(cfs_hash_t *hs)
{
- return cfs_hash_with_counter(hs) ?
- cfs_atomic_read(&hs->hs_count) :
- cfs_hash_for_each_tight(hs, NULL, NULL, 0);
+ return cfs_hash_with_counter(hs) ?
+ atomic_read(&hs->hs_count) :
+ cfs_hash_for_each_tight(hs, NULL, NULL, 0);
}
EXPORT_SYMBOL(cfs_hash_size_get);
cfs_hash_bd_unlock(hs, &bd, 0);
cfs_hash_unlock(hs, 0);
- rc = func(hs, &bd, hnode, data);
- if (stop_on_change)
- cfs_hash_put(hs, hnode);
- cfs_cond_resched();
- count++;
+ rc = func(hs, &bd, hnode, data);
+ if (stop_on_change)
+ cfs_hash_put(hs, hnode);
+ cond_resched();
+ count++;
cfs_hash_lock(hs, 0);
cfs_hash_bd_lock(hs, &bd, 0);
}
for (i = 2; cfs_hash_is_rehashing(hs); i++) {
- cfs_hash_unlock(hs, 1);
- /* raise console warning while waiting too long */
- CDEBUG(IS_PO2(i >> 3) ? D_WARNING : D_INFO,
- "hash %s is still rehashing, rescheded %d\n",
- hs->hs_name, i - 1);
- cfs_cond_resched();
- cfs_hash_lock(hs, 1);
- }
+ cfs_hash_unlock(hs, 1);
+ /* raise console warning while waiting too long */
+ CDEBUG(IS_PO2(i >> 3) ? D_WARNING : D_INFO,
+ "hash %s is still rehashing, rescheded %d\n",
+ hs->hs_name, i - 1);
+ cond_resched();
+ cfs_hash_lock(hs, 1);
+ }
}
EXPORT_SYMBOL(cfs_hash_rehash_cancel_locked);
continue;
}
- count = 0;
- cfs_hash_unlock(hs, 1);
- cfs_cond_resched();
- cfs_hash_lock(hs, 1);
- }
+ count = 0;
+ cfs_hash_unlock(hs, 1);
+ cond_resched();
+ cfs_hash_lock(hs, 1);
+ }
hs->hs_rehash_count++;