From 99fb9376388e04d4fe713766e03dbb26f20bdc52 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Thu, 10 Aug 2023 18:00:46 +0530 Subject: [PATCH] LU-16796 target: Change struct top_multiple_thandle to use kref This patch changes struct top_multiple_thandle to use kref(refcount_t) instead of atomic_t Signed-off-by: Arshad Hussain Change-Id: I5892e5ab14ea6570645e6395af6d8a0d2c325398 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51922 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/lustre_update.h | 9 ++++----- lustre/target/update_trans.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lustre/include/lustre_update.h b/lustre/include/lustre_update.h index 23b309c..4bb11d8 100644 --- a/lustre/include/lustre_update.h +++ b/lustre/include/lustre_update.h @@ -299,7 +299,7 @@ struct thandle_update_records { #define TOP_THANDLE_MAGIC 0x20140917 struct top_multiple_thandle { struct dt_device *tmt_master_sub_dt; - atomic_t tmt_refcount; + struct kref tmt_refcount; /* Other sub transactions will be listed here. */ struct list_head tmt_sub_thandle_list; spinlock_t tmt_sub_lock; @@ -481,17 +481,16 @@ int top_trans_start(const struct lu_env *env, struct dt_device *master_dev, struct thandle *th); int top_trans_stop(const struct lu_env *env, struct dt_device *master_dev, struct thandle *th); -void top_multiple_thandle_destroy(struct top_multiple_thandle *tmt); +void top_multiple_thandle_destroy(struct kref *kref); static inline void top_multiple_thandle_get(struct top_multiple_thandle *tmt) { - atomic_inc(&tmt->tmt_refcount); + kref_get(&tmt->tmt_refcount); } static inline void top_multiple_thandle_put(struct top_multiple_thandle *tmt) { - if (atomic_dec_and_test(&tmt->tmt_refcount)) - top_multiple_thandle_destroy(tmt); + kref_put(&tmt->tmt_refcount, top_multiple_thandle_destroy); } struct sub_thandle *lookup_sub_thandle(struct top_multiple_thandle *tmt, diff --git a/lustre/target/update_trans.c b/lustre/target/update_trans.c index 6591b88..336dba5 100644 --- a/lustre/target/update_trans.c +++ b/lustre/target/update_trans.c @@ -76,7 +76,7 @@ static void top_multiple_thandle_dump(struct top_multiple_thandle *tmt, tmt->tmt_master_sub_dt ? tmt->tmt_master_sub_dt->dd_lu_dev.ld_obd->obd_name : "NULL", - tmt, atomic_read(&tmt->tmt_refcount), tmt->tmt_committed, + tmt, kref_read(&tmt->tmt_refcount), tmt->tmt_committed, tmt->tmt_result, tmt->tmt_batchid); list_for_each_entry(st, &tmt->tmt_sub_thandle_list, st_sub_list) { @@ -397,7 +397,7 @@ static void top_trans_committed_cb(struct top_multiple_thandle *tmt) struct lu_target *lut; ENTRY; - LASSERT(atomic_read(&tmt->tmt_refcount) > 0); + LASSERT(kref_read(&tmt->tmt_refcount) > 0); top_multiple_thandle_dump(tmt, D_HA); tmt->tmt_committed = 1; @@ -1122,7 +1122,7 @@ int top_trans_create_tmt(const struct lu_env *env, tmt->tmt_magic = TOP_THANDLE_MAGIC; INIT_LIST_HEAD(&tmt->tmt_sub_thandle_list); INIT_LIST_HEAD(&tmt->tmt_commit_list); - atomic_set(&tmt->tmt_refcount, 1); + kref_init(&tmt->tmt_refcount); spin_lock_init(&tmt->tmt_sub_lock); init_waitqueue_head(&tmt->tmt_stop_waitq); @@ -1238,13 +1238,16 @@ EXPORT_SYMBOL(thandle_get_sub_by_dt); * * Destroy multiple thandle and all its sub thandle. * - * \param[in] tmt top_multiple_thandle to be destroyed. + * \param[in] kref Pointer to struct kref */ -void top_multiple_thandle_destroy(struct top_multiple_thandle *tmt) +void top_multiple_thandle_destroy(struct kref *kref) { + struct top_multiple_thandle *tmt; struct sub_thandle *st; struct sub_thandle *tmp; + tmt = container_of(kref, struct top_multiple_thandle, tmt_refcount); + LASSERT(tmt->tmt_magic == TOP_THANDLE_MAGIC); list_for_each_entry_safe(st, tmp, &tmt->tmt_sub_thandle_list, st_sub_list) { -- 1.8.3.1