[PATCH] ini parser user friendliness
[fio.git] / init.c
diff --git a/init.c b/init.c
index 46c513223481238e41dd10791007c646b89e9e7f..d259c998c39215c3e0914b5aa1a57829bd464f9f 100644 (file)
--- a/init.c
+++ b/init.c
@@ -578,7 +578,7 @@ static int str_rw_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
-       fprintf(stderr, "bad data direction: %s\n", mem);
+       fprintf(stderr, "fio: data direction: read, write, randread, randwrite, rw, randrw\n");
        return 1;
 }
 
@@ -595,7 +595,7 @@ static int str_verify_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
-       fprintf(stderr, "bad verify type: %s\n", mem);
+       fprintf(stderr, "fio: verify types: md5, crc32\n");
        return 1;
 }
 
@@ -612,7 +612,7 @@ static int str_mem_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
-       fprintf(stderr, "bad mem type: %s\n", mem);
+       fprintf(stderr, "fio: mem type: malloc, shm, mmap\n");
        return 1;
 }
 
@@ -645,34 +645,13 @@ static int str_ioengine_cb(struct thread_data *td, char *str)
                return 0;
        }
 
-       fprintf(stderr, "bad ioengine type: %s\n", str);
+       fprintf(stderr, "fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice\n");
        return 1;
 }
 
-static int str_iolog_cb(struct thread_data *td, char *file)
-{
-       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;
-}
-
-static int str_iosched_cb(struct thread_data *td, char *file)
-{
-       td->ioscheduler = strdup(file);
-       return 0;
-}
-
+/*
+ * This is our [ini] type file parser.
+ */
 int parse_jobs_ini(char *file)
 {
        unsigned int prioclass, prio, cpu, global, il;
@@ -683,6 +662,7 @@ int parse_jobs_ini(char *file)
        fpos_t off;
        FILE *f;
        char *p;
+       int ret = 0;
 
        f = fopen(file, "r");
        if (!f) {
@@ -695,6 +675,8 @@ int parse_jobs_ini(char *file)
        tmpbuf = malloc(4096);
 
        while ((p = fgets(string, 4096, f)) != NULL) {
+               if (ret)
+                       break;
                if (is_empty_or_comment(p))
                        continue;
                if (sscanf(p, "[%s]", name) != 1)
@@ -705,8 +687,10 @@ int parse_jobs_ini(char *file)
                name[strlen(name) - 1] = '\0';
 
                td = get_new_job(global, &def_thread);
-               if (!td)
-                       return 1;
+               if (!td) {
+                       ret = 1;
+                       break;
+               }
 
                fgetpos(f, &off);
                while ((p = fgets(string, 4096, f)) != NULL) {
@@ -720,7 +704,8 @@ int parse_jobs_ini(char *file)
                        if (!check_int(p, "prio", &prio)) {
 #ifndef FIO_HAVE_IOPRIO
                                fprintf(stderr, "io priorities not available\n");
-                               return 1;
+                               ret = 1;
+                               break;
 #endif
                                td->ioprio |= prio;
                                fgetpos(f, &off);
@@ -729,7 +714,8 @@ int parse_jobs_ini(char *file)
                        if (!check_int(p, "prioclass", &prioclass)) {
 #ifndef FIO_HAVE_IOPRIO
                                fprintf(stderr, "io priorities not available\n");
-                               return 1;
+                               ret = 1;
+                               break;
 #endif
                                td->ioprio |= prioclass << IOPRIO_CLASS_SHIFT;
                                fgetpos(f, &off);
@@ -758,7 +744,8 @@ int parse_jobs_ini(char *file)
                        if (!check_int(p, "cpumask", &cpu)) {
 #ifndef FIO_HAVE_CPU_AFFINITY
                                fprintf(stderr, "cpu affinity not available\n");
-                               return 1;
+                               ret = 1;
+                               break;
 #endif
                                fill_cpu_mask(td->cpumask, cpu);
                                fgetpos(f, &off);
@@ -921,45 +908,58 @@ int parse_jobs_ini(char *file)
                                fgetpos(f, &off);
                                continue;
                        }
-                       if (!check_str(p, "iolog", str_iolog_cb, td)) {
+                       if (!check_strstore(p, "iolog", tmpbuf)) {
+                               td->iolog_file = strdup(tmpbuf);
                                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)) {
+                           !check_strstore(p, "write_iolog", tmpbuf)) {
+                               td->iolog_file = strdup(tmpbuf);
                                td->write_iolog = 1;
                                fgetpos(f, &off);
                                continue;
                        }
-                       if (!check_str(p, "exec_prerun", str_prerun_cb, td)) {
+                       if (!check_strstore(p, "exec_prerun", tmpbuf)) {
+                               td->exec_prerun = strdup(tmpbuf);
                                fgetpos(f, &off);
                                continue;
                        }
-                       if (!check_str(p, "exec_postrun", str_postrun_cb, td)) {
+                       if (!check_strstore(p, "exec_postrun", tmpbuf)) {
+                               td->exec_postrun = strdup(tmpbuf);
                                fgetpos(f, &off);
                                continue;
                        }
-                       if (!check_str(p, "ioscheduler", str_iosched_cb, td)) {
+                       if (!check_strstore(p, "ioscheduler", tmpbuf)) {
+                               td->ioscheduler = strdup(tmpbuf);
                                fgetpos(f, &off);
                                continue;
                        }
 
+                       /*
+                        * Don't break here, continue parsing options so we
+                        * dump all the bad ones. Makes trial/error fixups
+                        * easier on the user.
+                        */
                        printf("Client%d: bad option %s\n",td->thread_number,p);
-                       return 1;
+                       ret = 1;
                }
-               fsetpos(f, &off);
 
-               if (add_job(td, name, 0))
-                       return 1;
+               if (!ret) {
+                       fsetpos(f, &off);
+                       ret = add_job(td, name, 0);
+               }
+               if (ret)
+                       break;
        }
 
        free(string);
        free(name);
        free(tmpbuf);
        fclose(f);
-       return 0;
+       return ret;
 }
 
 static int fill_def_thread(void)
@@ -1132,10 +1132,8 @@ int parse_options(int argc, char *argv[])
                return 1;
        }
 
-       if (parse_jobs_ini(ini_file)) {
-               usage(argv[0]);
+       if (parse_jobs_ini(ini_file))
                return 1;
-       }
 
        return 0;
 }