blob: 9afc5be045224165c682e9b71c2ec238cd069c98 [file] [log] [blame]
Jens Axboefb7b71a2007-05-15 08:44:04 +02001/*
2 * blktrace support code for fio
3 */
4#include <stdio.h>
5#include <stdlib.h>
Jens Axboe5e6c2062007-05-16 14:40:29 +02006#include <sys/stat.h>
7#include <dirent.h>
Jens Axboe8c1fdf02007-05-15 11:54:21 +02008
Jens Axboe01743ee2008-06-02 12:19:19 +02009#include "flist.h"
Jens Axboefb7b71a2007-05-15 08:44:04 +020010#include "fio.h"
11#include "blktrace_api.h"
Jens Axboe42a80e32014-09-16 17:06:52 +020012#include "lib/linux-dev-lookup.h"
Jens Axboefb7b71a2007-05-15 08:44:04 +020013
Jens Axboe2da7df12010-08-01 21:27:28 +020014#define TRACE_FIFO_SIZE 8192
Jens Axboee2887562007-05-16 09:25:09 +020015
16/*
17 * fifo refill frontend, to avoid reading data in trace sized bites
18 */
19static int refill_fifo(struct thread_data *td, struct fifo *fifo, int fd)
20{
21 char buf[TRACE_FIFO_SIZE];
Jens Axboef12b3232007-05-16 12:16:44 +020022 unsigned int total;
Jens Axboee2887562007-05-16 09:25:09 +020023 int ret;
24
Jens Axboef12b3232007-05-16 12:16:44 +020025 total = sizeof(buf);
26 if (total > fifo_room(fifo))
27 total = fifo_room(fifo);
Jens Axboee2887562007-05-16 09:25:09 +020028
Jens Axboef12b3232007-05-16 12:16:44 +020029 ret = read(fd, buf, total);
30 if (ret < 0) {
31 td_verror(td, errno, "read blktrace file");
32 return -1;
Jens Axboee2887562007-05-16 09:25:09 +020033 }
34
Jens Axboef12b3232007-05-16 12:16:44 +020035 if (ret > 0)
36 ret = fifo_put(fifo, buf, ret);
37
Jens Axboebd6f78b2008-02-01 20:27:52 +010038 dprint(FD_BLKTRACE, "refill: filled %d bytes\n", ret);
Jens Axboef12b3232007-05-16 12:16:44 +020039 return ret;
Jens Axboee2887562007-05-16 09:25:09 +020040}
41
42/*
43 * Retrieve 'len' bytes from the fifo, refilling if necessary.
44 */
45static int trace_fifo_get(struct thread_data *td, struct fifo *fifo, int fd,
46 void *buf, unsigned int len)
47{
Jens Axboef12b3232007-05-16 12:16:44 +020048 if (fifo_len(fifo) < len) {
49 int ret = refill_fifo(td, fifo, fd);
Jens Axboee2887562007-05-16 09:25:09 +020050
Jens Axboef12b3232007-05-16 12:16:44 +020051 if (ret < 0)
52 return ret;
53 }
Jens Axboee2887562007-05-16 09:25:09 +020054
55 return fifo_get(fifo, buf, len);
56}
57
Jens Axboe8c1fdf02007-05-15 11:54:21 +020058/*
59 * Just discard the pdu by seeking past it.
60 */
Jens Axboef12b3232007-05-16 12:16:44 +020061static int discard_pdu(struct thread_data *td, struct fifo *fifo, int fd,
62 struct blk_io_trace *t)
Jens Axboefb7b71a2007-05-15 08:44:04 +020063{
64 if (t->pdu_len == 0)
65 return 0;
66
Jens Axboebd6f78b2008-02-01 20:27:52 +010067 dprint(FD_BLKTRACE, "discard pdu len %u\n", t->pdu_len);
Jens Axboef12b3232007-05-16 12:16:44 +020068 return trace_fifo_get(td, fifo, fd, NULL, t->pdu_len);
Jens Axboefb7b71a2007-05-15 08:44:04 +020069}
70
Jens Axboe8c1fdf02007-05-15 11:54:21 +020071/*
72 * Check if this is a blktrace binary data file. We read a single trace
73 * into memory and check for the magic signature.
74 */
Jens Axboed95b34a2013-11-21 09:55:49 -070075int is_blktrace(const char *filename, int *need_swap)
Jens Axboefb7b71a2007-05-15 08:44:04 +020076{
77 struct blk_io_trace t;
78 int fd, ret;
79
80 fd = open(filename, O_RDONLY);
Jens Axboe4dced402007-07-23 14:16:55 +020081 if (fd < 0)
Jens Axboefb7b71a2007-05-15 08:44:04 +020082 return 0;
Jens Axboefb7b71a2007-05-15 08:44:04 +020083
84 ret = read(fd, &t, sizeof(t));
85 close(fd);
86
87 if (ret < 0) {
88 perror("read blktrace");
89 return 0;
90 } else if (ret != sizeof(t)) {
91 log_err("fio: short read on blktrace file\n");
92 return 0;
93 }
94
Jens Axboed95b34a2013-11-21 09:55:49 -070095 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
96 *need_swap = 0;
Jens Axboefb7b71a2007-05-15 08:44:04 +020097 return 1;
Jens Axboed95b34a2013-11-21 09:55:49 -070098 }
99
100 /*
101 * Maybe it needs to be endian swapped...
102 */
103 t.magic = fio_swap32(t.magic);
104 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
105 *need_swap = 1;
106 return 1;
107 }
Jens Axboefb7b71a2007-05-15 08:44:04 +0200108
109 return 0;
110}
111
Jens Axboec69aa912007-05-22 15:51:50 +0200112#define FMINORBITS 20
113#define FMINORMASK ((1U << FMINORBITS) - 1)
114#define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS))
115#define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK))
Jens Axboeeeb9c2a2007-05-16 18:28:47 +0200116
Shaohua Li89ac1d42012-06-11 08:56:32 +0200117static void trace_add_open_close_event(struct thread_data *td, int fileno, enum file_log_act action)
Jens Axboe691c8fb2008-03-07 14:26:26 +0100118{
119 struct io_piece *ipo;
120
121 ipo = calloc(1, sizeof(*ipo));
Jens Axboe0d29de82010-09-01 13:54:15 +0200122 init_ipo(ipo);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100123
124 ipo->ddir = DDIR_INVAL;
125 ipo->fileno = fileno;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200126 ipo->file_action = action;
Jens Axboe01743ee2008-06-02 12:19:19 +0200127 flist_add_tail(&ipo->list, &td->io_log_list);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100128}
129
Shaohua Li89ac1d42012-06-11 08:56:32 +0200130static int trace_add_file(struct thread_data *td, __u32 device)
Jens Axboe5e6c2062007-05-16 14:40:29 +0200131{
Shaohua Li89ac1d42012-06-11 08:56:32 +0200132 static unsigned int last_maj, last_min, last_fileno;
Jens Axboec69aa912007-05-22 15:51:50 +0200133 unsigned int maj = FMAJOR(device);
134 unsigned int min = FMINOR(device);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200135 struct fio_file *f;
136 char dev[256];
137 unsigned int i;
138
139 if (last_maj == maj && last_min == min)
Shaohua Li89ac1d42012-06-11 08:56:32 +0200140 return last_fileno;
Jens Axboe5e6c2062007-05-16 14:40:29 +0200141
142 last_maj = maj;
143 last_min = min;
144
145 /*
146 * check for this file in our list
147 */
148 for_each_file(td, f, i)
Shaohua Li89ac1d42012-06-11 08:56:32 +0200149 if (f->major == maj && f->minor == min) {
150 last_fileno = f->fileno;
151 return last_fileno;
152 }
Jens Axboe5e6c2062007-05-16 14:40:29 +0200153
154 strcpy(dev, "/dev");
Jens Axboe42a80e32014-09-16 17:06:52 +0200155 if (blktrace_lookup_device(td->o.replay_redirect, dev, maj, min)) {
Jens Axboe691c8fb2008-03-07 14:26:26 +0100156 int fileno;
157
Jens Axboe42a80e32014-09-16 17:06:52 +0200158 if (td->o.replay_redirect)
159 dprint(FD_BLKTRACE, "device lookup: %d/%d\n overridden"
160 " with: %s\n", maj, min,
161 td->o.replay_redirect);
162 else
163 dprint(FD_BLKTRACE, "device lookup: %d/%d\n", maj, min);
164
Jens Axboebd6f78b2008-02-01 20:27:52 +0100165 dprint(FD_BLKTRACE, "add devices %s\n", dev);
Jens Axboe49ffb4a2010-08-24 15:01:37 +0200166 fileno = add_file_exclusive(td, dev);
Jens Axboeb53f2c52014-04-08 21:07:12 -0600167 td->o.open_files++;
Jens Axboe5903e7b2014-02-26 13:42:13 -0800168 td->files[fileno]->major = maj;
169 td->files[fileno]->minor = min;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200170 trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
171 last_fileno = fileno;
Jens Axboebd6f78b2008-02-01 20:27:52 +0100172 }
Jens Axboef01b34a2013-11-21 11:13:12 -0700173
Shaohua Li89ac1d42012-06-11 08:56:32 +0200174 return last_fileno;
Jens Axboe5e6c2062007-05-16 14:40:29 +0200175}
176
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200177/*
178 * Store blk_io_trace data in an ipo for later retrieval.
179 */
Jens Axboefdefd982007-05-15 10:12:26 +0200180static void store_ipo(struct thread_data *td, unsigned long long offset,
Shaohua Li89ac1d42012-06-11 08:56:32 +0200181 unsigned int bytes, int rw, unsigned long long ttime,
182 int fileno)
Jens Axboefdefd982007-05-15 10:12:26 +0200183{
184 struct io_piece *ipo = malloc(sizeof(*ipo));
185
Jens Axboe0d29de82010-09-01 13:54:15 +0200186 init_ipo(ipo);
187
Jens Axboea2eea812007-05-15 13:10:41 +0200188 /*
189 * the 512 is wrong here, it should be the hardware sector size...
190 */
191 ipo->offset = offset * 512;
Jens Axboefdefd982007-05-15 10:12:26 +0200192 ipo->len = bytes;
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200193 ipo->delay = ttime / 1000;
Jens Axboefdefd982007-05-15 10:12:26 +0200194 if (rw)
195 ipo->ddir = DDIR_WRITE;
196 else
197 ipo->ddir = DDIR_READ;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200198 ipo->fileno = fileno;
Jens Axboefdefd982007-05-15 10:12:26 +0200199
Jens Axboebd6f78b2008-02-01 20:27:52 +0100200 dprint(FD_BLKTRACE, "store ddir=%d, off=%llu, len=%lu, delay=%lu\n",
201 ipo->ddir, ipo->offset,
202 ipo->len, ipo->delay);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100203 queue_io_piece(td, ipo);
Jens Axboefdefd982007-05-15 10:12:26 +0200204}
205
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200206static void handle_trace_notify(struct blk_io_trace *t)
Jens Axboe691c8fb2008-03-07 14:26:26 +0100207{
208 switch (t->action) {
209 case BLK_TN_PROCESS:
Jens Axboe5bca6f92014-07-14 15:07:11 +0200210 dprint(FD_BLKTRACE, "got process notify: %x, %d\n",
Jens Axboed95b34a2013-11-21 09:55:49 -0700211 t->action, t->pid);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100212 break;
213 case BLK_TN_TIMESTAMP:
Jens Axboe5bca6f92014-07-14 15:07:11 +0200214 dprint(FD_BLKTRACE, "got timestamp notify: %x, %d\n",
Jens Axboed95b34a2013-11-21 09:55:49 -0700215 t->action, t->pid);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100216 break;
Jens Axboeff58fce2010-08-25 12:02:08 +0200217 case BLK_TN_MESSAGE:
218 break;
Jens Axboe691c8fb2008-03-07 14:26:26 +0100219 default:
220 dprint(FD_BLKTRACE, "unknown trace act %x\n", t->action);
221 break;
222 }
223}
224
Jens Axboe5bca6f92014-07-14 15:07:11 +0200225static void handle_trace_discard(struct thread_data *td,
226 struct blk_io_trace *t,
227 unsigned long long ttime,
228 unsigned long *ios, unsigned int *bs)
Jens Axboeff58fce2010-08-25 12:02:08 +0200229{
230 struct io_piece *ipo = malloc(sizeof(*ipo));
Shaohua Li89ac1d42012-06-11 08:56:32 +0200231 int fileno;
Jens Axboeff58fce2010-08-25 12:02:08 +0200232
Jens Axboe0d29de82010-09-01 13:54:15 +0200233 init_ipo(ipo);
Shaohua Li89ac1d42012-06-11 08:56:32 +0200234 fileno = trace_add_file(td, t->device);
Jens Axboeff58fce2010-08-25 12:02:08 +0200235
Jens Axboe5bca6f92014-07-14 15:07:11 +0200236 ios[DDIR_TRIM]++;
237 if (t->bytes > bs[DDIR_TRIM])
238 bs[DDIR_TRIM] = t->bytes;
239
Jens Axboeff58fce2010-08-25 12:02:08 +0200240 td->o.size += t->bytes;
241
242 memset(ipo, 0, sizeof(*ipo));
243 INIT_FLIST_HEAD(&ipo->list);
244
245 /*
246 * the 512 is wrong here, it should be the hardware sector size...
247 */
248 ipo->offset = t->sector * 512;
249 ipo->len = t->bytes;
250 ipo->delay = ttime / 1000;
251 ipo->ddir = DDIR_TRIM;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200252 ipo->fileno = fileno;
Jens Axboeff58fce2010-08-25 12:02:08 +0200253
254 dprint(FD_BLKTRACE, "store discard, off=%llu, len=%lu, delay=%lu\n",
255 ipo->offset, ipo->len,
256 ipo->delay);
257 queue_io_piece(td, ipo);
258}
259
Jens Axboe691c8fb2008-03-07 14:26:26 +0100260static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
261 unsigned long long ttime, unsigned long *ios,
262 unsigned int *bs)
Jens Axboefb7b71a2007-05-15 08:44:04 +0200263{
Jens Axboefdefd982007-05-15 10:12:26 +0200264 int rw;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200265 int fileno;
Jens Axboefdefd982007-05-15 10:12:26 +0200266
Shaohua Li89ac1d42012-06-11 08:56:32 +0200267 fileno = trace_add_file(td, t->device);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200268
Jens Axboee7a7d702007-05-15 10:13:04 +0200269 rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
Jens Axboed84f8d42007-05-16 08:47:46 +0200270
271 if (t->bytes > bs[rw])
272 bs[rw] = t->bytes;
273
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200274 ios[rw]++;
Jens Axboe6df8ada2007-05-15 13:23:19 +0200275 td->o.size += t->bytes;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200276 store_ipo(td, t->sector, t->bytes, rw, ttime, fileno);
Jens Axboefb7b71a2007-05-15 08:44:04 +0200277}
278
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200279/*
Jens Axboe691c8fb2008-03-07 14:26:26 +0100280 * We only care for queue traces, most of the others are side effects
281 * due to internal workings of the block layer.
282 */
283static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
Jens Axboe5bca6f92014-07-14 15:07:11 +0200284 unsigned long *ios, unsigned int *bs)
Jens Axboe691c8fb2008-03-07 14:26:26 +0100285{
Jens Axboe5bca6f92014-07-14 15:07:11 +0200286 static unsigned long long last_ttime;
287 unsigned long long delay;
288
Jens Axboe691c8fb2008-03-07 14:26:26 +0100289 if ((t->action & 0xffff) != __BLK_TA_QUEUE)
290 return;
Jens Axboe5bca6f92014-07-14 15:07:11 +0200291
292 if (!(t->action & BLK_TC_ACT(BLK_TC_NOTIFY))) {
293 if (!last_ttime || td->o.no_stall) {
294 last_ttime = t->time;
295 delay = 0;
296 } else {
297 delay = t->time - last_ttime;
298 last_ttime = t->time;
299 }
300 }
Jens Axboe691c8fb2008-03-07 14:26:26 +0100301
302 if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
Jens Axboeaec2de22008-04-24 12:44:42 +0200303 handle_trace_notify(t);
Jens Axboeff58fce2010-08-25 12:02:08 +0200304 else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
Jens Axboe5bca6f92014-07-14 15:07:11 +0200305 handle_trace_discard(td, t, delay, ios, bs);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100306 else
Jens Axboe5bca6f92014-07-14 15:07:11 +0200307 handle_trace_fs(td, t, delay, ios, bs);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100308}
309
Jens Axboed95b34a2013-11-21 09:55:49 -0700310static void byteswap_trace(struct blk_io_trace *t)
311{
312 t->magic = fio_swap32(t->magic);
313 t->sequence = fio_swap32(t->sequence);
314 t->time = fio_swap64(t->time);
315 t->sector = fio_swap64(t->sector);
316 t->bytes = fio_swap32(t->bytes);
317 t->action = fio_swap32(t->action);
318 t->pid = fio_swap32(t->pid);
319 t->device = fio_swap32(t->device);
320 t->cpu = fio_swap32(t->cpu);
321 t->error = fio_swap16(t->error);
322 t->pdu_len = fio_swap16(t->pdu_len);
323}
324
Jens Axboe5bca6f92014-07-14 15:07:11 +0200325static int t_is_write(struct blk_io_trace *t)
326{
327 return (t->action & BLK_TC_ACT(BLK_TC_WRITE | BLK_TC_DISCARD)) != 0;
328}
329
Jens Axboe691c8fb2008-03-07 14:26:26 +0100330/*
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200331 * Load a blktrace file by reading all the blk_io_trace entries, and storing
332 * them as io_pieces like the fio text version would do.
333 */
Jens Axboed95b34a2013-11-21 09:55:49 -0700334int load_blktrace(struct thread_data *td, const char *filename, int need_swap)
Jens Axboefb7b71a2007-05-15 08:44:04 +0200335{
336 struct blk_io_trace t;
Jens Axboe5bca6f92014-07-14 15:07:11 +0200337 unsigned long ios[DDIR_RWDIR_CNT], skipped_writes;
338 unsigned int rw_bs[DDIR_RWDIR_CNT];
Jens Axboee2887562007-05-16 09:25:09 +0200339 struct fifo *fifo;
Jens Axboe5903e7b2014-02-26 13:42:13 -0800340 int fd, i, old_state;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200341 struct fio_file *f;
Jens Axboeeb5fdcf2014-04-08 13:43:19 -0600342 int this_depth, depth;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200343
344 fd = open(filename, O_RDONLY);
345 if (fd < 0) {
346 td_verror(td, errno, "open blktrace file");
347 return 1;
348 }
349
Jens Axboee2887562007-05-16 09:25:09 +0200350 fifo = fifo_alloc(TRACE_FIFO_SIZE);
351
Jens Axboe8edd9732014-03-01 08:24:03 -0700352 old_state = td_bump_runstate(td, TD_SETTING_UP);
Jens Axboe5903e7b2014-02-26 13:42:13 -0800353
Jens Axboe6df8ada2007-05-15 13:23:19 +0200354 td->o.size = 0;
355
Jens Axboed84f8d42007-05-16 08:47:46 +0200356 ios[0] = ios[1] = 0;
357 rw_bs[0] = rw_bs[1] = 0;
Jens Axboe4241ea82007-09-12 08:18:36 +0200358 skipped_writes = 0;
Jens Axboeeb5fdcf2014-04-08 13:43:19 -0600359 this_depth = depth = 0;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200360 do {
Jens Axboee2887562007-05-16 09:25:09 +0200361 int ret = trace_fifo_get(td, fifo, fd, &t, sizeof(t));
Jens Axboefb7b71a2007-05-15 08:44:04 +0200362
Jens Axboee2887562007-05-16 09:25:09 +0200363 if (ret < 0)
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200364 goto err;
Jens Axboee2887562007-05-16 09:25:09 +0200365 else if (!ret)
Jens Axboefb7b71a2007-05-15 08:44:04 +0200366 break;
Jens Axboee2887562007-05-16 09:25:09 +0200367 else if (ret < (int) sizeof(t)) {
368 log_err("fio: short fifo get\n");
369 break;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200370 }
371
Jens Axboed95b34a2013-11-21 09:55:49 -0700372 if (need_swap)
373 byteswap_trace(&t);
374
Jens Axboefb7b71a2007-05-15 08:44:04 +0200375 if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100376 log_err("fio: bad magic in blktrace data: %x\n",
377 t.magic);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200378 goto err;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200379 }
380 if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100381 log_err("fio: bad blktrace version %d\n",
382 t.magic & 0xff);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200383 goto err;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200384 }
Jens Axboef12b3232007-05-16 12:16:44 +0200385 ret = discard_pdu(td, fifo, fd, &t);
386 if (ret < 0) {
Jens Axboefb7b71a2007-05-15 08:44:04 +0200387 td_verror(td, ret, "blktrace lseek");
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200388 goto err;
Jens Axboef12b3232007-05-16 12:16:44 +0200389 } else if (t.pdu_len != ret) {
390 log_err("fio: discarded %d of %d\n", ret, t.pdu_len);
391 goto err;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200392 }
Jens Axboe691c8fb2008-03-07 14:26:26 +0100393 if ((t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) == 0) {
Jens Axboeeb5fdcf2014-04-08 13:43:19 -0600394 if ((t.action & 0xffff) == __BLK_TA_QUEUE)
395 this_depth++;
396 else if ((t.action & 0xffff) == __BLK_TA_COMPLETE) {
397 depth = max(depth, this_depth);
398 this_depth = 0;
399 }
Jens Axboe691c8fb2008-03-07 14:26:26 +0100400
Jens Axboe5bca6f92014-07-14 15:07:11 +0200401 if (t_is_write(&t) && read_only) {
Jens Axboe691c8fb2008-03-07 14:26:26 +0100402 skipped_writes++;
Jens Axboe5bca6f92014-07-14 15:07:11 +0200403 continue;
David Nellans64bbb862010-08-24 22:13:30 +0200404 }
Jens Axboea6edd632008-03-07 21:41:54 +0100405 }
Jens Axboe5bca6f92014-07-14 15:07:11 +0200406
407 handle_trace(td, &t, ios, rw_bs);
Jens Axboefb7b71a2007-05-15 08:44:04 +0200408 } while (1);
409
Jens Axboe85a47ca2012-06-11 13:19:13 +0200410 for (i = 0; i < td->files_index; i++) {
Jens Axboef01b34a2013-11-21 11:13:12 -0700411 f = td->files[i];
Shaohua Li89ac1d42012-06-11 08:56:32 +0200412 trace_add_open_close_event(td, f->fileno, FIO_LOG_CLOSE_FILE);
Jens Axboe85a47ca2012-06-11 13:19:13 +0200413 }
Shaohua Li89ac1d42012-06-11 08:56:32 +0200414
Jens Axboe38470f82007-05-16 09:26:23 +0200415 fifo_free(fifo);
Jens Axboefb7b71a2007-05-15 08:44:04 +0200416 close(fd);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200417
Jens Axboe8edd9732014-03-01 08:24:03 -0700418 td_restore_runstate(td, old_state);
Jens Axboe5903e7b2014-02-26 13:42:13 -0800419
Jens Axboef01b34a2013-11-21 11:13:12 -0700420 if (!td->files_index) {
421 log_err("fio: did not find replay device(s)\n");
422 return 1;
423 }
424
Jens Axboeeb5fdcf2014-04-08 13:43:19 -0600425 /*
426 * For stacked devices, we don't always get a COMPLETE event so
427 * the depth grows to insane values. Limit it to something sane(r).
428 */
429 if (!depth || depth > 1024)
430 depth = 1024;
431
Jens Axboe4241ea82007-09-12 08:18:36 +0200432 if (skipped_writes)
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100433 log_err("fio: %s skips replay of %lu writes due to read-only\n",
434 td->o.name, skipped_writes);
Jens Axboe4241ea82007-09-12 08:18:36 +0200435
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200436 if (!ios[DDIR_READ] && !ios[DDIR_WRITE]) {
437 log_err("fio: found no ios in blktrace data\n");
438 return 1;
Jens Axboe5bca6f92014-07-14 15:07:11 +0200439 } else if (ios[DDIR_READ] && !ios[DDIR_WRITE]) {
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200440 td->o.td_ddir = TD_DDIR_READ;
Jens Axboed84f8d42007-05-16 08:47:46 +0200441 td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
442 } else if (!ios[DDIR_READ] && ios[DDIR_WRITE]) {
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200443 td->o.td_ddir = TD_DDIR_WRITE;
Jens Axboed84f8d42007-05-16 08:47:46 +0200444 td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
445 } else {
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200446 td->o.td_ddir = TD_DDIR_RW;
Jens Axboed84f8d42007-05-16 08:47:46 +0200447 td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
448 td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
Jens Axboe5bca6f92014-07-14 15:07:11 +0200449 td->o.max_bs[DDIR_TRIM] = rw_bs[DDIR_TRIM];
Jens Axboed84f8d42007-05-16 08:47:46 +0200450 }
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200451
452 /*
453 * We need to do direct/raw ios to the device, to avoid getting
454 * read-ahead in our way.
455 */
456 td->o.odirect = 1;
457
Jens Axboeeb5fdcf2014-04-08 13:43:19 -0600458 /*
459 * we don't know if this option was set or not. it defaults to 1,
460 * so we'll just guess that we should override it if it's still 1
461 */
Jens Axboe15ed5ae2014-11-21 13:49:00 -0700462 if (td->o.iodepth == 1)
463 td->o.iodepth = td->o.iodepth_low = depth;
Jens Axboeeb5fdcf2014-04-08 13:43:19 -0600464
Jens Axboefb7b71a2007-05-15 08:44:04 +0200465 return 0;
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200466err:
467 close(fd);
Jens Axboe38470f82007-05-16 09:26:23 +0200468 fifo_free(fifo);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200469 return 1;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200470}