Whamcloud - gitweb
LU-8066 lustre: drop ldebugfs_remove() 82/36682/7
authorMr NeilBrown <neilb@suse.de>
Tue, 5 Nov 2019 23:55:52 +0000 (10:55 +1100)
committerOleg Drokin <green@whamcloud.com>
Mon, 16 Dec 2019 05:58:59 +0000 (05:58 +0000)
ldebugfs_remove() is a wrapper around debugfs_remove_recursive()
which adds two features:
1/ the pointer is tested with IS_ERR_OR_NULL before making the call
2/ the pointer is cleared after the call.

The first is not needed since Linux 3.6
Commit a59d6293e537 ("debugfs: change parameter check in
                      debugfs_remove() functions")

and the "OR_NULL" part has never been needed.  In many cases a pointer
to a debugfs dentry is already never an error, or is NULLed as soon as
the error is noticed.  Only two place is an error stored (fid_request
and fld_request), so we change those to never store the error.

The second is only needed for a few global variables.  In most other
cases the structure holding the pointer will be freed in the near
future, so clearing the pointer is pointless.  obd_debugfs_entry is
one case where I wasn't certain the NULLing the pointer was not
needed.

Then the debugfs_remove_recursive() call is made just before module
exit, and the variable is local to the module, there is no point
clearing the variable.

As the extra functionality is barely needed, let's just use the
standard interface, with occasional checks and clears as needed.

Linux-commit b145d7865a7c ("staging: lustre: get rid of
                            ldebugfs_remove()")

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I68db147433273b70d6fe0957df10ed14e8e924bb
Reviewed-on: https://review.whamcloud.com/36682
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
19 files changed:
contrib/scripts/spelling.txt
lustre/fid/fid_handler.c
lustre/fid/fid_request.c
lustre/fld/fld_handler.c
lustre/fld/fld_request.c
lustre/include/lprocfs_status.h
lustre/ldlm/ldlm_pool.c
lustre/ldlm/ldlm_resource.c
lustre/llite/lproc_llite.c
lustre/lod/lproc_lod.c
lustre/obdclass/lprocfs_status.c
lustre/osp/lproc_osp.c
lustre/ptlrpc/gss/lproc_gss.c
lustre/ptlrpc/lproc_ptlrpc.c
lustre/ptlrpc/nrs_crr.c
lustre/ptlrpc/nrs_delay.c
lustre/ptlrpc/nrs_orr.c
lustre/ptlrpc/nrs_tbf.c
lustre/ptlrpc/sec_lproc.c

index 193a73b..6883eb6 100644 (file)
@@ -106,6 +106,7 @@ from_timer||cfs_from_timer
 f_dentry||f_path.dentry
 [^_]get_seconds||ktime_get_real_seconds
 GETSTRIPE||LFS getstripe
+ldebugfs_remove||debugfs_remove_recursive
 ldlm_appetite_t||enum ldlm_appetite
 ldlm_cancel_flags_t||enum ldlm_cancel_flags
 ldlm_error_t||enum ldlm_error
index 0b89847..12b708d 100644 (file)
@@ -458,8 +458,7 @@ LU_CONTEXT_KEY_DEFINE(seq, LCT_MD_THREAD | LCT_DT_THREAD);
 
 static void seq_server_debugfs_fini(struct lu_server_seq *seq)
 {
-       if (!IS_ERR_OR_NULL(seq->lss_debugfs_entry))
-               ldebugfs_remove(&seq->lss_debugfs_entry);
+       debugfs_remove_recursive(seq->lss_debugfs_entry);
 }
 
 static int seq_server_debugfs_init(struct lu_server_seq *seq)
index 9629f4e..450d4aa 100644 (file)
@@ -437,8 +437,7 @@ EXPORT_SYMBOL(seq_client_flush);
 
 static void seq_client_debugfs_fini(struct lu_client_seq *seq)
 {
-       if (!IS_ERR_OR_NULL(seq->lcs_debugfs_entry))
-               ldebugfs_remove(&seq->lcs_debugfs_entry);
+       debugfs_remove_recursive(seq->lcs_debugfs_entry);
 }
 
 static int seq_client_debugfs_init(struct lu_client_seq *seq)
@@ -580,16 +579,19 @@ EXPORT_SYMBOL(client_fid_fini);
 
 static int __init fid_init(void)
 {
+       struct dentry *de;
 #ifdef HAVE_SERVER_SUPPORT
        int rc = fid_server_mod_init();
 
        if (rc)
                return rc;
 #endif
-       seq_debugfs_dir = ldebugfs_register(LUSTRE_SEQ_NAME,
-                                           debugfs_lustre_root,
-                                           NULL, NULL);
-       return PTR_ERR_OR_ZERO(seq_debugfs_dir);
+       de = ldebugfs_register(LUSTRE_SEQ_NAME,
+                              debugfs_lustre_root,
+                              NULL, NULL);
+       if (!IS_ERR(de))
+               seq_debugfs_dir = de;
+       return PTR_ERR_OR_ZERO(de);
 }
 
 static void __exit fid_exit(void)
@@ -597,8 +599,7 @@ static void __exit fid_exit(void)
 # ifdef HAVE_SERVER_SUPPORT
        fid_server_mod_exit();
 # endif
-       if (!IS_ERR_OR_NULL(seq_debugfs_dir))
-               ldebugfs_remove(&seq_debugfs_dir);
+       debugfs_remove_recursive(seq_debugfs_dir);
 }
 
 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
index 42f00da..12bdcc0 100644 (file)
@@ -402,8 +402,7 @@ EXPORT_SYMBOL(fid_is_local);
 
 static void fld_server_debugfs_fini(struct lu_server_fld *fld)
 {
-       if (!IS_ERR_OR_NULL(fld->lsf_debugfs_entry))
-               ldebugfs_remove(&fld->lsf_debugfs_entry);
+       debugfs_remove_recursive(fld->lsf_debugfs_entry);
 }
 
 static int fld_server_debugfs_init(struct lu_server_fld *fld)
@@ -424,7 +423,7 @@ static int fld_server_debugfs_init(struct lu_server_fld *fld)
        rc = ldebugfs_seq_create(fld->lsf_debugfs_entry, "fldb", 0444,
                                 &fld_debugfs_seq_fops, fld);
        if (rc)
-               ldebugfs_remove(&fld->lsf_debugfs_entry);
+               debugfs_remove_recursive(fld->lsf_debugfs_entry);
 
        RETURN(rc);
 }
