Plug a free basic memory leaks
[fio.git] / init.c
diff --git a/init.c b/init.c
index b330925c0067e856d3e9ddbda94d42013139bf45..fa1df8e7e760eac9c7a37f7d8afaa3ff9614c6cd 100644 (file)
--- a/init.c
+++ b/init.c
@@ -100,7 +100,7 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
        },
        {
                .name           = (char *) "minimal",
-               .has_arg        = optional_argument,
+               .has_arg        = no_argument,
                .val            = 'm' | FIO_CLIENT_FLAG,
        },
        {
@@ -207,6 +207,11 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
                .has_arg        = no_argument,
                .val            = 'T',
        },
+       {
+               .name           = (char *) "crctest",
+               .has_arg        = optional_argument,
+               .val            = 'G',
+       },
        {
                .name           = (char *) "idle-prof",
                .has_arg        = required_argument,
@@ -245,6 +250,7 @@ void free_shm(void)
                free_threads_shm();
        }
 
+       options_free(fio_options, &def_thread);
        scleanup();
 }
 
@@ -621,6 +627,26 @@ static int fixup_options(struct thread_data *td)
        if (td->o.random_distribution != FIO_RAND_DIST_RANDOM)
                td->o.norandommap = 1;
 
+       /*
+        * If size is set but less than the min block size, complain
+        */
+       if (o->size && o->size < td_min_bs(td)) {
+               log_err("fio: size too small, must be larger than the IO size: %llu\n", (unsigned long long) o->size);
+               ret = 1;
+       }
+
+       /*
+        * O_ATOMIC implies O_DIRECT
+        */
+       if (td->o.oatomic)
+               td->o.odirect = 1;
+
+       /*
+        * If randseed is set, that overrides randrepeat
+        */
+       if (td->o.rand_seed)
+               td->o.rand_repeatable = 0;
+
        return ret;
 }
 
@@ -693,6 +719,10 @@ static void td_fill_rand_seeds_os(struct thread_data *td)
                td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number;
 
        os_random_seed(td->rand_seeds[FIO_RAND_BLOCK_OFF], &td->random_state);
+
+       os_random_seed(td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], &td->seq_rand_state[DDIR_READ]);
+       os_random_seed(td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF], &td->seq_rand_state[DDIR_WRITE]);
+       os_random_seed(td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF], &td->seq_rand_state[DDIR_TRIM]);
 }
 
 static void td_fill_rand_seeds_internal(struct thread_data *td)
@@ -714,6 +744,9 @@ static void td_fill_rand_seeds_internal(struct thread_data *td)
                td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number;
 
        init_rand_seed(&td->__random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF]);
+       init_rand_seed(&td->__seq_rand_state[DDIR_READ], td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF]);
+       init_rand_seed(&td->__seq_rand_state[DDIR_WRITE], td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF]);
+       init_rand_seed(&td->__seq_rand_state[DDIR_TRIM], td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF]);
 }
 
 void td_fill_rand_seeds(struct thread_data *td)
@@ -739,6 +772,10 @@ int ioengine_load(struct thread_data *td)
         */
        if (td->io_ops)
                return 0;
+       if (!td->o.ioengine) {
+               log_err("fio: internal fault, no IO engine specified\n");
+               return 1;
+       }
 
        engine = get_engine_name(td->o.ioengine);
        td->io_ops = load_ioengine(td, engine);
@@ -805,10 +842,15 @@ static int setup_random_seeds(struct thread_data *td)
        unsigned long seed;
        unsigned int i;
 
-       if (!td->o.rand_repeatable)
+       if (!td->o.rand_repeatable && !td->o.rand_seed)
                return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds));
 
