init.c: Fix non-regular-file booboo
[fio.git] / init.c
diff --git a/init.c b/init.c
index eee23359afc68d209366d7f95cb1c5242de111bf..624d2842d69b2e576487357d9d6f44e4443f650c 100644 (file)
--- a/init.c
+++ b/init.c
@@ -623,6 +623,8 @@ FILE *f_err = NULL;
 static int write_lat_log = 0;
 int write_bw_log = 0;
 
+static int prev_group_jobs;
+
 FILE *get_f_out()
 {
        return f_out;
@@ -804,6 +806,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        int numjobs, i;
        struct fio_file *f;
        const char *engine;
+       int fn_given;
 
        /*
         * the def_thread is just for options, it's not a real job
@@ -826,6 +829,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (td->odirect)
                td->io_ops->flags |= FIO_RAWIO;
 
+       fn_given = (long) td->filename;
        if (!td->filename)
                td->filename = strdup(jobname);
 
@@ -839,12 +843,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
 
        fixup_options(td);
 
-       if (td->filename)
+       if (fn_given)
                td->nr_uniq_files = 1;
        else
                td->nr_uniq_files = td->open_files;
 
-       if (td->filetype == FIO_TYPE_FILE || td->filename) {
+       if (td->filetype == FIO_TYPE_FILE) {
                char tmp[PATH_MAX];
                int len = 0;
 
@@ -867,10 +871,10 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        memset(f, 0, sizeof(*f));
                        f->fd = -1;
 
-                       if (td->filename)
+                       if (fn_given)
                                sprintf(tmp + len, "%s", td->filename);
                        else
-                               sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
+                               sprintf(tmp + len, "%s.%d.%d", td->filename, td->thread_number, i);
                        f->file_name = strdup(tmp);
                }
        } else {
@@ -880,7 +884,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
 
                memset(f, 0, sizeof(*f));
                f->fd = -1;
-               f->file_name = strdup(jobname);
+               f->file_name = strdup(td->filename);
        }
 
        for_each_file(td, f, i) {
@@ -894,10 +898,13 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
        td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
 
-       if (td->stonewall && td->thread_number > 1)
+       if ((td->stonewall || td->numjobs > 1) && prev_group_jobs) {
+               prev_group_jobs = 0;
                groupid++;
+       }
 
        td->groupid = groupid;
+       prev_group_jobs++;
 
        if (setup_rate(td))
                goto err;
@@ -953,6 +960,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                if (add_job(td_new, jobname, job_add_num))
                        goto err;
        }
+
+       if (td->numjobs > 1) {
+               groupid++;
+               prev_group_jobs = 0;
+       }
+
        return 0;
 err:
        put_job(td);