Whamcloud - gitweb
LU-16796 mdt: Change struct cdt_agent_req to use kref 48/52148/3
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Tue, 29 Aug 2023 07:00:35 +0000 (12:30 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 6 Sep 2023 06:23:30 +0000 (06:23 +0000)
This patch changes struct cdt_agent_req to use
kref(refcount_t) instead of atomic_t

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I0a99002504ff453b8b748391f08bd1020c545321
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52148
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Etienne AUJAMES <eaujames@ddn.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mdt/mdt_hsm_cdt_requests.c
lustre/mdt/mdt_internal.h

index 9452638..66b8191 100644 (file)
@@ -116,7 +116,7 @@ void dump_requests(char *prefix, struct coordinator *cdt)
                       car->car_hai->hai_extent.offset,
                       car->car_hai->hai_extent.length,
                       car->car_hai->hai_gid,
-                      atomic_read(&car->car_refcount),
+                      kref_read(&car->car_refcount),
                       car->car_canceled);
        }
        up_read(&cdt->cdt_request_lock);
@@ -239,7 +239,7 @@ struct cdt_agent_req *mdt_cdt_alloc_request(__u32 archive_id, __u64 flags,
        if (car == NULL)
                RETURN(ERR_PTR(-ENOMEM));
 
-       atomic_set(&car->car_refcount, 1);
+       kref_init(&car->car_refcount);
        car->car_archive_id = archive_id;
        car->car_flags = flags;
        car->car_canceled = 0;
@@ -275,7 +275,15 @@ void mdt_cdt_free_request(struct cdt_agent_req *car)
  */
 void mdt_cdt_get_request(struct cdt_agent_req *car)
 {
-       atomic_inc(&car->car_refcount);
+       kref_get(&car->car_refcount);
+}
+
+void mdt_cdt_put_request_free(struct kref *kref)
+{
+       struct cdt_agent_req *car;
+
+       car = container_of(kref, struct cdt_agent_req, car_refcount);
+       mdt_cdt_free_request(car);
 }
 
 /**
@@ -285,9 +293,7 @@ void mdt_cdt_get_request(struct cdt_agent_req *car)
  */
 void mdt_cdt_put_request(struct cdt_agent_req *car)
 {
-       LASSERT(atomic_read(&car->car_refcount) > 0);
-       if (atomic_dec_and_test(&car->car_refcount))
-               mdt_cdt_free_request(car);
+       kref_put(&car->car_refcount, mdt_cdt_put_request_free);
 }
 
 /**
index 2f65e74..55e6062 100644 (file)
@@ -622,7 +622,7 @@ struct cdt_req_progress {
 struct cdt_agent_req {
        struct hlist_node        car_cookie_hash;  /**< find req by cookie */
        struct list_head         car_request_list; /**< to chain all the req. */
-       atomic_t                 car_refcount;     /**< reference counter */
+       struct kref              car_refcount;     /**< reference counter */
        __u64                    car_flags;        /**< request original flags */
        struct obd_uuid          car_uuid;         /**< agent doing the req. */
        __u32                    car_archive_id;   /**< archive id */