Make sure the ->files array is job private
authorJens Axboe <jens.axboe@oracle.com>
Fri, 23 Mar 2007 14:29:45 +0000 (15:29 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 23 Mar 2007 14:29:45 +0000 (15:29 +0100)
Otherwise we introduce differences between threads and processes,
we don't want to do that.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
filesetup.c
fio.h
init.c

index 137afac..d8b7401 100644 (file)
@@ -539,6 +539,7 @@ void close_files(struct thread_data *td)
        }
 
        td->o.filename = NULL;
+       free(td->files);
        td->files = NULL;
        td->o.nr_files = 0;
 }
@@ -661,3 +662,22 @@ int add_dir_files(struct thread_data *td, const char *path)
 {
        return recurse_dir(td, path);
 }
+
+void dup_files(struct thread_data *td, struct thread_data *org)
+{
+       struct fio_file *f;
+       unsigned int i;
+       size_t bytes;
+
+       if (!org->files)
+               return;
+
+       bytes = org->files_index * sizeof(*f);
+       td->files = malloc(bytes);
+       memcpy(td->files, org->files, bytes);
+
+       for_each_file(td, f, i) {
+               if (f->file_name)
+                       f->file_name = strdup(f->file_name);
+       }
+}
diff --git a/fio.h b/fio.h
index d0629ec..8a79289 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -708,6 +708,7 @@ extern void get_file(struct fio_file *);
 extern void put_file(struct thread_data *, struct fio_file *);
 extern int add_dir_files(struct thread_data *, const char *);
 extern int init_random_map(struct thread_data *);
+extern void dup_files(struct thread_data *, struct thread_data *);
 
 /*
  * ETA/status stuff
diff --git a/init.c b/init.c
index 1e0eecc..e5d776c 100644 (file)
--- a/init.c
+++ b/init.c
@@ -115,6 +115,8 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent)
        td = &threads[thread_number++];
        *td = *parent;
 
+       dup_files(td, parent);
+
        td->thread_number = thread_number;
        return td;
 }