*/
#include <stdio.h>
#include <stdlib.h>
-#include <sys/ioctl.h>
#include <unistd.h>
-#include <linux/fs.h>
#include "flist.h"
#include "fio.h"
ret = read(fd, buf, total);
if (ret < 0) {
- td_verror(td, errno, "read blktrace file");
- return -1;
+ int read_err = errno;
+
+ assert(read_err > 0);
+ td_verror(td, read_err, "read blktrace file");
+ return -read_err;
}
if (ret > 0)
flist_add_tail(&ipo->list, &td->io_log_list);
}
-static int get_dev_blocksize(const char *dev, unsigned int *bs)
+static int trace_add_file(struct thread_data *td, __u32 device)
{
- int fd;
-
- fd = open(dev, O_RDONLY);
- if (fd < 0)
- return 1;
-
- if (ioctl(fd, BLKSSZGET, bs) < 0) {
- close(fd);
- return 1;
- }
-
- close(fd);
- return 0;
-}
-
-static int trace_add_file(struct thread_data *td, __u32 device,
- unsigned int *bs)
-{
- static unsigned int last_maj, last_min, last_fileno, last_bs;
+ static unsigned int last_maj, last_min, last_fileno;
unsigned int maj = FMAJOR(device);
unsigned int min = FMINOR(device);
struct fio_file *f;
- unsigned int i;
char dev[256];
+ unsigned int i;
- if (last_maj == maj && last_min == min) {
- *bs = last_bs;
+ if (last_maj == maj && last_min == min)
return last_fileno;
- }
last_maj = maj;
last_min = min;
/*
* check for this file in our list
*/
- for_each_file(td, f, i) {
+ for_each_file(td, f, i)
if (f->major == maj && f->minor == min) {
last_fileno = f->fileno;
- last_bs = f->bs;
- goto out;
+ return last_fileno;
}
- }
strcpy(dev, "/dev");
if (blktrace_lookup_device(td->o.replay_redirect, dev, maj, min)) {
- unsigned int this_bs;
int fileno;
if (td->o.replay_redirect)
dprint(FD_BLKTRACE, "add devices %s\n", dev);
fileno = add_file_exclusive(td, dev);
-
- if (get_dev_blocksize(dev, &this_bs))
- this_bs = 512;
-
td->o.open_files++;
td->files[fileno]->major = maj;
td->files[fileno]->minor = min;
- td->files[fileno]->bs = this_bs;
trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
-
last_fileno = fileno;
- last_bs = this_bs;
}
-out:
- *bs = last_bs;
return last_fileno;
}
*/
static void store_ipo(struct thread_data *td, unsigned long long offset,
unsigned int bytes, int rw, unsigned long long ttime,
- int fileno, unsigned int bs)
+ int fileno)
{
struct io_piece *ipo;
ipo = calloc(1, sizeof(*ipo));
init_ipo(ipo);
- ipo->offset = offset * bs;
+ ipo->offset = offset * 512;
if (td->o.replay_scale)
ipo->offset = ipo->offset / td->o.replay_scale;
ipo_bytes_align(td->o.replay_align, ipo);
static void handle_trace_discard(struct thread_data *td,
struct blk_io_trace *t,
unsigned long long ttime,
- unsigned long *ios, unsigned int *rw_bs)
+ unsigned long *ios, unsigned int *bs)
{
struct io_piece *ipo;
- unsigned int bs;
int fileno;
if (td->o.replay_skip & (1u << DDIR_TRIM))
ipo = calloc(1, sizeof(*ipo));
init_ipo(ipo);
- fileno = trace_add_file(td, t->device, &bs);
+ fileno = trace_add_file(td, t->device);
ios[DDIR_TRIM]++;
- if (t->bytes > rw_bs[DDIR_TRIM])
- rw_bs[DDIR_TRIM] = t->bytes;
+ if (t->bytes > bs[DDIR_TRIM])
+ bs[DDIR_TRIM] = t->bytes;
td->o.size += t->bytes;
INIT_FLIST_HEAD(&ipo->list);
- ipo->offset = t->sector * bs;
+ ipo->offset = t->sector * 512;
if (td->o.replay_scale)
ipo->offset = ipo->offset / td->o.replay_scale;
ipo_bytes_align(td->o.replay_align, ipo);
static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
unsigned long long ttime, unsigned long *ios,
- unsigned int *rw_bs)
+ unsigned int *bs)
{
- unsigned int bs;
int rw;
int fileno;
- fileno = trace_add_file(td, t->device, &bs);
+ fileno = trace_add_file(td, t->device);
rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
return;
}
- if (t->bytes > rw_bs[rw])
- rw_bs[rw] = t->bytes;
+ if (t->bytes > bs[rw])
+ bs[rw] = t->bytes;
ios[rw]++;
td->o.size += t->bytes;
- store_ipo(td, t->sector, t->bytes, rw, ttime, fileno, bs);
+ store_ipo(td, t->sector, t->bytes, rw, ttime, fileno);
}
static void handle_trace_flush(struct thread_data *td, struct blk_io_trace *t,
unsigned long long ttime, unsigned long *ios)
{
struct io_piece *ipo;
- unsigned int bs;
int fileno;
if (td->o.replay_skip & (1u << DDIR_SYNC))
ipo = calloc(1, sizeof(*ipo));
init_ipo(ipo);
- fileno = trace_add_file(td, t->device, &bs);
+ fileno = trace_add_file(td, t->device);
ipo->delay = ttime / 1000;
ipo->ddir = DDIR_SYNC;
}
ret = discard_pdu(td, fifo, fd, &t);
if (ret < 0) {
- td_verror(td, ret, "blktrace lseek");
+ td_verror(td, -ret, "blktrace lseek");
goto err;
} else if (t.pdu_len != ret) {
log_err("fio: discarded %d of %d\n", ret, t.pdu_len);
!ios[DDIR_SYNC]) {
log_err("fio: found no ios in blktrace data\n");
return false;
- } else if (ios[DDIR_READ] && !ios[DDIR_WRITE]) {
- td->o.td_ddir = TD_DDIR_READ;
- td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
- } else if (!ios[DDIR_READ] && ios[DDIR_WRITE]) {
- td->o.td_ddir = TD_DDIR_WRITE;
- td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
- } else {
- td->o.td_ddir = TD_DDIR_RW;
+ }
+
+ td->o.td_ddir = 0;
+ if (ios[DDIR_READ]) {
+ td->o.td_ddir |= TD_DDIR_READ;
td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
+ }
+ if (ios[DDIR_WRITE]) {
+ td->o.td_ddir |= TD_DDIR_WRITE;
td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
+ }
+ if (ios[DDIR_TRIM]) {
+ td->o.td_ddir |= TD_DDIR_TRIM;
td->o.max_bs[DDIR_TRIM] = rw_bs[DDIR_TRIM];
}
t_get_ddir(t) == DDIR_INVAL) {
ret = discard_pdu(td, bc->fifo, bc->fd, t);
if (ret < 0) {
- td_verror(td, ret, "blktrace lseek");
+ td_verror(td, -ret, "blktrace lseek");
return ret;
} else if (t->pdu_len != ret) {
log_err("fio: discarded %d of %d\n", ret,
/* setup output file */
merge_fp = fopen(td->o.merge_blktrace_file, "w");
merge_buf = malloc(128 * 1024);
+ if (!merge_buf)
+ goto err_out_file;
ret = setvbuf(merge_fp, merge_buf, _IOFBF, 128 * 1024);
if (ret)
- goto err_out_file;
+ goto err_merge_buf;
/* setup input files */
str = ptr = strdup(td->o.read_iolog_file);
if (bcs[i].fd < 0) {
log_err("fio: could not open file: %s\n", name);
ret = bcs[i].fd;
+ free(str);
goto err_file;
}
bcs[i].fifo = fifo_alloc(TRACE_FIFO_SIZE);
if (!is_blktrace(name, &bcs[i].swap)) {
log_err("fio: file is not a blktrace: %s\n", name);
+ free(str);
goto err_file;
}
ret = read_trace(td, &bcs[i]);
if (ret < 0) {
+ free(str);
goto err_file;
} else if (!ret) {
merge_finish_file(bcs, i, &nr_logs);
/* skip over the pdu */
ret = discard_pdu(td, bc->fifo, bc->fd, &bc->t);
if (ret < 0) {
- td_verror(td, ret, "blktrace lseek");
+ td_verror(td, -ret, "blktrace lseek");
goto err_file;
} else if (bc->t.pdu_len != ret) {
log_err("fio: discarded %d of %d\n", ret,
fifo_free(bcs[i].fifo);
close(bcs[i].fd);
}
+err_merge_buf:
+ free(merge_buf);
err_out_file:
fflush(merge_fp);
fclose(merge_fp);