Whamcloud - gitweb
LU-11986 lnet: properly cleanup lnet debugfs files 69/34669/5
authorJames Simmons <uja.ornl@yahoo.com>
Mon, 15 Apr 2019 23:16:27 +0000 (19:16 -0400)
committerOleg Drokin <green@whamcloud.com>
Mon, 22 Apr 2019 21:56:28 +0000 (21:56 +0000)
The function lnet_router_debugfs_remove() is suppose to cleanup
the lnet specific debugfs files but that is not happening at all.
Change lnet_remove_debugfs() from doing the final debugfs lnet
and libcfs cleanup to doing specific debugfs file removal. We
can make libcfs module unloading to directly finish the entire
libcfs and debugfs tree removal instead. With this change we can
make lnet_router_debugfs_fini() call lnet_remove_debugfs().

Change-Id: I9e314e7efde806073b621166ff2e1b344e550875
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/34669
Reviewed-by: Sonia Sharma <sharmaso@whamcloud.com>
Reviewed-by: Amir Shehata <ashehata@whamcloud.com>
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/libcfs.h
libcfs/libcfs/module.c
lnet/lnet/api-ni.c
lnet/lnet/router_proc.c

index 99dc942..e3bf27d 100644 (file)
@@ -121,8 +121,8 @@ struct lnet_debugfs_symlink_def {
        const char *target;
 };
 
-void lnet_insert_debugfs(struct ctl_table *table,
-                        const struct lnet_debugfs_symlink_def *symlinks);
+void lnet_insert_debugfs(struct ctl_table *table);
+void lnet_remove_debugfs(struct ctl_table *table);
 
 /* helper for sysctl handlers */
 int lprocfs_call_handler(void *data, int write, loff_t *ppos,
index 3a696e9..de792a9 100644 (file)
@@ -548,8 +548,7 @@ static const struct file_operations *lnet_debugfs_fops_select(umode_t mode)
        return &lnet_debugfs_file_operations_rw;
 }
 
-void lnet_insert_debugfs(struct ctl_table *table,
-                        const struct lnet_debugfs_symlink_def *symlinks)
+void lnet_insert_debugfs(struct ctl_table *table)
 {
        if (!lnet_debugfs_root)
                lnet_debugfs_root = debugfs_create_dir("lnet", NULL);
@@ -565,19 +564,29 @@ void lnet_insert_debugfs(struct ctl_table *table,
                debugfs_create_file(table->procname, table->mode,
                                    lnet_debugfs_root, table,
                                    lnet_debugfs_fops_select(table->mode));
+}
+EXPORT_SYMBOL_GPL(lnet_insert_debugfs);
 
+static void lnet_insert_debugfs_links(
+               const struct lnet_debugfs_symlink_def *symlinks)
+{
        for (; symlinks && symlinks->name; symlinks++)
                debugfs_create_symlink(symlinks->name, lnet_debugfs_root,
                                       symlinks->target);
 }
-EXPORT_SYMBOL_GPL(lnet_insert_debugfs);
 
-static void lnet_remove_debugfs(void)
+void lnet_remove_debugfs(struct ctl_table *table)
 {
-       debugfs_remove_recursive(lnet_debugfs_root);
+       for (; table && table->procname; table++) {
+               struct qstr dname = QSTR_INIT(table->procname,
+                                             strlen(table->procname));
+               struct dentry *dentry;
 
-       lnet_debugfs_root = NULL;
+               dentry = d_hash_and_lookup(lnet_debugfs_root, &dname);
+               debugfs_remove(dentry);
+       }
 }
+EXPORT_SYMBOL_GPL(lnet_remove_debugfs);
 
 static int __init libcfs_init(void)
 {
@@ -619,7 +628,9 @@ static int __init libcfs_init(void)
                goto cleanup_wi;
        }
 
-       lnet_insert_debugfs(lnet_table, lnet_debugfs_symlinks);
+       lnet_insert_debugfs(lnet_table);
+       if (!IS_ERR_OR_NULL(lnet_debugfs_root))
+               lnet_insert_debugfs_links(lnet_debugfs_symlinks);
 
        CDEBUG (D_OTHER, "portals setup OK\n");
        return 0;
@@ -638,7 +649,9 @@ static void __exit libcfs_exit(void)
 {
        int rc;
 
-       lnet_remove_debugfs();
+       /* Remove everthing */
+       debugfs_remove_recursive(lnet_debugfs_root);
+       lnet_debugfs_root = NULL;
 
        CDEBUG(D_MALLOC, "before Portals cleanup: kmem %d\n",
               atomic_read(&libcfs_kmemory));
index 186be3d..c08e929 100644 (file)
@@ -2657,7 +2657,7 @@ LNetNIFini()
 
                lnet_fault_fini();
 
-               lnet_router_debugfs_init();
+               lnet_router_debugfs_fini();
                lnet_peer_discovery_stop();
                lnet_push_target_fini();
                lnet_monitor_thr_stop();
index a839507..bbcc0fd 100644 (file)
@@ -957,5 +957,10 @@ static struct ctl_table lnet_table[] = {
 
 void lnet_router_debugfs_init(void)
 {
-       lnet_insert_debugfs(lnet_table, NULL);
+       lnet_insert_debugfs(lnet_table);
+}
+
+void lnet_router_debugfs_fini(void)
+{
+       lnet_remove_debugfs(lnet_table);
 }