index 3dd616e..1498c70 100644 (file)
@@ -247,8 +247,7 @@ static int fld_client_debugfs_init(struct lu_client_fld *fld)
 
 void fld_client_debugfs_fini(struct lu_client_fld *fld)
 {
-       if (!IS_ERR_OR_NULL(fld->lcf_debugfs_entry))
-               ldebugfs_remove(&fld->lcf_debugfs_entry);
+       debugfs_remove_recursive(fld->lcf_debugfs_entry);
 }
 EXPORT_SYMBOL(fld_client_debugfs_fini);
 
@@ -523,6 +522,7 @@ void fld_client_flush(struct lu_client_fld *fld)
 
 static int __init fld_init(void)
 {
+       struct dentry *de;
 #ifdef HAVE_SERVER_SUPPORT
        int rc;
 
@@ -531,10 +531,12 @@ static int __init fld_init(void)
                return rc;
 #endif /* HAVE_SERVER_SUPPORT */
 
-       fld_debugfs_dir = ldebugfs_register(LUSTRE_FLD_NAME,
-                                           debugfs_lustre_root,
-                                           NULL, NULL);
-       return PTR_ERR_OR_ZERO(fld_debugfs_dir);
+       de = ldebugfs_register(LUSTRE_FLD_NAME,
+                              debugfs_lustre_root,
+                              NULL, NULL);
+       if (!IS_ERR(de))
+               fld_debugfs_dir = de;
+       return PTR_ERR_OR_ZERO(de);
 }
 
 static void __exit fld_exit(void)
@@ -543,8 +545,7 @@ static void __exit fld_exit(void)
        fld_server_mod_exit();
 #endif /* HAVE_SERVER_SUPPORT */
 
-       if (!IS_ERR_OR_NULL(fld_debugfs_dir))
-               ldebugfs_remove(&fld_debugfs_dir);
+       debugfs_remove_recursive(fld_debugfs_dir);
 }
 
 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
index fd916d3..1ff0926 100644 (file)
@@ -534,7 +534,6 @@ extern struct proc_dir_entry *
 lprocfs_register(const char *name, struct proc_dir_entry *parent,
                 struct lprocfs_vars *list, void *data);
 
-extern void ldebugfs_remove(struct dentry **entryp);
 extern void lprocfs_remove(struct proc_dir_entry **root);
 extern void lprocfs_remove_proc_entry(const char *name,
                                       struct proc_dir_entry *parent);
