Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / lustre / obdclass / lu_ref.c
index a1ac74e..bcc59fb 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * GPL HEADER START
  *
@@ -27,7 +28,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/obdclass/lu_ref.c
  *
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
-#include <libcfs/libcfs.h>
 #include <obd.h>
 #include <obd_class.h>
 #include <obd_support.h>
 #include <lu_ref.h>
 
-#ifdef USE_LU_REF
-
+#ifdef CONFIG_LUSTRE_DEBUG_LU_REF
 /**
  * Asserts a condition for a given lu_ref. Must be called with
  * lu_ref::lf_guard held.
@@ -153,9 +151,9 @@ static struct lu_ref_link *lu_ref_add_context(struct lu_ref *ref,
        struct lu_ref_link *link;
 
        link = NULL;
-       if (lu_ref_link_kmem != NULL) {
+       if (lu_ref_link_kmem) {
                OBD_SLAB_ALLOC_PTR_GFP(link, lu_ref_link_kmem, flags);
-               if (link != NULL) {
+               if (link) {
                        link->ll_ref = ref;
                        link->ll_scope = scope;
                        link->ll_source = source;
@@ -166,7 +164,7 @@ static struct lu_ref_link *lu_ref_add_context(struct lu_ref *ref,
                }
        }
 
-       if (link == NULL) {
+       if (!link) {
                spin_lock(&ref->lf_guard);
                ref->lf_failed++;
                spin_unlock(&ref->lf_guard);
@@ -216,13 +214,13 @@ static inline int lu_ref_link_eq(const struct lu_ref_link *link,
 /**
  * Maximal chain length seen so far.
  */
-static unsigned lu_ref_chain_max_length = 127;
+static unsigned int lu_ref_chain_max_length = 127;
 
 /**
  * Searches for a lu_ref_link with given [scope, source] within given lu_ref.
  */
 static struct lu_ref_link *lu_ref_find(struct lu_ref *ref, const char *scope,
-                                       const void *source)
+                                      const void *source)
 {
        struct lu_ref_link *link;
        unsigned int iterations;
@@ -248,7 +246,7 @@ void lu_ref_del(struct lu_ref *ref, const char *scope, const void *source)
 
        spin_lock(&ref->lf_guard);
        link = lu_ref_find(ref, scope, source);
-       if (link != NULL) {
+       if (link) {
                list_del(&link->ll_linkage);
                ref->lf_refs--;
                spin_unlock(&ref->lf_guard);
@@ -266,7 +264,7 @@ void lu_ref_set_at(struct lu_ref *ref, struct lu_ref_link *link,
                   const void *source0, const void *source1)
 {
        spin_lock(&ref->lf_guard);
-       REFASSERT(ref, link != NULL && !IS_ERR(link));
+       REFASSERT(ref, !IS_ERR_OR_NULL(link));
        REFASSERT(ref, link->ll_ref == ref);
        REFASSERT(ref, lu_ref_link_eq(link, scope, source0));
        link->ll_source = source1;
@@ -278,7 +276,7 @@ void lu_ref_del_at(struct lu_ref *ref, struct lu_ref_link *link,
                   const char *scope, const void *source)
 {
        spin_lock(&ref->lf_guard);
-       REFASSERT(ref, link != NULL && !IS_ERR(link));
+       REFASSERT(ref, !IS_ERR_OR_NULL(link));
        REFASSERT(ref, link->ll_ref == ref);
        REFASSERT(ref, lu_ref_link_eq(link, scope, source));
        list_del(&link->ll_linkage);
@@ -287,8 +285,6 @@ void lu_ref_del_at(struct lu_ref *ref, struct lu_ref_link *link,
 }
 EXPORT_SYMBOL(lu_ref_del_at);
 
-#ifdef CONFIG_PROC_FS
-
 static void *lu_ref_seq_start(struct seq_file *seq, loff_t *pos)
 {
        struct lu_ref *ref = seq->private;
@@ -360,11 +356,11 @@ static int lu_ref_seq_show(struct seq_file *seq, void *p)
        return 0;
 }
 
-static struct seq_operations lu_ref_seq_ops = {
-       .start = lu_ref_seq_start,
-       .stop  = lu_ref_seq_stop,
-       .next  = lu_ref_seq_next,
-       .show  = lu_ref_seq_show
+static const struct seq_operations lu_ref_seq_ops = {
+       .start  = lu_ref_seq_start,
+       .stop   = lu_ref_seq_stop,
+       .next   = lu_ref_seq_next,
+       .show   = lu_ref_seq_show
 };
 
 static int lu_ref_seq_open(struct inode *inode, struct file *file)
@@ -413,8 +409,6 @@ static const struct file_operations lu_ref_dump_fops = {
        .release        = lu_ref_seq_release
 };
 
-#endif /* CONFIG_PROC_FS */
-
 int lu_ref_global_init(void)
 {
        int result;
@@ -423,25 +417,21 @@ int lu_ref_global_init(void)
               "lu_ref tracking is enabled. Performance isn't.\n");
 
        result = lu_kmem_init(lu_ref_caches);
+       if (result)
+               return result;
 
-#ifdef CONFIG_PROC_FS
-       if (result == 0) {
-               result = lprocfs_seq_create(proc_lustre_root, "lu_refs",
-                                           0444, &lu_ref_dump_fops, NULL);
-               if (result)
-                       lu_kmem_fini(lu_ref_caches);
-       }
-#endif /* CONFIG_PROC_FS */
+       debugfs_create_file("lu_refs", 0444, debugfs_lustre_root,
+                           NULL, &lu_ref_dump_fops);
 
        return result;
 }
 
 void lu_ref_global_fini(void)
 {
-#ifdef CONFIG_PROC_FS
-       lprocfs_remove_proc_entry("lu_refs", proc_lustre_root);
-#endif /* CONFIG_PROC_FS */
+       /* debugfs file gets cleaned up by debugfs_remove_recursive on
+        * debugfs_lustre_root
+        */
        lu_kmem_fini(lu_ref_caches);
 }
 
-#endif /* USE_LU_REF */
+#endif /* CONFIG_LUSTRE_DEBUG_LU_REF */