Whamcloud - gitweb
LU-16796 mdt: Change struct cdt_agent_record_loc to use kref 53/52153/3
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Tue, 29 Aug 2023 07:41:51 +0000 (13:11 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 13 Sep 2023 04:06:34 +0000 (04:06 +0000)
This patch changes struct cdt_agent_record_loc to use
kref(refcount_t) instead of atomic_t

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I99141b00b4cfc7b4b46a87462b9ce21735bb0e7d
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52153
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mdt/mdt_hsm_cdt_actions.c

index f74f79e..773300d 100644 (file)
@@ -47,7 +47,7 @@
 
 struct cdt_agent_record_loc {
        struct hlist_node carl_hnode;
-       atomic_t carl_refcount;
+       struct kref carl_refcount;
        u64 carl_cookie;
        u32 carl_cat_idx;
        u32 carl_rec_idx;
@@ -55,15 +55,21 @@ struct cdt_agent_record_loc {
 
 static inline void cdt_agent_record_loc_get(struct cdt_agent_record_loc *carl)
 {
-       LASSERT(atomic_read(&carl->carl_refcount) > 0);
-       atomic_inc(&carl->carl_refcount);
+       kref_get(&carl->carl_refcount);
+}
+
+static void cdt_agent_record_loc_put_free(struct kref *kref)
+{
+       struct cdt_agent_record_loc *carl;
+
+       carl = container_of(kref, struct cdt_agent_record_loc, carl_refcount);
+       OBD_FREE_PTR(carl);
+
 }
 
 static inline void cdt_agent_record_loc_put(struct cdt_agent_record_loc *carl)
 {
-       LASSERT(atomic_read(&carl->carl_refcount) > 0);
-       if (atomic_dec_and_test(&carl->carl_refcount))
-               OBD_FREE_PTR(carl);
+       kref_put(&carl->carl_refcount, cdt_agent_record_loc_put_free);
 }
 
 static unsigned int
@@ -125,7 +131,7 @@ void cdt_agent_record_hash_add(struct coordinator *cdt, u64 cookie, u32 cat_idx,
                return;
 
        INIT_HLIST_NODE(&carl1->carl_hnode);
-       atomic_set(&carl1->carl_refcount, 1);
+       kref_init(&carl1->carl_refcount);
        carl1->carl_cookie = cookie;
        carl1->carl_cat_idx = cat_idx;
        carl1->carl_rec_idx = rec_idx;