From 9a339420d903a10fdb310adc691426321637e91e Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Thu, 22 Aug 2024 04:54:46 -0400 Subject: [PATCH] LU-16796 llite: Change struct pcc_dataset to use kref This patch changes struct pcc_dataset to use kref instead of atomic_t Test-Parameters: trivial testlist=sanity-pcc Signed-off-by: Arshad Hussain Change-Id: Id9f7521a999be5917ce03a0ec4572091b2043c3f Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56121 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Qian Yingjin Reviewed-by: James Simmons Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- lustre/llite/pcc.c | 22 ++++++++++++++-------- lustre/llite/pcc.h | 8 +++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 489adf3..7ad8416 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -948,7 +948,7 @@ pcc_dataset_match_get(struct pcc_super *super, enum lu_pcc_type type, list_for_each_entry(dataset, &super->pccs_datasets, pccd_linkage) { if (pcc_dataset_attach_allowed(dataset, type) && pcc_cond_match(&dataset->pccd_rule, matcher)) { - atomic_inc(&dataset->pccd_refcount); + kref_get(&dataset->pccd_refcount); selected = dataset; break; } @@ -1036,7 +1036,7 @@ pcc_dataset_add(struct pcc_super *super, struct pcc_cmd *cmd) dataset->pccd_roid = cmd->u.pccc_add.pccc_roid; dataset->pccd_flags = cmd->u.pccc_add.pccc_flags; dataset->pccd_hsmtool_type = cmd->u.pccc_add.pccc_hsmtool_type; - atomic_set(&dataset->pccd_refcount, 1); + kref_init(&dataset->pccd_refcount); rc = pcc_dataset_rule_init(&dataset->pccd_rule, cmd); if (rc) { @@ -1088,7 +1088,7 @@ pcc_dataset_get(struct pcc_super *super, enum lu_pcc_type type, __u32 id) (!(dataset->pccd_roid == id || id == 0) || !(dataset->pccd_flags & PCC_DATASET_PCCRO))) continue; - atomic_inc(&dataset->pccd_refcount); + kref_get(&dataset->pccd_refcount); selected = dataset; break; } @@ -1099,14 +1099,20 @@ pcc_dataset_get(struct pcc_super *super, enum lu_pcc_type type, __u32 id) return selected; } +void pcc_dataset_free(struct kref *kref) +{ + struct pcc_dataset *dataset = container_of(kref, struct pcc_dataset, + pccd_refcount); + + pcc_dataset_rule_fini(&dataset->pccd_rule); + path_put(&dataset->pccd_path); + OBD_FREE_PTR(dataset); +} + void pcc_dataset_put(struct pcc_dataset *dataset) { - if (atomic_dec_and_test(&dataset->pccd_refcount)) { - pcc_dataset_rule_fini(&dataset->pccd_rule); - path_put(&dataset->pccd_path); - OBD_FREE_PTR(dataset); - } + kref_put(&dataset->pccd_refcount, pcc_dataset_free); } static int diff --git a/lustre/llite/pcc.h b/lustre/llite/pcc.h index fb3045e..609b383 100644 --- a/lustre/llite/pcc.h +++ b/lustre/llite/pcc.h @@ -32,10 +32,11 @@ #ifndef LLITE_PCC_H #define LLITE_PCC_H -#include #include -#include #include +#include +#include +#include #include extern struct kmem_cache *pcc_inode_slab; @@ -149,7 +150,7 @@ struct pcc_dataset { char pccd_pathname[PATH_MAX]; /* full path */ struct path pccd_path; /* Root path */ struct list_head pccd_linkage; /* Linked to pccs_datasets */ - atomic_t pccd_refcount; /* Reference count */ + struct kref pccd_refcount; /* Reference count */ enum hsmtool_type pccd_hsmtool_type; /* HSM copytool type */ }; @@ -318,6 +319,7 @@ void pcc_create_attach_cleanup(struct super_block *sb, struct pcc_dataset *pcc_dataset_match_get(struct pcc_super *super, enum lu_pcc_type type, struct pcc_matcher *matcher); +void pcc_dataset_free(struct kref *kref); void pcc_dataset_put(struct pcc_dataset *dataset); void pcc_inode_free(struct inode *inode); void pcc_layout_invalidate(struct inode *inode); -- 1.8.3.1