Make sure the ->files array is job private
[fio.git] / filesetup.c
index f6e2a19c19b74a0fa175b710440c699712344466..d8b7401b35e0230d9f40afe53dcbfcd5e84b83e1 100644 (file)
@@ -523,15 +523,15 @@ void close_files(struct thread_data *td)
        unsigned int i;
 
        for_each_file(td, f, i) {
-               if (!f->file_name && (f->flags & FIO_FILE_UNLINK) &&
-                   f->filetype == FIO_TYPE_FILE) {
+               if ((f->flags & FIO_FILE_UNLINK) &&
+                   f->filetype == FIO_TYPE_FILE)
                        unlink(f->file_name);
-                       free(f->file_name);
-                       f->file_name = NULL;
-               }
 
                td_io_close_file(td, f);
 
+               free(f->file_name);
+               f->file_name = NULL;
+
                if (f->file_map) {
                        free(f->file_map);
                        f->file_map = NULL;
@@ -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);
+       }
+}