From 9c1b858fd0eecc4136471643a8b35ade65e4772e Mon Sep 17 00:00:00 2001 From: Lei Feng Date: Fri, 9 Jun 2023 11:04:37 +0800 Subject: [PATCH] EX-7584 ptlrpc: define nrs_orr_object.oo_ref atomic_t nrs_orr_object.oo_ref is a reference counter but not atomic type. nrs_trr_hash_ops.hs_put() is filled with nrs_orr_hop_put(), which decreases oo_ref without any protection. So change it to atomic_t to eliminate any potential race condition. Signed-off-by: Lei Feng Test-Parameters: trivial testlist=sanityn env=ONLY=77d,ONLY_REPEAT=100 Change-Id: I69d27eebdddab79d7dd7e279391cd841e438b5d3 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52948 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/include/lustre_nrs_orr.h | 2 +- lustre/ptlrpc/nrs_orr.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lustre/include/lustre_nrs_orr.h b/lustre/include/lustre_nrs_orr.h index 3698a80..609eb25 100644 --- a/lustre/include/lustre_nrs_orr.h +++ b/lustre/include/lustre_nrs_orr.h @@ -165,7 +165,7 @@ struct nrs_orr_object { * scheduling RPCs */ struct nrs_orr_key oo_key; - long oo_ref; + atomic_t oo_ref; /** * Round Robin quantum; the maximum number of RPCs that are allowed to * be scheduled for the object or OST in a single batch of each round. diff --git a/lustre/ptlrpc/nrs_orr.c b/lustre/ptlrpc/nrs_orr.c index 9324dbd..6d3ab7e 100644 --- a/lustre/ptlrpc/nrs_orr.c +++ b/lustre/ptlrpc/nrs_orr.c @@ -421,7 +421,7 @@ static void nrs_orr_hop_get(struct cfs_hash *hs, struct hlist_node *hnode) struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); - orro->oo_ref++; + atomic_inc(&orro->oo_ref); } /** @@ -439,13 +439,12 @@ static void nrs_orr_hop_put_free(struct cfs_hash *hs, struct hlist_node *hnode) cfs_hash_bd_get_and_lock(hs, &orro->oo_key, &bd, 1); - if (--orro->oo_ref > 1) { + if (atomic_dec_return(&orro->oo_ref) > 1) { cfs_hash_bd_unlock(hs, &bd, 1); - return; } - LASSERT(orro->oo_ref == 1); + LASSERT(atomic_read(&orro->oo_ref) == 1); cfs_hash_bd_del_locked(hs, &bd, hnode); cfs_hash_bd_unlock(hs, &bd, 1); @@ -457,7 +456,7 @@ static void nrs_orr_hop_put(struct cfs_hash *hs, struct hlist_node *hnode) struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); - orro->oo_ref--; + atomic_dec(&orro->oo_ref); } static int nrs_trr_hop_keycmp(const void *key, struct hlist_node *hnode) @@ -476,10 +475,11 @@ static void nrs_trr_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode) oo_hnode); struct nrs_orr_data *orrd = container_of(orro->oo_res.res_parent, struct nrs_orr_data, od_res); + int refs = atomic_read(&orro->oo_ref); - LASSERTF(orro->oo_ref == 0, - "Busy NRS TRR policy object for OST with index %u, with %ld " - "refs\n", orro->oo_key.ok_idx, orro->oo_ref); + LASSERTF(refs == 0, + "Busy NRS TRR policy object for OST with index %u, with %d " + "refs\n", orro->oo_key.ok_idx, refs); OBD_SLAB_FREE_PTR(orro, orrd->od_cache); } @@ -876,7 +876,7 @@ static int nrs_orr_res_get(struct ptlrpc_nrs_policy *policy, RETURN(-ENOMEM); orro->oo_key = key; - orro->oo_ref = 1; + atomic_set(&orro->oo_ref, 1); tmp = cfs_hash_findadd_unique(orrd->od_obj_hash, &orro->oo_key, &orro->oo_hnode); -- 1.8.3.1