Start of client/server
[fio.git] / init.c
diff --git a/init.c b/init.c
index a920c6ed87e71e8b0399708fcb12ac0d6361c88a..5d5709110c22d1519becdbbd5d9082dc0f853b06 100644 (file)
--- a/init.c
+++ b/init.c
 #include "filehash.h"
 #include "verify.h"
 #include "profile.h"
+#include "server.h"
 
 #include "lib/getopt.h"
 
-static char fio_version_string[] = "fio 1.57";
+static char fio_version_string[] = "fio 1.58";
 
 #define FIO_RANDSEED           (0xb1899bedUL)
 
@@ -43,6 +44,8 @@ char **job_sections = NULL;
 int nr_job_sections = 0;
 char *exec_profile = NULL;
 int warnings_fatal = 0;
+int terse_version = 2;
+int is_backend = 0;
 
 int write_bw_log = 0;
 int read_only = 0;
@@ -147,6 +150,16 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
                .has_arg        = required_argument,
                .val            = 'j',
        },
+       {
+               .name           = (char *) "terse-version",
+               .has_arg        = required_argument,
+               .val            = 'V',
+       },
+       {
+               .name           = (char *) "server",
+               .has_arg        = no_argument,
+               .val            = 'S',
+       },
        {
                .name           = NULL,
        },
@@ -515,6 +528,8 @@ void td_fill_rand_seeds(struct thread_data *td)
                td_fill_rand_seeds_os(td);
        else
                td_fill_rand_seeds_internal(td);
+
+       init_rand_seed(&td->buf_state, td->rand_seeds[7]);
 }
 
 /*
@@ -791,7 +806,7 @@ static int is_empty_or_comment(char *line)
 /*
  * This is our [ini] type file parser.
  */
-static int parse_jobs_ini(char *file, int stonewall_flag)
+int parse_jobs_ini(char *file, int is_buf, int stonewall_flag)
 {
        unsigned int global;
        struct thread_data *td;
@@ -805,14 +820,18 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
        char **opts;
        int i, alloc_opts, num_opts;
 
-       if (!strcmp(file, "-"))
-               f = stdin;
-       else
-               f = fopen(file, "r");
+       if (is_buf)
+               f = NULL;
+       else {
+               if (!strcmp(file, "-"))
+                       f = stdin;
+               else
+                       f = fopen(file, "r");
 
-       if (!f) {
-               perror("fopen job file");
-               return 1;
+               if (!f) {
+                       perror("fopen job file");
+                       return 1;
+               }
        }
 
        string = malloc(4096);
@@ -834,7 +853,10 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
                 * haven't handled.
                 */
                if (!skip_fgets) {
-                       p = fgets(string, 4095, f);
+                       if (is_buf)
+                               p = strsep(&file, "\n");
+                       else
+                               p = fgets(string, 4095, f);
                        if (!p)
                                break;
                }
@@ -888,7 +910,14 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
                num_opts = 0;
                memset(opts, 0, alloc_opts * sizeof(char *));
 
-               while ((p = fgets(string, 4096, f)) != NULL) {
+               while (1) {
+                       if (is_buf)
+                               p = strsep(&file, "\n");
+                       else
+                               p = fgets(string, 4096, f);
+                       if (!p)
+                               break;
+
                        if (is_empty_or_comment(p))
                                continue;
 
@@ -941,7 +970,7 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
        free(string);
        free(name);
        free(opts);
-       if (f != stdin)
+       if (!is_buf && f != stdin)
                fclose(f);
        return ret;
 }
@@ -1036,6 +1065,7 @@ static void usage(const char *name)
        printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
        printf("\t--minimal\tMinimal (terse) output\n");
        printf("\t--version\tPrint version info and exit\n");
+       printf("\t--terse-version=x Terse version output format\n");
        printf("\t--help\t\tPrint this page\n");
        printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of"
                " them\n");
@@ -1197,6 +1227,14 @@ static int parse_cmd_line(int argc, char *argv[])
                case 'v':
                        log_info("%s\n", fio_version_string);
                        exit(0);
+               case 'V':
+                       terse_version = atoi(optarg);
+                       if (terse_version != 2) {
+                               log_err("fio: bad terse version format\n");
+                               exit_val = 1;
+                               do_exit++;
+                       }
+                       break;
                case 'e':
                        if (!strcmp("always", optarg))
                                eta_print = FIO_ETA_ALWAYS;
@@ -1265,6 +1303,9 @@ static int parse_cmd_line(int argc, char *argv[])
                                exit_val = 1;
                        }
                        break;
+               case 'S':
+                       is_backend = 1;
+                       break;
                default:
                        do_exit++;
                        exit_val = 1;
@@ -1275,6 +1316,9 @@ static int parse_cmd_line(int argc, char *argv[])
        if (do_exit)
                exit(exit_val);
 
+       if (is_backend)
+               fio_server();
+
        if (td) {
                if (!ret)
                        ret = add_job(td, td->o.name ?: "fio", 0);
@@ -1310,7 +1354,7 @@ int parse_options(int argc, char *argv[])
        for (i = 0; i < job_files; i++) {
                if (fill_def_thread())
                        return 1;
-               if (parse_jobs_ini(ini_file[i], i))
+               if (parse_jobs_ini(ini_file[i], 0, i))
                        return 1;
                free(ini_file[i]);
        }