From ff22bc6aff258577993b08ca3c938870a4b0ea25 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Mon, 28 Aug 2023 03:09:47 +0530 Subject: [PATCH] LU-16796 lov: Change struct pool_desc to use kref This patch changes struct pool_desc to use kref(refcount_t) instead of atomic_t Signed-off-by: Arshad Hussain Change-Id: I3829de190ec148c2e087f6a0262bf3bb76c196af Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52122 Reviewed-by: Neil Brown Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/lod/lod_internal.h | 2 +- lustre/lod/lod_pool.c | 31 +++++++++++++++++++------------ lustre/lov/lov_internal.h | 2 +- lustre/lov/lov_pool.c | 33 ++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 486169f..1bb2afd9 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -58,7 +58,7 @@ enum lod_uses_hint { struct lod_pool_desc { char pool_name[LOV_MAXPOOLNAME + 1]; struct lu_tgt_pool pool_obds; /* pool members */ - atomic_t pool_refcount; + struct kref pool_refcount; struct lu_qos_rr pool_rr; struct rhash_head pool_hash; /* access by poolname */ struct list_head pool_list; diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index 9553229..2c85740 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -78,7 +78,20 @@ static void pool_getref(struct lod_pool_desc *pool) { CDEBUG(D_INFO, "pool %p\n", pool); - atomic_inc(&pool->pool_refcount); + kref_get(&pool->pool_refcount); +} + +static void lod_pool_putref_free(struct kref *kref) +{ + struct lod_pool_desc *pool = container_of(kref, struct lod_pool_desc, + pool_refcount); + + LASSERT(list_empty(&pool->pool_list)); + LASSERT(pool->pool_proc_entry == NULL); + lu_tgt_pool_free(&(pool->pool_rr.lqr_pool)); + lu_tgt_pool_free(&(pool->pool_obds)); + kfree_rcu(pool, pool_rcu); + EXIT; } /** @@ -91,19 +104,13 @@ static void pool_getref(struct lod_pool_desc *pool) * it is explicitly destroyed by the sysadmin. The pool structure is freed * after the last reference on the structure is released. * - * \param[in] pool pool descriptor to drop reference on and possibly free + * \param[in] pool lod pool descriptor to drop reference on and possibly + * free */ void lod_pool_putref(struct lod_pool_desc *pool) { CDEBUG(D_INFO, "pool %p\n", pool); - if (atomic_dec_and_test(&pool->pool_refcount)) { - LASSERT(list_empty(&pool->pool_list)); - LASSERT(pool->pool_proc_entry == NULL); - lu_tgt_pool_free(&(pool->pool_rr.lqr_pool)); - lu_tgt_pool_free(&(pool->pool_obds)); - kfree_rcu(pool, pool_rcu); - EXIT; - } + kref_put(&pool->pool_refcount, lod_pool_putref_free); } static u32 pool_hashfh(const void *data, u32 len, u32 seed) @@ -396,7 +403,7 @@ struct lod_pool_desc *lod_pool_find(struct lod_device *lod, char *poolname) pool = rhashtable_lookup(&lod->lod_pools_hash_body, poolname, pools_hash_params); - if (pool && !atomic_inc_not_zero(&pool->pool_refcount)) + if (pool && !kref_get_unless_zero(&pool->pool_refcount)) pool = NULL; rcu_read_unlock(); return pool; @@ -463,7 +470,7 @@ int lod_pool_new(struct obd_device *obd, char *poolname) new_pool->pool_spill_target[0] = '\0'; atomic_set(&new_pool->pool_spill_hit, 0); new_pool->pool_lobd = obd; - atomic_set(&new_pool->pool_refcount, 1); + kref_init(&new_pool->pool_refcount); rc = lu_tgt_pool_init(&new_pool->pool_obds, 0); if (rc) GOTO(out_free_pool, rc); diff --git a/lustre/lov/lov_internal.h b/lustre/lov/lov_internal.h index 2350e45..e2546ec 100644 --- a/lustre/lov/lov_internal.h +++ b/lustre/lov/lov_internal.h @@ -197,7 +197,7 @@ static inline bool lov_supported_comp_magic(unsigned int magic) struct lov_pool_desc { char pool_name[LOV_MAXPOOLNAME + 1]; struct lu_tgt_pool pool_obds; - atomic_t pool_refcount; + struct kref pool_refcount; struct rhash_head pool_hash; /* access by poolname */ struct list_head pool_list; /* serial access */ struct rcu_head pool_rcu; diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index d8c76d5..31a4287 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -105,7 +105,19 @@ static const struct rhashtable_params pools_hash_params = { static void lov_pool_getref(struct lov_pool_desc *pool) { CDEBUG(D_INFO, "pool %p\n", pool); - atomic_inc(&pool->pool_refcount); + kref_get(&pool->pool_refcount); +} + +static void lov_pool_putref_free(struct kref *kref) +{ + struct lov_pool_desc *pool = container_of(kref, struct lov_pool_desc, + pool_refcount); + + LASSERT(list_empty(&pool->pool_list)); + LASSERT(pool->pool_proc_entry == NULL); + lu_tgt_pool_free(&(pool->pool_obds)); + kfree_rcu(pool, pool_rcu); + EXIT; } /** @@ -118,18 +130,13 @@ static void lov_pool_getref(struct lov_pool_desc *pool) * it is explicitly destroyed by the sysadmin. The pool structure is freed * after the last reference on the structure is released. * - * \param[in] pool pool descriptor to drop reference on and possibly free + * \param[in] pool lov pool descriptor to drop reference on and possibly + * free */ void lov_pool_putref(struct lov_pool_desc *pool) { CDEBUG(D_INFO, "pool %p\n", pool); - if (atomic_dec_and_test(&pool->pool_refcount)) { - LASSERT(list_empty(&pool->pool_list)); - LASSERT(pool->pool_proc_entry == NULL); - lu_tgt_pool_free(&(pool->pool_obds)); - kfree_rcu(pool, pool_rcu); - EXIT; - } + kref_put(&pool->pool_refcount, lov_pool_putref_free); } #ifdef CONFIG_PROC_FS @@ -388,7 +395,7 @@ int lov_pool_new(struct obd_device *obd, char *poolname) /* ref count init to 1 because when created a pool is always used * up to deletion */ - atomic_set(&new_pool->pool_refcount, 1); + kref_init(&new_pool->pool_refcount); rc = lu_tgt_pool_init(&new_pool->pool_obds, 0); if (rc) GOTO(out_free_pool, rc); @@ -454,7 +461,7 @@ struct lov_pool_desc *lov_pool_find(struct obd_device *obd, char *poolname) pool = rhashtable_lookup(&lov->lov_pools_hash_body, poolname, pools_hash_params); - if (pool && !atomic_inc_not_zero(&pool->pool_refcount)) + if (pool && !kref_get_unless_zero(&pool->pool_refcount)) pool = NULL; rcu_read_unlock(); @@ -533,7 +540,7 @@ int lov_pool_add(struct obd_device *obd, char *poolname, char *ostname) rcu_read_lock(); pool = rhashtable_lookup(&lov->lov_pools_hash_body, poolname, pools_hash_params); - if (pool && !atomic_inc_not_zero(&pool->pool_refcount)) + if (pool && !kref_get_unless_zero(&pool->pool_refcount)) pool = NULL; rcu_read_unlock(); if (!pool) @@ -598,7 +605,7 @@ int lov_pool_remove(struct obd_device *obd, char *poolname, char *ostname) rcu_read_lock(); pool = rhashtable_lookup(&lov->lov_pools_hash_body, poolname, pools_hash_params); - if (pool && !atomic_inc_not_zero(&pool->pool_refcount)) + if (pool && !kref_get_unless_zero(&pool->pool_refcount)) pool = NULL; rcu_read_unlock(); if (!pool) -- 1.8.3.1