init: use __log_buf() if we know buf != NULL
[fio.git] / blktrace.c
CommitLineData
fb7b71a3
JA
1/*
2 * blktrace support code for fio
3 */
4#include <stdio.h>
5#include <stdlib.h>
26e616d0
JA
6#include <sys/ioctl.h>
7#include <linux/fs.h>
8c1fdf04 8
01743ee1 9#include "flist.h"
fb7b71a3 10#include "fio.h"
a3e59412 11#include "blktrace.h"
fb7b71a3 12#include "blktrace_api.h"
984f30c9 13#include "oslib/linux-dev-lookup.h"
fb7b71a3 14
2da7df1d 15#define TRACE_FIFO_SIZE 8192
e2887563
JA
16
17/*
18 * fifo refill frontend, to avoid reading data in trace sized bites
19 */
20static int refill_fifo(struct thread_data *td, struct fifo *fifo, int fd)
21{
22 char buf[TRACE_FIFO_SIZE];
f12b323f 23 unsigned int total;
e2887563
JA
24 int ret;
25
f12b323f
JA
26 total = sizeof(buf);
27 if (total > fifo_room(fifo))
28 total = fifo_room(fifo);
e2887563 29
f12b323f
JA
30 ret = read(fd, buf, total);
31 if (ret < 0) {
32 td_verror(td, errno, "read blktrace file");
33 return -1;
e2887563
JA
34 }
35
f12b323f
JA
36 if (ret > 0)
37 ret = fifo_put(fifo, buf, ret);
38
bd6f78b2 39 dprint(FD_BLKTRACE, "refill: filled %d bytes\n", ret);
f12b323f 40 return ret;
e2887563
JA
41}
42
43/*
44 * Retrieve 'len' bytes from the fifo, refilling if necessary.
45 */
46static int trace_fifo_get(struct thread_data *td, struct fifo *fifo, int fd,
47 void *buf, unsigned int len)
48{
f12b323f
JA
49 if (fifo_len(fifo) < len) {
50 int ret = refill_fifo(td, fifo, fd);
e2887563 51
f12b323f
JA
52 if (ret < 0)
53 return ret;
54 }
e2887563
JA
55
56 return fifo_get(fifo, buf, len);
57}
58
8c1fdf04
JA
59/*
60 * Just discard the pdu by seeking past it.
61 */
f12b323f
JA
62static int discard_pdu(struct thread_data *td, struct fifo *fifo, int fd,
63 struct blk_io_trace *t)
fb7b71a3
JA
64{
65 if (t->pdu_len == 0)
66 return 0;
67
bd6f78b2 68 dprint(FD_BLKTRACE, "discard pdu len %u\n", t->pdu_len);
f12b323f 69 return trace_fifo_get(td, fifo, fd, NULL, t->pdu_len);
fb7b71a3
JA
70}
71
8c1fdf04
JA
72/*
73 * Check if this is a blktrace binary data file. We read a single trace
74 * into memory and check for the magic signature.
75 */
b153f94a 76bool is_blktrace(const char *filename, int *need_swap)
fb7b71a3
JA
77{
78 struct blk_io_trace t;
79 int fd, ret;
80
81 fd = open(filename, O_RDONLY);
4dced407 82 if (fd < 0)
b153f94a 83 return false;
fb7b71a3
JA
84
85 ret = read(fd, &t, sizeof(t));
86 close(fd);
87
88 if (ret < 0) {
89 perror("read blktrace");
b153f94a 90 return false;
fb7b71a3
JA
91 } else if (ret != sizeof(t)) {
92 log_err("fio: short read on blktrace file\n");
b153f94a 93 return false;
fb7b71a3
JA
94 }
95
d95b34a6
JA
96 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
97 *need_swap = 0;
b153f94a 98 return true;
d95b34a6
JA
99 }
100
101 /*
102 * Maybe it needs to be endian swapped...
103 */
104 t.magic = fio_swap32(t.magic);
105 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
106 *need_swap = 1;
b153f94a 107 return true;
d95b34a6 108 }
fb7b71a3 109
b153f94a 110 return false;
fb7b71a3
JA
111}
112
c69aa91f
JA
113#define FMINORBITS 20
114#define FMINORMASK ((1U << FMINORBITS) - 1)
115#define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS))
116#define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK))
eeb9c2aa 117
89ac1d48 118static void trace_add_open_close_event(struct thread_data *td, int fileno, enum file_log_act action)
691c8fb0
JA
119{
120 struct io_piece *ipo;
121
122 ipo = calloc(1, sizeof(*ipo));
0d29de83 123 init_ipo(ipo);
691c8fb0
JA
124
125 ipo->ddir = DDIR_INVAL;
126 ipo->fileno = fileno;
89ac1d48 127 ipo->file_action = action;
01743ee1 128 flist_add_tail(&ipo->list, &td->io_log_list);
691c8fb0
JA
129}
130
26e616d0 131static int get_dev_blocksize(const char *dev, unsigned int *bs)
5e6c2067 132{
26e616d0
JA
133 int fd;
134
135 fd = open(dev, O_RDONLY);
136 if (fd < 0)
137 return 1;
138
139 if (ioctl(fd, BLKSSZGET, bs) < 0) {
140 close(fd);
141 return 1;
142 }
143
144 close(fd);
145 return 0;
146}
147
148static int trace_add_file(struct thread_data *td, __u32 device,
149 unsigned int *bs)
150{
151 static unsigned int last_maj, last_min, last_fileno, last_bs;
c69aa91f
JA
152 unsigned int maj = FMAJOR(device);
153 unsigned int min = FMINOR(device);
5e6c2067 154 struct fio_file *f;
5e6c2067 155 unsigned int i;
26e616d0 156 char dev[256];
5e6c2067 157
26e616d0
JA
158 if (last_maj == maj && last_min == min) {
159 *bs = last_bs;
89ac1d48 160 return last_fileno;
26e616d0 161 }
5e6c2067
JA
162
163 last_maj = maj;
164 last_min = min;
165
166 /*
167 * check for this file in our list
168 */
26e616d0 169 for_each_file(td, f, i) {
89ac1d48
SL
170 if (f->major == maj && f->minor == min) {
171 last_fileno = f->fileno;
26e616d0
JA
172 last_bs = f->bs;
173 goto out;
89ac1d48 174 }
26e616d0 175 }
5e6c2067
JA
176
177 strcpy(dev, "/dev");
40bafa33 178 if (blktrace_lookup_device(td->o.replay_redirect, dev, maj, min)) {
26e616d0 179 unsigned int this_bs;
691c8fb0
JA
180 int fileno;
181
40bafa33
JA
182 if (td->o.replay_redirect)
183 dprint(FD_BLKTRACE, "device lookup: %d/%d\n overridden"
184 " with: %s\n", maj, min,
185 td->o.replay_redirect);
186 else
187 dprint(FD_BLKTRACE, "device lookup: %d/%d\n", maj, min);
188
bd6f78b2 189 dprint(FD_BLKTRACE, "add devices %s\n", dev);
49ffb4a2 190 fileno = add_file_exclusive(td, dev);
26e616d0
JA
191
192 if (get_dev_blocksize(dev, &this_bs))
193 this_bs = 512;
194
b53f2c54 195 td->o.open_files++;
5903e7b7
JA
196 td->files[fileno]->major = maj;
197 td->files[fileno]->minor = min;
26e616d0 198 td->files[fileno]->bs = this_bs;
89ac1d48 199 trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
26e616d0 200
89ac1d48 201 last_fileno = fileno;
26e616d0 202 last_bs = this_bs;
bd6f78b2 203 }
f01b34ae 204
26e616d0
JA
205out:
206 *bs = last_bs;
89ac1d48 207 return last_fileno;
5e6c2067
JA
208}
209
0c63576e
JA
210static void t_bytes_align(struct thread_options *o, struct blk_io_trace *t)
211{
212 if (!o->replay_align)
213 return;
214
215 t->bytes = (t->bytes + o->replay_align - 1) & ~(o->replay_align - 1);
216}
217
8c1fdf04
JA
218/*
219 * Store blk_io_trace data in an ipo for later retrieval.
220 */
fdefd987 221static void store_ipo(struct thread_data *td, unsigned long long offset,
89ac1d48 222 unsigned int bytes, int rw, unsigned long long ttime,
26e616d0 223 int fileno, unsigned int bs)
fdefd987 224{
8812d7f2 225 struct io_piece *ipo;
fdefd987 226
8812d7f2 227 ipo = calloc(1, sizeof(*ipo));
0d29de83
JA
228 init_ipo(ipo);
229
26e616d0 230 ipo->offset = offset * bs;
0c63576e
JA
231 if (td->o.replay_scale)
232 ipo->offset = ipo->offset / td->o.replay_scale;
a79f17bf 233 ipo_bytes_align(td->o.replay_align, ipo);
fdefd987 234 ipo->len = bytes;
8c1fdf04 235 ipo->delay = ttime / 1000;
fdefd987
JA
236 if (rw)
237 ipo->ddir = DDIR_WRITE;
238 else
239 ipo->ddir = DDIR_READ;
89ac1d48 240 ipo->fileno = fileno;
fdefd987 241
bd6f78b2
JA
242 dprint(FD_BLKTRACE, "store ddir=%d, off=%llu, len=%lu, delay=%lu\n",
243 ipo->ddir, ipo->offset,
244 ipo->len, ipo->delay);
691c8fb0 245 queue_io_piece(td, ipo);
fdefd987
JA
246}
247
0b9d69ec 248static void handle_trace_notify(struct blk_io_trace *t)
cd991b9e 249{
691c8fb0
JA
250 switch (t->action) {
251 case BLK_TN_PROCESS:
24653680 252 dprint(FD_BLKTRACE, "got process notify: %x, %d\n",
d95b34a6 253 t->action, t->pid);
691c8fb0
JA
254 break;
255 case BLK_TN_TIMESTAMP:
24653680 256 dprint(FD_BLKTRACE, "got timestamp notify: %x, %d\n",
d95b34a6 257 t->action, t->pid);
691c8fb0 258 break;
ff58fced
JA
259 case BLK_TN_MESSAGE:
260 break;
691c8fb0
JA
261 default:
262 dprint(FD_BLKTRACE, "unknown trace act %x\n", t->action);
263 break;
264 }
265}
5b3023b8 266
24653680
JA
267static void handle_trace_discard(struct thread_data *td,
268 struct blk_io_trace *t,
269 unsigned long long ttime,
26e616d0 270 unsigned long *ios, unsigned int *rw_bs)
ff58fced 271{
8812d7f2 272 struct io_piece *ipo;
26e616d0 273 unsigned int bs;
89ac1d48 274 int fileno;
ff58fced 275
d7235efb
JA
276 if (td->o.replay_skip & (1u << DDIR_TRIM))
277 return;
278
8812d7f2 279 ipo = calloc(1, sizeof(*ipo));
0d29de83 280 init_ipo(ipo);
26e616d0 281 fileno = trace_add_file(td, t->device, &bs);
ff58fced 282
24653680 283 ios[DDIR_TRIM]++;
26e616d0
JA
284 if (t->bytes > rw_bs[DDIR_TRIM])
285 rw_bs[DDIR_TRIM] = t->bytes;
24653680 286
ff58fced
JA
287 td->o.size += t->bytes;
288
ff58fced
JA
289 INIT_FLIST_HEAD(&ipo->list);
290
26e616d0 291 ipo->offset = t->sector * bs;
0c63576e
JA
292 if (td->o.replay_scale)
293 ipo->offset = ipo->offset / td->o.replay_scale;
a79f17bf 294 ipo_bytes_align(td->o.replay_align, ipo);
ff58fced
JA
295 ipo->len = t->bytes;
296 ipo->delay = ttime / 1000;
297 ipo->ddir = DDIR_TRIM;
89ac1d48 298 ipo->fileno = fileno;
ff58fced
JA
299
300 dprint(FD_BLKTRACE, "store discard, off=%llu, len=%lu, delay=%lu\n",
301 ipo->offset, ipo->len,
302 ipo->delay);
303 queue_io_piece(td, ipo);
304}
305
19a8064e
JA
306static void dump_trace(struct blk_io_trace *t)
307{
308 log_err("blktrace: ignoring zero byte trace: action=%x\n", t->action);
309}
310
691c8fb0
JA
311static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
312 unsigned long long ttime, unsigned long *ios,
26e616d0 313 unsigned int *rw_bs)
691c8fb0 314{
26e616d0 315 unsigned int bs;
691c8fb0 316 int rw;
89ac1d48 317 int fileno;
5b3023b8 318
26e616d0 319 fileno = trace_add_file(td, t->device, &bs);
5b3023b8
JA
320
321 rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
322
d7235efb
JA
323 if (rw) {
324 if (td->o.replay_skip & (1u << DDIR_WRITE))
325 return;
326 } else {
327 if (td->o.replay_skip & (1u << DDIR_READ))
328 return;
329 }
330
19a8064e
JA
331 if (!t->bytes) {
332 if (!fio_did_warn(FIO_WARN_BTRACE_ZERO))
333 dump_trace(t);
334 return;
335 }
c1f22c21
JA
336
337 if (t->bytes > rw_bs[rw])
26e616d0 338 rw_bs[rw] = t->bytes;
5b3023b8
JA
339
340 ios[rw]++;
341 td->o.size += t->bytes;
26e616d0 342 store_ipo(td, t->sector, t->bytes, rw, ttime, fileno, bs);
cd991b9e
JA
343}
344
65c42cc8 345static void handle_trace_flush(struct thread_data *td, struct blk_io_trace *t,
811f5421 346 unsigned long long ttime, unsigned long *ios)
65c42cc8
JA
347{
348 struct io_piece *ipo;
349 unsigned int bs;
350 int fileno;
351
d7235efb
JA
352 if (td->o.replay_skip & (1u << DDIR_SYNC))
353 return;
354
65c42cc8
JA
355 ipo = calloc(1, sizeof(*ipo));
356 init_ipo(ipo);
357 fileno = trace_add_file(td, t->device, &bs);
358
359 ipo->delay = ttime / 1000;
360 ipo->ddir = DDIR_SYNC;
361 ipo->fileno = fileno;
362
811f5421 363 ios[DDIR_SYNC]++;
65c42cc8
JA
364 dprint(FD_BLKTRACE, "store flush delay=%lu\n", ipo->delay);
365 queue_io_piece(td, ipo);
366}
367
691c8fb0
JA
368/*
369 * We only care for queue traces, most of the others are side effects
370 * due to internal workings of the block layer.
371 */
372static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
24653680 373 unsigned long *ios, unsigned int *bs)
691c8fb0 374{
24653680 375 static unsigned long long last_ttime;
0c63576e 376 unsigned long long delay = 0;
24653680 377
691c8fb0
JA
378 if ((t->action & 0xffff) != __BLK_TA_QUEUE)
379 return;
24653680
JA
380
381 if (!(t->action & BLK_TC_ACT(BLK_TC_NOTIFY))) {
6dd7fa77 382 if (!last_ttime || td->o.no_stall)
24653680 383 delay = 0;
6dd7fa77 384 else if (td->o.replay_time_scale == 100)
24653680 385 delay = t->time - last_ttime;
6dd7fa77
JA
386 else {
387 double tmp = t->time - last_ttime;
388 double scale;
389
390 scale = (double) 100.0 / (double) td->o.replay_time_scale;
391 tmp *= scale;
392 delay = tmp;
24653680 393 }
6dd7fa77 394 last_ttime = t->time;
24653680 395 }
691c8fb0 396
0c63576e
JA
397 t_bytes_align(&td->o, t);
398
691c8fb0 399 if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
aec2de20 400 handle_trace_notify(t);
ff58fced 401 else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
24653680 402 handle_trace_discard(td, t, delay, ios, bs);
65c42cc8 403 else if (t->action & BLK_TC_ACT(BLK_TC_FLUSH))
811f5421 404 handle_trace_flush(td, t, delay, ios);
691c8fb0 405 else
24653680 406 handle_trace_fs(td, t, delay, ios, bs);
691c8fb0
JA
407}
408
d95b34a6
JA
409static void byteswap_trace(struct blk_io_trace *t)
410{
411 t->magic = fio_swap32(t->magic);
412 t->sequence = fio_swap32(t->sequence);
413 t->time = fio_swap64(t->time);
414 t->sector = fio_swap64(t->sector);
415 t->bytes = fio_swap32(t->bytes);
416 t->action = fio_swap32(t->action);
417 t->pid = fio_swap32(t->pid);
418 t->device = fio_swap32(t->device);
419 t->cpu = fio_swap32(t->cpu);
420 t->error = fio_swap16(t->error);
421 t->pdu_len = fio_swap16(t->pdu_len);
422}
423
b153f94a 424static bool t_is_write(struct blk_io_trace *t)
24653680
JA
425{
426 return (t->action & BLK_TC_ACT(BLK_TC_WRITE | BLK_TC_DISCARD)) != 0;
427}
428
a6eaf6c9
JA
429static enum fio_ddir t_get_ddir(struct blk_io_trace *t)
430{
431 if (t->action & BLK_TC_ACT(BLK_TC_READ))
432 return DDIR_READ;
433 else if (t->action & BLK_TC_ACT(BLK_TC_WRITE))
434 return DDIR_WRITE;
435 else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
436 return DDIR_TRIM;
437
438 return DDIR_INVAL;
439}
440
441static void depth_inc(struct blk_io_trace *t, int *depth)
442{
443 enum fio_ddir ddir;
444
445 ddir = t_get_ddir(t);
446 if (ddir != DDIR_INVAL)
447 depth[ddir]++;
448}
449
450static void depth_dec(struct blk_io_trace *t, int *depth)
451{
452 enum fio_ddir ddir;
453
454 ddir = t_get_ddir(t);
455 if (ddir != DDIR_INVAL)
456 depth[ddir]--;
457}
458
459static void depth_end(struct blk_io_trace *t, int *this_depth, int *depth)
460{
461 enum fio_ddir ddir = DDIR_INVAL;
462
463 ddir = t_get_ddir(t);
464 if (ddir != DDIR_INVAL) {
465 depth[ddir] = max(depth[ddir], this_depth[ddir]);
466 this_depth[ddir] = 0;
467 }
468}
469
8c1fdf04
JA
470/*
471 * Load a blktrace file by reading all the blk_io_trace entries, and storing
472 * them as io_pieces like the fio text version would do.
473 */
b153f94a 474bool load_blktrace(struct thread_data *td, const char *filename, int need_swap)
fb7b71a3
JA
475{
476 struct blk_io_trace t;
811f5421
JA
477 unsigned long ios[DDIR_RWDIR_SYNC_CNT] = { };
478 unsigned int rw_bs[DDIR_RWDIR_CNT] = { };
479 unsigned long skipped_writes;
e2887563 480 struct fifo *fifo;
811f5421 481 int fd, i, old_state, max_depth;
89ac1d48 482 struct fio_file *f;
811f5421
JA
483 int this_depth[DDIR_RWDIR_CNT] = { };
484 int depth[DDIR_RWDIR_CNT] = { };
fb7b71a3
JA
485
486 fd = open(filename, O_RDONLY);
487 if (fd < 0) {
488 td_verror(td, errno, "open blktrace file");
b153f94a 489 return false;
fb7b71a3
JA
490 }
491
e2887563
JA
492 fifo = fifo_alloc(TRACE_FIFO_SIZE);
493
8edd973d 494 old_state = td_bump_runstate(td, TD_SETTING_UP);
5903e7b7 495
6df8adaa 496 td->o.size = 0;
4241ea8f 497 skipped_writes = 0;
fb7b71a3 498 do {
e2887563 499 int ret = trace_fifo_get(td, fifo, fd, &t, sizeof(t));
fb7b71a3 500
e2887563 501 if (ret < 0)
8c1fdf04 502 goto err;
e2887563
JA
503 else if (!ret)
504 break;
505 else if (ret < (int) sizeof(t)) {
506 log_err("fio: short fifo get\n");
fb7b71a3 507 break;
fb7b71a3
JA
508 }
509
d95b34a6
JA
510 if (need_swap)
511 byteswap_trace(&t);
512
fb7b71a3 513 if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
5ec10eaa
JA
514 log_err("fio: bad magic in blktrace data: %x\n",
515 t.magic);
8c1fdf04 516 goto err;
fb7b71a3
JA
517 }
518 if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) {
5ec10eaa
JA
519 log_err("fio: bad blktrace version %d\n",
520 t.magic & 0xff);
8c1fdf04 521 goto err;
fb7b71a3 522 }
f12b323f
JA
523 ret = discard_pdu(td, fifo, fd, &t);
524 if (ret < 0) {
fb7b71a3 525 td_verror(td, ret, "blktrace lseek");
8c1fdf04 526 goto err;
f12b323f
JA
527 } else if (t.pdu_len != ret) {
528 log_err("fio: discarded %d of %d\n", ret, t.pdu_len);
529 goto err;
fb7b71a3 530 }
691c8fb0 531 if ((t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) == 0) {
eb5fdcf1 532 if ((t.action & 0xffff) == __BLK_TA_QUEUE)
a6eaf6c9
JA
533 depth_inc(&t, this_depth);
534 else if (((t.action & 0xffff) == __BLK_TA_BACKMERGE) ||
535 ((t.action & 0xffff) == __BLK_TA_FRONTMERGE))
536 depth_dec(&t, this_depth);
537 else if ((t.action & 0xffff) == __BLK_TA_COMPLETE)
538 depth_end(&t, this_depth, depth);
691c8fb0 539
24653680 540 if (t_is_write(&t) && read_only) {
691c8fb0 541 skipped_writes++;
24653680 542 continue;
64bbb865 543 }
a6edd638 544 }
24653680
JA
545
546 handle_trace(td, &t, ios, rw_bs);
fb7b71a3
JA
547 } while (1);
548
3643a1f2 549 for_each_file(td, f, i)
89ac1d48 550 trace_add_open_close_event(td, f->fileno, FIO_LOG_CLOSE_FILE);
89ac1d48 551
38470f85 552 fifo_free(fifo);
fb7b71a3 553 close(fd);
8c1fdf04 554
8edd973d 555 td_restore_runstate(td, old_state);
5903e7b7 556
f01b34ae
JA
557 if (!td->files_index) {
558 log_err("fio: did not find replay device(s)\n");
b153f94a 559 return false;
f01b34ae
JA
560 }
561
eb5fdcf1
JA
562 /*
563 * For stacked devices, we don't always get a COMPLETE event so
564 * the depth grows to insane values. Limit it to something sane(r).
565 */
a6eaf6c9
JA
566 max_depth = 0;
567 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
568 if (depth[i] > 1024)
569 depth[i] = 1024;
570 else if (!depth[i] && ios[i])
571 depth[i] = 1;
572 max_depth = max(depth[i], max_depth);
573 }
eb5fdcf1 574
4241ea8f 575 if (skipped_writes)
5ec10eaa
JA
576 log_err("fio: %s skips replay of %lu writes due to read-only\n",
577 td->o.name, skipped_writes);
4241ea8f 578
811f5421
JA
579 if (!ios[DDIR_READ] && !ios[DDIR_WRITE] && !ios[DDIR_TRIM] &&
580 !ios[DDIR_SYNC]) {
8c1fdf04 581 log_err("fio: found no ios in blktrace data\n");
b153f94a 582 return false;
24653680 583 } else if (ios[DDIR_READ] && !ios[DDIR_WRITE]) {
8c1fdf04 584 td->o.td_ddir = TD_DDIR_READ;
d84f8d49
JA
585 td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
586 } else if (!ios[DDIR_READ] && ios[DDIR_WRITE]) {
8c1fdf04 587 td->o.td_ddir = TD_DDIR_WRITE;
d84f8d49
JA
588 td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
589 } else {
8c1fdf04 590 td->o.td_ddir = TD_DDIR_RW;
d84f8d49
JA
591 td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
592 td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
24653680 593 td->o.max_bs[DDIR_TRIM] = rw_bs[DDIR_TRIM];
d84f8d49 594 }
8c1fdf04
JA
595
596 /*
597 * We need to do direct/raw ios to the device, to avoid getting
76a00ec6
JA
598 * read-ahead in our way. But only do so if the minimum block size
599 * is a multiple of 4k, otherwise we don't know if it's safe to do so.
8c1fdf04 600 */
76a00ec6 601 if (!fio_option_is_set(&td->o, odirect) && !(td_min_bs(td) & 4095))
a6eaf6c9 602 td->o.odirect = 1;
8c1fdf04 603
eb5fdcf1 604 /*
8a16f59b 605 * If depth wasn't manually set, use probed depth
eb5fdcf1 606 */
8a16f59b 607 if (!fio_option_is_set(&td->o, iodepth))
a6eaf6c9 608 td->o.iodepth = td->o.iodepth_low = max_depth;
eb5fdcf1 609
b153f94a 610 return true;
8c1fdf04
JA
611err:
612 close(fd);
38470f85 613 fifo_free(fifo);
b153f94a 614 return false;
fb7b71a3 615}