Whamcloud - gitweb
EX-7584 ptlrpc: define nrs_orr_object.oo_ref atomic_t
authorLei Feng <flei@whamcloud.com>
Fri, 9 Jun 2023 03:04:37 +0000 (11:04 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Sun, 5 Nov 2023 10:42:45 +0000 (10:42 +0000)
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 <flei@whamcloud.com>
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 <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/lustre_nrs_orr.h
lustre/ptlrpc/nrs_orr.c

index 3698a80..609eb25 100644 (file)
@@ -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.
index 9324dbd..6d3ab7e 100644 (file)
@@ -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);