diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-12-07 22:15:59 -0500 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2009-12-13 12:37:27 -0500 |
commit | fdb372ed4cadbfe9dbba0e932a77d0523682e690 (patch) | |
tree | fe58239da27070baac9c0dc3c692f7535cfcfa15 /kernel/trace/trace.c | |
parent | 91baf6285be7282cfa487de92f836c50749dffb9 (diff) |
tracing: Use seq file for trace_options
Code simplification for reading trace_options.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-reference: <4B1DC4EF.3090106@cn.fujitsu.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 88bd9ae2a9ed..a6c41cc63285 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -2316,67 +2316,32 @@ static const struct file_operations tracing_cpumask_fops = { | |||
2316 | .write = tracing_cpumask_write, | 2316 | .write = tracing_cpumask_write, |
2317 | }; | 2317 | }; |
2318 | 2318 | ||
2319 | static ssize_t | 2319 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
2320 | tracing_trace_options_read(struct file *filp, char __user *ubuf, | ||
2321 | size_t cnt, loff_t *ppos) | ||
2322 | { | 2320 | { |
2323 | struct tracer_opt *trace_opts; | 2321 | struct tracer_opt *trace_opts; |
2324 | u32 tracer_flags; | 2322 | u32 tracer_flags; |
2325 | int len = 0; | ||
2326 | char *buf; | ||
2327 | int r = 0; | ||
2328 | int i; | 2323 | int i; |
2329 | 2324 | ||
2330 | |||
2331 | /* calculate max size */ | ||
2332 | for (i = 0; trace_options[i]; i++) { | ||
2333 | len += strlen(trace_options[i]); | ||
2334 | len += 3; /* "no" and newline */ | ||
2335 | } | ||
2336 | |||
2337 | mutex_lock(&trace_types_lock); | 2325 | mutex_lock(&trace_types_lock); |
2338 | tracer_flags = current_trace->flags->val; | 2326 | tracer_flags = current_trace->flags->val; |
2339 | trace_opts = current_trace->flags->opts; | 2327 | trace_opts = current_trace->flags->opts; |
2340 | 2328 | ||
2341 | /* | ||
2342 | * Increase the size with names of options specific | ||
2343 | * of the current tracer. | ||
2344 | */ | ||
2345 | for (i = 0; trace_opts[i].name; i++) { | ||
2346 | len += strlen(trace_opts[i].name); | ||
2347 | len += 3; /* "no" and newline */ | ||
2348 | } | ||
2349 | |||
2350 | /* +1 for \0 */ | ||
2351 | buf = kmalloc(len + 1, GFP_KERNEL); | ||
2352 | if (!buf) { | ||
2353 | mutex_unlock(&trace_types_lock); | ||
2354 | return -ENOMEM; | ||
2355 | } | ||
2356 | |||
2357 | for (i = 0; trace_options[i]; i++) { | 2329 | for (i = 0; trace_options[i]; i++) { |
2358 | if (trace_flags & (1 << i)) | 2330 | if (trace_flags & (1 << i)) |
2359 | r += sprintf(buf + r, "%s\n", trace_options[i]); | 2331 | seq_printf(m, "%s\n", trace_options[i]); |
2360 | else | 2332 | else |
2361 | r += sprintf(buf + r, "no%s\n", trace_options[i]); | 2333 | seq_printf(m, "no%s\n", trace_options[i]); |
2362 | } | 2334 | } |
2363 | 2335 | ||
2364 | for (i = 0; trace_opts[i].name; i++) { | 2336 | for (i = 0; trace_opts[i].name; i++) { |
2365 | if (tracer_flags & trace_opts[i].bit) | 2337 | if (tracer_flags & trace_opts[i].bit) |
2366 | r += sprintf(buf + r, "%s\n", | 2338 | seq_printf(m, "%s\n", trace_opts[i].name); |
2367 | trace_opts[i].name); | ||
2368 | else | 2339 | else |
2369 | r += sprintf(buf + r, "no%s\n", | 2340 | seq_printf(m, "no%s\n", trace_opts[i].name); |
2370 | trace_opts[i].name); | ||
2371 | } | 2341 | } |
2372 | mutex_unlock(&trace_types_lock); | 2342 | mutex_unlock(&trace_types_lock); |
2373 | 2343 | ||
2374 | WARN_ON(r >= len + 1); | 2344 | return 0; |
2375 | |||
2376 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | ||
2377 | |||
2378 | kfree(buf); | ||
2379 | return r; | ||
2380 | } | 2345 | } |
2381 | 2346 | ||
2382 | /* Try to assign a tracer specific option */ | 2347 | /* Try to assign a tracer specific option */ |
@@ -2471,9 +2436,18 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf, | |||
2471 | return cnt; | 2436 | return cnt; |
2472 | } | 2437 | } |
2473 | 2438 | ||
2439 | static int tracing_trace_options_open(struct inode *inode, struct file *file) | ||
2440 | { | ||
2441 | if (tracing_disabled) | ||
2442 | return -ENODEV; | ||
2443 | return single_open(file, tracing_trace_options_show, NULL); | ||
2444 | } | ||
2445 | |||
2474 | static const struct file_operations tracing_iter_fops = { | 2446 | static const struct file_operations tracing_iter_fops = { |
2475 | .open = tracing_open_generic, | 2447 | .open = tracing_trace_options_open, |
2476 | .read = tracing_trace_options_read, | 2448 | .read = seq_read, |
2449 | .llseek = seq_lseek, | ||
2450 | .release = single_release, | ||
2477 | .write = tracing_trace_options_write, | 2451 | .write = tracing_trace_options_write, |
2478 | }; | 2452 | }; |
2479 | 2453 | ||