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 eta_print = FIO_ETA_AUTO;
55 char *exec_profile = NULL;
56 int warnings_fatal = 0;
57 int terse_version = 3;
64 int status_interval = 0;
66 char *trigger_file = NULL;
67 long long trigger_timeout = 0;
68 char *trigger_cmd = NULL;
69 char *trigger_remote_cmd = NULL;
71 char *aux_path = NULL;
73 static int prev_group_jobs;
75 unsigned long fio_debug = 0;
76 unsigned int fio_debug_jobno = -1;
77 unsigned int *fio_debug_jobp = NULL;
79 static char cmd_optstr[256];
82 #define FIO_CLIENT_FLAG (1 << 16)
85 * Command line options. These will contain the above, plus a few
86 * extra that only pertain to fio itself and not jobs.
88 static struct option l_opts[FIO_NR_OPTIONS] = {
90 .name = (char *) "output",
91 .has_arg = required_argument,
92 .val = 'o' | FIO_CLIENT_FLAG,
95 .name = (char *) "timeout",
96 .has_arg = required_argument,
97 .val = 't' | FIO_CLIENT_FLAG,
100 .name = (char *) "latency-log",
101 .has_arg = required_argument,
102 .val = 'l' | FIO_CLIENT_FLAG,
105 .name = (char *) "bandwidth-log",
106 .has_arg = required_argument,
107 .val = 'b' | FIO_CLIENT_FLAG,
110 .name = (char *) "minimal",
111 .has_arg = no_argument,
112 .val = 'm' | FIO_CLIENT_FLAG,
115 .name = (char *) "output-format",
116 .has_arg = optional_argument,
117 .val = 'F' | FIO_CLIENT_FLAG,
120 .name = (char *) "append-terse",
121 .has_arg = optional_argument,
125 .name = (char *) "version",
126 .has_arg = no_argument,
127 .val = 'v' | FIO_CLIENT_FLAG,
130 .name = (char *) "help",
131 .has_arg = no_argument,
132 .val = 'h' | FIO_CLIENT_FLAG,
135 .name = (char *) "cmdhelp",
136 .has_arg = optional_argument,
137 .val = 'c' | FIO_CLIENT_FLAG,
140 .name = (char *) "enghelp",
141 .has_arg = optional_argument,
142 .val = 'i' | FIO_CLIENT_FLAG,
145 .name = (char *) "showcmd",
146 .has_arg = no_argument,
147 .val = 's' | FIO_CLIENT_FLAG,
150 .name = (char *) "readonly",
151 .has_arg = no_argument,
152 .val = 'r' | FIO_CLIENT_FLAG,
155 .name = (char *) "eta",
156 .has_arg = required_argument,
157 .val = 'e' | FIO_CLIENT_FLAG,
160 .name = (char *) "eta-newline",
161 .has_arg = required_argument,
162 .val = 'E' | FIO_CLIENT_FLAG,
165 .name = (char *) "debug",
166 .has_arg = required_argument,
167 .val = 'd' | FIO_CLIENT_FLAG,
170 .name = (char *) "parse-only",
171 .has_arg = no_argument,
172 .val = 'P' | FIO_CLIENT_FLAG,
175 .name = (char *) "section",
176 .has_arg = required_argument,
177 .val = 'x' | FIO_CLIENT_FLAG,
181 .name = (char *) "inflate-log",
182 .has_arg = required_argument,
183 .val = 'X' | FIO_CLIENT_FLAG,
187 .name = (char *) "alloc-size",
188 .has_arg = required_argument,
189 .val = 'a' | FIO_CLIENT_FLAG,
192 .name = (char *) "profile",
193 .has_arg = required_argument,
194 .val = 'p' | FIO_CLIENT_FLAG,
197 .name = (char *) "warnings-fatal",
198 .has_arg = no_argument,
199 .val = 'w' | FIO_CLIENT_FLAG,
202 .name = (char *) "max-jobs",
203 .has_arg = required_argument,
204 .val = 'j' | FIO_CLIENT_FLAG,
207 .name = (char *) "terse-version",
208 .has_arg = required_argument,
209 .val = 'V' | FIO_CLIENT_FLAG,
212 .name = (char *) "server",
213 .has_arg = optional_argument,
216 { .name = (char *) "daemonize",
217 .has_arg = required_argument,
221 .name = (char *) "client",
222 .has_arg = required_argument,
226 .name = (char *) "remote-config",
227 .has_arg = required_argument,
231 .name = (char *) "cpuclock-test",
232 .has_arg = no_argument,
236 .name = (char *) "crctest",
237 .has_arg = optional_argument,
241 .name = (char *) "idle-prof",
242 .has_arg = required_argument,
246 .name = (char *) "status-interval",
247 .has_arg = required_argument,
251 .name = (char *) "trigger-file",
252 .has_arg = required_argument,
256 .name = (char *) "trigger-timeout",
257 .has_arg = required_argument,
261 .name = (char *) "trigger",
262 .has_arg = required_argument,
266 .name = (char *) "trigger-remote",
267 .has_arg = required_argument,
271 .name = (char *) "aux-path",
272 .has_arg = required_argument,
280 void free_threads_shm(void)
284 #ifndef CONFIG_NO_SHM
285 struct shmid_ds sbuf;
289 shmctl(shm_id, IPC_RMID, &sbuf);
298 static void free_shm(void)
303 fio_debug_jobp = NULL;
309 free(trigger_remote_cmd);
310 trigger_file = trigger_cmd = trigger_remote_cmd = NULL;
312 options_free(fio_options, &def_thread);
318 * The thread area is shared between the main process and the job
319 * threads/processes. So setup a shared memory segment that will hold
320 * all the job info. We use the end of the region for keeping track of
321 * open files across jobs, for file sharing.
323 static int setup_thread_area(void)
331 * 1024 is too much on some machines, scale max_jobs if
332 * we get a failure that looks like too large a shm segment
335 size_t size = max_jobs * sizeof(struct thread_data);
337 size += file_hash_size;
338 size += sizeof(unsigned int);
340 #ifndef CONFIG_NO_SHM
341 shm_id = shmget(0, size, IPC_CREAT | 0600);
344 if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC) {
349 threads = malloc(size);
357 #ifndef CONFIG_NO_SHM
361 threads = shmat(shm_id, NULL, 0);
362 if (threads == (void *) -1) {
368 memset(threads, 0, max_jobs * sizeof(struct thread_data));
369 hash = (void *) threads + max_jobs * sizeof(struct thread_data);
370 fio_debug_jobp = (void *) hash + file_hash_size;
371 *fio_debug_jobp = -1;
372 file_hash_init(hash);
379 static void set_cmd_options(struct thread_data *td)
381 struct thread_options *o = &td->o;
384 o->timeout = def_timeout;
388 * Return a free job structure.
390 static struct thread_data *get_new_job(int global, struct thread_data *parent,
391 int preserve_eo, const char *jobname)
393 struct thread_data *td;
396 set_cmd_options(&def_thread);
399 if (setup_thread_area()) {
400 log_err("error: failed to setup shm segment\n");
403 if (thread_number >= max_jobs) {
404 log_err("error: maximum number of jobs (%d) reached.\n",
409 td = &threads[thread_number++];
416 td->o.uid = td->o.gid = -1U;
418 dup_files(td, parent);
419 fio_options_mem_dupe(td);
421 profile_add_hooks(td);
423 td->thread_number = thread_number;
424 td->subjob_number = 0;
427 td->o.name = strdup(jobname);
429 if (!parent->o.group_reporting)
436 static void put_job(struct thread_data *td)
438 if (td == &def_thread)
445 log_info("fio: %s\n", td->verror);
447 fio_options_free(td);
454 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
458 static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
460 unsigned int bs = td->o.min_bs[ddir];
462 assert(ddir_rw(ddir));
464 if (td->o.rate[ddir])
465 td->rate_bps[ddir] = td->o.rate[ddir];
467 td->rate_bps[ddir] = (uint64_t) td->o.rate_iops[ddir] * bs;
469 if (!td->rate_bps[ddir]) {
470 log_err("rate lower than supported\n");
474 td->rate_next_io_time[ddir] = 0;
475 td->rate_io_issue_bytes[ddir] = 0;
479 static int setup_rate(struct thread_data *td)
483 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
484 ret = __setup_rate(td, DDIR_READ);
485 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
486 ret |= __setup_rate(td, DDIR_WRITE);
487 if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM])
488 ret |= __setup_rate(td, DDIR_TRIM);
493 static int fixed_block_size(struct thread_options *o)
495 return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
496 o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
497 o->min_bs[DDIR_TRIM] == o->max_bs[DDIR_TRIM] &&
498 o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE] &&
499 o->min_bs[DDIR_READ] == o->min_bs[DDIR_TRIM];
503 static unsigned long long get_rand_start_delay(struct thread_data *td)
505 unsigned long long delayrange;
509 delayrange = td->o.start_delay_high - td->o.start_delay;
511 frand_max = rand_max(&td->delay_state);
512 r = __rand(&td->delay_state);
513 delayrange = (unsigned long long) ((double) delayrange * (r / (frand_max + 1.0)));
515 delayrange += td->o.start_delay;
520 * Lazy way of fixing up options that depend on each other. We could also
521 * define option callback handlers, but this is easier.
523 static int fixup_options(struct thread_data *td)
525 struct thread_options *o = &td->o;
528 #ifndef FIO_HAVE_PSHARED_MUTEX
529 if (!o->use_thread) {
530 log_info("fio: this platform does not support process shared"
531 " mutexes, forcing use of threads. Use the 'thread'"
532 " option to get rid of this warning.\n");
534 ret = warnings_fatal;
538 if (o->write_iolog_file && o->read_iolog_file) {
539 log_err("fio: read iolog overrides write_iolog\n");
540 free(o->write_iolog_file);
541 o->write_iolog_file = NULL;
542 ret = warnings_fatal;
546 * only really works with 1 file
548 if (o->zone_size && o->open_files > 1)
552 * If zone_range isn't specified, backward compatibility dictates it
553 * should be made equal to zone_size.
555 if (o->zone_size && !o->zone_range)
556 o->zone_range = o->zone_size;
559 * Reads can do overwrites, we always need to pre-create the file
561 if (td_read(td) || td_rw(td))
564 if (!o->min_bs[DDIR_READ])
565 o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
566 if (!o->max_bs[DDIR_READ])
567 o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
568 if (!o->min_bs[DDIR_WRITE])
569 o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
570 if (!o->max_bs[DDIR_WRITE])
571 o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
572 if (!o->min_bs[DDIR_TRIM])
573 o->min_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
574 if (!o->max_bs[DDIR_TRIM])
575 o->max_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
577 o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
578 o->rw_min_bs = min(o->min_bs[DDIR_TRIM], o->rw_min_bs);
581 * For random IO, allow blockalign offset other than min_bs.
583 if (!o->ba[DDIR_READ] || !td_random(td))
584 o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
585 if (!o->ba[DDIR_WRITE] || !td_random(td))
586 o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
587 if (!o->ba[DDIR_TRIM] || !td_random(td))
588 o->ba[DDIR_TRIM] = o->min_bs[DDIR_TRIM];
590 if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
591 o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE] ||
592 o->ba[DDIR_TRIM] != o->min_bs[DDIR_TRIM]) &&
594 log_err("fio: Any use of blockalign= turns off randommap\n");
596 ret = warnings_fatal;
599 if (!o->file_size_high)
600 o->file_size_high = o->file_size_low;
602 if (o->start_delay_high)
603 o->start_delay = get_rand_start_delay(td);
605 if (o->norandommap && o->verify != VERIFY_NONE
606 && !fixed_block_size(o)) {
607 log_err("fio: norandommap given for variable block sizes, "
609 ret = warnings_fatal;
611 if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
612 log_err("fio: bs_unaligned may not work with raw io\n");
615 * thinktime_spin must be less than thinktime
617 if (o->thinktime_spin > o->thinktime)
618 o->thinktime_spin = o->thinktime;
621 * The low water mark cannot be bigger than the iodepth
623 if (o->iodepth_low > o->iodepth || !o->iodepth_low)
624 o->iodepth_low = o->iodepth;
627 * If batch number isn't set, default to the same as iodepth
629 if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
630 o->iodepth_batch = o->iodepth;
633 * If max batch complete number isn't set or set incorrectly,
634 * default to the same as iodepth_batch_complete_min
636 if (o->iodepth_batch_complete_min > o->iodepth_batch_complete_max)
637 o->iodepth_batch_complete_max = o->iodepth_batch_complete_min;
639 if (o->nr_files > td->files_index)
640 o->nr_files = td->files_index;
642 if (o->open_files > o->nr_files || !o->open_files)
643 o->open_files = o->nr_files;
645 if (((o->rate[DDIR_READ] + o->rate[DDIR_WRITE] + o->rate[DDIR_TRIM]) &&
646 (o->rate_iops[DDIR_READ] + o->rate_iops[DDIR_WRITE] + o->rate_iops[DDIR_TRIM])) ||
647 ((o->ratemin[DDIR_READ] + o->ratemin[DDIR_WRITE] + o->ratemin[DDIR_TRIM]) &&
648 (o->rate_iops_min[DDIR_READ] + o->rate_iops_min[DDIR_WRITE] + o->rate_iops_min[DDIR_TRIM]))) {
649 log_err("fio: rate and rate_iops are mutually exclusive\n");
652 if ((o->rate[DDIR_READ] && (o->rate[DDIR_READ] < o->ratemin[DDIR_READ])) ||
653 (o->rate[DDIR_WRITE] && (o->rate[DDIR_WRITE] < o->ratemin[DDIR_WRITE])) ||
654 (o->rate[DDIR_TRIM] && (o->rate[DDIR_TRIM] < o->ratemin[DDIR_TRIM])) ||
655 (o->rate_iops[DDIR_READ] && (o->rate_iops[DDIR_READ] < o->rate_iops_min[DDIR_READ])) ||
656 (o->rate_iops[DDIR_WRITE] && (o->rate_iops[DDIR_WRITE] < o->rate_iops_min[DDIR_WRITE])) ||
657 (o->rate_iops[DDIR_TRIM] && (o->rate_iops[DDIR_TRIM] < o->rate_iops_min[DDIR_TRIM]))) {
658 log_err("fio: minimum rate exceeds rate\n");
662 if (!o->timeout && o->time_based) {
663 log_err("fio: time_based requires a runtime/timeout setting\n");
665 ret = warnings_fatal;
668 if (o->fill_device && !o->size)
671 if (o->verify != VERIFY_NONE) {
672 if (td_write(td) && o->do_verify && o->numjobs > 1) {
673 log_info("Multiple writers may overwrite blocks that "
674 "belong to other jobs. This can cause "
675 "verification failures.\n");
676 ret = warnings_fatal;
679 if (!fio_option_is_set(o, refill_buffers))
680 o->refill_buffers = 1;
682 if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
684 o->verify_interval = o->min_bs[DDIR_WRITE];
687 * Verify interval must be smaller or equal to the
690 if (o->verify_interval > o->min_bs[DDIR_WRITE])
691 o->verify_interval = o->min_bs[DDIR_WRITE];
692 else if (td_read(td) && o->verify_interval > o->min_bs[DDIR_READ])
693 o->verify_interval = o->min_bs[DDIR_READ];
697 o->invalidate_cache = 0;
698 if (td->io_ops->flags & FIO_PIPEIO) {
699 log_info("fio: cannot pre-read files with an IO engine"
700 " that isn't seekable. Pre-read disabled.\n");
701 ret = warnings_fatal;
706 if (td->io_ops->flags & FIO_BIT_BASED)
712 #ifndef CONFIG_FDATASYNC
713 if (o->fdatasync_blocks) {
714 log_info("fio: this platform does not support fdatasync()"
715 " falling back to using fsync(). Use the 'fsync'"
716 " option instead of 'fdatasync' to get rid of"
718 o->fsync_blocks = o->fdatasync_blocks;
719 o->fdatasync_blocks = 0;
720 ret = warnings_fatal;
726 * Windows doesn't support O_DIRECT or O_SYNC with the _open interface,
727 * so fail if we're passed those flags
729 if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) {
730 log_err("fio: Windows does not support direct or non-buffered io with"
731 " the synchronous ioengines. Use the 'windowsaio' ioengine"
732 " with 'direct=1' and 'iodepth=1' instead.\n");
738 * For fully compressible data, just zero them at init time.
739 * It's faster than repeatedly filling it.
741 if (td->o.compress_percentage == 100) {
742 td->o.zero_buffers = 1;
743 td->o.compress_percentage = 0;
747 * Using a non-uniform random distribution excludes usage of
750 if (td->o.random_distribution != FIO_RAND_DIST_RANDOM)
751 td->o.norandommap = 1;
754 * If size is set but less than the min block size, complain
756 if (o->size && o->size < td_min_bs(td)) {
757 log_err("fio: size too small, must be larger than the IO size: %llu\n", (unsigned long long) o->size);
762 * O_ATOMIC implies O_DIRECT
768 * If randseed is set, that overrides randrepeat
770 if (fio_option_is_set(&td->o, rand_seed))
771 td->o.rand_repeatable = 0;
773 if ((td->io_ops->flags & FIO_NOEXTEND) && td->o.file_append) {
774 log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name);
778 if (fio_option_is_set(o, gtod_cpu)) {
780 fio_gtod_set_cpu(o->gtod_cpu);
781 fio_gtod_offload = 1;
784 td->loops = o->loops;
788 if (td->o.block_error_hist && td->o.nr_files != 1) {
789 log_err("fio: block error histogram only available with "
790 "with a single file per job, but %d files "
791 "provided\n", td->o.nr_files);
799 * This function leaks the buffer
801 char *fio_uint_to_kmg(unsigned int val)
803 char *buf = malloc(32);
804 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
815 snprintf(buf, 32, "%u%c", val, *p);
819 /* External engines are specified by "external:name.o") */
820 static const char *get_engine_name(const char *str)
822 char *p = strstr(str, ":");
828 strip_blank_front(&p);
833 static int exists_and_not_file(const char *filename)
837 if (lstat(filename, &sb) == -1)
840 /* \\.\ is the device namespace in Windows, where every file
841 * is a device node */
842 if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
848 static void td_fill_rand_seeds_internal(struct thread_data *td, int use64)
850 init_rand_seed(&td->bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF], use64);
851 init_rand_seed(&td->verify_state, td->rand_seeds[FIO_RAND_VER_OFF], use64);
852 init_rand_seed(&td->rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF], use64);
854 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
855 init_rand_seed(&td->next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF], use64);
857 init_rand_seed(&td->file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF], use64);
858 init_rand_seed(&td->trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF], use64);
859 init_rand_seed(&td->delay_state, td->rand_seeds[FIO_RAND_START_DELAY], use64);
864 if (td->o.rand_repeatable)
865 td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number;
867 init_rand_seed(&td->random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF], use64);
868 init_rand_seed(&td->seq_rand_state[DDIR_READ], td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], use64);
869 init_rand_seed(&td->seq_rand_state[DDIR_WRITE], td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF], use64);
870 init_rand_seed(&td->seq_rand_state[DDIR_TRIM], td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF], use64);
873 void td_fill_rand_seeds(struct thread_data *td)
877 if (td->o.allrand_repeatable) {
880 for (i = 0; i < FIO_RAND_NR_OFFS; i++)
881 td->rand_seeds[i] = FIO_RANDSEED * td->thread_number
885 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64)
890 td_fill_rand_seeds_internal(td, use64);
892 init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF], use64);
893 frand_copy(&td->buf_state_prev, &td->buf_state);
895 init_rand_seed(&td->dedupe_state, td->rand_seeds[FIO_DEDUPE_OFF], use64);
899 * Initializes the ioengine configured for a job, if it has not been done so
902 int ioengine_load(struct thread_data *td)
907 * Engine has already been loaded.
911 if (!td->o.ioengine) {
912 log_err("fio: internal fault, no IO engine specified\n");
916 engine = get_engine_name(td->o.ioengine);
917 td->io_ops = load_ioengine(td, engine);
919 log_err("fio: failed to load engine %s\n", engine);
923 if (td->io_ops->option_struct_size && td->io_ops->options) {
925 * In cases where td->eo is set, clone it for a child thread.
926 * This requires that the parent thread has the same ioengine,
927 * but that requirement must be enforced by the code which
930 void *origeo = td->eo;
932 * Otherwise use the default thread options.
934 if (!origeo && td != &def_thread && def_thread.eo &&
935 def_thread.io_ops->options == td->io_ops->options)
936 origeo = def_thread.eo;
938 options_init(td->io_ops->options);
939 td->eo = malloc(td->io_ops->option_struct_size);
941 * Use the default thread as an option template if this uses the
942 * same options structure and there are non-default options
946 memcpy(td->eo, origeo, td->io_ops->option_struct_size);
947 options_mem_dupe(td->eo, td->io_ops->options);
949 memset(td->eo, 0, td->io_ops->option_struct_size);
950 fill_default_options(td->eo, td->io_ops->options);
952 *(struct thread_data **)td->eo = td;
958 static void init_flags(struct thread_data *td)
960 struct thread_options *o = &td->o;
962 if (o->verify_backlog)
963 td->flags |= TD_F_VER_BACKLOG;
965 td->flags |= TD_F_TRIM_BACKLOG;
966 if (o->read_iolog_file)
967 td->flags |= TD_F_READ_IOLOG;
968 if (o->refill_buffers)
969 td->flags |= TD_F_REFILL_BUFFERS;
971 * Always scramble buffers if asked to
973 if (o->scramble_buffers && fio_option_is_set(o, scramble_buffers))
974 td->flags |= TD_F_SCRAMBLE_BUFFERS;
976 * But also scramble buffers, unless we were explicitly asked
979 if (o->scramble_buffers && !(o->zero_buffers &&
980 fio_option_is_set(o, zero_buffers)))
981 td->flags |= TD_F_SCRAMBLE_BUFFERS;
982 if (o->verify != VERIFY_NONE)
983 td->flags |= TD_F_VER_NONE;
985 if (o->verify_async || o->io_submit_mode == IO_MODE_OFFLOAD)
986 td->flags |= TD_F_NEED_LOCK;
989 static int setup_random_seeds(struct thread_data *td)
994 if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed))
995 return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds));
997 seed = td->o.rand_seed;
998 for (i = 0; i < 4; i++)
999 seed *= 0x9e370001UL;
1001 for (i = 0; i < FIO_RAND_NR_OFFS; i++) {
1002 td->rand_seeds[i] = seed;
1003 seed *= 0x9e370001UL;
1006 td_fill_rand_seeds(td);
1017 static struct fpre_keyword {
1018 const char *keyword;
1021 } fpre_keywords[] = {
1022 { .keyword = "$jobname", .key = FPRE_JOBNAME, },
1023 { .keyword = "$jobnum", .key = FPRE_JOBNUM, },
1024 { .keyword = "$filenum", .key = FPRE_FILENUM, },
1025 { .keyword = NULL, },
1028 static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
1029 const char *jobname, int jobnum, int filenum)
1031 struct fpre_keyword *f;
1032 char copy[PATH_MAX];
1033 size_t dst_left = PATH_MAX - 1;
1035 if (!o->filename_format || !strlen(o->filename_format)) {
1036 sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum);
1040 for (f = &fpre_keywords[0]; f->keyword; f++)
1041 f->strlen = strlen(f->keyword);
1043 buf[buf_size - 1] = '\0';
1044 strncpy(buf, o->filename_format, buf_size - 1);
1046 memset(copy, 0, sizeof(copy));
1047 for (f = &fpre_keywords[0]; f->keyword; f++) {
1049 size_t pre_len, post_start = 0;
1050 char *str, *dst = copy;
1052 str = strcasestr(buf, f->keyword);
1056 pre_len = str - buf;
1057 if (strlen(str) != f->strlen)
1058 post_start = pre_len + f->strlen;
1061 strncpy(dst, buf, pre_len);
1063 dst_left -= pre_len;
1067 case FPRE_JOBNAME: {
1070 ret = snprintf(dst, dst_left, "%s", jobname);
1073 else if (ret > dst_left) {
1074 log_err("fio: truncated filename\n");
1086 ret = snprintf(dst, dst_left, "%d", jobnum);
1089 else if (ret > dst_left) {
1090 log_err("fio: truncated filename\n");
1099 case FPRE_FILENUM: {
1102 ret = snprintf(dst, dst_left, "%d", filenum);
1105 else if (ret > dst_left) {
1106 log_err("fio: truncated filename\n");
1121 strncpy(dst, buf + post_start, dst_left);
1123 strncpy(buf, copy, buf_size - 1);
1130 int parse_dryrun(void)
1132 return dump_cmdline || parse_only;
1135 static void gen_log_name(char *name, size_t size, const char *logtype,
1136 const char *logname, unsigned int num,
1137 const char *suf, int per_job)
1140 snprintf(name, size, "%s_%s.%d.%s", logname, logtype, num, suf);
1142 snprintf(name, size, "%s_%s.%s", logname, logtype, suf);
1146 * Adds a job to the list of things todo. Sanitizes the various options
1147 * to make sure we don't have conflicts, and initializes various
1150 static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
1151 int recursed, int client_type)
1154 char fname[PATH_MAX];
1155 int numjobs, file_alloced;
1156 struct thread_options *o = &td->o;
1157 char logname[PATH_MAX + 32];
1160 * the def_thread is just for options, it's not a real job
1162 if (td == &def_thread)
1168 * if we are just dumping the output command line, don't add the job
1170 if (parse_dryrun()) {
1175 td->client_type = client_type;
1177 if (profile_td_init(td))
1180 if (ioengine_load(td))
1184 td->io_ops->flags |= FIO_RAWIO;
1187 if (!o->filename && !td->files_index && !o->read_iolog_file) {
1190 if (o->nr_files == 1 && exists_and_not_file(jobname))
1191 add_file(td, jobname, job_add_num, 0);
1193 for (i = 0; i < o->nr_files; i++)
1194 add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0);
1198 if (fixup_options(td))
1204 * IO engines only need this for option callbacks, and the address may
1205 * change in subprocesses.
1208 *(struct thread_data **)td->eo = NULL;
1210 if (td->io_ops->flags & FIO_DISKLESSIO) {
1213 for_each_file(td, f, i)
1214 f->real_file_size = -1ULL;
1217 td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
1219 td->ts.clat_percentiles = o->clat_percentiles;
1220 td->ts.percentile_precision = o->percentile_precision;
1221 memcpy(td->ts.percentile_list, o->percentile_list, sizeof(o->percentile_list));
1223 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1224 td->ts.clat_stat[i].min_val = ULONG_MAX;
1225 td->ts.slat_stat[i].min_val = ULONG_MAX;
1226 td->ts.lat_stat[i].min_val = ULONG_MAX;
1227 td->ts.bw_stat[i].min_val = ULONG_MAX;
1229 td->ddir_seq_nr = o->ddir_seq_nr;
1231 if ((o->stonewall || o->new_group) && prev_group_jobs) {
1232 prev_group_jobs = 0;
1236 td->groupid = groupid;
1239 if (setup_random_seeds(td)) {
1240 td_verror(td, errno, "init_random_state");
1247 if (o->lat_log_file) {
1248 struct log_params p = {
1250 .avg_msec = o->log_avg_msec,
1251 .log_type = IO_LOG_TYPE_LAT,
1252 .log_offset = o->log_offset,
1253 .log_gz = o->log_gz,
1254 .log_gz_store = o->log_gz_store,
1263 gen_log_name(logname, sizeof(logname), "lat", o->lat_log_file,
1264 td->thread_number, suf, o->per_job_logs);
1265 setup_log(&td->lat_log, &p, logname);
1267 gen_log_name(logname, sizeof(logname), "slat", o->lat_log_file,
1268 td->thread_number, suf, o->per_job_logs);
1269 setup_log(&td->slat_log, &p, logname);
1271 gen_log_name(logname, sizeof(logname), "clat", o->lat_log_file,
1272 td->thread_number, suf, o->per_job_logs);
1273 setup_log(&td->clat_log, &p, logname);
1275 if (o->bw_log_file) {
1276 struct log_params p = {
1278 .avg_msec = o->log_avg_msec,
1279 .log_type = IO_LOG_TYPE_BW,
1280 .log_offset = o->log_offset,
1281 .log_gz = o->log_gz,
1282 .log_gz_store = o->log_gz_store,
1291 gen_log_name(logname, sizeof(logname), "bw", o->bw_log_file,
1292 td->thread_number, suf, o->per_job_logs);
1293 setup_log(&td->bw_log, &p, logname);
1295 if (o->iops_log_file) {
1296 struct log_params p = {
1298 .avg_msec = o->log_avg_msec,
1299 .log_type = IO_LOG_TYPE_IOPS,
1300 .log_offset = o->log_offset,
1301 .log_gz = o->log_gz,
1302 .log_gz_store = o->log_gz_store,
1311 gen_log_name(logname, sizeof(logname), "iops", o->iops_log_file,
1312 td->thread_number, suf, o->per_job_logs);
1313 setup_log(&td->iops_log, &p, logname);
1317 o->name = strdup(jobname);
1319 if (output_format & FIO_OUTPUT_NORMAL) {
1321 if (is_backend && !recursed)
1322 fio_server_send_add_job(td);
1324 if (!(td->io_ops->flags & FIO_NOIO)) {
1325 char *c1, *c2, *c3, *c4;
1326 char *c5 = NULL, *c6 = NULL;
1328 c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
1329 c2 = fio_uint_to_kmg(o->max_bs[DDIR_READ]);
1330 c3 = fio_uint_to_kmg(o->min_bs[DDIR_WRITE]);
1331 c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
1333 if (!o->bs_is_seq_rand) {
1334 c5 = fio_uint_to_kmg(o->min_bs[DDIR_TRIM]);
1335 c6 = fio_uint_to_kmg(o->max_bs[DDIR_TRIM]);
1338 log_info("%s: (g=%d): rw=%s, ", td->o.name,
1340 ddir_str(o->td_ddir));
1342 if (o->bs_is_seq_rand)
1343 log_info("bs(seq/rand)=%s-%s/%s-%s, ",
1346 log_info("bs=%s-%s/%s-%s/%s-%s, ",
1347 c1, c2, c3, c4, c5, c6);
1349 log_info("ioengine=%s, iodepth=%u\n",
1350 td->io_ops->name, o->iodepth);
1359 } else if (job_add_num == 1)
1364 * recurse add identical jobs, clear numjobs and stonewall options
1365 * as they don't apply to sub-jobs
1367 numjobs = o->numjobs;
1369 struct thread_data *td_new = get_new_job(0, td, 1, jobname);
1374 td_new->o.numjobs = 1;
1375 td_new->o.stonewall = 0;
1376 td_new->o.new_group = 0;
1377 td_new->subjob_number = numjobs;
1380 if (td_new->files) {
1382 for_each_file(td_new, f, i) {
1384 sfree(f->file_name);
1387 free(td_new->files);
1388 td_new->files = NULL;
1390 td_new->files_index = 0;
1391 td_new->files_size = 0;
1392 if (td_new->o.filename) {
1393 free(td_new->o.filename);
1394 td_new->o.filename = NULL;
1398 if (add_job(td_new, jobname, numjobs, 1, client_type))
1409 * Parse as if 'o' was a command line
1411 void add_job_opts(const char **o, int client_type)
1413 struct thread_data *td, *td_parent;
1414 int i, in_global = 1;
1418 td_parent = td = NULL;
1420 if (!strncmp(o[i], "name", 4)) {
1423 add_job(td, jobname, 0, 0, client_type);
1425 sprintf(jobname, "%s", o[i] + 5);
1427 if (in_global && !td_parent)
1428 td_parent = get_new_job(1, &def_thread, 0, jobname);
1429 else if (!in_global && !td) {
1431 td_parent = &def_thread;
1432 td = get_new_job(0, td_parent, 0, jobname);
1435 fio_options_parse(td_parent, (char **) &o[i], 1, 0);
1437 fio_options_parse(td, (char **) &o[i], 1, 0);
1442 add_job(td, jobname, 0, 0, client_type);
1445 static int skip_this_section(const char *name)
1449 if (!nr_job_sections)
1451 if (!strncmp(name, "global", 6))
1454 for (i = 0; i < nr_job_sections; i++)
1455 if (!strcmp(job_sections[i], name))
1461 static int is_empty_or_comment(char *line)
1465 for (i = 0; i < strlen(line); i++) {
1470 if (!isspace((int) line[i]) && !iscntrl((int) line[i]))
1478 * This is our [ini] type file parser.
1480 int __parse_jobs_ini(struct thread_data *td,
1481 char *file, int is_buf, int stonewall_flag, int type,
1482 int nested, char *name, char ***popts, int *aopts, int *nopts)
1484 unsigned int global = 0;
1488 int ret = 0, stonewall;
1491 int inside_skip = 0;
1493 int i, alloc_opts, num_opts;
1495 dprint(FD_PARSE, "Parsing ini file %s\n", file);
1496 assert(td || !nested);
1501 if (!strcmp(file, "-"))
1504 f = fopen(file, "r");
1509 log_err("fio: unable to open '%s' job file\n", file);
1511 td_verror(td, __err, "job file open");
1516 string = malloc(4096);
1519 * it's really 256 + small bit, 280 should suffice
1523 memset(name, 0, 280);
1527 if (nested && popts) {
1529 alloc_opts = *aopts;
1535 opts = malloc(sizeof(char *) * alloc_opts);
1539 stonewall = stonewall_flag;
1542 * if skip_fgets is set, we already have loaded a line we
1547 p = strsep(&file, "\n");
1549 p = fgets(string, 4096, f);
1555 strip_blank_front(&p);
1558 dprint(FD_PARSE, "%s\n", p);
1559 if (is_empty_or_comment(p))
1563 if (sscanf(p, "[%255[^\n]]", name) != 1) {
1567 log_err("fio: option <%s> outside of "
1568 "[] job section\n", p);
1573 name[strlen(name) - 1] = '\0';
1575 if (skip_this_section(name)) {
1581 dprint(FD_PARSE, "Parsing section [%s]\n", name);
1583 global = !strncmp(name, "global", 6);
1589 log_info("--name=%s ", name);
1593 td = get_new_job(global, &def_thread, 0, name);
1600 * Separate multiple job files by a stonewall
1602 if (!global && stonewall) {
1603 td->o.stonewall = stonewall;
1608 memset(opts, 0, alloc_opts * sizeof(char *));
1616 p = strsep(&file, "\n");
1618 p = fgets(string, 4096, f);
1621 dprint(FD_PARSE, "%s", p);
1626 if (is_empty_or_comment(p))
1629 strip_blank_front(&p);
1632 * new section, break out and make sure we don't
1633 * fgets() a new line at the top.
1637 log_err("No new sections in included files\n");
1647 if (!strncmp(p, "include", strlen("include"))) {
1648 char *filename = p + strlen("include") + 1;
1650 if ((ret = __parse_jobs_ini(td, filename,
1651 is_buf, stonewall_flag, type, 1,
1652 name, &opts, &alloc_opts, &num_opts))) {
1653 log_err("Error %d while parsing include file %s\n",
1660 if (num_opts == alloc_opts) {
1662 opts = realloc(opts,
1663 alloc_opts * sizeof(char *));
1666 opts[num_opts] = strdup(p);
1672 *aopts = alloc_opts;
1677 ret = fio_options_parse(td, opts, num_opts, dump_cmdline);
1679 ret = add_job(td, name, 0, 0, type);
1681 log_err("fio: job %s dropped\n", name);
1685 for (i = 0; i < num_opts; i++)
1694 while (i < nr_job_sections) {
1695 free(job_sections[i]);
1704 if (!is_buf && f != stdin)
1709 int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
1711 return __parse_jobs_ini(NULL, file, is_buf, stonewall_flag, type,
1712 0, NULL, NULL, NULL, NULL);
1715 static int fill_def_thread(void)
1717 memset(&def_thread, 0, sizeof(def_thread));
1719 fio_getaffinity(getpid(), &def_thread.o.cpumask);
1720 def_thread.o.error_dump = 1;
1723 * fill default options
1725 fio_fill_default_options(&def_thread);
1729 static void show_debug_categories(void)
1731 struct debug_level *dl = &debug_levels[0];
1732 int curlen, first = 1;
1736 int has_next = (dl + 1)->name != NULL;
1738 if (first || curlen + strlen(dl->name) >= 80) {
1743 curlen += printf("\t\t\t%s", dl->name);
1744 curlen += 3 * (8 - 1);
1746 curlen += printf(",");
1748 curlen += printf("%s", dl->name);
1750 curlen += printf(",");
1758 static void usage(const char *name)
1760 printf("%s\n", fio_version_string);
1761 printf("%s [options] [job options] <job file(s)>\n", name);
1762 printf(" --debug=options\tEnable debug logging. May be one/more of:\n");
1763 show_debug_categories();
1764 printf(" --parse-only\t\tParse options only, don't start any IO\n");
1765 printf(" --output\t\tWrite output to file\n");
1766 printf(" --runtime\t\tRuntime in seconds\n");
1767 printf(" --bandwidth-log\tGenerate per-job bandwidth logs\n");
1768 printf(" --minimal\t\tMinimal (terse) output\n");
1769 printf(" --output-format=x\tOutput format (terse,json,normal)\n");
1770 printf(" --terse-version=x\tSet terse version output format to 'x'\n");
1771 printf(" --version\t\tPrint version info and exit\n");
1772 printf(" --help\t\tPrint this page\n");
1773 printf(" --cpuclock-test\tPerform test/validation of CPU clock\n");
1774 printf(" --crctest\t\tTest speed of checksum functions\n");
1775 printf(" --cmdhelp=cmd\t\tPrint command help, \"all\" for all of"
1777 printf(" --enghelp=engine\tPrint ioengine help, or list"
1778 " available ioengines\n");
1779 printf(" --enghelp=engine,cmd\tPrint help for an ioengine"
1781 printf(" --showcmd\t\tTurn a job file into command line options\n");
1782 printf(" --eta=when\t\tWhen ETA estimate should be printed\n");
1783 printf(" \t\tMay be \"always\", \"never\" or \"auto\"\n");
1784 printf(" --eta-newline=time\tForce a new line for every 'time'");
1785 printf(" period passed\n");
1786 printf(" --status-interval=t\tForce full status dump every");
1787 printf(" 't' period passed\n");
1788 printf(" --readonly\t\tTurn on safety read-only checks, preventing"
1790 printf(" --section=name\tOnly run specified section in job file\n");
1791 printf(" --alloc-size=kb\tSet smalloc pool to this size in kb"
1793 printf(" --warnings-fatal\tFio parser warnings are fatal\n");
1794 printf(" --max-jobs=nr\t\tMaximum number of threads/processes to support\n");
1795 printf(" --server=args\t\tStart a backend fio server\n");
1796 printf(" --daemonize=pidfile\tBackground fio server, write pid to file\n");
1797 printf(" --client=hostname\tTalk to remote backend fio server at hostname\n");
1798 printf(" --remote-config=file\tTell fio server to load this local job file\n");
1799 printf(" --idle-prof=option\tReport cpu idleness on a system or percpu basis\n"
1800 "\t\t\t(option=system,percpu) or run unit work\n"
1801 "\t\t\tcalibration only (option=calibrate)\n");
1803 printf(" --inflate-log=log\tInflate and output compressed log\n");
1805 printf(" --trigger-file=file\tExecute trigger cmd when file exists\n");
1806 printf(" --trigger-timeout=t\tExecute trigger af this time\n");
1807 printf(" --trigger=cmd\t\tSet this command as local trigger\n");
1808 printf(" --trigger-remote=cmd\tSet this command as remote trigger\n");
1809 printf(" --aux-path=path\tUse this path for fio state generated files\n");
1810 printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
1811 printf("\n Jens Axboe <jaxboe@fusionio.com>");
1812 printf("\n Jens Axboe <axboe@fb.com>\n");
1815 #ifdef FIO_INC_DEBUG
1816 struct debug_level debug_levels[] = {
1817 { .name = "process",
1818 .help = "Process creation/exit logging",
1819 .shift = FD_PROCESS,
1822 .help = "File related action logging",
1826 .help = "IO and IO engine action logging (offsets, queue, completions, etc)",
1830 .help = "Memory allocation/freeing logging",
1833 { .name = "blktrace",
1834 .help = "blktrace action logging",
1835 .shift = FD_BLKTRACE,
1838 .help = "IO verification action logging",
1842 .help = "Random generation logging",
1846 .help = "Parser logging",
1849 { .name = "diskutil",
1850 .help = "Disk utility logging actions",
1851 .shift = FD_DISKUTIL,
1854 .help = "Logging related to creating/destroying jobs",
1858 .help = "Mutex logging",
1861 { .name = "profile",
1862 .help = "Logging related to profiles",
1863 .shift = FD_PROFILE,
1866 .help = "Logging related to time keeping functions",
1870 .help = "Network logging",
1874 .help = "Rate logging",
1877 { .name = "compress",
1878 .help = "Log compression logging",
1879 .shift = FD_COMPRESS,
1884 static int set_debug(const char *string)
1886 struct debug_level *dl;
1887 char *p = (char *) string;
1891 if (!strcmp(string, "?") || !strcmp(string, "help")) {
1892 log_info("fio: dumping debug options:");
1893 for (i = 0; debug_levels[i].name; i++) {
1894 dl = &debug_levels[i];
1895 log_info("%s,", dl->name);
1901 while ((opt = strsep(&p, ",")) != NULL) {
1904 if (!strncmp(opt, "all", 3)) {
1905 log_info("fio: set all debug options\n");
1910 for (i = 0; debug_levels[i].name; i++) {
1911 dl = &debug_levels[i];
1912 found = !strncmp(opt, dl->name, strlen(dl->name));
1916 if (dl->shift == FD_JOB) {
1917 opt = strchr(opt, ':');
1919 log_err("fio: missing job number\n");
1923 fio_debug_jobno = atoi(opt);
1924 log_info("fio: set debug jobno %d\n",
1927 log_info("fio: set debug option %s\n", opt);
1928 fio_debug |= (1UL << dl->shift);
1934 log_err("fio: debug mask %s not found\n", opt);
1939 static int set_debug(const char *string)
1941 log_err("fio: debug tracing not included in build\n");
1946 static void fio_options_fill_optstring(void)
1948 char *ostr = cmd_optstr;
1952 while (l_opts[i].name) {
1953 ostr[c++] = l_opts[i].val;
1954 if (l_opts[i].has_arg == required_argument)
1956 else if (l_opts[i].has_arg == optional_argument) {
1965 static int client_flag_set(char c)
1970 while (l_opts[i].name) {
1971 int val = l_opts[i].val;
1973 if (c == (val & 0xff))
1974 return (val & FIO_CLIENT_FLAG);
1982 static void parse_cmd_client(void *client, char *opt)
1984 fio_client_add_cmd_option(client, opt);
1987 static void show_closest_option(const char *name)
1989 int best_option, best_distance;
1992 while (*name == '-')
1996 best_distance = INT_MAX;
1998 while (l_opts[i].name) {
1999 distance = string_distance(name, l_opts[i].name);
2000 if (distance < best_distance) {
2001 best_distance = distance;
2007 if (best_option != -1 && string_distance_ok(name, best_distance))
2008 log_err("Did you mean %s?\n", l_opts[best_option].name);
2011 static int parse_output_format(const char *optarg)
2013 char *p, *orig, *opt;
2016 p = orig = strdup(optarg);
2020 while ((opt = strsep(&p, ",")) != NULL) {
2021 if (!strcmp(opt, "minimal") ||
2022 !strcmp(opt, "terse") ||
2023 !strcmp(opt, "csv"))
2024 output_format |= FIO_OUTPUT_TERSE;
2025 else if (!strcmp(opt, "json"))
2026 output_format |= FIO_OUTPUT_JSON;
2027 else if (!strcmp(opt, "normal"))
2028 output_format |= FIO_OUTPUT_NORMAL;
2030 log_err("fio: invalid output format %s\n", opt);
2040 int parse_cmd_line(int argc, char *argv[], int client_type)
2042 struct thread_data *td = NULL;
2043 int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
2044 char *ostr = cmd_optstr;
2045 void *pid_file = NULL;
2046 void *cur_client = NULL;
2050 * Reset optind handling, since we may call this multiple times
2055 while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
2056 if ((c & FIO_CLIENT_FLAG) || client_flag_set(c)) {
2057 parse_cmd_client(cur_client, argv[optind - 1]);
2058 c &= ~FIO_CLIENT_FLAG;
2063 smalloc_pool_size = atoi(optarg);
2066 if (check_str_time(optarg, &def_timeout, 1)) {
2067 log_err("fio: failed parsing time %s\n", optarg);
2073 log_err("fio: --latency-log is deprecated. Use per-job latency log options.\n");
2081 if (f_out && f_out != stdout)
2084 f_out = fopen(optarg, "w+");
2086 perror("fopen output");
2092 output_format = FIO_OUTPUT_TERSE;
2096 log_err("fio: missing --output-format argument\n");
2101 if (parse_output_format(optarg)) {
2102 log_err("fio: failed parsing output-format\n");
2109 output_format |= FIO_OUTPUT_TERSE;
2121 fio_show_option_help(optarg);
2128 fio_show_ioengine_help(optarg);
2142 log_info("%s\n", fio_version_string);
2147 terse_version = atoi(optarg);
2148 if (!(terse_version == 2 || terse_version == 3 ||
2149 terse_version == 4)) {
2150 log_err("fio: bad terse version format\n");
2156 if (!strcmp("always", optarg))
2157 eta_print = FIO_ETA_ALWAYS;
2158 else if (!strcmp("never", optarg))
2159 eta_print = FIO_ETA_NEVER;
2164 if (check_str_time(optarg, &t, 1)) {
2165 log_err("fio: failed parsing eta time %s\n", optarg);
2169 eta_new_line = t / 1000;
2173 if (set_debug(optarg))
2183 if (!strcmp(optarg, "global")) {
2184 log_err("fio: can't use global as only "
2190 new_size = (nr_job_sections + 1) * sizeof(char *);
2191 job_sections = realloc(job_sections, new_size);
2192 job_sections[nr_job_sections] = strdup(optarg);
2198 exit_val = iolog_file_inflate(optarg);
2207 exec_profile = strdup(optarg);
2209 case FIO_GETOPT_JOB: {
2210 const char *opt = l_opts[lidx].name;
2213 if (!strncmp(opt, "name", 4) && td) {
2214 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
2221 int is_section = !strncmp(opt, "name", 4);
2224 if (!is_section || !strncmp(val, "global", 6))
2227 if (is_section && skip_this_section(val))
2230 td = get_new_job(global, &def_thread, 1, NULL);
2231 if (!td || ioengine_load(td)) {
2240 fio_options_set_ioengine_opts(l_opts, td);
2243 if ((!val || !strlen(val)) &&
2244 l_opts[lidx].has_arg == required_argument) {
2245 log_err("fio: option %s requires an argument\n", opt);
2248 ret = fio_cmd_option_parse(td, opt, val);
2259 if (!ret && !strcmp(opt, "ioengine")) {
2261 if (ioengine_load(td)) {
2268 fio_options_set_ioengine_opts(l_opts, td);
2272 case FIO_GETOPT_IOENGINE: {
2273 const char *opt = l_opts[lidx].name;
2279 ret = fio_cmd_ioengine_option_parse(td, opt, val);
2286 max_jobs = atoi(optarg);
2287 if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
2288 log_err("fio: invalid max jobs: %d\n", max_jobs);
2295 #ifndef CONFIG_NO_SHM
2297 log_err("fio: can't be both client and server\n");
2303 fio_server_set_arg(optarg);
2307 log_err("fio: client/server requires SHM support\n");
2315 pid_file = strdup(optarg);
2318 if ((ret = fio_idle_prof_parse_opt(optarg))) {
2319 /* exit on error and calibration only */
2329 log_err("fio: can't be both client and server\n");
2334 /* if --client parameter contains a pathname */
2335 if (0 == access(optarg, R_OK)) {
2336 /* file contains a list of host addrs or names */
2337 char hostaddr[PATH_MAX] = {0};
2339 FILE * hostf = fopen(optarg, "r");
2341 log_err("fio: could not open client list file %s for read\n", optarg);
2346 sprintf(formatstr, "%%%ds", PATH_MAX - 1);
2348 * read at most PATH_MAX-1 chars from each
2349 * record in this file
2351 while (fscanf(hostf, formatstr, hostaddr) == 1) {
2352 /* expect EVERY host in file to be valid */
2353 if (fio_client_add(&fio_client_ops, hostaddr, &cur_client)) {
2354 log_err("fio: failed adding client %s from file %s\n", hostaddr, optarg);
2361 break; /* no possibility of job file for "this client only" */
2363 if (fio_client_add(&fio_client_ops, optarg, &cur_client)) {
2364 log_err("fio: failed adding client %s\n", optarg);
2370 * If the next argument exists and isn't an option,
2371 * assume it's a job file for this client only.
2373 while (optind < argc) {
2374 if (!strncmp(argv[optind], "--", 2) ||
2375 !strncmp(argv[optind], "-", 1))
2378 if (fio_client_add_ini_file(cur_client, argv[optind], 0))
2385 if (fio_client_add_ini_file(cur_client, optarg, 1)) {
2393 exit_val = fio_monotonic_clocktest(1);
2398 exit_val = fio_crctest(optarg);
2403 if (check_str_time(optarg, &val, 1)) {
2404 log_err("fio: failed parsing time %s\n", optarg);
2409 status_interval = val / 1000;
2415 trigger_file = strdup(optarg);
2420 trigger_cmd = strdup(optarg);
2423 if (trigger_remote_cmd)
2424 free(trigger_remote_cmd);
2425 trigger_remote_cmd = strdup(optarg);
2430 aux_path = strdup(optarg);
2433 if (check_str_time(optarg, &trigger_timeout, 1)) {
2434 log_err("fio: failed parsing time %s\n", optarg);
2438 trigger_timeout /= 1000000;
2441 log_err("%s: unrecognized option '%s'\n", argv[0],
2443 show_closest_option(argv[optind - 1]);
2453 if (do_exit && !(is_backend || nr_clients))
2456 if (nr_clients && fio_clients_connect())
2459 if (is_backend && backend)
2460 return fio_start_server(pid_file);
2466 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
2472 while (!ret && optind < argc) {
2474 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
2475 ini_file[ini_idx - 1] = strdup(argv[optind]);
2486 int fio_init_options(void)
2491 fio_options_fill_optstring();
2492 fio_options_dup_and_init(l_opts);
2496 if (fill_def_thread())
2502 extern int fio_check_options(struct thread_options *);
2504 int parse_options(int argc, char *argv[])
2506 const int type = FIO_CLIENT_TYPE_CLI;
2509 if (fio_init_options())
2511 if (fio_test_cconv(&def_thread.o))
2512 log_err("fio: failed internal cconv test\n");
2514 job_files = parse_cmd_line(argc, argv, type);
2516 if (job_files > 0) {
2517 for (i = 0; i < job_files; i++) {
2518 if (i && fill_def_thread())
2521 if (fio_clients_send_ini(ini_file[i]))
2524 } else if (!is_backend) {
2525 if (parse_jobs_ini(ini_file[i], 0, i, type))
2530 } else if (nr_clients) {
2531 if (fill_def_thread())
2533 if (fio_clients_send_ini(NULL))
2538 fio_options_free(&def_thread);
2539 filesetup_mem_free();
2541 if (!thread_number) {
2546 if (is_backend || nr_clients)
2551 log_err("No jobs(s) defined\n\n");
2561 if (output_format & FIO_OUTPUT_NORMAL)
2562 log_info("%s\n", fio_version_string);
2567 void options_default_fill(struct thread_options *o)
2569 memcpy(o, &def_thread.o, sizeof(*o));