[PATCH] Add exec_prerun/exec_postrun options
[fio.git] / fio-ini.c
index 38d60a2d7dcff820af84989d2e8511f625d38762..0c874085f466002c5893c994914ead475d412f4a 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -40,7 +40,7 @@
 #define DEF_RWMIX_READ         (50)
 #define DEF_NICE               (0)
 
-static char fio_version_string[] = "fio 1.3";
+static char fio_version_string[] = "fio 1.4";
 
 static int repeatable = DEF_RAND_REPEAT;
 static char *ini_file;
@@ -216,7 +216,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        }
 
        if (td->filetype == FIO_TYPE_FILE) {
-               if (td->directory[0] != '\0')
+               if (td->directory && td->directory[0] != '\0')
                        sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->jobnum);
                else
                        sprintf(td->file_name, "%s.%d", jobname, td->jobnum);
@@ -406,8 +406,12 @@ typedef int (str_cb_fn)(struct thread_data *, char *);
 
 static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
 {
-       char *s = strstr(p, name);
+       char *s;
 
+       if (strncmp(p, name, strlen(name)))
+               return 1;
+
+       s = strstr(p, name);
        if (!s)
                return 1;
 
@@ -422,8 +426,12 @@ static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
 
 static int check_strstore(char *p, char *name, char *dest)
 {
-       char *s = strstr(p, name);
+       char *s;
 
+       if (strncmp(p, name, strlen(name)))
+               return 1;
+
+       s = strstr(p, name);
        if (!s)
                return 1;
 
@@ -458,6 +466,9 @@ static int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
        char option[128];
        char *str, *p1, *p2;
 
+       if (strncmp(p, name, strlen(name)))
+               return 1;
+
        strcpy(option, p);
        p = option;
 
@@ -637,8 +648,19 @@ static int str_ioengine_cb(struct thread_data *td, char *str)
 
 static int str_iolog_cb(struct thread_data *td, char *file)
 {
-       strncpy(td->iolog_file, file, sizeof(td->iolog_file) - 1);
+       td->iolog_file = strdup(file);
+       return 0;
+}
 
+static int str_prerun_cb(struct thread_data *td, char *file)
+{
+       td->exec_prerun = strdup(file);
+       return 0;
+}
+
+static int str_postrun_cb(struct thread_data *td, char *file)
+{
+       td->exec_postrun = strdup(file);
        return 0;
 }
 
@@ -648,7 +670,7 @@ int parse_jobs_ini(char *file)
        unsigned long long ull;
        unsigned long ul1, ul2;
        struct thread_data *td;
-       char *string, *name;
+       char *string, *name, *tmpbuf;
        fpos_t off;
        FILE *f;
        char *p;
@@ -661,6 +683,7 @@ int parse_jobs_ini(char *file)
 
        string = malloc(4096);
        name = malloc(256);
+       tmpbuf = malloc(4096);
 
        while ((p = fgets(string, 4096, f)) != NULL) {
                if (is_empty_or_comment(p))
@@ -843,7 +866,8 @@ int parse_jobs_ini(char *file)
                                fgetpos(f, &off);
                                continue;
                        }
-                       if (!check_strstore(p, "directory", td->directory)) {
+                       if (!check_strstore(p, "directory", tmpbuf)) {
+                               td->directory = strdup(tmpbuf);
                                fgetpos(f, &off);
                                continue;
                        }
@@ -884,7 +908,22 @@ int parse_jobs_ini(char *file)
                                continue;
                        }
                        if (!check_str(p, "iolog", str_iolog_cb, td)) {
-                               td->iolog = 1;
+                               td->read_iolog = 1;
+                               td->write_iolog = 0;
+                               fgetpos(f, &off);
+                               continue;
+                       }
+                       if (!td->read_iolog &&
+                           !check_str(p, "write_iolog", str_iolog_cb, td)) {
+                               td->write_iolog = 1;
+                               fgetpos(f, &off);
+                               continue;
+                       }
+                       if (!check_str(p, "exec_prerun", str_prerun_cb, td)) {
+                               fgetpos(f, &off);
+                               continue;
+                       }
+                       if (!check_str(p, "exec_postrun", str_postrun_cb, td)) {
                                fgetpos(f, &off);
                                continue;
                        }
@@ -900,6 +939,7 @@ int parse_jobs_ini(char *file)
 
        free(string);
        free(name);
+       free(tmpbuf);
        fclose(f);
        return 0;
 }