Fix busy looping for io_u_queued_complete()
[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
JA
11#include <getopt.h>
12#include <assert.h>
ebac4655
JA
13#include <sys/ipc.h>
14#include <sys/shm.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17
18#include "fio.h"
cb2c86fd 19#include "parse.h"
ebac4655 20
ee738499 21#define FIO_RANDSEED (0xb1899bedUL)
ebac4655 22
e1f36503
JA
23#define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
24
b4692828
JA
25static int str_rw_cb(void *, const char *);
26static int str_ioengine_cb(void *, const char *);
27static int str_mem_cb(void *, const char *);
28static int str_verify_cb(void *, const char *);
e1f36503 29static int str_lockmem_cb(void *, unsigned long *);
34cfcdaf 30#ifdef FIO_HAVE_IOPRIO
e1f36503
JA
31static int str_prio_cb(void *, unsigned int *);
32static int str_prioclass_cb(void *, unsigned int *);
34cfcdaf 33#endif
e1f36503
JA
34static int str_exitall_cb(void);
35static int str_cpumask_cb(void *, unsigned int *);
36
ee738499
JA
37#define __stringify_1(x) #x
38#define __stringify(x) __stringify_1(x)
39
e1f36503
JA
40/*
41 * Map of job/command line options
42 */
43static struct fio_option options[] = {
61697c37
JA
44 {
45 .name = "description",
46 .type = FIO_OPT_STR_STORE,
47 .off1 = td_var_offset(description),
48 .help = "Text job description",
49 },
e1f36503
JA
50 {
51 .name = "name",
52 .type = FIO_OPT_STR_STORE,
53 .off1 = td_var_offset(name),
fd28ca49 54 .help = "Name of this job",
e1f36503
JA
55 },
56 {
57 .name = "directory",
58 .type = FIO_OPT_STR_STORE,
59 .off1 = td_var_offset(directory),
fd28ca49 60 .help = "Directory to store files in",
e1f36503
JA
61 },
62 {
63 .name = "filename",
64 .type = FIO_OPT_STR_STORE,
65 .off1 = td_var_offset(filename),
fd28ca49 66 .help = "Force the use of a specific file",
e1f36503
JA
67 },
68 {
69 .name = "rw",
70 .type = FIO_OPT_STR,
71 .cb = str_rw_cb,
15f7918f 72 .help = "IO direction",
ee738499 73 .def = "read",
15f7918f
JA
74 .posval = { "read", "write", "randwrite", "randread", "rw",
75 "randrw", },
e1f36503
JA
76 },
77 {
78 .name = "ioengine",
79 .type = FIO_OPT_STR,
80 .cb = str_ioengine_cb,
15f7918f 81 .help = "IO engine to use",
ee738499 82 .def = "sync",
15f7918f 83 .posval = { "sync", "libaio", "posixaio", "mmap", "splice",
a4f4fdd7 84 "sg", "null", "net", "syslet-rw" },
e1f36503 85 },
03b74b3e
JA
86 {
87 .name = "iodepth",
88 .type = FIO_OPT_INT,
89 .off1 = td_var_offset(iodepth),
90 .help = "Amount of IO buffers to keep in flight",
91 .def = "1",
92 },
93 {
94 .name = "size",
95 .type = FIO_OPT_STR_VAL,
96 .off1 = td_var_offset(total_file_size),
97 .help = "Size of device or file",
98 },
99 {
100 .name = "bs",
101 .type = FIO_OPT_STR_VAL_INT,
102 .off1 = td_var_offset(bs[DDIR_READ]),
103 .off2 = td_var_offset(bs[DDIR_WRITE]),
104 .help = "Block size unit",
105 .def = "4k",
106 },
107 {
108 .name = "bsrange",
109 .type = FIO_OPT_RANGE,
110 .off1 = td_var_offset(min_bs[DDIR_READ]),
111 .off2 = td_var_offset(max_bs[DDIR_READ]),
112 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
113 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
114 .help = "Set block size range (in more detail than bs)",
115 },
116 {
117 .name = "bs_unaligned",
118 .type = FIO_OPT_STR_SET,
119 .off1 = td_var_offset(bs_unaligned),
120 .help = "Don't sector align IO buffer sizes",
121 },
122 {
123 .name = "offset",
124 .type = FIO_OPT_STR_VAL,
125 .off1 = td_var_offset(start_offset),
126 .help = "Start IO from this offset",
127 .def = "0",
128 },
129 {
130 .name = "randrepeat",
131 .type = FIO_OPT_BOOL,
132 .off1 = td_var_offset(rand_repeatable),
133 .help = "Use repeatable random IO pattern",
134 .def = "1",
135 },
136 {
137 .name = "norandommap",
138 .type = FIO_OPT_STR_SET,
139 .off1 = td_var_offset(norandommap),
140 .help = "Accept potential duplicate random blocks",
141 },
142 {
143 .name = "nrfiles",
144 .type = FIO_OPT_INT,
145 .off1 = td_var_offset(nr_files),
146 .help = "Split job workload between this number of files",
147 .def = "1",
148 },
149 {
150 .name = "fsync",
151 .type = FIO_OPT_INT,
152 .off1 = td_var_offset(fsync_blocks),
153 .help = "Issue fsync for writes every given number of blocks",
154 .def = "0",
155 },
156 {
157 .name = "direct",
158 .type = FIO_OPT_BOOL,
159 .off1 = td_var_offset(odirect),
76a43db4
JA
160 .help = "Use O_DIRECT IO (negates buffered)",
161 .def = "0",
162 },
163 {
164 .name = "buffered",
165 .type = FIO_OPT_BOOL,
166 .off1 = td_var_offset(odirect),
167 .neg = 1,
168 .help = "Use buffered IO (negates direct)",
03b74b3e
JA
169 .def = "1",
170 },
171 {
172 .name = "overwrite",
173 .type = FIO_OPT_BOOL,
174 .off1 = td_var_offset(overwrite),
175 .help = "When writing, set whether to overwrite current data",
176 .def = "0",
177 },
178 {
179 .name = "loops",
180 .type = FIO_OPT_INT,
181 .off1 = td_var_offset(loops),
182 .help = "Number of times to run the job",
183 .def = "1",
184 },
185 {
186 .name = "numjobs",
187 .type = FIO_OPT_INT,
188 .off1 = td_var_offset(numjobs),
189 .help = "Duplicate this job this many times",
190 .def = "1",
191 },
192 {
193 .name = "startdelay",
194 .type = FIO_OPT_INT,
195 .off1 = td_var_offset(start_delay),
196 .help = "Only start job when this period has passed",
197 .def = "0",
198 },
199 {
200 .name = "runtime",
201 .alias = "timeout",
202 .type = FIO_OPT_STR_VAL_TIME,
203 .off1 = td_var_offset(timeout),
204 .help = "Stop workload when this amount of time has passed",
205 .def = "0",
206 },
e1f36503
JA
207 {
208 .name = "mem",
209 .type = FIO_OPT_STR,
210 .cb = str_mem_cb,
15f7918f 211 .help = "Backing type for IO buffers",
ee738499 212 .def = "malloc",
15f7918f 213 .posval = { "malloc", "shm", "shmhuge", "mmap", "mmaphuge", },
e1f36503
JA
214 },
215 {
216 .name = "verify",
217 .type = FIO_OPT_STR,
218 .cb = str_verify_cb,
15f7918f 219 .help = "Verify sum function",
ee738499 220 .def = "0",
15f7918f 221 .posval = { "crc32", "md5", },
e1f36503
JA
222 },
223 {
224 .name = "write_iolog",
076efc7c
JA
225 .type = FIO_OPT_STR_STORE,
226 .off1 = td_var_offset(write_iolog_file),
fd28ca49 227 .help = "Store IO pattern to file",
e1f36503
JA
228 },
229 {
076efc7c 230 .name = "read_iolog",
e1f36503 231 .type = FIO_OPT_STR_STORE,
076efc7c 232 .off1 = td_var_offset(read_iolog_file),
fd28ca49 233 .help = "Playback IO pattern from file",
e1f36503
JA
234 },
235 {
236 .name = "exec_prerun",
237 .type = FIO_OPT_STR_STORE,
238 .off1 = td_var_offset(exec_prerun),
fd28ca49 239 .help = "Execute this file prior to running job",
e1f36503
JA
240 },
241 {
242 .name = "exec_postrun",
243 .type = FIO_OPT_STR_STORE,
244 .off1 = td_var_offset(exec_postrun),
fd28ca49 245 .help = "Execute this file after running job",
e1f36503
JA
246 },
247#ifdef FIO_HAVE_IOSCHED_SWITCH
248 {
249 .name = "ioscheduler",
250 .type = FIO_OPT_STR_STORE,
251 .off1 = td_var_offset(ioscheduler),
fd28ca49 252 .help = "Use this IO scheduler on the backing device",
e1f36503
JA
253 },
254#endif
e1f36503
JA
255 {
256 .name = "zonesize",
257 .type = FIO_OPT_STR_VAL,
258 .off1 = td_var_offset(zone_size),
fd28ca49 259 .help = "Give size of an IO zone",
ee738499 260 .def = "0",
e1f36503
JA
261 },
262 {
263 .name = "zoneskip",
264 .type = FIO_OPT_STR_VAL,
265 .off1 = td_var_offset(zone_skip),
fd28ca49 266 .help = "Space between IO zones",
ee738499 267 .def = "0",
e1f36503
JA
268 },
269 {
270 .name = "lockmem",
271 .type = FIO_OPT_STR_VAL,
272 .cb = str_lockmem_cb,
fd28ca49 273 .help = "Lock down this amount of memory",
ee738499 274 .def = "0",
e1f36503 275 },
e1f36503
JA
276 {
277 .name = "rwmixcycle",
278 .type = FIO_OPT_INT,
279 .off1 = td_var_offset(rwmixcycle),
ee738499
JA
280 .help = "Cycle period for mixed read/write workloads (msec)",
281 .def = "500",
e1f36503
JA
282 },
283 {
284 .name = "rwmixread",
285 .type = FIO_OPT_INT,
286 .off1 = td_var_offset(rwmixread),
ee738499 287 .maxval = 100,
fd28ca49 288 .help = "Percentage of mixed workload that is reads",
ee738499 289 .def = "50",
e1f36503
JA
290 },
291 {
292 .name = "rwmixwrite",
293 .type = FIO_OPT_INT,
294 .off1 = td_var_offset(rwmixwrite),
ee738499 295 .maxval = 100,
fd28ca49 296 .help = "Percentage of mixed workload that is writes",
ee738499 297 .def = "50",
e1f36503
JA
298 },
299 {
300 .name = "nice",
301 .type = FIO_OPT_INT,
302 .off1 = td_var_offset(nice),
fd28ca49 303 .help = "Set job CPU nice value",
15f7918f 304 .minval = -19,
ee738499
JA
305 .maxval = 20,
306 .def = "0",
e1f36503
JA
307 },
308#ifdef FIO_HAVE_IOPRIO
309 {
310 .name = "prio",
311 .type = FIO_OPT_INT,
312 .cb = str_prio_cb,
fd28ca49 313 .help = "Set job IO priority value",
15f7918f
JA
314 .minval = 0,
315 .maxval = 7,
e1f36503
JA
316 },
317 {
318 .name = "prioclass",
319 .type = FIO_OPT_INT,
320 .cb = str_prioclass_cb,
fd28ca49 321 .help = "Set job IO priority class",
15f7918f
JA
322 .minval = 0,
323 .maxval = 3,
e1f36503
JA
324 },
325#endif
326 {
327 .name = "thinktime",
328 .type = FIO_OPT_INT,
1304923a 329 .off1 = td_var_offset(thinktime),
5fa0f817 330 .help = "Idle time between IO buffers (usec)",
ee738499 331 .def = "0",
e1f36503 332 },
48097d5c
JA
333 {
334 .name = "thinktime_spin",
335 .type = FIO_OPT_INT,
336 .off1 = td_var_offset(thinktime_spin),
337 .help = "Start thinktime by spinning this amount (usec)",
338 .def = "0",
339 },
9c1f7434
JA
340 {
341 .name = "thinktime_blocks",
342 .type = FIO_OPT_INT,
1304923a 343 .off1 = td_var_offset(thinktime_blocks),
fd28ca49 344 .help = "IO buffer period between 'thinktime'",
ee738499 345 .def = "1",
9c1f7434 346 },
e1f36503
JA
347 {
348 .name = "rate",
349 .type = FIO_OPT_INT,
1304923a 350 .off1 = td_var_offset(rate),
fd28ca49 351 .help = "Set bandwidth rate",
e1f36503
JA
352 },
353 {
354 .name = "ratemin",
355 .type = FIO_OPT_INT,
1304923a 356 .off1 = td_var_offset(ratemin),
fd28ca49 357 .help = "The bottom limit accepted",
e1f36503
JA
358 },
359 {
360 .name = "ratecycle",
361 .type = FIO_OPT_INT,
1304923a 362 .off1 = td_var_offset(ratecycle),
6da1fa7f 363 .help = "Window average for rate limits (msec)",
ee738499 364 .def = "1000",
e1f36503 365 },
e1f36503
JA
366 {
367 .name = "invalidate",
13335ddb 368 .type = FIO_OPT_BOOL,
1304923a 369 .off1 = td_var_offset(invalidate_cache),
fd28ca49 370 .help = "Invalidate buffer/page cache prior to running job",
ee738499 371 .def = "1",
e1f36503
JA
372 },
373 {
374 .name = "sync",
13335ddb 375 .type = FIO_OPT_BOOL,
1304923a 376 .off1 = td_var_offset(sync_io),
fd28ca49 377 .help = "Use O_SYNC for buffered writes",
ee738499 378 .def = "0",
e1f36503
JA
379 },
380 {
381 .name = "bwavgtime",
382 .type = FIO_OPT_INT,
1304923a 383 .off1 = td_var_offset(bw_avg_time),
ee738499
JA
384 .help = "Time window over which to calculate bandwidth (msec)",
385 .def = "500",
e1f36503
JA
386 },
387 {
388 .name = "create_serialize",
13335ddb 389 .type = FIO_OPT_BOOL,
1304923a 390 .off1 = td_var_offset(create_serialize),
fd28ca49 391 .help = "Serialize creating of job files",
ee738499 392 .def = "1",
e1f36503
JA
393 },
394 {
395 .name = "create_fsync",
13335ddb 396 .type = FIO_OPT_BOOL,
1304923a 397 .off1 = td_var_offset(create_fsync),
fd28ca49 398 .help = "Fsync file after creation",
ee738499 399 .def = "1",
e1f36503 400 },
e1f36503
JA
401 {
402 .name = "cpuload",
403 .type = FIO_OPT_INT,
1304923a 404 .off1 = td_var_offset(cpuload),
fd28ca49 405 .help = "Use this percentage of CPU",
e1f36503
JA
406 },
407 {
408 .name = "cpuchunks",
409 .type = FIO_OPT_INT,
1304923a 410 .off1 = td_var_offset(cpucycle),
fd28ca49 411 .help = "Length of the CPU burn cycles",
e1f36503 412 },
e1f36503
JA
413#ifdef FIO_HAVE_CPU_AFFINITY
414 {
415 .name = "cpumask",
416 .type = FIO_OPT_INT,
417 .cb = str_cpumask_cb,
fd28ca49 418 .help = "CPU affinity mask",
e1f36503
JA
419 },
420#endif
421 {
422 .name = "end_fsync",
13335ddb 423 .type = FIO_OPT_BOOL,
1304923a 424 .off1 = td_var_offset(end_fsync),
fd28ca49 425 .help = "Include fsync at the end of job",
ee738499 426 .def = "0",
e1f36503
JA
427 },
428 {
429 .name = "unlink",
13335ddb 430 .type = FIO_OPT_BOOL,
e1f36503 431 .off1 = td_var_offset(unlink),
ee738499 432 .help = "Unlink created files after job has completed",
e545a6ce 433 .def = "0",
e1f36503
JA
434 },
435 {
436 .name = "exitall",
437 .type = FIO_OPT_STR_SET,
438 .cb = str_exitall_cb,
fd28ca49 439 .help = "Terminate all jobs when one exits",
e1f36503
JA
440 },
441 {
442 .name = "stonewall",
443 .type = FIO_OPT_STR_SET,
444 .off1 = td_var_offset(stonewall),
fd28ca49 445 .help = "Insert a hard barrier between this job and previous",
e1f36503
JA
446 },
447 {
448 .name = "thread",
449 .type = FIO_OPT_STR_SET,
d9bb3b80 450 .off1 = td_var_offset(use_thread),
fd28ca49 451 .help = "Use threads instead of forks",
e1f36503
JA
452 },
453 {
454 .name = "write_bw_log",
455 .type = FIO_OPT_STR_SET,
456 .off1 = td_var_offset(write_bw_log),
fd28ca49 457 .help = "Write log of bandwidth during run",
e1f36503
JA
458 },
459 {
460 .name = "write_lat_log",
461 .type = FIO_OPT_STR_SET,
462 .off1 = td_var_offset(write_lat_log),
fd28ca49 463 .help = "Write log of latency during run",
e1f36503 464 },
56bb17f2
JA
465 {
466 .name = "hugepage-size",
467 .type = FIO_OPT_STR_VAL,
468 .off1 = td_var_offset(hugepage_size),
fd28ca49 469 .help = "When using hugepages, specify size of each page",
ee738499 470 .def = __stringify(FIO_HUGE_PAGE),
56bb17f2 471 },
e1f36503
JA
472 {
473 .name = NULL,
474 },
475};
476
b4692828
JA
477#define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
478#define FIO_CMD_OPTS (16)
479#define FIO_GETOPT_JOB (0x89988998)
480
481/*
482 * Command line options. These will contain the above, plus a few
483 * extra that only pertain to fio itself and not jobs.
484 */
485static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
486 {
487 .name = "output",
488 .has_arg = required_argument,
489 .val = 'o',
490 },
491 {
492 .name = "timeout",
493 .has_arg = required_argument,
494 .val = 't',
495 },
496 {
497 .name = "latency-log",
498 .has_arg = required_argument,
499 .val = 'l',
500 },
501 {
502 .name = "bandwidth-log",
503 .has_arg = required_argument,
504 .val = 'b',
505 },
506 {
507 .name = "minimal",
508 .has_arg = optional_argument,
509 .val = 'm',
510 },
511 {
512 .name = "version",
513 .has_arg = no_argument,
514 .val = 'v',
515 },
fd28ca49
JA
516 {
517 .name = "help",
518 .has_arg = no_argument,
519 .val = 'h',
520 },
521 {
522 .name = "cmdhelp",
523 .has_arg = required_argument,
524 .val = 'c',
525 },
b4692828
JA
526 {
527 .name = NULL,
528 },
529};
530
ee738499 531static int def_timeout = 0;
972cfd25 532
5cd033bb 533static char fio_version_string[] = "fio 1.11";
ebac4655 534
972cfd25 535static char **ini_file;
ebac4655
JA
536static int max_jobs = MAX_JOBS;
537
538struct thread_data def_thread;
539struct thread_data *threads = NULL;
540
ebac4655 541int exitall_on_terminate = 0;
c6ae0a5b 542int terse_output = 0;
c04f7ec3 543unsigned long long mlock_size = 0;
eb8bbf48
JA
544FILE *f_out = NULL;
545FILE *f_err = NULL;
ebac4655 546
ee738499 547static int write_lat_log = 0;
bb3884d8 548int write_bw_log = 0;
ec94ec56 549
906c8d75
JA
550/*
551 * Return a free job structure.
552 */
ebac4655
JA
553static struct thread_data *get_new_job(int global, struct thread_data *parent)
554{
555 struct thread_data *td;
556
557 if (global)
558 return &def_thread;
559 if (thread_number >= max_jobs)
560 return NULL;
561
562 td = &threads[thread_number++];
ddaeaa5a 563 *td = *parent;
ebac4655 564
ebac4655 565 td->thread_number = thread_number;
ebac4655
JA
566 return td;
567}
568
569static void put_job(struct thread_data *td)
570{
549577a7
JA
571 if (td == &def_thread)
572 return;
573
16edf25d
JA
574 if (td->error)
575 fprintf(f_out, "fio: %s\n", td->verror);
576
ebac4655
JA
577 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
578 thread_number--;
579}
580
dad915e3
JA
581/*
582 * Lazy way of fixing up options that depend on each other. We could also
583 * define option callback handlers, but this is easier.
584 */
e1f36503
JA
585static void fixup_options(struct thread_data *td)
586{
e1f36503
JA
587 if (!td->rwmixread && td->rwmixwrite)
588 td->rwmixread = 100 - td->rwmixwrite;
dad915e3 589
076efc7c
JA
590 if (td->write_iolog_file && td->read_iolog_file) {
591 log_err("fio: read iolog overrides write_iolog\n");
592 free(td->write_iolog_file);
593 td->write_iolog_file = NULL;
594 }
16b462ae
JA
595
596 if (td->io_ops->flags & FIO_SYNCIO)
597 td->iodepth = 1;
598 else {
599 if (!td->iodepth)
600 td->iodepth = td->nr_files;
601 }
602
603 /*
604 * only really works for sequential io for now, and with 1 file
605 */
606 if (td->zone_size && !td->sequential && td->nr_files == 1)
607 td->zone_size = 0;
608
609 /*
610 * Reads can do overwrites, we always need to pre-create the file
611 */
612 if (td_read(td) || td_rw(td))
613 td->overwrite = 1;
614
a00735e6
JA
615 if (!td->min_bs[DDIR_READ])
616 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
617 if (!td->max_bs[DDIR_READ])
618 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
619 if (!td->min_bs[DDIR_WRITE])
75e6f36f 620 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
a00735e6 621 if (!td->max_bs[DDIR_WRITE])
75e6f36f 622 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
a00735e6
JA
623
624 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
625
16b462ae
JA
626 if (td_read(td) && !td_rw(td))
627 td->verify = 0;
bb8895e0
JA
628
629 if (td->norandommap && td->verify != VERIFY_NONE) {
630 log_err("fio: norandommap given, verify disabled\n");
631 td->verify = VERIFY_NONE;
632 }
690adba3
JA
633 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
634 log_err("fio: bs_unaligned may not work with raw io\n");
e0a22335
JA
635
636 /*
637 * O_DIRECT and char doesn't mix, clear that flag if necessary.
638 */
639 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
640 td->odirect = 0;
48097d5c
JA
641
642 /*
643 * thinktime_spin must be less than thinktime
644 */
645 if (td->thinktime_spin > td->thinktime)
646 td->thinktime_spin = td->thinktime;
e1f36503
JA
647}
648
f8977ee6
JA
649/*
650 * This function leaks the buffer
651 */
652static char *to_kmg(unsigned int val)
653{
654 char *buf = malloc(32);
f3502ba2 655 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
f8977ee6
JA
656 char *p = post;
657
245142ff 658 do {
f8977ee6
JA
659 if (val & 1023)
660 break;
661
662 val >>= 10;
663 p++;
245142ff 664 } while (*p);
f8977ee6
JA
665
666 snprintf(buf, 31, "%u%c", val, *p);
667 return buf;
668}
669
906c8d75
JA
670/*
671 * Adds a job to the list of things todo. Sanitizes the various options
672 * to make sure we don't have conflicts, and initializes various
673 * members of td.
674 */
75154845 675static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
ebac4655 676{
3c9b60c1
JA
677 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
678 "rw", NULL, "randrw" };
ebac4655 679 struct stat sb;
53cdc686
JA
680 int numjobs, ddir, i;
681 struct fio_file *f;
ebac4655 682
ebac4655
JA
683 /*
684 * the def_thread is just for options, it's not a real job
685 */
686 if (td == &def_thread)
687 return 0;
688
ee738499 689 assert(td->io_ops);
df64119d 690
690adba3
JA
691 if (td->odirect)
692 td->io_ops->flags |= FIO_RAWIO;
693
ebac4655 694 td->filetype = FIO_TYPE_FILE;
890df538 695 if (td->filename && !lstat(td->filename, &sb)) {
0af7b542
JA
696 if (S_ISBLK(sb.st_mode))
697 td->filetype = FIO_TYPE_BD;
698 else if (S_ISCHR(sb.st_mode))
699 td->filetype = FIO_TYPE_CHAR;
700 }
ebac4655 701
e0a22335
JA
702 fixup_options(td);
703
13f8e2d2
JA
704 if (td->filename)
705 td->nr_uniq_files = 1;
706 else
707 td->nr_uniq_files = td->nr_files;
708
709 if (td->filetype == FIO_TYPE_FILE || td->filename) {
e9c047a0 710 char tmp[PATH_MAX];
53cdc686 711 int len = 0;
e9c047a0 712
16edf25d
JA
713 if (td->directory && td->directory[0] != '\0') {
714 if (lstat(td->directory, &sb) < 0) {
715 log_err("fio: %s is not a directory\n", td->directory);
716 td_verror(td, errno);
717 return 1;
718 }
719 if (!S_ISDIR(sb.st_mode)) {
720 log_err("fio: %s is not a directory\n", td->directory);
721 return 1;
722 }
8aeebd55 723 len = sprintf(tmp, "%s/", td->directory);
16edf25d 724 }
ebac4655 725
53cdc686
JA
726 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
727
728 for_each_file(td, f, i) {
729 memset(f, 0, sizeof(*f));
730 f->fd = -1;
731
13f8e2d2
JA
732 if (td->filename)
733 sprintf(tmp + len, "%s", td->filename);
734 else
735 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
53cdc686
JA
736 f->file_name = strdup(tmp);
737 }
738 } else {
739 td->nr_files = 1;
740 td->files = malloc(sizeof(struct fio_file));
741 f = &td->files[0];
742
743 memset(f, 0, sizeof(*f));
744 f->fd = -1;
745 f->file_name = strdup(jobname);
746 }
747
748 for_each_file(td, f, i) {
749 f->file_size = td->total_file_size / td->nr_files;
750 f->file_offset = td->start_offset;
751 }
752
bbfd6b00 753 fio_sem_init(&td->mutex, 0);
ebac4655
JA
754
755 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
756 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
757 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
758
ebac4655
JA
759 if (td->stonewall && td->thread_number > 1)
760 groupid++;
761
762 td->groupid = groupid;
763
764 if (setup_rate(td))
765 goto err;
766
ec94ec56 767 if (td->write_lat_log) {
ebac4655
JA
768 setup_log(&td->slat_log);
769 setup_log(&td->clat_log);
770 }
ec94ec56 771 if (td->write_bw_log)
ebac4655
JA
772 setup_log(&td->bw_log);
773
b4692828
JA
774 if (!td->name)
775 td->name = strdup(jobname);
01452055 776
3d60d1ed 777 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
75154845 778
c6ae0a5b 779 if (!terse_output) {
b990b5c0 780 if (!job_add_num) {
2866c82d 781 if (td->io_ops->flags & FIO_CPUIO)
b990b5c0 782 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
f8977ee6
JA
783 else {
784 char *c1, *c2, *c3, *c4;
785
786 c1 = to_kmg(td->min_bs[DDIR_READ]);
787 c2 = to_kmg(td->max_bs[DDIR_READ]);
788 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
789 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
790
d56cbab0 791 fprintf(f_out, "%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth);
f8977ee6
JA
792
793 free(c1);
794 free(c2);
795 free(c3);
796 free(c4);
797 }
b990b5c0 798 } else if (job_add_num == 1)
c6ae0a5b
JA
799 fprintf(f_out, "...\n");
800 }
ebac4655
JA
801
802 /*
803 * recurse add identical jobs, clear numjobs and stonewall options
804 * as they don't apply to sub-jobs
805 */
806 numjobs = td->numjobs;
807 while (--numjobs) {
808 struct thread_data *td_new = get_new_job(0, td);
809
810 if (!td_new)
811 goto err;
812
813 td_new->numjobs = 1;
814 td_new->stonewall = 0;
75154845 815 job_add_num = numjobs - 1;
ebac4655 816
75154845 817 if (add_job(td_new, jobname, job_add_num))
ebac4655
JA
818 goto err;
819 }
820 return 0;
821err:
822 put_job(td);
823 return -1;
824}
825
906c8d75
JA
826/*
827 * Initialize the various random states we need (random io, block size ranges,
828 * read/write mix, etc).
829 */
ebac4655
JA
830int init_random_state(struct thread_data *td)
831{
a6ccc7be 832 unsigned long seeds[4];
53cdc686 833 int fd, num_maps, blocks, i;
0ab8db89 834 struct fio_file *f;
ebac4655 835
f48b467c
JA
836 if (td->io_ops->flags & FIO_CPUIO)
837 return 0;
838
1ac267bb 839 fd = open("/dev/urandom", O_RDONLY);
ebac4655
JA
840 if (fd == -1) {
841 td_verror(td, errno);
842 return 1;
843 }
844
a6ccc7be 845 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
ebac4655
JA
846 td_verror(td, EIO);
847 close(fd);
848 return 1;
849 }
850
851 close(fd);
852
6dfd46b9
JA
853 os_random_seed(seeds[0], &td->bsrange_state);
854 os_random_seed(seeds[1], &td->verify_state);
855 os_random_seed(seeds[2], &td->rwmix_state);
ebac4655
JA
856
857 if (td->sequential)
858 return 0;
859
9ebc27e1 860 if (td->rand_repeatable)
2f073b09 861 seeds[3] = FIO_RANDSEED * td->thread_number;
ebac4655 862
bb8895e0
JA
863 if (!td->norandommap) {
864 for_each_file(td, f, i) {
a4a81712 865 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
c7c280ed 866 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
bb8895e0
JA
867 f->file_map = malloc(num_maps * sizeof(long));
868 f->num_maps = num_maps;
869 memset(f->file_map, 0, num_maps * sizeof(long));
870 }
53cdc686 871 }
ebac4655 872
6dfd46b9 873 os_random_seed(seeds[3], &td->random_state);
ebac4655
JA
874 return 0;
875}
876
877static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
878{
879#ifdef FIO_HAVE_CPU_AFFINITY
880 unsigned int i;
881
882 CPU_ZERO(&cpumask);
883
884 for (i = 0; i < sizeof(int) * 8; i++) {
885 if ((1 << i) & cpu)
886 CPU_SET(i, &cpumask);
887 }
888#endif
889}
890
ebac4655
JA
891static int is_empty_or_comment(char *line)
892{
893 unsigned int i;
894
895 for (i = 0; i < strlen(line); i++) {
896 if (line[i] == ';')
897 return 1;
898 if (!isspace(line[i]) && !iscntrl(line[i]))
899 return 0;
900 }
901
902 return 1;
903}
904
b4692828 905static int str_rw_cb(void *data, const char *mem)
ebac4655 906{
cb2c86fd
JA
907 struct thread_data *td = data;
908
ebac4655
JA
909 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
910 td->ddir = DDIR_READ;
911 td->sequential = 1;
912 return 0;
913 } else if (!strncmp(mem, "randread", 8)) {
914 td->ddir = DDIR_READ;
915 td->sequential = 0;
916 return 0;
917 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
918 td->ddir = DDIR_WRITE;
919 td->sequential = 1;
920 return 0;
921 } else if (!strncmp(mem, "randwrite", 9)) {
922 td->ddir = DDIR_WRITE;
923 td->sequential = 0;
924 return 0;
3d60d1ed 925 } else if (!strncmp(mem, "rw", 2)) {
1e97cce9 926 td->ddir = DDIR_READ;
3d60d1ed
JA
927 td->iomix = 1;
928 td->sequential = 1;
929 return 0;
930 } else if (!strncmp(mem, "randrw", 6)) {
1e97cce9 931 td->ddir = DDIR_READ;
3d60d1ed
JA
932 td->iomix = 1;
933 td->sequential = 0;
934 return 0;
ebac4655
JA
935 }
936
3b70d7e5 937 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
ebac4655
JA
938 return 1;
939}
940
b4692828 941static int str_verify_cb(void *data, const char *mem)
ebac4655 942{
cb2c86fd
JA
943 struct thread_data *td = data;
944
ebac4655
JA
945 if (!strncmp(mem, "0", 1)) {
946 td->verify = VERIFY_NONE;
947 return 0;
948 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
949 td->verify = VERIFY_MD5;
950 return 0;
951 } else if (!strncmp(mem, "crc32", 5)) {
952 td->verify = VERIFY_CRC32;
953 return 0;
954 }
955
3b70d7e5 956 log_err("fio: verify types: md5, crc32\n");
ebac4655
JA
957 return 1;
958}
959
313cb206
JA
960/*
961 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
962 */
963static char *get_mmap_file(const char *str)
964{
965 char *p = strstr(str, ":");
966
967 if (!p)
968 return NULL;
969
970 p++;
971 strip_blank_front(&p);
972 strip_blank_end(p);
973 return strdup(p);
974}
975
b4692828 976static int str_mem_cb(void *data, const char *mem)
ebac4655 977{
cb2c86fd
JA
978 struct thread_data *td = data;
979
ebac4655
JA
980 if (!strncmp(mem, "malloc", 6)) {
981 td->mem_type = MEM_MALLOC;
982 return 0;
d0bdaf49
JA
983 } else if (!strncmp(mem, "mmaphuge", 8)) {
984#ifdef FIO_HAVE_HUGETLB
d0bdaf49
JA
985 /*
986 * mmaphuge must be appended with the actual file
987 */
313cb206
JA
988 td->mmapfile = get_mmap_file(mem);
989 if (!td->mmapfile) {
d0bdaf49
JA
990 log_err("fio: mmaphuge:/path/to/file\n");
991 return 1;
992 }
993
d0bdaf49
JA
994 td->mem_type = MEM_MMAPHUGE;
995 return 0;
996#else
997 log_err("fio: mmaphuge not available\n");
998 return 1;
999#endif
ebac4655 1000 } else if (!strncmp(mem, "mmap", 4)) {
313cb206
JA
1001 /*
1002 * Check if the user wants file backed memory. It's ok
1003 * if there's no file given, we'll just use anon mamp then.
1004 */
1005 td->mmapfile = get_mmap_file(mem);
ebac4655
JA
1006 td->mem_type = MEM_MMAP;
1007 return 0;
74b025b0
JA
1008 } else if (!strncmp(mem, "shmhuge", 7)) {
1009#ifdef FIO_HAVE_HUGETLB
1010 td->mem_type = MEM_SHMHUGE;
1011 return 0;
1012#else
1013 log_err("fio: shmhuge not available\n");
1014 return 1;
1015#endif
0268b8ba
JA
1016 } else if (!strncmp(mem, "shm", 3)) {
1017 td->mem_type = MEM_SHM;
1018 return 0;
ebac4655
JA
1019 }
1020
d0bdaf49 1021 log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
ebac4655
JA
1022 return 1;
1023}
1024
b4692828 1025static int str_ioengine_cb(void *data, const char *str)
ebac4655 1026{
cb2c86fd
JA
1027 struct thread_data *td = data;
1028
2866c82d
JA
1029 td->io_ops = load_ioengine(td, str);
1030 if (td->io_ops)
b990b5c0 1031 return 0;
ebac4655 1032
08aae9a0 1033 log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
5f350952 1034 log_err("fio: or specify path to dynamic ioengine module\n");
ebac4655
JA
1035 return 1;
1036}
1037
e1f36503
JA
1038static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1039{
1040 mlock_size = *val;
1041 return 0;
1042}
1043
34cfcdaf 1044#ifdef FIO_HAVE_IOPRIO
e1f36503
JA
1045static int str_prioclass_cb(void *data, unsigned int *val)
1046{
1047 struct thread_data *td = data;
1048
1049 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1050 return 0;
1051}
1052
1053static int str_prio_cb(void *data, unsigned int *val)
1054{
1055 struct thread_data *td = data;
1056
1057 td->ioprio |= *val;
1058 return 0;
1059}
34cfcdaf 1060#endif
e1f36503
JA
1061
1062static int str_exitall_cb(void)
1063{
1064 exitall_on_terminate = 1;
1065 return 0;
1066}
1067
1068static int str_cpumask_cb(void *data, unsigned int *val)
1069{
1070 struct thread_data *td = data;
1071
1072 fill_cpu_mask(td->cpumask, *val);
1073 return 0;
1074}
1075
07261983
JA
1076/*
1077 * This is our [ini] type file parser.
1078 */
1e97cce9 1079static int parse_jobs_ini(char *file, int stonewall_flag)
ebac4655 1080{
e1f36503 1081 unsigned int global;
ebac4655 1082 struct thread_data *td;
fee3bb48 1083 char *string, *name;
ebac4655
JA
1084 fpos_t off;
1085 FILE *f;
1086 char *p;
0c7e37a0 1087 int ret = 0, stonewall;
ebac4655
JA
1088
1089 f = fopen(file, "r");
1090 if (!f) {
aea47d44 1091 perror("fopen job file");
ebac4655
JA
1092 return 1;
1093 }
1094
1095 string = malloc(4096);
1096 name = malloc(256);
fee3bb48 1097 memset(name, 0, 256);
ebac4655 1098
0c7e37a0 1099 stonewall = stonewall_flag;
7c124ac1
JA
1100 do {
1101 p = fgets(string, 4095, f);
1102 if (!p)
45410acb 1103 break;
ebac4655
JA
1104 if (is_empty_or_comment(p))
1105 continue;
fee3bb48 1106 if (sscanf(p, "[%255s]", name) != 1)
ebac4655
JA
1107 continue;
1108
1109 global = !strncmp(name, "global", 6);
1110
1111 name[strlen(name) - 1] = '\0';
1112
1113 td = get_new_job(global, &def_thread);
45410acb
JA
1114 if (!td) {
1115 ret = 1;
1116 break;
1117 }
ebac4655 1118
972cfd25
JA
1119 /*
1120 * Seperate multiple job files by a stonewall
1121 */
f9481919 1122 if (!global && stonewall) {
972cfd25
JA
1123 td->stonewall = stonewall;
1124 stonewall = 0;
1125 }
1126
ebac4655
JA
1127 fgetpos(f, &off);
1128 while ((p = fgets(string, 4096, f)) != NULL) {
1129 if (is_empty_or_comment(p))
1130 continue;
e1f36503 1131
b6754f9d 1132 strip_blank_front(&p);
7c124ac1
JA
1133
1134 if (p[0] == '[')
1135 break;
1136
4ae3f763 1137 strip_blank_end(p);
aea47d44 1138
e1f36503 1139 fgetpos(f, &off);
ebac4655 1140
45410acb
JA
1141 /*
1142 * Don't break here, continue parsing options so we
1143 * dump all the bad ones. Makes trial/error fixups
1144 * easier on the user.
1145 */
7c124ac1 1146 ret |= parse_option(p, options, td);
ebac4655 1147 }
ebac4655 1148
45410acb
JA
1149 if (!ret) {
1150 fsetpos(f, &off);
1151 ret = add_job(td, name, 0);
b1508cf9
JA
1152 } else {
1153 log_err("fio: job %s dropped\n", name);
1154 put_job(td);
45410acb 1155 }
7c124ac1 1156 } while (!ret);
ebac4655
JA
1157
1158 free(string);
1159 free(name);
1160 fclose(f);
45410acb 1161 return ret;
ebac4655
JA
1162}
1163
1164static int fill_def_thread(void)
1165{
1166 memset(&def_thread, 0, sizeof(def_thread));
1167
1168 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1169 perror("sched_getaffinity");
1170 return 1;
1171 }
1172
1173 /*
ee738499 1174 * fill default options
ebac4655 1175 */
ee738499
JA
1176 fill_default_options(&def_thread, options);
1177
972cfd25 1178 def_thread.timeout = def_timeout;
ec94ec56
JA
1179 def_thread.write_bw_log = write_bw_log;
1180 def_thread.write_lat_log = write_lat_log;
ee738499 1181
ebac4655
JA
1182#ifdef FIO_HAVE_DISK_UTIL
1183 def_thread.do_disk_util = 1;
1184#endif
1185
1186 return 0;
1187}
1188
0ab8db89 1189static void usage(void)
4785f995
JA
1190{
1191 printf("%s\n", fio_version_string);
b4692828
JA
1192 printf("\t--output\tWrite output to file\n");
1193 printf("\t--timeout\tRuntime in seconds\n");
1194 printf("\t--latency-log\tGenerate per-job latency logs\n");
1195 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1196 printf("\t--minimal\tMinimal (terse) output\n");
1197 printf("\t--version\tPrint version info and exit\n");
fd28ca49
JA
1198 printf("\t--help\t\tPrint this page\n");
1199 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
4785f995
JA
1200}
1201
972cfd25 1202static int parse_cmd_line(int argc, char *argv[])
ebac4655 1203{
b4692828 1204 struct thread_data *td = NULL;
c2b1e753 1205 int c, ini_idx = 0, lidx, ret;
ebac4655 1206
b4692828 1207 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
ebac4655 1208 switch (c) {
b4692828
JA
1209 case 't':
1210 def_timeout = atoi(optarg);
1211 break;
1212 case 'l':
1213 write_lat_log = 1;
1214 break;
1215 case 'w':
1216 write_bw_log = 1;
1217 break;
1218 case 'o':
1219 f_out = fopen(optarg, "w+");
1220 if (!f_out) {
1221 perror("fopen output");
1222 exit(1);
1223 }
1224 f_err = f_out;
1225 break;
1226 case 'm':
1227 terse_output = 1;
1228 break;
1229 case 'h':
1230 usage();
1231 exit(0);
fd28ca49 1232 case 'c':
29fc6afe
JA
1233 ret = show_cmd_help(options, optarg);
1234 exit(ret);
b4692828
JA
1235 case 'v':
1236 printf("%s\n", fio_version_string);
1237 exit(0);
1238 case FIO_GETOPT_JOB: {
1239 const char *opt = long_options[lidx].name;
1240 char *val = optarg;
1241
c2b1e753
JA
1242 if (!strncmp(opt, "name", 4) && td) {
1243 ret = add_job(td, td->name ?: "fio", 0);
1244 if (ret) {
1245 put_job(td);
1246 return 0;
1247 }
1248 td = NULL;
1249 }
b4692828 1250 if (!td) {
38d0adb0 1251 int global = !strncmp(val, "global", 6);
c2b1e753
JA
1252
1253 td = get_new_job(global, &def_thread);
b4692828
JA
1254 if (!td)
1255 return 0;
1256 }
38d0adb0 1257
b1508cf9
JA
1258 ret = parse_cmd_option(opt, val, options, td);
1259 if (ret) {
1260 log_err("fio: job dropped\n");
1261 put_job(td);
1262 td = NULL;
1263 }
b4692828
JA
1264 break;
1265 }
1266 default:
b4692828 1267 break;
ebac4655
JA
1268 }
1269 }
c9fad893 1270
b4692828 1271 if (td) {
c2b1e753 1272 ret = add_job(td, td->name ?: "fio", 0);
b4692828
JA
1273 if (ret)
1274 put_job(td);
972cfd25 1275 }
774a6177 1276
b4692828
JA
1277 while (optind < argc) {
1278 ini_idx++;
1279 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1280 ini_file[ini_idx - 1] = strdup(argv[optind]);
1281 optind++;
eb8bbf48 1282 }
972cfd25
JA
1283
1284 return ini_idx;
ebac4655
JA
1285}
1286
1287static void free_shm(void)
1288{
1289 struct shmid_ds sbuf;
1290
1291 if (threads) {
2c0ecd28 1292 shmdt((void *) threads);
ebac4655
JA
1293 threads = NULL;
1294 shmctl(shm_id, IPC_RMID, &sbuf);
1295 }
1296}
1297
906c8d75
JA
1298/*
1299 * The thread area is shared between the main process and the job
1300 * threads/processes. So setup a shared memory segment that will hold
1301 * all the job info.
1302 */
ebac4655
JA
1303static int setup_thread_area(void)
1304{
1305 /*
1306 * 1024 is too much on some machines, scale max_jobs if
1307 * we get a failure that looks like too large a shm segment
1308 */
1309 do {
906c8d75 1310 size_t size = max_jobs * sizeof(struct thread_data);
ebac4655 1311
906c8d75 1312 shm_id = shmget(0, size, IPC_CREAT | 0600);
ebac4655
JA
1313 if (shm_id != -1)
1314 break;
1315 if (errno != EINVAL) {
1316 perror("shmget");
1317 break;
1318 }
1319
1320 max_jobs >>= 1;
1321 } while (max_jobs);
1322
1323 if (shm_id == -1)
1324 return 1;
1325
1326 threads = shmat(shm_id, NULL, 0);
1327 if (threads == (void *) -1) {
1328 perror("shmat");
1329 return 1;
1330 }
1331
1332 atexit(free_shm);
1333 return 0;
1334}
1335
b4692828
JA
1336/*
1337 * Copy the fio options into the long options map, so we mirror
1338 * job and cmd line options.
1339 */
1340static void dupe_job_options(void)
1341{
1342 struct fio_option *o;
1343 unsigned int i;
1344
1345 i = 0;
1346 while (long_options[i].name)
1347 i++;
1348
1349 o = &options[0];
1350 while (o->name) {
1351 long_options[i].name = o->name;
1352 long_options[i].val = FIO_GETOPT_JOB;
1353 if (o->type == FIO_OPT_STR_SET)
1354 long_options[i].has_arg = no_argument;
1355 else
1356 long_options[i].has_arg = required_argument;
1357
1358 i++;
1359 o++;
1360 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1361 }
1362}
1363
ebac4655
JA
1364int parse_options(int argc, char *argv[])
1365{
972cfd25
JA
1366 int job_files, i;
1367
b4692828
JA
1368 f_out = stdout;
1369 f_err = stderr;
1370
13335ddb
JA
1371 options_init(options);
1372
b4692828
JA
1373 dupe_job_options();
1374
ebac4655
JA
1375 if (setup_thread_area())
1376 return 1;
1377 if (fill_def_thread())
1378 return 1;
1379
972cfd25 1380 job_files = parse_cmd_line(argc, argv);
ebac4655 1381
972cfd25
JA
1382 for (i = 0; i < job_files; i++) {
1383 if (fill_def_thread())
1384 return 1;
0c7e37a0 1385 if (parse_jobs_ini(ini_file[i], i))
972cfd25 1386 return 1;
88c6ed80 1387 free(ini_file[i]);
972cfd25 1388 }
ebac4655 1389
88c6ed80 1390 free(ini_file);
b4692828
JA
1391
1392 if (!thread_number) {
1393 log_err("No jobs defined(s)\n");
b4692828
JA
1394 return 1;
1395 }
1396
ebac4655
JA
1397 return 0;
1398}