From 8cb7ccf54e2d34010bea9a71fe0eff708545ab78 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 15 Apr 2019 19:16:27 -0400 Subject: [PATCH] LU-11986 lnet: properly cleanup lnet debugfs files 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 Reviewed-on: https://review.whamcloud.com/34669 Reviewed-by: Sonia Sharma Reviewed-by: Amir Shehata Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/libcfs.h | 4 ++-- libcfs/libcfs/module.c | 29 +++++++++++++++++++++-------- lnet/lnet/api-ni.c | 2 +- lnet/lnet/router_proc.c | 7 ++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 99dc942..e3bf27d 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -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, diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 3a696e9..de792a9 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -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)); diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 186be3d..c08e929 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -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(); diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index a839507..bbcc0fd 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -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); } -- 1.8.3.1