index 9bf4dcc..95ad36b 100644 (file)
@@ -872,10 +872,8 @@ static void ldlm_pool_debugfs_fini(struct ldlm_pool *pl)
                lprocfs_free_stats(&pl->pl_stats);
                pl->pl_stats = NULL;
        }
-       if (pl->pl_debugfs_entry != NULL) {
-               ldebugfs_remove(&pl->pl_debugfs_entry);
-               pl->pl_debugfs_entry = NULL;
-       }
+       debugfs_remove_recursive(pl->pl_debugfs_entry);
+       pl->pl_debugfs_entry = NULL;
 }
 
 int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns,
index 9275227..a65a75c 100644 (file)
@@ -230,6 +230,7 @@ int ldlm_debugfs_setup(void)
        if (IS_ERR_OR_NULL(ldlm_debugfs_dir)) {
                CERROR("LDebugFS failed in ldlm-init\n");
                rc = ldlm_debugfs_dir ? PTR_ERR(ldlm_debugfs_dir) : -ENOMEM;
+               ldlm_debugfs_dir = NULL;
                GOTO(err, rc);
        }
 
@@ -240,7 +241,7 @@ int ldlm_debugfs_setup(void)
                CERROR("LProcFS failed in ldlm-init\n");
                rc = ldlm_ns_debugfs_dir ? PTR_ERR(ldlm_ns_debugfs_dir)
                                         : -ENOMEM;
-               GOTO(err_type, rc);
+               GOTO(err, rc);
        }
 
        ldlm_svc_debugfs_dir = ldebugfs_register("services",
@@ -250,24 +251,19 @@ int ldlm_debugfs_setup(void)
                CERROR("LProcFS failed in ldlm-init\n");
                rc = ldlm_svc_debugfs_dir ? PTR_ERR(ldlm_svc_debugfs_dir)
                                          : -ENOMEM;
-               GOTO(err_ns, rc);
+               GOTO(err, rc);
        }
 
        rc = ldebugfs_add_vars(ldlm_debugfs_dir, ldlm_debugfs_list, NULL);
        if (rc != 0) {
                CERROR("LProcFS failed in ldlm-init\n");
-               GOTO(err_svc, rc);
+               GOTO(err, rc);
        }
 
        RETURN(0);
 
-err_svc:
-       ldebugfs_remove(&ldlm_svc_debugfs_dir);
-err_ns:
-       ldebugfs_remove(&ldlm_ns_debugfs_dir);
-err_type:
-       ldebugfs_remove(&ldlm_debugfs_dir);
 err:
+       debugfs_remove_recursive(ldlm_debugfs_dir);
        ldlm_svc_debugfs_dir = NULL;
        ldlm_ns_debugfs_dir = NULL;
        ldlm_debugfs_dir = NULL;
@@ -276,14 +272,7 @@ err:
 
 void ldlm_debugfs_cleanup(void)
 {
-       if (!IS_ERR_OR_NULL(ldlm_svc_debugfs_dir))
-               ldebugfs_remove(&ldlm_svc_debugfs_dir);
-
-       if (!IS_ERR_OR_NULL(ldlm_ns_debugfs_dir))
-               ldebugfs_remove(&ldlm_ns_debugfs_dir);
-
-       if (!IS_ERR_OR_NULL(ldlm_debugfs_dir))
-               ldebugfs_remove(&ldlm_debugfs_dir);
+       debugfs_remove_recursive(ldlm_debugfs_dir);
 
        ldlm_svc_debugfs_dir = NULL;
        ldlm_ns_debugfs_dir = NULL;
@@ -705,7 +694,7 @@ static void ldlm_namespace_debugfs_unregister(struct ldlm_namespace *ns)
                CERROR("dlm namespace %s has no procfs dir?\n",
                       ldlm_ns_name(ns));
        else
-               ldebugfs_remove(&ns->ns_debugfs_entry);
+               debugfs_remove_recursive(ns->ns_debugfs_entry);
 
        if (ns->ns_stats != NULL)
                lprocfs_free_stats(&ns->ns_stats);
index 081316e..44502de 100644 (file)
@@ -1730,7 +1730,7 @@ out_ra_stats:
 out_stats:
        lprocfs_free_stats(&sbi->ll_stats);
 out_debugfs:
-       ldebugfs_remove(&sbi->ll_debugfs_entry);
+       debugfs_remove_recursive(sbi->ll_debugfs_entry);
 
        RETURN(err);
 }
