2 * This file contains job initialization and setup functions.
13 #include <sys/types.h>
24 #include "lib/getopt.h"
26 static char fio_version_string[] = "fio 1.58";
28 #define FIO_RANDSEED (0xb1899bedUL)
30 static char **ini_file;
31 static int max_jobs = FIO_MAX_JOBS;
32 static int dump_cmdline;
34 static struct thread_data def_thread;
35 struct thread_data *threads = NULL;
37 int exitall_on_terminate = 0;
40 unsigned long long mlock_size = 0;
43 char **job_sections = NULL;
44 int nr_job_sections = 0;
45 char *exec_profile = NULL;
46 int warnings_fatal = 0;
47 int terse_version = 2;
55 static int write_lat_log;
57 static int prev_group_jobs;
59 unsigned long fio_debug = 0;
60 unsigned int fio_debug_jobno = -1;
61 unsigned int *fio_debug_jobp = NULL;
63 static char cmd_optstr[256];
66 * Command line options. These will contain the above, plus a few
67 * extra that only pertain to fio itself and not jobs.
69 static struct option l_opts[FIO_NR_OPTIONS] = {
71 .name = (char *) "output",
72 .has_arg = required_argument,
76 .name = (char *) "timeout",
77 .has_arg = required_argument,
81 .name = (char *) "latency-log",
82 .has_arg = required_argument,
86 .name = (char *) "bandwidth-log",
87 .has_arg = required_argument,
91 .name = (char *) "minimal",
92 .has_arg = optional_argument,
96 .name = (char *) "version",
97 .has_arg = no_argument,
101 .name = (char *) "help",
102 .has_arg = no_argument,
106 .name = (char *) "cmdhelp",
107 .has_arg = optional_argument,
111 .name = (char *) "showcmd",
112 .has_arg = no_argument,
116 .name = (char *) "readonly",
117 .has_arg = no_argument,
121 .name = (char *) "eta",
122 .has_arg = required_argument,
126 .name = (char *) "debug",
127 .has_arg = required_argument,
131 .name = (char *) "section",
132 .has_arg = required_argument,
136 .name = (char *) "alloc-size",
137 .has_arg = required_argument,
141 .name = (char *) "profile",
142 .has_arg = required_argument,
146 .name = (char *) "warnings-fatal",
147 .has_arg = no_argument,
151 .name = (char *) "max-jobs",
152 .has_arg = required_argument,
156 .name = (char *) "terse-version",
157 .has_arg = required_argument,
161 .name = (char *) "server",
162 .has_arg = no_argument,
166 .name = (char *) "net-port",
167 .has_arg = required_argument,
171 .name = (char *) "client",
172 .has_arg = required_argument,
191 * Return a free job structure.
193 static struct thread_data *get_new_job(int global, struct thread_data *parent)
195 struct thread_data *td;
199 if (thread_number >= max_jobs) {
200 log_err("error: maximum number of jobs (%d) reached.\n",
205 td = &threads[thread_number++];
208 td->o.uid = td->o.gid = -1U;
210 dup_files(td, parent);
211 options_mem_dupe(td);
213 profile_add_hooks(td);
215 td->thread_number = thread_number;
219 static void put_job(struct thread_data *td)
221 if (td == &def_thread)
227 log_info("fio: %s\n", td->verror);
229 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
233 static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
235 unsigned int bs = td->o.min_bs[ddir];
236 unsigned long long bytes_per_sec;
238 assert(ddir_rw(ddir));
240 if (td->o.rate[ddir])
241 bytes_per_sec = td->o.rate[ddir];
243 bytes_per_sec = td->o.rate_iops[ddir] * bs;
245 if (!bytes_per_sec) {
246 log_err("rate lower than supported\n");
250 td->rate_nsec_cycle[ddir] = 1000000000ULL / bytes_per_sec;
251 td->rate_pending_usleep[ddir] = 0;
255 static int setup_rate(struct thread_data *td)
259 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
260 ret = __setup_rate(td, DDIR_READ);
261 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
262 ret |= __setup_rate(td, DDIR_WRITE);
267 static int fixed_block_size(struct thread_options *o)
269 return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
270 o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
271 o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE];
275 * Lazy way of fixing up options that depend on each other. We could also
276 * define option callback handlers, but this is easier.
278 static int fixup_options(struct thread_data *td)
280 struct thread_options *o = &td->o;
283 #ifndef FIO_HAVE_PSHARED_MUTEX
284 if (!o->use_thread) {
285 log_info("fio: this platform does not support process shared"
286 " mutexes, forcing use of threads. Use the 'thread'"
287 " option to get rid of this warning.\n");
289 ret = warnings_fatal;
293 if (o->write_iolog_file && o->read_iolog_file) {
294 log_err("fio: read iolog overrides write_iolog\n");
295 free(o->write_iolog_file);
296 o->write_iolog_file = NULL;
297 ret = warnings_fatal;
301 * only really works for sequential io for now, and with 1 file
303 if (o->zone_size && td_random(td) && o->open_files == 1)
307 * Reads can do overwrites, we always need to pre-create the file
309 if (td_read(td) || td_rw(td))
312 if (!o->min_bs[DDIR_READ])
313 o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
314 if (!o->max_bs[DDIR_READ])
315 o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
316 if (!o->min_bs[DDIR_WRITE])
317 o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
318 if (!o->max_bs[DDIR_WRITE])
319 o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
321 o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
324 * For random IO, allow blockalign offset other than min_bs.
326 if (!o->ba[DDIR_READ] || !td_random(td))
327 o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
328 if (!o->ba[DDIR_WRITE] || !td_random(td))
329 o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
331 if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
332 o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE]) &&
334 log_err("fio: Any use of blockalign= turns off randommap\n");
336 ret = warnings_fatal;
339 if (!o->file_size_high)
340 o->file_size_high = o->file_size_low;
342 if (o->norandommap && o->verify != VERIFY_NONE
343 && !fixed_block_size(o)) {
344 log_err("fio: norandommap given for variable block sizes, "
345 "verify disabled\n");
346 o->verify = VERIFY_NONE;
347 ret = warnings_fatal;
349 if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
350 log_err("fio: bs_unaligned may not work with raw io\n");
353 * thinktime_spin must be less than thinktime
355 if (o->thinktime_spin > o->thinktime)
356 o->thinktime_spin = o->thinktime;
359 * The low water mark cannot be bigger than the iodepth
361 if (o->iodepth_low > o->iodepth || !o->iodepth_low) {
363 * syslet work around - if the workload is sequential,
364 * we want to let the queue drain all the way down to
365 * avoid seeking between async threads
367 if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
370 o->iodepth_low = o->iodepth;
374 * If batch number isn't set, default to the same as iodepth
376 if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
377 o->iodepth_batch = o->iodepth;
379 if (o->nr_files > td->files_index)
380 o->nr_files = td->files_index;
382 if (o->open_files > o->nr_files || !o->open_files)
383 o->open_files = o->nr_files;
385 if (((o->rate[0] + o->rate[1]) && (o->rate_iops[0] + o->rate_iops[1]))||
386 ((o->ratemin[0] + o->ratemin[1]) && (o->rate_iops_min[0] +
387 o->rate_iops_min[1]))) {
388 log_err("fio: rate and rate_iops are mutually exclusive\n");
391 if ((o->rate[0] < o->ratemin[0]) || (o->rate[1] < o->ratemin[1]) ||
392 (o->rate_iops[0] < o->rate_iops_min[0]) ||
393 (o->rate_iops[1] < o->rate_iops_min[1])) {
394 log_err("fio: minimum rate exceeds rate\n");
398 if (!o->timeout && o->time_based) {
399 log_err("fio: time_based requires a runtime/timeout setting\n");
401 ret = warnings_fatal;
404 if (o->fill_device && !o->size)
407 if (o->verify != VERIFY_NONE) {
408 if (td_write(td) && o->do_verify && o->numjobs > 1) {
409 log_info("Multiple writers may overwrite blocks that "
410 "belong to other jobs. This can cause "
411 "verification failures.\n");
412 ret = warnings_fatal;
415 o->refill_buffers = 1;
416 if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
418 o->verify_interval = o->min_bs[DDIR_WRITE];
422 o->invalidate_cache = 0;
423 if (td->io_ops->flags & FIO_PIPEIO) {
424 log_info("fio: cannot pre-read files with an IO engine"
425 " that isn't seekable. Pre-read disabled.\n");
426 ret = warnings_fatal;
430 #ifndef FIO_HAVE_FDATASYNC
431 if (o->fdatasync_blocks) {
432 log_info("fio: this platform does not support fdatasync()"
433 " falling back to using fsync(). Use the 'fsync'"
434 " option instead of 'fdatasync' to get rid of"
436 o->fsync_blocks = o->fdatasync_blocks;
437 o->fdatasync_blocks = 0;
438 ret = warnings_fatal;
446 * This function leaks the buffer
448 static char *to_kmg(unsigned int val)
450 char *buf = malloc(32);
451 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
462 snprintf(buf, 31, "%u%c", val, *p);
466 /* External engines are specified by "external:name.o") */
467 static const char *get_engine_name(const char *str)
469 char *p = strstr(str, ":");
475 strip_blank_front(&p);
480 static int exists_and_not_file(const char *filename)
484 if (lstat(filename, &sb) == -1)
487 /* \\.\ is the device namespace in Windows, where every file
488 * is a device node */
489 if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
495 static void td_fill_rand_seeds_os(struct thread_data *td)
497 os_random_seed(td->rand_seeds[0], &td->bsrange_state);
498 os_random_seed(td->rand_seeds[1], &td->verify_state);
499 os_random_seed(td->rand_seeds[2], &td->rwmix_state);
501 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
502 os_random_seed(td->rand_seeds[3], &td->next_file_state);
504 os_random_seed(td->rand_seeds[5], &td->file_size_state);
505 os_random_seed(td->rand_seeds[6], &td->trim_state);
510 if (td->o.rand_repeatable)
511 td->rand_seeds[4] = FIO_RANDSEED * td->thread_number;
513 os_random_seed(td->rand_seeds[4], &td->random_state);
516 static void td_fill_rand_seeds_internal(struct thread_data *td)
518 init_rand_seed(&td->__bsrange_state, td->rand_seeds[0]);
519 init_rand_seed(&td->__verify_state, td->rand_seeds[1]);
520 init_rand_seed(&td->__rwmix_state, td->rand_seeds[2]);
522 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
523 init_rand_seed(&td->__next_file_state, td->rand_seeds[3]);
525 init_rand_seed(&td->__file_size_state, td->rand_seeds[5]);
526 init_rand_seed(&td->__trim_state, td->rand_seeds[6]);
531 if (td->o.rand_repeatable)
532 td->rand_seeds[4] = FIO_RANDSEED * td->thread_number;
534 init_rand_seed(&td->__random_state, td->rand_seeds[4]);
537 void td_fill_rand_seeds(struct thread_data *td)
539 if (td->o.use_os_rand)
540 td_fill_rand_seeds_os(td);
542 td_fill_rand_seeds_internal(td);
544 init_rand_seed(&td->buf_state, td->rand_seeds[7]);
548 * Initialize the various random states we need (random io, block size ranges,
549 * read/write mix, etc).
551 static int init_random_state(struct thread_data *td)
555 fd = open("/dev/urandom", O_RDONLY);
557 td_verror(td, errno, "open");
561 if (read(fd, td->rand_seeds, sizeof(td->rand_seeds)) <
562 (int) sizeof(td->rand_seeds)) {
563 td_verror(td, EIO, "read");
569 td_fill_rand_seeds(td);
574 * Adds a job to the list of things todo. Sanitizes the various options
575 * to make sure we don't have conflicts, and initializes various
578 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
580 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
581 "randread", "randwrite", "randrw" };
584 char fname[PATH_MAX];
585 int numjobs, file_alloced;
588 * the def_thread is just for options, it's not a real job
590 if (td == &def_thread)
594 * if we are just dumping the output command line, don't add the job
601 if (profile_td_init(td))
604 engine = get_engine_name(td->o.ioengine);
605 td->io_ops = load_ioengine(td, engine);
607 log_err("fio: failed to load engine %s\n", engine);
611 if (td->o.use_thread)
617 td->io_ops->flags |= FIO_RAWIO;
620 if (!td->o.filename && !td->files_index && !td->o.read_iolog_file) {
623 if (td->o.nr_files == 1 && exists_and_not_file(jobname))
624 add_file(td, jobname);
626 for (i = 0; i < td->o.nr_files; i++) {
627 sprintf(fname, "%s.%d.%d", jobname,
628 td->thread_number, i);
634 if (fixup_options(td))
637 if (td->io_ops->flags & FIO_DISKLESSIO) {
640 for_each_file(td, f, i)
641 f->real_file_size = -1ULL;
644 td->mutex = fio_mutex_init(0);
646 td->ts.clat_percentiles = td->o.clat_percentiles;
647 if (td->o.overwrite_plist)
648 td->ts.percentile_list = td->o.percentile_list;
650 td->ts.percentile_list = NULL;
652 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
653 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
654 td->ts.lat_stat[0].min_val = td->ts.lat_stat[1].min_val = ULONG_MAX;
655 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
656 td->ddir_seq_nr = td->o.ddir_seq_nr;
658 if ((td->o.stonewall || td->o.new_group) && prev_group_jobs) {
663 td->groupid = groupid;
666 if (init_random_state(td))
672 if (td->o.write_lat_log) {
673 setup_log(&td->ts.lat_log);
674 setup_log(&td->ts.slat_log);
675 setup_log(&td->ts.clat_log);
677 if (td->o.write_bw_log)
678 setup_log(&td->ts.bw_log);
681 td->o.name = strdup(jobname);
685 if (!strcmp(td->io_ops->name, "cpuio")) {
686 log_info("%s: ioengine=cpu, cpuload=%u,"
687 " cpucycle=%u\n", td->o.name,
691 char *c1, *c2, *c3, *c4;
693 c1 = to_kmg(td->o.min_bs[DDIR_READ]);
694 c2 = to_kmg(td->o.max_bs[DDIR_READ]);
695 c3 = to_kmg(td->o.min_bs[DDIR_WRITE]);
696 c4 = to_kmg(td->o.max_bs[DDIR_WRITE]);
698 log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s,"
699 " ioengine=%s, iodepth=%u\n",
700 td->o.name, td->groupid,
701 ddir_str[td->o.td_ddir],
711 } else if (job_add_num == 1)
716 * recurse add identical jobs, clear numjobs and stonewall options
717 * as they don't apply to sub-jobs
719 numjobs = td->o.numjobs;
721 struct thread_data *td_new = get_new_job(0, td);
726 td_new->o.numjobs = 1;
727 td_new->o.stonewall = 0;
728 td_new->o.new_group = 0;
731 td_new->o.filename = NULL;
732 td_new->files_index = 0;
733 td_new->files_size = 0;
734 td_new->files = NULL;
737 job_add_num = numjobs - 1;
739 if (add_job(td_new, jobname, job_add_num))
750 * Parse as if 'o' was a command line
752 void add_job_opts(const char **o)
754 struct thread_data *td, *td_parent;
755 int i, in_global = 1;
759 td_parent = td = NULL;
761 if (!strncmp(o[i], "name", 4)) {
764 add_job(td, jobname, 0);
766 sprintf(jobname, "%s", o[i] + 5);
768 if (in_global && !td_parent)
769 td_parent = get_new_job(1, &def_thread);
770 else if (!in_global && !td) {
772 td_parent = &def_thread;
773 td = get_new_job(0, td_parent);
776 fio_options_parse(td_parent, (char **) &o[i], 1);
778 fio_options_parse(td, (char **) &o[i], 1);
783 add_job(td, jobname, 0);
786 static int skip_this_section(const char *name)
790 if (!nr_job_sections)
792 if (!strncmp(name, "global", 6))
795 for (i = 0; i < nr_job_sections; i++)
796 if (!strcmp(job_sections[i], name))
802 static int is_empty_or_comment(char *line)
806 for (i = 0; i < strlen(line); i++) {
811 if (!isspace((int) line[i]) && !iscntrl((int) line[i]))
819 * This is our [ini] type file parser.
821 int parse_jobs_ini(char *file, int is_buf, int stonewall_flag)
824 struct thread_data *td;
828 int ret = 0, stonewall;
833 int i, alloc_opts, num_opts;
838 if (!strcmp(file, "-"))
841 f = fopen(file, "r");
844 perror("fopen job file");
849 string = malloc(4096);
852 * it's really 256 + small bit, 280 should suffice
855 memset(name, 0, 280);
858 opts = malloc(sizeof(char *) * alloc_opts);
861 stonewall = stonewall_flag;
864 * if skip_fgets is set, we already have loaded a line we
869 p = strsep(&file, "\n");
871 p = fgets(string, 4095, f);
877 strip_blank_front(&p);
880 if (is_empty_or_comment(p))
882 if (sscanf(p, "[%255[^\n]]", name) != 1) {
885 log_err("fio: option <%s> outside of [] job section\n",
890 name[strlen(name) - 1] = '\0';
892 if (skip_this_section(name)) {
898 global = !strncmp(name, "global", 6);
904 log_info("--name=%s ", name);
908 td = get_new_job(global, &def_thread);
915 * Seperate multiple job files by a stonewall
917 if (!global && stonewall) {
918 td->o.stonewall = stonewall;
923 memset(opts, 0, alloc_opts * sizeof(char *));
927 p = strsep(&file, "\n");
929 p = fgets(string, 4096, f);
933 if (is_empty_or_comment(p))
936 strip_blank_front(&p);
939 * new section, break out and make sure we don't
940 * fgets() a new line at the top.
949 if (num_opts == alloc_opts) {
952 alloc_opts * sizeof(char *));
955 opts[num_opts] = strdup(p);
959 ret = fio_options_parse(td, opts, num_opts);
962 for (i = 0; i < num_opts; i++)
963 log_info("--%s ", opts[i]);
965 ret = add_job(td, name, 0);
967 log_err("fio: job %s dropped\n", name);
971 for (i = 0; i < num_opts; i++)
979 for (i = 0; i < num_opts; i++)
985 if (!is_buf && f != stdin)
990 static int fill_def_thread(void)
992 memset(&def_thread, 0, sizeof(def_thread));
994 fio_getaffinity(getpid(), &def_thread.o.cpumask);
997 * fill default options
999 fio_fill_default_options(&def_thread);
1003 static void free_shm(void)
1005 struct shmid_ds sbuf;
1012 fio_debug_jobp = NULL;
1014 shmctl(shm_id, IPC_RMID, &sbuf);
1021 * The thread area is shared between the main process and the job
1022 * threads/processes. So setup a shared memory segment that will hold
1023 * all the job info. We use the end of the region for keeping track of
1024 * open files across jobs, for file sharing.
1026 static int setup_thread_area(void)
1031 * 1024 is too much on some machines, scale max_jobs if
1032 * we get a failure that looks like too large a shm segment
1035 size_t size = max_jobs * sizeof(struct thread_data);
1037 size += file_hash_size;
1038 size += sizeof(unsigned int);
1040 shm_id = shmget(0, size, IPC_CREAT | 0600);
1043 if (errno != EINVAL) {
1054 threads = shmat(shm_id, NULL, 0);
1055 if (threads == (void *) -1) {
1060 memset(threads, 0, max_jobs * sizeof(struct thread_data));
1061 hash = (void *) threads + max_jobs * sizeof(struct thread_data);
1062 fio_debug_jobp = (void *) hash + file_hash_size;
1063 *fio_debug_jobp = -1;
1064 file_hash_init(hash);
1069 static void usage(const char *name)
1071 printf("%s\n", fio_version_string);
1072 printf("%s [options] [job options] <job file(s)>\n", name);
1073 printf("\t--debug=options\tEnable debug logging\n");
1074 printf("\t--output\tWrite output to file\n");
1075 printf("\t--timeout\tRuntime in seconds\n");
1076 printf("\t--latency-log\tGenerate per-job latency logs\n");
1077 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1078 printf("\t--minimal\tMinimal (terse) output\n");
1079 printf("\t--version\tPrint version info and exit\n");
1080 printf("\t--terse-version=x Terse version output format\n");
1081 printf("\t--help\t\tPrint this page\n");
1082 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of"
1084 printf("\t--showcmd\tTurn a job file into command line options\n");
1085 printf("\t--eta=when\tWhen ETA estimate should be printed\n");
1086 printf("\t \tMay be \"always\", \"never\" or \"auto\"\n");
1087 printf("\t--readonly\tTurn on safety read-only checks, preventing"
1089 printf("\t--section=name\tOnly run specified section in job file\n");
1090 printf("\t--alloc-size=kb\tSet smalloc pool to this size in kb"
1092 printf("\t--warnings-fatal Fio parser warnings are fatal\n");
1093 printf("\t--max-jobs\tMaximum number of threads/processes to support\n");
1094 printf("\t--server\tStart a backend fio server\n");
1095 printf("\t--client=hostname Talk to remove backend fio server at hostname\n");
1096 printf("\t--net-port=port\tUse specified port for client/server connection\n");
1097 printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
1098 printf("\n Jens Axboe <jaxboe@fusionio.com>\n");
1101 #ifdef FIO_INC_DEBUG
1102 struct debug_level debug_levels[] = {
1103 { .name = "process", .shift = FD_PROCESS, },
1104 { .name = "file", .shift = FD_FILE, },
1105 { .name = "io", .shift = FD_IO, },
1106 { .name = "mem", .shift = FD_MEM, },
1107 { .name = "blktrace", .shift = FD_BLKTRACE },
1108 { .name = "verify", .shift = FD_VERIFY },
1109 { .name = "random", .shift = FD_RANDOM },
1110 { .name = "parse", .shift = FD_PARSE },
1111 { .name = "diskutil", .shift = FD_DISKUTIL },
1112 { .name = "job", .shift = FD_JOB },
1113 { .name = "mutex", .shift = FD_MUTEX },
1114 { .name = "profile", .shift = FD_PROFILE },
1115 { .name = "time", .shift = FD_TIME },
1119 static int set_debug(const char *string)
1121 struct debug_level *dl;
1122 char *p = (char *) string;
1126 if (!strcmp(string, "?") || !strcmp(string, "help")) {
1127 log_info("fio: dumping debug options:");
1128 for (i = 0; debug_levels[i].name; i++) {
1129 dl = &debug_levels[i];
1130 log_info("%s,", dl->name);
1136 while ((opt = strsep(&p, ",")) != NULL) {
1139 if (!strncmp(opt, "all", 3)) {
1140 log_info("fio: set all debug options\n");
1145 for (i = 0; debug_levels[i].name; i++) {
1146 dl = &debug_levels[i];
1147 found = !strncmp(opt, dl->name, strlen(dl->name));
1151 if (dl->shift == FD_JOB) {
1152 opt = strchr(opt, ':');
1154 log_err("fio: missing job number\n");
1158 fio_debug_jobno = atoi(opt);
1159 log_info("fio: set debug jobno %d\n",
1162 log_info("fio: set debug option %s\n", opt);
1163 fio_debug |= (1UL << dl->shift);
1169 log_err("fio: debug mask %s not found\n", opt);
1174 static int set_debug(const char *string)
1176 log_err("fio: debug tracing not included in build\n");
1181 static void fio_options_fill_optstring(void)
1183 char *ostr = cmd_optstr;
1187 while (l_opts[i].name) {
1188 ostr[c++] = l_opts[i].val;
1189 if (l_opts[i].has_arg == required_argument)
1191 else if (l_opts[i].has_arg == optional_argument) {
1200 static int parse_cmd_line(int argc, char *argv[])
1202 struct thread_data *td = NULL;
1203 int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
1204 char *ostr = cmd_optstr;
1206 while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
1209 smalloc_pool_size = atoi(optarg);
1212 def_thread.o.timeout = atoi(optarg);
1221 f_out = fopen(optarg, "w+");
1223 perror("fopen output");
1235 exit(fio_show_option_help(optarg));
1243 log_info("%s\n", fio_version_string);
1246 terse_version = atoi(optarg);
1247 if (terse_version != 2) {
1248 log_err("fio: bad terse version format\n");
1254 if (!strcmp("always", optarg))
1255 eta_print = FIO_ETA_ALWAYS;
1256 else if (!strcmp("never", optarg))
1257 eta_print = FIO_ETA_NEVER;
1260 if (set_debug(optarg))
1266 if (!strcmp(optarg, "global")) {
1267 log_err("fio: can't use global as only "
1273 new_size = (nr_job_sections + 1) * sizeof(char *);
1274 job_sections = realloc(job_sections, new_size);
1275 job_sections[nr_job_sections] = strdup(optarg);
1280 exec_profile = strdup(optarg);
1282 case FIO_GETOPT_JOB: {
1283 const char *opt = l_opts[lidx].name;
1286 if (!strncmp(opt, "name", 4) && td) {
1287 ret = add_job(td, td->o.name ?: "fio", 0);
1293 int is_section = !strncmp(opt, "name", 4);
1296 if (!is_section || !strncmp(val, "global", 6))
1299 if (is_section && skip_this_section(val))
1302 td = get_new_job(global, &def_thread);
1307 ret = fio_cmd_option_parse(td, opt, val);
1314 max_jobs = atoi(optarg);
1315 if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
1316 log_err("fio: invalid max jobs: %d\n", max_jobs);
1323 log_err("fio: can't be both client and server\n");
1331 fio_net_port = atoi(optarg);
1335 log_err("fio: can't be both client and server\n");
1341 client = strdup(optarg);
1353 if (is_client && fio_client_connect(client)) {
1360 return fio_server();
1364 ret = add_job(td, td->o.name ?: "fio", 0);
1367 while (optind < argc) {
1369 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1370 ini_file[ini_idx - 1] = strdup(argv[optind]);
1377 int parse_options(int argc, char *argv[])
1384 fio_options_fill_optstring();
1385 fio_options_dup_and_init(l_opts);
1387 if (setup_thread_area())
1389 if (fill_def_thread())
1392 job_files = parse_cmd_line(argc, argv);
1394 for (i = 0; i < job_files; i++) {
1395 if (fill_def_thread())
1398 if (fio_client_send_ini(ini_file[i]))
1401 if (parse_jobs_ini(ini_file[i], 0, i))
1408 options_mem_free(&def_thread);
1410 if (!thread_number) {
1418 log_err("No jobs(s) defined\n\n");
1423 if (def_thread.o.gtod_offload) {
1425 fio_gtod_offload = 1;
1426 fio_gtod_cpu = def_thread.o.gtod_cpu;
1429 log_info("%s\n", fio_version_string);