From 9e597a09510c2f7bbc98ab0ce2aca2fe21a9ab45 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 29 Aug 2023 12:30:35 +0530 Subject: [PATCH] LU-16796 mdt: Change struct cdt_agent_req to use kref This patch changes struct cdt_agent_req to use kref(refcount_t) instead of atomic_t Signed-off-by: Arshad Hussain Change-Id: I0a99002504ff453b8b748391f08bd1020c545321 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52148 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Etienne AUJAMES Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_hsm_cdt_requests.c | 18 ++++++++++++------ lustre/mdt/mdt_internal.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lustre/mdt/mdt_hsm_cdt_requests.c b/lustre/mdt/mdt_hsm_cdt_requests.c index 9452638..66b8191 100644 --- a/lustre/mdt/mdt_hsm_cdt_requests.c +++ b/lustre/mdt/mdt_hsm_cdt_requests.c @@ -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); } /** diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 2f65e74..55e6062 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -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 */ -- 1.8.3.1