X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=blktrace.c;h=64a610a95944c9ec1e5d4fdaba56b987e24c7943;hp=772a0c768b0a7f58db80d4b79b31a613bfb1f31e;hb=d9137307bc621280dcb1738e5df5d5ee4269a665;hpb=4d2707ef027cc5b2418ab5de622318e0f70c096a diff --git a/blktrace.c b/blktrace.c index 772a0c76..64a610a9 100644 --- a/blktrace.c +++ b/blktrace.c @@ -3,9 +3,7 @@ */ #include #include -#include #include -#include #include "flist.h" #include "fio.h" @@ -30,8 +28,11 @@ static int refill_fifo(struct thread_data *td, struct fifo *fifo, int fd) 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) @@ -129,37 +130,17 @@ static void trace_add_open_close_event(struct thread_data *td, int fileno, enum flist_add_tail(&ipo->list, &td->io_log_list); } -static int get_dev_blocksize(const char *dev, unsigned int *bs) -{ - 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 int trace_add_file(struct thread_data *td, __u32 device) { - 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; @@ -167,17 +148,14 @@ static int trace_add_file(struct thread_data *td, __u32 device, /* * 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) @@ -189,22 +167,13 @@ static int trace_add_file(struct thread_data *td, __u32 device, 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; } @@ -221,14 +190,14 @@ static void t_bytes_align(struct thread_options *o, struct blk_io_trace *t) */ 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); @@ -268,10 +237,9 @@ static void handle_trace_notify(struct blk_io_trace *t) 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)) @@ -279,17 +247,17 @@ static void handle_trace_discard(struct thread_data *td, 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); @@ -311,13 +279,12 @@ static void dump_trace(struct blk_io_trace *t) 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; @@ -335,19 +302,18 @@ static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t, 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)) @@ -355,7 +321,7 @@ static void handle_trace_flush(struct thread_data *td, struct blk_io_trace *t, 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; @@ -523,7 +489,7 @@ bool load_blktrace(struct thread_data *td, const char *filename, int need_swap) } 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); @@ -581,16 +547,19 @@ bool load_blktrace(struct thread_data *td, const char *filename, int need_swap) !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]; } @@ -697,7 +666,7 @@ read_skip: 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, @@ -750,9 +719,11 @@ int merge_blktrace_iologs(struct thread_data *td) /* 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); @@ -762,6 +733,7 @@ int merge_blktrace_iologs(struct thread_data *td) 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); @@ -769,11 +741,13 @@ int merge_blktrace_iologs(struct thread_data *td) 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); @@ -789,7 +763,7 @@ int merge_blktrace_iologs(struct thread_data *td) /* 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, @@ -815,10 +789,11 @@ err_file: fifo_free(bcs[i].fifo); close(bcs[i].fd); } +err_merge_buf: + free(merge_buf); err_out_file: fflush(merge_fp); fclose(merge_fp); - free(merge_buf); err_param: free(bcs);