-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include <libcfs/libcfs.h>
#if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1
-static unsigned int warn_on_depth = 0;
+static unsigned int warn_on_depth = 8;
CFS_MODULE_PARM(warn_on_depth, "i", uint, 0644,
"warning when hash depth is high.");
#endif
+struct cfs_wi_sched *cfs_sched_rehash;
+
static inline void
cfs_hash_nl_lock(cfs_hash_lock_t *lock, int exclusive) {}
hs->hs_dep_bits = hs->hs_cur_bits;
cfs_spin_unlock(&hs->hs_dep_lock);
- cfs_wi_schedule(&hs->hs_dep_wi);
+ cfs_wi_schedule(cfs_sched_rehash, &hs->hs_dep_wi);
# endif
}
static void cfs_hash_depth_wi_init(cfs_hash_t *hs)
{
- cfs_spin_lock_init(&hs->hs_dep_lock);
- cfs_wi_init(&hs->hs_dep_wi, hs,
- cfs_hash_dep_print, CFS_WI_SCHED_ANY);
+ cfs_spin_lock_init(&hs->hs_dep_lock);
+ cfs_wi_init(&hs->hs_dep_wi, hs, cfs_hash_dep_print);
}
static void cfs_hash_depth_wi_cancel(cfs_hash_t *hs)
{
- if (cfs_wi_cancel(&hs->hs_dep_wi))
+ if (cfs_wi_deschedule(cfs_sched_rehash, &hs->hs_dep_wi))
return;
cfs_spin_lock(&hs->hs_dep_lock);
hs->hs_ops = ops;
hs->hs_extra_bytes = extra_bytes;
hs->hs_rehash_bits = 0;
- cfs_wi_init(&hs->hs_rehash_wi, hs,
- cfs_hash_rehash_worker, CFS_WI_SCHED_ANY);
+ cfs_wi_init(&hs->hs_rehash_wi, hs, cfs_hash_rehash_worker);
cfs_hash_depth_wi_init(hs);
if (cfs_hash_with_rehash(hs))
void cfs_hash_putref(cfs_hash_t *hs)
{
- if (hs && cfs_atomic_dec_and_test(&hs->hs_refcount))
+ if (cfs_atomic_dec_and_test(&hs->hs_refcount))
cfs_hash_destroy(hs);
}
CFS_EXPORT_SYMBOL(cfs_hash_putref);
cfs_hash_lock(hs, 0);
cfs_hash_dual_bd_get_and_lock(hs, key, bds, 1);
- if (bds[1].bd_bucket == NULL && hnode != NULL)
- cfs_hash_bd_del_locked(hs, &bds[0], hnode);
- else
- hnode = cfs_hash_dual_bd_finddel_locked(hs, bds, key, hnode);
+ /* NB: do nothing if @hnode is not in hash table */
+ if (hnode == NULL || !cfs_hlist_unhashed(hnode)) {
+ if (bds[1].bd_bucket == NULL && hnode != NULL) {
+ cfs_hash_bd_del_locked(hs, &bds[0], hnode);
+ } else {
+ hnode = cfs_hash_dual_bd_finddel_locked(hs, bds,
+ key, hnode);
+ }
+ }
if (hnode != NULL) {
obj = cfs_hash_object(hs, hnode);
if (!cfs_hash_is_rehashing(hs))
return;
- if (cfs_wi_cancel(&hs->hs_rehash_wi)) {
+ if (cfs_wi_deschedule(cfs_sched_rehash, &hs->hs_rehash_wi)) {
hs->hs_rehash_bits = 0;
return;
}
hs->hs_rehash_bits = rc;
if (!do_rehash) {
/* launch and return */
- cfs_wi_schedule(&hs->hs_rehash_wi);
+ cfs_wi_schedule(cfs_sched_rehash, &hs->hs_rehash_wi);
cfs_hash_unlock(hs, 1);
return 0;
}
hs->hs_cur_bits = hs->hs_rehash_bits;
out:
hs->hs_rehash_bits = 0;
- if (rc == -ESRCH)
- cfs_wi_exit(wi); /* never be scheduled again */
+ if (rc == -ESRCH) /* never be scheduled again */
+ cfs_wi_exit(cfs_sched_rehash, wi);
bsize = cfs_hash_bkt_size(hs);
cfs_hash_unlock(hs, 1);
/* can't refer to @hs anymore because it could be destroyed */
cfs_hash_buckets_free(bkts, bsize, new_size, old_size);
if (rc != 0)
CDEBUG(D_INFO, "early quit of of rehashing: %d\n", rc);
- /* cfs_workitem require us to always return 0 */
- return 0;
+ /* return 1 only if cfs_wi_exit is called */
+ return rc == -ESRCH;
}
/**