Improve rate accounting
[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>
b4692828 11#include <getopt.h>
ebac4655
JA
12#include <sys/ipc.h>
13#include <sys/shm.h>
14#include <sys/types.h>
15#include <sys/stat.h>
16
17#include "fio.h"
cb2c86fd 18#include "parse.h"
ebac4655 19
214e1eca
JA
20static char fio_version_string[] = "fio 1.14a";
21
ee738499 22#define FIO_RANDSEED (0xb1899bedUL)
ebac4655 23
214e1eca
JA
24static char **ini_file;
25static int max_jobs = MAX_JOBS;
e1f36503 26
214e1eca
JA
27struct thread_data def_thread;
28struct thread_data *threads = NULL;
e1f36503 29
214e1eca
JA
30int exitall_on_terminate = 0;
31int terse_output = 0;
32unsigned long long mlock_size = 0;
33FILE *f_out = NULL;
34FILE *f_err = NULL;
ee738499 35
214e1eca
JA
36int write_bw_log = 0;
37
38static int def_timeout = 0;
39static int write_lat_log = 0;
e1f36503 40
214e1eca 41static int prev_group_jobs;
b4692828
JA
42
43/*
44 * Command line options. These will contain the above, plus a few
45 * extra that only pertain to fio itself and not jobs.
46 */
214e1eca 47static struct option long_options[FIO_NR_OPTIONS] = {
b4692828
JA
48 {
49 .name = "output",
50 .has_arg = required_argument,
51 .val = 'o',
52 },
53 {
54 .name = "timeout",
55 .has_arg = required_argument,
56 .val = 't',
57 },
58 {
59 .name = "latency-log",
60 .has_arg = required_argument,
61 .val = 'l',
62 },
63 {
64 .name = "bandwidth-log",
65 .has_arg = required_argument,
66 .val = 'b',
67 },
68 {
69 .name = "minimal",
70 .has_arg = optional_argument,
71 .val = 'm',
72 },
73 {
74 .name = "version",
75 .has_arg = no_argument,
76 .val = 'v',
77 },
fd28ca49
JA
78 {
79 .name = "help",
80 .has_arg = no_argument,
81 .val = 'h',
82 },
83 {
84 .name = "cmdhelp",
320beefe 85 .has_arg = optional_argument,
fd28ca49
JA
86 .val = 'c',
87 },
b4692828
JA
88 {
89 .name = NULL,
90 },
91};
92
9728ce37
JB
93FILE *get_f_out()
94{
95 return f_out;
96}
97
98FILE *get_f_err()
99{
100 return f_err;
101}
102
906c8d75
JA
103/*
104 * Return a free job structure.
105 */
ebac4655
JA
106static struct thread_data *get_new_job(int global, struct thread_data *parent)
107{
108 struct thread_data *td;
109
110 if (global)
111 return &def_thread;
112 if (thread_number >= max_jobs)
113 return NULL;
114
115 td = &threads[thread_number++];
ddaeaa5a 116 *td = *parent;
ebac4655 117
ebac4655 118 td->thread_number = thread_number;
ebac4655
JA
119 return td;
120}
121
122static void put_job(struct thread_data *td)
123{
549577a7
JA
124 if (td == &def_thread)
125 return;
126
16edf25d 127 if (td->error)
6d86144d 128 log_info("fio: %s\n", td->verror);
16edf25d 129
ebac4655
JA
130 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
131 thread_number--;
132}
133
dad915e3
JA
134/*
135 * Lazy way of fixing up options that depend on each other. We could also
136 * define option callback handlers, but this is easier.
137 */
4e991c23 138static int fixup_options(struct thread_data *td)
e1f36503 139{
e1f36503
JA
140 if (!td->rwmixread && td->rwmixwrite)
141 td->rwmixread = 100 - td->rwmixwrite;
dad915e3 142
076efc7c
JA
143 if (td->write_iolog_file && td->read_iolog_file) {
144 log_err("fio: read iolog overrides write_iolog\n");
145 free(td->write_iolog_file);
146 td->write_iolog_file = NULL;
147 }
16b462ae
JA
148
149 if (td->io_ops->flags & FIO_SYNCIO)
150 td->iodepth = 1;
151 else {
152 if (!td->iodepth)
b5af8293 153 td->iodepth = td->open_files;
16b462ae
JA
154 }
155
156 /*
157 * only really works for sequential io for now, and with 1 file
158 */
b5af8293 159 if (td->zone_size && td_random(td) && td->open_files == 1)
16b462ae
JA
160 td->zone_size = 0;
161
162 /*
163 * Reads can do overwrites, we always need to pre-create the file
164 */
165 if (td_read(td) || td_rw(td))
166 td->overwrite = 1;
167
a00735e6
JA
168 if (!td->min_bs[DDIR_READ])
169 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
170 if (!td->max_bs[DDIR_READ])
171 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
172 if (!td->min_bs[DDIR_WRITE])
75e6f36f 173 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
a00735e6 174 if (!td->max_bs[DDIR_WRITE])
75e6f36f 175 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
a00735e6
JA
176
177 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
178
9c60ce64
JA
179 if (!td->file_size_high)
180 td->file_size_high = td->file_size_low;
181
16b462ae
JA
182 if (td_read(td) && !td_rw(td))
183 td->verify = 0;
bb8895e0
JA
184
185 if (td->norandommap && td->verify != VERIFY_NONE) {
186 log_err("fio: norandommap given, verify disabled\n");
187 td->verify = VERIFY_NONE;
188 }
690adba3
JA
189 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
190 log_err("fio: bs_unaligned may not work with raw io\n");
e0a22335 191
48097d5c
JA
192 /*
193 * thinktime_spin must be less than thinktime
194 */
195 if (td->thinktime_spin > td->thinktime)
196 td->thinktime_spin = td->thinktime;
e916b390
JA
197
198 /*
199 * The low water mark cannot be bigger than the iodepth
200 */
9467b77c
JA
201 if (td->iodepth_low > td->iodepth || !td->iodepth_low) {
202 /*
203 * syslet work around - if the workload is sequential,
204 * we want to let the queue drain all the way down to
205 * avoid seeking between async threads
206 */
207 if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
208 td->iodepth_low = 1;
209 else
210 td->iodepth_low = td->iodepth;
211 }
cb5ab512
JA
212
213 /*
214 * If batch number isn't set, default to the same as iodepth
215 */
216 if (td->iodepth_batch > td->iodepth || !td->iodepth_batch)
217 td->iodepth_batch = td->iodepth;
b5af8293 218
bbf6b540 219 if (td->nr_files > td->files_index)
9f9214f2
JA
220 td->nr_files = td->files_index;
221
222 if (td->open_files > td->nr_files || !td->open_files)
b5af8293 223 td->open_files = td->nr_files;
4e991c23
JA
224
225 if ((td->rate && td->rate_iops) || (td->ratemin && td->rate_iops_min)) {
226 log_err("fio: rate and rate_iops are mutually exclusive\n");
227 return 1;
228 }
229 if ((td->rate < td->ratemin) || (td->rate_iops < td->rate_iops_min)) {
230 log_err("fio: minimum rate exceeds rate\n");
231 return 1;
232 }
233
234 return 0;
e1f36503
JA
235}
236
f8977ee6
JA
237/*
238 * This function leaks the buffer
239 */
240static char *to_kmg(unsigned int val)
241{
242 char *buf = malloc(32);
f3502ba2 243 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
f8977ee6
JA
244 char *p = post;
245
245142ff 246 do {
f8977ee6
JA
247 if (val & 1023)
248 break;
249
250 val >>= 10;
251 p++;
245142ff 252 } while (*p);
f8977ee6
JA
253
254 snprintf(buf, 31, "%u%c", val, *p);
255 return buf;
256}
257
09629a90
JA
258/* External engines are specified by "external:name.o") */
259static const char *get_engine_name(const char *str)
260{
261 char *p = strstr(str, ":");
262
263 if (!p)
264 return str;
265
266 p++;
267 strip_blank_front(&p);
268 strip_blank_end(p);
269 return p;
270}
271
e132cbae
JA
272static int exists_and_not_file(const char *filename)
273{
274 struct stat sb;
275
276 if (lstat(filename, &sb) == -1)
277 return 0;
278
279 if (S_ISREG(sb.st_mode))
280 return 0;
281
282 return 1;
283}
284
9c60ce64
JA
285/*
286 * Initialize the various random states we need (random io, block size ranges,
287 * read/write mix, etc).
288 */
289static int init_random_state(struct thread_data *td)
290{
291 unsigned long seeds[6];
292 int fd, num_maps, blocks;
293 struct fio_file *f;
294 unsigned int i;
295
296 fd = open("/dev/urandom", O_RDONLY);
297 if (fd == -1) {
298 td_verror(td, errno, "open");
299 return 1;
300 }
301
302 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
303 td_verror(td, EIO, "read");
304 close(fd);
305 return 1;
306 }
307
308 close(fd);
309
310 os_random_seed(seeds[0], &td->bsrange_state);
311 os_random_seed(seeds[1], &td->verify_state);
312 os_random_seed(seeds[2], &td->rwmix_state);
313
314 if (td->file_service_type == FIO_FSERVICE_RANDOM)
315 os_random_seed(seeds[3], &td->next_file_state);
316
317 os_random_seed(seeds[5], &td->file_size_state);
318
319 if (!td_random(td))
320 return 0;
321
322 if (td->rand_repeatable)
323 seeds[4] = FIO_RANDSEED * td->thread_number;
324
325 if (!td->norandommap) {
326 for_each_file(td, f, i) {
327 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
328 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
329 f->file_map = malloc(num_maps * sizeof(long));
330 if (!f->file_map) {
331 log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n");
332 return 1;
333 }
334 f->num_maps = num_maps;
335 memset(f->file_map, 0, num_maps * sizeof(long));
336 }
337 }
338
339 os_random_seed(seeds[4], &td->random_state);
340 return 0;
341}
342
343
906c8d75
JA
344/*
345 * Adds a job to the list of things todo. Sanitizes the various options
346 * to make sure we don't have conflicts, and initializes various
347 * members of td.
348 */
75154845 349static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
ebac4655 350{
413dd459
JA
351 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
352 "randread", "randwrite", "randrw" };
af52b345 353 unsigned int i;
53cdc686 354 struct fio_file *f;
09629a90 355 const char *engine;
af52b345 356 char fname[PATH_MAX];
e132cbae 357 int numjobs, file_alloced;
ebac4655 358
ebac4655
JA
359 /*
360 * the def_thread is just for options, it's not a real job
361 */
362 if (td == &def_thread)
363 return 0;
364
09629a90
JA
365 engine = get_engine_name(td->ioengine);
366 td->io_ops = load_ioengine(td, engine);
367 if (!td->io_ops) {
368 log_err("fio: failed to load engine %s\n", engine);
205927a3 369 goto err;
09629a90 370 }
df64119d 371
9cedf167
JA
372 if (td->use_thread)
373 nr_thread++;
374 else
375 nr_process++;
376
690adba3
JA
377 if (td->odirect)
378 td->io_ops->flags |= FIO_RAWIO;
379
e132cbae 380 file_alloced = 0;
bbf6b540 381 if (!td->filename && !td->files_index) {
e132cbae 382 file_alloced = 1;
80be24f4 383
e132cbae
JA
384 if (td->nr_files == 1 && exists_and_not_file(jobname))
385 add_file(td, jobname);
7b05a215
JA
386 else {
387 for (i = 0; i < td->nr_files; i++) {
e132cbae 388 sprintf(fname, "%s.%d.%d", jobname, td->thread_number, i);
7b05a215
JA
389 add_file(td, fname);
390 }
af52b345 391 }
0af7b542 392 }
ebac4655 393
4e991c23
JA
394 if (fixup_options(td))
395 goto err;
e0a22335 396
af52b345
JA
397 for_each_file(td, f, i) {
398 if (td->directory && f->filetype == FIO_TYPE_FILE) {
399 sprintf(fname, "%s/%s", td->directory, f->file_name);
400 f->file_name = strdup(fname);
53cdc686 401 }
53cdc686
JA
402 }
403
07739b57 404 td->mutex = fio_sem_init(0);
ebac4655 405
756867bd
JA
406 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
407 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
408 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
ebac4655 409
3c5df6fa
JA
410 if ((td->stonewall || td->numjobs > 1) && prev_group_jobs) {
411 prev_group_jobs = 0;
ebac4655 412 groupid++;
3c5df6fa 413 }
ebac4655
JA
414
415 td->groupid = groupid;
3c5df6fa 416 prev_group_jobs++;
ebac4655 417
9c60ce64
JA
418 if (init_random_state(td))
419 goto err;
420
ebac4655
JA
421 if (setup_rate(td))
422 goto err;
423
ec94ec56 424 if (td->write_lat_log) {
756867bd
JA
425 setup_log(&td->ts.slat_log);
426 setup_log(&td->ts.clat_log);
ebac4655 427 }
ec94ec56 428 if (td->write_bw_log)
756867bd 429 setup_log(&td->ts.bw_log);
ebac4655 430
b4692828
JA
431 if (!td->name)
432 td->name = strdup(jobname);
01452055 433
c6ae0a5b 434 if (!terse_output) {
b990b5c0 435 if (!job_add_num) {
ba0fbe10 436 if (!strcmp(td->io_ops->name, "cpuio"))
6d86144d 437 log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
f8977ee6
JA
438 else {
439 char *c1, *c2, *c3, *c4;
440
441 c1 = to_kmg(td->min_bs[DDIR_READ]);
442 c2 = to_kmg(td->max_bs[DDIR_READ]);
443 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
444 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
445
6d86144d 446 log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth);
f8977ee6
JA
447
448 free(c1);
449 free(c2);
450 free(c3);
451 free(c4);
452 }
b990b5c0 453 } else if (job_add_num == 1)
6d86144d 454 log_info("...\n");
c6ae0a5b 455 }
ebac4655
JA
456
457 /*
458 * recurse add identical jobs, clear numjobs and stonewall options
459 * as they don't apply to sub-jobs
460 */
461 numjobs = td->numjobs;
462 while (--numjobs) {
463 struct thread_data *td_new = get_new_job(0, td);
464
465 if (!td_new)
466 goto err;
467
468 td_new->numjobs = 1;
469 td_new->stonewall = 0;
e132cbae
JA
470
471 if (file_alloced) {
472 td_new->filename = NULL;
473 td_new->files_index = 0;
474 td_new->files = NULL;
475 }
476
75154845 477 job_add_num = numjobs - 1;
ebac4655 478
75154845 479 if (add_job(td_new, jobname, job_add_num))
ebac4655
JA
480 goto err;
481 }
3c5df6fa
JA
482
483 if (td->numjobs > 1) {
484 groupid++;
485 prev_group_jobs = 0;
486 }
487
ebac4655
JA
488 return 0;
489err:
490 put_job(td);
491 return -1;
492}
493
ebac4655
JA
494static int is_empty_or_comment(char *line)
495{
496 unsigned int i;
497
498 for (i = 0; i < strlen(line); i++) {
499 if (line[i] == ';')
500 return 1;
5cc2da30
IM
501 if (line[i] == '#')
502 return 1;
ebac4655
JA
503 if (!isspace(line[i]) && !iscntrl(line[i]))
504 return 0;
505 }
506
507 return 1;
508}
509
07261983
JA
510/*
511 * This is our [ini] type file parser.
512 */
1e97cce9 513static int parse_jobs_ini(char *file, int stonewall_flag)
ebac4655 514{
e1f36503 515 unsigned int global;
ebac4655 516 struct thread_data *td;
fee3bb48 517 char *string, *name;
ebac4655
JA
518 fpos_t off;
519 FILE *f;
520 char *p;
0c7e37a0 521 int ret = 0, stonewall;
ebac4655
JA
522
523 f = fopen(file, "r");
524 if (!f) {
aea47d44 525 perror("fopen job file");
ebac4655
JA
526 return 1;
527 }
528
529 string = malloc(4096);
530 name = malloc(256);
fee3bb48 531 memset(name, 0, 256);
ebac4655 532
0c7e37a0 533 stonewall = stonewall_flag;
7c124ac1
JA
534 do {
535 p = fgets(string, 4095, f);
536 if (!p)
45410acb 537 break;
ebac4655
JA
538 if (is_empty_or_comment(p))
539 continue;
fee3bb48 540 if (sscanf(p, "[%255s]", name) != 1)
ebac4655
JA
541 continue;
542
543 global = !strncmp(name, "global", 6);
544
545 name[strlen(name) - 1] = '\0';
546
547 td = get_new_job(global, &def_thread);
45410acb
JA
548 if (!td) {
549 ret = 1;
550 break;
551 }
ebac4655 552
972cfd25
JA
553 /*
554 * Seperate multiple job files by a stonewall
555 */
f9481919 556 if (!global && stonewall) {
972cfd25
JA
557 td->stonewall = stonewall;
558 stonewall = 0;
559 }
560
ebac4655
JA
561 fgetpos(f, &off);
562 while ((p = fgets(string, 4096, f)) != NULL) {
563 if (is_empty_or_comment(p))
564 continue;
e1f36503 565
b6754f9d 566 strip_blank_front(&p);
7c124ac1
JA
567
568 if (p[0] == '[')
569 break;
570
4ae3f763 571 strip_blank_end(p);
aea47d44 572
e1f36503 573 fgetpos(f, &off);
ebac4655 574
45410acb
JA
575 /*
576 * Don't break here, continue parsing options so we
577 * dump all the bad ones. Makes trial/error fixups
578 * easier on the user.
579 */
214e1eca 580 ret |= fio_option_parse(td, p);
ebac4655 581 }
ebac4655 582
45410acb
JA
583 if (!ret) {
584 fsetpos(f, &off);
585 ret = add_job(td, name, 0);
b1508cf9
JA
586 } else {
587 log_err("fio: job %s dropped\n", name);
588 put_job(td);
45410acb 589 }
7c124ac1 590 } while (!ret);
ebac4655
JA
591
592 free(string);
593 free(name);
594 fclose(f);
45410acb 595 return ret;
ebac4655
JA
596}
597
598static int fill_def_thread(void)
599{
600 memset(&def_thread, 0, sizeof(def_thread));
601
602 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
603 perror("sched_getaffinity");
604 return 1;
605 }
606
607 /*
ee738499 608 * fill default options
ebac4655 609 */
214e1eca 610 fio_fill_default_options(&def_thread);
ee738499 611
972cfd25 612 def_thread.timeout = def_timeout;
ec94ec56
JA
613 def_thread.write_bw_log = write_bw_log;
614 def_thread.write_lat_log = write_lat_log;
ee738499 615
ebac4655
JA
616#ifdef FIO_HAVE_DISK_UTIL
617 def_thread.do_disk_util = 1;
618#endif
619
620 return 0;
621}
622
214e1eca
JA
623static void free_shm(void)
624{
625 struct shmid_ds sbuf;
626
627 if (threads) {
628 shmdt((void *) threads);
629 threads = NULL;
630 shmctl(shm_id, IPC_RMID, &sbuf);
631 }
632}
633
634/*
635 * The thread area is shared between the main process and the job
636 * threads/processes. So setup a shared memory segment that will hold
637 * all the job info.
638 */
639static int setup_thread_area(void)
640{
641 /*
642 * 1024 is too much on some machines, scale max_jobs if
643 * we get a failure that looks like too large a shm segment
644 */
645 do {
646 size_t size = max_jobs * sizeof(struct thread_data);
647
648 shm_id = shmget(0, size, IPC_CREAT | 0600);
649 if (shm_id != -1)
650 break;
651 if (errno != EINVAL) {
652 perror("shmget");
653 break;
654 }
655
656 max_jobs >>= 1;
657 } while (max_jobs);
658
659 if (shm_id == -1)
660 return 1;
661
662 threads = shmat(shm_id, NULL, 0);
663 if (threads == (void *) -1) {
664 perror("shmat");
665 return 1;
666 }
667
668 atexit(free_shm);
669 return 0;
670}
671
0ab8db89 672static void usage(void)
4785f995
JA
673{
674 printf("%s\n", fio_version_string);
b4692828
JA
675 printf("\t--output\tWrite output to file\n");
676 printf("\t--timeout\tRuntime in seconds\n");
677 printf("\t--latency-log\tGenerate per-job latency logs\n");
678 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
679 printf("\t--minimal\tMinimal (terse) output\n");
680 printf("\t--version\tPrint version info and exit\n");
fd28ca49
JA
681 printf("\t--help\t\tPrint this page\n");
682 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
4785f995
JA
683}
684
972cfd25 685static int parse_cmd_line(int argc, char *argv[])
ebac4655 686{
b4692828 687 struct thread_data *td = NULL;
b1ec1da6 688 int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
ebac4655 689
0be06ea2 690 while ((c = getopt_long_only(argc, argv, "", long_options, &lidx)) != -1) {
ebac4655 691 switch (c) {
b4692828
JA
692 case 't':
693 def_timeout = atoi(optarg);
694 break;
695 case 'l':
696 write_lat_log = 1;
697 break;
698 case 'w':
699 write_bw_log = 1;
700 break;
701 case 'o':
702 f_out = fopen(optarg, "w+");
703 if (!f_out) {
704 perror("fopen output");
705 exit(1);
706 }
707 f_err = f_out;
708 break;
709 case 'm':
710 terse_output = 1;
711 break;
712 case 'h':
713 usage();
714 exit(0);
fd28ca49 715 case 'c':
214e1eca 716 exit(fio_show_option_help(optarg));
b4692828
JA
717 case 'v':
718 printf("%s\n", fio_version_string);
719 exit(0);
720 case FIO_GETOPT_JOB: {
721 const char *opt = long_options[lidx].name;
722 char *val = optarg;
723
c2b1e753
JA
724 if (!strncmp(opt, "name", 4) && td) {
725 ret = add_job(td, td->name ?: "fio", 0);
726 if (ret) {
727 put_job(td);
728 return 0;
729 }
730 td = NULL;
731 }
b4692828 732 if (!td) {
38d0adb0 733 int global = !strncmp(val, "global", 6);
c2b1e753
JA
734
735 td = get_new_job(global, &def_thread);
b4692828
JA
736 if (!td)
737 return 0;
738 }
38d0adb0 739
214e1eca 740 ret = fio_cmd_option_parse(td, opt, val);
78217dfa 741 if (ret)
b1ec1da6 742 dont_add_job = 1;
b4692828
JA
743 break;
744 }
745 default:
b4692828 746 break;
ebac4655
JA
747 }
748 }
c9fad893 749
b4692828 750 if (td) {
b1ec1da6 751 if (dont_add_job)
b4692828 752 put_job(td);
b1ec1da6
JA
753 else {
754 ret = add_job(td, td->name ?: "fio", 0);
755 if (ret)
756 put_job(td);
757 }
972cfd25 758 }
774a6177 759
b4692828
JA
760 while (optind < argc) {
761 ini_idx++;
762 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
763 ini_file[ini_idx - 1] = strdup(argv[optind]);
764 optind++;
eb8bbf48 765 }
972cfd25
JA
766
767 return ini_idx;
ebac4655
JA
768}
769
b4692828 770
ebac4655
JA
771int parse_options(int argc, char *argv[])
772{
972cfd25
JA
773 int job_files, i;
774
b4692828
JA
775 f_out = stdout;
776 f_err = stderr;
777
214e1eca 778 fio_options_dup_and_init(long_options);
b4692828 779
ebac4655
JA
780 if (setup_thread_area())
781 return 1;
782 if (fill_def_thread())
783 return 1;
784
972cfd25 785 job_files = parse_cmd_line(argc, argv);
ebac4655 786
972cfd25
JA
787 for (i = 0; i < job_files; i++) {
788 if (fill_def_thread())
789 return 1;
0c7e37a0 790 if (parse_jobs_ini(ini_file[i], i))
972cfd25 791 return 1;
88c6ed80 792 free(ini_file[i]);
972cfd25 793 }
ebac4655 794
88c6ed80 795 free(ini_file);
b4692828
JA
796
797 if (!thread_number) {
798 log_err("No jobs defined(s)\n");
b4692828
JA
799 return 1;
800 }
801
ebac4655
JA
802 return 0;
803}