aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/blktrace.c
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2014-11-12 11:35:48 -0500
committerSteven Rostedt <rostedt@goodmis.org>2014-11-19 15:25:39 -0500
commitf4a1d08ce65d7156504f2f0eac26f47dfc9120e6 (patch)
treea346ee16752fcbb8a8c97ab7a980a0ea80cc15c6 /kernel/trace/blktrace.c
parent19a7fe206232cc875a3083211e0a21c08edd756e (diff)
blktrace/tracing: Use trace_seq_has_overflowed() helper function
Checking the return code of every trace_seq_printf() operation and having to return early if it overflowed makes the code messy. Using the new trace_seq_has_overflowed() and trace_handle_return() functions allows us to clean up the code. In the future, trace_seq_printf() and friends will be turning into void functions and not returning a value. The trace_seq_has_overflowed() is to be used instead. This cleanup allows that change to take place. Cc: Jens Axboe <axboe@fb.com> Reviewed-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/blktrace.c')
-rw-r--r--kernel/trace/blktrace.c148
1 files changed, 66 insertions, 82 deletions
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c1bd4ada2a04..11b9cb36092b 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -1142,9 +1142,9 @@ static void get_pdu_remap(const struct trace_entry *ent,
1142 r->sector_from = be64_to_cpu(sector_from); 1142 r->sector_from = be64_to_cpu(sector_from);
1143} 1143}
1144 1144
1145typedef int (blk_log_action_t) (struct trace_iterator *iter, const char *act); 1145typedef void (blk_log_action_t) (struct trace_iterator *iter, const char *act);
1146 1146
1147static int blk_log_action_classic(struct trace_iterator *iter, const char *act) 1147static void blk_log_action_classic(struct trace_iterator *iter, const char *act)
1148{ 1148{
1149 char rwbs[RWBS_LEN]; 1149 char rwbs[RWBS_LEN];
1150 unsigned long long ts = iter->ts; 1150 unsigned long long ts = iter->ts;
@@ -1154,33 +1154,33 @@ static int blk_log_action_classic(struct trace_iterator *iter, const char *act)
1154 1154
1155 fill_rwbs(rwbs, t); 1155 fill_rwbs(rwbs, t);
1156 1156
1157 return trace_seq_printf(&iter->seq, 1157 trace_seq_printf(&iter->seq,
1158 "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ", 1158 "%3d,%-3d %2d %5d.%09lu %5u %2s %3s ",
1159 MAJOR(t->device), MINOR(t->device), iter->cpu, 1159 MAJOR(t->device), MINOR(t->device), iter->cpu,
1160 secs, nsec_rem, iter->ent->pid, act, rwbs); 1160 secs, nsec_rem, iter->ent->pid, act, rwbs);
1161} 1161}
1162 1162
1163static int blk_log_action(struct trace_iterator *iter, const char *act) 1163static void blk_log_action(struct trace_iterator *iter, const char *act)
1164{ 1164{
1165 char rwbs[RWBS_LEN]; 1165 char rwbs[RWBS_LEN];
1166 const struct blk_io_trace *t = te_blk_io_trace(iter->ent); 1166 const struct blk_io_trace *t = te_blk_io_trace(iter->ent);
1167 1167
1168 fill_rwbs(rwbs, t); 1168 fill_rwbs(rwbs, t);
1169 return trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ", 1169 trace_seq_printf(&iter->seq, "%3d,%-3d %2s %3s ",
1170 MAJOR(t->device), MINOR(t->device), act, rwbs); 1170 MAJOR(t->device), MINOR(t->device), act, rwbs);
1171} 1171}
1172 1172
1173static int blk_log_dump_pdu(struct trace_seq *s, const struct trace_entry *ent) 1173static void blk_log_dump_pdu(struct trace_seq *s, const struct trace_entry *ent)
1174{ 1174{
1175 const unsigned char *pdu_buf; 1175 const unsigned char *pdu_buf;
1176 int pdu_len; 1176 int pdu_len;
1177 int i, end, ret; 1177 int i, end;
1178 1178
1179 pdu_buf = pdu_start(ent); 1179 pdu_buf = pdu_start(ent);
1180 pdu_len = te_blk_io_trace(ent)->pdu_len; 1180 pdu_len = te_blk_io_trace(ent)->pdu_len;
1181 1181
1182 if (!pdu_len) 1182 if (!pdu_len)
1183 return 1; 1183 return;
1184 1184
1185 /* find the last zero that needs to be printed */ 1185 /* find the last zero that needs to be printed */
1186 for (end = pdu_len - 1; end >= 0; end--) 1186 for (end = pdu_len - 1; end >= 0; end--)
@@ -1188,119 +1188,107 @@ static int blk_log_dump_pdu(struct trace_seq *s, const struct trace_entry *ent)
1188 break; 1188 break;
1189 end++; 1189 end++;
1190 1190
1191 if (!trace_seq_putc(s, '(')) 1191 trace_seq_putc(s, '(');
1192 return 0;
1193 1192
1194 for (i = 0; i < pdu_len; i++) { 1193 for (i = 0; i < pdu_len; i++) {
1195 1194
1196 ret = trace_seq_printf(s, "%s%02x", 1195 trace_seq_printf(s, "%s%02x",
1197 i == 0 ? "" : " ", pdu_buf[i]); 1196 i == 0 ? "" : " ", pdu_buf[i]);
1198 if (!ret)
1199 return ret;
1200 1197
1201 /* 1198 /*
1202 * stop when the rest is just zeroes and indicate so 1199 * stop when the rest is just zeroes and indicate so
1203 * with a ".." appended 1200 * with a ".." appended
1204 */ 1201 */
1205 if (i == end && end != pdu_len - 1) 1202 if (i == end && end != pdu_len - 1) {
1206 return trace_seq_puts(s, " ..) "); 1203 trace_seq_puts(s, " ..) ");
1204 return;
1205 }
1207 } 1206 }
1208 1207
1209 return trace_seq_puts(s, ") "); 1208 trace_seq_puts(s, ") ");
1210} 1209}
1211 1210
1212static int blk_log_generic(struct trace_seq *s, const struct trace_entry *ent) 1211static void blk_log_generic(struct trace_seq *s, const struct trace_entry *ent)
1213{ 1212{
1214 char cmd[TASK_COMM_LEN]; 1213 char cmd[TASK_COMM_LEN];
1215 1214
1216 trace_find_cmdline(ent->pid, cmd); 1215 trace_find_cmdline(ent->pid, cmd);
1217 1216
1218 if (t_action(ent) & BLK_TC_ACT(BLK_TC_PC)) { 1217 if (t_action(ent) & BLK_TC_ACT(BLK_TC_PC)) {
1219 int ret; 1218 trace_seq_printf(s, "%u ", t_bytes(ent));
1220 1219 blk_log_dump_pdu(s, ent);
1221 ret = trace_seq_printf(s, "%u ", t_bytes(ent)); 1220 trace_seq_printf(s, "[%s]\n", cmd);
1222 if (!ret)
1223 return 0;
1224 ret = blk_log_dump_pdu(s, ent);
1225 if (!ret)
1226 return 0;
1227 return trace_seq_printf(s, "[%s]\n", cmd);
1228 } else { 1221 } else {
1229 if (t_sec(ent)) 1222 if (t_sec(ent))
1230 return trace_seq_printf(s, "%llu + %u [%s]\n", 1223 trace_seq_printf(s, "%llu + %u [%s]\n",
1231 t_sector(ent), t_sec(ent), cmd); 1224 t_sector(ent), t_sec(ent), cmd);
1232 return trace_seq_printf(s, "[%s]\n", cmd); 1225 else
1226 trace_seq_printf(s, "[%s]\n", cmd);
1233 } 1227 }
1234} 1228}
1235 1229
1236static int blk_log_with_error(struct trace_seq *s, 1230static void blk_log_with_error(struct trace_seq *s,
1237 const struct trace_entry *ent) 1231 const struct trace_entry *ent)
1238{ 1232{
1239 if (t_action(ent) & BLK_TC_ACT(BLK_TC_PC)) { 1233 if (t_action(ent) & BLK_TC_ACT(BLK_TC_PC)) {
1240 int ret; 1234 blk_log_dump_pdu(s, ent);
1241 1235 trace_seq_printf(s, "[%d]\n", t_error(ent));
1242 ret = blk_log_dump_pdu(s, ent);
1243 if (ret)
1244 return trace_seq_printf(s, "[%d]\n", t_error(ent));
1245 return 0;
1246 } else { 1236 } else {
1247 if (t_sec(ent)) 1237 if (t_sec(ent))
1248 return trace_seq_printf(s, "%llu + %u [%d]\n", 1238 trace_seq_printf(s, "%llu + %u [%d]\n",
1249 t_sector(ent), 1239 t_sector(ent),
1250 t_sec(ent), t_error(ent)); 1240 t_sec(ent), t_error(ent));
1251 return trace_seq_printf(s, "%llu [%d]\n", 1241 else
1252 t_sector(ent), t_error(ent)); 1242 trace_seq_printf(s, "%llu [%d]\n",
1243 t_sector(ent), t_error(ent));
1253 } 1244 }
1254} 1245}
1255 1246
1256static int blk_log_remap(struct trace_seq *s, const struct trace_entry *ent) 1247static void blk_log_remap(struct trace_seq *s, const struct trace_entry *ent)
1257{ 1248{
1258 struct blk_io_trace_remap r = { .device_from = 0, }; 1249 struct blk_io_trace_remap r = { .device_from = 0, };
1259 1250
1260 get_pdu_remap(ent, &r); 1251 get_pdu_remap(ent, &r);
1261 return trace_seq_printf(s, "%llu + %u <- (%d,%d) %llu\n", 1252 trace_seq_printf(s, "%llu + %u <- (%d,%d) %llu\n",
1262 t_sector(ent), t_sec(ent), 1253 t_sector(ent), t_sec(ent),
1263 MAJOR(r.device_from), MINOR(r.device_from), 1254 MAJOR(r.device_from), MINOR(r.device_from),
1264 (unsigned long long)r.sector_from); 1255 (unsigned long long)r.sector_from);
1265} 1256}
1266 1257
1267static int blk_log_plug(struct trace_seq *s, const struct trace_entry *ent) 1258static void blk_log_plug(struct trace_seq *s, const struct trace_entry *ent)
1268{ 1259{
1269 char cmd[TASK_COMM_LEN]; 1260 char cmd[TASK_COMM_LEN];
1270 1261
1271 trace_find_cmdline(ent->pid, cmd); 1262 trace_find_cmdline(ent->pid, cmd);
1272 1263
1273 return trace_seq_printf(s, "[%s]\n", cmd); 1264 trace_seq_printf(s, "[%s]\n", cmd);
1274} 1265}
1275 1266
1276static int blk_log_unplug(struct trace_seq *s, const struct trace_entry *ent) 1267static void blk_log_unplug(struct trace_seq *s, const struct trace_entry *ent)
1277{ 1268{
1278 char cmd[TASK_COMM_LEN]; 1269 char cmd[TASK_COMM_LEN];
1279 1270
1280 trace_find_cmdline(ent->pid, cmd); 1271 trace_find_cmdline(ent->pid, cmd);
1281 1272
1282 return trace_seq_printf(s, "[%s] %llu\n", cmd, get_pdu_int(ent)); 1273 trace_seq_printf(s, "[%s] %llu\n", cmd, get_pdu_int(ent));
1283} 1274}
1284 1275
1285static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent) 1276static void blk_log_split(struct trace_seq *s, const struct trace_entry *ent)
1286{ 1277{
1287 char cmd[TASK_COMM_LEN]; 1278 char cmd[TASK_COMM_LEN];
1288 1279
1289 trace_find_cmdline(ent->pid, cmd); 1280 trace_find_cmdline(ent->pid, cmd);
1290 1281
1291 return trace_seq_printf(s, "%llu / %llu [%s]\n", t_sector(ent), 1282 trace_seq_printf(s, "%llu / %llu [%s]\n", t_sector(ent),
1292 get_pdu_int(ent), cmd); 1283 get_pdu_int(ent), cmd);
1293} 1284}
1294 1285
1295static int blk_log_msg(struct trace_seq *s, const struct trace_entry *ent) 1286static void blk_log_msg(struct trace_seq *s, const struct trace_entry *ent)
1296{ 1287{
1297 int ret;
1298 const struct blk_io_trace *t = te_blk_io_trace(ent); 1288 const struct blk_io_trace *t = te_blk_io_trace(ent);
1299 1289
1300 ret = trace_seq_putmem(s, t + 1, t->pdu_len); 1290 trace_seq_putmem(s, t + 1, t->pdu_len);
1301 if (ret) 1291 trace_seq_putc(s, '\n');
1302 return trace_seq_putc(s, '\n');
1303 return ret;
1304} 1292}
1305 1293
1306/* 1294/*
@@ -1339,7 +1327,7 @@ static void blk_tracer_reset(struct trace_array *tr)
1339 1327
1340static const struct { 1328static const struct {
1341 const char *act[2]; 1329 const char *act[2];
1342 int (*print)(struct trace_seq *s, const struct trace_entry *ent); 1330 void (*print)(struct trace_seq *s, const struct trace_entry *ent);
1343} what2act[] = { 1331} what2act[] = {
1344 [__BLK_TA_QUEUE] = {{ "Q", "queue" }, blk_log_generic }, 1332 [__BLK_TA_QUEUE] = {{ "Q", "queue" }, blk_log_generic },
1345 [__BLK_TA_BACKMERGE] = {{ "M", "backmerge" }, blk_log_generic }, 1333 [__BLK_TA_BACKMERGE] = {{ "M", "backmerge" }, blk_log_generic },
@@ -1364,7 +1352,6 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
1364 struct trace_seq *s = &iter->seq; 1352 struct trace_seq *s = &iter->seq;
1365 const struct blk_io_trace *t; 1353 const struct blk_io_trace *t;
1366 u16 what; 1354 u16 what;
1367 int ret;
1368 bool long_act; 1355 bool long_act;
1369 blk_log_action_t *log_action; 1356 blk_log_action_t *log_action;
1370 1357
@@ -1374,21 +1361,18 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
1374 log_action = classic ? &blk_log_action_classic : &blk_log_action; 1361 log_action = classic ? &blk_log_action_classic : &blk_log_action;
1375 1362
1376 if (t->action == BLK_TN_MESSAGE) { 1363 if (t->action == BLK_TN_MESSAGE) {
1377 ret = log_action(iter, long_act ? "message" : "m"); 1364 log_action(iter, long_act ? "message" : "m");
1378 if (ret) 1365 blk_log_msg(s, iter->ent);
1379 ret = blk_log_msg(s, iter->ent);
1380 goto out;
1381 } 1366 }
1382 1367
1383 if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act))) 1368 if (unlikely(what == 0 || what >= ARRAY_SIZE(what2act)))
1384 ret = trace_seq_printf(s, "Unknown action %x\n", what); 1369 trace_seq_printf(s, "Unknown action %x\n", what);
1385 else { 1370 else {
1386 ret = log_action(iter, what2act[what].act[long_act]); 1371 log_action(iter, what2act[what].act[long_act]);
1387 if (ret) 1372 what2act[what].print(s, iter->ent);
1388 ret = what2act[what].print(s, iter->ent);
1389 } 1373 }
1390out: 1374
1391 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; 1375 return trace_handle_return(s);
1392} 1376}
1393 1377
1394static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, 1378static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
@@ -1397,7 +1381,7 @@ static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
1397 return print_one_line(iter, false); 1381 return print_one_line(iter, false);
1398} 1382}
1399 1383
1400static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) 1384static void blk_trace_synthesize_old_trace(struct trace_iterator *iter)
1401{ 1385{
1402 struct trace_seq *s = &iter->seq; 1386 struct trace_seq *s = &iter->seq;
1403 struct blk_io_trace *t = (struct blk_io_trace *)iter->ent; 1387 struct blk_io_trace *t = (struct blk_io_trace *)iter->ent;
@@ -1407,18 +1391,18 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
1407 .time = iter->ts, 1391 .time = iter->ts,
1408 }; 1392 };
1409 1393
1410 if (!trace_seq_putmem(s, &old, offset)) 1394 trace_seq_putmem(s, &old, offset);
1411 return 0; 1395 trace_seq_putmem(s, &t->sector,
1412 return trace_seq_putmem(s, &t->sector, 1396 sizeof(old) - offset + t->pdu_len);
1413 sizeof(old) - offset + t->pdu_len);
1414} 1397}
1415 1398
1416static enum print_line_t 1399static enum print_line_t
1417blk_trace_event_print_binary(struct trace_iterator *iter, int flags, 1400blk_trace_event_print_binary(struct trace_iterator *iter, int flags,
1418 struct trace_event *event) 1401 struct trace_event *event)
1419{ 1402{
1420 return blk_trace_synthesize_old_trace(iter) ? 1403 blk_trace_synthesize_old_trace(iter);
1421 TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; 1404
1405 return trace_handle_return(&iter->seq);
1422} 1406}
1423 1407
1424static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter) 1408static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)