Whamcloud - gitweb
LU-16796 target: Change struct top_multiple_thandle to use kref 22/51922/2
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Thu, 10 Aug 2023 12:30:46 +0000 (18:00 +0530)
committerOleg Drokin <green@whamcloud.com>
Thu, 24 Aug 2023 04:35:59 +0000 (04:35 +0000)
This patch changes struct top_multiple_thandle to use
kref(refcount_t) instead of atomic_t

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I5892e5ab14ea6570645e6395af6d8a0d2c325398
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51922
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_update.h
lustre/target/update_trans.c

index 23b309c..4bb11d8 100644 (file)
@@ -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,
index 6591b88..336dba5 100644 (file)
@@ -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) {