diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-12-07 22:17:06 -0500 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2009-12-13 12:37:28 -0500 |
commit | 8d18eaaff5acaa58369be342c86e607643ce10c7 (patch) | |
tree | ff5d275165cd224468a9930f94ac80a53bfc55c7 /kernel/trace/trace.c | |
parent | 2cbafd68b826f8e0471875cf33cdfb8a1478aef1 (diff) |
tracing: Simplify trace_option_write()
- remove duplicate code inside trace_options_write()
- extract duplicate code in trace_options_write() and set_tracer_option()
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <4B1DC532.9010802@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 | 85 |
1 files changed, 31 insertions, 54 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 898409d60422..05076008f371 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -2343,38 +2343,39 @@ static int tracing_trace_options_show(struct seq_file *m, void *v) | |||
2343 | return 0; | 2343 | return 0; |
2344 | } | 2344 | } |
2345 | 2345 | ||
2346 | static int __set_tracer_option(struct tracer *trace, | ||
2347 | struct tracer_flags *tracer_flags, | ||
2348 | struct tracer_opt *opts, int neg) | ||
2349 | { | ||
2350 | int ret; | ||
2351 | |||
2352 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); | ||
2353 | if (ret) | ||
2354 | return ret; | ||
2355 | |||
2356 | if (neg) | ||
2357 | tracer_flags->val &= ~opts->bit; | ||
2358 | else | ||
2359 | tracer_flags->val |= opts->bit; | ||
2360 | return 0; | ||
2361 | } | ||
2362 | |||
2346 | /* Try to assign a tracer specific option */ | 2363 | /* Try to assign a tracer specific option */ |
2347 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | 2364 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
2348 | { | 2365 | { |
2349 | struct tracer_flags *tracer_flags = trace->flags; | 2366 | struct tracer_flags *tracer_flags = trace->flags; |
2350 | struct tracer_opt *opts = NULL; | 2367 | struct tracer_opt *opts = NULL; |
2351 | int ret = 0, i = 0; | 2368 | int i; |
2352 | int len; | ||
2353 | 2369 | ||
2354 | for (i = 0; tracer_flags->opts[i].name; i++) { | 2370 | for (i = 0; tracer_flags->opts[i].name; i++) { |
2355 | opts = &tracer_flags->opts[i]; | 2371 | opts = &tracer_flags->opts[i]; |
2356 | len = strlen(opts->name); | ||
2357 | 2372 | ||
2358 | if (strncmp(cmp, opts->name, len) == 0) { | 2373 | if (strcmp(cmp, opts->name) == 0) |
2359 | ret = trace->set_flag(tracer_flags->val, | 2374 | return __set_tracer_option(trace, trace->flags, |
2360 | opts->bit, !neg); | 2375 | opts, neg); |
2361 | break; | ||
2362 | } | ||
2363 | } | 2376 | } |
2364 | /* Not found */ | ||
2365 | if (!tracer_flags->opts[i].name) | ||
2366 | return -EINVAL; | ||
2367 | 2377 | ||
2368 | /* Refused to handle */ | 2378 | return -EINVAL; |
2369 | if (ret) | ||
2370 | return ret; | ||
2371 | |||
2372 | if (neg) | ||
2373 | tracer_flags->val &= ~opts->bit; | ||
2374 | else | ||
2375 | tracer_flags->val |= opts->bit; | ||
2376 | |||
2377 | return 0; | ||
2378 | } | 2379 | } |
2379 | 2380 | ||
2380 | static void set_tracer_flags(unsigned int mask, int enabled) | 2381 | static void set_tracer_flags(unsigned int mask, int enabled) |
@@ -2394,7 +2395,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf, | |||
2394 | size_t cnt, loff_t *ppos) | 2395 | size_t cnt, loff_t *ppos) |
2395 | { | 2396 | { |
2396 | char buf[64]; | 2397 | char buf[64]; |
2397 | char *cmp = buf; | 2398 | char *cmp; |
2398 | int neg = 0; | 2399 | int neg = 0; |
2399 | int ret; | 2400 | int ret; |
2400 | int i; | 2401 | int i; |
@@ -2406,16 +2407,15 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf, | |||
2406 | return -EFAULT; | 2407 | return -EFAULT; |
2407 | 2408 | ||
2408 | buf[cnt] = 0; | 2409 | buf[cnt] = 0; |
2410 | cmp = strstrip(buf); | ||
2409 | 2411 | ||
2410 | if (strncmp(buf, "no", 2) == 0) { | 2412 | if (strncmp(cmp, "no", 2) == 0) { |
2411 | neg = 1; | 2413 | neg = 1; |
2412 | cmp += 2; | 2414 | cmp += 2; |
2413 | } | 2415 | } |
2414 | 2416 | ||
2415 | for (i = 0; trace_options[i]; i++) { | 2417 | for (i = 0; trace_options[i]; i++) { |
2416 | int len = strlen(trace_options[i]); | 2418 | if (strcmp(cmp, trace_options[i]) == 0) { |
2417 | |||
2418 | if (strncmp(cmp, trace_options[i], len) == 0) { | ||
2419 | set_tracer_flags(1 << i, !neg); | 2419 | set_tracer_flags(1 << i, !neg); |
2420 | break; | 2420 | break; |
2421 | } | 2421 | } |
@@ -3927,39 +3927,16 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
3927 | if (ret < 0) | 3927 | if (ret < 0) |
3928 | return ret; | 3928 | return ret; |
3929 | 3929 | ||
3930 | ret = 0; | 3930 | if (val != 0 && val != 1) |
3931 | switch (val) { | 3931 | return -EINVAL; |
3932 | case 0: | ||
3933 | /* do nothing if already cleared */ | ||
3934 | if (!(topt->flags->val & topt->opt->bit)) | ||
3935 | break; | ||
3936 | |||
3937 | mutex_lock(&trace_types_lock); | ||
3938 | if (current_trace->set_flag) | ||
3939 | ret = current_trace->set_flag(topt->flags->val, | ||
3940 | topt->opt->bit, 0); | ||
3941 | mutex_unlock(&trace_types_lock); | ||
3942 | if (ret) | ||
3943 | return ret; | ||
3944 | topt->flags->val &= ~topt->opt->bit; | ||
3945 | break; | ||
3946 | case 1: | ||
3947 | /* do nothing if already set */ | ||
3948 | if (topt->flags->val & topt->opt->bit) | ||
3949 | break; | ||
3950 | 3932 | ||
3933 | if (!!(topt->flags->val & topt->opt->bit) != val) { | ||
3951 | mutex_lock(&trace_types_lock); | 3934 | mutex_lock(&trace_types_lock); |
3952 | if (current_trace->set_flag) | 3935 | ret = __set_tracer_option(current_trace, topt->flags, |
3953 | ret = current_trace->set_flag(topt->flags->val, | 3936 | topt->opt, val); |
3954 | topt->opt->bit, 1); | ||
3955 | mutex_unlock(&trace_types_lock); | 3937 | mutex_unlock(&trace_types_lock); |
3956 | if (ret) | 3938 | if (ret) |
3957 | return ret; | 3939 | return ret; |
3958 | topt->flags->val |= topt->opt->bit; | ||
3959 | break; | ||
3960 | |||
3961 | default: | ||
3962 | return -EINVAL; | ||
3963 | } | 3940 | } |
3964 | 3941 | ||
3965 | *ppos += cnt; | 3942 | *ppos += cnt; |