[PATCH] Get closer to FreeBSD compile
[fio.git] / init.c
diff --git a/init.c b/init.c
index 5c5a918312db06e3d39a251b08fac8197e746aef..d02056cc12b08cd837165ed57ee5679abd6a3421 100644 (file)
--- a/init.c
+++ b/init.c
@@ -55,55 +55,6 @@ int write_bw_log = 0;
 int exitall_on_terminate = 0;
 unsigned long long mlock_size = 0;
 
-static int setup_rate(struct thread_data *td)
-{
-       int nr_reads_per_sec;
-
-       if (!td->rate)
-               return 0;
-
-       if (td->rate < td->ratemin) {
-               fprintf(stderr, "min rate larger than nominal rate\n");
-               return -1;
-       }
-
-       nr_reads_per_sec = (td->rate * 1024) / td->min_bs;
-       td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
-       td->rate_pending_usleep = 0;
-       return 0;
-}
-
-static void setup_log(struct io_log **log)
-{
-       struct io_log *l = malloc(sizeof(*l));
-
-       l->nr_samples = 0;
-       l->max_samples = 1024;
-       l->log = malloc(l->max_samples * sizeof(struct io_sample));
-       *log = l;
-}
-
-void finish_log(struct thread_data *td, struct io_log *log, const char *name)
-{
-       char file_name[256];
-       FILE *f;
-       unsigned int i;
-
-       snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
-       f = fopen(file_name, "w");
-       if (!f) {
-               perror("fopen log");
-               return;
-       }
-
-       for (i = 0; i < log->nr_samples; i++)
-               fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);
-
-       fclose(f);
-       free(log->log);
-       free(log);
-}
-
 static struct thread_data *get_new_job(int global, struct thread_data *parent)
 {
        struct thread_data *td;
@@ -578,7 +529,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 +546,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 +563,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,10 +596,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;
 }
 
+/*
+ * This is our [ini] type file parser.
+ */
 int parse_jobs_ini(char *file)
 {
        unsigned int prioclass, prio, cpu, global, il;
@@ -659,6 +613,7 @@ int parse_jobs_ini(char *file)
        fpos_t off;
        FILE *f;
        char *p;
+       int ret = 0;
 
        f = fopen(file, "r");
        if (!f) {
@@ -671,6 +626,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)
@@ -681,8 +638,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) {
@@ -696,7 +655,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);
@@ -705,7 +665,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);
@@ -734,7 +695,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);
@@ -922,25 +884,39 @@ int parse_jobs_ini(char *file)
                                continue;
                        }
                        if (!check_strstore(p, "ioscheduler", tmpbuf)) {
+#ifndef FIO_HAVE_IOSCHED_SWITCH
+                               fprintf(stderr, "io scheduler switching not available\n");
+                               ret = 1;
+                               break;
+#else
                                td->ioscheduler = strdup(tmpbuf);
                                fgetpos(f, &off);
                                continue;
+#endif
                        }
 
+                       /*
+                        * 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)
@@ -1113,10 +1089,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;
 }