2 * This file contains job initialization and setup functions.
12 #include <sys/types.h>
16 #ifndef FIO_NO_HAVE_SHM_H
29 #include "lib/getopt.h"
30 #include "lib/strcasestr.h"
34 const char fio_version_string[] = FIO_VERSION;
36 #define FIO_RANDSEED (0xb1899bedUL)
38 static char **ini_file;
39 static int max_jobs = FIO_MAX_JOBS;
40 static int dump_cmdline;
41 static long long def_timeout;
42 static int parse_only;
44 static struct thread_data def_thread;
45 struct thread_data *threads = NULL;
46 static char **job_sections;
47 static int nr_job_sections;
49 int exitall_on_terminate = 0;
50 int output_format = FIO_OUTPUT_NORMAL;
51 int append_terse_output = 0;
52 int eta_print = FIO_ETA_AUTO;
56 char *exec_profile = NULL;
57 int warnings_fatal = 0;
58 int terse_version = 3;
65 int status_interval = 0;
67 char *trigger_file = NULL;
68 long long trigger_timeout = 0;
69 char *trigger_cmd = NULL;
70 char *trigger_remote_cmd = NULL;
72 char *aux_path = NULL;
74 static int prev_group_jobs;
76 unsigned long fio_debug = 0;
77 unsigned int fio_debug_jobno = -1;
78 unsigned int *fio_debug_jobp = NULL;
80 static char cmd_optstr[256];
83 #define FIO_CLIENT_FLAG (1 << 16)
86 * Command line options. These will contain the above, plus a few
87 * extra that only pertain to fio itself and not jobs.
89 static struct option l_opts[FIO_NR_OPTIONS] = {
91 .name = (char *) "output",
92 .has_arg = required_argument,
93 .val = 'o' | FIO_CLIENT_FLAG,
96 .name = (char *) "timeout",
97 .has_arg = required_argument,
98 .val = 't' | FIO_CLIENT_FLAG,
101 .name = (char *) "latency-log",
102 .has_arg = required_argument,
103 .val = 'l' | FIO_CLIENT_FLAG,
106 .name = (char *) "bandwidth-log",
107 .has_arg = required_argument,
108 .val = 'b' | FIO_CLIENT_FLAG,
111 .name = (char *) "minimal",
112 .has_arg = no_argument,
113 .val = 'm' | FIO_CLIENT_FLAG,
116 .name = (char *) "output-format",
117 .has_arg = optional_argument,
118 .val = 'F' | FIO_CLIENT_FLAG,
121 .name = (char *) "append-terse",
122 .has_arg = optional_argument,
126 .name = (char *) "version",
127 .has_arg = no_argument,
128 .val = 'v' | FIO_CLIENT_FLAG,
131 .name = (char *) "help",
132 .has_arg = no_argument,
133 .val = 'h' | FIO_CLIENT_FLAG,
136 .name = (char *) "cmdhelp",
137 .has_arg = optional_argument,
138 .val = 'c' | FIO_CLIENT_FLAG,
141 .name = (char *) "enghelp",
142 .has_arg = optional_argument,
143 .val = 'i' | FIO_CLIENT_FLAG,
146 .name = (char *) "showcmd",
147 .has_arg = no_argument,
148 .val = 's' | FIO_CLIENT_FLAG,
151 .name = (char *) "readonly",
152 .has_arg = no_argument,
153 .val = 'r' | FIO_CLIENT_FLAG,
156 .name = (char *) "eta",
157 .has_arg = required_argument,
158 .val = 'e' | FIO_CLIENT_FLAG,
161 .name = (char *) "eta-newline",
162 .has_arg = required_argument,
163 .val = 'E' | FIO_CLIENT_FLAG,
166 .name = (char *) "debug",
167 .has_arg = required_argument,
168 .val = 'd' | FIO_CLIENT_FLAG,
171 .name = (char *) "parse-only",
172 .has_arg = no_argument,
173 .val = 'P' | FIO_CLIENT_FLAG,
176 .name = (char *) "section",
177 .has_arg = required_argument,
178 .val = 'x' | FIO_CLIENT_FLAG,
182 .name = (char *) "inflate-log",
183 .has_arg = required_argument,
184 .val = 'X' | FIO_CLIENT_FLAG,
188 .name = (char *) "alloc-size",
189 .has_arg = required_argument,
190 .val = 'a' | FIO_CLIENT_FLAG,
193 .name = (char *) "profile",
194 .has_arg = required_argument,
195 .val = 'p' | FIO_CLIENT_FLAG,
198 .name = (char *) "warnings-fatal",
199 .has_arg = no_argument,
200 .val = 'w' | FIO_CLIENT_FLAG,
203 .name = (char *) "max-jobs",
204 .has_arg = required_argument,
205 .val = 'j' | FIO_CLIENT_FLAG,
208 .name = (char *) "terse-version",
209 .has_arg = required_argument,
210 .val = 'V' | FIO_CLIENT_FLAG,
213 .name = (char *) "server",
214 .has_arg = optional_argument,
217 { .name = (char *) "daemonize",
218 .has_arg = required_argument,
222 .name = (char *) "client",
223 .has_arg = required_argument,
227 .name = (char *) "remote-config",
228 .has_arg = required_argument,
232 .name = (char *) "cpuclock-test",
233 .has_arg = no_argument,
237 .name = (char *) "crctest",
238 .has_arg = optional_argument,
242 .name = (char *) "idle-prof",
243 .has_arg = required_argument,
247 .name = (char *) "status-interval",
248 .has_arg = required_argument,
252 .name = (char *) "trigger-file",
253 .has_arg = required_argument,
257 .name = (char *) "trigger-timeout",
258 .has_arg = required_argument,
262 .name = (char *) "trigger",
263 .has_arg = required_argument,
267 .name = (char *) "trigger-remote",
268 .has_arg = required_argument,
272 .name = (char *) "aux-path",
273 .has_arg = required_argument,
281 void free_threads_shm(void)
285 #ifndef CONFIG_NO_SHM
286 struct shmid_ds sbuf;
290 shmctl(shm_id, IPC_RMID, &sbuf);
299 static void free_shm(void)
304 fio_debug_jobp = NULL;
310 free(trigger_remote_cmd);
311 trigger_file = trigger_cmd = trigger_remote_cmd = NULL;
313 options_free(fio_options, &def_thread);
319 * The thread area is shared between the main process and the job
320 * threads/processes. So setup a shared memory segment that will hold
321 * all the job info. We use the end of the region for keeping track of
322 * open files across jobs, for file sharing.
324 static int setup_thread_area(void)
332 * 1024 is too much on some machines, scale max_jobs if
333 * we get a failure that looks like too large a shm segment
336 size_t size = max_jobs * sizeof(struct thread_data);
338 size += file_hash_size;
339 size += sizeof(unsigned int);
341 #ifndef CONFIG_NO_SHM
342 shm_id = shmget(0, size, IPC_CREAT | 0600);
345 if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC) {
350 threads = malloc(size);
358 #ifndef CONFIG_NO_SHM
362 threads = shmat(shm_id, NULL, 0);
363 if (threads == (void *) -1) {
369 memset(threads, 0, max_jobs * sizeof(struct thread_data));
370 hash = (void *) threads + max_jobs * sizeof(struct thread_data);
371 fio_debug_jobp = (void *) hash + file_hash_size;
372 *fio_debug_jobp = -1;
373 file_hash_init(hash);
380 static void set_cmd_options(struct thread_data *td)
382 struct thread_options *o = &td->o;
385 o->timeout = def_timeout;
389 * Return a free job structure.
391 static struct thread_data *get_new_job(int global, struct thread_data *parent,
392 int preserve_eo, const char *jobname)
394 struct thread_data *td;
397 set_cmd_options(&def_thread);
400 if (setup_thread_area()) {
401 log_err("error: failed to setup shm segment\n");
404 if (thread_number >= max_jobs) {
405 log_err("error: maximum number of jobs (%d) reached.\n",
410 td = &threads[thread_number++];
417 td->o.uid = td->o.gid = -1U;
419 dup_files(td, parent);
420 fio_options_mem_dupe(td);
422 profile_add_hooks(td);
424 td->thread_number = thread_number;
425 td->subjob_number = 0;
428 td->o.name = strdup(jobname);
430 if (!parent->o.group_reporting)
437 static void put_job(struct thread_data *td)
439 if (td == &def_thread)
446 log_info("fio: %s\n", td->verror);
448 fio_options_free(td);
455 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
459 static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
461 unsigned int bs = td->o.min_bs[ddir];
463 assert(ddir_rw(ddir));
465 if (td->o.rate[ddir])
466 td->rate_bps[ddir] = td->o.rate[ddir];
468 td->rate_bps[ddir] = (uint64_t) td->o.rate_iops[ddir] * bs;
470 if (!td->rate_bps[ddir]) {
471 log_err("rate lower than supported\n");
475 td->rate_next_io_time[ddir] = 0;
476 td->rate_io_issue_bytes[ddir] = 0;
480 static int setup_rate(struct thread_data *td)
484 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
485 ret = __setup_rate(td, DDIR_READ);
486 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
487 ret |= __setup_rate(td, DDIR_WRITE);
488 if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM])
489 ret |= __setup_rate(td, DDIR_TRIM);
494 static int fixed_block_size(struct thread_options *o)
496 return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
497 o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
498 o->min_bs[DDIR_TRIM] == o->max_bs[DDIR_TRIM] &&
499 o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE] &&
500 o->min_bs[DDIR_READ] == o->min_bs[DDIR_TRIM];
504 static unsigned long long get_rand_start_delay(struct thread_data *td)
506 unsigned long long delayrange;
510 delayrange = td->o.start_delay_high - td->o.start_delay;
512 frand_max = rand_max(&td->delay_state);
513 r = __rand(&td->delay_state);
514 delayrange = (unsigned long long) ((double) delayrange * (r / (frand_max + 1.0)));
516 delayrange += td->o.start_delay;
521 * Lazy way of fixing up options that depend on each other. We could also
522 * define option callback handlers, but this is easier.
524 static int fixup_options(struct thread_data *td)
526 struct thread_options *o = &td->o;
529 #ifndef FIO_HAVE_PSHARED_MUTEX
530 if (!o->use_thread) {
531 log_info("fio: this platform does not support process shared"
532 " mutexes, forcing use of threads. Use the 'thread'"
533 " option to get rid of this warning.\n");
535 ret = warnings_fatal;
539 if (o->write_iolog_file && o->read_iolog_file) {
540 log_err("fio: read iolog overrides write_iolog\n");
541 free(o->write_iolog_file);
542 o->write_iolog_file = NULL;
543 ret = warnings_fatal;
547 * only really works with 1 file
549 if (o->zone_size && o->open_files > 1)
553 * If zone_range isn't specified, backward compatibility dictates it
554 * should be made equal to zone_size.
556 if (o->zone_size && !o->zone_range)
557 o->zone_range = o->zone_size;
560 * Reads can do overwrites, we always need to pre-create the file
562 if (td_read(td) || td_rw(td))
565 if (!o->min_bs[DDIR_READ])
566 o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
567 if (!o->max_bs[DDIR_READ])
568 o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
569 if (!o->min_bs[DDIR_WRITE])
570 o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
571 if (!o->max_bs[DDIR_WRITE])
572 o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
573 if (!o->min_bs[DDIR_TRIM])
574 o->min_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
575 if (!o->max_bs[DDIR_TRIM])
576 o->max_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
578 o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
579 o->rw_min_bs = min(o->min_bs[DDIR_TRIM], o->rw_min_bs);
582 * For random IO, allow blockalign offset other than min_bs.
584 if (!o->ba[DDIR_READ] || !td_random(td))
585 o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
586 if (!o->ba[DDIR_WRITE] || !td_random(td))
587 o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
588 if (!o->ba[DDIR_TRIM] || !td_random(td))
589 o->ba[DDIR_TRIM] = o->min_bs[DDIR_TRIM];
591 if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
592 o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE] ||
593 o->ba[DDIR_TRIM] != o->min_bs[DDIR_TRIM]) &&
595 log_err("fio: Any use of blockalign= turns off randommap\n");
597 ret = warnings_fatal;
600 if (!o->file_size_high)
601 o->file_size_high = o->file_size_low;
603 if (o->start_delay_high)
604 o->start_delay = get_rand_start_delay(td);
606 if (o->norandommap && o->verify != VERIFY_NONE
607 && !fixed_block_size(o)) {
608 log_err("fio: norandommap given for variable block sizes, "
610 ret = warnings_fatal;
612 if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
613 log_err("fio: bs_unaligned may not work with raw io\n");
616 * thinktime_spin must be less than thinktime
618 if (o->thinktime_spin > o->thinktime)
619 o->thinktime_spin = o->thinktime;
622 * The low water mark cannot be bigger than the iodepth
624 if (o->iodepth_low > o->iodepth || !o->iodepth_low)
625 o->iodepth_low = o->iodepth;
628 * If batch number isn't set, default to the same as iodepth
630 if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
631 o->iodepth_batch = o->iodepth;
634 * If max batch complete number isn't set or set incorrectly,
635 * default to the same as iodepth_batch_complete_min
637 if (o->iodepth_batch_complete_min > o->iodepth_batch_complete_max)
638 o->iodepth_batch_complete_max = o->iodepth_batch_complete_min;
640 if (o->nr_files > td->files_index)
641 o->nr_files = td->files_index;
643 if (o->open_files > o->nr_files || !o->open_files)
644 o->open_files = o->nr_files;
646 if (((o->rate[DDIR_READ] + o->rate[DDIR_WRITE] + o->rate[DDIR_TRIM]) &&
647 (o->rate_iops[DDIR_READ] + o->rate_iops[DDIR_WRITE] + o->rate_iops[DDIR_TRIM])) ||
648 ((o->ratemin[DDIR_READ] + o->ratemin[DDIR_WRITE] + o->ratemin[DDIR_TRIM]) &&
649 (o->rate_iops_min[DDIR_READ] + o->rate_iops_min[DDIR_WRITE] + o->rate_iops_min[DDIR_TRIM]))) {
650 log_err("fio: rate and rate_iops are mutually exclusive\n");
653 if ((o->rate[DDIR_READ] && (o->rate[DDIR_READ] < o->ratemin[DDIR_READ])) ||
654 (o->rate[DDIR_WRITE] && (o->rate[DDIR_WRITE] < o->ratemin[DDIR_WRITE])) ||
655 (o->rate[DDIR_TRIM] && (o->rate[DDIR_TRIM] < o->ratemin[DDIR_TRIM])) ||
656 (o->rate_iops[DDIR_READ] && (o->rate_iops[DDIR_READ] < o->rate_iops_min[DDIR_READ])) ||
657 (o->rate_iops[DDIR_WRITE] && (o->rate_iops[DDIR_WRITE] < o->rate_iops_min[DDIR_WRITE])) ||
658 (o->rate_iops[DDIR_TRIM] && (o->rate_iops[DDIR_TRIM] < o->rate_iops_min[DDIR_TRIM]))) {
659 log_err("fio: minimum rate exceeds rate\n");
663 if (!o->timeout && o->time_based) {
664 log_err("fio: time_based requires a runtime/timeout setting\n");
666 ret = warnings_fatal;
669 if (o->fill_device && !o->size)
672 if (o->verify != VERIFY_NONE) {
673 if (td_write(td) && o->do_verify && o->numjobs > 1) {
674 log_info("Multiple writers may overwrite blocks that "
675 "belong to other jobs. This can cause "
676 "verification failures.\n");
677 ret = warnings_fatal;
680 if (!fio_option_is_set(o, refill_buffers))
681 o->refill_buffers = 1;
683 if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
685 o->verify_interval = o->min_bs[DDIR_WRITE];
688 * Verify interval must be smaller or equal to the
691 if (o->verify_interval > o->min_bs[DDIR_WRITE])
692 o->verify_interval = o->min_bs[DDIR_WRITE];
693 else if (td_read(td) && o->verify_interval > o->min_bs[DDIR_READ])
694 o->verify_interval = o->min_bs[DDIR_READ];
698 o->invalidate_cache = 0;
699 if (td->io_ops->flags & FIO_PIPEIO) {
700 log_info("fio: cannot pre-read files with an IO engine"
701 " that isn't seekable. Pre-read disabled.\n");
702 ret = warnings_fatal;
707 if (td->io_ops->flags & FIO_BIT_BASED)
713 #ifndef CONFIG_FDATASYNC
714 if (o->fdatasync_blocks) {
715 log_info("fio: this platform does not support fdatasync()"
716 " falling back to using fsync(). Use the 'fsync'"
717 " option instead of 'fdatasync' to get rid of"
719 o->fsync_blocks = o->fdatasync_blocks;
720 o->fdatasync_blocks = 0;
721 ret = warnings_fatal;
727 * Windows doesn't support O_DIRECT or O_SYNC with the _open interface,
728 * so fail if we're passed those flags
730 if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) {
731 log_err("fio: Windows does not support direct or non-buffered io with"
732 " the synchronous ioengines. Use the 'windowsaio' ioengine"
733 " with 'direct=1' and 'iodepth=1' instead.\n");
739 * For fully compressible data, just zero them at init time.
740 * It's faster than repeatedly filling it.
742 if (td->o.compress_percentage == 100) {
743 td->o.zero_buffers = 1;
744 td->o.compress_percentage = 0;
748 * Using a non-uniform random distribution excludes usage of
751 if (td->o.random_distribution != FIO_RAND_DIST_RANDOM)
752 td->o.norandommap = 1;
755 * If size is set but less than the min block size, complain
757 if (o->size && o->size < td_min_bs(td)) {
758 log_err("fio: size too small, must be larger than the IO size: %llu\n", (unsigned long long) o->size);
763 * O_ATOMIC implies O_DIRECT
769 * If randseed is set, that overrides randrepeat
771 if (fio_option_is_set(&td->o, rand_seed))
772 td->o.rand_repeatable = 0;
774 if ((td->io_ops->flags & FIO_NOEXTEND) && td->o.file_append) {
775 log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name);
779 if (fio_option_is_set(o, gtod_cpu)) {
781 fio_gtod_set_cpu(o->gtod_cpu);
782 fio_gtod_offload = 1;
785 td->loops = o->loops;
789 if (td->o.block_error_hist && td->o.nr_files != 1) {
790 log_err("fio: block error histogram only available with "
791 "with a single file per job, but %d files "
792 "provided\n", td->o.nr_files);
800 * This function leaks the buffer
802 char *fio_uint_to_kmg(unsigned int val)
804 char *buf = malloc(32);
805 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
816 snprintf(buf, 32, "%u%c", val, *p);
820 /* External engines are specified by "external:name.o") */
821 static const char *get_engine_name(const char *str)
823 char *p = strstr(str, ":");
829 strip_blank_front(&p);
834 static int exists_and_not_file(const char *filename)
838 if (lstat(filename, &sb) == -1)
841 /* \\.\ is the device namespace in Windows, where every file
842 * is a device node */
843 if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
849 static void td_fill_rand_seeds_internal(struct thread_data *td, int use64)
851 init_rand_seed(&td->bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF], use64);
852 init_rand_seed(&td->verify_state, td->rand_seeds[FIO_RAND_VER_OFF], use64);
853 init_rand_seed(&td->rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF], use64);
855 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
856 init_rand_seed(&td->next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF], use64);
858 init_rand_seed(&td->file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF], use64);
859 init_rand_seed(&td->trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF], use64);
860 init_rand_seed(&td->delay_state, td->rand_seeds[FIO_RAND_START_DELAY], use64);
865 if (td->o.rand_repeatable)
866 td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number;
868 init_rand_seed(&td->random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF], use64);
869 init_rand_seed(&td->seq_rand_state[DDIR_READ], td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], use64);
870 init_rand_seed(&td->seq_rand_state[DDIR_WRITE], td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF], use64);
871 init_rand_seed(&td->seq_rand_state[DDIR_TRIM], td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF], use64);
874 void td_fill_rand_seeds(struct thread_data *td)
878 if (td->o.allrand_repeatable) {
881 for (i = 0; i < FIO_RAND_NR_OFFS; i++)
882 td->rand_seeds[i] = FIO_RANDSEED * td->thread_number
886 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64)
891 td_fill_rand_seeds_internal(td, use64);
893 init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF], use64);
894 frand_copy(&td->buf_state_prev, &td->buf_state);
896 init_rand_seed(&td->dedupe_state, td->rand_seeds[FIO_DEDUPE_OFF], use64);
900 * Initializes the ioengine configured for a job, if it has not been done so
903 int ioengine_load(struct thread_data *td)
908 * Engine has already been loaded.
912 if (!td->o.ioengine) {
913 log_err("fio: internal fault, no IO engine specified\n");
917 engine = get_engine_name(td->o.ioengine);
918 td->io_ops = load_ioengine(td, engine);
920 log_err("fio: failed to load engine %s\n", engine);
924 if (td->io_ops->option_struct_size && td->io_ops->options) {
926 * In cases where td->eo is set, clone it for a child thread.
927 * This requires that the parent thread has the same ioengine,
928 * but that requirement must be enforced by the code which
931 void *origeo = td->eo;
933 * Otherwise use the default thread options.
935 if (!origeo && td != &def_thread && def_thread.eo &&
936 def_thread.io_ops->options == td->io_ops->options)
937 origeo = def_thread.eo;
939 options_init(td->io_ops->options);
940 td->eo = malloc(td->io_ops->option_struct_size);
942 * Use the default thread as an option template if this uses the
943 * same options structure and there are non-default options
947 memcpy(td->eo, origeo, td->io_ops->option_struct_size);
948 options_mem_dupe(td->eo, td->io_ops->options);
950 memset(td->eo, 0, td->io_ops->option_struct_size);
951 fill_default_options(td->eo, td->io_ops->options);
953 *(struct thread_data **)td->eo = td;
959 static void init_flags(struct thread_data *td)
961 struct thread_options *o = &td->o;
963 if (o->verify_backlog)
964 td->flags |= TD_F_VER_BACKLOG;
966 td->flags |= TD_F_TRIM_BACKLOG;
967 if (o->read_iolog_file)
968 td->flags |= TD_F_READ_IOLOG;
969 if (o->refill_buffers)
970 td->flags |= TD_F_REFILL_BUFFERS;
972 * Always scramble buffers if asked to
974 if (o->scramble_buffers && fio_option_is_set(o, scramble_buffers))
975 td->flags |= TD_F_SCRAMBLE_BUFFERS;
977 * But also scramble buffers, unless we were explicitly asked
980 if (o->scramble_buffers && !(o->zero_buffers &&
981 fio_option_is_set(o, zero_buffers)))
982 td->flags |= TD_F_SCRAMBLE_BUFFERS;
983 if (o->verify != VERIFY_NONE)
984 td->flags |= TD_F_VER_NONE;
986 if (o->verify_async || o->io_submit_mode == IO_MODE_OFFLOAD)
987 td->flags |= TD_F_NEED_LOCK;
990 static int setup_random_seeds(struct thread_data *td)
995 if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed))
996 return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds));
998 seed = td->o.rand_seed;
999 for (i = 0; i < 4; i++)
1000 seed *= 0x9e370001UL;
1002 for (i = 0; i < FIO_RAND_NR_OFFS; i++) {
1003 td->rand_seeds[i] = seed;
1004 seed *= 0x9e370001UL;
1007 td_fill_rand_seeds(td);
1018 static struct fpre_keyword {
1019 const char *keyword;
1022 } fpre_keywords[] = {
1023 { .keyword = "$jobname", .key = FPRE_JOBNAME, },
1024 { .keyword = "$jobnum", .key = FPRE_JOBNUM, },
1025 { .keyword = "$filenum", .key = FPRE_FILENUM, },
1026 { .keyword = NULL, },
1029 static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
1030 const char *jobname, int jobnum, int filenum)
1032 struct fpre_keyword *f;
1033 char copy[PATH_MAX];
1034 size_t dst_left = PATH_MAX - 1;
1036 if (!o->filename_format || !strlen(o->filename_format)) {
1037 sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum);
1041 for (f = &fpre_keywords[0]; f->keyword; f++)
1042 f->strlen = strlen(f->keyword);
1044 buf[buf_size - 1] = '\0';
1045 strncpy(buf, o->filename_format, buf_size - 1);
1047 memset(copy, 0, sizeof(copy));
1048 for (f = &fpre_keywords[0]; f->keyword; f++) {
1050 size_t pre_len, post_start = 0;
1051 char *str, *dst = copy;
1053 str = strcasestr(buf, f->keyword);
1057 pre_len = str - buf;
1058 if (strlen(str) != f->strlen)
1059 post_start = pre_len + f->strlen;
1062 strncpy(dst, buf, pre_len);
1064 dst_left -= pre_len;
1068 case FPRE_JOBNAME: {
1071 ret = snprintf(dst, dst_left, "%s", jobname);
1074 else if (ret > dst_left) {
1075 log_err("fio: truncated filename\n");
1087 ret = snprintf(dst, dst_left, "%d", jobnum);
1090 else if (ret > dst_left) {
1091 log_err("fio: truncated filename\n");
1100 case FPRE_FILENUM: {
1103 ret = snprintf(dst, dst_left, "%d", filenum);
1106 else if (ret > dst_left) {
1107 log_err("fio: truncated filename\n");
1122 strncpy(dst, buf + post_start, dst_left);
1124 strncpy(buf, copy, buf_size - 1);
1131 int parse_dryrun(void)
1133 return dump_cmdline || parse_only;
1136 static void gen_log_name(char *name, size_t size, const char *logtype,
1137 const char *logname, unsigned int num,
1138 const char *suf, int per_job)
1141 snprintf(name, size, "%s_%s.%d.%s", logname, logtype, num, suf);
1143 snprintf(name, size, "%s_%s.%s", logname, logtype, suf);
1147 * Adds a job to the list of things todo. Sanitizes the various options
1148 * to make sure we don't have conflicts, and initializes various
1151 static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
1152 int recursed, int client_type)
1155 char fname[PATH_MAX];
1156 int numjobs, file_alloced;
1157 struct thread_options *o = &td->o;
1158 char logname[PATH_MAX + 32];
1161 * the def_thread is just for options, it's not a real job
1163 if (td == &def_thread)
1169 * if we are just dumping the output command line, don't add the job
1171 if (parse_dryrun()) {
1176 td->client_type = client_type;
1178 if (profile_td_init(td))
1181 if (ioengine_load(td))
1185 td->io_ops->flags |= FIO_RAWIO;
1188 if (!o->filename && !td->files_index && !o->read_iolog_file) {
1191 if (o->nr_files == 1 && exists_and_not_file(jobname))
1192 add_file(td, jobname, job_add_num, 0);
1194 for (i = 0; i < o->nr_files; i++)
1195 add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0);
1199 if (fixup_options(td))
1205 * IO engines only need this for option callbacks, and the address may
1206 * change in subprocesses.
1209 *(struct thread_data **)td->eo = NULL;
1211 if (td->io_ops->flags & FIO_DISKLESSIO) {
1214 for_each_file(td, f, i)
1215 f->real_file_size = -1ULL;
1218 td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
1220 td->ts.clat_percentiles = o->clat_percentiles;
1221 td->ts.percentile_precision = o->percentile_precision;
1222 memcpy(td->ts.percentile_list, o->percentile_list, sizeof(o->percentile_list));
1224 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1225 td->ts.clat_stat[i].min_val = ULONG_MAX;
1226 td->ts.slat_stat[i].min_val = ULONG_MAX;
1227 td->ts.lat_stat[i].min_val = ULONG_MAX;
1228 td->ts.bw_stat[i].min_val = ULONG_MAX;
1230 td->ddir_seq_nr = o->ddir_seq_nr;
1232 if ((o->stonewall || o->new_group) && prev_group_jobs) {
1233 prev_group_jobs = 0;
1237 td->groupid = groupid;
1240 if (setup_random_seeds(td)) {
1241 td_verror(td, errno, "init_random_state");
1248 if (o->lat_log_file) {
1249 struct log_params p = {
1251 .avg_msec = o->log_avg_msec,
1252 .log_type = IO_LOG_TYPE_LAT,
1253 .log_offset = o->log_offset,
1254 .log_gz = o->log_gz,
1255 .log_gz_store = o->log_gz_store,
1264 gen_log_name(logname, sizeof(logname), "lat", o->lat_log_file,
1265 td->thread_number, suf, o->per_job_logs);
1266 setup_log(&td->lat_log, &p, logname);
1268 gen_log_name(logname, sizeof(logname), "slat", o->lat_log_file,
1269 td->thread_number, suf, o->per_job_logs);
1270 setup_log(&td->slat_log, &p, logname);
1272 gen_log_name(logname, sizeof(logname), "clat", o->lat_log_file,
1273 td->thread_number, suf, o->per_job_logs);
1274 setup_log(&td->clat_log, &p, logname);
1276 if (o->bw_log_file) {
1277 struct log_params p = {
1279 .avg_msec = o->log_avg_msec,
1280 .log_type = IO_LOG_TYPE_BW,
1281 .log_offset = o->log_offset,
1282 .log_gz = o->log_gz,
1283 .log_gz_store = o->log_gz_store,
1292 gen_log_name(logname, sizeof(logname), "bw", o->bw_log_file,
1293 td->thread_number, suf, o->per_job_logs);
1294 setup_log(&td->bw_log, &p, logname);
1296 if (o->iops_log_file) {
1297 struct log_params p = {
1299 .avg_msec = o->log_avg_msec,
1300 .log_type = IO_LOG_TYPE_IOPS,
1301 .log_offset = o->log_offset,
1302 .log_gz = o->log_gz,
1303 .log_gz_store = o->log_gz_store,
1312 gen_log_name(logname, sizeof(logname), "iops", o->iops_log_file,
1313 td->thread_number, suf, o->per_job_logs);
1314 setup_log(&td->iops_log, &p, logname);
1318 o->name = strdup(jobname);
1320 if (output_format == FIO_OUTPUT_NORMAL) {
1322 if (is_backend && !recursed)
1323 fio_server_send_add_job(td);
1325 if (!(td->io_ops->flags & FIO_NOIO)) {
1326 char *c1, *c2, *c3, *c4;
1327 char *c5 = NULL, *c6 = NULL;
1329 c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
1330 c2 = fio_uint_to_kmg(o->max_bs[DDIR_READ]);
1331 c3 = fio_uint_to_kmg(o->min_bs[DDIR_WRITE]);
1332 c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
1334 if (!o->bs_is_seq_rand) {
1335 c5 = fio_uint_to_kmg(o->min_bs[DDIR_TRIM]);
1336 c6 = fio_uint_to_kmg(o->max_bs[DDIR_TRIM]);
1339 log_info("%s: (g=%d): rw=%s, ", td->o.name,
1341 ddir_str(o->td_ddir));
1343 if (o->bs_is_seq_rand)
1344 log_info("bs(seq/rand)=%s-%s/%s-%s, ",
1347 log_info("bs=%s-%s/%s-%s/%s-%s, ",
1348 c1, c2, c3, c4, c5, c6);
1350 log_info("ioengine=%s, iodepth=%u\n",
1351 td->io_ops->name, o->iodepth);
1360 } else if (job_add_num == 1)
1365 * recurse add identical jobs, clear numjobs and stonewall options
1366 * as they don't apply to sub-jobs
1368 numjobs = o->numjobs;
1370 struct thread_data *td_new = get_new_job(0, td, 1, jobname);
1375 td_new->o.numjobs = 1;
1376 td_new->o.stonewall = 0;
1377 td_new->o.new_group = 0;
1378 td_new->subjob_number = numjobs;
1381 if (td_new->files) {
1383 for_each_file(td_new, f, i) {
1385 sfree(f->file_name);
1388 free(td_new->files);
1389 td_new->files = NULL;
1391 td_new->files_index = 0;
1392 td_new->files_size = 0;
1393 if (td_new->o.filename) {
1394 free(td_new->o.filename);
1395 td_new->o.filename = NULL;
1399 if (add_job(td_new, jobname, numjobs, 1, client_type))
1410 * Parse as if 'o' was a command line
1412 void add_job_opts(const char **o, int client_type)
1414 struct thread_data *td, *td_parent;
1415 int i, in_global = 1;
1419 td_parent = td = NULL;
1421 if (!strncmp(o[i], "name", 4)) {
1424 add_job(td, jobname, 0, 0, client_type);
1426 sprintf(jobname, "%s", o[i] + 5);
1428 if (in_global && !td_parent)
1429 td_parent = get_new_job(1, &def_thread, 0, jobname);
1430 else if (!in_global && !td) {
1432 td_parent = &def_thread;
1433 td = get_new_job(0, td_parent, 0, jobname);
1436 fio_options_parse(td_parent, (char **) &o[i], 1, 0);
1438 fio_options_parse(td, (char **) &o[i], 1, 0);
1443 add_job(td, jobname, 0, 0, client_type);
1446 static int skip_this_section(const char *name)
1450 if (!nr_job_sections)
1452 if (!strncmp(name, "global", 6))
1455 for (i = 0; i < nr_job_sections; i++)
1456 if (!strcmp(job_sections[i], name))
1462 static int is_empty_or_comment(char *line)
1466 for (i = 0; i < strlen(line); i++) {
1471 if (!isspace((int) line[i]) && !iscntrl((int) line[i]))
1479 * This is our [ini] type file parser.
1481 int __parse_jobs_ini(struct thread_data *td,
1482 char *file, int is_buf, int stonewall_flag, int type,
1483 int nested, char *name, char ***popts, int *aopts, int *nopts)
1485 unsigned int global = 0;
1489 int ret = 0, stonewall;
1492 int inside_skip = 0;
1494 int i, alloc_opts, num_opts;
1496 dprint(FD_PARSE, "Parsing ini file %s\n", file);
1497 assert(td || !nested);
1502 if (!strcmp(file, "-"))
1505 f = fopen(file, "r");
1510 log_err("fio: unable to open '%s' job file\n", file);
1512 td_verror(td, __err, "job file open");
1517 string = malloc(4096);
1520 * it's really 256 + small bit, 280 should suffice
1524 memset(name, 0, 280);
1528 if (nested && popts) {
1530 alloc_opts = *aopts;
1536 opts = malloc(sizeof(char *) * alloc_opts);
1540 stonewall = stonewall_flag;
1543 * if skip_fgets is set, we already have loaded a line we
1548 p = strsep(&file, "\n");
1550 p = fgets(string, 4096, f);
1556 strip_blank_front(&p);
1559 dprint(FD_PARSE, "%s\n", p);
1560 if (is_empty_or_comment(p))
1564 if (sscanf(p, "[%255[^\n]]", name) != 1) {
1568 log_err("fio: option <%s> outside of "
1569 "[] job section\n", p);
1574 name[strlen(name) - 1] = '\0';
1576 if (skip_this_section(name)) {
1582 dprint(FD_PARSE, "Parsing section [%s]\n", name);
1584 global = !strncmp(name, "global", 6);
1590 log_info("--name=%s ", name);
1594 td = get_new_job(global, &def_thread, 0, name);
1601 * Separate multiple job files by a stonewall
1603 if (!global && stonewall) {
1604 td->o.stonewall = stonewall;
1609 memset(opts, 0, alloc_opts * sizeof(char *));
1617 p = strsep(&file, "\n");
1619 p = fgets(string, 4096, f);
1622 dprint(FD_PARSE, "%s", p);
1627 if (is_empty_or_comment(p))
1630 strip_blank_front(&p);
1633 * new section, break out and make sure we don't
1634 * fgets() a new line at the top.
1638 log_err("No new sections in included files\n");
1648 if (!strncmp(p, "include", strlen("include"))) {
1649 char *filename = p + strlen("include") + 1;
1651 if ((ret = __parse_jobs_ini(td, filename,
1652 is_buf, stonewall_flag, type, 1,
1653 name, &opts, &alloc_opts, &num_opts))) {
1654 log_err("Error %d while parsing include file %s\n",
1661 if (num_opts == alloc_opts) {
1663 opts = realloc(opts,
1664 alloc_opts * sizeof(char *));
1667 opts[num_opts] = strdup(p);
1673 *aopts = alloc_opts;
1678 ret = fio_options_parse(td, opts, num_opts, dump_cmdline);
1680 ret = add_job(td, name, 0, 0, type);
1682 log_err("fio: job %s dropped\n", name);
1686 for (i = 0; i < num_opts; i++)
1695 while (i < nr_job_sections) {
1696 free(job_sections[i]);
1705 if (!is_buf && f != stdin)
1710 int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
1712 return __parse_jobs_ini(NULL, file, is_buf, stonewall_flag, type,
1713 0, NULL, NULL, NULL, NULL);
1716 static int fill_def_thread(void)
1718 memset(&def_thread, 0, sizeof(def_thread));
1720 fio_getaffinity(getpid(), &def_thread.o.cpumask);
1721 def_thread.o.error_dump = 1;
1724 * fill default options
1726 fio_fill_default_options(&def_thread);
1730 static void show_debug_categories(void)
1732 struct debug_level *dl = &debug_levels[0];
1733 int curlen, first = 1;
1737 int has_next = (dl + 1)->name != NULL;
1739 if (first || curlen + strlen(dl->name) >= 80) {
1744 curlen += printf("\t\t\t%s", dl->name);
1745 curlen += 3 * (8 - 1);
1747 curlen += printf(",");
1749 curlen += printf("%s", dl->name);
1751 curlen += printf(",");
1759 static void usage(const char *name)
1761 printf("%s\n", fio_version_string);
1762 printf("%s [options] [job options] <job file(s)>\n", name);
1763 printf(" --debug=options\tEnable debug logging. May be one/more of:\n");
1764 show_debug_categories();
1765 printf(" --parse-only\t\tParse options only, don't start any IO\n");
1766 printf(" --output\t\tWrite output to file\n");
1767 printf(" --runtime\t\tRuntime in seconds\n");
1768 printf(" --bandwidth-log\tGenerate per-job bandwidth logs\n");
1769 printf(" --minimal\t\tMinimal (terse) output\n");
1770 printf(" --output-format=x\tOutput format (terse,json,normal)\n");
1771 printf(" --terse-version=x\tSet terse version output format to 'x'\n");
1772 printf(" --version\t\tPrint version info and exit\n");
1773 printf(" --help\t\tPrint this page\n");
1774 printf(" --cpuclock-test\tPerform test/validation of CPU clock\n");
1775 printf(" --crctest\t\tTest speed of checksum functions\n");
1776 printf(" --cmdhelp=cmd\t\tPrint command help, \"all\" for all of"
1778 printf(" --enghelp=engine\tPrint ioengine help, or list"
1779 " available ioengines\n");
1780 printf(" --enghelp=engine,cmd\tPrint help for an ioengine"
1782 printf(" --showcmd\t\tTurn a job file into command line options\n");
1783 printf(" --eta=when\t\tWhen ETA estimate should be printed\n");
1784 printf(" \t\tMay be \"always\", \"never\" or \"auto\"\n");
1785 printf(" --eta-newline=time\tForce a new line for every 'time'");
1786 printf(" period passed\n");
1787 printf(" --status-interval=t\tForce full status dump every");
1788 printf(" 't' period passed\n");
1789 printf(" --readonly\t\tTurn on safety read-only checks, preventing"
1791 printf(" --section=name\tOnly run specified section in job file\n");
1792 printf(" --alloc-size=kb\tSet smalloc pool to this size in kb"
1794 printf(" --warnings-fatal\tFio parser warnings are fatal\n");
1795 printf(" --max-jobs=nr\t\tMaximum number of threads/processes to support\n");
1796 printf(" --server=args\t\tStart a backend fio server\n");
1797 printf(" --daemonize=pidfile\tBackground fio server, write pid to file\n");
1798 printf(" --client=hostname\tTalk to remote backend fio server at hostname\n");
1799 printf(" --remote-config=file\tTell fio server to load this local job file\n");
1800 printf(" --idle-prof=option\tReport cpu idleness on a system or percpu basis\n"
1801 "\t\t\t(option=system,percpu) or run unit work\n"
1802 "\t\t\tcalibration only (option=calibrate)\n");
1804 printf(" --inflate-log=log\tInflate and output compressed log\n");
1806 printf(" --trigger-file=file\tExecute trigger cmd when file exists\n");
1807 printf(" --trigger-timeout=t\tExecute trigger af this time\n");
1808 printf(" --trigger=cmd\t\tSet this command as local trigger\n");
1809 printf(" --trigger-remote=cmd\tSet this command as remote trigger\n");
1810 printf(" --aux-path=path\tUse this path for fio state generated files\n");
1811 printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
1812 printf("\n Jens Axboe <jaxboe@fusionio.com>");
1813 printf("\n Jens Axboe <axboe@fb.com>\n");
1816 #ifdef FIO_INC_DEBUG
1817 struct debug_level debug_levels[] = {
1818 { .name = "process",
1819 .help = "Process creation/exit logging",
1820 .shift = FD_PROCESS,
1823 .help = "File related action logging",
1827 .help = "IO and IO engine action logging (offsets, queue, completions, etc)",
1831 .help = "Memory allocation/freeing logging",
1834 { .name = "blktrace",
1835 .help = "blktrace action logging",
1836 .shift = FD_BLKTRACE,
1839 .help = "IO verification action logging",
1843 .help = "Random generation logging",
1847 .help = "Parser logging",
1850 { .name = "diskutil",
1851 .help = "Disk utility logging actions",
1852 .shift = FD_DISKUTIL,
1855 .help = "Logging related to creating/destroying jobs",
1859 .help = "Mutex logging",
1862 { .name = "profile",
1863 .help = "Logging related to profiles",
1864 .shift = FD_PROFILE,
1867 .help = "Logging related to time keeping functions",
1871 .help = "Network logging",
1875 .help = "Rate logging",
1878 { .name = "compress",
1879 .help = "Log compression logging",
1880 .shift = FD_COMPRESS,
1885 static int set_debug(const char *string)
1887 struct debug_level *dl;
1888 char *p = (char *) string;
1892 if (!strcmp(string, "?") || !strcmp(string, "help")) {
1893 log_info("fio: dumping debug options:");
1894 for (i = 0; debug_levels[i].name; i++) {
1895 dl = &debug_levels[i];
1896 log_info("%s,", dl->name);
1902 while ((opt = strsep(&p, ",")) != NULL) {
1905 if (!strncmp(opt, "all", 3)) {
1906 log_info("fio: set all debug options\n");
1911 for (i = 0; debug_levels[i].name; i++) {
1912 dl = &debug_levels[i];
1913 found = !strncmp(opt, dl->name, strlen(dl->name));
1917 if (dl->shift == FD_JOB) {
1918 opt = strchr(opt, ':');
1920 log_err("fio: missing job number\n");
1924 fio_debug_jobno = atoi(opt);
1925 log_info("fio: set debug jobno %d\n",
1928 log_info("fio: set debug option %s\n", opt);
1929 fio_debug |= (1UL << dl->shift);
1935 log_err("fio: debug mask %s not found\n", opt);
1940 static int set_debug(const char *string)
1942 log_err("fio: debug tracing not included in build\n");
1947 static void fio_options_fill_optstring(void)
1949 char *ostr = cmd_optstr;
1953 while (l_opts[i].name) {
1954 ostr[c++] = l_opts[i].val;
1955 if (l_opts[i].has_arg == required_argument)
1957 else if (l_opts[i].has_arg == optional_argument) {
1966 static int client_flag_set(char c)
1971 while (l_opts[i].name) {
1972 int val = l_opts[i].val;
1974 if (c == (val & 0xff))
1975 return (val & FIO_CLIENT_FLAG);
1983 static void parse_cmd_client(void *client, char *opt)
1985 fio_client_add_cmd_option(client, opt);
1988 static void show_closest_option(const char *name)
1990 int best_option, best_distance;
1993 while (*name == '-')
1997 best_distance = INT_MAX;
1999 while (l_opts[i].name) {
2000 distance = string_distance(name, l_opts[i].name);
2001 if (distance < best_distance) {
2002 best_distance = distance;
2008 if (best_option != -1 && string_distance_ok(name, best_distance))
2009 log_err("Did you mean %s?\n", l_opts[best_option].name);
2012 int parse_cmd_line(int argc, char *argv[], int client_type)
2014 struct thread_data *td = NULL;
2015 int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
2016 char *ostr = cmd_optstr;
2017 void *pid_file = NULL;
2018 void *cur_client = NULL;
2022 * Reset optind handling, since we may call this multiple times
2027 while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
2028 if ((c & FIO_CLIENT_FLAG) || client_flag_set(c)) {
2029 parse_cmd_client(cur_client, argv[optind - 1]);
2030 c &= ~FIO_CLIENT_FLAG;
2035 smalloc_pool_size = atoi(optarg);
2038 if (check_str_time(optarg, &def_timeout, 1)) {
2039 log_err("fio: failed parsing time %s\n", optarg);
2045 log_err("fio: --latency-log is deprecated. Use per-job latency log options.\n");
2053 if (f_out && f_out != stdout)
2056 f_out = fopen(optarg, "w+");
2058 perror("fopen output");
2064 output_format = FIO_OUTPUT_TERSE;
2068 log_err("fio: missing --output-format argument\n");
2073 if (!strcmp(optarg, "minimal") ||
2074 !strcmp(optarg, "terse") ||
2075 !strcmp(optarg, "csv"))
2076 output_format = FIO_OUTPUT_TERSE;
2077 else if (!strcmp(optarg, "json"))
2078 output_format = FIO_OUTPUT_JSON;
2080 output_format = FIO_OUTPUT_NORMAL;
2083 append_terse_output = 1;
2095 fio_show_option_help(optarg);
2102 fio_show_ioengine_help(optarg);
2116 log_info("%s\n", fio_version_string);
2121 terse_version = atoi(optarg);
2122 if (!(terse_version == 2 || terse_version == 3 ||
2123 terse_version == 4)) {
2124 log_err("fio: bad terse version format\n");
2130 if (!strcmp("always", optarg))
2131 eta_print = FIO_ETA_ALWAYS;
2132 else if (!strcmp("never", optarg))
2133 eta_print = FIO_ETA_NEVER;
2138 if (check_str_time(optarg, &t, 1)) {
2139 log_err("fio: failed parsing eta time %s\n", optarg);
2143 eta_new_line = t / 1000;
2147 if (set_debug(optarg))
2157 if (!strcmp(optarg, "global")) {
2158 log_err("fio: can't use global as only "
2164 new_size = (nr_job_sections + 1) * sizeof(char *);
2165 job_sections = realloc(job_sections, new_size);
2166 job_sections[nr_job_sections] = strdup(optarg);
2172 exit_val = iolog_file_inflate(optarg);
2181 exec_profile = strdup(optarg);
2183 case FIO_GETOPT_JOB: {
2184 const char *opt = l_opts[lidx].name;
2187 if (!strncmp(opt, "name", 4) && td) {
2188 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
2195 int is_section = !strncmp(opt, "name", 4);
2198 if (!is_section || !strncmp(val, "global", 6))
2201 if (is_section && skip_this_section(val))
2204 td = get_new_job(global, &def_thread, 1, NULL);
2205 if (!td || ioengine_load(td)) {
2214 fio_options_set_ioengine_opts(l_opts, td);
2217 if ((!val || !strlen(val)) &&
2218 l_opts[lidx].has_arg == required_argument) {
2219 log_err("fio: option %s requires an argument\n", opt);
2222 ret = fio_cmd_option_parse(td, opt, val);
2233 if (!ret && !strcmp(opt, "ioengine")) {
2235 if (ioengine_load(td)) {
2242 fio_options_set_ioengine_opts(l_opts, td);
2246 case FIO_GETOPT_IOENGINE: {
2247 const char *opt = l_opts[lidx].name;
2253 ret = fio_cmd_ioengine_option_parse(td, opt, val);
2260 max_jobs = atoi(optarg);
2261 if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
2262 log_err("fio: invalid max jobs: %d\n", max_jobs);
2269 #ifndef CONFIG_NO_SHM
2271 log_err("fio: can't be both client and server\n");
2277 fio_server_set_arg(optarg);
2281 log_err("fio: client/server requires SHM support\n");
2289 pid_file = strdup(optarg);
2292 if ((ret = fio_idle_prof_parse_opt(optarg))) {
2293 /* exit on error and calibration only */
2303 log_err("fio: can't be both client and server\n");
2308 /* if --client parameter contains a pathname */
2309 if (0 == access(optarg, R_OK)) {
2310 /* file contains a list of host addrs or names */
2311 char hostaddr[PATH_MAX] = {0};
2313 FILE * hostf = fopen(optarg, "r");
2315 log_err("fio: could not open client list file %s for read\n", optarg);
2320 sprintf(formatstr, "%%%ds", PATH_MAX - 1);
2322 * read at most PATH_MAX-1 chars from each
2323 * record in this file
2325 while (fscanf(hostf, formatstr, hostaddr) == 1) {
2326 /* expect EVERY host in file to be valid */
2327 if (fio_client_add(&fio_client_ops, hostaddr, &cur_client)) {
2328 log_err("fio: failed adding client %s from file %s\n", hostaddr, optarg);
2335 break; /* no possibility of job file for "this client only" */
2337 if (fio_client_add(&fio_client_ops, optarg, &cur_client)) {
2338 log_err("fio: failed adding client %s\n", optarg);
2344 * If the next argument exists and isn't an option,
2345 * assume it's a job file for this client only.
2347 while (optind < argc) {
2348 if (!strncmp(argv[optind], "--", 2) ||
2349 !strncmp(argv[optind], "-", 1))
2352 if (fio_client_add_ini_file(cur_client, argv[optind], 0))
2359 if (fio_client_add_ini_file(cur_client, optarg, 1)) {
2367 exit_val = fio_monotonic_clocktest(1);
2372 exit_val = fio_crctest(optarg);
2377 if (check_str_time(optarg, &val, 1)) {
2378 log_err("fio: failed parsing time %s\n", optarg);
2383 status_interval = val / 1000;
2389 trigger_file = strdup(optarg);
2394 trigger_cmd = strdup(optarg);
2397 if (trigger_remote_cmd)
2398 free(trigger_remote_cmd);
2399 trigger_remote_cmd = strdup(optarg);
2404 aux_path = strdup(optarg);
2407 if (check_str_time(optarg, &trigger_timeout, 1)) {
2408 log_err("fio: failed parsing time %s\n", optarg);
2412 trigger_timeout /= 1000000;
2415 log_err("%s: unrecognized option '%s'\n", argv[0],
2417 show_closest_option(argv[optind - 1]);
2427 if (do_exit && !(is_backend || nr_clients))
2430 if (nr_clients && fio_clients_connect())
2433 if (is_backend && backend)
2434 return fio_start_server(pid_file);
2440 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
2446 while (!ret && optind < argc) {
2448 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
2449 ini_file[ini_idx - 1] = strdup(argv[optind]);
2460 int fio_init_options(void)
2465 fio_options_fill_optstring();
2466 fio_options_dup_and_init(l_opts);
2470 if (fill_def_thread())
2476 extern int fio_check_options(struct thread_options *);
2478 int parse_options(int argc, char *argv[])
2480 const int type = FIO_CLIENT_TYPE_CLI;
2483 if (fio_init_options())
2485 if (fio_test_cconv(&def_thread.o))
2486 log_err("fio: failed internal cconv test\n");
2488 job_files = parse_cmd_line(argc, argv, type);
2490 if (job_files > 0) {
2491 for (i = 0; i < job_files; i++) {
2492 if (i && fill_def_thread())
2495 if (fio_clients_send_ini(ini_file[i]))
2498 } else if (!is_backend) {
2499 if (parse_jobs_ini(ini_file[i], 0, i, type))
2504 } else if (nr_clients) {
2505 if (fill_def_thread())
2507 if (fio_clients_send_ini(NULL))
2512 fio_options_free(&def_thread);
2513 filesetup_mem_free();
2515 if (!thread_number) {
2520 if (is_backend || nr_clients)
2525 log_err("No jobs(s) defined\n\n");
2535 if (output_format == FIO_OUTPUT_NORMAL)
2536 log_info("%s\n", fio_version_string);
2541 void options_default_fill(struct thread_options *o)
2543 memcpy(o, &def_thread.o, sizeof(*o));