Merge branch 'master' of ssh://router/data/git/fio
authorJens Axboe <jens.axboe@oracle.com>
Fri, 23 Mar 2007 17:31:49 +0000 (18:31 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 23 Mar 2007 17:31:49 +0000 (18:31 +0100)
filesetup.c
fio.c
fio.h
init.c
options.c

index 1426b151085b1553af318cdf58ecdc47ce84fb14..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;
 }
@@ -569,14 +570,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);
 
@@ -654,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.c b/fio.c
index 9fabbe93bc53a7887cc6457371b55ea202ff3ebc..f6c3fc8fe555ca31e78b7eb1666dfa6ac27185f7 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -878,6 +878,7 @@ err:
        close_files(td);
        close_ioengine(td);
        cleanup_io_u(td);
+       options_mem_free(td);
        td_set_runstate(td, TD_EXITED);
        return (void *) (unsigned long) td->error;
 err_sem:
diff --git a/fio.h b/fio.h
index d0629ece3fe6d3f2463a22fbc4dd16628c1ce2ae..736fefb1dd0c6256b98f8a73864af6982ee493ac 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -691,6 +691,8 @@ extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
 extern void fio_fill_default_options(struct thread_data *);
 extern int fio_show_option_help(const char *);
 extern void fio_options_dup_and_init(struct option *);
+extern void options_mem_dupe(struct thread_data *);
+extern void options_mem_free(struct thread_data *);
 #define FIO_GETOPT_JOB         0x89988998
 #define FIO_NR_OPTIONS         128
 
@@ -708,6 +710,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 27040326424a10ebc992e70c5fdc9929801309d9..c1f774d8e03f42df01dd5c0298a2013d0ba6343b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -115,6 +115,9 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent)
        td = &threads[thread_number++];
        *td = *parent;
 
+       dup_files(td, parent);
+       options_mem_dupe(td);
+
        td->thread_number = thread_number;
        return td;
 }
@@ -358,7 +361,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 +371,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 +413,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;
@@ -808,6 +802,7 @@ int parse_options(int argc, char *argv[])
        }
 
        free(ini_file);
+       options_mem_free(&def_thread);
 
        if (!thread_number) {
                log_err("No jobs defined(s)\n");
index 4f30f2c1991aaf8769e2802d4dceef7cb0d83a34..7d4396e81d1aa637748bd135c52e520c09beb7ca 100644 (file)
--- a/options.c
+++ b/options.c
@@ -864,3 +864,39 @@ int fio_show_option_help(const char *opt)
 {
        return show_cmd_help(options, opt);
 }
+
+static void __options_mem(struct thread_data *td, int alloc)
+{
+       struct thread_options *o = &td->o;
+       struct fio_option *opt;
+       char **ptr;
+       int i;
+
+       for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
+               if (opt->type != FIO_OPT_STR_STORE)
+                       continue;
+
+               ptr = (void *) o + opt->off1;
+               if (*ptr) {
+                       if (alloc)
+                               *ptr = strdup(*ptr);
+                       else {
+                               free(*ptr);
+                               *ptr = NULL;
+                       }
+               }
+       }
+}
+
+/*
+ * dupe FIO_OPT_STR_STORE options
+ */
+void options_mem_dupe(struct thread_data *td)
+{
+       __options_mem(td, 1);
+}
+
+void options_mem_free(struct thread_data *td)
+{
+       __options_mem(td, 0);
+}