init.c revision f57a9c59e366aa2f0621aa260bfd5ef5aeb61643
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>
11ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/ipc.h>
12ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/shm.h>
13ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/types.h>
14ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/stat.h>
15ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
16ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "fio.h"
17cb2c86fdf03241fee32fd2e2caff43af1022403cJens Axboe#include "parse.h"
182e5cdb118aeb26cb469a50f746b632676306f698Jens Axboe#include "smalloc.h"
19380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe#include "filehash.h"
204f5af7b2370a6d3e64bc5128905c1aa8b0dc51b0Jens Axboe#include "verify.h"
2179d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe#include "profile.h"
22ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
23bf2e821a55d8aa3de1cda7288a0e22883110fdc6Cigy Cyriac#include "lib/getopt.h"
24bf2e821a55d8aa3de1cda7288a0e22883110fdc6Cigy Cyriac
25173dbaa47e3a477db65aa9fb1932a33d87436994Jens Axboestatic char fio_version_string[] = "fio 1.57";
26214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
27ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe#define FIO_RANDSEED		(0xb1899bedUL)
28ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
29214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboestatic char **ini_file;
30fca7035863bd570270376a0c06776e5549ff813eJens Axboestatic int max_jobs = FIO_MAX_JOBS;
31cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboestatic int dump_cmdline;
32e1f365035a952233463d85d659bd960ba78f012eJens Axboe
33be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboestatic struct thread_data def_thread;
34214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboestruct thread_data *threads = NULL;
35e1f365035a952233463d85d659bd960ba78f012eJens Axboe
36214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboeint exitall_on_terminate = 0;
37214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboeint terse_output = 0;
38e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carrollint eta_print;
39214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboeunsigned long long mlock_size = 0;
40214e1ecae844a32bf8f66d19132f4948d922dceeJens AxboeFILE *f_out = NULL;
41214e1ecae844a32bf8f66d19132f4948d922dceeJens AxboeFILE *f_err = NULL;
42ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboechar **job_sections = NULL;
43ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboeint nr_job_sections = 0;
4407b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboechar *exec_profile = NULL;
45a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboeint warnings_fatal = 0;
46f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboeint terse_version = 2;
47ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe
48214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboeint write_bw_log = 0;
494241ea8fb0606f9bd5b7ed1278d3b7825883acf6Jens Axboeint read_only = 0;
50214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
515ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboestatic int write_lat_log;
52e1f365035a952233463d85d659bd960ba78f012eJens Axboe
53214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboestatic int prev_group_jobs;
54b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
55ee56ad500f6692381e131cc37299d23fa910a24aJens Axboeunsigned long fio_debug = 0;
565e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboeunsigned int fio_debug_jobno = -1;
575e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboeunsigned int *fio_debug_jobp = NULL;
58ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe
594c6107ff4db87f50545bad515543f5024bb39e4aJens Axboestatic char cmd_optstr[256];
604c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe
61b46928282e0a890f49250e79b81af773a2b7108fJens Axboe/*
62b46928282e0a890f49250e79b81af773a2b7108fJens Axboe * Command line options. These will contain the above, plus a few
63b46928282e0a890f49250e79b81af773a2b7108fJens Axboe * extra that only pertain to fio itself and not jobs.
64b46928282e0a890f49250e79b81af773a2b7108fJens Axboe */
655ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboestatic struct option l_opts[FIO_NR_OPTIONS] = {
66b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
6708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "output",
68b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
69b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'o',
70b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
71b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
7208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "timeout",
73b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
74b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 't',
75b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
76b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
7708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "latency-log",
78b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
79b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'l',
80b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
81b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
8208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "bandwidth-log",
83b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= required_argument,
84b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'b',
85b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
86b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
8708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "minimal",
88b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= optional_argument,
89b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'm',
90b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
91b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
9208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "version",
93b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.has_arg	= no_argument,
94b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.val		= 'v',
95b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
96b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	{
9708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "help",
98fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.has_arg	= no_argument,
99fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.val		= 'h',
100fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	},
101fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	{
10208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "cmdhelp",
103320beefe2d0c5f05f24b4e0c1d13fcb2f1286a78Jens Axboe		.has_arg	= optional_argument,
104fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		.val		= 'c',
105fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	},
106fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	{
10708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "showcmd",
108cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		.has_arg	= no_argument,
109724e4435c1374e97309b122429ad9291744966c0Jens Axboe		.val		= 's',
110724e4435c1374e97309b122429ad9291744966c0Jens Axboe	},
111724e4435c1374e97309b122429ad9291744966c0Jens Axboe	{
11208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "readonly",
113724e4435c1374e97309b122429ad9291744966c0Jens Axboe		.has_arg	= no_argument,
114724e4435c1374e97309b122429ad9291744966c0Jens Axboe		.val		= 'r',
115cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	},
116cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	{
11708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "eta",
118e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll		.has_arg	= required_argument,
119e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll		.val		= 'e',
120e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll	},
121e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll	{
12208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "debug",
123ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		.has_arg	= required_argument,
124ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		.val		= 'd',
125ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	},
126ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	{
12708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "section",
12801f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe		.has_arg	= required_argument,
12901f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe		.val		= 'x',
13001f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe	},
13101f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe	{
13208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "alloc-size",
1332b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe		.has_arg	= required_argument,
1342b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe		.val		= 'a',
1352b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe	},
1362b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe	{
13708d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "profile",
1389ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe		.has_arg	= required_argument,
1399ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe		.val		= 'p',
1409ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe	},
1419ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe	{
14208d2a19c76b310f68ad2ecab17dff2a2a4c1adf8Jens Axboe		.name		= (char *) "warnings-fatal",
143a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		.has_arg	= no_argument,
144a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		.val		= 'w',
145a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe	},
146a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe	{
147fca7035863bd570270376a0c06776e5549ff813eJens Axboe		.name		= (char *) "max-jobs",
148fca7035863bd570270376a0c06776e5549ff813eJens Axboe		.has_arg	= required_argument,
149fca7035863bd570270376a0c06776e5549ff813eJens Axboe		.val		= 'j',
150fca7035863bd570270376a0c06776e5549ff813eJens Axboe	},
151fca7035863bd570270376a0c06776e5549ff813eJens Axboe	{
152f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe		.name		= (char *) "terse-version",
153f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe		.has_arg	= required_argument,
154f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe		.val		= 'V',
155f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe	},
156f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe	{
157b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		.name		= NULL,
158b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	},
159b46928282e0a890f49250e79b81af773a2b7108fJens Axboe};
160b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1619728ce37ea4348d4bdb2eefbaafee75ad651758cJoel BeckerFILE *get_f_out()
1629728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker{
1639728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker	return f_out;
1649728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker}
1659728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker
1669728ce37ea4348d4bdb2eefbaafee75ad651758cJoel BeckerFILE *get_f_err()
1679728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker{
1689728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker	return f_err;
1699728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker}
1709728ce37ea4348d4bdb2eefbaafee75ad651758cJoel Becker
171906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
172906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * Return a free job structure.
173906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
174ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic struct thread_data *get_new_job(int global, struct thread_data *parent)
175ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
176ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct thread_data *td;
177ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
178ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (global)
179ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return &def_thread;
180e61f1ec89de8eb5bb0f8b1e6a79594f0bff2a259Bruce Cran	if (thread_number >= max_jobs) {
181e61f1ec89de8eb5bb0f8b1e6a79594f0bff2a259Bruce Cran		log_err("error: maximum number of jobs (%d) reached.\n",
182e61f1ec89de8eb5bb0f8b1e6a79594f0bff2a259Bruce Cran				max_jobs);
183ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return NULL;
184e61f1ec89de8eb5bb0f8b1e6a79594f0bff2a259Bruce Cran	}
185ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
186ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td = &threads[thread_number++];
187ddaeaa5ab1e3f1cb6f35a9f4a18ee932151a0ab8Jens Axboe	*td = *parent;
188ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
189e0b0d89201bd301f47fbbfcf86545b7e77b16ef3Jens Axboe	td->o.uid = td->o.gid = -1U;
190e0b0d89201bd301f47fbbfcf86545b7e77b16ef3Jens Axboe
191cade3ef44669c5c962d7ed18ca0e361116ee44adJens Axboe	dup_files(td, parent);
192d23bb327374520295509bbd98912c8091b701a3eJens Axboe	options_mem_dupe(td);
193cade3ef44669c5c962d7ed18ca0e361116ee44adJens Axboe
19415dc1934435dc84d66547c4fc92d936224d7238fJens Axboe	profile_add_hooks(td);
19515dc1934435dc84d66547c4fc92d936224d7238fJens Axboe
196ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->thread_number = thread_number;
197ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return td;
198ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
199ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
200ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void put_job(struct thread_data *td)
201ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
202549577a728fc3bacbfea8978c4f514cef5b073dcJens Axboe	if (td == &def_thread)
203549577a728fc3bacbfea8978c4f514cef5b073dcJens Axboe		return;
20484dd18865235caa675424c62a4624618ff961d78Bruce Cran
20558c55ba02aca24ed30beb343fcb1dc3df4667389Jens Axboe	profile_td_exit(td);
206549577a728fc3bacbfea8978c4f514cef5b073dcJens Axboe
20716edf25dba269ee9e8239130e75b690440b1e120Jens Axboe	if (td->error)
2086d86144dd10b05e8b82e9b895c35dd778e5e71abJens Axboe		log_info("fio: %s\n", td->verror);
20916edf25dba269ee9e8239130e75b690440b1e120Jens Axboe
210ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(&threads[td->thread_number - 1], 0, sizeof(*td));
211ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	thread_number--;
212ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
213ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
214581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboestatic int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
215127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe{
216581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	unsigned int bs = td->o.min_bs[ddir];
217ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran	unsigned long long bytes_per_sec;
218127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe
219ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe	assert(ddir_rw(ddir));
220ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe
221ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran	if (td->o.rate[ddir])
222ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran		bytes_per_sec = td->o.rate[ddir];
223ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran	else
224ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran		bytes_per_sec = td->o.rate_iops[ddir] * bs;
225127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe
226ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran	if (!bytes_per_sec) {
227127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe		log_err("rate lower than supported\n");
228127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe		return -1;
229127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe	}
230127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe
231ba3e4e0ca697f83c97a250d85a74506ace69de2cRadha Ramachandran	td->rate_nsec_cycle[ddir] = 1000000000ULL / bytes_per_sec;
232581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	td->rate_pending_usleep[ddir] = 0;
233127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe	return 0;
234127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe}
235127f686514ef8b1d9ab6ed702971b205454974e6Jens Axboe
236581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboestatic int setup_rate(struct thread_data *td)
237581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe{
238581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	int ret = 0;
239581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe
240581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
241581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe		ret = __setup_rate(td, DDIR_READ);
242581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
243581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe		ret |= __setup_rate(td, DDIR_WRITE);
244581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe
245581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	return ret;
246581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe}
247581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe
2488347239af0a361e160293100bfc053f88bbbf737Jens Axboestatic int fixed_block_size(struct thread_options *o)
2498347239af0a361e160293100bfc053f88bbbf737Jens Axboe{
2508347239af0a361e160293100bfc053f88bbbf737Jens Axboe	return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
2518347239af0a361e160293100bfc053f88bbbf737Jens Axboe		o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
2528347239af0a361e160293100bfc053f88bbbf737Jens Axboe		o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE];
2538347239af0a361e160293100bfc053f88bbbf737Jens Axboe}
2548347239af0a361e160293100bfc053f88bbbf737Jens Axboe
255dad915e36819e74c4540db19faae488ede963ee4Jens Axboe/*
256dad915e36819e74c4540db19faae488ede963ee4Jens Axboe * Lazy way of fixing up options that depend on each other. We could also
257dad915e36819e74c4540db19faae488ede963ee4Jens Axboe * define option callback handlers, but this is easier.
258dad915e36819e74c4540db19faae488ede963ee4Jens Axboe */
2594e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboestatic int fixup_options(struct thread_data *td)
260e1f365035a952233463d85d659bd960ba78f012eJens Axboe{
2612dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	struct thread_options *o = &td->o;
262ff21745102e2410df4b950ca2ff774ad5ea717d1Jens Axboe	int ret = 0;
263dad915e36819e74c4540db19faae488ede963ee4Jens Axboe
264f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe#ifndef FIO_HAVE_PSHARED_MUTEX
2659bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe	if (!o->use_thread) {
266f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe		log_info("fio: this platform does not support process shared"
267f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe			 " mutexes, forcing use of threads. Use the 'thread'"
268f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe			 " option to get rid of this warning.\n");
2699bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe		o->use_thread = 1;
270a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = warnings_fatal;
271f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe	}
272f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe#endif
273f356d01d0cf8fec2ee58f66a9b5c00c93defbc47Jens Axboe
2742dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->write_iolog_file && o->read_iolog_file) {
275076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe		log_err("fio: read iolog overrides write_iolog\n");
2762dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		free(o->write_iolog_file);
2772dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->write_iolog_file = NULL;
278a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = warnings_fatal;
279076efc7c60c351df783960a646e7fe8fba29dc19Jens Axboe	}
28016b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
28116b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	/*
28216b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 * only really works for sequential io for now, and with 1 file
28316b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 */
2842dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->zone_size && td_random(td) && o->open_files == 1)
2852dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->zone_size = 0;
28616b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
28716b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	/*
28816b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 * Reads can do overwrites, we always need to pre-create the file
28916b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	 */
29016b462aeb47996111ee6aa516c9226708db7c248Jens Axboe	if (td_read(td) || td_rw(td))
2912dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->overwrite = 1;
29216b462aeb47996111ee6aa516c9226708db7c248Jens Axboe
2932dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (!o->min_bs[DDIR_READ])
2945ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe		o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
2952dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (!o->max_bs[DDIR_READ])
2962dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
2972dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (!o->min_bs[DDIR_WRITE])
2985ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe		o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
2992dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (!o->max_bs[DDIR_WRITE])
3002dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
301a00735e66f9ec42549da94eba3170e543b542904Jens Axboe
3022dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
303a00735e66f9ec42549da94eba3170e543b542904Jens Axboe
3042b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	/*
3052b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	 * For random IO, allow blockalign offset other than min_bs.
3062b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	 */
3072b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	if (!o->ba[DDIR_READ] || !td_random(td))
3082b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe		o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
3092b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	if (!o->ba[DDIR_WRITE] || !td_random(td))
3102b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe		o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
3112b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe
3122b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
3132b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	    o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE]) &&
3149bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe	    !o->norandommap) {
3152b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe		log_err("fio: Any use of blockalign= turns off randommap\n");
3169bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe		o->norandommap = 1;
317a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = warnings_fatal;
3182b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe	}
3192b7a01d01ea19f6e4090c7a8280bc6bf983e781fJens Axboe
3202dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (!o->file_size_high)
3212dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->file_size_high = o->file_size_low;
3229c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe
3238347239af0a361e160293100bfc053f88bbbf737Jens Axboe	if (o->norandommap && o->verify != VERIFY_NONE
3248347239af0a361e160293100bfc053f88bbbf737Jens Axboe	    && !fixed_block_size(o))  {
3258347239af0a361e160293100bfc053f88bbbf737Jens Axboe		log_err("fio: norandommap given for variable block sizes, "
3268347239af0a361e160293100bfc053f88bbbf737Jens Axboe			"verify disabled\n");
3272dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->verify = VERIFY_NONE;
328a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = warnings_fatal;
329bb8895e07c6d6417410545f45d34b1b7916cd90aJens Axboe	}
3302dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
331690adba373bb8c97a365c67da369e265953c4b4cJens Axboe		log_err("fio: bs_unaligned may not work with raw io\n");
332e0a223354342cc45a916b669343718b80a20c2eaJens Axboe
333e0a223354342cc45a916b669343718b80a20c2eaJens Axboe	/*
33448097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	 * thinktime_spin must be less than thinktime
33548097d5c61aa1718e6dd4b3b647ea2eb6f00fcfbJens Axboe	 */
3362dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->thinktime_spin > o->thinktime)
3372dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->thinktime_spin = o->thinktime;
338e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe
339e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	/*
340e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	 * The low water mark cannot be bigger than the iodepth
341e916b390684ec1ca6247f98138fa9c1682701d29Jens Axboe	 */
3422dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->iodepth_low > o->iodepth || !o->iodepth_low) {
3439467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		/*
3449467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 * syslet work around - if the workload is sequential,
3459467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 * we want to let the queue drain all the way down to
3469467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 * avoid seeking between async threads
3479467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		 */
3489467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
3492dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe			o->iodepth_low = 1;
3509467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe		else
3512dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe			o->iodepth_low = o->iodepth;
3529467b77c9ac41f09a93a8a984d21b94c1f7d515eJens Axboe	}
353cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe
354cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	/*
355cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	 * If batch number isn't set, default to the same as iodepth
356cb5ab5121ac4fa62e0ca2612b359f19bfdd30f29Jens Axboe	 */
3572dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
3582dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->iodepth_batch = o->iodepth;
359b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe
3602dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->nr_files > td->files_index)
3612dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->nr_files = td->files_index;
3629f9214f243701626a04b4a0f9aceec03b8b40e0fJens Axboe
3632dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (o->open_files > o->nr_files || !o->open_files)
3642dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		o->open_files = o->nr_files;
3654e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe
366581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	if (((o->rate[0] + o->rate[1]) && (o->rate_iops[0] + o->rate_iops[1]))||
367581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	    ((o->ratemin[0] + o->ratemin[1]) && (o->rate_iops_min[0] +
368581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe		o->rate_iops_min[1]))) {
3694e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe		log_err("fio: rate and rate_iops are mutually exclusive\n");
370a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = 1;
3714e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe	}
372581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	if ((o->rate[0] < o->ratemin[0]) || (o->rate[1] < o->ratemin[1]) ||
373581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	    (o->rate_iops[0] < o->rate_iops_min[0]) ||
374581e71417760e0aa86eac0acd704253ff0eeea4fJens Axboe	    (o->rate_iops[1] < o->rate_iops_min[1])) {
3754e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe		log_err("fio: minimum rate exceeds rate\n");
376a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = 1;
3774e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe	}
3784e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe
379cf4464ca60ce75ac241c621bc70a2500beeb782fJens Axboe	if (!o->timeout && o->time_based) {
380cf4464ca60ce75ac241c621bc70a2500beeb782fJens Axboe		log_err("fio: time_based requires a runtime/timeout setting\n");
381cf4464ca60ce75ac241c621bc70a2500beeb782fJens Axboe		o->time_based = 0;
382a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = warnings_fatal;
383cf4464ca60ce75ac241c621bc70a2500beeb782fJens Axboe	}
384cf4464ca60ce75ac241c621bc70a2500beeb782fJens Axboe
385aa31f1f108348ba2a8749c73fa8c25f3d4630a7cShawn Lewis	if (o->fill_device && !o->size)
3865921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe		o->size = -1ULL;
3875ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe
3889bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe	if (o->verify != VERIFY_NONE) {
389996936f995c47f4744a49e05419e7d4c0364c64eJens Axboe		if (td_write(td) && o->do_verify && o->numjobs > 1) {
390a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe			log_info("Multiple writers may overwrite blocks that "
391a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe				"belong to other jobs. This can cause "
392a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe				"verification failures.\n");
393a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe			ret = warnings_fatal;
394a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		}
395a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe
3969bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe		o->refill_buffers = 1;
3972f1b8e8b2efff5cf6887fc465f711391ab5b1825Jens Axboe		if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
3982f1b8e8b2efff5cf6887fc465f711391ab5b1825Jens Axboe		    !o->verify_interval)
3992f1b8e8b2efff5cf6887fc465f711391ab5b1825Jens Axboe			o->verify_interval = o->min_bs[DDIR_WRITE];
400d990588ef84dacb107971143c239565e149d6f73Jens Axboe	}
40141ccd84597867a36289392e59634d9fd7dc4c397Jens Axboe
4029bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe	if (o->pre_read) {
4039bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe		o->invalidate_cache = 0;
404a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		if (td->io_ops->flags & FIO_PIPEIO) {
4059c0d224129b0c59698e4c77e7fed00dc8cbb50e1Jens Axboe			log_info("fio: cannot pre-read files with an IO engine"
4069c0d224129b0c59698e4c77e7fed00dc8cbb50e1Jens Axboe				 " that isn't seekable. Pre-read disabled.\n");
407a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe			ret = warnings_fatal;
408a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		}
4099c0d224129b0c59698e4c77e7fed00dc8cbb50e1Jens Axboe	}
41034f1c044d361d04a576c3e7ed387fe064f9db5c6Jens Axboe
411e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune#ifndef FIO_HAVE_FDATASYNC
4129bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe	if (o->fdatasync_blocks) {
413e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune		log_info("fio: this platform does not support fdatasync()"
414e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune			 " falling back to using fsync().  Use the 'fsync'"
415e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune			 " option instead of 'fdatasync' to get rid of"
416e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune			 " this warning\n");
4179bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe		o->fsync_blocks = o->fdatasync_blocks;
4189bbf57cc80d915d8cc87240276334ddd5aaac547Jens Axboe		o->fdatasync_blocks = 0;
419a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		ret = warnings_fatal;
420e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune	}
421e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune#endif
422e72fa4d40565e7a213698d8696b81f80e4670982Joshua Aune
423a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe	return ret;
424e1f365035a952233463d85d659bd960ba78f012eJens Axboe}
425e1f365035a952233463d85d659bd960ba78f012eJens Axboe
426906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe/*
427f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe * This function leaks the buffer
428f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe */
429f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboestatic char *to_kmg(unsigned int val)
430f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe{
431f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	char *buf = malloc(32);
432f3502ba2dd72d846a388c774a01c6bb833871248Jens Axboe	char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
433f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	char *p = post;
434f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
435245142ff7554290cf666e3ef6b7b57512bf17d75Jens Axboe	do {
436f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe		if (val & 1023)
437f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe			break;
438f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
439f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe		val >>= 10;
440f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe		p++;
441245142ff7554290cf666e3ef6b7b57512bf17d75Jens Axboe	} while (*p);
442f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
443f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	snprintf(buf, 31, "%u%c", val, *p);
444f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe	return buf;
445f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe}
446f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
44709629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe/* External engines are specified by "external:name.o") */
44809629a90d5b68b220e3fb98318e2dcd019943edaJens Axboestatic const char *get_engine_name(const char *str)
44909629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe{
45009629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	char *p = strstr(str, ":");
45109629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe
45209629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	if (!p)
45309629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		return str;
45409629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe
45509629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	p++;
45609629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	strip_blank_front(&p);
45709629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	strip_blank_end(p);
45809629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	return p;
45909629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe}
46009629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe
461e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboestatic int exists_and_not_file(const char *filename)
462e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe{
463e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe	struct stat sb;
464e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe
465e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe	if (lstat(filename, &sb) == -1)
466e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe		return 0;
467e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe
468ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6feBruce Cran	/* \\.\ is the device namespace in Windows, where every file
469ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6feBruce Cran	 * is a device node */
470ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6feBruce Cran	if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
471e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe		return 0;
472e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe
473e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe	return 1;
474e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe}
475e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe
4764c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboestatic void td_fill_rand_seeds_os(struct thread_data *td)
4775bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe{
4785bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	os_random_seed(td->rand_seeds[0], &td->bsrange_state);
4795bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	os_random_seed(td->rand_seeds[1], &td->verify_state);
4805bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	os_random_seed(td->rand_seeds[2], &td->rwmix_state);
4815bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe
4825bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
4835bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe		os_random_seed(td->rand_seeds[3], &td->next_file_state);
4845bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe
4855bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	os_random_seed(td->rand_seeds[5], &td->file_size_state);
4860d29de831183dfd049c97a03008d425ce21e2fa4Jens Axboe	os_random_seed(td->rand_seeds[6], &td->trim_state);
4875bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe
4885bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	if (!td_random(td))
4895bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe		return;
4905bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe
4915bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	if (td->o.rand_repeatable)
4925bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe		td->rand_seeds[4] = FIO_RANDSEED * td->thread_number;
4935bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe
4945bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	os_random_seed(td->rand_seeds[4], &td->random_state);
4954c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe}
4964c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
4974c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboestatic void td_fill_rand_seeds_internal(struct thread_data *td)
4984c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe{
4994c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	init_rand_seed(&td->__bsrange_state, td->rand_seeds[0]);
5004c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	init_rand_seed(&td->__verify_state, td->rand_seeds[1]);
5014c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	init_rand_seed(&td->__rwmix_state, td->rand_seeds[2]);
5024c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
5034c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
5044c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe		init_rand_seed(&td->__next_file_state, td->rand_seeds[3]);
5054c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
5064c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	init_rand_seed(&td->__file_size_state, td->rand_seeds[5]);
5074c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	init_rand_seed(&td->__trim_state, td->rand_seeds[6]);
5084c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
5094c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	if (!td_random(td))
5104c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe		return;
5114c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
5124c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	if (td->o.rand_repeatable)
5134c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe		td->rand_seeds[4] = FIO_RANDSEED * td->thread_number;
5144c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
5152615cc4b28e7d0e436a625dff92e6a71ccc6c49bJens Axboe	init_rand_seed(&td->__random_state, td->rand_seeds[4]);
5165bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe}
5175bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe
5184c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboevoid td_fill_rand_seeds(struct thread_data *td)
5194c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe{
5204c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	if (td->o.use_os_rand)
5214c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe		td_fill_rand_seeds_os(td);
5224c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe	else
5234c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe		td_fill_rand_seeds_internal(td);
5243545a109a2cfe5ab22969ef453dc049db47f0b68Jens Axboe
5253545a109a2cfe5ab22969ef453dc049db47f0b68Jens Axboe	init_rand_seed(&td->buf_state, td->rand_seeds[7]);
5264c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe}
5274c07ad86c6cc6e158c70a5c625f60144db03f20dJens Axboe
528f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe/*
5299c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe * Initialize the various random states we need (random io, block size ranges,
5309c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe * read/write mix, etc).
5319c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe */
5329c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboestatic int init_random_state(struct thread_data *td)
5339c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe{
534687270767de17dbad53c50e03e5d73d52505405cJens Axboe	int fd;
5359c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe
5369c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	fd = open("/dev/urandom", O_RDONLY);
5379c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	if (fd == -1) {
5389c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe		td_verror(td, errno, "open");
5399c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe		return 1;
5409c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	}
5419c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe
5425bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	if (read(fd, td->rand_seeds, sizeof(td->rand_seeds)) <
5435bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	    (int) sizeof(td->rand_seeds)) {
5449c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe		td_verror(td, EIO, "read");
5459c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe		close(fd);
5469c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe		return 1;
5479c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	}
5489c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe
5499c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	close(fd);
5505bfc35d7abe2582dc54127ca1d6e03792c9d62f5Jens Axboe	td_fill_rand_seeds(td);
5519c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	return 0;
5529c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe}
5539c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe
5549c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe/*
555906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * Adds a job to the list of things todo. Sanitizes the various options
556906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * to make sure we don't have conflicts, and initializes various
557906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe * members of td.
558906c8d75eef9247c02d1f1f6771b6fa2338329faJens Axboe */
559751548451d969148529b642c05e7544726ec3b64Jens Axboestatic int add_job(struct thread_data *td, const char *jobname, int job_add_num)
560ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
561413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe	const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
562413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe				   "randread", "randwrite", "randrw" };
563af52b3455ad892322aab2791282b6bd4efdfdbf3Jens Axboe	unsigned int i;
56409629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	const char *engine;
565af52b3455ad892322aab2791282b6bd4efdfdbf3Jens Axboe	char fname[PATH_MAX];
566e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe	int numjobs, file_alloced;
567ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
568ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
569ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * the def_thread is just for options, it's not a real job
570ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
571ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td == &def_thread)
572ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
573ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
574cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	/*
575cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	 * if we are just dumping the output command line, don't add the job
576cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	 */
577cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	if (dump_cmdline) {
578cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		put_job(td);
579cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		return 0;
580cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	}
581cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe
58258c55ba02aca24ed30beb343fcb1dc3df4667389Jens Axboe	if (profile_td_init(td))
5836625155407de739e1e857419b7b4fb62f6c6bb2eJens Axboe		goto err;
58458c55ba02aca24ed30beb343fcb1dc3df4667389Jens Axboe
5852dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	engine = get_engine_name(td->o.ioengine);
58609629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	td->io_ops = load_ioengine(td, engine);
58709629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	if (!td->io_ops) {
58809629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe		log_err("fio: failed to load engine %s\n", engine);
589205927a3cfc25baeb318e3aedf3ac29d16bf4be9Jens Axboe		goto err;
59009629a90d5b68b220e3fb98318e2dcd019943edaJens Axboe	}
591df64119de537aba99c85d1dc80190b354589f8b9Jens Axboe
5922dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (td->o.use_thread)
5939cedf16704b71cec33138bb4cf524d3fc9ad338aJens Axboe		nr_thread++;
5949cedf16704b71cec33138bb4cf524d3fc9ad338aJens Axboe	else
5959cedf16704b71cec33138bb4cf524d3fc9ad338aJens Axboe		nr_process++;
5969cedf16704b71cec33138bb4cf524d3fc9ad338aJens Axboe
5972dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (td->o.odirect)
598690adba373bb8c97a365c67da369e265953c4b4cJens Axboe		td->io_ops->flags |= FIO_RAWIO;
599690adba373bb8c97a365c67da369e265953c4b4cJens Axboe
600e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe	file_alloced = 0;
601691c8fb014da9dd82e999a90b5511423f4eee188Jens Axboe	if (!td->o.filename && !td->files_index && !td->o.read_iolog_file) {
602e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe		file_alloced = 1;
60380be24f4671164d597463e4b5c794d4cbd0a4537Jens Axboe
6042dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		if (td->o.nr_files == 1 && exists_and_not_file(jobname))
605e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe			add_file(td, jobname);
6067b05a215c8c39b8c878297b90eba112fe9176542Jens Axboe		else {
6072dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe			for (i = 0; i < td->o.nr_files; i++) {
6085ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe				sprintf(fname, "%s.%d.%d", jobname,
6095ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe							td->thread_number, i);
6107b05a215c8c39b8c878297b90eba112fe9176542Jens Axboe				add_file(td, fname);
6117b05a215c8c39b8c878297b90eba112fe9176542Jens Axboe			}
612af52b3455ad892322aab2791282b6bd4efdfdbf3Jens Axboe		}
6130af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe	}
614ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
6154e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe	if (fixup_options(td))
6164e991c23d2d06484f581eb5e2105bc102cb35941Jens Axboe		goto err;
617e0a223354342cc45a916b669343718b80a20c2eaJens Axboe
61807eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe	if (td->io_ops->flags & FIO_DISKLESSIO) {
61907eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe		struct fio_file *f;
62007eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe
62107eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe		for_each_file(td, f, i)
62207eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe			f->real_file_size = -1ULL;
62307eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe	}
62407eb79dfa0e3801875d1c2907cfdb5da7c9d2cb3Jens Axboe
625cdd18ad87ed9a3639b76c41cfc9682ad7cce652eJens Axboe	td->mutex = fio_mutex_init(0);
626ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
627833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong	td->ts.clat_percentiles = td->o.clat_percentiles;
628833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong	if (td->o.overwrite_plist)
629833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong		td->ts.percentile_list = td->o.percentile_list;
630833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong	else
631833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong		td->ts.percentile_list = NULL;
632833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong
633756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe	td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
634756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe	td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
63502af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe	td->ts.lat_stat[0].min_val = td->ts.lat_stat[1].min_val = ULONG_MAX;
636756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe	td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
637cdd5411e02b05f5c9fd305a0f07f58e3abef4d5eAdam DeBellins	td->ddir_seq_nr = td->o.ddir_seq_nr;
638ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
639755c31896364ad2887c07e0383ce639d1f5b52abJens Axboe	if ((td->o.stonewall || td->o.new_group) && prev_group_jobs) {
6403c5df6fa2259c12fd6a7beb9a3521dec76d12dd2Jens Axboe		prev_group_jobs = 0;
641ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		groupid++;
6423c5df6fa2259c12fd6a7beb9a3521dec76d12dd2Jens Axboe	}
643ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
644ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->groupid = groupid;
6453c5df6fa2259c12fd6a7beb9a3521dec76d12dd2Jens Axboe	prev_group_jobs++;
646ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
6479c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe	if (init_random_state(td))
6489c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe		goto err;
6499c60ce649d3f976d196709d4399bb7c540ce97b5Jens Axboe
650ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (setup_rate(td))
651ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		goto err;
652ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
6532dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (td->o.write_lat_log) {
65402af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe		setup_log(&td->ts.lat_log);
655756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe		setup_log(&td->ts.slat_log);
656756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe		setup_log(&td->ts.clat_log);
657ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
6582dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (td->o.write_bw_log)
659756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe		setup_log(&td->ts.bw_log);
660ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
6612dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	if (!td->o.name)
6622dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		td->o.name = strdup(jobname);
66301452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe
664c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe	if (!terse_output) {
665b990b5c06801d6d25e3fcc5415efbbe7bb23341eJens Axboe		if (!job_add_num) {
6665ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe			if (!strcmp(td->io_ops->name, "cpuio")) {
6675ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe				log_info("%s: ioengine=cpu, cpuload=%u,"
6685ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe					 " cpucycle=%u\n", td->o.name,
6695ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe							td->o.cpuload,
6705ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe							td->o.cpucycle);
6715ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe			} else {
672f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				char *c1, *c2, *c3, *c4;
673f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
6742dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe				c1 = to_kmg(td->o.min_bs[DDIR_READ]);
6752dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe				c2 = to_kmg(td->o.max_bs[DDIR_READ]);
6762dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe				c3 = to_kmg(td->o.min_bs[DDIR_WRITE]);
6772dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe				c4 = to_kmg(td->o.max_bs[DDIR_WRITE]);
678f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
6795ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe				log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s,"
6805ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe					 " ioengine=%s, iodepth=%u\n",
6815ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe						td->o.name, td->groupid,
6825ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe						ddir_str[td->o.td_ddir],
6835ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe						c1, c2, c3, c4,
6845ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe						td->io_ops->name,
6855ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe						td->o.iodepth);
686f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe
687f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c1);
688f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c2);
689f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c3);
690f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe				free(c4);
691f8977ee606bc51138a77f6a1b653df00faa77742Jens Axboe			}
692b990b5c06801d6d25e3fcc5415efbbe7bb23341eJens Axboe		} else if (job_add_num == 1)
6936d86144dd10b05e8b82e9b895c35dd778e5e71abJens Axboe			log_info("...\n");
694c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe	}
695ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
696ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
697ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * recurse add identical jobs, clear numjobs and stonewall options
698ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * as they don't apply to sub-jobs
699ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
7002dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe	numjobs = td->o.numjobs;
701ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	while (--numjobs) {
702ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		struct thread_data *td_new = get_new_job(0, td);
703ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
704ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (!td_new)
705ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			goto err;
706ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
7072dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		td_new->o.numjobs = 1;
7082dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe		td_new->o.stonewall = 0;
70992c1d41f9cb4da2513ad261552f92511d69f6b8eJens Axboe		td_new->o.new_group = 0;
710e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe
711e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe		if (file_alloced) {
7122dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe			td_new->o.filename = NULL;
713e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe			td_new->files_index = 0;
7144e6ea2f1e9b7da6d7d1057670fcc19f063e46fd4Jens Axboe			td_new->files_size = 0;
715e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe			td_new->files = NULL;
716e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe		}
717e132cbae2cf26736af86fede134c14d41dae4a5aJens Axboe
718751548451d969148529b642c05e7544726ec3b64Jens Axboe		job_add_num = numjobs - 1;
719ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
720751548451d969148529b642c05e7544726ec3b64Jens Axboe		if (add_job(td_new, jobname, job_add_num))
721ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			goto err;
722ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
7233c5df6fa2259c12fd6a7beb9a3521dec76d12dd2Jens Axboe
724ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
725ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeerr:
726ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	put_job(td);
727ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return -1;
728ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
729ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
73079d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe/*
73179d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe * Parse as if 'o' was a command line
73279d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe */
73379d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboevoid add_job_opts(const char **o)
73479d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe{
73579d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	struct thread_data *td, *td_parent;
73679d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	int i, in_global = 1;
73779d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	char jobname[32];
73879d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe
73979d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	i = 0;
74079d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	td_parent = td = NULL;
74179d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	while (o[i]) {
74279d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		if (!strncmp(o[i], "name", 4)) {
74379d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			in_global = 0;
74479d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			if (td)
74579d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe				add_job(td, jobname, 0);
74679d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			td = NULL;
74779d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			sprintf(jobname, "%s", o[i] + 5);
74879d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		}
74979d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		if (in_global && !td_parent)
75079d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			td_parent = get_new_job(1, &def_thread);
75179d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		else if (!in_global && !td) {
75279d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			if (!td_parent)
75379d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe				td_parent = &def_thread;
75479d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			td = get_new_job(0, td_parent);
75579d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		}
75679d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		if (in_global)
75779d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			fio_options_parse(td_parent, (char **) &o[i], 1);
75879d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		else
75979d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe			fio_options_parse(td, (char **) &o[i], 1);
76079d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		i++;
76179d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	}
76279d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe
76379d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	if (td)
76479d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe		add_job(td, jobname, 0);
76579d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe}
76679d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe
76701f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboestatic int skip_this_section(const char *name)
76801f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe{
769ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe	int i;
770ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe
771ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe	if (!nr_job_sections)
77201f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe		return 0;
77301f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe	if (!strncmp(name, "global", 6))
77401f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe		return 0;
77501f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe
776ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe	for (i = 0; i < nr_job_sections; i++)
777ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe		if (!strcmp(job_sections[i], name))
778ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			return 0;
779ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe
780ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe	return 1;
78101f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe}
78201f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe
783ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int is_empty_or_comment(char *line)
784ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
785ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned int i;
786ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
787ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	for (i = 0; i < strlen(line); i++) {
788ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (line[i] == ';')
789ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1;
7905cc2da300b3fc30e00b79b4ddb3f372df3b2fe93Ingo Molnar		if (line[i] == '#')
7915cc2da300b3fc30e00b79b4ddb3f372df3b2fe93Ingo Molnar			return 1;
79276cd9378b90dddf2cedc9a5d49f317aaad485b90Jens Axboe		if (!isspace((int) line[i]) && !iscntrl((int) line[i]))
793ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 0;
794ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
795ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
796ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
797ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
798ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
799313cb206ffc6e50c089314d322ebf1c523f37531Jens Axboe/*
800072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe * This is our [ini] type file parser.
801072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe */
8021e97cce9f5a87a67293a05ec4533ed6968698b2eJens Axboestatic int parse_jobs_ini(char *file, int stonewall_flag)
803ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
804e1f365035a952233463d85d659bd960ba78f012eJens Axboe	unsigned int global;
805ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct thread_data *td;
806fee3bb48f748afe5cf10f8505e1efd36b87c627eJens Axboe	char *string, *name;
807ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	FILE *f;
808ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	char *p;
8090c7e37a04aa04ba22e812f8de7971fcef46b8191Jens Axboe	int ret = 0, stonewall;
810097b2991ace8e069dbfb0c2286d31da714247573Jens Axboe	int first_sect = 1;
811ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe	int skip_fgets = 0;
81201f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe	int inside_skip = 0;
8133b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe	char **opts;
8143b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe	int i, alloc_opts, num_opts;
815ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
8165a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll	if (!strcmp(file, "-"))
8175a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll		f = stdin;
8185a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll	else
8195a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll		f = fopen(file, "r");
8205a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll
821ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!f) {
822aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe		perror("fopen job file");
823ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
824ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
825ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
826ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	string = malloc(4096);
8277f7e6e59f48bbd754847c825075a9c46962e0116Jens Axboe
8287f7e6e59f48bbd754847c825075a9c46962e0116Jens Axboe	/*
8297f7e6e59f48bbd754847c825075a9c46962e0116Jens Axboe	 * it's really 256 + small bit, 280 should suffice
8307f7e6e59f48bbd754847c825075a9c46962e0116Jens Axboe	 */
8317f7e6e59f48bbd754847c825075a9c46962e0116Jens Axboe	name = malloc(280);
8327f7e6e59f48bbd754847c825075a9c46962e0116Jens Axboe	memset(name, 0, 280);
833ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
8343b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe	alloc_opts = 8;
8353b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe	opts = malloc(sizeof(char *) * alloc_opts);
836b7c6302da8b30f221310dd6c917136229ee5e688Jens Axboe	num_opts = 0;
8373b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe
8380c7e37a04aa04ba22e812f8de7971fcef46b8191Jens Axboe	stonewall = stonewall_flag;
8397c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe	do {
840ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		/*
841ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		 * if skip_fgets is set, we already have loaded a line we
842ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		 * haven't handled.
843ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		 */
844ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		if (!skip_fgets) {
845ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			p = fgets(string, 4095, f);
846ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			if (!p)
847ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe				break;
848ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		}
849cdc7f1936e07f3b51aaa96c589e43abd7fea0051gurudas pai
850ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe		skip_fgets = 0;
851cdc7f1936e07f3b51aaa96c589e43abd7fea0051gurudas pai		strip_blank_front(&p);
8526c7c7da18aa2ab744b9485482e64acd30f31da6dJens Axboe		strip_blank_end(p);
853cdc7f1936e07f3b51aaa96c589e43abd7fea0051gurudas pai
854ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (is_empty_or_comment(p))
855ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			continue;
85684dd18865235caa675424c62a4624618ff961d78Bruce Cran		if (sscanf(p, "[%255[^\n]]", name) != 1) {
85701f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			if (inside_skip)
85801f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe				continue;
8595ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe			log_err("fio: option <%s> outside of [] job section\n",
8605ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe									p);
861088b42076dcbadf4d61367e19e49cb0d12aaadd1Jens Axboe			break;
8626c7c7da18aa2ab744b9485482e64acd30f31da6dJens Axboe		}
863ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
8647a4b80a14c6ac6d47d486b1f5d1f166fa7065ee3Jens Axboe		name[strlen(name) - 1] = '\0';
8657a4b80a14c6ac6d47d486b1f5d1f166fa7065ee3Jens Axboe
86601f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe		if (skip_this_section(name)) {
86701f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			inside_skip = 1;
86801f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			continue;
86901f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe		} else
87001f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			inside_skip = 0;
87101f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe
872ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		global = !strncmp(name, "global", 6);
873ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
874cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		if (dump_cmdline) {
875097b2991ace8e069dbfb0c2286d31da714247573Jens Axboe			if (first_sect)
876097b2991ace8e069dbfb0c2286d31da714247573Jens Axboe				log_info("fio ");
877cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe			if (!global)
878cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe				log_info("--name=%s ", name);
879097b2991ace8e069dbfb0c2286d31da714247573Jens Axboe			first_sect = 0;
880cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		}
881cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe
882ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td = get_new_job(global, &def_thread);
88345410acb636e526575d62a037f81ade7916b738cJens Axboe		if (!td) {
88445410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = 1;
88545410acb636e526575d62a037f81ade7916b738cJens Axboe			break;
88645410acb636e526575d62a037f81ade7916b738cJens Axboe		}
887ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
888972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		/*
889972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		 * Seperate multiple job files by a stonewall
890972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		 */
891f94819192600fe35d03ebed26a803abdc2b9864cJens Axboe		if (!global && stonewall) {
8922dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe			td->o.stonewall = stonewall;
893972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			stonewall = 0;
894972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		}
895972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
8963b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		num_opts = 0;
8973b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		memset(opts, 0, alloc_opts * sizeof(char *));
8983b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe
899ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		while ((p = fgets(string, 4096, f)) != NULL) {
900ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (is_empty_or_comment(p))
901ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
902e1f365035a952233463d85d659bd960ba78f012eJens Axboe
903b6754f9d3f719627d8aae4c3e8f39212d9405f99Jens Axboe			strip_blank_front(&p);
9047c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe
905ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			/*
906ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			 * new section, break out and make sure we don't
907ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			 * fgets() a new line at the top.
908ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			 */
909ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			if (p[0] == '[') {
910ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe				skip_fgets = 1;
9117c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe				break;
912ccf8f1273301ccb286636ff169a7d47e09f47a90Jens Axboe			}
9137c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe
9144ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe			strip_blank_end(p);
915aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe
9163b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe			if (num_opts == alloc_opts) {
9173b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe				alloc_opts <<= 1;
9183b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe				opts = realloc(opts,
9193b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe						alloc_opts * sizeof(char *));
9203b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe			}
9213b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe
9223b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe			opts[num_opts] = strdup(p);
9233b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe			num_opts++;
924ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
925ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
9263b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		ret = fio_options_parse(td, opts, num_opts);
9273b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		if (!ret) {
9283b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe			if (dump_cmdline)
9293b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe				for (i = 0; i < num_opts; i++)
9303b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe					log_info("--%s ", opts[i]);
9313b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe
93245410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = add_job(td, name, 0);
9333b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		} else {
934b1508cf9ead36dc789a4e289f7522a070e57058cJens Axboe			log_err("fio: job %s dropped\n", name);
935b1508cf9ead36dc789a4e289f7522a070e57058cJens Axboe			put_job(td);
93645410acb636e526575d62a037f81ade7916b738cJens Axboe		}
9373b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe
9383b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		for (i = 0; i < num_opts; i++)
9393b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe			free(opts[i]);
9403b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		num_opts = 0;
9417c124ac153eebf48bc85f9033ae06fd7152e4216Jens Axboe	} while (!ret);
942ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
943cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	if (dump_cmdline)
944cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		log_info("\n");
945cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe
9463b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe	for (i = 0; i < num_opts; i++)
9473b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe		free(opts[i]);
9483b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe
949ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	free(string);
950ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	free(name);
9512577594dd6e2857d9efbf6bd81cd7ef507dbcd64Jens Axboe	free(opts);
9525a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll	if (f != stdin)
9535a729cbec53a158fa8d8dc5737749cfee20ab31bAaron Carroll		fclose(f);
95445410acb636e526575d62a037f81ade7916b738cJens Axboe	return ret;
955ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
956ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
957ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int fill_def_thread(void)
958ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
959ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(&def_thread, 0, sizeof(def_thread));
960ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
961375b2695693f56987e23deef3ded8e5b06ef6797Jens Axboe	fio_getaffinity(getpid(), &def_thread.o.cpumask);
962ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
963ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
964ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe	 * fill default options
965ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
966214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	fio_fill_default_options(&def_thread);
967ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
968ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
969ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
970214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboestatic void free_shm(void)
971214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe{
972214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	struct shmid_ds sbuf;
973214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
974214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	if (threads) {
9755e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		void *tp = threads;
9765e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe
977214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		threads = NULL;
9785e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		file_hash_exit();
9795e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		fio_debug_jobp = NULL;
9805e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		shmdt(tp);
981214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		shmctl(shm_id, IPC_RMID, &sbuf);
982214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	}
9832e5cdb118aeb26cb469a50f746b632676306f698Jens Axboe
9842e5cdb118aeb26cb469a50f746b632676306f698Jens Axboe	scleanup();
985214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe}
986214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
987214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe/*
988214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe * The thread area is shared between the main process and the job
989214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe * threads/processes. So setup a shared memory segment that will hold
990380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe * all the job info. We use the end of the region for keeping track of
991380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe * open files across jobs, for file sharing.
992214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe */
993214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboestatic int setup_thread_area(void)
994214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe{
995380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe	void *hash;
996380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe
997214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	/*
998214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	 * 1024 is too much on some machines, scale max_jobs if
999214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	 * we get a failure that looks like too large a shm segment
1000214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	 */
1001214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	do {
1002214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		size_t size = max_jobs * sizeof(struct thread_data);
1003214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
1004380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe		size += file_hash_size;
10055e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		size += sizeof(unsigned int);
1006380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe
1007214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		shm_id = shmget(0, size, IPC_CREAT | 0600);
1008214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		if (shm_id != -1)
1009214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe			break;
1010214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		if (errno != EINVAL) {
1011214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe			perror("shmget");
1012214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe			break;
1013214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		}
1014214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
1015214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		max_jobs >>= 1;
1016214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	} while (max_jobs);
1017214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
1018214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	if (shm_id == -1)
1019214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		return 1;
1020214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
1021214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	threads = shmat(shm_id, NULL, 0);
1022214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	if (threads == (void *) -1) {
1023214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		perror("shmat");
1024214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe		return 1;
1025214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	}
1026214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
10271f809d151ddc4a4c348c2e4f6007db510e3e08a2Jens Axboe	memset(threads, 0, max_jobs * sizeof(struct thread_data));
1028380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe	hash = (void *) threads + max_jobs * sizeof(struct thread_data);
10295e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe	fio_debug_jobp = (void *) hash + file_hash_size;
10305e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe	*fio_debug_jobp = -1;
1031380065aa652b87093d6bbd240e70db30bd6f193dJens Axboe	file_hash_init(hash);
1032214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	atexit(free_shm);
1033214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe	return 0;
1034214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe}
1035214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe
103645378b35a047b590d0d3b6f9a7b8fea6dfa47300Jens Axboestatic void usage(const char *name)
10374785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe{
10384361762833dee0f5c2840e348efaaf5967a2ab78Bruce Cran	printf("%s\n", fio_version_string);
103945378b35a047b590d0d3b6f9a7b8fea6dfa47300Jens Axboe	printf("%s [options] [job options] <job file(s)>\n", name);
1040ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	printf("\t--debug=options\tEnable debug logging\n");
1041b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--output\tWrite output to file\n");
1042b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--timeout\tRuntime in seconds\n");
1043b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--latency-log\tGenerate per-job latency logs\n");
1044b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1045b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--minimal\tMinimal (terse) output\n");
1046b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	printf("\t--version\tPrint version info and exit\n");
1047f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe	printf("\t--terse-version=x Terse version output format\n");
1048fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe	printf("\t--help\t\tPrint this page\n");
10495ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe	printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of"
10505ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe		" them\n");
1051cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe	printf("\t--showcmd\tTurn a job file into command line options\n");
1052e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll	printf("\t--eta=when\tWhen ETA estimate should be printed\n");
1053e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll	printf("\t          \tMay be \"always\", \"never\" or \"auto\"\n");
10545ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe	printf("\t--readonly\tTurn on safety read-only checks, preventing"
10555ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe		" writes\n");
105601f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe	printf("\t--section=name\tOnly run specified section in job file\n");
10572b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe	printf("\t--alloc-size=kb\tSet smalloc pool to this size in kb"
10582b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe		" (def 1024)\n");
1059a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe	printf("\t--warnings-fatal Fio parser warnings are fatal\n");
1060fca7035863bd570270376a0c06776e5549ff813eJens Axboe	printf("\t--max-jobs\tMaximum number of threads/processes to support\n");
1061aa58d2520204f5ae12291fae0289a90fb03dc587Jens Axboe	printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
1062aa58d2520204f5ae12291fae0289a90fb03dc587Jens Axboe	printf("\n                   Jens Axboe <jaxboe@fusionio.com>\n");
10634785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe}
10644785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe
106579e48f72dea1639bcbee310c354938287b6d5790Jens Axboe#ifdef FIO_INC_DEBUG
1066ee56ad500f6692381e131cc37299d23fa910a24aJens Axboestruct debug_level debug_levels[] = {
1067bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe	{ .name = "process",	.shift = FD_PROCESS, },
1068bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe	{ .name = "file",	.shift = FD_FILE, },
1069bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe	{ .name = "io",		.shift = FD_IO, },
1070bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe	{ .name = "mem",	.shift = FD_MEM, },
1071bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe	{ .name = "blktrace",	.shift = FD_BLKTRACE },
1072bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe	{ .name = "verify",	.shift = FD_VERIFY },
107384422acde41c9cf462245de115d425cf5a82124cJens Axboe	{ .name = "random",	.shift = FD_RANDOM },
1074a3d741fa3bc3120d5b62a56826a97524daa32803Jens Axboe	{ .name = "parse",	.shift = FD_PARSE },
1075cd991b9e36b18903f1564a4bfafdc83a9f165219Jens Axboe	{ .name = "diskutil",	.shift = FD_DISKUTIL },
10765e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe	{ .name = "job",	.shift = FD_JOB },
107729adda3ce304f16036cafee6c099aa08444a7db1Jens Axboe	{ .name = "mutex",	.shift = FD_MUTEX },
107879d16311c8d0c7188d73df77838fb1b4b6ff58dbJens Axboe	{ .name	= "profile",	.shift = FD_PROFILE },
1079c223da83e253b0057bb029bf4fbb55a05844215cJens Axboe	{ .name = "time",	.shift = FD_TIME },
108002444ad1868ee94c7c38810cc775784e6a9a5dbeJens Axboe	{ .name = NULL, },
1081ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe};
1082ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe
1083c09823ab5c841791025c564ecfc9ada0f850770bJens Axboestatic int set_debug(const char *string)
1084ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe{
1085ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	struct debug_level *dl;
1086ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	char *p = (char *) string;
1087ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	char *opt;
1088ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	int i;
1089ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe
1090ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	if (!strcmp(string, "?") || !strcmp(string, "help")) {
1091ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		log_info("fio: dumping debug options:");
1092ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		for (i = 0; debug_levels[i].name; i++) {
1093ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe			dl = &debug_levels[i];
1094ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe			log_info("%s,", dl->name);
1095ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		}
1096bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe		log_info("all\n");
1097c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe		return 1;
1098ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	}
1099ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe
1100ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	while ((opt = strsep(&p, ",")) != NULL) {
1101ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		int found = 0;
1102ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe
11035e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		if (!strncmp(opt, "all", 3)) {
11045e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			log_info("fio: set all debug options\n");
11055e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			fio_debug = ~0UL;
11065e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			continue;
11075e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe		}
11085e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe
1109ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		for (i = 0; debug_levels[i].name; i++) {
1110ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe			dl = &debug_levels[i];
11115e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			found = !strncmp(opt, dl->name, strlen(dl->name));
11125e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			if (!found)
11135e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				continue;
11145e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe
11155e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			if (dl->shift == FD_JOB) {
11165e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				opt = strchr(opt, ':');
11175e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				if (!opt) {
11185e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe					log_err("fio: missing job number\n");
11195e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe					break;
11205e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				}
11215e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				opt++;
11225e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				fio_debug_jobno = atoi(opt);
11235e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe				log_info("fio: set debug jobno %d\n",
11245e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe							fio_debug_jobno);
11255e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			} else {
1126ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe				log_info("fio: set debug option %s\n", opt);
1127bd6f78b2f0b6375383948f126368804612ec0035Jens Axboe				fio_debug |= (1UL << dl->shift);
1128ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe			}
11295e1d306e4f9a6337d07cc2d536d77c53e083226fJens Axboe			break;
1130ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		}
1131ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe
1132ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		if (!found)
1133ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe			log_err("fio: debug mask %s not found\n", opt);
1134ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe	}
1135c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe	return 0;
1136ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe}
113779e48f72dea1639bcbee310c354938287b6d5790Jens Axboe#else
113869b98d4c9945bed6b3446a9e73bfaf8e557cf033Jens Axboestatic int set_debug(const char *string)
113979e48f72dea1639bcbee310c354938287b6d5790Jens Axboe{
114079e48f72dea1639bcbee310c354938287b6d5790Jens Axboe	log_err("fio: debug tracing not included in build\n");
1141c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe	return 1;
114279e48f72dea1639bcbee310c354938287b6d5790Jens Axboe}
114379e48f72dea1639bcbee310c354938287b6d5790Jens Axboe#endif
11449ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe
11454c6107ff4db87f50545bad515543f5024bb39e4aJens Axboestatic void fio_options_fill_optstring(void)
11464c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe{
11474c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	char *ostr = cmd_optstr;
11484c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	int i, c;
11494c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe
11504c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	c = i = 0;
11514c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	while (l_opts[i].name) {
11524c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe		ostr[c++] = l_opts[i].val;
11534c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe		if (l_opts[i].has_arg == required_argument)
11544c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe			ostr[c++] = ':';
11554c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe		else if (l_opts[i].has_arg == optional_argument) {
11564c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe			ostr[c++] = ':';
11574c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe			ostr[c++] = ':';
11584c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe		}
11594c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe		i++;
11604c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	}
11614c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	ostr[c] = '\0';
11624c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe}
11634c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe
1164972cfd2546081c0397447ca9243ea419b1ff579aJens Axboestatic int parse_cmd_line(int argc, char *argv[])
1165ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1166b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	struct thread_data *td = NULL;
1167c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe	int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
11684c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	char *ostr = cmd_optstr;
1169ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
11704c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
1171ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		switch (c) {
11722b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe		case 'a':
11732b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe			smalloc_pool_size = atoi(optarg);
11742b386d2569c9078ca9790c4e6d318ec3835b8739Jens Axboe			break;
1175b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 't':
1176ab2cabdb2c67d8b90c94c1a95f7a2286a0f818b9Jens Axboe			def_thread.o.timeout = atoi(optarg);
1177b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1178b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'l':
1179b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			write_lat_log = 1;
1180b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
11813d73e5a9549d30324d1c5e31eb644077380c0b95Jens Axboe		case 'b':
1182b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			write_bw_log = 1;
1183b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1184b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'o':
1185b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			f_out = fopen(optarg, "w+");
1186b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			if (!f_out) {
1187b46928282e0a890f49250e79b81af773a2b7108fJens Axboe				perror("fopen output");
1188b46928282e0a890f49250e79b81af773a2b7108fJens Axboe				exit(1);
1189b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			}
1190b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			f_err = f_out;
1191b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1192b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'm':
1193b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			terse_output = 1;
1194b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1195b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'h':
119645378b35a047b590d0d3b6f9a7b8fea6dfa47300Jens Axboe			usage(argv[0]);
1197b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			exit(0);
1198fd28ca4948aa67b76585c6c23d7f70a2cdc7a0d5Jens Axboe		case 'c':
1199214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe			exit(fio_show_option_help(optarg));
1200cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		case 's':
1201cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe			dump_cmdline = 1;
1202cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe			break;
1203724e4435c1374e97309b122429ad9291744966c0Jens Axboe		case 'r':
1204724e4435c1374e97309b122429ad9291744966c0Jens Axboe			read_only = 1;
1205724e4435c1374e97309b122429ad9291744966c0Jens Axboe			break;
1206b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case 'v':
1207ca740f4e2bdab2a94a8b6ddecba6dde605fbc866Jens Axboe			log_info("%s\n", fio_version_string);
1208b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			exit(0);
1209f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe		case 'V':
1210f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe			terse_version = atoi(optarg);
1211f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe			if (terse_version != 2) {
1212f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe				log_err("fio: bad terse version format\n");
1213f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe				exit_val = 1;
1214f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe				do_exit++;
1215f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe			}
1216f57a9c59e366aa2f0621aa260bfd5ef5aeb61643Jens Axboe			break;
1217e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll		case 'e':
1218e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll			if (!strcmp("always", optarg))
1219e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll				eta_print = FIO_ETA_ALWAYS;
1220e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll			else if (!strcmp("never", optarg))
1221e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll				eta_print = FIO_ETA_NEVER;
1222e592a06b36999bbb30675a4a58d4ff16ed65e555Aaron Carroll			break;
1223ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe		case 'd':
1224c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe			if (set_debug(optarg))
1225c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe				do_exit++;
1226ee56ad500f6692381e131cc37299d23fa910a24aJens Axboe			break;
1227ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe		case 'x': {
1228ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			size_t new_size;
1229ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe
123001f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			if (!strcmp(optarg, "global")) {
12315ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe				log_err("fio: can't use global as only "
12325ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe					"section\n");
1233c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe				do_exit++;
1234c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe				exit_val = 1;
123501f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe				break;
123601f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			}
1237ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			new_size = (nr_job_sections + 1) * sizeof(char *);
1238ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			job_sections = realloc(job_sections, new_size);
1239ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			job_sections[nr_job_sections] = strdup(optarg);
1240ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			nr_job_sections++;
124101f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe			break;
1242ad0a273593b93f61e72fbdf1910fcf8cdcac738cJens Axboe			}
12439ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe		case 'p':
124407b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboe			exec_profile = strdup(optarg);
12459ac8a797da61a59c9fa1b59f8574246555403d19Jens Axboe			break;
1246b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		case FIO_GETOPT_JOB: {
12475ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe			const char *opt = l_opts[lidx].name;
1248b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			char *val = optarg;
1249b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1250c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe			if (!strncmp(opt, "name", 4) && td) {
12512dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe				ret = add_job(td, td->o.name ?: "fio", 0);
12526625155407de739e1e857419b7b4fb62f6c6bb2eJens Axboe				if (ret)
1253c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe					return 0;
1254c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				td = NULL;
1255c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe			}
1256b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			if (!td) {
125701f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe				int is_section = !strncmp(opt, "name", 4);
12583106f220e1710d7e53cb7bd0dbc7dac4584af463Jens Axboe				int global = 0;
12593106f220e1710d7e53cb7bd0dbc7dac4584af463Jens Axboe
126001f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe				if (!is_section || !strncmp(val, "global", 6))
12613106f220e1710d7e53cb7bd0dbc7dac4584af463Jens Axboe					global = 1;
1262c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe
126301f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe				if (is_section && skip_this_section(val))
126401f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe					continue;
126501f06b63ba67d3bc7fa11766d9f13d229c4cec5cJens Axboe
1266c2b1e753ca7abaca7f177cb1ca5087ca3971542bJens Axboe				td = get_new_job(global, &def_thread);
1267b46928282e0a890f49250e79b81af773a2b7108fJens Axboe				if (!td)
1268b46928282e0a890f49250e79b81af773a2b7108fJens Axboe					return 0;
1269b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			}
127038d0adb0d129e2eef7bf21e85ba4758c3789cb8eJens Axboe
1271214e1ecae844a32bf8f66d19132f4948d922dceeJens Axboe			ret = fio_cmd_option_parse(td, opt, val);
1272b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1273b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		}
1274a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe		case 'w':
1275a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe			warnings_fatal = 1;
1276a9523c6f4a43e4bbf942ee49068fe4f052c6991dJens Axboe			break;
1277fca7035863bd570270376a0c06776e5549ff813eJens Axboe		case 'j':
1278fca7035863bd570270376a0c06776e5549ff813eJens Axboe			max_jobs = atoi(optarg);
1279fca7035863bd570270376a0c06776e5549ff813eJens Axboe			if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
1280fca7035863bd570270376a0c06776e5549ff813eJens Axboe				log_err("fio: invalid max jobs: %d\n", max_jobs);
1281fca7035863bd570270376a0c06776e5549ff813eJens Axboe				do_exit++;
1282fca7035863bd570270376a0c06776e5549ff813eJens Axboe				exit_val = 1;
1283fca7035863bd570270376a0c06776e5549ff813eJens Axboe			}
1284fca7035863bd570270376a0c06776e5549ff813eJens Axboe			break;
1285b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		default:
1286c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe			do_exit++;
1287c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe			exit_val = 1;
1288b46928282e0a890f49250e79b81af773a2b7108fJens Axboe			break;
1289ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
1290ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1291c9fad893e8333682d6ab67a269b0dd74f303c5bcJens Axboe
1292c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe	if (do_exit)
1293c09823ab5c841791025c564ecfc9ada0f850770bJens Axboe		exit(exit_val);
1294536582bf89bb97eb3636e41470f303877a738810Jens Axboe
1295b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	if (td) {
12967d6a8904cc2973a857f4bb50f85e7c75375c553dJens Axboe		if (!ret)
12972dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe			ret = add_job(td, td->o.name ?: "fio", 0);
1298972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	}
1299774a617767830b5023f6cad4a45609a92ec82d41Jens Axboe
1300b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	while (optind < argc) {
1301b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		ini_idx++;
1302b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1303b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		ini_file[ini_idx - 1] = strdup(argv[optind]);
1304b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		optind++;
1305eb8bbf48e79a8c6afd3c84e3d64263d10ee45daaJens Axboe	}
1306972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
1307972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	return ini_idx;
1308ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1309ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1310ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint parse_options(int argc, char *argv[])
1311ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1312972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	int job_files, i;
1313972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe
1314b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	f_out = stdout;
1315b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	f_err = stderr;
1316b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
13174c6107ff4db87f50545bad515543f5024bb39e4aJens Axboe	fio_options_fill_optstring();
13185ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe	fio_options_dup_and_init(l_opts);
1319b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1320ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (setup_thread_area())
1321ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1322ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fill_def_thread())
1323ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1324ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1325972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	job_files = parse_cmd_line(argc, argv);
1326ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1327972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	for (i = 0; i < job_files; i++) {
1328972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe		if (fill_def_thread())
1329972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			return 1;
13300c7e37a04aa04ba22e812f8de7971fcef46b8191Jens Axboe		if (parse_jobs_ini(ini_file[i], i))
1331972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe			return 1;
133288c6ed8085efd1403fd34072311991cb666a5b9eJens Axboe		free(ini_file[i]);
1333972cfd2546081c0397447ca9243ea419b1ff579aJens Axboe	}
1334ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
133588c6ed8085efd1403fd34072311991cb666a5b9eJens Axboe	free(ini_file);
1336d23bb327374520295509bbd98912c8091b701a3eJens Axboe	options_mem_free(&def_thread);
1337b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1338b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	if (!thread_number) {
1339cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe		if (dump_cmdline)
1340cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe			return 0;
134107b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboe		if (exec_profile)
134207b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboe			return 0;
1343cca73aa73328c3cb4d78adf1e54345701eff29fdJens Axboe
134403e20d687566753b90383571e5e152c5142bdffdBruce Cran		log_err("No jobs(s) defined\n\n");
134545378b35a047b590d0d3b6f9a7b8fea6dfa47300Jens Axboe		usage(argv[0]);
1346b46928282e0a890f49250e79b81af773a2b7108fJens Axboe		return 1;
1347b46928282e0a890f49250e79b81af773a2b7108fJens Axboe	}
1348b46928282e0a890f49250e79b81af773a2b7108fJens Axboe
1349be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe	if (def_thread.o.gtod_offload) {
1350be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe		fio_gtod_init();
1351be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe		fio_gtod_offload = 1;
1352be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe		fio_gtod_cpu = def_thread.o.gtod_cpu;
1353be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe	}
1354be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe
1355ca740f4e2bdab2a94a8b6ddecba6dde605fbc866Jens Axboe	log_info("%s\n", fio_version_string);
1356ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1357ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1358