From 49ffb4a2e1ac3026d77d9e1c03edc2753fcec41b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 24 Aug 2010 15:01:37 +0200 Subject: [PATCH] Fix blktrace replay We would add duplicate files, if the open event comes before the add file event. Make sure we return the current index file instead of adding a duplicate, this causes bad file lookups. Signed-off-by: Jens Axboe --- blktrace.c | 2 +- file.h | 1 + filesetup.c | 13 +++++++++++++ log.c | 1 - 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/blktrace.c b/blktrace.c index ef3e18fd..68ba964a 100644 --- a/blktrace.c +++ b/blktrace.c @@ -187,7 +187,7 @@ static void trace_add_file(struct thread_data *td, __u32 device) int fileno; dprint(FD_BLKTRACE, "add devices %s\n", dev); - fileno = add_file(td, dev); + fileno = add_file_exclusive(td, dev); trace_add_open_event(td, fileno); } } diff --git a/file.h b/file.h index 3b4ed0b9..63494653 100644 --- a/file.h +++ b/file.h @@ -140,6 +140,7 @@ extern int __must_check generic_close_file(struct thread_data *, struct fio_file extern int __must_check generic_get_file_size(struct thread_data *, struct fio_file *); extern int __must_check pre_read_files(struct thread_data *); extern int add_file(struct thread_data *, const char *); +extern int add_file_exclusive(struct thread_data *, const char *); extern void get_file(struct fio_file *); extern int __must_check put_file(struct thread_data *, struct fio_file *); extern void put_file_log(struct thread_data *, struct fio_file *); diff --git a/filesetup.c b/filesetup.c index d2b74d7f..5a8105a6 100644 --- a/filesetup.c +++ b/filesetup.c @@ -963,6 +963,19 @@ int add_file(struct thread_data *td, const char *fname) return cur_files; } +int add_file_exclusive(struct thread_data *td, const char *fname) +{ + struct fio_file *f; + unsigned int i; + + for_each_file(td, f, i) { + if (!strcmp(f->file_name, fname)) + return i; + } + + return add_file(td, fname); +} + void get_file(struct fio_file *f) { dprint(FD_FILE, "get file %s, ref=%d\n", f->file_name, f->references); diff --git a/log.c b/log.c index 80d3742f..4a64132c 100644 --- a/log.c +++ b/log.c @@ -131,7 +131,6 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u) io_u->buflen = ipo->len; io_u->file = td->files[ipo->fileno]; get_file(io_u->file); - dprint(FD_IO, "iolog: get %llu/%lu/%s\n", io_u->offset, io_u->buflen, io_u->file->file_name); if (ipo->delay) iolog_delay(td, ipo->delay); -- 2.25.1