-       for (seed = 0x89, i = 0; i < 4; i++)
+       if (!td->o.rand_seed)
+               seed = 0x89;
+       else
+               seed = td->o.rand_seed;
+
+       for (i = 0; i < 4; i++)
                seed *= 0x9e370001UL;
 
        for (i = 0; i < FIO_RAND_NR_OFFS; i++) {
@@ -896,6 +938,12 @@ static char *make_filename(char *buf, struct thread_options *o,
 
        return buf;
 }
+
+int parse_dryrun(void)
+{
+       return dump_cmdline || parse_only;
+}
+
 /*
  * Adds a job to the list of things todo. Sanitizes the various options
  * to make sure we don't have conflicts, and initializes various
@@ -920,7 +968,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
        /*
         * if we are just dumping the output command line, don't add the job
         */
-       if (dump_cmdline || parse_only) {
+       if (parse_dryrun()) {
                put_job(td);
                return 0;
        }
@@ -1016,20 +1064,31 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                                fio_server_send_add_job(td);
 
                        if (!(td->io_ops->flags & FIO_NOIO)) {
-                               char *c1, *c2, *c3, *c4, *c5, *c6;
+                               char *c1, *c2, *c3, *c4;
+                               char *c5 = NULL, *c6 = NULL;
 
                                c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
                                c2 = fio_uint_to_kmg(o->max_bs[DDIR_READ]);
                                c3 = fio_uint_to_kmg(o->min_bs[DDIR_WRITE]);
                                c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
-                               c5 = fio_uint_to_kmg(o->min_bs[DDIR_TRIM]);
-                               c6 = fio_uint_to_kmg(o->max_bs[DDIR_TRIM]);
-
-                               log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s/%s-%s,"
-                                        " ioengine=%s, iodepth=%u\n",
-                                               td->o.name, td->groupid,
-                                               ddir_str(o->td_ddir),
-                                               c1, c2, c3, c4, c5, c6,
+
+                               if (!o->bs_is_seq_rand) {
+                                       c5 = fio_uint_to_kmg(o->min_bs[DDIR_TRIM]);
+                                       c6 = fio_uint_to_kmg(o->max_bs[DDIR_TRIM]);
+                               }
+
+                               log_info("%s: (g=%d): rw=%s, ", td->o.name,
+                                                       td->groupid,
+                                                       ddir_str(o->td_ddir));
+
+                               if (o->bs_is_seq_rand)
+                                       log_info("bs(seq/rand)=%s-%s/%s-%s, ",
+                                                       c1, c2, c3, c4);
+                               else
+                                       log_info("bs=%s-%s/%s-%s/%s-%s, ",
+                                                       c1, c2, c3, c4, c5, c6);
+
+                               log_info("ioengine=%s, iodepth=%u\n",
                                                td->io_ops->name, o->iodepth);
 
                                free(c1);
@@ -1104,9 +1163,9 @@ void add_job_opts(const char **o, int client_type)
                        td = get_new_job(0, td_parent, 0);
                }
                if (in_global)
-                       fio_options_parse(td_parent, (char **) &o[i], 1);
+                       fio_options_parse(td_parent, (char **) &o[i], 1, 0);
                else
-                       fio_options_parse(td, (char **) &o[i], 1);
+                       fio_options_parse(td, (char **) &o[i], 1, 0);
                i++;
        }
 
@@ -1243,7 +1302,7 @@ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
                }
 
                /*
-                * Seperate multiple job files by a stonewall
+                * Separate multiple job files by a stonewall
                 */
                if (!global && stonewall) {
                        td->o.stonewall = stonewall;
@@ -1287,14 +1346,10 @@ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
                        num_opts++;
                }
 
