#include <linux/spinlock.h>
#include <linux/workqueue.h>
+#include <linux/refcount.h>
#include <libcfs/linux/linux-hash.h>
/** disable debug */
static inline int
cfs_hash_bd_dec_and_lock(struct cfs_hash *hs, struct cfs_hash_bd *bd,
- atomic_t *condition)
+ refcount_t *condition)
{
LASSERT(cfs_hash_with_spin_bktlock(hs));
- return atomic_dec_and_lock(condition, &bd->bd_bucket->hsb_lock.spin);
+ return refcount_dec_and_lock(condition, &bd->bd_bucket->hsb_lock.spin);
}
static inline struct hlist_head *
};
/** Reference count for this resource */
- atomic_t lr_refcount;
+ refcount_t lr_refcount;
/** Spinlock to protect locks under this resource. */
spinlock_t lr_lock;
/** Hash key of the client. */
char tc_key[NRS_TBF_KEY_LEN];
/** Reference number of the client. */
- atomic_t tc_ref;
+ refcount_t tc_ref;
/** Lock to protect rule and linkage. */
spinlock_t tc_rule_lock;
/** Linkage to rule. */
* Helper function.
*/
void _ldlm_lock_debug(struct ldlm_lock *lock,
- struct libcfs_debug_msg_data *msgdata,
- const char *fmt, ...)
+ struct libcfs_debug_msg_data *msgdata,
+ const char *fmt, ...)
{
- va_list args;
- struct obd_export *exp = lock->l_export;
+ va_list args;
+ struct obd_export *exp = lock->l_export;
struct ldlm_resource *resource = NULL;
struct va_format vaf;
- char *nid = "local";
+ char *nid = "local";
rcu_read_lock();
resource = rcu_dereference(lock->l_resource);
- if (resource && !atomic_inc_not_zero(&resource->lr_refcount))
+ if (resource && !refcount_inc_not_zero(&resource->lr_refcount))
resource = NULL;
rcu_read_unlock();
- va_start(args, fmt);
+ va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
- if (exp && exp->exp_connection) {
+ if (exp && exp->exp_connection) {
nid = obd_export_nid2str(exp);
- } else if (exp && exp->exp_obd != NULL) {
- struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
+ } else if (exp && exp->exp_obd != NULL) {
+ struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
+
nid = obd_import_nid2str(imp);
- }
+ }
- if (resource == NULL) {
+ if (resource == NULL) {
libcfs_debug_msg(msgdata,
"%pV ns: \?\? lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s res: \?\? rrc=\?\? type: \?\?\? flags: %#llx nid: %s remote: %#llx expref: %d pid: %u timeout: %lld lvb_type: %d\n",
&vaf,
exp ? refcount_read(&exp->exp_handle.h_ref) : -99,
lock->l_pid, lock->l_callback_timestamp,
lock->l_lvb_type);
- va_end(args);
- return;
- }
+ va_end(args);
+ return;
+ }
switch (resource->lr_type) {
case LDLM_EXTENT:
ldlm_lockname[lock->l_granted_mode],
ldlm_lockname[lock->l_req_mode],
PLDLMRES(resource),
- atomic_read(&resource->lr_refcount),
+ refcount_read(&resource->lr_refcount),
ldlm_typename[resource->lr_type],
lock->l_policy_data.l_extent.start,
lock->l_policy_data.l_extent.end,
ldlm_lockname[lock->l_granted_mode],
ldlm_lockname[lock->l_req_mode],
PLDLMRES(resource),
- atomic_read(&resource->lr_refcount),
+ refcount_read(&resource->lr_refcount),
ldlm_typename[resource->lr_type],
lock->l_policy_data.l_flock.pid,
lock->l_policy_data.l_flock.start,
PLDLMRES(resource),
lock->l_policy_data.l_inodebits.bits,
lock->l_policy_data.l_inodebits.try_bits,
- atomic_read(&resource->lr_refcount),
+ refcount_read(&resource->lr_refcount),
ldlm_typename[resource->lr_type],
lock->l_flags, lock->l_pid,
lock->l_policy_data.l_inodebits.li_initiator_id);
PLDLMRES(resource),
lock->l_policy_data.l_inodebits.bits,
lock->l_policy_data.l_inodebits.try_bits,
- atomic_read(&resource->lr_refcount),
+ refcount_read(&resource->lr_refcount),
ldlm_typename[resource->lr_type],
lock->l_policy_data.l_inodebits.li_gid,
lock->l_flags, nid,
ldlm_lockname[lock->l_granted_mode],
ldlm_lockname[lock->l_req_mode],
PLDLMRES(resource),
- atomic_read(&resource->lr_refcount),
+ refcount_read(&resource->lr_refcount),
ldlm_typename[resource->lr_type],
lock->l_flags, nid,
lock->l_remote_handle.cookie,
CERROR("%s: namespace resource "DLDLMRES" (%p) refcount nonzero "
"(%d) after lock cleanup; forcing cleanup.\n",
ldlm_ns_name(ldlm_res_to_ns(res)), PLDLMRES(res), res,
- atomic_read(&res->lr_refcount) - 1);
+ refcount_read(&res->lr_refcount) - 1);
/* Use D_NETERROR since it is in the default mask */
ldlm_resource_dump(D_NETERROR, res);
INIT_LIST_HEAD(&res->lr_granted);
INIT_LIST_HEAD(&res->lr_waiting);
- atomic_set(&res->lr_refcount, 1);
+ refcount_set(&res->lr_refcount, 1);
spin_lock_init(&res->lr_lock);
lu_ref_init(&res->lr_reference);
{
LASSERT(res != NULL);
LASSERT(res != LP_POISON);
- atomic_inc(&res->lr_refcount);
+ refcount_inc(&res->lr_refcount);
CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
- atomic_read(&res->lr_refcount));
+ refcount_read(&res->lr_refcount));
return res;
}
static void __ldlm_resource_putref_final(struct cfs_hash_bd *bd,
- struct ldlm_resource *res)
+ struct ldlm_resource *res)
{
struct ldlm_ns_bucket *nsb = res->lr_ns_bucket;
struct cfs_hash_bd bd;
int refcount;
- refcount = atomic_read(&res->lr_refcount);
- LASSERT(refcount > 0 && refcount < LI_POISON);
+ refcount = refcount_read(&res->lr_refcount);
+ LASSERT(refcount < LI_POISON);
CDEBUG(D_INFO, "putref res: %p count: %d\n",
- res, atomic_read(&res->lr_refcount) - 1);
+ res, refcount_read(&res->lr_refcount) - 1);
cfs_hash_bd_get(ns->ns_rs_hash, &res->lr_name, &bd);
if (cfs_hash_bd_dec_and_lock(ns->ns_rs_hash, &bd, &res->lr_refcount)) {
return;
CDEBUG(level, "--- Resource: "DLDLMRES" (%p) refcount = %d\n",
- PLDLMRES(res), res, atomic_read(&res->lr_refcount));
+ PLDLMRES(res), res, refcount_read(&res->lr_refcount));
if (!list_empty(&res->lr_granted)) {
CDEBUG(level, "Granted locks (in reverse order):\n");
INIT_LIST_HEAD(&cli->tc_list);
INIT_LIST_HEAD(&cli->tc_linkage);
spin_lock_init(&cli->tc_rule_lock);
- atomic_set(&cli->tc_ref, 1);
+ refcount_set(&cli->tc_ref, 1);
rule = nrs_tbf_rule_match(head, cli);
nrs_tbf_cli_reset(head, rule, cli);
}
{
LASSERT(list_empty(&cli->tc_list));
LASSERT(!cli->tc_in_heap);
- LASSERT(atomic_read(&cli->tc_ref) == 0);
spin_lock(&cli->tc_rule_lock);
nrs_tbf_cli_rule_put(cli);
spin_unlock(&cli->tc_rule_lock);
struct nrs_tbf_client,
tc_hnode);
- atomic_inc(&cli->tc_ref);
+ refcount_inc(&cli->tc_ref);
}
static void nrs_tbf_jobid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
struct nrs_tbf_client,
tc_hnode);
- atomic_dec(&cli->tc_ref);
+ refcount_dec(&cli->tc_ref);
}
static void
struct nrs_tbf_client,
tc_hnode);
- LASSERT(atomic_read(&cli->tc_ref) == 0);
nrs_tbf_cli_fini(cli);
}
cli = list_first_entry(&bkt->ntb_lru,
struct nrs_tbf_client,
tc_lru);
- LASSERT(atomic_read(&cli->tc_ref) == 0);
cfs_hash_bd_del_locked(hs, &bd, &cli->tc_hnode);
list_move(&cli->tc_lru, &zombies);
}
struct nrs_tbf_client,
tc_hnode);
- atomic_inc(&cli->tc_ref);
+ refcount_inc(&cli->tc_ref);
}
static void nrs_tbf_nid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
struct nrs_tbf_client,
tc_hnode);
- atomic_dec(&cli->tc_ref);
+ refcount_dec(&cli->tc_ref);
}
static void nrs_tbf_nid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
struct nrs_tbf_client,
tc_hnode);
- LASSERTF(atomic_read(&cli->tc_ref) == 0,
- "Busy TBF object from client with NID %s, with %d refs\n",
- libcfs_nidstr(&cli->tc_nid), atomic_read(&cli->tc_ref));
+ CDEBUG(D_RPCTRACE,
+ "Busy TBF object from client with NID %s, with %d refs\n",
+ libcfs_nidstr(&cli->tc_nid), refcount_read(&cli->tc_ref));
nrs_tbf_cli_fini(cli);
}
struct nrs_tbf_client,
tc_hnode);
- atomic_inc(&cli->tc_ref);
+ refcount_inc(&cli->tc_ref);
}
static void nrs_tbf_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
struct nrs_tbf_client,
tc_hnode);
- atomic_dec(&cli->tc_ref);
+ refcount_dec(&cli->tc_ref);
}
static void nrs_tbf_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
struct nrs_tbf_client,
tc_hnode);
- LASSERT(atomic_read(&cli->tc_ref) == 0);
nrs_tbf_cli_fini(cli);
}
cli = list_first_entry(&bkt->ntb_lru,
struct nrs_tbf_client,
tc_lru);
- LASSERT(atomic_read(&cli->tc_ref) == 0);
cfs_hash_bd_del_locked(hs, &bd, &cli->tc_hnode);
list_move(&cli->tc_lru, &zombies);
}
struct nrs_tbf_client,
tc_hnode);
- atomic_inc(&cli->tc_ref);
+ refcount_inc(&cli->tc_ref);
}
static void nrs_tbf_opcode_hop_put(struct cfs_hash *hs,
struct nrs_tbf_client,
tc_hnode);
- atomic_dec(&cli->tc_ref);
+ refcount_dec(&cli->tc_ref);
}
static void nrs_tbf_opcode_hop_exit(struct cfs_hash *hs,
struct nrs_tbf_client,
tc_hnode);
- LASSERTF(atomic_read(&cli->tc_ref) == 0,
- "Busy TBF object from client with opcode %s, with %d refs\n",
- ll_opcode2str(cli->tc_opcode),
- atomic_read(&cli->tc_ref));
+ CDEBUG(D_RPCTRACE,
+ "Busy TBF object from client with opcode %s, with %d refs\n",
+ ll_opcode2str(cli->tc_opcode), refcount_read(&cli->tc_ref));
nrs_tbf_cli_fini(cli);
}
struct nrs_tbf_client,
tc_hnode);
- atomic_inc(&cli->tc_ref);
+ refcount_inc(&cli->tc_ref);
}
static void nrs_tbf_id_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
struct nrs_tbf_client,
tc_hnode);
- atomic_dec(&cli->tc_ref);
+ refcount_dec(&cli->tc_ref);
}
static void
struct nrs_tbf_client,
tc_hnode);
- LASSERT(atomic_read(&cli->tc_ref) == 0);
nrs_tbf_cli_fini(cli);
}
nrs_tbf_cli_init(head, cli, req);
tmp = head->th_ops->o_cli_findadd(head, cli);
if (tmp != cli) {
- atomic_dec(&cli->tc_ref);
+ refcount_dec(&cli->tc_ref);
nrs_tbf_cli_fini(cli);
cli = tmp;
}