lustre: libcfs: fix libcfs debugfs bugs
cover lustre: libcfs: fix libcfs debugfs bugs
The original port to sysfs / debugfs was done in haste without any testing so many bugs were introduced. This patch set resolves the bugs found in the libcfs code when it was reviewed.
James Simmons (10):
lustre: libcfs: rename lustre_*_debugfs to lnet_*_debugfs
lustre: libcfs: rename *_debugmb to *_debug_mb
lustre: libcfs: make lnet_debugfs_symlink_def fields const
lustre: libcfs: fix module loading and sysfs setting race
lustre: libcfs: fix wrong debugfs symlink name
lustre: libcfs: don't assume sysfs mount point
lustre: libcfs: properly initialize lnet_debugfs_symlink_def
lustre: libcfs: test if table is NULL for lnet_insert_debugfs
lustre: libcfs: return ssize_t for lnet_debugfs_*
lustre: libcfs: small cleanups for debugfs code
.../staging/lustre/include/linux/libcfs/libcfs.h | 2 +- drivers/staging/lustre/lnet/libcfs/debug.c | 28 ++++---- drivers/staging/lustre/lnet/libcfs/module.c | 78 +++++++++++----------- drivers/staging/lustre/lnet/lnet/router_proc.c | 2 +- 4 files changed, 57 insertions(+), 53 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/10 lustre: libcfs: rename lustre_*_debugfs to lnet_*_debugfs
Both lustre_insert_debugfs() and lustre_remove_debugfs() are only used by the LNet layer so replace lustre_* with lnet_* to make the code more consistent.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/include/linux/libcfs/libcfs.h | 2 +- drivers/staging/lustre/lnet/libcfs/module.c | 14 +++++++------- drivers/staging/lustre/lnet/lnet/router_proc.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs.h +1 -1
@@ -56,7 +56,7 @@ static inline int notifier_from_ioctl_errno(int err)extern struct workqueue_struct *cfs_rehash_wq; -void lustre_insert_debugfs (struct ctl_table *table); +void lnet_insert_debugfs (struct ctl_table *table);/* * Memory
drivers/staging/lustre/lnet/libcfs/module.c +7 -7
@@ -646,7 +646,7 @@ static const struct file_operations *lnet_debugfs_fops_select(umode_t mode)return &lnet_debugfs_file_operations_rw; } -void lustre_insert_debugfs (struct ctl_table *table) +void lnet_insert_debugfs (struct ctl_table *table) {if (!lnet_debugfs_root) lnet_debugfs_root =debugfs_create_dir ("lnet" ,NULL );
@@ -664,9 +664,9 @@ void lustre_insert_debugfs(struct ctl_table *table) lnet_debugfs_root, table, lnet_debugfs_fops_select(table->mode)); } -EXPORT_SYMBOL_GPL (lustre_insert_debugfs); +EXPORT_SYMBOL_GPL (lnet_insert_debugfs); -static void lustre_insert_debugfs_links ( +static void lnet_insert_debugfs_links (const struct lnet_debugfs_symlink_def *symlinks) {for (; symlinks && symlinks->name; symlinks++)
@@ -674,7 +674,7 @@ static void lustre_insert_debugfs_links( symlinks->target); } -static void lustre_remove_debugfs (void ) +static void lnet_remove_debugfs (void ) {debugfs_remove_recursive (lnet_debugfs_root);
@@ -718,9 +718,9 @@ int libcfs_setup(void) goto err; } -lustre_insert_debugfs (lnet_table); +lnet_insert_debugfs (lnet_table);if (!IS_ERR_OR_NULL (lnet_debugfs_root)) -lustre_insert_debugfs_links (lnet_debugfs_symlinks); +lnet_insert_debugfs_links (lnet_debugfs_symlinks);CDEBUG (D_OTHER ,"portals setup OK\n" ); out:
@@ -754,7 +754,7 @@ static void libcfs_exit(void) {int rc; -lustre_remove_debugfs (); +lnet_remove_debugfs ();if (cfs_rehash_wq)destroy_workqueue (cfs_rehash_wq);
drivers/staging/lustre/lnet/lnet/router_proc.c +1 -1
@@ -881,7 +881,7 @@ static int proc_lnet_portal_rotor(struct ctl_table *table, int write,void lnet_router_debugfs_init (void ) { -lustre_insert_debugfs (lnet_table); +lnet_insert_debugfs (lnet_table); }void lnet_router_debugfs_fini (void )
Signature · 1 line
1.8.3.1
PATCH 2/10 lustre: libcfs: rename *_debugmb to *_debug_mb
In reply to James SimmonsThe module parameter is called libcfs_debug_mb but the code refers to it as *_debugmb. Change the naming to match the module parameter.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/libcfs/debug.c +4 -4
@@ -82,18 +82,18 @@ static int libcfs_param_debug_mb_set(const char *val,/* While debug_mb setting look like unsigned int, in fact * it needs quite a bunch of extra processing, so we define special -* debugmb parameter type with corresponding methods to handle this case +* debug_mb parameter type with corresponding methods to handle this case */ -static const struct kernel_param_ops param_ops_debugmb = { +static const struct kernel_param_ops param_ops_debug_mb = { .set = libcfs_param_debug_mb_set, .get = param_get_uint, }; -#define param_check_debugmb (name, p) \ +#define param_check_debug_mb (name, p) \ __param_check(name, p, unsigned int)static unsigned int libcfs_debug_mb; -module_param (libcfs_debug_mb, debugmb,0644 ); +module_param (libcfs_debug_mb, debug_mb,0644 );MODULE_PARM_DESC (libcfs_debug_mb,"Total debug buffer size." );unsigned int libcfs_printk =D_CANTMASK ;
Signature · 1 line
1.8.3.1
PATCH 3/10 lustre: libcfs: make lnet_debugfs_symlink_def fields const
In reply to James SimmonsChange the fields in struct lnet_debubfs_symlink_def to const char *.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/lustre/lnet/libcfs/module.c +2 -2
@@ -60,8 +60,8 @@#include "tracefile.h" struct lnet_debugfs_symlink_def { -char *name; -char *target; +const char *name; +const char *target; };static struct dentry *lnet_debugfs_root;
Signature · 1 line
1.8.3.1
PATCH 4/10 lustre: libcfs: fix module loading and sysfs setting race
In reply to James SimmonsThe set method is called when a module parameter is parsed and this happens before libcfs __init function has been called. Also the sysfs files corresponding to libcfs module parameters are also constructed before the __init function. Lastly the set method can be called while the __init function does run. Add kernel_param_[un]lock() to void stomping over the module parameter setting.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/debug.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/libcfs/debug.c +8 -4
@@ -422,18 +422,22 @@ int libcfs_debug_init(unsigned long bufsize) } rc =cfs_tracefile_init (max); -if (!rc) { -libcfs_register_panic_notifier (); - libcfs_debug_mb =cfs_trace_get_debug_mb (); - } +if (rc) +return rc; +libcfs_register_panic_notifier (); +kernel_param_lock (THIS_MODULE ); + libcfs_debug_mb =cfs_trace_get_debug_mb (); +kernel_param_unlock (THIS_MODULE );return rc; }int libcfs_debug_cleanup (void ) {libcfs_unregister_panic_notifier (); +kernel_param_lock (THIS_MODULE );cfs_tracefile_exit (); +kernel_param_unlock (THIS_MODULE );return 0 ; }
Signature · 1 line
1.8.3.1
PATCH 5/10 lustre: libcfs: fix wrong debugfs symlink name
In reply to James SimmonsThe symlink libcfs_console_backoff is incorrect. Rename to the correct name console_backoff.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lnet/libcfs/module.c +1 -1
@@ -568,7 +568,7 @@ static int proc_cpt_distance(struct ctl_table *table, int write, "/sys/module/libcfs/parameters/libcfs_debug_file_path"}, {"panic_on_lbug" , "/sys/module/libcfs/parameters/libcfs_panic_on_lbug"}, - { "libcfs_console_backoff", + { "console_backoff", "/sys/module/libcfs/parameters/libcfs_console_backoff"}, { "debug_mb", "/sys/module/libcfs/parameters/libcfs_debug_mb"},
Signature · 1 line
1.8.3.1
PATCH 6/10 lustre: libcfs: don't assume sysfs mount point
In reply to James SimmonsThe symlinks created for the libcfs module parameters assume the mount point of syfs is always /sys. We shouldn't assume that is the case so use relative paths that guaranteed to work.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/module.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/lustre/lnet/libcfs/module.c +7 -7
@@ -563,19 +563,19 @@ static int proc_cpt_distance(struct ctl_table *table, int write,static const struct lnet_debugfs_symlink_def lnet_debugfs_symlinks[] = { {"console_ratelimit" , -"/sys/module/libcfs/parameters/libcfs_console_ratelimit" }, +"../../../module/libcfs/parameters/libcfs_console_ratelimit" }, {"debug_path" , -"/sys/module/libcfs/parameters/libcfs_debug_file_path" }, +"../../../module/libcfs/parameters/libcfs_debug_file_path" }, {"panic_on_lbug" , -"/sys/module/libcfs/parameters/libcfs_panic_on_lbug" }, +"../../../module/libcfs/parameters/libcfs_panic_on_lbug" }, {"console_backoff" , -"/sys/module/libcfs/parameters/libcfs_console_backoff" }, +"../../../module/libcfs/parameters/libcfs_console_backoff" }, {"debug_mb" , -"/sys/module/libcfs/parameters/libcfs_debug_mb" }, +"../../../module/libcfs/parameters/libcfs_debug_mb" }, {"console_min_delay_centisecs" , -"/sys/module/libcfs/parameters/libcfs_console_min_delay" }, +"../../../module/libcfs/parameters/libcfs_console_min_delay" }, {"console_max_delay_centisecs" , -"/sys/module/libcfs/parameters/libcfs_console_max_delay" }, +"../../../module/libcfs/parameters/libcfs_console_max_delay" }, {}, };
Signature · 1 line
1.8.3.1
PATCH 7/10 lustre: libcfs: properly initialize lnet_debugfs_symlink_def
In reply to James SimmonsMirgate struct lnet_debugfs_symlink_def to C99 struct initializers.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/module.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/staging/lustre/lnet/libcfs/module.c +14 -14
@@ -562,20 +562,20 @@ static int proc_cpt_distance(struct ctl_table *table, int write, };static const struct lnet_debugfs_symlink_def lnet_debugfs_symlinks[] = { - {"console_ratelimit" , -"../../../module/libcfs/parameters/libcfs_console_ratelimit" }, - {"debug_path" , -"../../../module/libcfs/parameters/libcfs_debug_file_path" }, - {"panic_on_lbug" , -"../../../module/libcfs/parameters/libcfs_panic_on_lbug" }, - {"console_backoff" , -"../../../module/libcfs/parameters/libcfs_console_backoff" }, - {"debug_mb" , -"../../../module/libcfs/parameters/libcfs_debug_mb" }, - {"console_min_delay_centisecs" , -"../../../module/libcfs/parameters/libcfs_console_min_delay" }, - {"console_max_delay_centisecs" , -"../../../module/libcfs/parameters/libcfs_console_max_delay" }, + { .name ="console_ratelimit" , + .target ="../../../module/libcfs/parameters/libcfs_console_ratelimit" }, + { .name ="debug_path" , + .target ="../../../module/libcfs/parameters/libcfs_debug_file_path" }, + { .name ="panic_on_lbug" , + .target ="../../../module/libcfs/parameters/libcfs_panic_on_lbug" }, + { .name ="console_backoff" , + .target ="../../../module/libcfs/parameters/libcfs_console_backoff" }, + { .name ="debug_mb" , + .target ="../../../module/libcfs/parameters/libcfs_debug_mb" }, + { .name ="console_min_delay_centisecs" , + .target ="../../../module/libcfs/parameters/libcfs_console_min_delay" }, + { .name ="console_max_delay_centisecs" , + .target ="../../../module/libcfs/parameters/libcfs_console_max_delay" }, {}, };
Signature · 1 line
1.8.3.1
PATCH 8/10 lustre: libcfs: test if table is NULL for lnet_insert_debugfs
In reply to James SimmonsIt is possible to call lnet_insert_debugfs() with table being NULL. We can avoid a potential oops by adding a test to see if table is not NULL.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lnet/libcfs/module.c +1 -1
@@ -659,7 +659,7 @@ void lnet_insert_debugfs(struct ctl_table *table)* We don't save the dentry returned because we don't call * debugfs_remove() but rather remove_recursive() */ -for (; table->procname; table++) +for (; table && table->procname; table++)debugfs_create_file (table->procname, table->mode, lnet_debugfs_root, table,lnet_debugfs_fops_select (table->mode));
Signature · 1 line
1.8.3.1
PATCH 9/10 lustre: libcfs: return ssize_t for lnet_debugfs_*
In reply to James SimmonsThe debugfs layer expects both lnet_debugfs_read() and lnet_debugfs_write() to return ssize_t instead of int. Change the return type.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/module.c | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/staging/lustre/lnet/libcfs/module.c +15 -15
@@ -583,37 +583,37 @@ static ssize_t lnet_debugfs_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) { struct ctl_table *table = filp->private_data; -int error;loff_t old_pos = *ppos; +ssize_t rc; - error = table->proc_handler (table,0 , (void __user *)buf, &count, ppos); + rc = table->proc_handler (table,0 , (void __user *)buf, &count, ppos);/* * On success, the length read is either in error or in count. * If ppos changed, then use count, else use error */ -if (!error && *ppos != old_pos) - error = count; -else if (error >0 ) - *ppos += error; +if (!rc && *ppos != old_pos) + rc = count; +else if (rc >0 ) + *ppos += rc; -return error; +return rc; }static ssize_t lnet_debugfs_write (struct file *filp,const char __user *buf,size_t count,loff_t *ppos) {struct ctl_table *table = filp->private_data; -int error;loff_t old_pos = *ppos; +ssize_t rc; - error = table->proc_handler (table,1 , (void __user *)buf, &count, ppos); -if (!error) { - error = count; -if (*ppos == old_pos) - *ppos += count; - } + rc = table->proc_handler (table,1 , (void __user *)buf, &count, ppos); +if (rc) +return rc; + +if (*ppos == old_pos) + *ppos += count; -return error; +return count; } static const struct file_operations lnet_debugfs_file_operations_rw = {
Signature · 1 line
1.8.3.1
PATCH 10/10 lustre: libcfs: small cleanups for debugfs code
In reply to James SimmonsSmall cleanups to make the code easier to read.
WC-bug-id: https://jira.whamcloud.com/browse/LU-8066
Reviewed-on: https://review.whamcloud.com/24688
--- drivers/staging/lustre/lnet/libcfs/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/libcfs/debug.c +4 -4
@@ -180,9 +180,11 @@ static int param_set_uint_minmax(const char *val,if (!val)return -EINVAL ; + ret =kstrtouint (val,0 , &num);if (ret <0 || num < min || num > max)return -EINVAL ; + *((unsigned int *)kp->arg) = num;return 0 ; }
@@ -229,8 +231,7 @@ static int param_set_uintpos(const char *val, const struct kernel_param *kp)int libcfs_panic_in_progress;/* libcfs_debug_token2mask() expects the returned string in lower-case */ -static const char * -libcfs_debug_subsys2str (int subsys) +static const char *libcfs_debug_subsys2str (int subsys) {static const char *const libcfs_debug_subsystems[] =LIBCFS_DEBUG_SUBSYS_NAMES ;
@@ -242,8 +243,7 @@ static int param_set_uintpos(const char *val, const struct kernel_param *kp) }/* libcfs_debug_token2mask() expects the returned string in lower-case */ -static const char * -libcfs_debug_dbg2str (int debug) +static const char *libcfs_debug_dbg2str (int debug) {static const char *const libcfs_debug_masks[] =LIBCFS_DEBUG_MASKS_NAMES ;
Signature · 1 line
1.8.3.1
cover lustre: libcfs: fix libcfs debugfs bugs
In reply to James SimmonsQuoted 16 lines · James Simmons
The original port to sysfs / debugfs was done in haste without any testing so many bugs were introduced. This patch set resolves the bugs found in the libcfs code when it was reviewed.
James Simmons (10):
lustre: libcfs: rename lustre_*_debugfs to lnet_*_debugfs
lustre: libcfs: rename*_debugmbto*_debug_mb
lustre: libcfs: makelnet_debugfs_symlink_deffields const
lustre: libcfs: fix module loading and sysfs setting race
lustre: libcfs: fix wrong debugfs symlink name
lustre: libcfs: don't assume sysfs mount point
lustre: libcfs: properly initializelnet_debugfs_symlink_def
lustre: libcfs: test if table is NULL forlnet_insert_debugfs
lustre: libcfs: returnssize_tfor lnet_debugfs_*
lustre: libcfs: small cleanups for debugfs code
Quoted 8 lines
.../staging/lustre/include/linux/libcfs/libcfs.h | 2 +- drivers/staging/lustre/lnet/libcfs/debug.c | 28 ++++---- drivers/staging/lustre/lnet/libcfs/module.c | 78 +++++++++++----------- drivers/staging/lustre/lnet/lnet/router_proc.c | 2 +- 4 files changed, 57 insertions(+), 53 deletions(-)Signature · 1 line
1.8.3.1
These all look good to me, so I've (provisionally) applied them. I didn't know about kernel_param_lock() before. I wonder if it would make sense to use that to protect updates to sbi->ll_flags???
Thanks,
NeilBrown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180704/9f21b8eb/attachment.sig>
cover lustre: libcfs: fix libcfs debugfs bugs
Quoted 23 lines
Quoted 23 lines
The original port to sysfs / debugfs was done in haste without any testing so many bugs were introduced. This patch set resolves the bugs found in the libcfs code when it was reviewed.
James Simmons (10):
lustre: libcfs: rename lustre_*_debugfs to lnet_*_debugfs
lustre: libcfs: rename*_debugmbto*_debug_mb
lustre: libcfs: makelnet_debugfs_symlink_deffields const
lustre: libcfs: fix module loading and sysfs setting race
lustre: libcfs: fix wrong debugfs symlink name
lustre: libcfs: don't assume sysfs mount point
lustre: libcfs: properly initializelnet_debugfs_symlink_def
lustre: libcfs: test if table is NULL forlnet_insert_debugfs
lustre: libcfs: returnssize_tfor lnet_debugfs_*
lustre: libcfs: small cleanups for debugfs code.../staging/lustre/include/linux/libcfs/libcfs.h | 2 +- drivers/staging/lustre/lnet/libcfs/debug.c | 28 ++++---- drivers/staging/lustre/lnet/libcfs/module.c | 78 +++++++++++----------- drivers/staging/lustre/lnet/lnet/router_proc.c | 2 +- 4 files changed, 57 insertions(+), 53 deletions(-)
Quoted 6 lines
Quoted 2 lines
Signature · 1 line
1.8.3.1These all look good to me, so I've (provisionally) applied them. I didn't know about
kernel_param_lock()before. I wonder if it would make sense to use that to protect updates tosbi->ll_flags???
Sadly no. The kernel_param_lock() takes a special mutex, param_lock to handle the racing between modules and sysfs. In the case of sbu->ll_flags that is parsed from the mount string. You can see the flow in obd_mount.c with lmd->lmd_opts being filled from the mount string and that ends up being processed in llite_lib.c with the function ll_option(). Their it translates to sbi->ll_flags.