Whamcloud - gitweb
LU-16796 libcfs: Change struct cfs_hash to use kref 38/51938/3
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 11 Aug 2023 07:32:49 +0000 (13:02 +0530)
committerOleg Drokin <green@whamcloud.com>
Thu, 24 Aug 2023 04:36:17 +0000 (04:36 +0000)
This patch changes struct cfs_hash to use
kref(refcount_t) instead of atomic_t

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I58b5e8311a34b3b128c1440b93958389b0fcdd48
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51938
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>
libcfs/include/libcfs/libcfs_hash.h
libcfs/libcfs/hash.c

index 34ffdb1..b10ad5a 100644 (file)
@@ -233,7 +233,7 @@ struct cfs_hash {
        /** rehash workitem */
        struct work_struct              hs_rehash_work;
        /** refcount on this hash table */
-       atomic_t                        hs_refcount;
+       struct kref                     hs_refcount;
        /** rehash buckets-table */
        struct cfs_hash_bucket          **hs_rehash_buckets;
 #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1
index e4e061b..cd0bc77 100644 (file)
@@ -1071,7 +1071,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits,
        strlcpy(hs->hs_name, name, len);
        hs->hs_flags = flags;
 
-       atomic_set(&hs->hs_refcount, 1);
+       kref_init(&hs->hs_refcount);
        atomic_set(&hs->hs_count, 0);
 
        cfs_hash_lock_setup(hs);
@@ -1105,11 +1105,12 @@ EXPORT_SYMBOL(cfs_hash_create);
  * Cleanup libcfs hash @hs.
  */
 static void
-cfs_hash_destroy(struct cfs_hash *hs)
+cfs_hash_destroy(struct kref *kref)
 {
+       struct cfs_hash *hs = container_of(kref, struct cfs_hash, hs_refcount);
        struct hlist_node     *hnode;
        struct hlist_node     *pos;
-       struct cfs_hash_bd         bd;
+       struct cfs_hash_bd    bd;
        int                   i;
        ENTRY;
 
@@ -1168,7 +1169,7 @@ cfs_hash_destroy(struct cfs_hash *hs)
 
 struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs)
 {
-       if (atomic_inc_not_zero(&hs->hs_refcount))
+       if (kref_get_unless_zero(&hs->hs_refcount))
                return hs;
        return NULL;
 }
@@ -1176,8 +1177,7 @@ EXPORT_SYMBOL(cfs_hash_getref);
 
 void cfs_hash_putref(struct cfs_hash *hs)
 {
-       if (atomic_dec_and_test(&hs->hs_refcount))
-               cfs_hash_destroy(hs);
+       kref_put(&hs->hs_refcount, cfs_hash_destroy);
 }
 EXPORT_SYMBOL(cfs_hash_putref);