init.c revision 80be24f4671164d597463e4b5c794d4cbd0a4537
1906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
2cb2c86fdf03241fee32fd2e2caff43af1022403cJens Axboe * This file contains job initialization and setup functions.
3906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
4ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <stdio.h>
5ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <stdlib.h>
6ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <unistd.h>
7ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <fcntl.h>
8ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <ctype.h>
9ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <string.h>
10ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <errno.h>
11b46928282e0a890f49250e79b81af773a2b7108fJens Axboe#include <getopt.h>
12b46928282e0a890f49250e79b81af773a2b7108fJens Axboe#include <assert.h>
13ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/ipc.h>
14ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/shm.h>
15ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/types.h>
16ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/stat.h>
17ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
18ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "fio.h"
19cb2c86fdf03241fee32fd2e2caff43af1022403cJens Axboe#include "parse.h"
20ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
21ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe#define FIO_RANDSEED		(0xb1899bedUL)
22ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
23e1f365035a952233463d85d659bd960ba78f012eJens Axboe#define td_var_offset(var)	((size_t) &((struct thread_data *)0)->var)
24e1f365035a952233463d85d659bd960ba78f012eJens Axboe
25b46928282e0a890f49250e79b81af773a2b7108fJens Axboestatic int str_mem_cb(void *, const char *);
26e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_lockmem_cb(void *, unsigned long *);
2734cfcdafa994a0a75120e498c51eda08bde5df72Jens Axboe#ifdef FIO_HAVE_IOPRIO
28e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_prio_cb(void *, unsigned int *);
29e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_prioclass_cb(void *, unsigned int *);
3034cfcdafa994a0a75120e498c51eda08bde5df72Jens Axboe#endif
31e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_exitall_cb(void);
32e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_cpumask_cb(void *, unsigned int *);
33e1f365035a952233463d85d659bd960ba78f012eJens Axboe
34ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe#define __stringify_1(x)	#x
35ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe#define __stringify(x)		__stringify_1(x)
36ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe
37e1f365035a952233463d85d659bd960ba78f012eJens Axboe/*
38e1f365035a952233463d85d659bd960ba78f012eJens Axboe * Map of job/command line options
39e1f365035a952233463d85d659bd960ba78f012eJens Axboe */
40e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic struct fio_option options[] = {
41e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
4261697c37566a211ad3fd70f46397d9b7675b0fc2Jens Axboe		.name	= "description",
4361697c37566a211ad3fd70f46397d9b7675b0fc2Jens Axboe		.type	= FIO_OPT_STR_STORE,
4461697c37566a211ad3fd70f46397d9b7675b0fc2Jens Axboe		.off1	= td_var_offset(description),
4561697c37566a211ad3fd70f46397d9b7675b0fc2Jens Axboe		.help	= "Text job description",
4661697c37566a211ad3fd70f46397d9b7675b0fc2Jens Axboe	},
4761697c37566a211ad3fd70f46397d9b7675b0fc2Jens Axboe	{
48e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "name",
49e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
50e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(name),
51fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Name of this job",
52e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
53e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
54e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "directory",
55e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
56e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(directory),
57fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Directory to store files in",
58e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
59e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
60e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "filename",
61e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
62e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(filename),
63fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Force the use of a specific file",
64e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
65e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
66e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "rw",
67e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR,
68b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.off1	= td_var_offset(td_ddir),
6915f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.help	= "IO direction",
70ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "read",
71b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.posval = {
72b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "read", .oval = TD_DDIR_READ },
73b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "write", .oval = TD_DDIR_WRITE },
74b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "randread", .oval = TD_DDIR_RANDREAD },
75b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE },
76b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "rw", .oval = TD_DDIR_RW },
77b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "randrw", .oval = TD_DDIR_RANDRW },
78b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  },
79e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
80e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
81e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "ioengine",
8209629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		.type	= FIO_OPT_STR_STORE,
8309629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		.off1	= td_var_offset(ioengine),
8415f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.help	= "IO engine to use",
85ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "sync",
86b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.posval	= {
8710cad1aa7af1c47be6655cff0438c46843964294Jens Axboe			  { .ival = "sync", },
8810cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#ifdef FIO_HAVE_LIBAIO
8910cad1aa7af1c47be6655cff0438c46843964294Jens Axboe			  { .ival = "libaio", },
9010cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#endif
9110cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#ifdef FIO_HAVE_POSIXAIO
9210cad1aa7af1c47be6655cff0438c46843964294Jens Axboe			  { .ival = "posixaio", },
9310cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#endif
9410cad1aa7af1c47be6655cff0438c46843964294Jens Axboe			  { .ival = "mmap", },
9510cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#ifdef FIO_HAVE_SPLICE
9610cad1aa7af1c47be6655cff0438c46843964294Jens Axboe			  { .ival = "splice", },
9710cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#endif
9810cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#ifdef FIO_HAVE_SGIO
9910cad1aa7af1c47be6655cff0438c46843964294Jens Axboe			  { .ival = "sg", },
10010cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#endif
101b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "null", }, { .ival = "net", },
10210cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#ifdef FIO_HAVE_SYSLET
103b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "syslet-rw", },
10410cad1aa7af1c47be6655cff0438c46843964294Jens Axboe#endif
105ba0fbe1029bae1de08d66a72b6d0b2505c67c438Jens Axboe			  { .ival = "cpuio", },
1067b395ca5d5f38d50f0c9d4c11fb2b51760caf119Joel Becker			  { .ival = "external", },
107b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  },
108e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
109e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
11003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "iodepth",
11103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_INT,
11203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(iodepth),
11303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Amount of IO buffers to keep in flight",
11403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "1",
11503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
11603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
117cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe		.name	= "iodepth_batch",
118cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe		.type	= FIO_OPT_INT,
119cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe		.off1	= td_var_offset(iodepth_batch),
120cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe		.help	= "Number of IO to submit in one go",
121cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	},
122cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	{
123e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe		.name	= "iodepth_low",
124e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe		.type	= FIO_OPT_INT,
125e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe		.off1	= td_var_offset(iodepth_low),
126e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe		.help	= "Low water mark for queuing depth",
127e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	},
128e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	{
12903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "size",
13003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_STR_VAL,
13103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(total_file_size),
13203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Size of device or file",
13303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
13403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
13503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "bs",
13603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_STR_VAL_INT,
13703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(bs[DDIR_READ]),
13803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off2	= td_var_offset(bs[DDIR_WRITE]),
13903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Block size unit",
14003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "4k",
14103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
14203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
14303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "bsrange",
14403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_RANGE,
14503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(min_bs[DDIR_READ]),
14603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off2	= td_var_offset(max_bs[DDIR_READ]),
14703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off3	= td_var_offset(min_bs[DDIR_WRITE]),
14803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off4	= td_var_offset(max_bs[DDIR_WRITE]),
14903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Set block size range (in more detail than bs)",
15003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
15103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
15203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "bs_unaligned",
15303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_STR_SET,
15403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(bs_unaligned),
15503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Don't sector align IO buffer sizes",
15603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
15703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
15803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "offset",
15903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_STR_VAL,
16003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(start_offset),
16103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Start IO from this offset",
16203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "0",
16303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
16403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
16503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "randrepeat",
16603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_BOOL,
16703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(rand_repeatable),
16803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Use repeatable random IO pattern",
16903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "1",
17003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
17103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
17203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "norandommap",
17303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_STR_SET,
17403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(norandommap),
17503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Accept potential duplicate random blocks",
17603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
17703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
17803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "nrfiles",
17903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_INT,
18003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(nr_files),
18103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Split job workload between this number of files",
18203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "1",
18303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
18403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
185b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		.name	= "openfiles",
186b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		.type	= FIO_OPT_INT,
187b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		.off1	= td_var_offset(open_files),
188b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		.help	= "Number of files to keep open at the same time",
189b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe	},
190b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe	{
1910aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe		.name	= "file_service_type",
1920aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe		.type	= FIO_OPT_STR,
193b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.off1	= td_var_offset(file_service_type),
1940aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe		.help	= "How to select which file to service next",
1950aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe		.def	= "roundrobin",
196b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.posval	= {
197b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "random", .oval = FIO_FSERVICE_RANDOM },
198b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "roundrobin", .oval = FIO_FSERVICE_RR },
199b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  },
2000aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe	},
2010aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe	{
20203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "fsync",
20303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_INT,
20403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(fsync_blocks),
20503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Issue fsync for writes every given number of blocks",
20603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "0",
20703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
20803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
20903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "direct",
21003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_BOOL,
21103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(odirect),
21276a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.help	= "Use O_DIRECT IO (negates buffered)",
21376a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.def	= "0",
21476a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe	},
21576a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe	{
21676a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.name	= "buffered",
21776a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.type	= FIO_OPT_BOOL,
21876a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.off1	= td_var_offset(odirect),
21976a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.neg	= 1,
22076a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe		.help	= "Use buffered IO (negates direct)",
22103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "1",
22203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
22303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
22403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "overwrite",
22503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_BOOL,
22603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(overwrite),
22703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "When writing, set whether to overwrite current data",
22803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "0",
22903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
23003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
23103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "loops",
23203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_INT,
23303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(loops),
23403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Number of times to run the job",
23503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "1",
23603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
23703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
23803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "numjobs",
23903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_INT,
24003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(numjobs),
24103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Duplicate this job this many times",
24203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "1",
24303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
24403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
24503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "startdelay",
24603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_INT,
24703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(start_delay),
24803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Only start job when this period has passed",
24903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "0",
25003b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
25103b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
25203b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.name	= "runtime",
25303b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.alias	= "timeout",
25403b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.type	= FIO_OPT_STR_VAL_TIME,
25503b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.off1	= td_var_offset(timeout),
25603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.help	= "Stop workload when this amount of time has passed",
25703b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe		.def	= "0",
25803b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	},
25903b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe	{
260e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "mem",
261e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR,
262e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.cb	= str_mem_cb,
263b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.off1	= td_var_offset(mem_type),
26415f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.help	= "Backing type for IO buffers",
265ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "malloc",
266b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.posval	= {
267b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "malloc", .oval = MEM_MALLOC },
268b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "shm", .oval = MEM_SHM },
269b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe#ifdef FIO_HAVE_HUGETLB
270b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "shmhuge", .oval = MEM_SHMHUGE },
271b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe#endif
272b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "mmap", .oval = MEM_MMAP },
273b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe#ifdef FIO_HAVE_HUGETLB
274b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "mmaphuge", .oval = MEM_MMAPHUGE },
275b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe#endif
276b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  },
277e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
278e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
279e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "verify",
280e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR,
281b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.off1	= td_var_offset(verify),
28215f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.help	= "Verify sum function",
283ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
284b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		.posval = {
285b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "0", .oval = VERIFY_NONE },
286b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "crc32", .oval = VERIFY_CRC32 },
287b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  { .ival = "md5", .oval = VERIFY_MD5 },
288b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			  },
289e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
290e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
291e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "write_iolog",
292076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		.type	= FIO_OPT_STR_STORE,
293076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		.off1	= td_var_offset(write_iolog_file),
294fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Store IO pattern to file",
295e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
296e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
297076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		.name	= "read_iolog",
298e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
299076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		.off1	= td_var_offset(read_iolog_file),
300fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Playback IO pattern from file",
301e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
302e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
303e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "exec_prerun",
304e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
305e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(exec_prerun),
306fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Execute this file prior to running job",
307e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
308e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
309e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "exec_postrun",
310e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
311e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(exec_postrun),
312fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Execute this file after running job",
313e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
314e1f365035a952233463d85d659bd960ba78f012eJens Axboe#ifdef FIO_HAVE_IOSCHED_SWITCH
315e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
316e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "ioscheduler",
317e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_STORE,
318e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(ioscheduler),
319fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Use this IO scheduler on the backing device",
320e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
321e1f365035a952233463d85d659bd960ba78f012eJens Axboe#endif
322e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
323e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "zonesize",
324e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_VAL,
325e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(zone_size),
326fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Give size of an IO zone",
327ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
328e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
329e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
330e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "zoneskip",
331e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_VAL,
332e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(zone_skip),
333fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Space between IO zones",
334ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
335e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
336e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
337e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "lockmem",
338e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_VAL,
339e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.cb	= str_lockmem_cb,
340fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Lock down this amount of memory",
341ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
342e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
343e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
344e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "rwmixcycle",
345e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
346e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(rwmixcycle),
347ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.help	= "Cycle period for mixed read/write workloads (msec)",
348ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "500",
349e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
350e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
351e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "rwmixread",
352e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
353e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(rwmixread),
354ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.maxval	= 100,
355fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Percentage of mixed workload that is reads",
356ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "50",
357e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
358e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
359e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "rwmixwrite",
360e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
361e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(rwmixwrite),
362ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.maxval	= 100,
363fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Percentage of mixed workload that is writes",
364ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "50",
365e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
366e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
367e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "nice",
368e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
369e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(nice),
370fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Set job CPU nice value",
37115f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.minval	= -19,
372ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.maxval	= 20,
373ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
374e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
375e1f365035a952233463d85d659bd960ba78f012eJens Axboe#ifdef FIO_HAVE_IOPRIO
376e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
377e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "prio",
378e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
379e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.cb	= str_prio_cb,
380fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Set job IO priority value",
38115f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.minval	= 0,
38215f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.maxval	= 7,
383e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
384e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
385e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "prioclass",
386e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
387e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.cb	= str_prioclass_cb,
388fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Set job IO priority class",
38915f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.minval	= 0,
39015f7918ff432d5da2b2abc84a50c685bde5e72efJens Axboe		.maxval	= 3,
391e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
392e1f365035a952233463d85d659bd960ba78f012eJens Axboe#endif
393e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
394e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "thinktime",
395e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
3961304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(thinktime),
3975fa0f817d41211f45c04809dfe6c324f916fbcb4Jens Axboe		.help	= "Idle time between IO buffers (usec)",
398ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
399e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
400e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
40148097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe		.name	= "thinktime_spin",
40248097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe		.type	= FIO_OPT_INT,
40348097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe		.off1	= td_var_offset(thinktime_spin),
40434403fb14ba48d708fdfd2934583506bb5caac05Jens Axboe		.help	= "Start think time by spinning this amount (usec)",
40548097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe		.def	= "0",
40648097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	},
40748097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	{
4089c1f7434526606fc8a4296190a2dea5de2651266Jens Axboe		.name	= "thinktime_blocks",
4099c1f7434526606fc8a4296190a2dea5de2651266Jens Axboe		.type	= FIO_OPT_INT,
4101304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(thinktime_blocks),
411fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "IO buffer period between 'thinktime'",
412ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "1",
4139c1f7434526606fc8a4296190a2dea5de2651266Jens Axboe	},
4149c1f7434526606fc8a4296190a2dea5de2651266Jens Axboe	{
415e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "rate",
416e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
4171304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(rate),
418fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Set bandwidth rate",
419e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
420e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
421e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "ratemin",
422e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
4231304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(ratemin),
424fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "The bottom limit accepted",
425e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
426e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
427e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "ratecycle",
428e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
4291304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(ratecycle),
4306da1fa7f0a8d7e588dc0ea40a5e175edded9a8acJens Axboe		.help	= "Window average for rate limits (msec)",
431ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "1000",
432e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
433e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
434e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "invalidate",
43513335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe		.type	= FIO_OPT_BOOL,
4361304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(invalidate_cache),
437fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Invalidate buffer/page cache prior to running job",
438ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "1",
439e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
440e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
441e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "sync",
44213335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe		.type	= FIO_OPT_BOOL,
4431304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(sync_io),
444fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Use O_SYNC for buffered writes",
445ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
446e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
447e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
448e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "bwavgtime",
449e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
4501304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(bw_avg_time),
451ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.help	= "Time window over which to calculate bandwidth (msec)",
452ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "500",
453e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
454e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
455e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "create_serialize",
45613335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe		.type	= FIO_OPT_BOOL,
4571304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(create_serialize),
458fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Serialize creating of job files",
459ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "1",
460e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
461e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
462e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "create_fsync",
46313335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe		.type	= FIO_OPT_BOOL,
4641304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(create_fsync),
465fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Fsync file after creation",
466ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "1",
467e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
468e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
469e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "cpuload",
470e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
4711304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(cpuload),
472fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Use this percentage of CPU",
473e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
474e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
475e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "cpuchunks",
476e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
4771304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(cpucycle),
478ba0fbe1029bae1de08d66a72b6d0b2505c67c438Jens Axboe		.help	= "Length of the CPU burn cycles (usecs)",
479ba0fbe1029bae1de08d66a72b6d0b2505c67c438Jens Axboe		.def	= "50000",
480e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
481e1f365035a952233463d85d659bd960ba78f012eJens Axboe#ifdef FIO_HAVE_CPU_AFFINITY
482e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
483e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "cpumask",
484e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_INT,
485e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.cb	= str_cpumask_cb,
486fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "CPU affinity mask",
487e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
488e1f365035a952233463d85d659bd960ba78f012eJens Axboe#endif
489e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
490e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "end_fsync",
49113335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe		.type	= FIO_OPT_BOOL,
4921304923a76e2e7f8c283240b3c6eb13ddd71db7aJens Axboe		.off1	= td_var_offset(end_fsync),
493fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Include fsync at the end of job",
494ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= "0",
495e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
496e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
497e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "unlink",
49813335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe		.type	= FIO_OPT_BOOL,
499e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(unlink),
500ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.help	= "Unlink created files after job has completed",
501e545a6ce0f0f3e6881e997bf2af8969fc6dd7082Jens Axboe		.def	= "0",
502e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
503e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
504e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "exitall",
505e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_SET,
506e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.cb	= str_exitall_cb,
507fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Terminate all jobs when one exits",
508e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
509e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
510e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "stonewall",
511e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_SET,
512e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(stonewall),
513fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Insert a hard barrier between this job and previous",
514e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
515e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
516e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "thread",
517e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_SET,
518d9bb3b809d80cc3226d1c603e87fc90b6680320bJens Axboe		.off1	= td_var_offset(use_thread),
519fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Use threads instead of forks",
520e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
521e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
522e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "write_bw_log",
523e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_SET,
524e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(write_bw_log),
525fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Write log of bandwidth during run",
526e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
527e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
528e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name	= "write_lat_log",
529e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.type	= FIO_OPT_STR_SET,
530e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.off1	= td_var_offset(write_lat_log),
531fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "Write log of latency during run",
532e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
533e1f365035a952233463d85d659bd960ba78f012eJens Axboe	{
53456bb17f297c50b2832c845b0f6cdde5063748b34Jens Axboe		.name	= "hugepage-size",
53556bb17f297c50b2832c845b0f6cdde5063748b34Jens Axboe		.type	= FIO_OPT_STR_VAL,
53656bb17f297c50b2832c845b0f6cdde5063748b34Jens Axboe		.off1	= td_var_offset(hugepage_size),
537fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.help	= "When using hugepages, specify size of each page",
538ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe		.def	= __stringify(FIO_HUGE_PAGE),
53956bb17f297c50b2832c845b0f6cdde5063748b34Jens Axboe	},
54056bb17f297c50b2832c845b0f6cdde5063748b34Jens Axboe	{
541b2560f3ca4677e2908fc4111f4d04fae5df3b229Jens Axboe		.name	= "group_reporting",
542b2560f3ca4677e2908fc4111f4d04fae5df3b229Jens Axboe		.type	= FIO_OPT_STR_SET,
543b2560f3ca4677e2908fc4111f4d04fae5df3b229Jens Axboe		.off1	= td_var_offset(group_reporting),
544b2560f3ca4677e2908fc4111f4d04fae5df3b229Jens Axboe		.help	= "Do reporting on a per-group basis",
545b2560f3ca4677e2908fc4111f4d04fae5df3b229Jens Axboe	},
546b2560f3ca4677e2908fc4111f4d04fae5df3b229Jens Axboe	{
547e1f365035a952233463d85d659bd960ba78f012eJens Axboe		.name = NULL,
548e1f365035a952233463d85d659bd960ba78f012eJens Axboe	},
549e1f365035a952233463d85d659bd960ba78f012eJens Axboe};
550e1f365035a952233463d85d659bd960ba78f012eJens Axboe
551b46928282e0a890f49250e79b81af773a2b7108fJens Axboe#define FIO_JOB_OPTS	(sizeof(options) / sizeof(struct fio_option))
552b46928282e0a890f49250e79b81af773a2b7108fJens Axboe#define FIO_CMD_OPTS	(16)
553b46928282e0a890f49250e79b81af773a2b7108fJens Axboe#define FIO_GETOPT_JOB	(0x89988998)
554b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
555b46928282e0a890f49250e79b81af773a2b7108fJens Axboe/*
556b46928282e0a890f49250e79b81af773a2b7108fJens Axboe * Command line options. These will contain the above, plus a few
557b46928282e0a890f49250e79b81af773a2b7108fJens Axboe * extra that only pertain to fio itself and not jobs.
558b46928282e0a890f49250e79b81af773a2b7108fJens Axboe */
559b46928282e0a890f49250e79b81af773a2b7108fJens Axboestatic struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
560b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
561b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= "output",
562b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
563b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'o',
564b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
565b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
566b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= "timeout",
567b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
568b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 't',
569b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
570b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
571b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= "latency-log",
572b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
573b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'l',
574b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
575b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
576b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= "bandwidth-log",
577b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
578b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'b',
579b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
580b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
581b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= "minimal",
582b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= optional_argument,
583b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'm',
584b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
585b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
586b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= "version",
587b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= no_argument,
588b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'v',
589b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
590b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
591fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.name		= "help",
592fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.has_arg	= no_argument,
593fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.val		= 'h',
594fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	},
595fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	{
596fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.name		= "cmdhelp",
597320beefe2d0c5f05f24b4e0c1d13fcb2f1286a78Jens Axboe		.has_arg	= optional_argument,
598fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.val		= 'c',
599fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	},
600fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	{
601b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= NULL,
602b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
603b46928282e0a890f49250e79b81af773a2b7108fJens Axboe};
604b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
605ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboestatic int def_timeout = 0;
606972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
607fdf3de27417d9a673466041851266ffb5c88cab8Jens Axboestatic char fio_version_string[] = "fio 1.13";
608ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
609972cfd2546081c0397447ca9243ea419b1ff579aJens Axboestatic char **ini_file;
610ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int max_jobs = MAX_JOBS;
611ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
612ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestruct thread_data def_thread;
613ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestruct thread_data *threads = NULL;
614ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
615ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint exitall_on_terminate = 0;
616c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboeint terse_output = 0;
617c04f7ec3ecb8ce780bde6ad3515f003e6015c62aJens Axboeunsigned long long mlock_size = 0;
618eb8bbf48e79a8c6afd3c84e3d64263d10ee45daaJens AxboeFILE *f_out = NULL;
619eb8bbf48e79a8c6afd3c84e3d64263d10ee45daaJens AxboeFILE *f_err = NULL;
620ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
621ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboestatic int write_lat_log = 0;
622bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboeint write_bw_log = 0;
623ec94ec567cae47f91fa31a18250c2a7a0029d2adJens Axboe
6249728ce37ea4348d4bdb2eefbaafee75ad651758cJoel BeckerFILE *get_f_out()
6259728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker{
6269728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker	return f_out;
6279728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker}
6289728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker
6299728ce37ea4348d4bdb2eefbaafee75ad651758cJoel BeckerFILE *get_f_err()
6309728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker{
6319728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker	return f_err;
6329728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker}
6339728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker
634906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
635906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * Return a free job structure.
636906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
637ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic struct thread_data *get_new_job(int global, struct thread_data *parent)
638ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
639ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct thread_data *td;
640ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
641ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (global)
642ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return &def_thread;
643ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (thread_number >= max_jobs)
644ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return NULL;
645ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
646ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td = &threads[thread_number++];
647ddaeaa5ab1e3f1cb6f35a9f4a18ee932151a0ab8Jens Axboe	*td = *parent;
648ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
649ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->thread_number = thread_number;
650ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return td;
651ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
652ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
653ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void put_job(struct thread_data *td)
654ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
655549577a728fc3bacbfea8978c4f514cef5b073dcJens Axboe	if (td == &def_thread)
656549577a728fc3bacbfea8978c4f514cef5b073dcJens Axboe		return;
657549577a728fc3bacbfea8978c4f514cef5b073dcJens Axboe
65816edf25dba269ee9e8239130e75b690440b1e120Jens Axboe	if (td->error)
65916edf25dba269ee9e8239130e75b690440b1e120Jens Axboe		fprintf(f_out, "fio: %s\n", td->verror);
66016edf25dba269ee9e8239130e75b690440b1e120Jens Axboe
661ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(&threads[td->thread_number - 1], 0, sizeof(*td));
662ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	thread_number--;
663ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
664ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
665dad915e36819e74c4540db19faae488ede963ee4Jens Axboe/*
666dad915e36819e74c4540db19faae488ede963ee4Jens Axboe * Lazy way of fixing up options that depend on each other. We could also
667dad915e36819e74c4540db19faae488ede963ee4Jens Axboe * define option callback handlers, but this is easier.
668dad915e36819e74c4540db19faae488ede963ee4Jens Axboe */
669e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic void fixup_options(struct thread_data *td)
670e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
671e1f365035a952233463d85d659bd960ba78f012eJens Axboe	if (!td->rwmixread && td->rwmixwrite)
672e1f365035a952233463d85d659bd960ba78f012eJens Axboe		td->rwmixread = 100 - td->rwmixwrite;
673dad915e36819e74c4540db19faae488ede963ee4Jens Axboe
674076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe	if (td->write_iolog_file && td->read_iolog_file) {
675076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		log_err("fio: read iolog overrides write_iolog\n");
676076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		free(td->write_iolog_file);
677076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		td->write_iolog_file = NULL;
678076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe	}
67916b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
68016b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	if (td->io_ops->flags & FIO_SYNCIO)
68116b462aeb47996111ee6aa516c9226708db7c248Jens Axboe		td->iodepth = 1;
68216b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	else {
68316b462aeb47996111ee6aa516c9226708db7c248Jens Axboe		if (!td->iodepth)
684b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe			td->iodepth = td->open_files;
68516b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	}
68616b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
68716b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	/*
68816b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 * only really works for sequential io for now, and with 1 file
68916b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 */
690b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe	if (td->zone_size && td_random(td) && td->open_files == 1)
69116b462aeb47996111ee6aa516c9226708db7c248Jens Axboe		td->zone_size = 0;
69216b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
69316b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	/*
69416b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 * Reads can do overwrites, we always need to pre-create the file
69516b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 */
69616b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	if (td_read(td) || td_rw(td))
69716b462aeb47996111ee6aa516c9226708db7c248Jens Axboe		td->overwrite = 1;
69816b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
699a00735e66f9ec42549da94eba3170e543b542904Jens Axboe	if (!td->min_bs[DDIR_READ])
700a00735e66f9ec42549da94eba3170e543b542904Jens Axboe		td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
701a00735e66f9ec42549da94eba3170e543b542904Jens Axboe	if (!td->max_bs[DDIR_READ])
702a00735e66f9ec42549da94eba3170e543b542904Jens Axboe		td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
703a00735e66f9ec42549da94eba3170e543b542904Jens Axboe	if (!td->min_bs[DDIR_WRITE])
70475e6f36fae06978f29296fce76a7f00ca0df7b56Jens Axboe		td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
705a00735e66f9ec42549da94eba3170e543b542904Jens Axboe	if (!td->max_bs[DDIR_WRITE])
70675e6f36fae06978f29296fce76a7f00ca0df7b56Jens Axboe		td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
707a00735e66f9ec42549da94eba3170e543b542904Jens Axboe
708a00735e66f9ec42549da94eba3170e543b542904Jens Axboe	td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
709a00735e66f9ec42549da94eba3170e543b542904Jens Axboe
71016b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	if (td_read(td) && !td_rw(td))
71116b462aeb47996111ee6aa516c9226708db7c248Jens Axboe		td->verify = 0;
712bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe
713bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe	if (td->norandommap && td->verify != VERIFY_NONE) {
714bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe		log_err("fio: norandommap given, verify disabled\n");
715bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe		td->verify = VERIFY_NONE;
716bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe	}
717690adba373bb8c97a365c67da369e265953c4b4cJens Axboe	if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
718690adba373bb8c97a365c67da369e265953c4b4cJens Axboe		log_err("fio: bs_unaligned may not work with raw io\n");
719e0a223354342cc45a916b669343718b80a20c2eaJens Axboe
720e0a223354342cc45a916b669343718b80a20c2eaJens Axboe	/*
721e0a223354342cc45a916b669343718b80a20c2eaJens Axboe	 * O_DIRECT and char doesn't mix, clear that flag if necessary.
722e0a223354342cc45a916b669343718b80a20c2eaJens Axboe	 */
723e0a223354342cc45a916b669343718b80a20c2eaJens Axboe	if (td->filetype == FIO_TYPE_CHAR && td->odirect)
724e0a223354342cc45a916b669343718b80a20c2eaJens Axboe		td->odirect = 0;
72548097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe
72648097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	/*
72748097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	 * thinktime_spin must be less than thinktime
72848097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	 */
72948097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	if (td->thinktime_spin > td->thinktime)
73048097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe		td->thinktime_spin = td->thinktime;
731e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe
732e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	/*
733e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	 * The low water mark cannot be bigger than the iodepth
734e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	 */
7359467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe	if (td->iodepth_low > td->iodepth || !td->iodepth_low) {
7369467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		/*
7379467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 * syslet work around - if the workload is sequential,
7389467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 * we want to let the queue drain all the way down to
7399467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 * avoid seeking between async threads
7409467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 */
7419467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
7429467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe			td->iodepth_low = 1;
7439467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		else
7449467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe			td->iodepth_low = td->iodepth;
7459467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe	}
746cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe
747cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	/*
748cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	 * If batch number isn't set, default to the same as iodepth
749cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	 */
750cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	if (td->iodepth_batch > td->iodepth || !td->iodepth_batch)
751cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe		td->iodepth_batch = td->iodepth;
752b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe
753b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe	if (td->open_files > td->nr_files || !td->open_files)
754b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		td->open_files = td->nr_files;
755e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
756e1f365035a952233463d85d659bd960ba78f012eJens Axboe
757906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
758f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe * This function leaks the buffer
759f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe */
760f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboestatic char *to_kmg(unsigned int val)
761f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe{
762f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	char *buf = malloc(32);
763f3502ba2dd72d846a388c774a01c6bb833871248Jens Axboe	char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
764f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	char *p = post;
765f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
766245142ff7554290cf666e3ef6b7b57512bf17d75Jens Axboe	do {
767f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe		if (val & 1023)
768f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe			break;
769f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
770f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe		val >>= 10;
771f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe		p++;
772245142ff7554290cf666e3ef6b7b57512bf17d75Jens Axboe	} while (*p);
773f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
774f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	snprintf(buf, 31, "%u%c", val, *p);
775f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	return buf;
776f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe}
777f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
77809629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe/* External engines are specified by "external:name.o") */
77909629a90d5b68b220e3fb98318e2dcd019943edaJens Axboestatic const char *get_engine_name(const char *str)
78009629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe{
78109629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	char *p = strstr(str, ":");
78209629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe
78309629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	if (!p)
78409629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		return str;
78509629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe
78609629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	p++;
78709629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	strip_blank_front(&p);
78809629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	strip_blank_end(p);
78909629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	return p;
79009629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe}
79109629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe
792f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe/*
793906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * Adds a job to the list of things todo. Sanitizes the various options
794906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * to make sure we don't have conflicts, and initializes various
795906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * members of td.
796906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
797751548451d969148529b642c05e7544726ec3b64Jens Axboestatic int add_job(struct thread_data *td, const char *jobname, int job_add_num)
798ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
799413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe	const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
800413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe				   "randread", "randwrite", "randrw" };
801ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct stat sb;
802413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe	int numjobs, i;
80353cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	struct fio_file *f;
80409629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	const char *engine;
805ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
806ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
807ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * the def_thread is just for options, it's not a real job
808ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
809ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td == &def_thread)
810ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
811ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
81209629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	engine = get_engine_name(td->ioengine);
81309629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	td->io_ops = load_ioengine(td, engine);
81409629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	if (!td->io_ops) {
81509629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		log_err("fio: failed to load engine %s\n", engine);
81609629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		return 1;
81709629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	}
818df64119de537aba99c85d1dc80190b354589f8b9Jens Axboe
819690adba373bb8c97a365c67da369e265953c4b4cJens Axboe	if (td->odirect)
820690adba373bb8c97a365c67da369e265953c4b4cJens Axboe		td->io_ops->flags |= FIO_RAWIO;
821690adba373bb8c97a365c67da369e265953c4b4cJens Axboe
82280be24f4671164d597463e4b5c794d4cbd0a4537Jens Axboe	if (!td->filename)
82380be24f4671164d597463e4b5c794d4cbd0a4537Jens Axboe		td->filename = strdup(jobname);
82480be24f4671164d597463e4b5c794d4cbd0a4537Jens Axboe
825ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->filetype = FIO_TYPE_FILE;
82680be24f4671164d597463e4b5c794d4cbd0a4537Jens Axboe	if (!lstat(td->filename, &sb)) {
8270af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe		if (S_ISBLK(sb.st_mode))
8280af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe			td->filetype = FIO_TYPE_BD;
8290af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe		else if (S_ISCHR(sb.st_mode))
8300af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe			td->filetype = FIO_TYPE_CHAR;
8310af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe	}
832ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
833e0a223354342cc45a916b669343718b80a20c2eaJens Axboe	fixup_options(td);
834e0a223354342cc45a916b669343718b80a20c2eaJens Axboe
83513f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe	if (td->filename)
83613f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe		td->nr_uniq_files = 1;
83713f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe	else
8380f14fef318f38a285a04097636a65a997596e821Jens Axboe		td->nr_uniq_files = td->open_files;
83913f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe
84013f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe	if (td->filetype == FIO_TYPE_FILE || td->filename) {
841e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe		char tmp[PATH_MAX];
84253cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		int len = 0;
843e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe
84416edf25dba269ee9e8239130e75b690440b1e120Jens Axboe		if (td->directory && td->directory[0] != '\0') {
84516edf25dba269ee9e8239130e75b690440b1e120Jens Axboe			if (lstat(td->directory, &sb) < 0) {
84616edf25dba269ee9e8239130e75b690440b1e120Jens Axboe				log_err("fio: %s is not a directory\n", td->directory);
847e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe				td_verror(td, errno, "lstat");
84816edf25dba269ee9e8239130e75b690440b1e120Jens Axboe				return 1;
84916edf25dba269ee9e8239130e75b690440b1e120Jens Axboe			}
85016edf25dba269ee9e8239130e75b690440b1e120Jens Axboe			if (!S_ISDIR(sb.st_mode)) {
85116edf25dba269ee9e8239130e75b690440b1e120Jens Axboe				log_err("fio: %s is not a directory\n", td->directory);
85216edf25dba269ee9e8239130e75b690440b1e120Jens Axboe				return 1;
85316edf25dba269ee9e8239130e75b690440b1e120Jens Axboe			}
8548aeebd5570ac4fccbcdd48f2e6f1cf1577f3c08dJens Axboe			len = sprintf(tmp, "%s/", td->directory);
85516edf25dba269ee9e8239130e75b690440b1e120Jens Axboe		}
856ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
857b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		td->files = malloc(sizeof(struct fio_file) * td->open_files);
85853cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe
85953cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		for_each_file(td, f, i) {
86053cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe			memset(f, 0, sizeof(*f));
86153cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe			f->fd = -1;
86253cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe
86313f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe			if (td->filename)
86413f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe				sprintf(tmp + len, "%s", td->filename);
86513f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe			else
86613f8e2d2e3e5ec7d8c18b70fb2a2e2a026190020Jens Axboe				sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
86753cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe			f->file_name = strdup(tmp);
86853cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		}
86953cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	} else {
870b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe		td->open_files = td->nr_files = 1;
87153cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		td->files = malloc(sizeof(struct fio_file));
87253cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		f = &td->files[0];
87353cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe
87453cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		memset(f, 0, sizeof(*f));
87553cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		f->fd = -1;
87653cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		f->file_name = strdup(jobname);
87753cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	}
87853cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe
87953cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	for_each_file(td, f, i) {
88053cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		f->file_size = td->total_file_size / td->nr_files;
88153cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe		f->file_offset = td->start_offset;
88253cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	}
88353cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe
88407739b57f09886b41323c605b0dbda7d2c12522bJens Axboe	td->mutex = fio_sem_init(0);
885ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
886756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe	td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
887756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe	td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
888756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe	td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
889ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
890ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->stonewall && td->thread_number > 1)
891ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		groupid++;
892ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
893ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->groupid = groupid;
894ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
895ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (setup_rate(td))
896ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		goto err;
897ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
898ec94ec567cae47f91fa31a18250c2a7a0029d2adJens Axboe	if (td->write_lat_log) {
899756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe		setup_log(&td->ts.slat_log);
900756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe		setup_log(&td->ts.clat_log);
901ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
902ec94ec567cae47f91fa31a18250c2a7a0029d2adJens Axboe	if (td->write_bw_log)
903756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe		setup_log(&td->ts.bw_log);
904ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
905b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	if (!td->name)
906b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		td->name = strdup(jobname);
90701452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe
908c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe	if (!terse_output) {
909b990b5c06801d6d25e3fcc5415efbbe7bb23341eJens Axboe		if (!job_add_num) {
910ba0fbe1029bae1de08d66a72b6d0b2505c67c438Jens Axboe			if (!strcmp(td->io_ops->name, "cpuio"))
911b990b5c06801d6d25e3fcc5415efbbe7bb23341eJens Axboe				fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
912f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe			else {
913f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				char *c1, *c2, *c3, *c4;
914f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
915f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				c1 = to_kmg(td->min_bs[DDIR_READ]);
916f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				c2 = to_kmg(td->max_bs[DDIR_READ]);
917f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				c3 = to_kmg(td->min_bs[DDIR_WRITE]);
918f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				c4 = to_kmg(td->max_bs[DDIR_WRITE]);
919f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
920413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe				fprintf(f_out, "%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);
921f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
922f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c1);
923f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c2);
924f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c3);
925f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c4);
926f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe			}
927b990b5c06801d6d25e3fcc5415efbbe7bb23341eJens Axboe		} else if (job_add_num == 1)
928c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe			fprintf(f_out, "...\n");
929c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe	}
930ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
931ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
932ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * recurse add identical jobs, clear numjobs and stonewall options
933ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * as they don't apply to sub-jobs
934ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
935ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	numjobs = td->numjobs;
936ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	while (--numjobs) {
937ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		struct thread_data *td_new = get_new_job(0, td);
938ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
939ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (!td_new)
940ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			goto err;
941ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
942ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td_new->numjobs = 1;
943ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td_new->stonewall = 0;
944751548451d969148529b642c05e7544726ec3b64Jens Axboe		job_add_num = numjobs - 1;
945ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
946751548451d969148529b642c05e7544726ec3b64Jens Axboe		if (add_job(td_new, jobname, job_add_num))
947ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			goto err;
948ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
949ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
950ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeerr:
951ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	put_job(td);
952ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return -1;
953ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
954ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
955906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
956906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * Initialize the various random states we need (random io, block size ranges,
957906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * read/write mix, etc).
958906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
959ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint init_random_state(struct thread_data *td)
960ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
9610aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe	unsigned long seeds[5];
96253cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	int fd, num_maps, blocks, i;
9630ab8db8943acc6b9ea778735563bfad2a79e8dddJens Axboe	struct fio_file *f;
964ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
965ba0fbe1029bae1de08d66a72b6d0b2505c67c438Jens Axboe	if (td->io_ops->flags & FIO_DISKLESSIO)
966f48b467cba78af0843c7320caf841e2bee72fb1eJens Axboe		return 0;
967f48b467cba78af0843c7320caf841e2bee72fb1eJens Axboe
9681ac267bb7dd678fa12bb3573c29cff5238ef9ccfJens Axboe	fd = open("/dev/urandom", O_RDONLY);
969ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fd == -1) {
970e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe		td_verror(td, errno, "open");
971ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
972ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
973ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
974a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe	if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
975e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe		td_verror(td, EIO, "read");
976ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		close(fd);
977ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
978ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
979ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
980ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	close(fd);
981ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
9826dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[0], &td->bsrange_state);
9836dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[1], &td->verify_state);
9846dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[2], &td->rwmix_state);
985ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
986413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe	if (td->file_service_type == FIO_FSERVICE_RANDOM)
987413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe		os_random_seed(seeds[3], &td->next_file_state);
988413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe
989413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe	if (!td_random(td))
990ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
991ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
9929ebc27e1352b905fe3396ce2350a7765fe9c57b8Jens Axboe	if (td->rand_repeatable)
9930aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe		seeds[4] = FIO_RANDSEED * td->thread_number;
994ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
995bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe	if (!td->norandommap) {
996bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe		for_each_file(td, f, i) {
997a4a81712f0bd76cbde8898c0b87faedbaa1d2da1Jens Axboe			blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
998c7c280ed2e4f836bd8e9e125d55d097539b70e21Jens Axboe			num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
999bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe			f->file_map = malloc(num_maps * sizeof(long));
1000bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe			f->num_maps = num_maps;
1001bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe			memset(f->file_map, 0, num_maps * sizeof(long));
1002bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe		}
100353cdc6864f7471b28cc9b40a5314ab43e5b1cb5eJens Axboe	}
1004ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
10050aabe160c38efc3c42157fac2a9af08e070341c6Jens Axboe	os_random_seed(seeds[4], &td->random_state);
1006ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1007ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1008ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1009ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
1010ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1011ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_CPU_AFFINITY
1012ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned int i;
1013ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1014ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	CPU_ZERO(&cpumask);
1015ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1016ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	for (i = 0; i < sizeof(int) * 8; i++) {
1017ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if ((1 << i) & cpu)
1018ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			CPU_SET(i, &cpumask);
1019ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1020ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
1021ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1022ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1023ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int is_empty_or_comment(char *line)
1024ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1025ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned int i;
1026ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1027ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	for (i = 0; i < strlen(line); i++) {
1028ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (line[i] == ';')
1029ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1;
10305cc2da300b3fc30e00b79b4ddb3f372df3b2fe93Ingo Molnar		if (line[i] == '#')
10315cc2da300b3fc30e00b79b4ddb3f372df3b2fe93Ingo Molnar			return 1;
1032ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (!isspace(line[i]) && !iscntrl(line[i]))
1033ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 0;
1034ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1035ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1036ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
1037ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1038ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1039313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe/*
1040313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
1041313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe */
1042313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboestatic char *get_mmap_file(const char *str)
1043313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe{
1044313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe	char *p = strstr(str, ":");
1045313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe
1046313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe	if (!p)
1047313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe		return NULL;
1048313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe
1049313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe	p++;
1050313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe	strip_blank_front(&p);
1051313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe	strip_blank_end(p);
1052313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe	return strdup(p);
1053313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe}
1054313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe
1055b46928282e0a890f49250e79b81af773a2b7108fJens Axboestatic int str_mem_cb(void *data, const char *mem)
1056ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1057cb2c86fdf03241fee32fd2e2caff43af1022403cJens Axboe	struct thread_data *td = data;
1058cb2c86fdf03241fee32fd2e2caff43af1022403cJens Axboe
1059b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe	if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
1060313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe		td->mmapfile = get_mmap_file(mem);
1061b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
1062d0bdaf49eb3f4faa941d02274f2bd875a187e7d7Jens Axboe			log_err("fio: mmaphuge:/path/to/file\n");
1063d0bdaf49eb3f4faa941d02274f2bd875a187e7d7Jens Axboe			return 1;
1064d0bdaf49eb3f4faa941d02274f2bd875a187e7d7Jens Axboe		}
1065ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1066ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1067b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe	return 0;
1068ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1069ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1070e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1071e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
1072e1f365035a952233463d85d659bd960ba78f012eJens Axboe	mlock_size = *val;
1073e1f365035a952233463d85d659bd960ba78f012eJens Axboe	return 0;
1074e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
1075e1f365035a952233463d85d659bd960ba78f012eJens Axboe
107634cfcdafa994a0a75120e498c51eda08bde5df72Jens Axboe#ifdef FIO_HAVE_IOPRIO
1077e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_prioclass_cb(void *data, unsigned int *val)
1078e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
1079e1f365035a952233463d85d659bd960ba78f012eJens Axboe	struct thread_data *td = data;
1080e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1081e1f365035a952233463d85d659bd960ba78f012eJens Axboe	td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1082e1f365035a952233463d85d659bd960ba78f012eJens Axboe	return 0;
1083e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
1084e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1085e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_prio_cb(void *data, unsigned int *val)
1086e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
1087e1f365035a952233463d85d659bd960ba78f012eJens Axboe	struct thread_data *td = data;
1088e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1089e1f365035a952233463d85d659bd960ba78f012eJens Axboe	td->ioprio |= *val;
1090e1f365035a952233463d85d659bd960ba78f012eJens Axboe	return 0;
1091e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
109234cfcdafa994a0a75120e498c51eda08bde5df72Jens Axboe#endif
1093e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1094e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_exitall_cb(void)
1095e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
1096e1f365035a952233463d85d659bd960ba78f012eJens Axboe	exitall_on_terminate = 1;
1097e1f365035a952233463d85d659bd960ba78f012eJens Axboe	return 0;
1098e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
1099e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1100e1f365035a952233463d85d659bd960ba78f012eJens Axboestatic int str_cpumask_cb(void *data, unsigned int *val)
1101e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
1102e1f365035a952233463d85d659bd960ba78f012eJens Axboe	struct thread_data *td = data;
1103e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1104e1f365035a952233463d85d659bd960ba78f012eJens Axboe	fill_cpu_mask(td->cpumask, *val);
1105e1f365035a952233463d85d659bd960ba78f012eJens Axboe	return 0;
1106e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
1107e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1108072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe/*
1109072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe * This is our [ini] type file parser.
1110072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe */
11111e97cce9f5a87a67293a05ec4533ed6968698b2eJens Axboestatic int parse_jobs_ini(char *file, int stonewall_flag)
1112ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1113e1f365035a952233463d85d659bd960ba78f012eJens Axboe	unsigned int global;
1114ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct thread_data *td;
1115fee3bb48f748afe5cf10f8505e1efd36b87c627eJens Axboe	char *string, *name;
1116ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	fpos_t off;
1117ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	FILE *f;
1118ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	char *p;
11190c7e37a04aa04ba22e812f8de7971fcef46b8191Jens Axboe	int ret = 0, stonewall;
1120ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1121ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	f = fopen(file, "r");
1122ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!f) {
1123aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe		perror("fopen job file");
1124ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1125ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1126ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1127ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	string = malloc(4096);
1128ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	name = malloc(256);
1129fee3bb48f748afe5cf10f8505e1efd36b87c627eJens Axboe	memset(name, 0, 256);
1130ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
11310c7e37a04aa04ba22e812f8de7971fcef46b8191Jens Axboe	stonewall = stonewall_flag;
11327c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe	do {
11337c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe		p = fgets(string, 4095, f);
11347c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe		if (!p)
113545410acb636e526575d62a037f81ade7916b738cJens Axboe			break;
1136ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (is_empty_or_comment(p))
1137ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			continue;
1138fee3bb48f748afe5cf10f8505e1efd36b87c627eJens Axboe		if (sscanf(p, "[%255s]", name) != 1)
1139ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			continue;
1140ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1141ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		global = !strncmp(name, "global", 6);
1142ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1143ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		name[strlen(name) - 1] = '\0';
1144ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1145ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td = get_new_job(global, &def_thread);
114645410acb636e526575d62a037f81ade7916b738cJens Axboe		if (!td) {
114745410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = 1;
114845410acb636e526575d62a037f81ade7916b738cJens Axboe			break;
114945410acb636e526575d62a037f81ade7916b738cJens Axboe		}
1150ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1151972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		/*
1152972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		 * Seperate multiple job files by a stonewall
1153972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		 */
1154f94819192600fe35d03ebed26a803abdc2b9864cJens Axboe		if (!global && stonewall) {
1155972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			td->stonewall = stonewall;
1156972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			stonewall = 0;
1157972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		}
1158972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
1159ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		fgetpos(f, &off);
1160ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		while ((p = fgets(string, 4096, f)) != NULL) {
1161ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (is_empty_or_comment(p))
1162ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
1163e1f365035a952233463d85d659bd960ba78f012eJens Axboe
1164b6754f9d3f719627d8aae4c3e8f39212d9405f99Jens Axboe			strip_blank_front(&p);
11657c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe
11667c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe			if (p[0] == '[')
11677c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe				break;
11687c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe
11694ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe			strip_blank_end(p);
1170aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe
1171e1f365035a952233463d85d659bd960ba78f012eJens Axboe			fgetpos(f, &off);
1172ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
117345410acb636e526575d62a037f81ade7916b738cJens Axboe			/*
117445410acb636e526575d62a037f81ade7916b738cJens Axboe			 * Don't break here, continue parsing options so we
117545410acb636e526575d62a037f81ade7916b738cJens Axboe			 * dump all the bad ones. Makes trial/error fixups
117645410acb636e526575d62a037f81ade7916b738cJens Axboe			 * easier on the user.
117745410acb636e526575d62a037f81ade7916b738cJens Axboe			 */
11787c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe			ret |= parse_option(p, options, td);
1179ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
1180ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
118145410acb636e526575d62a037f81ade7916b738cJens Axboe		if (!ret) {
118245410acb636e526575d62a037f81ade7916b738cJens Axboe			fsetpos(f, &off);
118345410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = add_job(td, name, 0);
1184b1508cf9ead36dc789a4e289f7522a070e57058cJens Axboe		} else {
1185b1508cf9ead36dc789a4e289f7522a070e57058cJens Axboe			log_err("fio: job %s dropped\n", name);
1186b1508cf9ead36dc789a4e289f7522a070e57058cJens Axboe			put_job(td);
118745410acb636e526575d62a037f81ade7916b738cJens Axboe		}
11887c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe	} while (!ret);
1189ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1190ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	free(string);
1191ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	free(name);
1192ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	fclose(f);
119345410acb636e526575d62a037f81ade7916b738cJens Axboe	return ret;
1194ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1195ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1196ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int fill_def_thread(void)
1197ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1198ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(&def_thread, 0, sizeof(def_thread));
1199ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1200ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1201ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		perror("sched_getaffinity");
1202ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1203ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1204ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1205ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
1206ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe	 * fill default options
1207ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
1208ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe	fill_default_options(&def_thread, options);
1209ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe
1210972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	def_thread.timeout = def_timeout;
1211ec94ec567cae47f91fa31a18250c2a7a0029d2adJens Axboe	def_thread.write_bw_log = write_bw_log;
1212ec94ec567cae47f91fa31a18250c2a7a0029d2adJens Axboe	def_thread.write_lat_log = write_lat_log;
1213ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe
1214ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_DISK_UTIL
1215ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.do_disk_util = 1;
1216ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
1217ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1218ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1219ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1220ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
12210ab8db8943acc6b9ea778735563bfad2a79e8dddJens Axboestatic void usage(void)
12224785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe{
12234785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("%s\n", fio_version_string);
1224b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--output\tWrite output to file\n");
1225b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--timeout\tRuntime in seconds\n");
1226b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--latency-log\tGenerate per-job latency logs\n");
1227b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1228b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--minimal\tMinimal (terse) output\n");
1229b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--version\tPrint version info and exit\n");
1230fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	printf("\t--help\t\tPrint this page\n");
1231fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
12324785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe}
12334785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe
1234972cfd2546081c0397447ca9243ea419b1ff579aJens Axboestatic int parse_cmd_line(int argc, char *argv[])
1235ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1236b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	struct thread_data *td = NULL;
1237b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe	int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
1238ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
12390be06ea2c87ecf1751a01ed528a2d3170bdca543Jens Axboe	while ((c = getopt_long_only(argc, argv, "", long_options, &lidx)) != -1) {
1240ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		switch (c) {
1241b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 't':
1242b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			def_timeout = atoi(optarg);
1243b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1244b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'l':
1245b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			write_lat_log = 1;
1246b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1247b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'w':
1248b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			write_bw_log = 1;
1249b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1250b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'o':
1251b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			f_out = fopen(optarg, "w+");
1252b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			if (!f_out) {
1253b46928282e0a890f49250e79b81af773a2b7108fJens Axboe				perror("fopen output");
1254b46928282e0a890f49250e79b81af773a2b7108fJens Axboe				exit(1);
1255b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			}
1256b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			f_err = f_out;
1257b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1258b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'm':
1259b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			terse_output = 1;
1260b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1261b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'h':
1262b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			usage();
1263b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			exit(0);
1264fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		case 'c':
126529fc6afe1bfcb97dd7f33d8e58b99b2d93237d47Jens Axboe			ret = show_cmd_help(options, optarg);
126629fc6afe1bfcb97dd7f33d8e58b99b2d93237d47Jens Axboe			exit(ret);
1267b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'v':
1268b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			printf("%s\n", fio_version_string);
1269b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			exit(0);
1270b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case FIO_GETOPT_JOB: {
1271b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			const char *opt = long_options[lidx].name;
1272b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			char *val = optarg;
1273b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1274c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe			if (!strncmp(opt, "name", 4) && td) {
1275c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				ret = add_job(td, td->name ?: "fio", 0);
1276c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				if (ret) {
1277c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe					put_job(td);
1278c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe					return 0;
1279c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				}
1280c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				td = NULL;
1281c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe			}
1282b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			if (!td) {
128338d0adb0d129e2eef7bf21e85ba4758c3789cb8eJens Axboe				int global = !strncmp(val, "global", 6);
1284c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe
1285c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				td = get_new_job(global, &def_thread);
1286b46928282e0a890f49250e79b81af773a2b7108fJens Axboe				if (!td)
1287b46928282e0a890f49250e79b81af773a2b7108fJens Axboe					return 0;
1288b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			}
128938d0adb0d129e2eef7bf21e85ba4758c3789cb8eJens Axboe
1290b1508cf9ead36dc789a4e289f7522a070e57058cJens Axboe			ret = parse_cmd_option(opt, val, options, td);
129178217dfa392a6a39f018722e91bc179e9d5443dfJens Axboe			if (ret)
1292b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe				dont_add_job = 1;
1293b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1294b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		}
1295b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		default:
1296b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1297ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
1298ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1299c9fad893e8333682d6ab67a269b0dd74f303c5bcJens Axboe
1300b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	if (td) {
1301b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		if (dont_add_job)
1302b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			put_job(td);
1303b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		else {
1304b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			ret = add_job(td, td->name ?: "fio", 0);
1305b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe			if (ret)
1306b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe				put_job(td);
1307b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe		}
1308972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	}
1309774a617767830b5023f6cad4a45609a92ec82d41Jens Axboe
1310b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	while (optind < argc) {
1311b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		ini_idx++;
1312b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1313b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		ini_file[ini_idx - 1] = strdup(argv[optind]);
1314b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		optind++;
1315eb8bbf48e79a8c6afd3c84e3d64263d10ee45daaJens Axboe	}
1316972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
1317972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	return ini_idx;
1318ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1319ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1320ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void free_shm(void)
1321ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1322ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct shmid_ds sbuf;
1323ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1324ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (threads) {
13252c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe		shmdt((void *) threads);
1326ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		threads = NULL;
1327ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		shmctl(shm_id, IPC_RMID, &sbuf);
1328ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1329ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1330ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1331906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
1332906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * The thread area is shared between the main process and the job
1333906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * threads/processes. So setup a shared memory segment that will hold
1334906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * all the job info.
1335906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
1336ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int setup_thread_area(void)
1337ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1338ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
1339ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * 1024 is too much on some machines, scale max_jobs if
1340ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * we get a failure that looks like too large a shm segment
1341ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
1342ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	do {
1343906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe		size_t size = max_jobs * sizeof(struct thread_data);
1344ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1345906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe		shm_id = shmget(0, size, IPC_CREAT | 0600);
1346ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (shm_id != -1)
1347ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			break;
1348ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (errno != EINVAL) {
1349ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			perror("shmget");
1350ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			break;
1351ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
1352ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1353ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		max_jobs >>= 1;
1354ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} while (max_jobs);
1355ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1356ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (shm_id == -1)
1357ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1358ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1359ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	threads = shmat(shm_id, NULL, 0);
1360ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (threads == (void *) -1) {
1361ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		perror("shmat");
1362ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1363ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1364ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1365ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	atexit(free_shm);
1366ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1367ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1368ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1369b46928282e0a890f49250e79b81af773a2b7108fJens Axboe/*
1370b46928282e0a890f49250e79b81af773a2b7108fJens Axboe * Copy the fio options into the long options map, so we mirror
1371b46928282e0a890f49250e79b81af773a2b7108fJens Axboe * job and cmd line options.
1372b46928282e0a890f49250e79b81af773a2b7108fJens Axboe */
1373b46928282e0a890f49250e79b81af773a2b7108fJens Axboestatic void dupe_job_options(void)
1374b46928282e0a890f49250e79b81af773a2b7108fJens Axboe{
1375b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	struct fio_option *o;
1376b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	unsigned int i;
1377b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1378b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	i = 0;
1379b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	while (long_options[i].name)
1380b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		i++;
1381b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1382b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	o = &options[0];
1383b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	while (o->name) {
1384b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		long_options[i].name = o->name;
1385b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		long_options[i].val = FIO_GETOPT_JOB;
1386b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		if (o->type == FIO_OPT_STR_SET)
1387b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			long_options[i].has_arg = no_argument;
1388b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		else
1389b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			long_options[i].has_arg = required_argument;
1390b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1391b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		i++;
1392b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		o++;
1393b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1394b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	}
1395b46928282e0a890f49250e79b81af773a2b7108fJens Axboe}
1396b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1397ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint parse_options(int argc, char *argv[])
1398ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1399972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	int job_files, i;
1400972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
1401b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	f_out = stdout;
1402b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	f_err = stderr;
1403b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
140413335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe	options_init(options);
140513335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe
1406b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	dupe_job_options();
1407b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1408ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (setup_thread_area())
1409ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1410ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fill_def_thread())
1411ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1412ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1413972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	job_files = parse_cmd_line(argc, argv);
1414ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1415972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	for (i = 0; i < job_files; i++) {
1416972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		if (fill_def_thread())
1417972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			return 1;
14180c7e37a04aa04ba22e812f8de7971fcef46b8191Jens Axboe		if (parse_jobs_ini(ini_file[i], i))
1419972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			return 1;
142088c6ed8085efd1403fd34072311991cb666a5b9eJens Axboe		free(ini_file[i]);
1421972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	}
1422ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
142388c6ed8085efd1403fd34072311991cb666a5b9eJens Axboe	free(ini_file);
1424b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1425b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	if (!thread_number) {
1426b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		log_err("No jobs defined(s)\n");
1427b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		return 1;
1428b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	}
1429b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1430ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1431ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1432