Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

blktrace: factor out recording a blktrace event

Factor out the recording of a blktrace event into its own function,
deduplicating the code.

This also enables recording different versions of the blktrace protocol
later on.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Johannes Thumshirn and committed by
Jens Axboe
472eca53 a65988a0

+47 -38
+47 -38
kernel/trace/blktrace.c
··· 63 63 static void blk_register_tracepoints(void); 64 64 static void blk_unregister_tracepoints(void); 65 65 66 + static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu, 67 + sector_t sector, int bytes, u32 what, 68 + dev_t dev, int error, u64 cgid, 69 + ssize_t cgid_len, void *pdu_data, int pdu_len) 70 + 71 + { 72 + /* 73 + * These two are not needed in ftrace as they are in the 74 + * generic trace_entry, filled by tracing_generic_entry_update, 75 + * but for the trace_event->bin() synthesizer benefit we do it 76 + * here too. 77 + */ 78 + t->cpu = cpu; 79 + t->pid = pid; 80 + 81 + t->sector = sector; 82 + t->bytes = bytes; 83 + t->action = what; 84 + t->device = dev; 85 + t->error = error; 86 + t->pdu_len = pdu_len + cgid_len; 87 + 88 + if (cgid_len) 89 + memcpy((void *)t + sizeof(*t), &cgid, cgid_len); 90 + if (pdu_len) 91 + memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len); 92 + } 93 + 66 94 /* 67 95 * Send out a notify message. 68 96 */ ··· 115 87 if (!event) 116 88 return; 117 89 t = ring_buffer_event_data(event); 118 - goto record_it; 90 + record_blktrace_event(t, pid, cpu, 0, 0, 91 + action | (cgid ? __BLK_TN_CGROUP : 0), 92 + bt->dev, 0, cgid, cgid_len, (void *)data, 93 + len); 94 + trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); 95 + return; 119 96 } 120 97 121 98 if (!bt->rchan) ··· 130 97 if (t) { 131 98 t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; 132 99 t->time = ktime_to_ns(ktime_get()); 133 - record_it: 134 - t->device = bt->dev; 135 - t->action = action | (cgid ? __BLK_TN_CGROUP : 0); 136 - t->pid = pid; 137 - t->cpu = cpu; 138 - t->pdu_len = len + cgid_len; 139 - if (cgid_len) 140 - memcpy((void *)t + sizeof(*t), &cgid, cgid_len); 141 - memcpy((void *) t + sizeof(*t) + cgid_len, data, len); 142 100 143 - if (blk_tracer) 144 - trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); 101 + record_blktrace_event(t, pid, cpu, 0, 0, 102 + action | (cgid ? __BLK_TN_CGROUP : 0), 103 + bt->dev, 0, cgid, cgid_len, (void *)data, 104 + len); 145 105 } 146 106 } 147 107 ··· 289 263 if (!event) 290 264 return; 291 265 t = ring_buffer_event_data(event); 292 - goto record_it; 266 + 267 + record_blktrace_event(t, pid, cpu, sector, bytes, what, bt->dev, 268 + error, cgid, cgid_len, pdu_data, pdu_len); 269 + 270 + trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); 271 + return; 293 272 } 294 273 295 274 if (unlikely(tsk->btrace_seq != blktrace_seq)) ··· 313 282 t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; 314 283 t->sequence = ++(*sequence); 315 284 t->time = ktime_to_ns(ktime_get()); 316 - record_it: 317 - /* 318 - * These two are not needed in ftrace as they are in the 319 - * generic trace_entry, filled by tracing_generic_entry_update, 320 - * but for the trace_event->bin() synthesizer benefit we do it 321 - * here too. 322 - */ 323 - t->cpu = cpu; 324 - t->pid = pid; 325 285 326 - t->sector = sector; 327 - t->bytes = bytes; 328 - t->action = what; 329 - t->device = bt->dev; 330 - t->error = error; 331 - t->pdu_len = pdu_len + cgid_len; 332 - 333 - if (cgid_len) 334 - memcpy((void *)t + sizeof(*t), &cgid, cgid_len); 335 - if (pdu_len) 336 - memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len); 337 - 338 - if (blk_tracer) { 339 - trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); 340 - return; 341 - } 286 + record_blktrace_event(t, pid, cpu, sector, bytes, what, 287 + bt->dev, error, cgid, cgid_len, 288 + pdu_data, pdu_len); 342 289 } 343 290 344 291 local_irq_restore(flags);