diff options
Diffstat (limited to 'kernel/trace/blktrace.c')
-rw-r--r-- | kernel/trace/blktrace.c | 473 |
1 files changed, 236 insertions, 237 deletions
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index b171778e3863..947c5b3f90c4 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c | |||
@@ -30,7 +30,7 @@ | |||
30 | static unsigned int blktrace_seq __read_mostly = 1; | 30 | static unsigned int blktrace_seq __read_mostly = 1; |
31 | 31 | ||
32 | static struct trace_array *blk_tr; | 32 | static struct trace_array *blk_tr; |
33 | static int __read_mostly blk_tracer_enabled; | 33 | static bool blk_tracer_enabled __read_mostly; |
34 | 34 | ||
35 | /* Select an alternative, minimalistic output than the original one */ | 35 | /* Select an alternative, minimalistic output than the original one */ |
36 | #define TRACE_BLK_OPT_CLASSIC 0x1 | 36 | #define TRACE_BLK_OPT_CLASSIC 0x1 |
@@ -47,10 +47,9 @@ static struct tracer_flags blk_tracer_flags = { | |||
47 | }; | 47 | }; |
48 | 48 | ||
49 | /* Global reference count of probes */ | 49 | /* Global reference count of probes */ |
50 | static DEFINE_MUTEX(blk_probe_mutex); | ||
51 | static atomic_t blk_probes_ref = ATOMIC_INIT(0); | 50 | static atomic_t blk_probes_ref = ATOMIC_INIT(0); |
52 | 51 | ||
53 | static int blk_register_tracepoints(void); | 52 | static void blk_register_tracepoints(void); |
54 | static void blk_unregister_tracepoints(void); | 53 | static void blk_unregister_tracepoints(void); |
55 | 54 | ||
56 | /* | 55 | /* |
@@ -60,22 +59,39 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action, | |||
60 | const void *data, size_t len) | 59 | const void *data, size_t len) |
61 | { | 60 | { |
62 | struct blk_io_trace *t; | 61 | struct blk_io_trace *t; |
62 | struct ring_buffer_event *event = NULL; | ||
63 | int pc = 0; | ||
64 | int cpu = smp_processor_id(); | ||
65 | bool blk_tracer = blk_tracer_enabled; | ||
66 | |||
67 | if (blk_tracer) { | ||
68 | pc = preempt_count(); | ||
69 | event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK, | ||
70 | sizeof(*t) + len, | ||
71 | 0, pc); | ||
72 | if (!event) | ||
73 | return; | ||
74 | t = ring_buffer_event_data(event); | ||
75 | goto record_it; | ||
76 | } | ||
63 | 77 | ||
64 | if (!bt->rchan) | 78 | if (!bt->rchan) |
65 | return; | 79 | return; |
66 | 80 | ||
67 | t = relay_reserve(bt->rchan, sizeof(*t) + len); | 81 | t = relay_reserve(bt->rchan, sizeof(*t) + len); |
68 | if (t) { | 82 | if (t) { |
69 | const int cpu = smp_processor_id(); | ||
70 | |||
71 | t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; | 83 | t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; |
72 | t->time = ktime_to_ns(ktime_get()); | 84 | t->time = ktime_to_ns(ktime_get()); |
85 | record_it: | ||
73 | t->device = bt->dev; | 86 | t->device = bt->dev; |
74 | t->action = action; | 87 | t->action = action; |
75 | t->pid = pid; | 88 | t->pid = pid; |
76 | t->cpu = cpu; | 89 | t->cpu = cpu; |
77 | t->pdu_len = len; | 90 | t->pdu_len = len; |
78 | memcpy((void *) t + sizeof(*t), data, len); | 91 | memcpy((void *) t + sizeof(*t), data, len); |
92 | |||
93 | if (blk_tracer) | ||
94 | trace_buffer_unlock_commit(blk_tr, event, 0, pc); | ||
79 | } | 95 | } |
80 | } | 96 | } |
81 | 97 | ||
@@ -111,14 +127,8 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...) | |||
111 | unsigned long flags; | 127 | unsigned long flags; |
112 | char *buf; | 128 | char *buf; |
113 | 129 | ||
114 | if (blk_tr) { | 130 | if (unlikely(bt->trace_state != Blktrace_running && |
115 | va_start(args, fmt); | 131 | !blk_tracer_enabled)) |
116 | ftrace_vprintk(fmt, args); | ||
117 | va_end(args); | ||
118 | return; | ||
119 | } | ||
120 | |||
121 | if (!bt->msg_data) | ||
122 | return; | 132 | return; |
123 | 133 | ||
124 | local_irq_save(flags); | 134 | local_irq_save(flags); |
@@ -148,8 +158,8 @@ static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector, | |||
148 | /* | 158 | /* |
149 | * Data direction bit lookup | 159 | * Data direction bit lookup |
150 | */ | 160 | */ |
151 | static u32 ddir_act[2] __read_mostly = { BLK_TC_ACT(BLK_TC_READ), | 161 | static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ), |
152 | BLK_TC_ACT(BLK_TC_WRITE) }; | 162 | BLK_TC_ACT(BLK_TC_WRITE) }; |
153 | 163 | ||
154 | /* The ilog2() calls fall out because they're constant */ | 164 | /* The ilog2() calls fall out because they're constant */ |
155 | #define MASK_TC_BIT(rw, __name) ((rw & (1 << BIO_RW_ ## __name)) << \ | 165 | #define MASK_TC_BIT(rw, __name) ((rw & (1 << BIO_RW_ ## __name)) << \ |
@@ -169,9 +179,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, | |||
169 | unsigned long *sequence; | 179 | unsigned long *sequence; |
170 | pid_t pid; | 180 | pid_t pid; |
171 | int cpu, pc = 0; | 181 | int cpu, pc = 0; |
182 | bool blk_tracer = blk_tracer_enabled; | ||
172 | 183 | ||
173 | if (unlikely(bt->trace_state != Blktrace_running || | 184 | if (unlikely(bt->trace_state != Blktrace_running && !blk_tracer)) |
174 | !blk_tracer_enabled)) | ||
175 | return; | 185 | return; |
176 | 186 | ||
177 | what |= ddir_act[rw & WRITE]; | 187 | what |= ddir_act[rw & WRITE]; |
@@ -186,7 +196,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, | |||
186 | return; | 196 | return; |
187 | cpu = raw_smp_processor_id(); | 197 | cpu = raw_smp_processor_id(); |
188 | 198 | ||
189 | if (blk_tr) { | 199 | if (blk_tracer) { |
190 | tracing_record_cmdline(current); | 200 | tracing_record_cmdline(current); |
191 | 201 | ||
192 | pc = preempt_count(); | 202 | pc = preempt_count(); |
@@ -236,7 +246,7 @@ record_it: | |||
236 | if (pdu_len) | 246 | if (pdu_len) |
237 | memcpy((void *) t + sizeof(*t), pdu_data, pdu_len); | 247 | memcpy((void *) t + sizeof(*t), pdu_data, pdu_len); |
238 | 248 | ||
239 | if (blk_tr) { | 249 | if (blk_tracer) { |
240 | trace_buffer_unlock_commit(blk_tr, event, 0, pc); | 250 | trace_buffer_unlock_commit(blk_tr, event, 0, pc); |
241 | return; | 251 | return; |
242 | } | 252 | } |
@@ -248,7 +258,7 @@ record_it: | |||
248 | static struct dentry *blk_tree_root; | 258 | static struct dentry *blk_tree_root; |
249 | static DEFINE_MUTEX(blk_tree_mutex); | 259 | static DEFINE_MUTEX(blk_tree_mutex); |
250 | 260 | ||
251 | static void blk_trace_cleanup(struct blk_trace *bt) | 261 | static void blk_trace_free(struct blk_trace *bt) |
252 | { | 262 | { |
253 | debugfs_remove(bt->msg_file); | 263 | debugfs_remove(bt->msg_file); |
254 | debugfs_remove(bt->dropped_file); | 264 | debugfs_remove(bt->dropped_file); |
@@ -256,10 +266,13 @@ static void blk_trace_cleanup(struct blk_trace *bt) | |||
256 | free_percpu(bt->sequence); | 266 | free_percpu(bt->sequence); |
257 | free_percpu(bt->msg_data); | 267 | free_percpu(bt->msg_data); |
258 | kfree(bt); | 268 | kfree(bt); |
259 | mutex_lock(&blk_probe_mutex); | 269 | } |
270 | |||
271 | static void blk_trace_cleanup(struct blk_trace *bt) | ||
272 | { | ||
273 | blk_trace_free(bt); | ||
260 | if (atomic_dec_and_test(&blk_probes_ref)) | 274 | if (atomic_dec_and_test(&blk_probes_ref)) |
261 | blk_unregister_tracepoints(); | 275 | blk_unregister_tracepoints(); |
262 | mutex_unlock(&blk_probe_mutex); | ||
263 | } | 276 | } |
264 | 277 | ||
265 | int blk_trace_remove(struct request_queue *q) | 278 | int blk_trace_remove(struct request_queue *q) |
@@ -270,8 +283,7 @@ int blk_trace_remove(struct request_queue *q) | |||
270 | if (!bt) | 283 | if (!bt) |
271 | return -EINVAL; | 284 | return -EINVAL; |
272 | 285 | ||
273 | if (bt->trace_state == Blktrace_setup || | 286 | if (bt->trace_state != Blktrace_running) |
274 | bt->trace_state == Blktrace_stopped) | ||
275 | blk_trace_cleanup(bt); | 287 | blk_trace_cleanup(bt); |
276 | 288 | ||
277 | return 0; | 289 | return 0; |
@@ -414,11 +426,11 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, | |||
414 | if (buts->name[i] == '/') | 426 | if (buts->name[i] == '/') |
415 | buts->name[i] = '_'; | 427 | buts->name[i] = '_'; |
416 | 428 | ||
417 | ret = -ENOMEM; | ||
418 | bt = kzalloc(sizeof(*bt), GFP_KERNEL); | 429 | bt = kzalloc(sizeof(*bt), GFP_KERNEL); |
419 | if (!bt) | 430 | if (!bt) |
420 | goto err; | 431 | return -ENOMEM; |
421 | 432 | ||
433 | ret = -ENOMEM; | ||
422 | bt->sequence = alloc_percpu(unsigned long); | 434 | bt->sequence = alloc_percpu(unsigned long); |
423 | if (!bt->sequence) | 435 | if (!bt->sequence) |
424 | goto err; | 436 | goto err; |
@@ -429,11 +441,15 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, | |||
429 | 441 | ||
430 | ret = -ENOENT; | 442 | ret = -ENOENT; |
431 | 443 | ||
444 | mutex_lock(&blk_tree_mutex); | ||
432 | if (!blk_tree_root) { | 445 | if (!blk_tree_root) { |
433 | blk_tree_root = debugfs_create_dir("block", NULL); | 446 | blk_tree_root = debugfs_create_dir("block", NULL); |
434 | if (!blk_tree_root) | 447 | if (!blk_tree_root) { |
435 | return -ENOMEM; | 448 | mutex_unlock(&blk_tree_mutex); |
449 | goto err; | ||
450 | } | ||
436 | } | 451 | } |
452 | mutex_unlock(&blk_tree_mutex); | ||
437 | 453 | ||
438 | dir = debugfs_create_dir(buts->name, blk_tree_root); | 454 | dir = debugfs_create_dir(buts->name, blk_tree_root); |
439 | 455 | ||
@@ -471,14 +487,6 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, | |||
471 | bt->pid = buts->pid; | 487 | bt->pid = buts->pid; |
472 | bt->trace_state = Blktrace_setup; | 488 | bt->trace_state = Blktrace_setup; |
473 | 489 | ||
474 | mutex_lock(&blk_probe_mutex); | ||
475 | if (atomic_add_return(1, &blk_probes_ref) == 1) { | ||
476 | ret = blk_register_tracepoints(); | ||
477 | if (ret) | ||
478 | goto probe_err; | ||
479 | } | ||
480 | mutex_unlock(&blk_probe_mutex); | ||
481 | |||
482 | ret = -EBUSY; | 490 | ret = -EBUSY; |
483 | old_bt = xchg(&q->blk_trace, bt); | 491 | old_bt = xchg(&q->blk_trace, bt); |
484 | if (old_bt) { | 492 | if (old_bt) { |
@@ -486,22 +494,12 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, | |||
486 | goto err; | 494 | goto err; |
487 | } | 495 | } |
488 | 496 | ||
497 | if (atomic_inc_return(&blk_probes_ref) == 1) | ||
498 | blk_register_tracepoints(); | ||
499 | |||
489 | return 0; | 500 | return 0; |
490 | probe_err: | ||
491 | atomic_dec(&blk_probes_ref); | ||
492 | mutex_unlock(&blk_probe_mutex); | ||
493 | err: | 501 | err: |
494 | if (bt) { | 502 | blk_trace_free(bt); |
495 | if (bt->msg_file) | ||
496 | debugfs_remove(bt->msg_file); | ||
497 | if (bt->dropped_file) | ||
498 | debugfs_remove(bt->dropped_file); | ||
499 | free_percpu(bt->sequence); | ||
500 | free_percpu(bt->msg_data); | ||
501 | if (bt->rchan) | ||
502 | relay_close(bt->rchan); | ||
503 | kfree(bt); | ||
504 | } | ||
505 | return ret; | 503 | return ret; |
506 | } | 504 | } |
507 | 505 | ||
@@ -863,7 +861,7 @@ void blk_add_driver_data(struct request_queue *q, | |||
863 | } | 861 | } |
864 | EXPORT_SYMBOL_GPL(blk_add_driver_data); | 862 | EXPORT_SYMBOL_GPL(blk_add_driver_data); |
865 | 863 | ||
866 | static int blk_register_tracepoints(void) | 864 | static void blk_register_tracepoints(void) |
867 | { | 865 | { |
868 | int ret; | 866 | int ret; |
869 | 867 | ||
@@ -901,7 +899,6 @@ static int blk_register_tracepoints(void) | |||
901 | WARN_ON(ret); | 899 | WARN_ON(ret); |
902 | ret = register_trace_block_remap(blk_add_trace_remap); | 900 | ret = register_trace_block_remap(blk_add_trace_remap); |
903 | WARN_ON(ret); | 901 | WARN_ON(ret); |
904 | return 0; | ||
905 | } | 902 | } |
906 | 903 | ||
907 | static void blk_unregister_tracepoints(void) | 904 | static void blk_unregister_tracepoints(void) |
@@ -934,25 +931,31 @@ static void blk_unregister_tracepoints(void) | |||
934 | static void fill_rwbs(char *rwbs, const struct blk_io_trace *t) | 931 | static void fill_rwbs(char *rwbs, const struct blk_io_trace *t) |
935 | { | 932 | { |
936 | int i = 0; | 933 | int i = 0; |
934 | int tc = t->action >> BLK_TC_SHIFT; | ||
935 | |||
936 | if (t->action == BLK_TN_MESSAGE) { | ||
937 | rwbs[i++] = 'N'; | ||
938 | goto out; | ||
939 | } | ||
937 | 940 | ||
938 | if (t->action & BLK_TC_DISCARD) | 941 | if (tc & BLK_TC_DISCARD) |
939 | rwbs[i++] = 'D'; | 942 | rwbs[i++] = 'D'; |
940 | else if (t->action & BLK_TC_WRITE) | 943 | else if (tc & BLK_TC_WRITE) |
941 | rwbs[i++] = 'W'; | 944 | rwbs[i++] = 'W'; |
942 | else if (t->bytes) | 945 | else if (t->bytes) |
943 | rwbs[i++] = 'R'; | 946 | rwbs[i++] = 'R'; |
944 | else | 947 | else |
945 | rwbs[i++] = 'N'; | 948 | rwbs[i++] = 'N'; |
946 | 949 | ||
947 | if (t->action & BLK_TC_AHEAD) | 950 | if (tc & BLK_TC_AHEAD) |
948 | rwbs[i++] = 'A'; | 951 | rwbs[i++] = 'A'; |
949 | if (t->action & BLK_TC_BARRIER) | 952 | if (tc & BLK_TC_BARRIER) |
950 | rwbs[i++] = 'B'; | 953 | rwbs[i++] = 'B'; |
951 | if (t->action & BLK_TC_SYNC) | 954 | if (tc & BLK_TC_SYNC) |
952 | rwbs[i++] = 'S'; | 955 | rwbs[i++] = 'S'; |
953 | if (t->action & BLK_TC_META) | 956 | if (tc & BLK_TC_META) |
954 | rwbs[i++] = 'M'; | 957 | rwbs[i++] = 'M'; |
955 | 958 | out: | |
956 | rwbs[i] = '\0'; | 959 | rwbs[i] = '\0'; |
957 | } | 960 | } |
958 | 961 | ||
@@ -979,7 +982,7 @@ static inline unsigned long long t_sector(const struct trace_entry *ent) | |||
979 | 982 | ||
980 | static inline __u16 t_error(const struct trace_entry *ent) | 983 | static inline __u16 t_error(const struct trace_entry *ent) |
981 | { | 984 | { |
982 | return te_blk_io_trace(ent)->sector; | 985 | return te_blk_io_trace(ent)->error; |
983 | } | 986 | } |
984 | 987 | ||
985 | static __u64 get_pdu_int(const struct trace_entry *ent) | 988 | static __u64 get_pdu_int(const struct trace_entry *ent) |
@@ -999,29 +1002,31 @@ static void get_pdu_remap(const struct trace_entry *ent, | |||
999 | r->sector = be64_to_cpu(sector); | 1002 | r->sector = be64_to_cpu(sector); |
1000 | } | 1003 | } |
1001 | 1004 | ||
1002 | static int blk_log_action_iter(struct trace_iterator *iter, const char *act) | 1005 | typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act); |
1006 | |||
1007 | static int blk_log_action_classic(struct trace_iterator *iter, const char *act) | ||
1003 | { | 1008 | { |
1004 | char rwbs[6]; | 1009 | char rwbs[6]; |
1005 | unsigned long long ts = ns2usecs(iter->ts); | 1010 | unsigned long long ts = iter->ts; |
1006 | unsigned long usec_rem = do_div(ts, USEC_PER_SEC); | 1011 | unsigned long nsec_rem = do_div(ts, NSEC_PER_SEC); |
1007 | unsigned secs = (unsigned long)ts; | 1012 | unsigned secs = (unsigned long)ts; |
1008 | const struct trace_entry *ent = iter->ent; | 1013 | const struct blk_io_trace *t = te_blk_io_trace(iter->ent); |
1009 | const struct blk_io_trace *t = (const struct blk_io_trace *)ent; | ||
1010 | 1014 | ||
1011 | fill_rwbs(rwbs, t); | 1015 | fill_rwbs(rwbs, t); |
1012 | 1016 | ||
1013 | return trace_seq_printf(&iter->seq, | 1017 | return trace_seq_printf(&iter->seq, |
1014 | "%3d,%-3d %2d %5d.%06lu %5u %2s %3s ", | 1018 | "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ", |
1015 | MAJOR(t->device), MINOR(t->device), iter->cpu, | 1019 | MAJOR(t->device), MINOR(t->device), iter->cpu, |
1016 | secs, usec_rem, ent->pid, act, rwbs); | 1020 | secs, nsec_rem, iter->ent->pid, act, rwbs); |
1017 | } | 1021 | } |
1018 | 1022 | ||
1019 | static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t, | 1023 | static int blk_log_action(struct trace_iterator *iter, const char *act) |
1020 | const char *act) | ||
1021 | { | 1024 | { |
1022 | char rwbs[6]; | 1025 | char rwbs[6]; |
1026 | const struct blk_io_trace *t = te_blk_io_trace(iter->ent); | ||
1027 | |||
1023 | fill_rwbs(rwbs, t); | 1028 | fill_rwbs(rwbs, t); |
1024 | return trace_seq_printf(s, "%3d,%-3d %2s %3s ", | 1029 | return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ", |
1025 | MAJOR(t->device), MINOR(t->device), act, rwbs); | 1030 | MAJOR(t->device), MINOR(t->device), act, rwbs); |
1026 | } | 1031 | } |
1027 | 1032 | ||
@@ -1085,6 +1090,17 @@ static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent) | |||
1085 | get_pdu_int(ent), cmd); | 1090 | get_pdu_int(ent), cmd); |
1086 | } | 1091 | } |
1087 | 1092 | ||
1093 | static int blk_log_msg(struct trace_seq *s, const struct trace_entry *ent) | ||
1094 | { | ||
1095 | int ret; | ||
1096 | const struct blk_io_trace *t = te_blk_io_trace(ent); | ||
1097 | |||
1098 | ret = trace_seq_putmem(s, t + 1, t->pdu_len); | ||
1099 | if (ret) | ||
1100 | return trace_seq_putc(s, '\n'); | ||
1101 | return ret; | ||
1102 | } | ||
1103 | |||
1088 | /* | 1104 | /* |
1089 | * struct tracer operations | 1105 | * struct tracer operations |
1090 | */ | 1106 | */ |
@@ -1099,11 +1115,7 @@ static void blk_tracer_print_header(struct seq_file *m) | |||
1099 | 1115 | ||
1100 | static void blk_tracer_start(struct trace_array *tr) | 1116 | static void blk_tracer_start(struct trace_array *tr) |
1101 | { | 1117 | { |
1102 | mutex_lock(&blk_probe_mutex); | 1118 | blk_tracer_enabled = true; |
1103 | if (atomic_add_return(1, &blk_probes_ref) == 1) | ||
1104 | if (blk_register_tracepoints()) | ||
1105 | atomic_dec(&blk_probes_ref); | ||
1106 | mutex_unlock(&blk_probe_mutex); | ||
1107 | trace_flags &= ~TRACE_ITER_CONTEXT_INFO; | 1119 | trace_flags &= ~TRACE_ITER_CONTEXT_INFO; |
1108 | } | 1120 | } |
1109 | 1121 | ||
@@ -1111,38 +1123,24 @@ static int blk_tracer_init(struct trace_array *tr) | |||
1111 | { | 1123 | { |
1112 | blk_tr = tr; | 1124 | blk_tr = tr; |
1113 | blk_tracer_start(tr); | 1125 | blk_tracer_start(tr); |
1114 | mutex_lock(&blk_probe_mutex); | ||
1115 | blk_tracer_enabled++; | ||
1116 | mutex_unlock(&blk_probe_mutex); | ||
1117 | return 0; | 1126 | return 0; |
1118 | } | 1127 | } |
1119 | 1128 | ||
1120 | static void blk_tracer_stop(struct trace_array *tr) | 1129 | static void blk_tracer_stop(struct trace_array *tr) |
1121 | { | 1130 | { |
1131 | blk_tracer_enabled = false; | ||
1122 | trace_flags |= TRACE_ITER_CONTEXT_INFO; | 1132 | trace_flags |= TRACE_ITER_CONTEXT_INFO; |
1123 | mutex_lock(&blk_probe_mutex); | ||
1124 | if (atomic_dec_and_test(&blk_probes_ref)) | ||
1125 | blk_unregister_tracepoints(); | ||
1126 | mutex_unlock(&blk_probe_mutex); | ||
1127 | } | 1133 | } |
1128 | 1134 | ||
1129 | static void blk_tracer_reset(struct trace_array *tr) | 1135 | static void blk_tracer_reset(struct trace_array *tr) |
1130 | { | 1136 | { |
1131 | if (!atomic_read(&blk_probes_ref)) | ||
1132 | return; | ||
1133 | |||
1134 | mutex_lock(&blk_probe_mutex); | ||
1135 | blk_tracer_enabled--; | ||
1136 | WARN_ON(blk_tracer_enabled < 0); | ||
1137 | mutex_unlock(&blk_probe_mutex); | ||
1138 | |||
1139 | blk_tracer_stop(tr); | 1137 | blk_tracer_stop(tr); |
1140 | } | 1138 | } |
1141 | 1139 | ||
1142 | static struct { | 1140 | static const struct { |
1143 | const char *act[2]; | 1141 | const char *act[2]; |
1144 | int (*print)(struct trace_seq *s, const struct trace_entry *ent); | 1142 | int (*print)(struct trace_seq *s, const struct trace_entry *ent); |
1145 | } what2act[] __read_mostly = { | 1143 | } what2act[] = { |
1146 | [__BLK_TA_QUEUE] = {{ "Q", "queue" }, blk_log_generic }, | 1144 | [__BLK_TA_QUEUE] = {{ "Q", "queue" }, blk_log_generic }, |
1147 | [__BLK_TA_BACKMERGE] = {{ "M", "backmerge" }, blk_log_generic }, | 1145 | [__BLK_TA_BACKMERGE] = {{ "M", "backmerge" }, blk_log_generic }, |
1148 | [__BLK_TA_FRONTMERGE] = {{ "F", "frontmerge" }, blk_log_generic }, | 1146 | [__BLK_TA_FRONTMERGE] = {{ "F", "frontmerge" }, blk_log_generic }, |
@@ -1160,29 +1158,48 @@ static struct { | |||
1160 | [__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap }, | 1158 | [__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap }, |
1161 | }; | 1159 | }; |
1162 | 1160 | ||
1163 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | 1161 | static enum print_line_t print_one_line(struct trace_iterator *iter, |
1164 | int flags) | 1162 | bool classic) |
1165 | { | 1163 | { |
1166 | struct trace_seq *s = &iter->seq; | 1164 | struct trace_seq *s = &iter->seq; |
1167 | const struct blk_io_trace *t = (struct blk_io_trace *)iter->ent; | 1165 | const struct blk_io_trace *t; |
1168 | const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1); | 1166 | u16 what; |
1169 | int ret; | 1167 | int ret; |
1168 | bool long_act; | ||
1169 | blk_log_action_t *log_action; | ||
1170 | 1170 | ||
1171 | if (!trace_print_context(iter)) | 1171 | t = te_blk_io_trace(iter->ent); |
1172 | return TRACE_TYPE_PARTIAL_LINE; | 1172 | what = t->action & ((1 << BLK_TC_SHIFT) - 1); |
1173 | long_act = !!(trace_flags & TRACE_ITER_VERBOSE); | ||
1174 | log_action = classic ? &blk_log_action_classic : &blk_log_action; | ||
1173 | 1175 | ||
1174 | if (unlikely(what == 0 || what > ARRAY_SIZE(what2act))) | 1176 | if (t->action == BLK_TN_MESSAGE) { |
1177 | ret = log_action(iter, long_act ? "message" : "m"); | ||
1178 | if (ret) | ||
1179 | ret = blk_log_msg(s, iter->ent); | ||
1180 | goto out; | ||
1181 | } | ||
1182 | |||
1183 | if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act))) | ||
1175 | ret = trace_seq_printf(s, "Bad pc action %x\n", what); | 1184 | ret = trace_seq_printf(s, "Bad pc action %x\n", what); |
1176 | else { | 1185 | else { |
1177 | const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE); | 1186 | ret = log_action(iter, what2act[what].act[long_act]); |
1178 | ret = blk_log_action_seq(s, t, what2act[what].act[long_act]); | ||
1179 | if (ret) | 1187 | if (ret) |
1180 | ret = what2act[what].print(s, iter->ent); | 1188 | ret = what2act[what].print(s, iter->ent); |
1181 | } | 1189 | } |
1182 | 1190 | out: | |
1183 | return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; | 1191 | return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; |
1184 | } | 1192 | } |
1185 | 1193 | ||
1194 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | ||
1195 | int flags) | ||
1196 | { | ||
1197 | if (!trace_print_context(iter)) | ||
1198 | return TRACE_TYPE_PARTIAL_LINE; | ||
1199 | |||
1200 | return print_one_line(iter, false); | ||
1201 | } | ||
1202 | |||
1186 | static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) | 1203 | static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) |
1187 | { | 1204 | { |
1188 | struct trace_seq *s = &iter->seq; | 1205 | struct trace_seq *s = &iter->seq; |
@@ -1190,7 +1207,7 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) | |||
1190 | const int offset = offsetof(struct blk_io_trace, sector); | 1207 | const int offset = offsetof(struct blk_io_trace, sector); |
1191 | struct blk_io_trace old = { | 1208 | struct blk_io_trace old = { |
1192 | .magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION, | 1209 | .magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION, |
1193 | .time = ns2usecs(iter->ts), | 1210 | .time = iter->ts, |
1194 | }; | 1211 | }; |
1195 | 1212 | ||
1196 | if (!trace_seq_putmem(s, &old, offset)) | 1213 | if (!trace_seq_putmem(s, &old, offset)) |
@@ -1208,26 +1225,10 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags) | |||
1208 | 1225 | ||
1209 | static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter) | 1226 | static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter) |
1210 | { | 1227 | { |
1211 | const struct blk_io_trace *t; | ||
1212 | u16 what; | ||
1213 | int ret; | ||
1214 | |||
1215 | if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC)) | 1228 | if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC)) |
1216 | return TRACE_TYPE_UNHANDLED; | 1229 | return TRACE_TYPE_UNHANDLED; |
1217 | 1230 | ||
1218 | t = (const struct blk_io_trace *)iter->ent; | 1231 | return print_one_line(iter, true); |
1219 | what = t->action & ((1 << BLK_TC_SHIFT) - 1); | ||
1220 | |||
1221 | if (unlikely(what == 0 || what > ARRAY_SIZE(what2act))) | ||
1222 | ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what); | ||
1223 | else { | ||
1224 | const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE); | ||
1225 | ret = blk_log_action_iter(iter, what2act[what].act[long_act]); | ||
1226 | if (ret) | ||
1227 | ret = what2act[what].print(&iter->seq, iter->ent); | ||
1228 | } | ||
1229 | |||
1230 | return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; | ||
1231 | } | 1232 | } |
1232 | 1233 | ||
1233 | static struct tracer blk_tracer __read_mostly = { | 1234 | static struct tracer blk_tracer __read_mostly = { |
@@ -1273,7 +1274,10 @@ static int blk_trace_remove_queue(struct request_queue *q) | |||
1273 | if (bt == NULL) | 1274 | if (bt == NULL) |
1274 | return -EINVAL; | 1275 | return -EINVAL; |
1275 | 1276 | ||
1276 | kfree(bt); | 1277 | if (atomic_dec_and_test(&blk_probes_ref)) |
1278 | blk_unregister_tracepoints(); | ||
1279 | |||
1280 | blk_trace_free(bt); | ||
1277 | return 0; | 1281 | return 0; |
1278 | } | 1282 | } |
1279 | 1283 | ||
@@ -1283,26 +1287,33 @@ static int blk_trace_remove_queue(struct request_queue *q) | |||
1283 | static int blk_trace_setup_queue(struct request_queue *q, dev_t dev) | 1287 | static int blk_trace_setup_queue(struct request_queue *q, dev_t dev) |
1284 | { | 1288 | { |
1285 | struct blk_trace *old_bt, *bt = NULL; | 1289 | struct blk_trace *old_bt, *bt = NULL; |
1286 | int ret; | 1290 | int ret = -ENOMEM; |
1287 | 1291 | ||
1288 | ret = -ENOMEM; | ||
1289 | bt = kzalloc(sizeof(*bt), GFP_KERNEL); | 1292 | bt = kzalloc(sizeof(*bt), GFP_KERNEL); |
1290 | if (!bt) | 1293 | if (!bt) |
1291 | goto err; | 1294 | return -ENOMEM; |
1295 | |||
1296 | bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char)); | ||
1297 | if (!bt->msg_data) | ||
1298 | goto free_bt; | ||
1292 | 1299 | ||
1293 | bt->dev = dev; | 1300 | bt->dev = dev; |
1294 | bt->act_mask = (u16)-1; | 1301 | bt->act_mask = (u16)-1; |
1295 | bt->end_lba = -1ULL; | 1302 | bt->end_lba = -1ULL; |
1296 | bt->trace_state = Blktrace_running; | ||
1297 | 1303 | ||
1298 | old_bt = xchg(&q->blk_trace, bt); | 1304 | old_bt = xchg(&q->blk_trace, bt); |
1299 | if (old_bt != NULL) { | 1305 | if (old_bt != NULL) { |
1300 | (void)xchg(&q->blk_trace, old_bt); | 1306 | (void)xchg(&q->blk_trace, old_bt); |
1301 | kfree(bt); | ||
1302 | ret = -EBUSY; | 1307 | ret = -EBUSY; |
1308 | goto free_bt; | ||
1303 | } | 1309 | } |
1310 | |||
1311 | if (atomic_inc_return(&blk_probes_ref) == 1) | ||
1312 | blk_register_tracepoints(); | ||
1304 | return 0; | 1313 | return 0; |
1305 | err: | 1314 | |
1315 | free_bt: | ||
1316 | blk_trace_free(bt); | ||
1306 | return ret; | 1317 | return ret; |
1307 | } | 1318 | } |
1308 | 1319 | ||
@@ -1310,72 +1321,6 @@ err: | |||
1310 | * sysfs interface to enable and configure tracing | 1321 | * sysfs interface to enable and configure tracing |
1311 | */ | 1322 | */ |
1312 | 1323 | ||
1313 | static ssize_t sysfs_blk_trace_enable_show(struct device *dev, | ||
1314 | struct device_attribute *attr, | ||
1315 | char *buf) | ||
1316 | { | ||
1317 | struct hd_struct *p = dev_to_part(dev); | ||
1318 | struct block_device *bdev; | ||
1319 | ssize_t ret = -ENXIO; | ||
1320 | |||
1321 | lock_kernel(); | ||
1322 | bdev = bdget(part_devt(p)); | ||
1323 | if (bdev != NULL) { | ||
1324 | struct request_queue *q = bdev_get_queue(bdev); | ||
1325 | |||
1326 | if (q != NULL) { | ||
1327 | mutex_lock(&bdev->bd_mutex); | ||
1328 | ret = sprintf(buf, "%u\n", !!q->blk_trace); | ||
1329 | mutex_unlock(&bdev->bd_mutex); | ||
1330 | } | ||
1331 | |||
1332 | bdput(bdev); | ||
1333 | } | ||
1334 | |||
1335 | unlock_kernel(); | ||
1336 | return ret; | ||
1337 | } | ||
1338 | |||
1339 | static ssize_t sysfs_blk_trace_enable_store(struct device *dev, | ||
1340 | struct device_attribute *attr, | ||
1341 | const char *buf, size_t count) | ||
1342 | { | ||
1343 | struct block_device *bdev; | ||
1344 | struct request_queue *q; | ||
1345 | struct hd_struct *p; | ||
1346 | int value; | ||
1347 | ssize_t ret = -ENXIO; | ||
1348 | |||
1349 | if (count == 0 || sscanf(buf, "%d", &value) != 1) | ||
1350 | goto out; | ||
1351 | |||
1352 | lock_kernel(); | ||
1353 | p = dev_to_part(dev); | ||
1354 | bdev = bdget(part_devt(p)); | ||
1355 | if (bdev == NULL) | ||
1356 | goto out_unlock_kernel; | ||
1357 | |||
1358 | q = bdev_get_queue(bdev); | ||
1359 | if (q == NULL) | ||
1360 | goto out_bdput; | ||
1361 | |||
1362 | mutex_lock(&bdev->bd_mutex); | ||
1363 | if (value) | ||
1364 | ret = blk_trace_setup_queue(q, bdev->bd_dev); | ||
1365 | else | ||
1366 | ret = blk_trace_remove_queue(q); | ||
1367 | mutex_unlock(&bdev->bd_mutex); | ||
1368 | |||
1369 | if (ret == 0) | ||
1370 | ret = count; | ||
1371 | out_bdput: | ||
1372 | bdput(bdev); | ||
1373 | out_unlock_kernel: | ||
1374 | unlock_kernel(); | ||
1375 | out: | ||
1376 | return ret; | ||
1377 | } | ||
1378 | |||
1379 | static ssize_t sysfs_blk_trace_attr_show(struct device *dev, | 1324 | static ssize_t sysfs_blk_trace_attr_show(struct device *dev, |
1380 | struct device_attribute *attr, | 1325 | struct device_attribute *attr, |
1381 | char *buf); | 1326 | char *buf); |
@@ -1387,8 +1332,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1387 | sysfs_blk_trace_attr_show, \ | 1332 | sysfs_blk_trace_attr_show, \ |
1388 | sysfs_blk_trace_attr_store) | 1333 | sysfs_blk_trace_attr_store) |
1389 | 1334 | ||
1390 | static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, | 1335 | static BLK_TRACE_DEVICE_ATTR(enable); |
1391 | sysfs_blk_trace_enable_show, sysfs_blk_trace_enable_store); | ||
1392 | static BLK_TRACE_DEVICE_ATTR(act_mask); | 1336 | static BLK_TRACE_DEVICE_ATTR(act_mask); |
1393 | static BLK_TRACE_DEVICE_ATTR(pid); | 1337 | static BLK_TRACE_DEVICE_ATTR(pid); |
1394 | static BLK_TRACE_DEVICE_ATTR(start_lba); | 1338 | static BLK_TRACE_DEVICE_ATTR(start_lba); |
@@ -1408,53 +1352,85 @@ struct attribute_group blk_trace_attr_group = { | |||
1408 | .attrs = blk_trace_attrs, | 1352 | .attrs = blk_trace_attrs, |
1409 | }; | 1353 | }; |
1410 | 1354 | ||
1411 | static int blk_str2act_mask(const char *str) | 1355 | static const struct { |
1356 | int mask; | ||
1357 | const char *str; | ||
1358 | } mask_maps[] = { | ||
1359 | { BLK_TC_READ, "read" }, | ||
1360 | { BLK_TC_WRITE, "write" }, | ||
1361 | { BLK_TC_BARRIER, "barrier" }, | ||
1362 | { BLK_TC_SYNC, "sync" }, | ||
1363 | { BLK_TC_QUEUE, "queue" }, | ||
1364 | { BLK_TC_REQUEUE, "requeue" }, | ||
1365 | { BLK_TC_ISSUE, "issue" }, | ||
1366 | { BLK_TC_COMPLETE, "complete" }, | ||
1367 | { BLK_TC_FS, "fs" }, | ||
1368 | { BLK_TC_PC, "pc" }, | ||
1369 | { BLK_TC_AHEAD, "ahead" }, | ||
1370 | { BLK_TC_META, "meta" }, | ||
1371 | { BLK_TC_DISCARD, "discard" }, | ||
1372 | { BLK_TC_DRV_DATA, "drv_data" }, | ||
1373 | }; | ||
1374 | |||
1375 | static int blk_trace_str2mask(const char *str) | ||
1412 | { | 1376 | { |
1377 | int i; | ||
1413 | int mask = 0; | 1378 | int mask = 0; |
1414 | char *copy = kstrdup(str, GFP_KERNEL), *s; | 1379 | char *s, *token; |
1415 | 1380 | ||
1416 | if (copy == NULL) | 1381 | s = kstrdup(str, GFP_KERNEL); |
1382 | if (s == NULL) | ||
1417 | return -ENOMEM; | 1383 | return -ENOMEM; |
1418 | 1384 | s = strstrip(s); | |
1419 | s = strstrip(copy); | ||
1420 | 1385 | ||
1421 | while (1) { | 1386 | while (1) { |
1422 | char *sep = strchr(s, ','); | 1387 | token = strsep(&s, ","); |
1423 | 1388 | if (token == NULL) | |
1424 | if (sep != NULL) | ||
1425 | *sep = '\0'; | ||
1426 | |||
1427 | if (strcasecmp(s, "barrier") == 0) | ||
1428 | mask |= BLK_TC_BARRIER; | ||
1429 | else if (strcasecmp(s, "complete") == 0) | ||
1430 | mask |= BLK_TC_COMPLETE; | ||
1431 | else if (strcasecmp(s, "fs") == 0) | ||
1432 | mask |= BLK_TC_FS; | ||
1433 | else if (strcasecmp(s, "issue") == 0) | ||
1434 | mask |= BLK_TC_ISSUE; | ||
1435 | else if (strcasecmp(s, "pc") == 0) | ||
1436 | mask |= BLK_TC_PC; | ||
1437 | else if (strcasecmp(s, "queue") == 0) | ||
1438 | mask |= BLK_TC_QUEUE; | ||
1439 | else if (strcasecmp(s, "read") == 0) | ||
1440 | mask |= BLK_TC_READ; | ||
1441 | else if (strcasecmp(s, "requeue") == 0) | ||
1442 | mask |= BLK_TC_REQUEUE; | ||
1443 | else if (strcasecmp(s, "sync") == 0) | ||
1444 | mask |= BLK_TC_SYNC; | ||
1445 | else if (strcasecmp(s, "write") == 0) | ||
1446 | mask |= BLK_TC_WRITE; | ||
1447 | |||
1448 | if (sep == NULL) | ||
1449 | break; | 1389 | break; |
1450 | 1390 | ||
1451 | s = sep + 1; | 1391 | if (*token == '\0') |
1392 | continue; | ||
1393 | |||
1394 | for (i = 0; i < ARRAY_SIZE(mask_maps); i++) { | ||
1395 | if (strcasecmp(token, mask_maps[i].str) == 0) { | ||
1396 | mask |= mask_maps[i].mask; | ||
1397 | break; | ||
1398 | } | ||
1399 | } | ||
1400 | if (i == ARRAY_SIZE(mask_maps)) { | ||
1401 | mask = -EINVAL; | ||
1402 | break; | ||
1403 | } | ||
1452 | } | 1404 | } |
1453 | kfree(copy); | 1405 | kfree(s); |
1454 | 1406 | ||
1455 | return mask; | 1407 | return mask; |
1456 | } | 1408 | } |
1457 | 1409 | ||
1410 | static ssize_t blk_trace_mask2str(char *buf, int mask) | ||
1411 | { | ||
1412 | int i; | ||
1413 | char *p = buf; | ||
1414 | |||
1415 | for (i = 0; i < ARRAY_SIZE(mask_maps); i++) { | ||
1416 | if (mask & mask_maps[i].mask) { | ||
1417 | p += sprintf(p, "%s%s", | ||
1418 | (p == buf) ? "" : ",", mask_maps[i].str); | ||
1419 | } | ||
1420 | } | ||
1421 | *p++ = '\n'; | ||
1422 | |||
1423 | return p - buf; | ||
1424 | } | ||
1425 | |||
1426 | static struct request_queue *blk_trace_get_queue(struct block_device *bdev) | ||
1427 | { | ||
1428 | if (bdev->bd_disk == NULL) | ||
1429 | return NULL; | ||
1430 | |||
1431 | return bdev_get_queue(bdev); | ||
1432 | } | ||
1433 | |||
1458 | static ssize_t sysfs_blk_trace_attr_show(struct device *dev, | 1434 | static ssize_t sysfs_blk_trace_attr_show(struct device *dev, |
1459 | struct device_attribute *attr, | 1435 | struct device_attribute *attr, |
1460 | char *buf) | 1436 | char *buf) |
@@ -1469,20 +1445,29 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev, | |||
1469 | if (bdev == NULL) | 1445 | if (bdev == NULL) |
1470 | goto out_unlock_kernel; | 1446 | goto out_unlock_kernel; |
1471 | 1447 | ||
1472 | q = bdev_get_queue(bdev); | 1448 | q = blk_trace_get_queue(bdev); |
1473 | if (q == NULL) | 1449 | if (q == NULL) |
1474 | goto out_bdput; | 1450 | goto out_bdput; |
1451 | |||
1475 | mutex_lock(&bdev->bd_mutex); | 1452 | mutex_lock(&bdev->bd_mutex); |
1453 | |||
1454 | if (attr == &dev_attr_enable) { | ||
1455 | ret = sprintf(buf, "%u\n", !!q->blk_trace); | ||
1456 | goto out_unlock_bdev; | ||
1457 | } | ||
1458 | |||
1476 | if (q->blk_trace == NULL) | 1459 | if (q->blk_trace == NULL) |
1477 | ret = sprintf(buf, "disabled\n"); | 1460 | ret = sprintf(buf, "disabled\n"); |
1478 | else if (attr == &dev_attr_act_mask) | 1461 | else if (attr == &dev_attr_act_mask) |
1479 | ret = sprintf(buf, "%#x\n", q->blk_trace->act_mask); | 1462 | ret = blk_trace_mask2str(buf, q->blk_trace->act_mask); |
1480 | else if (attr == &dev_attr_pid) | 1463 | else if (attr == &dev_attr_pid) |
1481 | ret = sprintf(buf, "%u\n", q->blk_trace->pid); | 1464 | ret = sprintf(buf, "%u\n", q->blk_trace->pid); |
1482 | else if (attr == &dev_attr_start_lba) | 1465 | else if (attr == &dev_attr_start_lba) |
1483 | ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba); | 1466 | ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba); |
1484 | else if (attr == &dev_attr_end_lba) | 1467 | else if (attr == &dev_attr_end_lba) |
1485 | ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba); | 1468 | ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba); |
1469 | |||
1470 | out_unlock_bdev: | ||
1486 | mutex_unlock(&bdev->bd_mutex); | 1471 | mutex_unlock(&bdev->bd_mutex); |
1487 | out_bdput: | 1472 | out_bdput: |
1488 | bdput(bdev); | 1473 | bdput(bdev); |
@@ -1499,7 +1484,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1499 | struct request_queue *q; | 1484 | struct request_queue *q; |
1500 | struct hd_struct *p; | 1485 | struct hd_struct *p; |
1501 | u64 value; | 1486 | u64 value; |
1502 | ssize_t ret = -ENXIO; | 1487 | ssize_t ret = -EINVAL; |
1503 | 1488 | ||
1504 | if (count == 0) | 1489 | if (count == 0) |
1505 | goto out; | 1490 | goto out; |
@@ -1507,24 +1492,36 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1507 | if (attr == &dev_attr_act_mask) { | 1492 | if (attr == &dev_attr_act_mask) { |
1508 | if (sscanf(buf, "%llx", &value) != 1) { | 1493 | if (sscanf(buf, "%llx", &value) != 1) { |
1509 | /* Assume it is a list of trace category names */ | 1494 | /* Assume it is a list of trace category names */ |
1510 | value = blk_str2act_mask(buf); | 1495 | ret = blk_trace_str2mask(buf); |
1511 | if (value < 0) | 1496 | if (ret < 0) |
1512 | goto out; | 1497 | goto out; |
1498 | value = ret; | ||
1513 | } | 1499 | } |
1514 | } else if (sscanf(buf, "%llu", &value) != 1) | 1500 | } else if (sscanf(buf, "%llu", &value) != 1) |
1515 | goto out; | 1501 | goto out; |
1516 | 1502 | ||
1503 | ret = -ENXIO; | ||
1504 | |||
1517 | lock_kernel(); | 1505 | lock_kernel(); |
1518 | p = dev_to_part(dev); | 1506 | p = dev_to_part(dev); |
1519 | bdev = bdget(part_devt(p)); | 1507 | bdev = bdget(part_devt(p)); |
1520 | if (bdev == NULL) | 1508 | if (bdev == NULL) |
1521 | goto out_unlock_kernel; | 1509 | goto out_unlock_kernel; |
1522 | 1510 | ||
1523 | q = bdev_get_queue(bdev); | 1511 | q = blk_trace_get_queue(bdev); |
1524 | if (q == NULL) | 1512 | if (q == NULL) |
1525 | goto out_bdput; | 1513 | goto out_bdput; |
1526 | 1514 | ||
1527 | mutex_lock(&bdev->bd_mutex); | 1515 | mutex_lock(&bdev->bd_mutex); |
1516 | |||
1517 | if (attr == &dev_attr_enable) { | ||
1518 | if (value) | ||
1519 | ret = blk_trace_setup_queue(q, bdev->bd_dev); | ||
1520 | else | ||
1521 | ret = blk_trace_remove_queue(q); | ||
1522 | goto out_unlock_bdev; | ||
1523 | } | ||
1524 | |||
1528 | ret = 0; | 1525 | ret = 0; |
1529 | if (q->blk_trace == NULL) | 1526 | if (q->blk_trace == NULL) |
1530 | ret = blk_trace_setup_queue(q, bdev->bd_dev); | 1527 | ret = blk_trace_setup_queue(q, bdev->bd_dev); |
@@ -1538,13 +1535,15 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1538 | q->blk_trace->start_lba = value; | 1535 | q->blk_trace->start_lba = value; |
1539 | else if (attr == &dev_attr_end_lba) | 1536 | else if (attr == &dev_attr_end_lba) |
1540 | q->blk_trace->end_lba = value; | 1537 | q->blk_trace->end_lba = value; |
1541 | ret = count; | ||
1542 | } | 1538 | } |
1539 | |||
1540 | out_unlock_bdev: | ||
1543 | mutex_unlock(&bdev->bd_mutex); | 1541 | mutex_unlock(&bdev->bd_mutex); |
1544 | out_bdput: | 1542 | out_bdput: |
1545 | bdput(bdev); | 1543 | bdput(bdev); |
1546 | out_unlock_kernel: | 1544 | out_unlock_kernel: |
1547 | unlock_kernel(); | 1545 | unlock_kernel(); |
1548 | out: | 1546 | out: |
1549 | return ret; | 1547 | return ret ? ret : count; |
1550 | } | 1548 | } |
1549 | |||