Ensure that job name is set before being used
authorJens Axboe <axboe@fb.com>
Tue, 24 Jun 2014 15:19:30 +0000 (09:19 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 24 Jun 2014 15:19:30 +0000 (09:19 -0600)
Andreas reports:

When passing the --readonly option, with the following write job (and
probably with any write job), I get an error message with a NULL job
name. Job description used:

[write]
thread
bs=64k
direct=1
ioengine=sync
size=128m
filename=test.tmp
rw=write
do_verify=0

Reported-by: Andreas Gr├╝nbacher <andreas.gruenbacher@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
init.c

diff --git a/init.c b/init.c
index d44eb5b1eaa2fb086afe25b3a6bda335320decf7..6b29aa702407a69799f54ff15a60011a105be5d8 100644 (file)
--- a/init.c
+++ b/init.c
@@ -342,7 +342,7 @@ static void set_cmd_options(struct thread_data *td)
  * Return a free job structure.
  */
 static struct thread_data *get_new_job(int global, struct thread_data *parent,
-                                      int preserve_eo)
+                                      int preserve_eo, const char *jobname)
 {
        struct thread_data *td;
 
@@ -376,6 +376,9 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent,
 
        td->thread_number = thread_number;
 
+       if (jobname)
+               td->o.name = strdup(jobname);
+
        if (!parent->o.group_reporting)
                stat_number++;
 
@@ -398,6 +401,9 @@ static void put_job(struct thread_data *td)
        if (td->io_ops)
                free_ioengine(td);
 
+       if (td->o.name)
+               free(td->o.name);
+
        memset(&threads[td->thread_number - 1], 0, sizeof(*td));
        thread_number--;
 }
@@ -1202,7 +1208,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
         */
        numjobs = o->numjobs;
        while (--numjobs) {
-               struct thread_data *td_new = get_new_job(0, td, 1);
+               struct thread_data *td_new = get_new_job(0, td, 1, jobname);
 
                if (!td_new)
                        goto err;
@@ -1260,11 +1266,11 @@ void add_job_opts(const char **o, int client_type)
                        sprintf(jobname, "%s", o[i] + 5);
                }
                if (in_global && !td_parent)
-                       td_parent = get_new_job(1, &def_thread, 0);
+                       td_parent = get_new_job(1, &def_thread, 0, jobname);
                else if (!in_global && !td) {
                        if (!td_parent)
                                td_parent = &def_thread;
-                       td = get_new_job(0, td_parent, 0);
+                       td = get_new_job(0, td_parent, 0, jobname);
                }
                if (in_global)
                        fio_options_parse(td_parent, (char **) &o[i], 1, 0);
@@ -1399,7 +1405,7 @@ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
                        first_sect = 0;
                }
 
-               td = get_new_job(global, &def_thread, 0);
+               td = get_new_job(global, &def_thread, 0, name);
                if (!td) {
                        ret = 1;
                        break;
@@ -1895,7 +1901,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                if (is_section && skip_this_section(val))
                                        continue;
 
-                               td = get_new_job(global, &def_thread, 1);
+                               td = get_new_job(global, &def_thread, 1, NULL);
                                if (!td || ioengine_load(td)) {
                                        if (td) {
                                                put_job(td);