init.c revision 2c0ecd28459b6a1b236c865defb5ef76ce8bfa02
1ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <stdio.h>
2ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <stdlib.h>
3ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <unistd.h>
4ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <fcntl.h>
5ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <ctype.h>
6ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <string.h>
7ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <errno.h>
8ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/ipc.h>
9ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/shm.h>
10ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/types.h>
11ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <sys/stat.h>
12ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
13ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "fio.h"
14ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1520dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_BS			(4096)
1620dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_TIMEOUT		(0)
1720dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_RATE_CYCLE		(1000)
1820dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_ODIRECT		(1)
1920dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_IO_ENGINE		(FIO_SYNCIO)
20ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define DEF_IO_ENGINE_NAME	"sync"
2120dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_SEQUENTIAL		(1)
2220dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_RAND_REPEAT		(1)
2320dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_OVERWRITE		(1)
2420dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_CREATE		(1)
2520dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_INVALIDATE		(1)
2620dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_SYNCIO		(0)
2720dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_RANDSEED		(0xb1899bedUL)
2820dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_BWAVGTIME		(500)
2920dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_CREATE_SER		(1)
30ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define DEF_CREATE_FSYNC	(1)
3120dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_LOOPS		(1)
3220dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_VERIFY		(0)
3320dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_STONEWALL		(0)
3420dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_NUMJOBS		(1)
3520dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_USE_THREAD		(0)
3620dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_FILE_SIZE		(1024 * 1024 * 1024UL)
3720dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_ZONE_SIZE		(0)
3820dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe#define DEF_ZONE_SKIP		(0)
39a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe#define DEF_RWMIX_CYCLE		(500)
40a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe#define DEF_RWMIX_READ		(50)
41b6f4d8804ad499adf10b4cad0657284a8a4a6287Jens Axboe#define DEF_NICE		(0)
42ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
43573275e7e119984e895d709f95cffc399bd39db8Jens Axboestatic char fio_version_string[] = "fio 1.4";
44ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
45ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int repeatable = DEF_RAND_REPEAT;
46ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic char *ini_file;
47ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int max_jobs = MAX_JOBS;
48ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
49ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestruct thread_data def_thread;
50ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestruct thread_data *threads = NULL;
51ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
52ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint rate_quit = 0;
53ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint write_lat_log = 0;
54ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint write_bw_log = 0;
55ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint exitall_on_terminate = 0;
56c04f7ec3ecb8ce780bde6ad3515f003e6015c62aJens Axboeunsigned long long mlock_size = 0;
57ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
58ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic struct thread_data *get_new_job(int global, struct thread_data *parent)
59ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
60ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct thread_data *td;
61ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
62ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (global)
63ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return &def_thread;
64ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (thread_number >= max_jobs)
65ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return NULL;
66ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
67ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td = &threads[thread_number++];
68ddaeaa5ab1e3f1cb6f35a9f4a18ee932151a0ab8Jens Axboe	*td = *parent;
69ddaeaa5ab1e3f1cb6f35a9f4a18ee932151a0ab8Jens Axboe	td->name[0] = '\0';
70ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
71ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->fd = -1;
72ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->thread_number = thread_number;
73ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
74ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return td;
75ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
76ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
77ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void put_job(struct thread_data *td)
78ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
79ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(&threads[td->thread_number - 1], 0, sizeof(*td));
80ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	thread_number--;
81ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
82ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
83751548451d969148529b642c05e7544726ec3b64Jens Axboestatic int add_job(struct thread_data *td, const char *jobname, int job_add_num)
84ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
853d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe	char *ddir_str[] = { "read", "write", "randread", "randwrite",
863d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe			     "rw", NULL, "randrw" };
87ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct stat sb;
88ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	int numjobs, ddir;
89ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
90ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_LIBAIO
91ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->io_engine == FIO_LIBAIO) {
92ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		fprintf(stderr, "Linux libaio not available\n");
93ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
94ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
95ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
96ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_POSIXAIO
97ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->io_engine == FIO_POSIXAIO) {
98ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		fprintf(stderr, "posix aio not available\n");
99ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
100ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
101ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
102ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
103ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
104ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * the def_thread is just for options, it's not a real job
105ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
106ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td == &def_thread)
107ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
108ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
109ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->io_engine & FIO_SYNCIO)
110ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->iodepth = 1;
111ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	else {
112ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (!td->iodepth)
113ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			td->iodepth = 1;
114ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
115ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
11620dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe	/*
11720dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe	 * only really works for sequential io for now
11820dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe	 */
11920dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe	if (td->zone_size && !td->sequential)
12020dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe		td->zone_size = 0;
12120dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe
122ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->filetype = FIO_TYPE_FILE;
1230af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe	if (!stat(jobname, &sb)) {
1240af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe		if (S_ISBLK(sb.st_mode))
1250af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe			td->filetype = FIO_TYPE_BD;
1260af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe		else if (S_ISCHR(sb.st_mode))
1270af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe			td->filetype = FIO_TYPE_CHAR;
1280af7b542b69af5ab2400a9960a5bcde82c05723fJens Axboe	}
129ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
130ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->filetype == FIO_TYPE_FILE) {
131e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe		char tmp[PATH_MAX];
132e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe
133ef899b6393c43abd655ad2cbc22de18b88a101f8Jens Axboe		if (td->directory && td->directory[0] != '\0')
134e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			sprintf(tmp, "%s/%s.%d", td->directory, jobname, td->jobnum);
135ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		else
136e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			sprintf(tmp, "%s.%d", jobname, td->jobnum);
137e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe		td->file_name = strdup(tmp);
138ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else
139e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe		td->file_name = strdup(jobname);
140ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
141bbfd6b00dea4daee05133c8cb991b78d091df9aeJens Axboe	fio_sem_init(&td->mutex, 0);
142ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
143ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
144ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
145ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
146ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
147ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->min_bs == -1U)
148ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->min_bs = td->bs;
149ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->max_bs == -1U)
150ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->max_bs = td->bs;
1513d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe	if (td_read(td) && !td_rw(td))
152ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->verify = 0;
153ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
154ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->stonewall && td->thread_number > 1)
155ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		groupid++;
156ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
157ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->groupid = groupid;
158ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
159ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (setup_rate(td))
160ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		goto err;
161ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
162ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (write_lat_log) {
163ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		setup_log(&td->slat_log);
164ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		setup_log(&td->clat_log);
165ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
166ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (write_bw_log)
167ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		setup_log(&td->bw_log);
168ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
16901452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe	if (td->name[0] == '\0')
17001452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe		snprintf(td->name, sizeof(td->name)-1, "client%d", td->thread_number);
17101452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe
1723d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe	ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
173751548451d969148529b642c05e7544726ec3b64Jens Axboe
174751548451d969148529b642c05e7544726ec3b64Jens Axboe	if (!job_add_num)
17501452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe		printf("%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_engine_name, td->iodepth);
176751548451d969148529b642c05e7544726ec3b64Jens Axboe	else if (job_add_num == 1)
177751548451d969148529b642c05e7544726ec3b64Jens Axboe		printf("...\n");
178ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
179ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
180ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * recurse add identical jobs, clear numjobs and stonewall options
181ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * as they don't apply to sub-jobs
182ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
183ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	numjobs = td->numjobs;
184ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	while (--numjobs) {
185ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		struct thread_data *td_new = get_new_job(0, td);
186ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
187ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (!td_new)
188ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			goto err;
189ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
190ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td_new->numjobs = 1;
191ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td_new->stonewall = 0;
192eba09dd3809a1af93de79996cf9945f7b895f35fJens Axboe		td_new->jobnum = numjobs;
193751548451d969148529b642c05e7544726ec3b64Jens Axboe		job_add_num = numjobs - 1;
194ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
195751548451d969148529b642c05e7544726ec3b64Jens Axboe		if (add_job(td_new, jobname, job_add_num))
196ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			goto err;
197ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
198ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
199ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeerr:
200ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	put_job(td);
201ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return -1;
202ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
203ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
204ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint init_random_state(struct thread_data *td)
205ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
206a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe	unsigned long seeds[4];
207ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	int fd, num_maps, blocks;
208ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
2091ac267bb7dd678fa12bb3573c29cff5238ef9ccfJens Axboe	fd = open("/dev/urandom", O_RDONLY);
210ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fd == -1) {
211ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td_verror(td, errno);
212ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
213ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
214ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
215a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe	if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
216ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td_verror(td, EIO);
217ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		close(fd);
218ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
219ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
220ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
221ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	close(fd);
222ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
2236dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[0], &td->bsrange_state);
2246dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[1], &td->verify_state);
2256dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[2], &td->rwmix_state);
226ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
227ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (td->sequential)
228ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
229ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
230ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (repeatable)
231a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe		seeds[3] = DEF_RANDSEED;
232ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
233ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	blocks = (td->io_size + td->min_bs - 1) / td->min_bs;
234ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	num_maps = blocks / BLOCKS_PER_MAP;
235ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->file_map = malloc(num_maps * sizeof(long));
236ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	td->num_maps = num_maps;
237ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(td->file_map, 0, num_maps * sizeof(long));
238ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
2396dfd46b99af38cc1e5f702f53c59212129fe615eJens Axboe	os_random_seed(seeds[3], &td->random_state);
240ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
241ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
242ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
243ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
244ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
245ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_CPU_AFFINITY
246ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned int i;
247ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
248ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	CPU_ZERO(&cpumask);
249ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
250ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	for (i = 0; i < sizeof(int) * 8; i++) {
251ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if ((1 << i) & cpu)
252ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			CPU_SET(i, &cpumask);
253ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
254ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
255ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
256ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
257ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic unsigned long get_mult(char c)
258ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
259ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	switch (c) {
260ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		case 'k':
261ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		case 'K':
262ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1024;
263ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		case 'm':
264ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		case 'M':
265ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1024 * 1024;
266ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		case 'g':
267ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		case 'G':
268ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1024 * 1024 * 1024;
269ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		default:
270ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1;
271ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
272ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
273ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
274ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe/*
275ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe * convert string after '=' into decimal value, noting any size suffix
276ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe */
277ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int str_cnv(char *p, unsigned long long *val)
278ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
279ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	char *str;
280ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	int len;
281ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
282f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	str = strchr(p, '=');
283ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!str)
284ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
285ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
286ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	str++;
287ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	len = strlen(str);
288ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
289ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	*val = strtoul(str, NULL, 10);
290ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (*val == ULONG_MAX && errno == ERANGE)
291ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
292ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
2939d0d424761eeff6e8a88103c23d9bdf481a97d8eJens Axboe	*val *= get_mult(str[len - 1]);
294ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
295ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
296ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
297ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int check_strcnv(char *p, char *name, unsigned long long *val)
298ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
29920dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe	if (strncmp(p, name, strlen(name) - 1))
300ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
301ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
302ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return str_cnv(p, val);
303ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
304ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
305ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void strip_blank_front(char **p)
306ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
307ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	char *s = *p;
308ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
3094ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe	while (isspace(*s))
310ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		s++;
311ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
312ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
313ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void strip_blank_end(char *p)
314ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
3154ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe	char *s = p + strlen(p) - 1;
316ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
3174ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe	while (isspace(*s) || iscntrl(*s))
3184ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe		s--;
319aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe
3204ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe	*(s + 1) = '\0';
321aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe}
322aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe
323ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboetypedef int (str_cb_fn)(struct thread_data *, char *);
324ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
325ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
326ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
327843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	char *s;
328ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
329843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	if (strncmp(p, name, strlen(name)))
330843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe		return 1;
331843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe
332843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	s = strstr(p, name);
333ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!s)
334ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
335ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
336f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	s = strchr(s, '=');
337ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!s)
338ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
339ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
340ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	s++;
341ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	strip_blank_front(&s);
342ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return cb(td, s);
343ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
344ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
345ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int check_strstore(char *p, char *name, char *dest)
346ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
347843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	char *s;
348ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
349843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	if (strncmp(p, name, strlen(name)))
350843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe		return 1;
351843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe
352843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	s = strstr(p, name);
353ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!s)
354ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
355ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
356f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	s = strchr(p, '=');
357ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!s)
358ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
359ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
360ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	s++;
361ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	strip_blank_front(&s);
362ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
363ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	strcpy(dest, s);
364ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
365ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
366ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
36701617be6d951cf10dd92783e61b4393404544e47Jens Axboestatic int __check_range(char *str, unsigned long *val)
368ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
36901617be6d951cf10dd92783e61b4393404544e47Jens Axboe	char suffix;
370ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
37101617be6d951cf10dd92783e61b4393404544e47Jens Axboe	if (sscanf(str, "%lu%c", val, &suffix) == 2) {
37201617be6d951cf10dd92783e61b4393404544e47Jens Axboe		*val *= get_mult(suffix);
373ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
374ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
375ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
37601617be6d951cf10dd92783e61b4393404544e47Jens Axboe	if (sscanf(str, "%lu", val) == 1)
377ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
378ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
37901617be6d951cf10dd92783e61b4393404544e47Jens Axboe	return 1;
38001617be6d951cf10dd92783e61b4393404544e47Jens Axboe}
38101617be6d951cf10dd92783e61b4393404544e47Jens Axboe
38201617be6d951cf10dd92783e61b4393404544e47Jens Axboestatic int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
38301617be6d951cf10dd92783e61b4393404544e47Jens Axboe{
38401617be6d951cf10dd92783e61b4393404544e47Jens Axboe	char option[128];
38501617be6d951cf10dd92783e61b4393404544e47Jens Axboe	char *str, *p1, *p2;
38601617be6d951cf10dd92783e61b4393404544e47Jens Axboe
387843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe	if (strncmp(p, name, strlen(name)))
388843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe		return 1;
389843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe
39001617be6d951cf10dd92783e61b4393404544e47Jens Axboe	strcpy(option, p);
39101617be6d951cf10dd92783e61b4393404544e47Jens Axboe	p = option;
39201617be6d951cf10dd92783e61b4393404544e47Jens Axboe
39301617be6d951cf10dd92783e61b4393404544e47Jens Axboe	str = strstr(p, name);
39401617be6d951cf10dd92783e61b4393404544e47Jens Axboe	if (!str)
39501617be6d951cf10dd92783e61b4393404544e47Jens Axboe		return 1;
396ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
39701617be6d951cf10dd92783e61b4393404544e47Jens Axboe	p += strlen(name);
39801617be6d951cf10dd92783e61b4393404544e47Jens Axboe
39901617be6d951cf10dd92783e61b4393404544e47Jens Axboe	str = strchr(p, '=');
40001617be6d951cf10dd92783e61b4393404544e47Jens Axboe	if (!str)
40101617be6d951cf10dd92783e61b4393404544e47Jens Axboe		return 1;
40201617be6d951cf10dd92783e61b4393404544e47Jens Axboe
40301617be6d951cf10dd92783e61b4393404544e47Jens Axboe	/*
40401617be6d951cf10dd92783e61b4393404544e47Jens Axboe	 * 'p' now holds whatever is after the '=' sign
40501617be6d951cf10dd92783e61b4393404544e47Jens Axboe	 */
40601617be6d951cf10dd92783e61b4393404544e47Jens Axboe	p1 = str + 1;
40701617be6d951cf10dd92783e61b4393404544e47Jens Axboe
40801617be6d951cf10dd92783e61b4393404544e47Jens Axboe	/*
40901617be6d951cf10dd92783e61b4393404544e47Jens Axboe	 * terminate p1 at the '-' sign
41001617be6d951cf10dd92783e61b4393404544e47Jens Axboe	 */
41101617be6d951cf10dd92783e61b4393404544e47Jens Axboe	p = strchr(p1, '-');
41201617be6d951cf10dd92783e61b4393404544e47Jens Axboe	if (!p)
41301617be6d951cf10dd92783e61b4393404544e47Jens Axboe		return 1;
41401617be6d951cf10dd92783e61b4393404544e47Jens Axboe
41501617be6d951cf10dd92783e61b4393404544e47Jens Axboe	p2 = p + 1;
41601617be6d951cf10dd92783e61b4393404544e47Jens Axboe	*p = '\0';
41701617be6d951cf10dd92783e61b4393404544e47Jens Axboe
41801617be6d951cf10dd92783e61b4393404544e47Jens Axboe	if (!__check_range(p1, s) && !__check_range(p2, e))
419ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
420ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
421ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
422ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
423ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
424ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int check_int(char *p, char *name, unsigned int *val)
425ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
426f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	char *str;
427ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
428b6754f9d3f719627d8aae4c3e8f39212d9405f99Jens Axboe	if (strncmp(p, name, strlen(name)))
429b6754f9d3f719627d8aae4c3e8f39212d9405f99Jens Axboe		return 1;
430b6754f9d3f719627d8aae4c3e8f39212d9405f99Jens Axboe
431f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	str = strstr(p, name);
432f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	if (!str)
433f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe		return 1;
434f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe
435f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	str = strchr(p, '=');
436f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	if (!str)
437f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe		return 1;
438f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe
439f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	str++;
440ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
441f5d3e5ec43653859e744225cc585757e77e4dbdcJens Axboe	if (sscanf(str, "%u", val) == 1)
442ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
443ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
444ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
445ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
446ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
447ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int check_strset(char *p, char *name)
448ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
449ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return strncmp(p, name, strlen(name));
450ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
451ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
452ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int is_empty_or_comment(char *line)
453ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
454ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned int i;
455ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
456ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	for (i = 0; i < strlen(line); i++) {
457ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (line[i] == ';')
458ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 1;
459ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (!isspace(line[i]) && !iscntrl(line[i]))
460ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			return 0;
461ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
462ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
463ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
464ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
465ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
466ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int str_rw_cb(struct thread_data *td, char *mem)
467ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
468ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
469ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->ddir = DDIR_READ;
470ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->sequential = 1;
471ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
472ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "randread", 8)) {
473ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->ddir = DDIR_READ;
474ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->sequential = 0;
475ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
476ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
477ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->ddir = DDIR_WRITE;
478ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->sequential = 1;
479ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
480ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "randwrite", 9)) {
481ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->ddir = DDIR_WRITE;
482ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->sequential = 0;
483ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
4843d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe	} else if (!strncmp(mem, "rw", 2)) {
4853d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		td->ddir = 0;
4863d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		td->iomix = 1;
4873d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		td->sequential = 1;
4883d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		return 0;
4893d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe	} else if (!strncmp(mem, "randrw", 6)) {
4903d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		td->ddir = 0;
4913d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		td->iomix = 1;
4923d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		td->sequential = 0;
4933d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe		return 0;
494ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
495ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
496072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe	fprintf(stderr, "fio: data direction: read, write, randread, randwrite, rw, randrw\n");
497ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
498ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
499ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
500ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int str_verify_cb(struct thread_data *td, char *mem)
501ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
502ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!strncmp(mem, "0", 1)) {
503ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->verify = VERIFY_NONE;
504ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
505ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
506ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->verify = VERIFY_MD5;
507ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
508ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "crc32", 5)) {
509ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->verify = VERIFY_CRC32;
510ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
511ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
512ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
513072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe	fprintf(stderr, "fio: verify types: md5, crc32\n");
514ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
515ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
516ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
517ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int str_mem_cb(struct thread_data *td, char *mem)
518ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
519ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!strncmp(mem, "malloc", 6)) {
520ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->mem_type = MEM_MALLOC;
521ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
522ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "shm", 3)) {
523ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->mem_type = MEM_SHM;
524ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
525ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(mem, "mmap", 4)) {
526ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->mem_type = MEM_MMAP;
527ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
528ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
529ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
530072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe	fprintf(stderr, "fio: mem type: malloc, shm, mmap\n");
531ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
532ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
533ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
534ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int str_ioengine_cb(struct thread_data *td, char *str)
535ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
536ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!strncmp(str, "linuxaio", 8) || !strncmp(str, "aio", 3) ||
537ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	    !strncmp(str, "libaio", 6)) {
538ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		strcpy(td->io_engine_name, "libaio");
539ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->io_engine = FIO_LIBAIO;
540ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
541ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(str, "posixaio", 8)) {
542ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		strcpy(td->io_engine_name, "posixaio");
543ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->io_engine = FIO_POSIXAIO;
544ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
545ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(str, "sync", 4)) {
546ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		strcpy(td->io_engine_name, "sync");
547ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->io_engine = FIO_SYNCIO;
548ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
549ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(str, "mmap", 4)) {
550ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		strcpy(td->io_engine_name, "mmap");
551ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->io_engine = FIO_MMAPIO;
552ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
553ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} else if (!strncmp(str, "sgio", 4)) {
554ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		strcpy(td->io_engine_name, "sgio");
555ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td->io_engine = FIO_SGIO;
556ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 0;
5578756e4d421722eaeb089067aeaaf317d05d53a57Jens Axboe	} else if (!strncmp(str, "splice", 6)) {
5588756e4d421722eaeb089067aeaaf317d05d53a57Jens Axboe		strcpy(td->io_engine_name, "splice");
5598756e4d421722eaeb089067aeaaf317d05d53a57Jens Axboe		td->io_engine = FIO_SPLICEIO;
5608756e4d421722eaeb089067aeaaf317d05d53a57Jens Axboe		return 0;
561ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
562ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
563072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe	fprintf(stderr, "fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice\n");
564ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 1;
565ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
566ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
567072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe/*
568072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe * This is our [ini] type file parser.
569072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe */
570ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint parse_jobs_ini(char *file)
571ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
572a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe	unsigned int prioclass, prio, cpu, global, il;
573ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned long long ull;
574ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	unsigned long ul1, ul2;
575ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct thread_data *td;
576ef899b6393c43abd655ad2cbc22de18b88a101f8Jens Axboe	char *string, *name, *tmpbuf;
577ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	fpos_t off;
578ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	FILE *f;
579ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	char *p;
58045410acb636e526575d62a037f81ade7916b738cJens Axboe	int ret = 0;
581ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
582ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	f = fopen(file, "r");
583ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!f) {
584aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe		perror("fopen job file");
585ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
586ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
587ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
588ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	string = malloc(4096);
589ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	name = malloc(256);
590ef899b6393c43abd655ad2cbc22de18b88a101f8Jens Axboe	tmpbuf = malloc(4096);
591ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
592ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	while ((p = fgets(string, 4096, f)) != NULL) {
59345410acb636e526575d62a037f81ade7916b738cJens Axboe		if (ret)
59445410acb636e526575d62a037f81ade7916b738cJens Axboe			break;
595ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (is_empty_or_comment(p))
596ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			continue;
597ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (sscanf(p, "[%s]", name) != 1)
598ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			continue;
599ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
600ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		global = !strncmp(name, "global", 6);
601ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
602ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		name[strlen(name) - 1] = '\0';
603ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
604ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		td = get_new_job(global, &def_thread);
60545410acb636e526575d62a037f81ade7916b738cJens Axboe		if (!td) {
60645410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = 1;
60745410acb636e526575d62a037f81ade7916b738cJens Axboe			break;
60845410acb636e526575d62a037f81ade7916b738cJens Axboe		}
609ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
610ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		fgetpos(f, &off);
611ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		while ((p = fgets(string, 4096, f)) != NULL) {
612ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (is_empty_or_comment(p))
613ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
614ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (strstr(p, "["))
615ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
616b6754f9d3f719627d8aae4c3e8f39212d9405f99Jens Axboe			strip_blank_front(&p);
6174ae3f76333bf2382e516db0b5c202b8982b1170fJens Axboe			strip_blank_end(p);
618aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe
619ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "prio", &prio)) {
620ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_IOPRIO
621ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fprintf(stderr, "io priorities not available\n");
62245410acb636e526575d62a037f81ade7916b738cJens Axboe				ret = 1;
62345410acb636e526575d62a037f81ade7916b738cJens Axboe				break;
624ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
6258756e4d421722eaeb089067aeaaf317d05d53a57Jens Axboe				td->ioprio |= prio;
626ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
627ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
628ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
629ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "prioclass", &prioclass)) {
630ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_IOPRIO
631ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fprintf(stderr, "io priorities not available\n");
63245410acb636e526575d62a037f81ade7916b738cJens Axboe				ret = 1;
63345410acb636e526575d62a037f81ade7916b738cJens Axboe				break;
6345c4e1dbc4ec6ee963220c5f4e64a04cd6130dc81Jens Axboe#else
6358756e4d421722eaeb089067aeaaf317d05d53a57Jens Axboe				td->ioprio |= prioclass << IOPRIO_CLASS_SHIFT;
636ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
637ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
6385c4e1dbc4ec6ee963220c5f4e64a04cd6130dc81Jens Axboe#endif
639ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
640e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "direct", &il)) {
641e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->odirect = il;
642ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
643ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
644ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
645ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "rate", &td->rate)) {
646ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
647ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
648ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
649ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "ratemin", &td->ratemin)) {
650ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
651ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
652ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
653ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "ratecycle", &td->ratecycle)) {
654ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
655ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
656ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
657ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "thinktime", &td->thinktime)) {
658ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
659ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
660ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
661ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "cpumask", &cpu)) {
662ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_CPU_AFFINITY
663ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fprintf(stderr, "cpu affinity not available\n");
66445410acb636e526575d62a037f81ade7916b738cJens Axboe				ret = 1;
66545410acb636e526575d62a037f81ade7916b738cJens Axboe				break;
666ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
667ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fill_cpu_mask(td->cpumask, cpu);
668ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
669ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
670ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
671ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "fsync", &td->fsync_blocks)) {
672ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
673fc1a471326fb5248a74ed3a206d37884b812c853Jens Axboe				td->end_fsync = 1;
674ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
675ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
676ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "startdelay", &td->start_delay)) {
677ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
678ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
679ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
680ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "timeout", &td->timeout)) {
681ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
682ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
683ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
684e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "invalidate", &il)) {
685e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->invalidate_cache = il;
686ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
687ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
688ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
689ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "iodepth", &td->iodepth)) {
690ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
691ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
692ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
693e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "sync", &il)) {
694e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->sync_io = il;
695ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
696ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
697ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
698ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "bwavgtime", &td->bw_avg_time)) {
699ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
700ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
701ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
702e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "create_serialize", &il)) {
703e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->create_serialize = il;
704ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
705ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
706ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
707e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "create_fsync", &il)) {
708e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->create_fsync = il;
709ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
710ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
711ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
712e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "end_fsync", &il)) {
713e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->end_fsync = il;
714fc1a471326fb5248a74ed3a206d37884b812c853Jens Axboe				fgetpos(f, &off);
715fc1a471326fb5248a74ed3a206d37884b812c853Jens Axboe				continue;
716fc1a471326fb5248a74ed3a206d37884b812c853Jens Axboe			}
717ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "loops", &td->loops)) {
718ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
719ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
720ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
721ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_int(p, "numjobs", &td->numjobs)) {
722ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
723ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
724ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
725e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe			if (!check_int(p, "overwrite", &il)) {
726e9c047a0d8dfc32634b896e1600c6f1aa4174378Jens Axboe				td->overwrite = il;
727ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
728ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
729ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
730a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe			if (!check_int(p, "rwmixcycle", &td->rwmixcycle)) {
731a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				fgetpos(f, &off);
732a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				continue;
733a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe			}
734a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe			if (!check_int(p, "rwmixread", &il)) {
735a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				if (il > 100)
736a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe					il = 100;
737a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				td->rwmixread = il;
738a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				fgetpos(f, &off);
739a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				continue;
740a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe			}
741a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe			if (!check_int(p, "rwmixwrite", &il)) {
742a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				if (il > 100)
743a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe					il = 100;
744a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				td->rwmixread = 100 - il;
745a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				fgetpos(f, &off);
746a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe				continue;
747a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe			}
748b6f4d8804ad499adf10b4cad0657284a8a4a6287Jens Axboe			if (!check_int(p, "nice", &td->nice)) {
749b6f4d8804ad499adf10b4cad0657284a8a4a6287Jens Axboe				fgetpos(f, &off);
750b6f4d8804ad499adf10b4cad0657284a8a4a6287Jens Axboe				continue;
751b6f4d8804ad499adf10b4cad0657284a8a4a6287Jens Axboe			}
752ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_range(p, "bsrange", &ul1, &ul2)) {
753ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				if (ul1 > ul2) {
754ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe					td->max_bs = ul1;
755ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe					td->min_bs = ul2;
756ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				} else {
757ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe					td->max_bs = ul2;
758ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe					td->min_bs = ul1;
759ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				}
760ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
761ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
762ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
763ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strcnv(p, "bs", &ull)) {
764ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				td->bs = ull;
765ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
766ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
767ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
768ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strcnv(p, "size", &td->file_size)) {
769ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
770ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
771ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
772ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strcnv(p, "offset", &td->file_offset)) {
773ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
77420dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe				continue;
77520dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe			}
77620dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe			if (!check_strcnv(p, "zonesize", &td->zone_size)) {
77720dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe				fgetpos(f, &off);
77820dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe				continue;
77920dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe			}
78020dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe			if (!check_strcnv(p, "zoneskip", &td->zone_skip)) {
78120dc95c47087d486b5d4608fc15b1c2021761923Jens Axboe				fgetpos(f, &off);
782ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
783ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
784c04f7ec3ecb8ce780bde6ad3515f003e6015c62aJens Axboe			if (!check_strcnv(p, "lockmem", &mlock_size)) {
785c04f7ec3ecb8ce780bde6ad3515f003e6015c62aJens Axboe				fgetpos(f, &off);
786c04f7ec3ecb8ce780bde6ad3515f003e6015c62aJens Axboe				continue;
787c04f7ec3ecb8ce780bde6ad3515f003e6015c62aJens Axboe			}
788ef899b6393c43abd655ad2cbc22de18b88a101f8Jens Axboe			if (!check_strstore(p, "directory", tmpbuf)) {
789ef899b6393c43abd655ad2cbc22de18b88a101f8Jens Axboe				td->directory = strdup(tmpbuf);
790ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
791ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
792ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
79301452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe			if (!check_strstore(p, "name", tmpbuf)) {
79401452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe				snprintf(td->name, sizeof(td->name)-1, "%s%d", tmpbuf, td->thread_number);
79501452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe				fgetpos(f, &off);
79601452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe				continue;
79701452055af61d6f5de543575dba3ebb0c9e55fabJens Axboe			}
798ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_str(p, "mem", str_mem_cb, td)) {
799ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
800ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
801ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
802ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_str(p, "verify", str_verify_cb, td)) {
803ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
804ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
805ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
806ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_str(p, "rw", str_rw_cb, td)) {
807ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
808ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
809ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
810ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_str(p, "ioengine", str_ioengine_cb, td)) {
811ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
812ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
813ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
814ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strset(p, "create")) {
815ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				td->create_file = 1;
816ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
817ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
818ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
819ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strset(p, "exitall")) {
820ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				exitall_on_terminate = 1;
821ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
822ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
823ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
824ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strset(p, "stonewall")) {
825ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				td->stonewall = 1;
826ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
827ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
828ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
829ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			if (!check_strset(p, "thread")) {
830ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				td->use_thread = 1;
831ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				fgetpos(f, &off);
832ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				continue;
833ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			}
83480b9feb08908e0493825043f807fcbea4591e09bJens Axboe			if (!check_strstore(p, "iolog", tmpbuf)) {
8354f693b9de45f8fe4a893bd4c3de7c3dc17979386Jens Axboe				if (td->write_iolog) {
8364f693b9de45f8fe4a893bd4c3de7c3dc17979386Jens Axboe					fprintf(stderr, "fio: read iolog overrides given write_iolog\n");
837af8c0b4f06fa2ebb4eaeb4601b16e2ed08f2b845Jens Axboe					free(td->iolog_file);
8384f693b9de45f8fe4a893bd4c3de7c3dc17979386Jens Axboe					td->write_iolog = 0;
8394f693b9de45f8fe4a893bd4c3de7c3dc17979386Jens Axboe				}
84080b9feb08908e0493825043f807fcbea4591e09bJens Axboe				td->iolog_file = strdup(tmpbuf);
841843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe				td->read_iolog = 1;
842843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe				fgetpos(f, &off);
843843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe				continue;
844843a741389226f5f2d0ce8636cd57532be9b7e4dJens Axboe			}
845af8c0b4f06fa2ebb4eaeb4601b16e2ed08f2b845Jens Axboe			if (!check_strstore(p, "write_iolog", tmpbuf)) {
846af8c0b4f06fa2ebb4eaeb4601b16e2ed08f2b845Jens Axboe				if (!td->read_iolog) {
847af8c0b4f06fa2ebb4eaeb4601b16e2ed08f2b845Jens Axboe					td->iolog_file = strdup(tmpbuf);
848af8c0b4f06fa2ebb4eaeb4601b16e2ed08f2b845Jens Axboe					td->write_iolog = 1;
8494f693b9de45f8fe4a893bd4c3de7c3dc17979386Jens Axboe				} else
8504f693b9de45f8fe4a893bd4c3de7c3dc17979386Jens Axboe					fprintf(stderr, "fio: read iolog overrides given write_iolog\n");
851aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe				fgetpos(f, &off);
852aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe				continue;
853aea47d444b02bd7c622f82bb73151fd7136a499fJens Axboe			}
85480b9feb08908e0493825043f807fcbea4591e09bJens Axboe			if (!check_strstore(p, "exec_prerun", tmpbuf)) {
85580b9feb08908e0493825043f807fcbea4591e09bJens Axboe				td->exec_prerun = strdup(tmpbuf);
8564e0ba8af8f0bfe0f194122661c8a659c2ac748e6Jens Axboe				fgetpos(f, &off);
8574e0ba8af8f0bfe0f194122661c8a659c2ac748e6Jens Axboe				continue;
8584e0ba8af8f0bfe0f194122661c8a659c2ac748e6Jens Axboe			}
85980b9feb08908e0493825043f807fcbea4591e09bJens Axboe			if (!check_strstore(p, "exec_postrun", tmpbuf)) {
86080b9feb08908e0493825043f807fcbea4591e09bJens Axboe				td->exec_postrun = strdup(tmpbuf);
8614e0ba8af8f0bfe0f194122661c8a659c2ac748e6Jens Axboe				fgetpos(f, &off);
8624e0ba8af8f0bfe0f194122661c8a659c2ac748e6Jens Axboe				continue;
8634e0ba8af8f0bfe0f194122661c8a659c2ac748e6Jens Axboe			}
86480b9feb08908e0493825043f807fcbea4591e09bJens Axboe			if (!check_strstore(p, "ioscheduler", tmpbuf)) {
86522f78b320a8d2ffa32b5736fe754c108a8d21525Jens Axboe#ifndef FIO_HAVE_IOSCHED_SWITCH
86622f78b320a8d2ffa32b5736fe754c108a8d21525Jens Axboe				fprintf(stderr, "io scheduler switching not available\n");
86722f78b320a8d2ffa32b5736fe754c108a8d21525Jens Axboe				ret = 1;
86822f78b320a8d2ffa32b5736fe754c108a8d21525Jens Axboe				break;
86922f78b320a8d2ffa32b5736fe754c108a8d21525Jens Axboe#else
87080b9feb08908e0493825043f807fcbea4591e09bJens Axboe				td->ioscheduler = strdup(tmpbuf);
871da86774e5a002acf2c8d779b805305bc193fc0a5Jens Axboe				fgetpos(f, &off);
872da86774e5a002acf2c8d779b805305bc193fc0a5Jens Axboe				continue;
87322f78b320a8d2ffa32b5736fe754c108a8d21525Jens Axboe#endif
874da86774e5a002acf2c8d779b805305bc193fc0a5Jens Axboe			}
875ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
87645410acb636e526575d62a037f81ade7916b738cJens Axboe			/*
87745410acb636e526575d62a037f81ade7916b738cJens Axboe			 * Don't break here, continue parsing options so we
87845410acb636e526575d62a037f81ade7916b738cJens Axboe			 * dump all the bad ones. Makes trial/error fixups
87945410acb636e526575d62a037f81ade7916b738cJens Axboe			 * easier on the user.
88045410acb636e526575d62a037f81ade7916b738cJens Axboe			 */
881ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			printf("Client%d: bad option %s\n",td->thread_number,p);
88245410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = 1;
883ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
884ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
88545410acb636e526575d62a037f81ade7916b738cJens Axboe		if (!ret) {
88645410acb636e526575d62a037f81ade7916b738cJens Axboe			fsetpos(f, &off);
88745410acb636e526575d62a037f81ade7916b738cJens Axboe			ret = add_job(td, name, 0);
88845410acb636e526575d62a037f81ade7916b738cJens Axboe		}
88945410acb636e526575d62a037f81ade7916b738cJens Axboe		if (ret)
89045410acb636e526575d62a037f81ade7916b738cJens Axboe			break;
891ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
892ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
893ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	free(string);
894ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	free(name);
895ef899b6393c43abd655ad2cbc22de18b88a101f8Jens Axboe	free(tmpbuf);
896ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	fclose(f);
89745410acb636e526575d62a037f81ade7916b738cJens Axboe	return ret;
898ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
899ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
900ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int fill_def_thread(void)
901ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
902ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	memset(&def_thread, 0, sizeof(def_thread));
903ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
904ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
905ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		perror("sched_getaffinity");
906ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
907ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
908ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
909ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
910ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * fill globals
911ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
912ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.ddir = DDIR_READ;
9133d60d1ed78b663659967e04cc92e1359bd50fb3aJens Axboe	def_thread.iomix = 0;
914ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.bs = DEF_BS;
915ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.min_bs = -1;
916ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.max_bs = -1;
917ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.io_engine = DEF_IO_ENGINE;
918ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	strcpy(def_thread.io_engine_name, DEF_IO_ENGINE_NAME);
919ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.odirect = DEF_ODIRECT;
920ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.ratecycle = DEF_RATE_CYCLE;
921ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.sequential = DEF_SEQUENTIAL;
922ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.timeout = DEF_TIMEOUT;
923ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.create_file = DEF_CREATE;
924ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.overwrite = DEF_OVERWRITE;
925ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.invalidate_cache = DEF_INVALIDATE;
926ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.sync_io = DEF_SYNCIO;
927ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.mem_type = MEM_MALLOC;
928ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.bw_avg_time = DEF_BWAVGTIME;
929ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.create_serialize = DEF_CREATE_SER;
930ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.create_fsync = DEF_CREATE_FSYNC;
931ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.loops = DEF_LOOPS;
932ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.verify = DEF_VERIFY;
933ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.stonewall = DEF_STONEWALL;
934ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.numjobs = DEF_NUMJOBS;
935ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.use_thread = DEF_USE_THREAD;
936a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe	def_thread.rwmixcycle = DEF_RWMIX_CYCLE;
937a6ccc7be771650f903ea77ace2a1af593622c0f4Jens Axboe	def_thread.rwmixread = DEF_RWMIX_READ;
938b6f4d8804ad499adf10b4cad0657284a8a4a6287Jens Axboe	def_thread.nice = DEF_NICE;
939ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_DISK_UTIL
940ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	def_thread.do_disk_util = 1;
941ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif
942ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
943ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
944ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
945ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
9464785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboestatic void usage(char *name)
9474785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe{
9484785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("%s\n", fio_version_string);
9494785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-s IO is sequential\n");
9504785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-b Block size in KiB for each IO\n");
9514785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-t Runtime in seconds\n");
9524785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-R Exit all threads on failure to meet rate goal\n");
9534785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-o Use O_DIRECT\n");
9544785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-l Generate per-job latency logs\n");
9554785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-w Generate per-job bandwidth logs\n");
9564785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-f Job file (Required)\n");
9574785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	printf("\t-v Print version info and exit\n");
9584785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe}
9594785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe
960ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void parse_cmd_line(int argc, char *argv[])
961ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
962ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	int c;
963ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
9644785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe	while ((c = getopt(argc, argv, "s:b:t:r:R:o:f:lwvh")) != EOF) {
965ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		switch (c) {
966ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 's':
967ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				def_thread.sequential = !!atoi(optarg);
968ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
969ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'b':
970ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				def_thread.bs = atoi(optarg);
971ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				def_thread.bs <<= 10;
972ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				if (!def_thread.bs) {
973ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe					printf("bad block size\n");
974ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe					def_thread.bs = DEF_BS;
975ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				}
976ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
977ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 't':
978ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				def_thread.timeout = atoi(optarg);
979ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
980ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'r':
981ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				repeatable = !!atoi(optarg);
982ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
983ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'R':
984ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				rate_quit = !!atoi(optarg);
985ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
986ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'o':
987ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				def_thread.odirect = !!atoi(optarg);
988ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
989ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'f':
990ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				ini_file = strdup(optarg);
991ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
992ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'l':
993ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				write_lat_log = 1;
994ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
995ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'w':
996ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				write_bw_log = 1;
997ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				break;
9984785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe			case 'h':
9994785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe				usage(argv[0]);
10004785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe				exit(0);
1001ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			case 'v':
1002ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				printf("%s\n", fio_version_string);
1003ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe				exit(0);
1004ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
1005ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1006c9fad893e8333682d6ab67a269b0dd74f303c5bcJens Axboe
1007c9fad893e8333682d6ab67a269b0dd74f303c5bcJens Axboe	if (!ini_file && argc > 1 && argv[argc - 1][0] != '-')
1008c9fad893e8333682d6ab67a269b0dd74f303c5bcJens Axboe		ini_file = strdup(argv[argc - 1]);
1009ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1010ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1011ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic void free_shm(void)
1012ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1013ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	struct shmid_ds sbuf;
1014ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1015ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (threads) {
10162c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe		shmdt((void *) threads);
1017ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		threads = NULL;
1018ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		shmctl(shm_id, IPC_RMID, &sbuf);
1019ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1020ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1021ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1022ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboestatic int setup_thread_area(void)
1023ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1024ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	/*
1025ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * 1024 is too much on some machines, scale max_jobs if
1026ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 * we get a failure that looks like too large a shm segment
1027ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	 */
1028ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	do {
1029ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		int s = max_jobs * sizeof(struct thread_data);
1030ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1031ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		shm_id = shmget(0, s, IPC_CREAT | 0600);
1032ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (shm_id != -1)
1033ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			break;
1034ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		if (errno != EINVAL) {
1035ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			perror("shmget");
1036ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe			break;
1037ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		}
1038ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1039ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		max_jobs >>= 1;
1040ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	} while (max_jobs);
1041ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1042ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (shm_id == -1)
1043ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1044ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1045ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	threads = shmat(shm_id, NULL, 0);
1046ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (threads == (void *) -1) {
1047ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		perror("shmat");
1048ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1049ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1050ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1051ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	atexit(free_shm);
1052ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1053ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1054ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1055ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboeint parse_options(int argc, char *argv[])
1056ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe{
1057ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (setup_thread_area())
1058ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1059ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (fill_def_thread())
1060ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1061ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1062ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	parse_cmd_line(argc, argv);
1063ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1064ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	if (!ini_file) {
1065ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		printf("Need job file\n");
10664785f99523f5c69635eb4bd826f25cd2e264cda7Jens Axboe		usage(argv[0]);
1067ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1068ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	}
1069ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1070072619835aa805f3335dca9d72f4d4eb1009aecdJens Axboe	if (parse_jobs_ini(ini_file))
1071ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe		return 1;
1072ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe
1073ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe	return 0;
1074ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe}
1075