From: Arshad Hussain Date: Fri, 11 Aug 2023 07:32:49 +0000 (+0530) Subject: LU-16796 libcfs: Change struct cfs_hash to use kref X-Git-Tag: 2.15.58~58 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=e04d7fc2913c73097b7d20f05d4e896fa9e95f6b;p=fs%2Flustre-release.git LU-16796 libcfs: Change struct cfs_hash to use kref This patch changes struct cfs_hash to use kref(refcount_t) instead of atomic_t Signed-off-by: Arshad Hussain Change-Id: I58b5e8311a34b3b128c1440b93958389b0fcdd48 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51938 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs_hash.h b/libcfs/include/libcfs/libcfs_hash.h index 34ffdb1..b10ad5a 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/libcfs/include/libcfs/libcfs_hash.h @@ -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 diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index e4e061b..cd0bc77 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -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);