From: Jens Axboe Date: Thu, 6 Mar 2008 09:26:25 +0000 (+0100) Subject: Multiple file handling fixes X-Git-Tag: fio-1.20-rc2~7 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=9efef3c4bd6a032a2a9f7a9aab1c29436525d781;ds=sidebyside Multiple file handling fixes Some of that got broken with the dynamically allocated file changes. Signed-off-by: Jens Axboe --- diff --git a/filesetup.c b/filesetup.c index 4d2017db..08c365d9 100644 --- a/filesetup.c +++ b/filesetup.c @@ -233,6 +233,7 @@ static int file_lookup_open(struct fio_file *f, int flags) __f = lookup_file_hash(f->file_name); if (__f) { + dprint(FD_FILE, "found file in hash %s\n", f->file_name); /* * racy, need the __f->lock locked */ @@ -244,6 +245,7 @@ static int file_lookup_open(struct fio_file *f, int flags) f->references++; from_hash = 1; } else { + dprint(FD_FILE, "file not found in hash %s\n", f->file_name); f->fd = open(f->file_name, flags, 0600); from_hash = 0; } @@ -383,6 +385,8 @@ static int get_file_sizes(struct thread_data *td) int err = 0; for_each_file(td, f, i) { + dprint(FD_FILE, "get file size for %p/%d/%p\n", f, i, f->file_name); + if (td->io_ops->open_file(td, f)) { if (td->error != ENOENT) { log_err("%s\n", td->verror); @@ -596,6 +600,7 @@ void close_and_free_files(struct thread_data *td) td->o.filename = NULL; free(td->files); + td->files_index = 0; td->files = NULL; td->o.nr_files = 0; } @@ -631,8 +636,9 @@ int add_file(struct thread_data *td, const char *fname) f = smalloc(sizeof(*f)); f->fd = -1; - td->files = realloc(td->files, (cur_files + 1) * sizeof(f)); + dprint(FD_FILE, "resize file array to %d files\n", cur_files + 1); + td->files = realloc(td->files, (cur_files + 1) * sizeof(f)); td->files[cur_files] = f; /* @@ -667,6 +673,8 @@ int add_file(struct thread_data *td, const char *fname) if (f->filetype == FIO_TYPE_FILE) td->nr_normal_files++; + dprint(FD_FILE, "file %p \"%s\" added at %d\n", f, f->file_name, cur_files); + return cur_files; } @@ -820,16 +828,15 @@ void dup_files(struct thread_data *td, struct thread_data *org) { struct fio_file *f; unsigned int i; - size_t bytes; + + dprint(FD_FILE, "dup files: %d\n", org->files_index); if (!org->files) return; - bytes = org->files_index * sizeof(f); - td->files = malloc(bytes); - memcpy(td->files, org->files, bytes); + td->files = malloc(org->files_index * sizeof(f)); - for_each_file(td, f, i) { + for_each_file(org, f, i) { struct fio_file *__f; __f = smalloc(sizeof(*__f)); diff --git a/fio.h b/fio.h index b22009b9..e7e32cc7 100644 --- a/fio.h +++ b/fio.h @@ -961,7 +961,7 @@ extern void close_ioengine(struct thread_data *); #define for_each_td(td, i) \ for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++) #define for_each_file(td, f, i) \ - for ((i) = 0, (f) = (td)->files[0]; (i) < (td)->o.nr_files; (i)++, (f)++) + for ((i) = 0, (f) = (td)->files[0]; (i) < (td)->o.nr_files; (i)++, (f) = (td)->files[i]) #define fio_assert(td, cond) do { \ if (!(cond)) { \