Whamcloud - gitweb
LU-16796 lov: Change struct pool_desc to use kref 22/52122/5
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Sun, 27 Aug 2023 21:39:47 +0000 (03:09 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 20 Dec 2023 01:45:28 +0000 (01:45 +0000)
This patch changes struct pool_desc to use
kref(refcount_t) instead of atomic_t

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I3829de190ec148c2e087f6a0262bf3bb76c196af
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52122
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/lod/lod_internal.h
lustre/lod/lod_pool.c
lustre/lov/lov_internal.h
lustre/lov/lov_pool.c

index 486169f..1bb2afd 100644 (file)
@@ -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;
index 9553229..2c85740 100644 (file)
 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);
index 2350e45..e2546ec 100644 (file)
@@ -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;
index d8c76d5..31a4287 100644 (file)
@@ -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)