@@ -1740,8 +1740,7 @@ void ll_debugfs_unregister_super(struct super_block *sb)
        struct lustre_sb_info *lsi = s2lsi(sb);
        struct ll_sb_info *sbi = ll_s2sbi(sb);
 
-       if (!IS_ERR_OR_NULL(sbi->ll_debugfs_entry))
-               ldebugfs_remove(&sbi->ll_debugfs_entry);
+       debugfs_remove_recursive(sbi->ll_debugfs_entry);
 
        if (sbi->ll_dt_obd)
                sysfs_remove_link(&sbi->ll_kset.kobj,
index d2fccda..f89b0dc 100644 (file)
@@ -1052,8 +1052,7 @@ void lod_procfs_fini(struct lod_device *lod)
                kobject_put(lov);
        }
 
-       if (!IS_ERR_OR_NULL(lod->lod_debugfs))
-               ldebugfs_remove(&lod->lod_debugfs);
+       debugfs_remove_recursive(lod->lod_debugfs);
 
        if (obd->obd_proc_entry) {
                lprocfs_remove(&obd->obd_proc_entry);
index d9154dc..1bd4b72 100644 (file)
@@ -207,13 +207,6 @@ lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
 }
 EXPORT_SYMBOL(lprocfs_add_vars);
 
-void ldebugfs_remove(struct dentry **entryp)
-{
-       debugfs_remove_recursive(*entryp);
-       *entryp = NULL;
-}
-EXPORT_SYMBOL_GPL(ldebugfs_remove);
-
 #ifndef HAVE_REMOVE_PROC_SUBTREE
 /* for b=10866, global variable */
 DECLARE_RWSEM(_lprocfs_lock);
@@ -1242,7 +1235,9 @@ int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
                CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
                obd->obd_proc_entry = NULL;
 
-               ldebugfs_remove(&obd->obd_debugfs_entry);
+               debugfs_remove_recursive(obd->obd_debugfs_entry);
+               obd->obd_debugfs_entry = NULL;
+
                sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
                obd->obd_attrs = NULL;
                kset_unregister(&obd->obd_kset);
@@ -1269,8 +1264,8 @@ int lprocfs_obd_cleanup(struct obd_device *obd)
                obd->obd_proc_entry = NULL;
        }
 
-       if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
-               ldebugfs_remove(&obd->obd_debugfs_entry);
+       debugfs_remove_recursive(obd->obd_debugfs_entry);
+       obd->obd_debugfs_entry = NULL;
 
        /* obd device never allocated a kset */
        if (!obd->obd_kset.kobj.state_initialized)
index 75b7f07..01f122b 100644 (file)
@@ -1019,13 +1019,13 @@ void osp_tunables_fini(struct osp_device *osp)
                kobject_put(osc);
        }
 
-       if (!IS_ERR_OR_NULL(osp->opd_debugfs))
-               ldebugfs_remove(&osp->opd_debugfs);
+       debugfs_remove_recursive(osp->opd_debugfs);
+       osp->opd_debugfs = NULL;
 
        ptlrpc_lprocfs_unregister_obd(obd);
 
-       if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
-               ldebugfs_remove(&obd->obd_debugfs_entry);
+       debugfs_remove_recursive(obd->obd_debugfs_entry);
+       obd->obd_debugfs_entry = NULL;
 
        dt_tunables_fini(&osp->opd_dt_dev);
 }
