[PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable

Wei Yongjun posted 4 patches 3 years, 7 months ago
There is a newer version of this series
[PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable
Posted by Wei Yongjun 3 years, 7 months ago
Attributes of stack filter are show as unsigned decimal, such
as 'require-start', 'require-end'. This patch change to
show them as unsigned hexadecimal for more readable.

Before:
  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  18446744072638263296

After:
  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  0xffffffffc0257000

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 lib/fault-inject.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 515fc5aaf032..deca05e7c9b3 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_t mode,
 
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
 
+DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n");
+
+static void debugfs_create_xl(const char *name, umode_t mode,
+			      struct dentry *parent, unsigned long *value)
+{
+	debugfs_create_file(name, mode, parent, value, &fops_xl);
+}
+
 static int debugfs_stacktrace_depth_set(void *data, u64 val)
 {
 	*(unsigned long *)data =
@@ -223,10 +231,10 @@ struct dentry *fault_create_debugfs_attr(const char *name,
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
 	debugfs_create_stacktrace_depth("stacktrace-depth", mode, dir,
 					&attr->stacktrace_depth);
-	debugfs_create_ul("require-start", mode, dir, &attr->require_start);
-	debugfs_create_ul("require-end", mode, dir, &attr->require_end);
-	debugfs_create_ul("reject-start", mode, dir, &attr->reject_start);
-	debugfs_create_ul("reject-end", mode, dir, &attr->reject_end);
+	debugfs_create_xl("require-start", mode, dir, &attr->require_start);
+	debugfs_create_xl("require-end", mode, dir, &attr->require_end);
+	debugfs_create_xl("reject-start", mode, dir, &attr->reject_start);
+	debugfs_create_xl("reject-end", mode, dir, &attr->reject_end);
 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
 
 	attr->dname = dget(dir);
-- 
2.34.1
Re: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable
Posted by Akinobu Mita 3 years, 7 months ago
2022年8月17日(水) 16:45 Wei Yongjun <weiyongjun1@huawei.com>:
>
> Attributes of stack filter are show as unsigned decimal, such
> as 'require-start', 'require-end'. This patch change to
> show them as unsigned hexadecimal for more readable.
>
> Before:
>   $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
>   $ cat /sys/kernel/debug/failslab/require-start
>   18446744072638263296
>
> After:
>   $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
>   $ cat /sys/kernel/debug/failslab/require-start
>   0xffffffffc0257000
>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  lib/fault-inject.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/lib/fault-inject.c b/lib/fault-inject.c
> index 515fc5aaf032..deca05e7c9b3 100644
> --- a/lib/fault-inject.c
> +++ b/lib/fault-inject.c
> @@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_t mode,
>
>  #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
>
> +DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n");
> +
> +static void debugfs_create_xl(const char *name, umode_t mode,
> +                             struct dentry *parent, unsigned long *value)
> +{
> +       debugfs_create_file(name, mode, parent, value, &fops_xl);
> +}

How about using an existing `debugfs_create_xul()` instead of defining
a local helper function?
Re: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable
Posted by Andrew Morton 3 years, 6 months ago
On Fri, 19 Aug 2022 22:24:10 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:

> 2022年8月17日(水) 16:45 Wei Yongjun <weiyongjun1@huawei.com>:
> >
> > Attributes of stack filter are show as unsigned decimal, such
> > as 'require-start', 'require-end'. This patch change to
> > show them as unsigned hexadecimal for more readable.
> >
> > Before:
> >   $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
> >   $ cat /sys/kernel/debug/failslab/require-start
> >   18446744072638263296
> >
> > After:
> >   $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
> >   $ cat /sys/kernel/debug/failslab/require-start
> >   0xffffffffc0257000
> >
> > Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> > ---
> >  lib/fault-inject.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/fault-inject.c b/lib/fault-inject.c
> > index 515fc5aaf032..deca05e7c9b3 100644
> > --- a/lib/fault-inject.c
> > +++ b/lib/fault-inject.c
> > @@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_t mode,
> >
> >  #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
> >
> > +DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n");
> > +
> > +static void debugfs_create_xl(const char *name, umode_t mode,
> > +                             struct dentry *parent, unsigned long *value)
> > +{
> > +       debugfs_create_file(name, mode, parent, value, &fops_xl);
> > +}
> 
> How about using an existing `debugfs_create_xul()` instead of defining
> a local helper function?

Could we please have a response to this?