-               ret = fio_options_parse(td, opts, num_opts);
-               if (!ret) {
-                       if (dump_cmdline)
-                               for (i = 0; i < num_opts; i++)
-                                       log_info("--%s ", opts[i]);
-
+               ret = fio_options_parse(td, opts, num_opts, dump_cmdline);
+               if (!ret)
                        ret = add_job(td, name, 0, 0, type);
-               else {
+               else {
                        log_err("fio: job %s dropped\n", name);
                        put_job(td);
                }
@@ -1344,7 +1399,7 @@ static void usage(const char *name)
        printf("%s [options] [job options] <job file(s)>\n", name);
        printf("  --debug=options\tEnable debug logging. May be one/more of:\n"
                "\t\t\tprocess,file,io,mem,blktrace,verify,random,parse,\n"
-               "\t\t\tdiskutil,job,mutex,profile,time,net\n");
+               "\t\t\tdiskutil,job,mutex,profile,time,net,rate\n");
        printf("  --parse-only\t\tParse options only, don't start any IO\n");
        printf("  --output\t\tWrite output to file\n");
        printf("  --runtime\t\tRuntime in seconds\n");
@@ -1356,6 +1411,7 @@ static void usage(const char *name)
        printf("  --version\t\tPrint version info and exit\n");
        printf("  --help\t\tPrint this page\n");
        printf("  --cpuclock-test\tPerform test/validation of CPU clock\n");
+       printf("  --crctest\t\tTest speed of checksum functions\n");
        printf("  --cmdhelp=cmd\t\tPrint command help, \"all\" for all of"
                " them\n");
        printf("  --enghelp=engine\tPrint ioengine help, or list"
@@ -1383,7 +1439,8 @@ static void usage(const char *name)
                "\t\t\t(option=system,percpu) or run unit work\n"
                "\t\t\tcalibration only (option=calibrate)\n");
        printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
-       printf("\n                   Jens Axboe <jaxboe@fusionio.com>\n");
+       printf("\n                   Jens Axboe <jaxboe@fusionio.com>");
+       printf("\n                   Jens Axboe <axboe@fb.com>\n");
 }
 
 #ifdef FIO_INC_DEBUG
@@ -1444,6 +1501,10 @@ struct debug_level debug_levels[] = {
          .help = "Network logging",
          .shift = FD_NET,
        },
+       { .name = "rate",
+         .help = "Rate logging",
+         .shift = FD_RATE,
+       },
        { .name = NULL, },
 };
 
@@ -1550,6 +1611,8 @@ void parse_cmd_client(void *client, char *opt)
        fio_client_add_cmd_option(client, opt);
 }
 
+extern int fio_crctest(const char *);
+
 int parse_cmd_line(int argc, char *argv[], int client_type)
 {
        struct thread_data *td = NULL;
@@ -1598,6 +1661,12 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        output_format = FIO_OUTPUT_TERSE;
                        break;
                case 'F':
+                       if (!optarg) {
+                               log_err("fio: missing --output-format argument\n");
+                               exit_val = 1;
+                               do_exit++;
+                               break;
+                       }
                        if (!strcmp(optarg, "minimal") ||
                            !strcmp(optarg, "terse") ||
                            !strcmp(optarg, "csv"))
@@ -1715,9 +1784,20 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                fio_options_set_ioengine_opts(l_opts, td);
                        }
 
-                       ret = fio_cmd_option_parse(td, opt, val);
-                       if (ret)
+                       if ((!val || !strlen(val)) &&
+                           l_opts[lidx].has_arg == required_argument) {
+                               log_err("fio: option %s requires an argument\n", opt);
+                               ret = 1;
+                       } else
+                               ret = fio_cmd_option_parse(td, opt, val);
+
+                       if (ret) {
+                               if (td) {
+                                       put_job(td);
+                                       td = NULL;
+                               }
                                do_exit++;
+                       }
 
                        if (!ret && !strcmp(opt, "ioengine")) {
                                free_ioengine(td);
@@ -1730,8 +1810,6 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                case FIO_GETOPT_IOENGINE: {
                        const char *opt = l_opts[lidx].name;
                        char *val = optarg;
-                       opt = l_opts[lidx].name;
-                       val = optarg;
                        ret = fio_cmd_ioengine_option_parse(td, opt, val);
                        break;
                }
@@ -1799,6 +1877,10 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        do_exit++;
                        exit_val = fio_monotonic_clocktest();
                        break;
+               case 'G':
+                       do_exit++;
+                       exit_val = fio_crctest(optarg);
+                       break;
                case 'L': {
                        long long val;
 
@@ -1823,10 +1905,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        break;
        }
 
-       if (do_exit) {
-               if (exit_val && !(is_backend || nr_clients))
-                       exit(exit_val);
-       }
+       if (do_exit && !(is_backend || nr_clients))
+               exit(exit_val);
 
        if (nr_clients && fio_clients_connect()) {
                do_exit++;
@@ -1907,7 +1987,7 @@ int parse_options(int argc, char *argv[])
        fio_options_free(&def_thread);
 
        if (!thread_number) {
-               if (dump_cmdline || parse_only)
+               if (parse_dryrun())
                        return 0;
                if (exec_profile)
                        return 0;