Commit fdb372ed authored by Li Zefan's avatar Li Zefan Committed by Frederic Weisbecker

tracing: Use seq file for trace_options

Code simplification for reading trace_options.
Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Acked-by: default avatarSteven Rostedt <rostedt@goodmis.org>
LKML-reference: <4B1DC4EF.3090106@cn.fujitsu.com>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
parent 91baf628
...@@ -2316,67 +2316,32 @@ static const struct file_operations tracing_cpumask_fops = { ...@@ -2316,67 +2316,32 @@ static const struct file_operations tracing_cpumask_fops = {
.write = tracing_cpumask_write, .write = tracing_cpumask_write,
}; };
static ssize_t static int tracing_trace_options_show(struct seq_file *m, void *v)
tracing_trace_options_read(struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos)
{ {
struct tracer_opt *trace_opts; struct tracer_opt *trace_opts;
u32 tracer_flags; u32 tracer_flags;
int len = 0;
char *buf;
int r = 0;
int i; int i;
/* calculate max size */
for (i = 0; trace_options[i]; i++) {
len += strlen(trace_options[i]);
len += 3; /* "no" and newline */
}
mutex_lock(&trace_types_lock); mutex_lock(&trace_types_lock);
tracer_flags = current_trace->flags->val; tracer_flags = current_trace->flags->val;
trace_opts = current_trace->flags->opts; trace_opts = current_trace->flags->opts;
/*
* Increase the size with names of options specific
* of the current tracer.
*/
for (i = 0; trace_opts[i].name; i++) {
len += strlen(trace_opts[i].name);
len += 3; /* "no" and newline */
}
/* +1 for \0 */
buf = kmalloc(len + 1, GFP_KERNEL);
if (!buf) {
mutex_unlock(&trace_types_lock);
return -ENOMEM;
}
for (i = 0; trace_options[i]; i++) { for (i = 0; trace_options[i]; i++) {
if (trace_flags & (1 << i)) if (trace_flags & (1 << i))
r += sprintf(buf + r, "%s\n", trace_options[i]); seq_printf(m, "%s\n", trace_options[i]);
else else
r += sprintf(buf + r, "no%s\n", trace_options[i]); seq_printf(m, "no%s\n", trace_options[i]);
} }
for (i = 0; trace_opts[i].name; i++) { for (i = 0; trace_opts[i].name; i++) {
if (tracer_flags & trace_opts[i].bit) if (tracer_flags & trace_opts[i].bit)
r += sprintf(buf + r, "%s\n", seq_printf(m, "%s\n", trace_opts[i].name);
trace_opts[i].name);
else else
r += sprintf(buf + r, "no%s\n", seq_printf(m, "no%s\n", trace_opts[i].name);
trace_opts[i].name);
} }
mutex_unlock(&trace_types_lock); mutex_unlock(&trace_types_lock);
WARN_ON(r >= len + 1); return 0;
r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
kfree(buf);
return r;
} }
/* Try to assign a tracer specific option */ /* Try to assign a tracer specific option */
...@@ -2471,9 +2436,18 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf, ...@@ -2471,9 +2436,18 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
return cnt; return cnt;
} }
static int tracing_trace_options_open(struct inode *inode, struct file *file)
{
if (tracing_disabled)
return -ENODEV;
return single_open(file, tracing_trace_options_show, NULL);
}
static const struct file_operations tracing_iter_fops = { static const struct file_operations tracing_iter_fops = {
.open = tracing_open_generic, .open = tracing_trace_options_open,
.read = tracing_trace_options_read, .read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = tracing_trace_options_write, .write = tracing_trace_options_write,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment