From bd0ee748e96338ace7b22b6f0ac1f8934d3385c0 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 23 Mar 2007 14:26:23 +0100 Subject: [PATCH] Fix bug with numjobs > 1, directory and filename given Reported by gurudas pai If numjobs > 1, add_job() will append the directory name several times. Fix this by doing the directory append in add_file() instead, it cleans up the code as well. Signed-off-by: Jens Axboe --- filesetup.c | 9 ++++++++- init.c | 9 --------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/filesetup.c b/filesetup.c index 1426b151..f6e2a19c 100644 --- a/filesetup.c +++ b/filesetup.c @@ -569,14 +569,21 @@ static void get_file_type(struct fio_file *f) void add_file(struct thread_data *td, const char *fname) { int cur_files = td->files_index; + char file_name[PATH_MAX]; struct fio_file *f; + int len = 0; td->files = realloc(td->files, (cur_files + 1) * sizeof(*f)); f = &td->files[cur_files]; memset(f, 0, sizeof(*f)); f->fd = -1; - f->file_name = strdup(fname); + + if (td->o.directory) + len = sprintf(file_name, "%s/", td->o.directory); + + sprintf(file_name + len, "%s", fname); + f->file_name = strdup(file_name); get_file_type(f); diff --git a/init.c b/init.c index 27040326..1e0eeccf 100644 --- a/init.c +++ b/init.c @@ -358,7 +358,6 @@ static int init_random_state(struct thread_data *td) return 0; } - /* * Adds a job to the list of things todo. Sanitizes the various options * to make sure we don't have conflicts, and initializes various @@ -369,7 +368,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) const char *ddir_str[] = { NULL, "read", "write", "rw", NULL, "randread", "randwrite", "randrw" }; unsigned int i; - struct fio_file *f; const char *engine; char fname[PATH_MAX]; int numjobs, file_alloced; @@ -412,13 +410,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) if (fixup_options(td)) goto err; - for_each_file(td, f, i) { - if (td->o.directory && f->filetype == FIO_TYPE_FILE) { - sprintf(fname, "%s/%s", td->o.directory, f->file_name); - f->file_name = strdup(fname); - } - } - td->mutex = fio_sem_init(0); td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX; -- 2.25.1