index 8bfdc49..b422523 100644 (file)
@@ -211,11 +211,11 @@ static struct lprocfs_vars gss_lk_debugfs_vars[] = {
 
 void gss_exit_tunables(void)
 {
-       if (!IS_ERR_OR_NULL(gss_debugfs_dir_lk))
-               ldebugfs_remove(&gss_debugfs_dir_lk);
+       debugfs_remove_recursive(gss_debugfs_dir_lk);
+       gss_debugfs_dir_lk = NULL;
 
-       if (!IS_ERR_OR_NULL(gss_debugfs_dir))
-               ldebugfs_remove(&gss_debugfs_dir);
+       debugfs_remove_recursive(gss_debugfs_dir);
+       gss_debugfs_dir = NULL;
 
        if (!IS_ERR_OR_NULL(gss_lprocfs_dir))
                lprocfs_remove(&gss_lprocfs_dir);
index f2d747a..08039c2 100644 (file)
@@ -258,15 +258,15 @@ ptlrpc_ldebugfs_register(struct dentry *root, char *dir, char *name,
         }
 
        rc = ldebugfs_register_stats(svc_debugfs_entry, name, svc_stats);
-        if (rc < 0) {
-                if (dir)
-                       ldebugfs_remove(&svc_debugfs_entry);
-                lprocfs_free_stats(&svc_stats);
-        } else {
-                if (dir)
+       if (rc < 0) {
+               if (dir)
+                       debugfs_remove_recursive(svc_debugfs_entry);
+               lprocfs_free_stats(&svc_stats);
+       } else {
+               if (dir)
                        *debugfs_root_ret = svc_debugfs_entry;
-                *stats_ret = svc_stats;
-        }
+               *stats_ret = svc_stats;
+       }
 }
 
 static int
@@ -1227,7 +1227,7 @@ void ptlrpc_ldebugfs_register_service(struct dentry *entry,
 
        ptlrpc_ldebugfs_register(entry, svc->srv_name, "stats",
                                 &svc->srv_debugfs_entry, &svc->srv_stats);
-       if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
+       if (!svc->srv_debugfs_entry)
                return;
 
        ldebugfs_add_vars(svc->srv_debugfs_entry, lproc_vars, NULL);
@@ -1290,11 +1290,10 @@ EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
 
 void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
 {
-       if (!IS_ERR_OR_NULL(svc->srv_debugfs_entry))
-               ldebugfs_remove(&svc->srv_debugfs_entry);
+       debugfs_remove_recursive(svc->srv_debugfs_entry);
 
-        if (svc->srv_stats)
-                lprocfs_free_stats(&svc->srv_stats);
+       if (svc->srv_stats)
+               lprocfs_free_stats(&svc->srv_stats);
 }
 
 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
@@ -1304,11 +1303,10 @@ void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
         */
        lprocfs_obd_cleanup(obd);
 
-       if (!IS_ERR_OR_NULL(obd->obd_svc_debugfs_entry))
-               ldebugfs_remove(&obd->obd_svc_debugfs_entry);
+       debugfs_remove_recursive(obd->obd_svc_debugfs_entry);
 
-        if (obd->obd_svc_stats)
-                lprocfs_free_stats(&obd->obd_svc_stats);
+       if (obd->obd_svc_stats)
+               lprocfs_free_stats(&obd->obd_svc_stats);
 }
 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
 
index f62728f..6d0a0be 100644 (file)
@@ -792,7 +792,7 @@ static int nrs_crrn_lprocfs_init(struct ptlrpc_service *svc)
                { NULL }
        };
 
-       if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
+       if (!svc->srv_debugfs_entry)
                return 0;
 
        return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_crrn_lprocfs_vars, NULL);
index 301b08c..9c1b238 100644 (file)
@@ -792,7 +792,7 @@ static int nrs_delay_lprocfs_init(struct ptlrpc_service *svc)
                { NULL }
        };
 
-       if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
+       if (!svc->srv_debugfs_entry)
                return 0;
 
        return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_delay_lprocfs_vars,
index 25dea5c..38e2d05 100644 (file)
@@ -1876,7 +1876,7 @@ static int nrs_orr_lprocfs_init(struct ptlrpc_service *svc)
                { NULL }
        };
 
-       if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
+       if (!svc->srv_debugfs_entry)
                return 0;
 
        lprocfs_orr_data.svc = svc;
@@ -1928,7 +1928,7 @@ static int nrs_trr_lprocfs_init(struct ptlrpc_service *svc)
                { NULL }
        };
 
-       if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
+       if (!svc->srv_debugfs_entry)
                return 0;
 
        lprocfs_trr_data.svc = svc;
index 371c784..d5fab11 100644 (file)
@@ -3674,7 +3674,7 @@ static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
                { NULL }
        };
 
-       if (IS_ERR_OR_NULL(svc->srv_debugfs_entry))
+       if (!svc->srv_debugfs_entry)
                return 0;
 
        return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_tbf_lprocfs_vars,
index c320081..e3d99ac 100644 (file)
@@ -289,8 +289,8 @@ int sptlrpc_lproc_init(void)
 
 void sptlrpc_lproc_fini(void)
 {
-       if (!IS_ERR_OR_NULL(sptlrpc_debugfs_dir))
-               ldebugfs_remove(&sptlrpc_debugfs_dir);
+       debugfs_remove_recursive(sptlrpc_debugfs_dir);
+       sptlrpc_debugfs_dir = NULL;
 
        if (!IS_ERR_OR_NULL(sptlrpc_lprocfs_dir))
                lprocfs_remove(&sptlrpc_lprocfs_dir);