Whamcloud - gitweb
LU-16796 llite: Change struct pcc_dataset to use kref 21/56121/4
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Thu, 22 Aug 2024 08:54:46 +0000 (04:54 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 30 Aug 2024 06:01:48 +0000 (06:01 +0000)
This patch changes struct pcc_dataset to use
kref instead of atomic_t

Test-Parameters: trivial testlist=sanity-pcc
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: Id9f7521a999be5917ce03a0ec4572091b2043c3f
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56121
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Qian Yingjin <qian@ddn.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/pcc.c
lustre/llite/pcc.h

index 489adf3..7ad8416 100644 (file)
@@ -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
index fb3045e..609b383 100644 (file)
 #ifndef LLITE_PCC_H
 #define LLITE_PCC_H
 
-#include <linux/types.h>
 #include <linux/fs.h>
-#include <linux/seq_file.h>
 #include <linux/mm.h>
+#include <linux/kref.h>
+#include <linux/types.h>
+#include <linux/seq_file.h>
 #include <uapi/linux/lustre/lustre_user.h>
 
 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);