From 7375cd6da6329e4d4a4bfb600d4fc9552b3c4c6f Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 12 Dec 2023 12:46:19 +0530 Subject: [PATCH] LU-16796 ldlm: Change struct ldlm_resource to use refcount_t This patch changes struct ldlm_resource and struct nrs_tbf_client to use refcount_t instead of atomic_t This patch also only changes spaces to tabs which were close to lines of code being changed. Signed-off-by: Arshad Hussain Change-Id: Ic15f27bc6281725f00bddc465668f81291aad6ec Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53416 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/libcfs_hash.h | 5 +++-- lustre/include/lustre_dlm.h | 2 +- lustre/include/lustre_nrs_tbf.h | 2 +- lustre/ldlm/ldlm_lock.c | 41 ++++++++++++++++++----------------- lustre/ldlm/ldlm_resource.c | 18 ++++++++-------- lustre/ptlrpc/nrs_tbf.c | 43 ++++++++++++++++--------------------- 6 files changed, 53 insertions(+), 58 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_hash.h b/libcfs/include/libcfs/libcfs_hash.h index 64feebf..7faa002 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/libcfs/include/libcfs/libcfs_hash.h @@ -39,6 +39,7 @@ #include #include +#include #include /** disable debug */ @@ -610,10 +611,10 @@ void cfs_hash_bd_move_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd_old, 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 * diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index 82e7a55..a5a3404 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -1083,7 +1083,7 @@ struct ldlm_resource { }; /** Reference count for this resource */ - atomic_t lr_refcount; + refcount_t lr_refcount; /** Spinlock to protect locks under this resource. */ spinlock_t lr_lock; diff --git a/lustre/include/lustre_nrs_tbf.h b/lustre/include/lustre_nrs_tbf.h index 442bafe..39365d5 100644 --- a/lustre/include/lustre_nrs_tbf.h +++ b/lustre/include/lustre_nrs_tbf.h @@ -92,7 +92,7 @@ struct nrs_tbf_client { /** 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. */ diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index 987c253..1d62ddc 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -2804,33 +2804,34 @@ EXPORT_SYMBOL(ldlm_lock_dump_handle); * 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, @@ -2845,9 +2846,9 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, 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: @@ -2861,7 +2862,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, 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, @@ -2885,7 +2886,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, 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, @@ -2910,7 +2911,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, 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); @@ -2927,7 +2928,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, 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, @@ -2948,7 +2949,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, 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, diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 30cde96..2d09fdd 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -1122,7 +1122,7 @@ static int ldlm_resource_complain(struct cfs_hash *hs, struct cfs_hash_bd *bd, 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); @@ -1452,7 +1452,7 @@ static struct ldlm_resource *ldlm_resource_new(enum ldlm_type ldlm_type) 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); @@ -1572,14 +1572,14 @@ struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res) { 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; @@ -1607,11 +1607,11 @@ int ldlm_resource_putref(struct ldlm_resource *res) 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)) { @@ -1790,7 +1790,7 @@ void ldlm_resource_dump(int level, struct ldlm_resource *res) 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"); diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 43fa946..7623174 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -260,7 +260,7 @@ nrs_tbf_cli_init(struct nrs_tbf_head *head, 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); } @@ -270,7 +270,6 @@ nrs_tbf_cli_fini(struct nrs_tbf_client *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); @@ -580,7 +579,7 @@ static void nrs_tbf_jobid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode) 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) @@ -589,7 +588,7 @@ 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 @@ -600,7 +599,6 @@ nrs_tbf_jobid_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); } @@ -707,7 +705,6 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head, 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); } @@ -1076,7 +1073,7 @@ static void nrs_tbf_nid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode) 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) @@ -1085,7 +1082,7 @@ 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) @@ -1094,9 +1091,9 @@ 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); } @@ -1305,7 +1302,7 @@ static void nrs_tbf_hop_get(struct cfs_hash *hs, struct hlist_node *hnode) 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) @@ -1314,7 +1311,7 @@ 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) @@ -1324,7 +1321,6 @@ 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); } @@ -1722,7 +1718,6 @@ nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *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); } @@ -2116,7 +2111,7 @@ static void nrs_tbf_opcode_hop_get(struct cfs_hash *hs, 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, @@ -2126,7 +2121,7 @@ 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, @@ -2136,10 +2131,9 @@ 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); } @@ -2387,7 +2381,7 @@ static void nrs_tbf_id_hop_get(struct cfs_hash *hs, struct hlist_node *hnode) 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) @@ -2396,7 +2390,7 @@ 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 @@ -2407,7 +2401,6 @@ nrs_tbf_id_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); } @@ -2970,7 +2963,7 @@ static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy, 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; } -- 1.8.3.1