From e7aa630ad46340b48b202ea0c946329abd3a4fdc Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Sun, 15 Sep 2024 06:18:25 -0400 Subject: [PATCH] LU-16796 lnet: Change struct lmv_stripe_object to use kref This patch changes struct lmv_stripe_object to use kref instead of atomic_t Test-Parameters: trivial Signed-off-by: Arshad Hussain Change-Id: I7df086a23f59eb352c0f07b96e30bfdf9bc96cad Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56363 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/lustre_lmv.h | 5 +++-- lustre/llite/namei.c | 2 +- lustre/lmv/lmv_obd.c | 38 ++++++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lustre/include/lustre_lmv.h b/lustre/include/lustre_lmv.h index ed58af6..575df58 100644 --- a/lustre/include/lustre_lmv.h +++ b/lustre/include/lustre_lmv.h @@ -37,7 +37,7 @@ struct lmv_stripe_md { }; struct lmv_stripe_object { - atomic_t lso_refs; + struct kref lso_refs; union { struct lmv_stripe_md lso_lsm; struct lmv_foreign_md lso_lfm; @@ -147,7 +147,7 @@ lmv_stripe_object_dump(int mask, const struct lmv_stripe_object *lsmo) CDEBUG(mask, "dump LMV: magic=%#x refs=%u count=%u index=%u hash=%s:%#x max_inherit=%hhu max_inherit_rr=%hhu version=%u migrate_offset=%u migrate_hash=%s:%x pool=%.*s\n", - lsm->lsm_md_magic, atomic_read(&lsmo->lso_refs), + lsm->lsm_md_magic, kref_read(&lsmo->lso_refs), lsm->lsm_md_stripe_count, lsm->lsm_md_master_mdt_index, lmv_is_known_hash_type(lsm->lsm_md_hash_type) ? mdt_hash_name[lsm->lsm_md_hash_type & LMV_HASH_TYPE_MASK] : @@ -192,6 +192,7 @@ struct lmv_stripe_object *lmv_stripe_object_alloc(__u32 magic, const union lmv_mds_md *lmm, size_t lmm_size); +void lmv_stripe_object_free(struct kref *kref); void lmv_stripe_object_put(struct lmv_stripe_object **lsm_obj); struct lmv_stripe_object * diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 6f8a5e8..1639d78 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -1962,7 +1962,7 @@ again: lum->lum_max_inherit; md.def_lsm_obj->lso_lsm.lsm_md_max_inherit_rr = lum->lum_max_inherit_rr; - atomic_set(&md.def_lsm_obj->lso_refs, 1); + kref_init(&md.def_lsm_obj->lso_refs); err = ll_update_inode(dir, &md); md_put_lustre_md(sbi->ll_md_exp, &md); diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index c5581aa..68d6c6d 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -3758,7 +3758,7 @@ struct lmv_stripe_object *lmv_stripe_object_alloc(__u32 magic, } if (lsm_obj) { - atomic_set(&lsm_obj->lso_refs, 1); + kref_init(&lsm_obj->lso_refs); RETURN(lsm_obj); } @@ -3845,31 +3845,20 @@ lmv_stripe_object_get(struct lmv_stripe_object *lsm_obj) if (lsm_obj == NULL) return NULL; - atomic_inc(&lsm_obj->lso_refs); + kref_get(&lsm_obj->lso_refs); CDEBUG(D_INODE, "get %p %u\n", lsm_obj, - atomic_read(&lsm_obj->lso_refs)); + kref_read(&lsm_obj->lso_refs)); return lsm_obj; } EXPORT_SYMBOL(lmv_stripe_object_get); -void lmv_stripe_object_put(struct lmv_stripe_object **lsop) +void lmv_stripe_object_free(struct kref *kref) { struct lmv_stripe_object *lsm_obj; size_t size; int i; - LASSERT(lsop != NULL); - - lsm_obj = *lsop; - if (lsm_obj == NULL) - return; - - *lsop = NULL; - CDEBUG(D_INODE, "put %p %u\n", lsm_obj, - atomic_read(&lsm_obj->lso_refs) - 1); - - if (!atomic_dec_and_test(&lsm_obj->lso_refs)) - return; + lsm_obj = container_of(kref, struct lmv_stripe_object, lso_refs); if (lmv_dir_foreign(lsm_obj)) { size = lsm_obj->lso_lfm.lfm_length + @@ -3890,6 +3879,23 @@ void lmv_stripe_object_put(struct lmv_stripe_object **lsop) } OBD_FREE(lsm_obj, size + offsetof(typeof(*lsm_obj), lso_lsm)); } + + +void lmv_stripe_object_put(struct lmv_stripe_object **lsop) +{ + struct lmv_stripe_object *lsm_obj; + + LASSERT(lsop != NULL); + + lsm_obj = *lsop; + if (lsm_obj == NULL) + return; + + *lsop = NULL; + CDEBUG(D_INODE, "put %p %u\n", lsm_obj, kref_read(&lsm_obj->lso_refs)); + + kref_put(&lsm_obj->lso_refs, lmv_stripe_object_free); +} EXPORT_SYMBOL(lmv_stripe_object_put); static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid, -- 1.8.3.1