Update fio man page
[fio.git] / init.c
CommitLineData
906c8d75 1/*
cb2c86fd 2 * This file contains job initialization and setup functions.
906c8d75 3 */
ebac4655
JA
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <ctype.h>
9#include <string.h>
10#include <errno.h>
11#include <sys/ipc.h>
ebac4655
JA
12#include <sys/types.h>
13#include <sys/stat.h>
14
15#include "fio.h"
a5e0ee11
O
16#ifndef FIO_NO_HAVE_SHM_H
17#include <sys/shm.h>
18#endif
19
cb2c86fd 20#include "parse.h"
2e5cdb11 21#include "smalloc.h"
380065aa 22#include "filehash.h"
4f5af7b2 23#include "verify.h"
79d16311 24#include "profile.h"
50d16976 25#include "server.h"
f2a2ce0e 26#include "idletime.h"
243bfe19 27#include "filelock.h"
ebac4655 28
bf2e821a 29#include "lib/getopt.h"
e25b6d5a 30#include "lib/strcasestr.h"
bf2e821a 31
10aa136b
JA
32#include "crc/test.h"
33
3d43382c 34const char fio_version_string[] = FIO_VERSION;
214e1eca 35
ee738499 36#define FIO_RANDSEED (0xb1899bedUL)
ebac4655 37
214e1eca 38static char **ini_file;
fca70358 39static int max_jobs = FIO_MAX_JOBS;
cca73aa7 40static int dump_cmdline;
25bd16ce 41static long long def_timeout;
111e032d 42static int parse_only;
e1f36503 43
be4ecfdf 44static struct thread_data def_thread;
214e1eca 45struct thread_data *threads = NULL;
10aa136b
JA
46static char **job_sections;
47static int nr_job_sections;
e1f36503 48
214e1eca 49int exitall_on_terminate = 0;
f3afa57e 50int output_format = FIO_OUTPUT_NORMAL;
5be4c944 51int eta_print = FIO_ETA_AUTO;
e382e661 52int eta_new_line = 0;
214e1eca
JA
53FILE *f_out = NULL;
54FILE *f_err = NULL;
07b3232d 55char *exec_profile = NULL;
a9523c6f 56int warnings_fatal = 0;
4d658652 57int terse_version = 3;
50d16976 58int is_backend = 0;
a37f69b7 59int nr_clients = 0;
e46d8091 60int log_syslog = 0;
ee738499 61
214e1eca 62int write_bw_log = 0;
4241ea8f 63int read_only = 0;
06464907 64int status_interval = 0;
214e1eca 65
ca09be4b 66char *trigger_file = NULL;
ca09be4b 67long long trigger_timeout = 0;
b63efd30
JA
68char *trigger_cmd = NULL;
69char *trigger_remote_cmd = NULL;
ca09be4b 70
d264264a
JA
71char *aux_path = NULL;
72
214e1eca 73static int prev_group_jobs;
b4692828 74
ee56ad50 75unsigned long fio_debug = 0;
5e1d306e
JA
76unsigned int fio_debug_jobno = -1;
77unsigned int *fio_debug_jobp = NULL;
ee56ad50 78
4c6107ff 79static char cmd_optstr[256];
085399db 80static int did_arg;
4c6107ff 81
7a4b8240
JA
82#define FIO_CLIENT_FLAG (1 << 16)
83
b4692828
JA
84/*
85 * Command line options. These will contain the above, plus a few
86 * extra that only pertain to fio itself and not jobs.
87 */
5ec10eaa 88static struct option l_opts[FIO_NR_OPTIONS] = {
b4692828 89 {
08d2a19c 90 .name = (char *) "output",
b4692828 91 .has_arg = required_argument,
7a4b8240 92 .val = 'o' | FIO_CLIENT_FLAG,
b4692828
JA
93 },
94 {
08d2a19c 95 .name = (char *) "timeout",
b4692828 96 .has_arg = required_argument,
7a4b8240 97 .val = 't' | FIO_CLIENT_FLAG,
b4692828
JA
98 },
99 {
08d2a19c 100 .name = (char *) "latency-log",
b4692828 101 .has_arg = required_argument,
7a4b8240 102 .val = 'l' | FIO_CLIENT_FLAG,
b4692828
JA
103 },
104 {
08d2a19c 105 .name = (char *) "bandwidth-log",
b4692828 106 .has_arg = required_argument,
7a4b8240 107 .val = 'b' | FIO_CLIENT_FLAG,
b4692828
JA
108 },
109 {
08d2a19c 110 .name = (char *) "minimal",
c4ec0a1d 111 .has_arg = no_argument,
7a4b8240 112 .val = 'm' | FIO_CLIENT_FLAG,
b4692828 113 },
cc372b17 114 {
f3afa57e 115 .name = (char *) "output-format",
cc372b17 116 .has_arg = optional_argument,
f3afa57e 117 .val = 'F' | FIO_CLIENT_FLAG,
cc372b17 118 },
b4692828 119 {
08d2a19c 120 .name = (char *) "version",
b4692828 121 .has_arg = no_argument,
7a4b8240 122 .val = 'v' | FIO_CLIENT_FLAG,
b4692828 123 },
fd28ca49 124 {
08d2a19c 125 .name = (char *) "help",
fd28ca49 126 .has_arg = no_argument,
7a4b8240 127 .val = 'h' | FIO_CLIENT_FLAG,
fd28ca49
JA
128 },
129 {
08d2a19c 130 .name = (char *) "cmdhelp",
320beefe 131 .has_arg = optional_argument,
7a4b8240 132 .val = 'c' | FIO_CLIENT_FLAG,
fd28ca49 133 },
de890a1e 134 {
06464907 135 .name = (char *) "enghelp",
de890a1e 136 .has_arg = optional_argument,
06464907 137 .val = 'i' | FIO_CLIENT_FLAG,
de890a1e 138 },
cca73aa7 139 {
08d2a19c 140 .name = (char *) "showcmd",
cca73aa7 141 .has_arg = no_argument,
7a4b8240 142 .val = 's' | FIO_CLIENT_FLAG,
724e4435
JA
143 },
144 {
08d2a19c 145 .name = (char *) "readonly",
724e4435 146 .has_arg = no_argument,
7a4b8240 147 .val = 'r' | FIO_CLIENT_FLAG,
cca73aa7 148 },
e592a06b 149 {
08d2a19c 150 .name = (char *) "eta",
e592a06b 151 .has_arg = required_argument,
7a4b8240 152 .val = 'e' | FIO_CLIENT_FLAG,
e592a06b 153 },
e382e661
JA
154 {
155 .name = (char *) "eta-newline",
156 .has_arg = required_argument,
157 .val = 'E' | FIO_CLIENT_FLAG,
158 },
ee56ad50 159 {
08d2a19c 160 .name = (char *) "debug",
ee56ad50 161 .has_arg = required_argument,
7a4b8240 162 .val = 'd' | FIO_CLIENT_FLAG,
ee56ad50 163 },
111e032d
JA
164 {
165 .name = (char *) "parse-only",
166 .has_arg = no_argument,
167 .val = 'P' | FIO_CLIENT_FLAG,
168 },
01f06b63 169 {
08d2a19c 170 .name = (char *) "section",
01f06b63 171 .has_arg = required_argument,
7a4b8240 172 .val = 'x' | FIO_CLIENT_FLAG,
01f06b63 173 },
b26317c9
JA
174#ifdef CONFIG_ZLIB
175 {
176 .name = (char *) "inflate-log",
177 .has_arg = required_argument,
178 .val = 'X' | FIO_CLIENT_FLAG,
179 },
180#endif
2b386d25 181 {
08d2a19c 182 .name = (char *) "alloc-size",
2b386d25 183 .has_arg = required_argument,
7a4b8240 184 .val = 'a' | FIO_CLIENT_FLAG,
2b386d25 185 },
9ac8a797 186 {
08d2a19c 187 .name = (char *) "profile",
9ac8a797 188 .has_arg = required_argument,
7a4b8240 189 .val = 'p' | FIO_CLIENT_FLAG,
9ac8a797 190 },
a9523c6f 191 {
08d2a19c 192 .name = (char *) "warnings-fatal",
a9523c6f 193 .has_arg = no_argument,
7a4b8240 194 .val = 'w' | FIO_CLIENT_FLAG,
a9523c6f 195 },
fca70358
JA
196 {
197 .name = (char *) "max-jobs",
198 .has_arg = required_argument,
7a4b8240 199 .val = 'j' | FIO_CLIENT_FLAG,
fca70358 200 },
f57a9c59
JA
201 {
202 .name = (char *) "terse-version",
203 .has_arg = required_argument,
7a4b8240 204 .val = 'V' | FIO_CLIENT_FLAG,
f57a9c59 205 },
50d16976
JA
206 {
207 .name = (char *) "server",
87aa8f19 208 .has_arg = optional_argument,
50d16976
JA
209 .val = 'S',
210 },
e46d8091 211 { .name = (char *) "daemonize",
402668f3 212 .has_arg = required_argument,
e46d8091
JA
213 .val = 'D',
214 },
132159a5
JA
215 {
216 .name = (char *) "client",
217 .has_arg = required_argument,
218 .val = 'C',
219 },
323255cc
JA
220 {
221 .name = (char *) "remote-config",
222 .has_arg = required_argument,
223 .val = 'R',
224 },
7d11f871
JA
225 {
226 .name = (char *) "cpuclock-test",
227 .has_arg = no_argument,
228 .val = 'T',
229 },
fec0f21c
JA
230 {
231 .name = (char *) "crctest",
232 .has_arg = optional_argument,
233 .val = 'G',
234 },
f2a2ce0e
HL
235 {
236 .name = (char *) "idle-prof",
237 .has_arg = required_argument,
238 .val = 'I',
239 },
06464907
JA
240 {
241 .name = (char *) "status-interval",
242 .has_arg = required_argument,
243 .val = 'L',
244 },
ca09be4b 245 {
b63efd30 246 .name = (char *) "trigger-file",
ca09be4b
JA
247 .has_arg = required_argument,
248 .val = 'W',
249 },
250 {
251 .name = (char *) "trigger-timeout",
252 .has_arg = required_argument,
253 .val = 'B',
254 },
b63efd30
JA
255 {
256 .name = (char *) "trigger",
257 .has_arg = required_argument,
258 .val = 'H',
259 },
260 {
261 .name = (char *) "trigger-remote",
262 .has_arg = required_argument,
263 .val = 'J',
264 },
d264264a
JA
265 {
266 .name = (char *) "aux-path",
267 .has_arg = required_argument,
268 .val = 'K',
269 },
b4692828
JA
270 {
271 .name = NULL,
272 },
273};
274
2bb3f0a7 275void free_threads_shm(void)
9d9eb2e7 276{
9d9eb2e7
JA
277 if (threads) {
278 void *tp = threads;
c8931876
JA
279#ifndef CONFIG_NO_SHM
280 struct shmid_ds sbuf;
9d9eb2e7
JA
281
282 threads = NULL;
2bb3f0a7
JA
283 shmdt(tp);
284 shmctl(shm_id, IPC_RMID, &sbuf);
285 shm_id = -1;
c8931876
JA
286#else
287 threads = NULL;
288 free(tp);
289#endif
2bb3f0a7
JA
290 }
291}
292
10aa136b 293static void free_shm(void)
2bb3f0a7
JA
294{
295 if (threads) {
9d9eb2e7 296 file_hash_exit();
9e684a49 297 flow_exit();
9d9eb2e7 298 fio_debug_jobp = NULL;
2bb3f0a7 299 free_threads_shm();
9d9eb2e7
JA
300 }
301
b63efd30
JA
302 free(trigger_file);
303 free(trigger_cmd);
304 free(trigger_remote_cmd);
305 trigger_file = trigger_cmd = trigger_remote_cmd = NULL;
306
eb0c74ae 307 options_free(fio_options, &def_thread);
243bfe19 308 fio_filelock_exit();
9d9eb2e7
JA
309 scleanup();
310}
311
312/*
313 * The thread area is shared between the main process and the job
314 * threads/processes. So setup a shared memory segment that will hold
315 * all the job info. We use the end of the region for keeping track of
316 * open files across jobs, for file sharing.
317 */
318static int setup_thread_area(void)
319{
320 void *hash;
321
322 if (threads)
323 return 0;
324
325 /*
326 * 1024 is too much on some machines, scale max_jobs if
327 * we get a failure that looks like too large a shm segment
328 */
329 do {
330 size_t size = max_jobs * sizeof(struct thread_data);
331
332 size += file_hash_size;
333 size += sizeof(unsigned int);
334
c8931876 335#ifndef CONFIG_NO_SHM
9d9eb2e7
JA
336 shm_id = shmget(0, size, IPC_CREAT | 0600);
337 if (shm_id != -1)
338 break;
f0c77f03 339 if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC) {
9d9eb2e7
JA
340 perror("shmget");
341 break;
342 }
c8931876
JA
343#else
344 threads = malloc(size);
345 if (threads)
346 break;
347#endif
9d9eb2e7
JA
348
349 max_jobs >>= 1;
350 } while (max_jobs);
351
c8931876 352#ifndef CONFIG_NO_SHM
9d9eb2e7
JA
353 if (shm_id == -1)
354 return 1;
355
356 threads = shmat(shm_id, NULL, 0);
357 if (threads == (void *) -1) {
358 perror("shmat");
359 return 1;
360 }
c8931876 361#endif
9d9eb2e7
JA
362
363 memset(threads, 0, max_jobs * sizeof(struct thread_data));
364 hash = (void *) threads + max_jobs * sizeof(struct thread_data);
365 fio_debug_jobp = (void *) hash + file_hash_size;
366 *fio_debug_jobp = -1;
367 file_hash_init(hash);
9e684a49
DE
368
369 flow_init();
370
9d9eb2e7
JA
371 return 0;
372}
373
25bd16ce
JA
374static void set_cmd_options(struct thread_data *td)
375{
376 struct thread_options *o = &td->o;
377
378 if (!o->timeout)
379 o->timeout = def_timeout;
380}
381
906c8d75
JA
382/*
383 * Return a free job structure.
384 */
de890a1e 385static struct thread_data *get_new_job(int global, struct thread_data *parent,
ef3d8e53 386 int preserve_eo, const char *jobname)
ebac4655
JA
387{
388 struct thread_data *td;
389
25bd16ce
JA
390 if (global) {
391 set_cmd_options(&def_thread);
ebac4655 392 return &def_thread;
25bd16ce 393 }
9d9eb2e7
JA
394 if (setup_thread_area()) {
395 log_err("error: failed to setup shm segment\n");
396 return NULL;
397 }
e61f1ec8
BC
398 if (thread_number >= max_jobs) {
399 log_err("error: maximum number of jobs (%d) reached.\n",
400 max_jobs);
ebac4655 401 return NULL;
e61f1ec8 402 }
ebac4655
JA
403
404 td = &threads[thread_number++];
ddaeaa5a 405 *td = *parent;
ebac4655 406
de890a1e
SL
407 td->io_ops = NULL;
408 if (!preserve_eo)
409 td->eo = NULL;
410
e0b0d892
JA
411 td->o.uid = td->o.gid = -1U;
412
cade3ef4 413 dup_files(td, parent);
de890a1e 414 fio_options_mem_dupe(td);
cade3ef4 415
15dc1934
JA
416 profile_add_hooks(td);
417
ebac4655 418 td->thread_number = thread_number;
69bdd6ba 419 td->subjob_number = 0;
108fea77 420
ef3d8e53
JA
421 if (jobname)
422 td->o.name = strdup(jobname);
423
bcdcb5ab 424 if (!parent->o.group_reporting)
108fea77
JA
425 stat_number++;
426
25bd16ce 427 set_cmd_options(td);
ebac4655
JA
428 return td;
429}
430
431static void put_job(struct thread_data *td)
432{
549577a7
JA
433 if (td == &def_thread)
434 return;
84dd1886 435
58c55ba0 436 profile_td_exit(td);
9e684a49 437 flow_exit_job(td);
549577a7 438
16edf25d 439 if (td->error)
6d86144d 440 log_info("fio: %s\n", td->verror);
16edf25d 441
7e356b2d 442 fio_options_free(td);
de890a1e
SL
443 if (td->io_ops)
444 free_ioengine(td);
7e356b2d 445
ef3d8e53
JA
446 if (td->o.name)
447 free(td->o.name);
448
ebac4655
JA
449 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
450 thread_number--;
451}
452
581e7141 453static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
127f6865 454{
581e7141 455 unsigned int bs = td->o.min_bs[ddir];
127f6865 456
ff58fced
JA
457 assert(ddir_rw(ddir));
458
ba3e4e0c 459 if (td->o.rate[ddir])
1b8dbf25 460 td->rate_bps[ddir] = td->o.rate[ddir];
ba3e4e0c 461 else
194fffd0 462 td->rate_bps[ddir] = (uint64_t) td->o.rate_iops[ddir] * bs;
127f6865 463
1b8dbf25 464 if (!td->rate_bps[ddir]) {
127f6865
JA
465 log_err("rate lower than supported\n");
466 return -1;
467 }
468
50a8ce86 469 td->rate_next_io_time[ddir] = 0;
89cdea5e 470 td->rate_io_issue_bytes[ddir] = 0;
127f6865
JA
471 return 0;
472}
473
581e7141
JA
474static int setup_rate(struct thread_data *td)
475{
476 int ret = 0;
477
478 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
479 ret = __setup_rate(td, DDIR_READ);
480 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
481 ret |= __setup_rate(td, DDIR_WRITE);
6eaf09d6
SL
482 if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM])
483 ret |= __setup_rate(td, DDIR_TRIM);
581e7141
JA
484
485 return ret;
486}
487
8347239a
JA
488static int fixed_block_size(struct thread_options *o)
489{
490 return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
491 o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
6eaf09d6
SL
492 o->min_bs[DDIR_TRIM] == o->max_bs[DDIR_TRIM] &&
493 o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE] &&
494 o->min_bs[DDIR_READ] == o->min_bs[DDIR_TRIM];
8347239a
JA
495}
496
23ed19b0
CE
497
498static unsigned long long get_rand_start_delay(struct thread_data *td)
499{
500 unsigned long long delayrange;
c3546b53 501 uint64_t frand_max;
23ed19b0
CE
502 unsigned long r;
503
504 delayrange = td->o.start_delay_high - td->o.start_delay;
505
c3546b53 506 frand_max = rand_max(&td->delay_state);
d6b72507 507 r = __rand(&td->delay_state);
c3546b53 508 delayrange = (unsigned long long) ((double) delayrange * (r / (frand_max + 1.0)));
23ed19b0
CE
509
510 delayrange += td->o.start_delay;
511 return delayrange;
512}
513
dad915e3
JA
514/*
515 * Lazy way of fixing up options that depend on each other. We could also
516 * define option callback handlers, but this is easier.
517 */
4e991c23 518static int fixup_options(struct thread_data *td)
e1f36503 519{
2dc1bbeb 520 struct thread_options *o = &td->o;
eefd98b1 521 int ret = 0;
dad915e3 522
f356d01d 523#ifndef FIO_HAVE_PSHARED_MUTEX
9bbf57cc 524 if (!o->use_thread) {
f356d01d
JA
525 log_info("fio: this platform does not support process shared"
526 " mutexes, forcing use of threads. Use the 'thread'"
527 " option to get rid of this warning.\n");
9bbf57cc 528 o->use_thread = 1;
a9523c6f 529 ret = warnings_fatal;
f356d01d
JA
530 }
531#endif
532
2dc1bbeb 533 if (o->write_iolog_file && o->read_iolog_file) {
076efc7c 534 log_err("fio: read iolog overrides write_iolog\n");
2dc1bbeb
JA
535 free(o->write_iolog_file);
536 o->write_iolog_file = NULL;
a9523c6f 537 ret = warnings_fatal;
076efc7c 538 }
16b462ae 539
16b462ae 540 /*
ed335855 541 * only really works with 1 file
16b462ae 542 */
627aa1a8 543 if (o->zone_size && o->open_files > 1)
2dc1bbeb 544 o->zone_size = 0;
16b462ae 545
ed335855
SN
546 /*
547 * If zone_range isn't specified, backward compatibility dictates it
548 * should be made equal to zone_size.
549 */
550 if (o->zone_size && !o->zone_range)
551 o->zone_range = o->zone_size;
552
16b462ae
JA
553 /*
554 * Reads can do overwrites, we always need to pre-create the file
555 */
556 if (td_read(td) || td_rw(td))
2dc1bbeb 557 o->overwrite = 1;
16b462ae 558
2dc1bbeb 559 if (!o->min_bs[DDIR_READ])
5ec10eaa 560 o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
2dc1bbeb
JA
561 if (!o->max_bs[DDIR_READ])
562 o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
563 if (!o->min_bs[DDIR_WRITE])
5ec10eaa 564 o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
2dc1bbeb
JA
565 if (!o->max_bs[DDIR_WRITE])
566 o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
6eaf09d6
SL
567 if (!o->min_bs[DDIR_TRIM])
568 o->min_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
569 if (!o->max_bs[DDIR_TRIM])
570 o->max_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
571
2dc1bbeb 572 o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
6eaf09d6 573 o->rw_min_bs = min(o->min_bs[DDIR_TRIM], o->rw_min_bs);
a00735e6 574
2b7a01d0
JA
575 /*
576 * For random IO, allow blockalign offset other than min_bs.
577 */
578 if (!o->ba[DDIR_READ] || !td_random(td))
579 o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
580 if (!o->ba[DDIR_WRITE] || !td_random(td))
581 o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
6eaf09d6
SL
582 if (!o->ba[DDIR_TRIM] || !td_random(td))
583 o->ba[DDIR_TRIM] = o->min_bs[DDIR_TRIM];
2b7a01d0
JA
584
585 if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
6eaf09d6
SL
586 o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE] ||
587 o->ba[DDIR_TRIM] != o->min_bs[DDIR_TRIM]) &&
9bbf57cc 588 !o->norandommap) {
2b7a01d0 589 log_err("fio: Any use of blockalign= turns off randommap\n");
9bbf57cc 590 o->norandommap = 1;
a9523c6f 591 ret = warnings_fatal;
2b7a01d0
JA
592 }
593
2dc1bbeb
JA
594 if (!o->file_size_high)
595 o->file_size_high = o->file_size_low;
9c60ce64 596
23ed19b0
CE
597 if (o->start_delay_high)
598 o->start_delay = get_rand_start_delay(td);
599
8347239a
JA
600 if (o->norandommap && o->verify != VERIFY_NONE
601 && !fixed_block_size(o)) {
602 log_err("fio: norandommap given for variable block sizes, "
83da8fbf 603 "verify limited\n");
a9523c6f 604 ret = warnings_fatal;
bb8895e0 605 }
2dc1bbeb 606 if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
690adba3 607 log_err("fio: bs_unaligned may not work with raw io\n");
e0a22335 608
48097d5c
JA
609 /*
610 * thinktime_spin must be less than thinktime
611 */
2dc1bbeb
JA
612 if (o->thinktime_spin > o->thinktime)
613 o->thinktime_spin = o->thinktime;
e916b390
JA
614
615 /*
616 * The low water mark cannot be bigger than the iodepth
617 */
67bf9823
JA
618 if (o->iodepth_low > o->iodepth || !o->iodepth_low)
619 o->iodepth_low = o->iodepth;
cb5ab512
JA
620
621 /*
622 * If batch number isn't set, default to the same as iodepth
623 */
2dc1bbeb
JA
624 if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
625 o->iodepth_batch = o->iodepth;
b5af8293 626
82407585
RP
627 /*
628 * If max batch complete number isn't set or set incorrectly,
629 * default to the same as iodepth_batch_complete_min
630 */
631 if (o->iodepth_batch_complete_min > o->iodepth_batch_complete_max)
632 o->iodepth_batch_complete_max = o->iodepth_batch_complete_min;
633
2dc1bbeb
JA
634 if (o->nr_files > td->files_index)
635 o->nr_files = td->files_index;
9f9214f2 636
2dc1bbeb
JA
637 if (o->open_files > o->nr_files || !o->open_files)
638 o->open_files = o->nr_files;
4e991c23 639
6eaf09d6
SL
640 if (((o->rate[DDIR_READ] + o->rate[DDIR_WRITE] + o->rate[DDIR_TRIM]) &&
641 (o->rate_iops[DDIR_READ] + o->rate_iops[DDIR_WRITE] + o->rate_iops[DDIR_TRIM])) ||
642 ((o->ratemin[DDIR_READ] + o->ratemin[DDIR_WRITE] + o->ratemin[DDIR_TRIM]) &&
643 (o->rate_iops_min[DDIR_READ] + o->rate_iops_min[DDIR_WRITE] + o->rate_iops_min[DDIR_TRIM]))) {
4e991c23 644 log_err("fio: rate and rate_iops are mutually exclusive\n");
a9523c6f 645 ret = 1;
4e991c23 646 }
2af0ad5e
D
647 if ((o->rate[DDIR_READ] && (o->rate[DDIR_READ] < o->ratemin[DDIR_READ])) ||
648 (o->rate[DDIR_WRITE] && (o->rate[DDIR_WRITE] < o->ratemin[DDIR_WRITE])) ||
649 (o->rate[DDIR_TRIM] && (o->rate[DDIR_TRIM] < o->ratemin[DDIR_TRIM])) ||
650 (o->rate_iops[DDIR_READ] && (o->rate_iops[DDIR_READ] < o->rate_iops_min[DDIR_READ])) ||
651 (o->rate_iops[DDIR_WRITE] && (o->rate_iops[DDIR_WRITE] < o->rate_iops_min[DDIR_WRITE])) ||
652 (o->rate_iops[DDIR_TRIM] && (o->rate_iops[DDIR_TRIM] < o->rate_iops_min[DDIR_TRIM]))) {
4e991c23 653 log_err("fio: minimum rate exceeds rate\n");
a9523c6f 654 ret = 1;
4e991c23
JA
655 }
656
cf4464ca
JA
657 if (!o->timeout && o->time_based) {
658 log_err("fio: time_based requires a runtime/timeout setting\n");
659 o->time_based = 0;
a9523c6f 660 ret = warnings_fatal;
cf4464ca
JA
661 }
662
aa31f1f1 663 if (o->fill_device && !o->size)
5921e80c 664 o->size = -1ULL;
5ec10eaa 665
9bbf57cc 666 if (o->verify != VERIFY_NONE) {
996936f9 667 if (td_write(td) && o->do_verify && o->numjobs > 1) {
a9523c6f
JA
668 log_info("Multiple writers may overwrite blocks that "
669 "belong to other jobs. This can cause "
670 "verification failures.\n");
671 ret = warnings_fatal;
672 }
673
7627557b
JA
674 if (!fio_option_is_set(o, refill_buffers))
675 o->refill_buffers = 1;
676
2f1b8e8b
JA
677 if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
678 !o->verify_interval)
679 o->verify_interval = o->min_bs[DDIR_WRITE];
7ffa8930
JA
680
681 /*
682 * Verify interval must be smaller or equal to the
683 * write size.
684 */
685 if (o->verify_interval > o->min_bs[DDIR_WRITE])
686 o->verify_interval = o->min_bs[DDIR_WRITE];
687 else if (td_read(td) && o->verify_interval > o->min_bs[DDIR_READ])
688 o->verify_interval = o->min_bs[DDIR_READ];
d990588e 689 }
41ccd845 690
9bbf57cc
JA
691 if (o->pre_read) {
692 o->invalidate_cache = 0;
a9523c6f 693 if (td->io_ops->flags & FIO_PIPEIO) {
9c0d2241
JA
694 log_info("fio: cannot pre-read files with an IO engine"
695 " that isn't seekable. Pre-read disabled.\n");
a9523c6f
JA
696 ret = warnings_fatal;
697 }
9c0d2241 698 }
34f1c044 699
ad705bcb
SN
700 if (!o->unit_base) {
701 if (td->io_ops->flags & FIO_BIT_BASED)
702 o->unit_base = 1;
703 else
704 o->unit_base = 8;
705 }
706
67bf9823 707#ifndef CONFIG_FDATASYNC
9bbf57cc 708 if (o->fdatasync_blocks) {
e72fa4d4
JA
709 log_info("fio: this platform does not support fdatasync()"
710 " falling back to using fsync(). Use the 'fsync'"
711 " option instead of 'fdatasync' to get rid of"
712 " this warning\n");
9bbf57cc
JA
713 o->fsync_blocks = o->fdatasync_blocks;
714 o->fdatasync_blocks = 0;
a9523c6f 715 ret = warnings_fatal;
e72fa4d4
JA
716 }
717#endif
718
93bcfd20
BC
719#ifdef WIN32
720 /*
721 * Windows doesn't support O_DIRECT or O_SYNC with the _open interface,
722 * so fail if we're passed those flags
723 */
724 if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) {
725 log_err("fio: Windows does not support direct or non-buffered io with"
726 " the synchronous ioengines. Use the 'windowsaio' ioengine"
727 " with 'direct=1' and 'iodepth=1' instead.\n");
728 ret = 1;
729 }
730#endif
731
811ac503
JA
732 /*
733 * For fully compressible data, just zero them at init time.
734 * It's faster than repeatedly filling it.
735 */
736 if (td->o.compress_percentage == 100) {
737 td->o.zero_buffers = 1;
738 td->o.compress_percentage = 0;
739 }
740
5881fda4
JA
741 /*
742 * Using a non-uniform random distribution excludes usage of
743 * a random map
744 */
745 if (td->o.random_distribution != FIO_RAND_DIST_RANDOM)
746 td->o.norandommap = 1;
747
8d916c94
JA
748 /*
749 * If size is set but less than the min block size, complain
750 */
751 if (o->size && o->size < td_min_bs(td)) {
752 log_err("fio: size too small, must be larger than the IO size: %llu\n", (unsigned long long) o->size);
753 ret = 1;
754 }
755
d01612f3
CM
756 /*
757 * O_ATOMIC implies O_DIRECT
758 */
759 if (td->o.oatomic)
760 td->o.odirect = 1;
761
04778baf
JA
762 /*
763 * If randseed is set, that overrides randrepeat
764 */
40fe5e7b 765 if (fio_option_is_set(&td->o, rand_seed))
04778baf
JA
766 td->o.rand_repeatable = 0;
767
b1bebc32
JA
768 if ((td->io_ops->flags & FIO_NOEXTEND) && td->o.file_append) {
769 log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name);
770 ret = 1;
771 }
772
79c896a1
JA
773 if (fio_option_is_set(o, gtod_cpu)) {
774 fio_gtod_init();
775 fio_gtod_set_cpu(o->gtod_cpu);
776 fio_gtod_offload = 1;
777 }
778
cf8a46a7
JA
779 td->loops = o->loops;
780 if (!td->loops)
781 td->loops = 1;
782
66347cfa
DE
783 if (td->o.block_error_hist && td->o.nr_files != 1) {
784 log_err("fio: block error histogram only available with "
785 "with a single file per job, but %d files "
786 "provided\n", td->o.nr_files);
787 ret = 1;
788 }
789
a9523c6f 790 return ret;
e1f36503
JA
791}
792
f8977ee6
JA
793/*
794 * This function leaks the buffer
795 */
99d633af 796char *fio_uint_to_kmg(unsigned int val)
f8977ee6
JA
797{
798 char *buf = malloc(32);
f3502ba2 799 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
f8977ee6
JA
800 char *p = post;
801
245142ff 802 do {
f8977ee6
JA
803 if (val & 1023)
804 break;
805
806 val >>= 10;
807 p++;
245142ff 808 } while (*p);
f8977ee6 809
98ffb8f3 810 snprintf(buf, 32, "%u%c", val, *p);
f8977ee6
JA
811 return buf;
812}
813
09629a90
JA
814/* External engines are specified by "external:name.o") */
815static const char *get_engine_name(const char *str)
816{
817 char *p = strstr(str, ":");
818
819 if (!p)
820 return str;
821
822 p++;
823 strip_blank_front(&p);
824 strip_blank_end(p);
825 return p;
826}
827
e132cbae
JA
828static int exists_and_not_file(const char *filename)
829{
830 struct stat sb;
831
832 if (lstat(filename, &sb) == -1)
833 return 0;
834
ecc314ba
BC
835 /* \\.\ is the device namespace in Windows, where every file
836 * is a device node */
837 if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
e132cbae
JA
838 return 0;
839
840 return 1;
841}
842
c3546b53 843static void td_fill_rand_seeds_internal(struct thread_data *td, int use64)
4c07ad86 844{
c3546b53
JA
845 init_rand_seed(&td->bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF], use64);
846 init_rand_seed(&td->verify_state, td->rand_seeds[FIO_RAND_VER_OFF], use64);
847 init_rand_seed(&td->rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF], use64);
4c07ad86
JA
848
849 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
c3546b53 850 init_rand_seed(&td->next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF], use64);
4c07ad86 851
c3546b53
JA
852 init_rand_seed(&td->file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF], use64);
853 init_rand_seed(&td->trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF], use64);
854 init_rand_seed(&td->delay_state, td->rand_seeds[FIO_RAND_START_DELAY], use64);
4c07ad86
JA
855
856 if (!td_random(td))
857 return;
858
859 if (td->o.rand_repeatable)
d24945f0 860 td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number;
4c07ad86 861
c3546b53
JA
862 init_rand_seed(&td->random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF], use64);
863 init_rand_seed(&td->seq_rand_state[DDIR_READ], td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], use64);
864 init_rand_seed(&td->seq_rand_state[DDIR_WRITE], td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF], use64);
865 init_rand_seed(&td->seq_rand_state[DDIR_TRIM], td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF], use64);
5bfc35d7
JA
866}
867
4c07ad86
JA
868void td_fill_rand_seeds(struct thread_data *td)
869{
c3546b53
JA
870 int use64;
871
56e2a5fc 872 if (td->o.allrand_repeatable) {
5c94b008
JA
873 unsigned int i;
874
875 for (i = 0; i < FIO_RAND_NR_OFFS; i++)
56e2a5fc
CE
876 td->rand_seeds[i] = FIO_RANDSEED * td->thread_number
877 + i;
878 }
879
c3546b53
JA
880 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64)
881 use64 = 1;
882 else
883 use64 = 0;
884
885 td_fill_rand_seeds_internal(td, use64);
3545a109 886
c3546b53 887 init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF], use64);
5c94b008
JA
888 frand_copy(&td->buf_state_prev, &td->buf_state);
889
c3546b53 890 init_rand_seed(&td->dedupe_state, td->rand_seeds[FIO_DEDUPE_OFF], use64);
4c07ad86
JA
891}
892
de890a1e
SL
893/*
894 * Initializes the ioengine configured for a job, if it has not been done so
895 * already.
896 */
897int ioengine_load(struct thread_data *td)
898{
899 const char *engine;
900
901 /*
902 * Engine has already been loaded.
903 */
904 if (td->io_ops)
905 return 0;
6e5c4b8e
JA
906 if (!td->o.ioengine) {
907 log_err("fio: internal fault, no IO engine specified\n");
908 return 1;
909 }
de890a1e
SL
910
911 engine = get_engine_name(td->o.ioengine);
912 td->io_ops = load_ioengine(td, engine);
913 if (!td->io_ops) {
914 log_err("fio: failed to load engine %s\n", engine);
915 return 1;
916 }
917
918 if (td->io_ops->option_struct_size && td->io_ops->options) {
919 /*
920 * In cases where td->eo is set, clone it for a child thread.
921 * This requires that the parent thread has the same ioengine,
922 * but that requirement must be enforced by the code which
923 * cloned the thread.
924 */
925 void *origeo = td->eo;
926 /*
927 * Otherwise use the default thread options.
928 */
929 if (!origeo && td != &def_thread && def_thread.eo &&
930 def_thread.io_ops->options == td->io_ops->options)
931 origeo = def_thread.eo;
932
933 options_init(td->io_ops->options);
934 td->eo = malloc(td->io_ops->option_struct_size);
935 /*
936 * Use the default thread as an option template if this uses the
937 * same options structure and there are non-default options
938 * used.
939 */
940 if (origeo) {
941 memcpy(td->eo, origeo, td->io_ops->option_struct_size);
942 options_mem_dupe(td->eo, td->io_ops->options);
943 } else {
944 memset(td->eo, 0, td->io_ops->option_struct_size);
945 fill_default_options(td->eo, td->io_ops->options);
946 }
947 *(struct thread_data **)td->eo = td;
948 }
949
950 return 0;
951}
952
d72be545
JA
953static void init_flags(struct thread_data *td)
954{
955 struct thread_options *o = &td->o;
956
957 if (o->verify_backlog)
958 td->flags |= TD_F_VER_BACKLOG;
959 if (o->trim_backlog)
960 td->flags |= TD_F_TRIM_BACKLOG;
961 if (o->read_iolog_file)
962 td->flags |= TD_F_READ_IOLOG;
963 if (o->refill_buffers)
964 td->flags |= TD_F_REFILL_BUFFERS;
1bf2498d 965 /*
b04f5905 966 * Always scramble buffers if asked to
1bf2498d 967 */
b04f5905
JA
968 if (o->scramble_buffers && fio_option_is_set(o, scramble_buffers))
969 td->flags |= TD_F_SCRAMBLE_BUFFERS;
970 /*
971 * But also scramble buffers, unless we were explicitly asked
972 * to zero them.
973 */
974 if (o->scramble_buffers && !(o->zero_buffers &&
975 fio_option_is_set(o, zero_buffers)))
d72be545
JA
976 td->flags |= TD_F_SCRAMBLE_BUFFERS;
977 if (o->verify != VERIFY_NONE)
978 td->flags |= TD_F_VER_NONE;
a9da8ab2
JA
979
980 if (o->verify_async || o->io_submit_mode == IO_MODE_OFFLOAD)
981 td->flags |= TD_F_NEED_LOCK;
d72be545
JA
982}
983
9dbc7bfe
JA
984static int setup_random_seeds(struct thread_data *td)
985{
986 unsigned long seed;
987 unsigned int i;
988
40fe5e7b 989 if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed))
9dbc7bfe
JA
990 return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds));
991
40fe5e7b 992 seed = td->o.rand_seed;
04778baf 993 for (i = 0; i < 4; i++)
9dbc7bfe
JA
994 seed *= 0x9e370001UL;
995
996 for (i = 0; i < FIO_RAND_NR_OFFS; i++) {
997 td->rand_seeds[i] = seed;
998 seed *= 0x9e370001UL;
999 }
1000
1001 td_fill_rand_seeds(td);
1002 return 0;
1003}
1004
de98bd30
JA
1005enum {
1006 FPRE_NONE = 0,
1007 FPRE_JOBNAME,
1008 FPRE_JOBNUM,
1009 FPRE_FILENUM
1010};
1011
1012static struct fpre_keyword {
1013 const char *keyword;
1014 size_t strlen;
1015 int key;
1016} fpre_keywords[] = {
1017 { .keyword = "$jobname", .key = FPRE_JOBNAME, },
1018 { .keyword = "$jobnum", .key = FPRE_JOBNUM, },
1019 { .keyword = "$filenum", .key = FPRE_FILENUM, },
1020 { .keyword = NULL, },
1021 };
1022
3660ceae 1023static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
de98bd30
JA
1024 const char *jobname, int jobnum, int filenum)
1025{
1026 struct fpre_keyword *f;
1027 char copy[PATH_MAX];
b400a20e 1028 size_t dst_left = PATH_MAX - 1;
de98bd30
JA
1029
1030 if (!o->filename_format || !strlen(o->filename_format)) {
1031 sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum);
1032 return NULL;
1033 }
1034
1035 for (f = &fpre_keywords[0]; f->keyword; f++)
1036 f->strlen = strlen(f->keyword);
1037
3660ceae
JA
1038 buf[buf_size - 1] = '\0';
1039 strncpy(buf, o->filename_format, buf_size - 1);
1040
de98bd30
JA
1041 memset(copy, 0, sizeof(copy));
1042 for (f = &fpre_keywords[0]; f->keyword; f++) {
1043 do {
1044 size_t pre_len, post_start = 0;
1045 char *str, *dst = copy;
1046
e25b6d5a 1047 str = strcasestr(buf, f->keyword);
de98bd30
JA
1048 if (!str)
1049 break;
1050
1051 pre_len = str - buf;
1052 if (strlen(str) != f->strlen)
1053 post_start = pre_len + f->strlen;
1054
1055 if (pre_len) {
1056 strncpy(dst, buf, pre_len);
1057 dst += pre_len;
73a467e6 1058 dst_left -= pre_len;
de98bd30
JA
1059 }
1060
1061 switch (f->key) {
73a467e6
JA
1062 case FPRE_JOBNAME: {
1063 int ret;
1064
1065 ret = snprintf(dst, dst_left, "%s", jobname);
1066 if (ret < 0)
1067 break;
17a2be59
JA
1068 else if (ret > dst_left) {
1069 log_err("fio: truncated filename\n");
1070 dst += dst_left;
1071 dst_left = 0;
1072 } else {
1073 dst += ret;
1074 dst_left -= ret;
1075 }
de98bd30 1076 break;
73a467e6
JA
1077 }
1078 case FPRE_JOBNUM: {
1079 int ret;
1080
1081 ret = snprintf(dst, dst_left, "%d", jobnum);
1082 if (ret < 0)
1083 break;
17a2be59
JA
1084 else if (ret > dst_left) {
1085 log_err("fio: truncated filename\n");
1086 dst += dst_left;
1087 dst_left = 0;
1088 } else {
1089 dst += ret;
1090 dst_left -= ret;
1091 }
de98bd30 1092 break;
73a467e6
JA
1093 }
1094 case FPRE_FILENUM: {
1095 int ret;
1096
1097 ret = snprintf(dst, dst_left, "%d", filenum);
1098 if (ret < 0)
1099 break;
17a2be59
JA
1100 else if (ret > dst_left) {
1101 log_err("fio: truncated filename\n");
1102 dst += dst_left;
1103 dst_left = 0;
1104 } else {
1105 dst += ret;
1106 dst_left -= ret;
1107 }
de98bd30 1108 break;
73a467e6 1109 }
de98bd30
JA
1110 default:
1111 assert(0);
1112 break;
1113 }
1114
1115 if (post_start)
73a467e6 1116 strncpy(dst, buf + post_start, dst_left);
de98bd30 1117
3660ceae 1118 strncpy(buf, copy, buf_size - 1);
de98bd30
JA
1119 } while (1);
1120 }
1121
1122 return buf;
1123}
f9633d72
JA
1124
1125int parse_dryrun(void)
1126{
1127 return dump_cmdline || parse_only;
1128}
1129
3a5db920
JA
1130static void gen_log_name(char *name, size_t size, const char *logtype,
1131 const char *logname, unsigned int num,
1132 const char *suf, int per_job)
1133{
1134 if (per_job)
1135 snprintf(name, size, "%s_%s.%d.%s", logname, logtype, num, suf);
1136 else
1137 snprintf(name, size, "%s_%s.%s", logname, logtype, suf);
1138}
1139
906c8d75
JA
1140/*
1141 * Adds a job to the list of things todo. Sanitizes the various options
1142 * to make sure we don't have conflicts, and initializes various
1143 * members of td.
1144 */
b7cfb2e1 1145static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
46bcd498 1146 int recursed, int client_type)
ebac4655 1147{
af52b345 1148 unsigned int i;
af52b345 1149 char fname[PATH_MAX];
e132cbae 1150 int numjobs, file_alloced;
de98bd30 1151 struct thread_options *o = &td->o;
cb7e0ace 1152 char logname[PATH_MAX + 32];
ebac4655 1153
ebac4655
JA
1154 /*
1155 * the def_thread is just for options, it's not a real job
1156 */
1157 if (td == &def_thread)
1158 return 0;
1159
d72be545
JA
1160 init_flags(td);
1161
cca73aa7
JA
1162 /*
1163 * if we are just dumping the output command line, don't add the job
1164 */
f9633d72 1165 if (parse_dryrun()) {
cca73aa7
JA
1166 put_job(td);
1167 return 0;
1168 }
1169
46bcd498
JA
1170 td->client_type = client_type;
1171
58c55ba0 1172 if (profile_td_init(td))
66251554 1173 goto err;
58c55ba0 1174
de890a1e 1175 if (ioengine_load(td))
205927a3 1176 goto err;
df64119d 1177
de98bd30 1178 if (o->odirect)
690adba3
JA
1179 td->io_ops->flags |= FIO_RAWIO;
1180
e132cbae 1181 file_alloced = 0;
de98bd30 1182 if (!o->filename && !td->files_index && !o->read_iolog_file) {
e132cbae 1183 file_alloced = 1;
80be24f4 1184
de98bd30 1185 if (o->nr_files == 1 && exists_and_not_file(jobname))
5903e7b7 1186 add_file(td, jobname, job_add_num, 0);
7b05a215 1187 else {
de98bd30 1188 for (i = 0; i < o->nr_files; i++)
3660ceae 1189 add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0);
af52b345 1190 }
0af7b542 1191 }
ebac4655 1192
4e991c23
JA
1193 if (fixup_options(td))
1194 goto err;
e0a22335 1195
9e684a49
DE
1196 flow_init_job(td);
1197
de890a1e
SL
1198 /*
1199 * IO engines only need this for option callbacks, and the address may
1200 * change in subprocesses.
1201 */
1202 if (td->eo)
1203 *(struct thread_data **)td->eo = NULL;
1204
07eb79df
JA
1205 if (td->io_ops->flags & FIO_DISKLESSIO) {
1206 struct fio_file *f;
1207
1208 for_each_file(td, f, i)
1209 f->real_file_size = -1ULL;
1210 }
1211
521da527 1212 td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
ebac4655 1213
de98bd30
JA
1214 td->ts.clat_percentiles = o->clat_percentiles;
1215 td->ts.percentile_precision = o->percentile_precision;
1216 memcpy(td->ts.percentile_list, o->percentile_list, sizeof(o->percentile_list));
83349190 1217
6eaf09d6
SL
1218 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1219 td->ts.clat_stat[i].min_val = ULONG_MAX;
1220 td->ts.slat_stat[i].min_val = ULONG_MAX;
1221 td->ts.lat_stat[i].min_val = ULONG_MAX;
1222 td->ts.bw_stat[i].min_val = ULONG_MAX;
1223 }
de98bd30 1224 td->ddir_seq_nr = o->ddir_seq_nr;
ebac4655 1225
de98bd30 1226 if ((o->stonewall || o->new_group) && prev_group_jobs) {
3c5df6fa 1227 prev_group_jobs = 0;
ebac4655 1228 groupid++;
3c5df6fa 1229 }
ebac4655
JA
1230
1231 td->groupid = groupid;
3c5df6fa 1232 prev_group_jobs++;
ebac4655 1233
9dbc7bfe 1234 if (setup_random_seeds(td)) {
93bcfd20 1235 td_verror(td, errno, "init_random_state");
9c60ce64 1236 goto err;
93bcfd20 1237 }
9c60ce64 1238
ebac4655
JA
1239 if (setup_rate(td))
1240 goto err;
1241
cb7e0ace 1242 if (o->lat_log_file) {
aee2ab67
JA
1243 struct log_params p = {
1244 .td = td,
1245 .avg_msec = o->log_avg_msec,
1246 .log_type = IO_LOG_TYPE_LAT,
1247 .log_offset = o->log_offset,
1248 .log_gz = o->log_gz,
b26317c9 1249 .log_gz_store = o->log_gz_store,
aee2ab67 1250 };
b26317c9 1251 const char *suf;
aee2ab67 1252
b26317c9
JA
1253 if (p.log_gz_store)
1254 suf = "log.fz";
1255 else
1256 suf = "log";
1257
3a5db920
JA
1258 gen_log_name(logname, sizeof(logname), "lat", o->lat_log_file,
1259 td->thread_number, suf, o->per_job_logs);
aee2ab67 1260 setup_log(&td->lat_log, &p, logname);
3a5db920
JA
1261
1262 gen_log_name(logname, sizeof(logname), "slat", o->lat_log_file,
1263 td->thread_number, suf, o->per_job_logs);
aee2ab67 1264 setup_log(&td->slat_log, &p, logname);
3a5db920
JA
1265
1266 gen_log_name(logname, sizeof(logname), "clat", o->lat_log_file,
1267 td->thread_number, suf, o->per_job_logs);
aee2ab67 1268 setup_log(&td->clat_log, &p, logname);
ebac4655 1269 }
cb7e0ace 1270 if (o->bw_log_file) {
aee2ab67
JA
1271 struct log_params p = {
1272 .td = td,
1273 .avg_msec = o->log_avg_msec,
1274 .log_type = IO_LOG_TYPE_BW,
1275 .log_offset = o->log_offset,
1276 .log_gz = o->log_gz,
b26317c9 1277 .log_gz_store = o->log_gz_store,
aee2ab67 1278 };
b26317c9
JA
1279 const char *suf;
1280
1281 if (p.log_gz_store)
1282 suf = "log.fz";
1283 else
1284 suf = "log";
aee2ab67 1285
3a5db920
JA
1286 gen_log_name(logname, sizeof(logname), "bw", o->bw_log_file,
1287 td->thread_number, suf, o->per_job_logs);
aee2ab67 1288 setup_log(&td->bw_log, &p, logname);
cb7e0ace
JA
1289 }
1290 if (o->iops_log_file) {
aee2ab67
JA
1291 struct log_params p = {
1292 .td = td,
1293 .avg_msec = o->log_avg_msec,
1294 .log_type = IO_LOG_TYPE_IOPS,
1295 .log_offset = o->log_offset,
1296 .log_gz = o->log_gz,
b26317c9 1297 .log_gz_store = o->log_gz_store,
aee2ab67 1298 };
b26317c9
JA
1299 const char *suf;
1300
1301 if (p.log_gz_store)
1302 suf = "log.fz";
1303 else
1304 suf = "log";
aee2ab67 1305
3a5db920
JA
1306 gen_log_name(logname, sizeof(logname), "iops", o->iops_log_file,
1307 td->thread_number, suf, o->per_job_logs);
aee2ab67 1308 setup_log(&td->iops_log, &p, logname);
cb7e0ace 1309 }
ebac4655 1310
de98bd30
JA
1311 if (!o->name)
1312 o->name = strdup(jobname);
01452055 1313
129fb2d4 1314 if (output_format & FIO_OUTPUT_NORMAL) {
b990b5c0 1315 if (!job_add_num) {
b7cfb2e1 1316 if (is_backend && !recursed)
2f122b13 1317 fio_server_send_add_job(td);
807f9971 1318
0353050f 1319 if (!(td->io_ops->flags & FIO_NOIO)) {
d21e2535
JA
1320 char *c1, *c2, *c3, *c4;
1321 char *c5 = NULL, *c6 = NULL;
f8977ee6 1322
22f80458
JA
1323 c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
1324 c2 = fio_uint_to_kmg(o->max_bs[DDIR_READ]);
1325 c3 = fio_uint_to_kmg(o->min_bs[DDIR_WRITE]);
1326 c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
d21e2535
JA
1327
1328 if (!o->bs_is_seq_rand) {
1329 c5 = fio_uint_to_kmg(o->min_bs[DDIR_TRIM]);
1330 c6 = fio_uint_to_kmg(o->max_bs[DDIR_TRIM]);
1331 }
1332
1333 log_info("%s: (g=%d): rw=%s, ", td->o.name,
1334 td->groupid,
1335 ddir_str(o->td_ddir));
1336
1337 if (o->bs_is_seq_rand)
1338 log_info("bs(seq/rand)=%s-%s/%s-%s, ",
1339 c1, c2, c3, c4);
1340 else
1341 log_info("bs=%s-%s/%s-%s/%s-%s, ",
1342 c1, c2, c3, c4, c5, c6);
1343
1344 log_info("ioengine=%s, iodepth=%u\n",
de98bd30 1345 td->io_ops->name, o->iodepth);
f8977ee6
JA
1346
1347 free(c1);
1348 free(c2);
1349 free(c3);
1350 free(c4);
6eaf09d6
SL
1351 free(c5);
1352 free(c6);
f8977ee6 1353 }
b990b5c0 1354 } else if (job_add_num == 1)
6d86144d 1355 log_info("...\n");
c6ae0a5b 1356 }
ebac4655
JA
1357
1358 /*
1359 * recurse add identical jobs, clear numjobs and stonewall options
1360 * as they don't apply to sub-jobs
1361 */
de98bd30 1362 numjobs = o->numjobs;
ebac4655 1363 while (--numjobs) {
ef3d8e53 1364 struct thread_data *td_new = get_new_job(0, td, 1, jobname);
ebac4655
JA
1365
1366 if (!td_new)
1367 goto err;
1368
2dc1bbeb
JA
1369 td_new->o.numjobs = 1;
1370 td_new->o.stonewall = 0;
92c1d41f 1371 td_new->o.new_group = 0;
69bdd6ba 1372 td_new->subjob_number = numjobs;
e132cbae
JA
1373
1374 if (file_alloced) {
455a50fa
CE
1375 if (td_new->files) {
1376 struct fio_file *f;
1377 for_each_file(td_new, f, i) {
1378 if (f->file_name)
ece6d647
AK
1379 sfree(f->file_name);
1380 sfree(f);
455a50fa 1381 }
ece6d647 1382 free(td_new->files);
455a50fa
CE
1383 td_new->files = NULL;
1384 }
ece6d647
AK
1385 td_new->files_index = 0;
1386 td_new->files_size = 0;
455a50fa
CE
1387 if (td_new->o.filename) {
1388 free(td_new->o.filename);
1389 td_new->o.filename = NULL;
1390 }
e132cbae
JA
1391 }
1392
bcbfeefa 1393 if (add_job(td_new, jobname, numjobs, 1, client_type))
ebac4655
JA
1394 goto err;
1395 }
3c5df6fa 1396
ebac4655
JA
1397 return 0;
1398err:
1399 put_job(td);
1400 return -1;
1401}
1402
79d16311
JA
1403/*
1404 * Parse as if 'o' was a command line
1405 */
46bcd498 1406void add_job_opts(const char **o, int client_type)
79d16311
JA
1407{
1408 struct thread_data *td, *td_parent;
1409 int i, in_global = 1;
1410 char jobname[32];
1411
1412 i = 0;
1413 td_parent = td = NULL;
1414 while (o[i]) {
1415 if (!strncmp(o[i], "name", 4)) {
1416 in_global = 0;
1417 if (td)
46bcd498 1418 add_job(td, jobname, 0, 0, client_type);
79d16311
JA
1419 td = NULL;
1420 sprintf(jobname, "%s", o[i] + 5);
1421 }
1422 if (in_global && !td_parent)
ef3d8e53 1423 td_parent = get_new_job(1, &def_thread, 0, jobname);
79d16311
JA
1424 else if (!in_global && !td) {
1425 if (!td_parent)
1426 td_parent = &def_thread;
ef3d8e53 1427 td = get_new_job(0, td_parent, 0, jobname);
79d16311
JA
1428 }
1429 if (in_global)
292cc475 1430 fio_options_parse(td_parent, (char **) &o[i], 1, 0);
79d16311 1431 else
292cc475 1432 fio_options_parse(td, (char **) &o[i], 1, 0);
79d16311
JA
1433 i++;
1434 }
1435
1436 if (td)
46bcd498 1437 add_job(td, jobname, 0, 0, client_type);
79d16311
JA
1438}
1439
01f06b63
JA
1440static int skip_this_section(const char *name)
1441{
ad0a2735
JA
1442 int i;
1443
1444 if (!nr_job_sections)
01f06b63
JA
1445 return 0;
1446 if (!strncmp(name, "global", 6))
1447 return 0;
1448
ad0a2735
JA
1449 for (i = 0; i < nr_job_sections; i++)
1450 if (!strcmp(job_sections[i], name))
1451 return 0;
1452
1453 return 1;
01f06b63
JA
1454}
1455
ebac4655
JA
1456static int is_empty_or_comment(char *line)
1457{
1458 unsigned int i;
1459
1460 for (i = 0; i < strlen(line); i++) {
1461 if (line[i] == ';')
1462 return 1;
5cc2da30
IM
1463 if (line[i] == '#')
1464 return 1;
76cd9378 1465 if (!isspace((int) line[i]) && !iscntrl((int) line[i]))
ebac4655
JA
1466 return 0;
1467 }
1468
1469 return 1;
1470}
1471
07261983
JA
1472/*
1473 * This is our [ini] type file parser.
1474 */
b3270921
AK
1475int __parse_jobs_ini(struct thread_data *td,
1476 char *file, int is_buf, int stonewall_flag, int type,
1477 int nested, char *name, char ***popts, int *aopts, int *nopts)
ebac4655 1478{
b3270921
AK
1479 unsigned int global = 0;
1480 char *string;
ebac4655
JA
1481 FILE *f;
1482 char *p;
0c7e37a0 1483 int ret = 0, stonewall;
097b2991 1484 int first_sect = 1;
ccf8f127 1485 int skip_fgets = 0;
01f06b63 1486 int inside_skip = 0;
3b8b7135
JA
1487 char **opts;
1488 int i, alloc_opts, num_opts;
ebac4655 1489
b3270921
AK
1490 dprint(FD_PARSE, "Parsing ini file %s\n", file);
1491 assert(td || !nested);
1492
50d16976
JA
1493 if (is_buf)
1494 f = NULL;
1495 else {
1496 if (!strcmp(file, "-"))
1497 f = stdin;
1498 else
1499 f = fopen(file, "r");
5a729cbe 1500
50d16976 1501 if (!f) {
323255cc
JA
1502 int __err = errno;
1503
1504 log_err("fio: unable to open '%s' job file\n", file);
02957cd4
JA
1505 if (td)
1506 td_verror(td, __err, "job file open");
50d16976
JA
1507 return 1;
1508 }
ebac4655
JA
1509 }
1510
1511 string = malloc(4096);
7f7e6e59
JA
1512
1513 /*
1514 * it's really 256 + small bit, 280 should suffice
1515 */
b3270921
AK
1516 if (!nested) {
1517 name = malloc(280);
1518 memset(name, 0, 280);
1519 }
ebac4655 1520
b3270921
AK
1521 opts = NULL;
1522 if (nested && popts) {
1523 opts = *popts;
1524 alloc_opts = *aopts;
1525 num_opts = *nopts;
1526 }
1527
1528 if (!opts) {
1529 alloc_opts = 8;
1530 opts = malloc(sizeof(char *) * alloc_opts);
1531 num_opts = 0;
1532 }
3b8b7135 1533
0c7e37a0 1534 stonewall = stonewall_flag;
7c124ac1 1535 do {
ccf8f127
JA
1536 /*
1537 * if skip_fgets is set, we already have loaded a line we
1538 * haven't handled.
1539 */
1540 if (!skip_fgets) {
50d16976
JA
1541 if (is_buf)
1542 p = strsep(&file, "\n");
1543 else
43f74792 1544 p = fgets(string, 4096, f);
ccf8f127
JA
1545 if (!p)
1546 break;
1547 }
cdc7f193 1548
ccf8f127 1549 skip_fgets = 0;
cdc7f193 1550 strip_blank_front(&p);
6c7c7da1 1551 strip_blank_end(p);
cdc7f193 1552
b3270921 1553 dprint(FD_PARSE, "%s\n", p);
ebac4655
JA
1554 if (is_empty_or_comment(p))
1555 continue;
b3270921
AK
1556
1557 if (!nested) {
1558 if (sscanf(p, "[%255[^\n]]", name) != 1) {
1559 if (inside_skip)
1560 continue;
1561
1562 log_err("fio: option <%s> outside of "
1563 "[] job section\n", p);
0e9c21a2 1564 ret = 1;
b3270921
AK
1565 break;
1566 }
1567
1568 name[strlen(name) - 1] = '\0';
1569
1570 if (skip_this_section(name)) {
1571 inside_skip = 1;
01f06b63 1572 continue;
b3270921
AK
1573 } else
1574 inside_skip = 0;
ebac4655 1575
b3270921 1576 dprint(FD_PARSE, "Parsing section [%s]\n", name);
7a4b80a1 1577
b3270921 1578 global = !strncmp(name, "global", 6);
01f06b63 1579
b3270921
AK
1580 if (dump_cmdline) {
1581 if (first_sect)
1582 log_info("fio ");
1583 if (!global)
1584 log_info("--name=%s ", name);
1585 first_sect = 0;
1586 }
ebac4655 1587
b3270921
AK
1588 td = get_new_job(global, &def_thread, 0, name);
1589 if (!td) {
1590 ret = 1;
1591 break;
1592 }
cca73aa7 1593
b3270921
AK
1594 /*
1595 * Separate multiple job files by a stonewall
1596 */
1597 if (!global && stonewall) {
1598 td->o.stonewall = stonewall;
1599 stonewall = 0;
1600 }
ebac4655 1601
b3270921
AK
1602 num_opts = 0;
1603 memset(opts, 0, alloc_opts * sizeof(char *));
972cfd25 1604 }
b3270921
AK
1605 else
1606 skip_fgets = 1;
3b8b7135 1607
50d16976 1608 while (1) {
b3270921
AK
1609 if (!skip_fgets) {
1610 if (is_buf)
1611 p = strsep(&file, "\n");
1612 else
1613 p = fgets(string, 4096, f);
1614 if (!p)
1615 break;
1616 dprint(FD_PARSE, "%s", p);
1617 }
50d16976 1618 else
b3270921 1619 skip_fgets = 0;
50d16976 1620
ebac4655
JA
1621 if (is_empty_or_comment(p))
1622 continue;
e1f36503 1623
b6754f9d 1624 strip_blank_front(&p);
7c124ac1 1625
ccf8f127
JA
1626 /*
1627 * new section, break out and make sure we don't
1628 * fgets() a new line at the top.
1629 */
1630 if (p[0] == '[') {
b3270921
AK
1631 if (nested) {
1632 log_err("No new sections in included files\n");
1633 return 1;
1634 }
1635
ccf8f127 1636 skip_fgets = 1;
7c124ac1 1637 break;
ccf8f127 1638 }
7c124ac1 1639
4ae3f763 1640 strip_blank_end(p);
aea47d44 1641
b3270921
AK
1642 if (!strncmp(p, "include", strlen("include"))) {
1643 char *filename = p + strlen("include") + 1;
1644
1645 if ((ret = __parse_jobs_ini(td, filename,
1646 is_buf, stonewall_flag, type, 1,
1647 name, &opts, &alloc_opts, &num_opts))) {
1648 log_err("Error %d while parsing include file %s\n",
1649 ret, filename);
1650 break;
1651 }
1652 continue;
1653 }
1654
3b8b7135
JA
1655 if (num_opts == alloc_opts) {
1656 alloc_opts <<= 1;
1657 opts = realloc(opts,
1658 alloc_opts * sizeof(char *));
1659 }
1660
1661 opts[num_opts] = strdup(p);
1662 num_opts++;
ebac4655 1663 }
ebac4655 1664
b3270921
AK
1665 if (nested) {
1666 *popts = opts;
1667 *aopts = alloc_opts;
1668 *nopts = num_opts;
1669 goto out;
1670 }
1671
292cc475
JA
1672 ret = fio_options_parse(td, opts, num_opts, dump_cmdline);
1673 if (!ret)
46bcd498 1674 ret = add_job(td, name, 0, 0, type);
292cc475 1675 else {
b1508cf9
JA
1676 log_err("fio: job %s dropped\n", name);
1677 put_job(td);
45410acb 1678 }
3b8b7135
JA
1679
1680 for (i = 0; i < num_opts; i++)
1681 free(opts[i]);
1682 num_opts = 0;
7c124ac1 1683 } while (!ret);
ebac4655 1684
cca73aa7
JA
1685 if (dump_cmdline)
1686 log_info("\n");
1687
7e356b2d
JA
1688 i = 0;
1689 while (i < nr_job_sections) {
1690 free(job_sections[i]);
1691 i++;
1692 }
1693
2577594d 1694 free(opts);
b3270921
AK
1695out:
1696 free(string);
1697 if (!nested)
1698 free(name);
50d16976 1699 if (!is_buf && f != stdin)
5a729cbe 1700 fclose(f);
45410acb 1701 return ret;
ebac4655
JA
1702}
1703
b3270921
AK
1704int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
1705{
1706 return __parse_jobs_ini(NULL, file, is_buf, stonewall_flag, type,
1707 0, NULL, NULL, NULL, NULL);
1708}
1709
ebac4655
JA
1710static int fill_def_thread(void)
1711{
1712 memset(&def_thread, 0, sizeof(def_thread));
1713
375b2695 1714 fio_getaffinity(getpid(), &def_thread.o.cpumask);
8b28bd41 1715 def_thread.o.error_dump = 1;
25bd16ce 1716
ebac4655 1717 /*
ee738499 1718 * fill default options
ebac4655 1719 */
214e1eca 1720 fio_fill_default_options(&def_thread);
ebac4655
JA
1721 return 0;
1722}
1723
2236df3d
JA
1724static void show_debug_categories(void)
1725{
1726 struct debug_level *dl = &debug_levels[0];
1727 int curlen, first = 1;
1728
1729 curlen = 0;
1730 while (dl->name) {
1731 int has_next = (dl + 1)->name != NULL;
1732
1733 if (first || curlen + strlen(dl->name) >= 80) {
1734 if (!first) {
1735 printf("\n");
1736 curlen = 0;
1737 }
1738 curlen += printf("\t\t\t%s", dl->name);
1739 curlen += 3 * (8 - 1);
1740 if (has_next)
1741 curlen += printf(",");
1742 } else {
1743 curlen += printf("%s", dl->name);
1744 if (has_next)
1745 curlen += printf(",");
1746 }
1747 dl++;
1748 first = 0;
1749 }
1750 printf("\n");
1751}
1752
45378b35 1753static void usage(const char *name)
4785f995 1754{
3d43382c 1755 printf("%s\n", fio_version_string);
45378b35 1756 printf("%s [options] [job options] <job file(s)>\n", name);
2236df3d
JA
1757 printf(" --debug=options\tEnable debug logging. May be one/more of:\n");
1758 show_debug_categories();
111e032d 1759 printf(" --parse-only\t\tParse options only, don't start any IO\n");
83881283 1760 printf(" --output\t\tWrite output to file\n");
b2cecdc2 1761 printf(" --runtime\t\tRuntime in seconds\n");
83881283
JA
1762 printf(" --bandwidth-log\tGenerate per-job bandwidth logs\n");
1763 printf(" --minimal\t\tMinimal (terse) output\n");
f3afa57e 1764 printf(" --output-format=x\tOutput format (terse,json,normal)\n");
75db6e2c 1765 printf(" --terse-version=x\tSet terse version output format to 'x'\n");
f3afa57e 1766 printf(" --version\t\tPrint version info and exit\n");
83881283 1767 printf(" --help\t\tPrint this page\n");
23893646 1768 printf(" --cpuclock-test\tPerform test/validation of CPU clock\n");
fec0f21c 1769 printf(" --crctest\t\tTest speed of checksum functions\n");
83881283 1770 printf(" --cmdhelp=cmd\t\tPrint command help, \"all\" for all of"
5ec10eaa 1771 " them\n");
de890a1e
SL
1772 printf(" --enghelp=engine\tPrint ioengine help, or list"
1773 " available ioengines\n");
1774 printf(" --enghelp=engine,cmd\tPrint help for an ioengine"
1775 " cmd\n");
83881283
JA
1776 printf(" --showcmd\t\tTurn a job file into command line options\n");
1777 printf(" --eta=when\t\tWhen ETA estimate should be printed\n");
1778 printf(" \t\tMay be \"always\", \"never\" or \"auto\"\n");
e382e661
JA
1779 printf(" --eta-newline=time\tForce a new line for every 'time'");
1780 printf(" period passed\n");
06464907
JA
1781 printf(" --status-interval=t\tForce full status dump every");
1782 printf(" 't' period passed\n");
83881283 1783 printf(" --readonly\t\tTurn on safety read-only checks, preventing"
5ec10eaa 1784 " writes\n");
83881283
JA
1785 printf(" --section=name\tOnly run specified section in job file\n");
1786 printf(" --alloc-size=kb\tSet smalloc pool to this size in kb"
2b386d25 1787 " (def 1024)\n");
83881283
JA
1788 printf(" --warnings-fatal\tFio parser warnings are fatal\n");
1789 printf(" --max-jobs=nr\t\tMaximum number of threads/processes to support\n");
1790 printf(" --server=args\t\tStart a backend fio server\n");
1791 printf(" --daemonize=pidfile\tBackground fio server, write pid to file\n");
1792 printf(" --client=hostname\tTalk to remote backend fio server at hostname\n");
323255cc 1793 printf(" --remote-config=file\tTell fio server to load this local job file\n");
f2a2ce0e
HL
1794 printf(" --idle-prof=option\tReport cpu idleness on a system or percpu basis\n"
1795 "\t\t\t(option=system,percpu) or run unit work\n"
1796 "\t\t\tcalibration only (option=calibrate)\n");
b26317c9
JA
1797#ifdef CONFIG_ZLIB
1798 printf(" --inflate-log=log\tInflate and output compressed log\n");
1799#endif
b63efd30 1800 printf(" --trigger-file=file\tExecute trigger cmd when file exists\n");
ca09be4b 1801 printf(" --trigger-timeout=t\tExecute trigger af this time\n");
b63efd30
JA
1802 printf(" --trigger=cmd\t\tSet this command as local trigger\n");
1803 printf(" --trigger-remote=cmd\tSet this command as remote trigger\n");
d264264a 1804 printf(" --aux-path=path\tUse this path for fio state generated files\n");
aa58d252 1805 printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
bfca2c74
JA
1806 printf("\n Jens Axboe <jaxboe@fusionio.com>");
1807 printf("\n Jens Axboe <axboe@fb.com>\n");
4785f995
JA
1808}
1809
79e48f72 1810#ifdef FIO_INC_DEBUG
ee56ad50 1811struct debug_level debug_levels[] = {
0b8d11ed
JA
1812 { .name = "process",
1813 .help = "Process creation/exit logging",
1814 .shift = FD_PROCESS,
1815 },
1816 { .name = "file",
1817 .help = "File related action logging",
1818 .shift = FD_FILE,
1819 },
1820 { .name = "io",
1821 .help = "IO and IO engine action logging (offsets, queue, completions, etc)",
1822 .shift = FD_IO,
1823 },
1824 { .name = "mem",
1825 .help = "Memory allocation/freeing logging",
1826 .shift = FD_MEM,
1827 },
1828 { .name = "blktrace",
1829 .help = "blktrace action logging",
1830 .shift = FD_BLKTRACE,
1831 },
1832 { .name = "verify",
1833 .help = "IO verification action logging",
1834 .shift = FD_VERIFY,
1835 },
1836 { .name = "random",
1837 .help = "Random generation logging",
1838 .shift = FD_RANDOM,
1839 },
1840 { .name = "parse",
1841 .help = "Parser logging",
1842 .shift = FD_PARSE,
1843 },
1844 { .name = "diskutil",
1845 .help = "Disk utility logging actions",
1846 .shift = FD_DISKUTIL,
1847 },
1848 { .name = "job",
1849 .help = "Logging related to creating/destroying jobs",
1850 .shift = FD_JOB,
1851 },
1852 { .name = "mutex",
1853 .help = "Mutex logging",
1854 .shift = FD_MUTEX
1855 },
1856 { .name = "profile",
1857 .help = "Logging related to profiles",
1858 .shift = FD_PROFILE,
1859 },
1860 { .name = "time",
1861 .help = "Logging related to time keeping functions",
1862 .shift = FD_TIME,
1863 },
1864 { .name = "net",
1865 .help = "Network logging",
1866 .shift = FD_NET,
1867 },
3e260a46
JA
1868 { .name = "rate",
1869 .help = "Rate logging",
1870 .shift = FD_RATE,
1871 },
0c56718d
JA
1872 { .name = "compress",
1873 .help = "Log compression logging",
1874 .shift = FD_COMPRESS,
1875 },
02444ad1 1876 { .name = NULL, },
ee56ad50
JA
1877};
1878
c09823ab 1879static int set_debug(const char *string)
ee56ad50
JA
1880{
1881 struct debug_level *dl;
1882 char *p = (char *) string;
1883 char *opt;
1884 int i;
1885
1886 if (!strcmp(string, "?") || !strcmp(string, "help")) {
ee56ad50
JA
1887 log_info("fio: dumping debug options:");
1888 for (i = 0; debug_levels[i].name; i++) {
1889 dl = &debug_levels[i];
1890 log_info("%s,", dl->name);
1891 }
bd6f78b2 1892 log_info("all\n");
c09823ab 1893 return 1;
ee56ad50
JA
1894 }
1895
1896 while ((opt = strsep(&p, ",")) != NULL) {
1897 int found = 0;
1898
5e1d306e
JA
1899 if (!strncmp(opt, "all", 3)) {
1900 log_info("fio: set all debug options\n");
1901 fio_debug = ~0UL;
1902 continue;
1903 }
1904
ee56ad50
JA
1905 for (i = 0; debug_levels[i].name; i++) {
1906 dl = &debug_levels[i];
5e1d306e
JA
1907 found = !strncmp(opt, dl->name, strlen(dl->name));
1908 if (!found)
1909 continue;
1910
1911 if (dl->shift == FD_JOB) {
1912 opt = strchr(opt, ':');
1913 if (!opt) {
1914 log_err("fio: missing job number\n");
1915 break;
1916 }
1917 opt++;
1918 fio_debug_jobno = atoi(opt);
1919 log_info("fio: set debug jobno %d\n",
1920 fio_debug_jobno);
1921 } else {
ee56ad50 1922 log_info("fio: set debug option %s\n", opt);
bd6f78b2 1923 fio_debug |= (1UL << dl->shift);
ee56ad50 1924 }
5e1d306e 1925 break;
ee56ad50
JA
1926 }
1927
1928 if (!found)
1929 log_err("fio: debug mask %s not found\n", opt);
1930 }
c09823ab 1931 return 0;
ee56ad50 1932}
79e48f72 1933#else
69b98d4c 1934static int set_debug(const char *string)
79e48f72
JA
1935{
1936 log_err("fio: debug tracing not included in build\n");
c09823ab 1937 return 1;
79e48f72
JA
1938}
1939#endif
9ac8a797 1940
4c6107ff
JA
1941static void fio_options_fill_optstring(void)
1942{
1943 char *ostr = cmd_optstr;
1944 int i, c;
1945
1946 c = i = 0;
1947 while (l_opts[i].name) {
1948 ostr[c++] = l_opts[i].val;
1949 if (l_opts[i].has_arg == required_argument)
1950 ostr[c++] = ':';
1951 else if (l_opts[i].has_arg == optional_argument) {
1952 ostr[c++] = ':';
1953 ostr[c++] = ':';
1954 }
1955 i++;
1956 }
1957 ostr[c] = '\0';
1958}
1959
c2c94585
JA
1960static int client_flag_set(char c)
1961{
1962 int i;
1963
1964 i = 0;
1965 while (l_opts[i].name) {
1966 int val = l_opts[i].val;
1967
1968 if (c == (val & 0xff))
1969 return (val & FIO_CLIENT_FLAG);
1970
1971 i++;
1972 }
1973
1974 return 0;
1975}
1976
10aa136b 1977static void parse_cmd_client(void *client, char *opt)
7a4b8240 1978{
fa2ea806 1979 fio_client_add_cmd_option(client, opt);
7a4b8240
JA
1980}
1981
a893c261
JA
1982static void show_closest_option(const char *name)
1983{
1984 int best_option, best_distance;
1985 int i, distance;
1986
1987 while (*name == '-')
1988 name++;
1989
1990 best_option = -1;
1991 best_distance = INT_MAX;
1992 i = 0;
1993 while (l_opts[i].name) {
1994 distance = string_distance(name, l_opts[i].name);
1995 if (distance < best_distance) {
1996 best_distance = distance;
1997 best_option = i;
1998 }
1999 i++;
2000 }
2001
3701636d 2002 if (best_option != -1 && string_distance_ok(name, best_distance))
a893c261
JA
2003 log_err("Did you mean %s?\n", l_opts[best_option].name);
2004}
2005
a666cab8
JA
2006static int parse_output_format(const char *optarg)
2007{
2008 char *p, *orig, *opt;
2009 int ret = 0;
2010
2011 p = orig = strdup(optarg);
2012
2013 output_format = 0;
2014
2015 while ((opt = strsep(&p, ",")) != NULL) {
2016 if (!strcmp(opt, "minimal") ||
2017 !strcmp(opt, "terse") ||
2018 !strcmp(opt, "csv"))
2019 output_format |= FIO_OUTPUT_TERSE;
2020 else if (!strcmp(opt, "json"))
2021 output_format |= FIO_OUTPUT_JSON;
2022 else if (!strcmp(opt, "normal"))
2023 output_format |= FIO_OUTPUT_NORMAL;
2024 else {
2025 log_err("fio: invalid output format %s\n", opt);
2026 ret = 1;
2027 break;
2028 }
2029 }
2030
2031 free(orig);
2032 return ret;
2033}
2034
46bcd498 2035int parse_cmd_line(int argc, char *argv[], int client_type)
ebac4655 2036{
b4692828 2037 struct thread_data *td = NULL;
c09823ab 2038 int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
4c6107ff 2039 char *ostr = cmd_optstr;
402668f3 2040 void *pid_file = NULL;
9bae26e8 2041 void *cur_client = NULL;
81179eec 2042 int backend = 0;
ebac4655 2043
c2c94585
JA
2044 /*
2045 * Reset optind handling, since we may call this multiple times
2046 * for the backend.
2047 */
2048 optind = 1;
7a4b8240 2049
c2c94585
JA
2050 while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
2051 if ((c & FIO_CLIENT_FLAG) || client_flag_set(c)) {
fa2ea806 2052 parse_cmd_client(cur_client, argv[optind - 1]);
7a4b8240
JA
2053 c &= ~FIO_CLIENT_FLAG;
2054 }
2055
ebac4655 2056 switch (c) {
2b386d25
JA
2057 case 'a':
2058 smalloc_pool_size = atoi(optarg);
2059 break;
b4692828 2060 case 't':
25bd16ce
JA
2061 if (check_str_time(optarg, &def_timeout, 1)) {
2062 log_err("fio: failed parsing time %s\n", optarg);
2063 do_exit++;
2064 exit_val = 1;
2065 }
b4692828
JA
2066 break;
2067 case 'l':
cb7e0ace
JA
2068 log_err("fio: --latency-log is deprecated. Use per-job latency log options.\n");
2069 do_exit++;
2070 exit_val = 1;
b4692828 2071 break;
3d73e5a9 2072 case 'b':
b4692828
JA
2073 write_bw_log = 1;
2074 break;
2075 case 'o':
988da120 2076 if (f_out && f_out != stdout)
5e1d8745
JA
2077 fclose(f_out);
2078
b4692828
JA
2079 f_out = fopen(optarg, "w+");
2080 if (!f_out) {
2081 perror("fopen output");
2082 exit(1);
2083 }
2084 f_err = f_out;
2085 break;
2086 case 'm':
f3afa57e 2087 output_format = FIO_OUTPUT_TERSE;
b4692828 2088 break;
f3afa57e 2089 case 'F':
d10983d7
SH
2090 if (!optarg) {
2091 log_err("fio: missing --output-format argument\n");
2092 exit_val = 1;
2093 do_exit++;
2094 break;
2095 }
a666cab8
JA
2096 if (parse_output_format(optarg)) {
2097 log_err("fio: failed parsing output-format\n");
2098 exit_val = 1;
2099 do_exit++;
2100 break;
2101 }
2b8c71b0 2102 break;
b4692828 2103 case 'h':
7d8ea970 2104 did_arg = 1;
7874f8b7 2105 if (!cur_client) {
c2c94585 2106 usage(argv[0]);
7874f8b7
JA
2107 do_exit++;
2108 }
c2c94585 2109 break;
fd28ca49 2110 case 'c':
7d8ea970 2111 did_arg = 1;
7874f8b7 2112 if (!cur_client) {
c2c94585 2113 fio_show_option_help(optarg);
7874f8b7
JA
2114 do_exit++;
2115 }
c2c94585 2116 break;
de890a1e 2117 case 'i':
7d8ea970 2118 did_arg = 1;
de890a1e
SL
2119 if (!cur_client) {
2120 fio_show_ioengine_help(optarg);
2121 do_exit++;
2122 }
2123 break;
cca73aa7 2124 case 's':
7d8ea970 2125 did_arg = 1;
cca73aa7
JA
2126 dump_cmdline = 1;
2127 break;
724e4435
JA
2128 case 'r':
2129 read_only = 1;
2130 break;
b4692828 2131 case 'v':
7d8ea970 2132 did_arg = 1;
7874f8b7 2133 if (!cur_client) {
3d43382c 2134 log_info("%s\n", fio_version_string);
7874f8b7
JA
2135 do_exit++;
2136 }
c2c94585 2137 break;
f57a9c59
JA
2138 case 'V':
2139 terse_version = atoi(optarg);
09786f5f
JA
2140 if (!(terse_version == 2 || terse_version == 3 ||
2141 terse_version == 4)) {
f57a9c59
JA
2142 log_err("fio: bad terse version format\n");
2143 exit_val = 1;
2144 do_exit++;
2145 }
2146 break;
e592a06b
AC
2147 case 'e':
2148 if (!strcmp("always", optarg))
2149 eta_print = FIO_ETA_ALWAYS;
2150 else if (!strcmp("never", optarg))
2151 eta_print = FIO_ETA_NEVER;
2152 break;
e382e661
JA
2153 case 'E': {
2154 long long t = 0;
2155
88038bc7 2156 if (check_str_time(optarg, &t, 1)) {
e382e661
JA
2157 log_err("fio: failed parsing eta time %s\n", optarg);
2158 exit_val = 1;
2159 do_exit++;
2160 }
88038bc7 2161 eta_new_line = t / 1000;
e382e661
JA
2162 break;
2163 }
ee56ad50 2164 case 'd':
c09823ab
JA
2165 if (set_debug(optarg))
2166 do_exit++;
ee56ad50 2167 break;
111e032d 2168 case 'P':
7d8ea970 2169 did_arg = 1;
111e032d
JA
2170 parse_only = 1;
2171 break;
ad0a2735
JA
2172 case 'x': {
2173 size_t new_size;
2174
01f06b63 2175 if (!strcmp(optarg, "global")) {
5ec10eaa
JA
2176 log_err("fio: can't use global as only "
2177 "section\n");
c09823ab
JA
2178 do_exit++;
2179 exit_val = 1;
01f06b63
JA
2180 break;
2181 }
ad0a2735
JA
2182 new_size = (nr_job_sections + 1) * sizeof(char *);
2183 job_sections = realloc(job_sections, new_size);
2184 job_sections[nr_job_sections] = strdup(optarg);
2185 nr_job_sections++;
01f06b63 2186 break;
ad0a2735 2187 }
b26317c9
JA
2188#ifdef CONFIG_ZLIB
2189 case 'X':
2190 exit_val = iolog_file_inflate(optarg);
2191 did_arg++;
2192 do_exit++;
2193 break;
2194#endif
9ac8a797 2195 case 'p':
7d8ea970 2196 did_arg = 1;
4af7c007
JA
2197 if (exec_profile)
2198 free(exec_profile);
07b3232d 2199 exec_profile = strdup(optarg);
9ac8a797 2200 break;
b4692828 2201 case FIO_GETOPT_JOB: {
5ec10eaa 2202 const char *opt = l_opts[lidx].name;
b4692828
JA
2203 char *val = optarg;
2204
c2b1e753 2205 if (!strncmp(opt, "name", 4) && td) {
46bcd498 2206 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
66251554 2207 if (ret)
4a4ac4e3 2208 goto out_free;
c2b1e753 2209 td = NULL;
7d8ea970 2210 did_arg = 1;
c2b1e753 2211 }
b4692828 2212 if (!td) {
01f06b63 2213 int is_section = !strncmp(opt, "name", 4);
3106f220
JA
2214 int global = 0;
2215
01f06b63 2216 if (!is_section || !strncmp(val, "global", 6))
3106f220 2217 global = 1;
c2b1e753 2218
01f06b63
JA
2219 if (is_section && skip_this_section(val))
2220 continue;
2221
ef3d8e53 2222 td = get_new_job(global, &def_thread, 1, NULL);
f6ff24cb
JA
2223 if (!td || ioengine_load(td)) {
2224 if (td) {
2225 put_job(td);
2226 td = NULL;
2227 }
2228 do_exit++;
205a719e 2229 exit_val = 1;
f6ff24cb
JA
2230 break;
2231 }
de890a1e 2232 fio_options_set_ioengine_opts(l_opts, td);
b4692828 2233 }
38d0adb0 2234
9d918187
JA
2235 if ((!val || !strlen(val)) &&
2236 l_opts[lidx].has_arg == required_argument) {
2237 log_err("fio: option %s requires an argument\n", opt);
2238 ret = 1;
2239 } else
2240 ret = fio_cmd_option_parse(td, opt, val);
2241
bfb3ea22
JA
2242 if (ret) {
2243 if (td) {
2244 put_job(td);
2245 td = NULL;
2246 }
a88c8c14 2247 do_exit++;
205a719e 2248 exit_val = 1;
bfb3ea22 2249 }
de890a1e
SL
2250
2251 if (!ret && !strcmp(opt, "ioengine")) {
2252 free_ioengine(td);
f6ff24cb 2253 if (ioengine_load(td)) {
342f570e
JA
2254 put_job(td);
2255 td = NULL;
f6ff24cb 2256 do_exit++;
205a719e 2257 exit_val = 1;
f6ff24cb
JA
2258 break;
2259 }
de890a1e
SL
2260 fio_options_set_ioengine_opts(l_opts, td);
2261 }
2262 break;
2263 }
2264 case FIO_GETOPT_IOENGINE: {
2265 const char *opt = l_opts[lidx].name;
2266 char *val = optarg;
b1ed74e0
JA
2267
2268 if (!td)
2269 break;
2270
de890a1e 2271 ret = fio_cmd_ioengine_option_parse(td, opt, val);
b4692828
JA
2272 break;
2273 }
a9523c6f
JA
2274 case 'w':
2275 warnings_fatal = 1;
2276 break;
fca70358
JA
2277 case 'j':
2278 max_jobs = atoi(optarg);
2279 if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
2280 log_err("fio: invalid max jobs: %d\n", max_jobs);
2281 do_exit++;
2282 exit_val = 1;
2283 }
2284 break;
50d16976 2285 case 'S':
7d8ea970 2286 did_arg = 1;
c8931876 2287#ifndef CONFIG_NO_SHM
a37f69b7 2288 if (nr_clients) {
132159a5
JA
2289 log_err("fio: can't be both client and server\n");
2290 do_exit++;
2291 exit_val = 1;
2292 break;
2293 }
87aa8f19 2294 if (optarg)
bebe6398 2295 fio_server_set_arg(optarg);
50d16976 2296 is_backend = 1;
81179eec 2297 backend = 1;
c8931876
JA
2298#else
2299 log_err("fio: client/server requires SHM support\n");
2300 do_exit++;
2301 exit_val = 1;
2302#endif
50d16976 2303 break;
e46d8091 2304 case 'D':
6cfe9a8c
JA
2305 if (pid_file)
2306 free(pid_file);
402668f3 2307 pid_file = strdup(optarg);
e46d8091 2308 break;
f2a2ce0e
HL
2309 case 'I':
2310 if ((ret = fio_idle_prof_parse_opt(optarg))) {
2311 /* exit on error and calibration only */
7d8ea970 2312 did_arg = 1;
f2a2ce0e 2313 do_exit++;
7d8ea970 2314 if (ret == -1)
f2a2ce0e
HL
2315 exit_val = 1;
2316 }
2317 break;
132159a5 2318 case 'C':
7d8ea970 2319 did_arg = 1;
132159a5
JA
2320 if (is_backend) {
2321 log_err("fio: can't be both client and server\n");
2322 do_exit++;
2323 exit_val = 1;
2324 break;
2325 }
08633c32
BE
2326 /* if --client parameter contains a pathname */
2327 if (0 == access(optarg, R_OK)) {
2328 /* file contains a list of host addrs or names */
2972708f 2329 char hostaddr[PATH_MAX] = {0};
08633c32
BE
2330 char formatstr[8];
2331 FILE * hostf = fopen(optarg, "r");
2332 if (!hostf) {
2333 log_err("fio: could not open client list file %s for read\n", optarg);
2334 do_exit++;
2335 exit_val = 1;
2336 break;
2337 }
2972708f
JA
2338 sprintf(formatstr, "%%%ds", PATH_MAX - 1);
2339 /*
2340 * read at most PATH_MAX-1 chars from each
2341 * record in this file
2342 */
08633c32
BE
2343 while (fscanf(hostf, formatstr, hostaddr) == 1) {
2344 /* expect EVERY host in file to be valid */
2345 if (fio_client_add(&fio_client_ops, hostaddr, &cur_client)) {
2346 log_err("fio: failed adding client %s from file %s\n", hostaddr, optarg);
2347 do_exit++;
2348 exit_val = 1;
2349 break;
2350 }
2351 }
2352 fclose(hostf);
2353 break; /* no possibility of job file for "this client only" */
2354 }
a5276616 2355 if (fio_client_add(&fio_client_ops, optarg, &cur_client)) {
bebe6398
JA
2356 log_err("fio: failed adding client %s\n", optarg);
2357 do_exit++;
2358 exit_val = 1;
2359 break;
2360 }
14ea90ed
JA
2361 /*
2362 * If the next argument exists and isn't an option,
2363 * assume it's a job file for this client only.
2364 */
2365 while (optind < argc) {
2366 if (!strncmp(argv[optind], "--", 2) ||
2367 !strncmp(argv[optind], "-", 1))
2368 break;
2369
323255cc
JA
2370 if (fio_client_add_ini_file(cur_client, argv[optind], 0))
2371 break;
14ea90ed
JA
2372 optind++;
2373 }
132159a5 2374 break;
323255cc
JA
2375 case 'R':
2376 did_arg = 1;
2377 if (fio_client_add_ini_file(cur_client, optarg, 1)) {
2378 do_exit++;
2379 exit_val = 1;
2380 }
2381 break;
7d11f871 2382 case 'T':
7d8ea970 2383 did_arg = 1;
7d11f871 2384 do_exit++;
aad918e4 2385 exit_val = fio_monotonic_clocktest(1);
7d11f871 2386 break;
fec0f21c 2387 case 'G':
7d8ea970 2388 did_arg = 1;
fec0f21c
JA
2389 do_exit++;
2390 exit_val = fio_crctest(optarg);
2391 break;
06464907
JA
2392 case 'L': {
2393 long long val;
2394
88038bc7 2395 if (check_str_time(optarg, &val, 1)) {
06464907
JA
2396 log_err("fio: failed parsing time %s\n", optarg);
2397 do_exit++;
2398 exit_val = 1;
2399 break;
2400 }
88038bc7 2401 status_interval = val / 1000;
06464907
JA
2402 break;
2403 }
b63efd30 2404 case 'W':
f9cbae9e
JA
2405 if (trigger_file)
2406 free(trigger_file);
b63efd30
JA
2407 trigger_file = strdup(optarg);
2408 break;
2409 case 'H':
f9cbae9e
JA
2410 if (trigger_cmd)
2411 free(trigger_cmd);
b63efd30
JA
2412 trigger_cmd = strdup(optarg);
2413 break;
2414 case 'J':
f9cbae9e
JA
2415 if (trigger_remote_cmd)
2416 free(trigger_remote_cmd);
b63efd30 2417 trigger_remote_cmd = strdup(optarg);
ca09be4b 2418 break;
d264264a
JA
2419 case 'K':
2420 if (aux_path)
2421 free(aux_path);
2422 aux_path = strdup(optarg);
2423 break;
ca09be4b
JA
2424 case 'B':
2425 if (check_str_time(optarg, &trigger_timeout, 1)) {
2426 log_err("fio: failed parsing time %s\n", optarg);
2427 do_exit++;
2428 exit_val = 1;
2429 }
2430 trigger_timeout /= 1000000;
2431 break;
798827c8
JA
2432 case '?':
2433 log_err("%s: unrecognized option '%s'\n", argv[0],
2434 argv[optind - 1]);
a893c261 2435 show_closest_option(argv[optind - 1]);
b4692828 2436 default:
c09823ab
JA
2437 do_exit++;
2438 exit_val = 1;
b4692828 2439 break;
ebac4655 2440 }
c7d5c941
JA
2441 if (do_exit)
2442 break;
ebac4655 2443 }
c9fad893 2444
0b14f0a8
JA
2445 if (do_exit && !(is_backend || nr_clients))
2446 exit(exit_val);
536582bf 2447
fb296043
JA
2448 if (nr_clients && fio_clients_connect())
2449 exit(1);
132159a5 2450
81179eec 2451 if (is_backend && backend)
402668f3 2452 return fio_start_server(pid_file);
b8ba87ac
JA
2453 else if (pid_file)
2454 free(pid_file);
50d16976 2455
b4692828 2456 if (td) {
7d8ea970 2457 if (!ret) {
46bcd498 2458 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
7d8ea970
JA
2459 if (ret)
2460 did_arg = 1;
2461 }
972cfd25 2462 }
774a6177 2463
7874f8b7 2464 while (!ret && optind < argc) {
b4692828
JA
2465 ini_idx++;
2466 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
2467 ini_file[ini_idx - 1] = strdup(argv[optind]);
2468 optind++;
eb8bbf48 2469 }
972cfd25 2470
4a4ac4e3
JA
2471out_free:
2472 if (pid_file)
2473 free(pid_file);
2474
972cfd25 2475 return ini_idx;
ebac4655
JA
2476}
2477
0420ba6a 2478int fio_init_options(void)
ebac4655 2479{
b4692828
JA
2480 f_out = stdout;
2481 f_err = stderr;
2482
4c6107ff 2483 fio_options_fill_optstring();
5ec10eaa 2484 fio_options_dup_and_init(l_opts);
b4692828 2485
9d9eb2e7
JA
2486 atexit(free_shm);
2487
ebac4655
JA
2488 if (fill_def_thread())
2489 return 1;
2490
0420ba6a
JA
2491 return 0;
2492}
2493
51167799
JA
2494extern int fio_check_options(struct thread_options *);
2495
0420ba6a
JA
2496int parse_options(int argc, char *argv[])
2497{
46bcd498 2498 const int type = FIO_CLIENT_TYPE_CLI;
0420ba6a
JA
2499 int job_files, i;
2500
2501 if (fio_init_options())
2502 return 1;
51167799
JA
2503 if (fio_test_cconv(&def_thread.o))
2504 log_err("fio: failed internal cconv test\n");
0420ba6a 2505
46bcd498 2506 job_files = parse_cmd_line(argc, argv, type);
ebac4655 2507
cdf54d85
JA
2508 if (job_files > 0) {
2509 for (i = 0; i < job_files; i++) {
bc4f5ef6 2510 if (i && fill_def_thread())
132159a5 2511 return 1;
cdf54d85
JA
2512 if (nr_clients) {
2513 if (fio_clients_send_ini(ini_file[i]))
2514 return 1;
2515 free(ini_file[i]);
2516 } else if (!is_backend) {
46bcd498 2517 if (parse_jobs_ini(ini_file[i], 0, i, type))
cdf54d85
JA
2518 return 1;
2519 free(ini_file[i]);
2520 }
132159a5 2521 }
14ea90ed
JA
2522 } else if (nr_clients) {
2523 if (fill_def_thread())
2524 return 1;
2525 if (fio_clients_send_ini(NULL))
2526 return 1;
972cfd25 2527 }
ebac4655 2528
88c6ed80 2529 free(ini_file);
7e356b2d 2530 fio_options_free(&def_thread);
bcbfeefa 2531 filesetup_mem_free();
b4692828
JA
2532
2533 if (!thread_number) {
f9633d72 2534 if (parse_dryrun())
cca73aa7 2535 return 0;
07b3232d
JA
2536 if (exec_profile)
2537 return 0;
a37f69b7 2538 if (is_backend || nr_clients)
5c341e9a 2539 return 0;
085399db
JA
2540 if (did_arg)
2541 return 0;
cca73aa7 2542
d65e11c6 2543 log_err("No jobs(s) defined\n\n");
085399db
JA
2544
2545 if (!did_arg) {
2546 usage(argv[0]);
2547 return 1;
2548 }
2549
2550 return 0;
b4692828
JA
2551 }
2552
129fb2d4 2553 if (output_format & FIO_OUTPUT_NORMAL)
3d43382c 2554 log_info("%s\n", fio_version_string);
f6dea4d3 2555
ebac4655
JA
2556 return 0;
2557}
588b7f09
JA
2558
2559void options_default_fill(struct thread_options *o)
2560{
2561 memcpy(o, &def_thread.o, sizeof(*o));
2562}