blob: 2cfa6d286544421dfd033bd9fecdb94890fa3d0b [file] [log] [blame]
Jens Axboe906c8d72006-06-13 09:37:56 +02001/*
Jens Axboecb2c86f2006-10-26 13:48:34 +02002 * This file contains job initialization and setup functions.
Jens Axboe906c8d72006-06-13 09:37:56 +02003 */
Jens Axboeebac4652005-12-08 15:25:21 +01004#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <ctype.h>
9#include <string.h>
10#include <errno.h>
Jens Axboeb4692822006-10-27 13:43:22 +020011#include <getopt.h>
12#include <assert.h>
Jens Axboeebac4652005-12-08 15:25:21 +010013#include <sys/ipc.h>
14#include <sys/shm.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17
18#include "fio.h"
Jens Axboecb2c86f2006-10-26 13:48:34 +020019#include "parse.h"
Jens Axboeebac4652005-12-08 15:25:21 +010020
Jens Axboe906c8d72006-06-13 09:37:56 +020021/*
22 * The default options
23 */
Jens Axboe20dc95c2005-12-09 10:29:35 +010024#define DEF_BS (4096)
25#define DEF_TIMEOUT (0)
26#define DEF_RATE_CYCLE (1000)
27#define DEF_ODIRECT (1)
28#define DEF_IO_ENGINE (FIO_SYNCIO)
Jens Axboeebac4652005-12-08 15:25:21 +010029#define DEF_IO_ENGINE_NAME "sync"
Jens Axboe20dc95c2005-12-09 10:29:35 +010030#define DEF_SEQUENTIAL (1)
31#define DEF_RAND_REPEAT (1)
32#define DEF_OVERWRITE (1)
Jens Axboe20dc95c2005-12-09 10:29:35 +010033#define DEF_INVALIDATE (1)
34#define DEF_SYNCIO (0)
35#define DEF_RANDSEED (0xb1899bedUL)
36#define DEF_BWAVGTIME (500)
37#define DEF_CREATE_SER (1)
Jens Axboeebac4652005-12-08 15:25:21 +010038#define DEF_CREATE_FSYNC (1)
Jens Axboe20dc95c2005-12-09 10:29:35 +010039#define DEF_LOOPS (1)
40#define DEF_VERIFY (0)
41#define DEF_STONEWALL (0)
42#define DEF_NUMJOBS (1)
43#define DEF_USE_THREAD (0)
44#define DEF_FILE_SIZE (1024 * 1024 * 1024UL)
45#define DEF_ZONE_SIZE (0)
46#define DEF_ZONE_SKIP (0)
Jens Axboea6ccc7b2006-06-02 10:14:15 +020047#define DEF_RWMIX_CYCLE (500)
48#define DEF_RWMIX_READ (50)
Jens Axboeb6f4d882006-06-02 10:32:51 +020049#define DEF_NICE (0)
Jens Axboe53cdc682006-10-18 11:50:58 +020050#define DEF_NR_FILES (1)
Jens Axboef6cbb262006-10-18 14:16:42 +020051#define DEF_UNLINK (0)
Jens Axboeec94ec52006-10-20 10:59:19 +020052#define DEF_WRITE_BW_LOG (0)
53#define DEF_WRITE_LAT_LOG (0)
Jens Axboeebac4652005-12-08 15:25:21 +010054
Jens Axboee1f36502006-10-27 10:54:08 +020055#define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
56
Jens Axboeb4692822006-10-27 13:43:22 +020057static int str_rw_cb(void *, const char *);
58static int str_ioengine_cb(void *, const char *);
59static int str_mem_cb(void *, const char *);
60static int str_verify_cb(void *, const char *);
Jens Axboee1f36502006-10-27 10:54:08 +020061static int str_lockmem_cb(void *, unsigned long *);
62static int str_prio_cb(void *, unsigned int *);
63static int str_prioclass_cb(void *, unsigned int *);
64static int str_exitall_cb(void);
65static int str_cpumask_cb(void *, unsigned int *);
66
67/*
68 * Map of job/command line options
69 */
70static struct fio_option options[] = {
71 {
72 .name = "name",
73 .type = FIO_OPT_STR_STORE,
74 .off1 = td_var_offset(name),
75 },
76 {
77 .name = "directory",
78 .type = FIO_OPT_STR_STORE,
79 .off1 = td_var_offset(directory),
80 },
81 {
82 .name = "filename",
83 .type = FIO_OPT_STR_STORE,
84 .off1 = td_var_offset(filename),
85 },
86 {
87 .name = "rw",
88 .type = FIO_OPT_STR,
89 .cb = str_rw_cb,
90 },
91 {
92 .name = "ioengine",
93 .type = FIO_OPT_STR,
94 .cb = str_ioengine_cb,
95 },
96 {
97 .name = "mem",
98 .type = FIO_OPT_STR,
99 .cb = str_mem_cb,
100 },
101 {
102 .name = "verify",
103 .type = FIO_OPT_STR,
104 .cb = str_verify_cb,
105 },
106 {
107 .name = "write_iolog",
Jens Axboe076efc72006-10-27 11:24:25 +0200108 .type = FIO_OPT_STR_STORE,
109 .off1 = td_var_offset(write_iolog_file),
Jens Axboee1f36502006-10-27 10:54:08 +0200110 },
111 {
Jens Axboe076efc72006-10-27 11:24:25 +0200112 .name = "read_iolog",
Jens Axboee1f36502006-10-27 10:54:08 +0200113 .type = FIO_OPT_STR_STORE,
Jens Axboe076efc72006-10-27 11:24:25 +0200114 .off1 = td_var_offset(read_iolog_file),
Jens Axboee1f36502006-10-27 10:54:08 +0200115 },
116 {
117 .name = "exec_prerun",
118 .type = FIO_OPT_STR_STORE,
119 .off1 = td_var_offset(exec_prerun),
120 },
121 {
122 .name = "exec_postrun",
123 .type = FIO_OPT_STR_STORE,
124 .off1 = td_var_offset(exec_postrun),
125 },
126#ifdef FIO_HAVE_IOSCHED_SWITCH
127 {
128 .name = "ioscheduler",
129 .type = FIO_OPT_STR_STORE,
130 .off1 = td_var_offset(ioscheduler),
131 },
132#endif
133 {
134 .name = "size",
135 .type = FIO_OPT_STR_VAL,
136 .off1 = td_var_offset(total_file_size),
137 },
138 {
139 .name = "bs",
140 .type = FIO_OPT_STR_VAL,
141 .off1 = td_var_offset(bs),
142 },
143 {
144 .name = "offset",
145 .type = FIO_OPT_STR_VAL,
146 .off1 = td_var_offset(start_offset),
147 },
148 {
149 .name = "zonesize",
150 .type = FIO_OPT_STR_VAL,
151 .off1 = td_var_offset(zone_size),
152 },
153 {
154 .name = "zoneskip",
155 .type = FIO_OPT_STR_VAL,
156 .off1 = td_var_offset(zone_skip),
157 },
158 {
159 .name = "lockmem",
160 .type = FIO_OPT_STR_VAL,
161 .cb = str_lockmem_cb,
162 },
163 {
164 .name = "bsrange",
165 .type = FIO_OPT_RANGE,
166 .off1 = td_var_offset(min_bs),
167 .off2 = td_var_offset(max_bs),
168 },
169 {
170 .name = "nrfiles",
171 .type = FIO_OPT_INT,
172 .off1 = td_var_offset(nr_files),
173 },
174 {
175 .name = "iodepth",
176 .type = FIO_OPT_INT,
177 .off1 = td_var_offset(iodepth),
178 },
179 {
180 .name = "fsync",
181 .type = FIO_OPT_INT,
182 .off1 = td_var_offset(fsync_blocks),
183 },
184 {
185 .name = "rwmixcycle",
186 .type = FIO_OPT_INT,
187 .off1 = td_var_offset(rwmixcycle),
188 },
189 {
190 .name = "rwmixread",
191 .type = FIO_OPT_INT,
192 .off1 = td_var_offset(rwmixread),
193 .max_val= 100,
194 },
195 {
196 .name = "rwmixwrite",
197 .type = FIO_OPT_INT,
198 .off1 = td_var_offset(rwmixwrite),
199 .max_val= 100,
200 },
201 {
202 .name = "nice",
203 .type = FIO_OPT_INT,
204 .off1 = td_var_offset(nice),
205 },
206#ifdef FIO_HAVE_IOPRIO
207 {
208 .name = "prio",
209 .type = FIO_OPT_INT,
210 .cb = str_prio_cb,
211 },
212 {
213 .name = "prioclass",
214 .type = FIO_OPT_INT,
215 .cb = str_prioclass_cb,
216 },
217#endif
218 {
219 .name = "thinktime",
220 .type = FIO_OPT_INT,
221 .off1 = td_var_offset(thinktime)
222 },
223 {
224 .name = "rate",
225 .type = FIO_OPT_INT,
226 .off1 = td_var_offset(rate)
227 },
228 {
229 .name = "ratemin",
230 .type = FIO_OPT_INT,
231 .off1 = td_var_offset(ratemin)
232 },
233 {
234 .name = "ratecycle",
235 .type = FIO_OPT_INT,
236 .off1 = td_var_offset(ratecycle)
237 },
238 {
239 .name = "startdelay",
240 .type = FIO_OPT_INT,
241 .off1 = td_var_offset(start_delay)
242 },
243 {
244 .name = "timeout",
245 .type = FIO_OPT_STR_VAL_TIME,
246 .off1 = td_var_offset(timeout)
247 },
248 {
249 .name = "invalidate",
250 .type = FIO_OPT_INT,
251 .off1 = td_var_offset(invalidate_cache)
252 },
253 {
254 .name = "sync",
255 .type = FIO_OPT_INT,
256 .off1 = td_var_offset(sync_io)
257 },
258 {
259 .name = "bwavgtime",
260 .type = FIO_OPT_INT,
261 .off1 = td_var_offset(bw_avg_time)
262 },
263 {
264 .name = "create_serialize",
265 .type = FIO_OPT_INT,
266 .off1 = td_var_offset(create_serialize)
267 },
268 {
269 .name = "create_fsync",
270 .type = FIO_OPT_INT,
271 .off1 = td_var_offset(create_fsync)
272 },
273 {
274 .name = "loops",
275 .type = FIO_OPT_INT,
276 .off1 = td_var_offset(loops)
277 },
278 {
279 .name = "numjobs",
280 .type = FIO_OPT_INT,
281 .off1 = td_var_offset(numjobs)
282 },
283 {
284 .name = "cpuload",
285 .type = FIO_OPT_INT,
286 .off1 = td_var_offset(cpuload)
287 },
288 {
289 .name = "cpuchunks",
290 .type = FIO_OPT_INT,
291 .off1 = td_var_offset(cpucycle)
292 },
293 {
294 .name = "direct",
295 .type = FIO_OPT_INT,
296 .off1 = td_var_offset(odirect)
297 },
298 {
299 .name = "overwrite",
300 .type = FIO_OPT_INT,
301 .off1 = td_var_offset(overwrite)
302 },
303#ifdef FIO_HAVE_CPU_AFFINITY
304 {
305 .name = "cpumask",
306 .type = FIO_OPT_INT,
307 .cb = str_cpumask_cb,
308 },
309#endif
310 {
311 .name = "end_fsync",
312 .type = FIO_OPT_INT,
313 .off1 = td_var_offset(end_fsync)
314 },
315 {
316 .name = "unlink",
317 .type = FIO_OPT_STR_SET,
318 .off1 = td_var_offset(unlink),
319 },
320 {
321 .name = "exitall",
322 .type = FIO_OPT_STR_SET,
323 .cb = str_exitall_cb,
324 },
325 {
326 .name = "stonewall",
327 .type = FIO_OPT_STR_SET,
328 .off1 = td_var_offset(stonewall),
329 },
330 {
331 .name = "thread",
332 .type = FIO_OPT_STR_SET,
333 .off1 = td_var_offset(thread),
334 },
335 {
336 .name = "write_bw_log",
337 .type = FIO_OPT_STR_SET,
338 .off1 = td_var_offset(write_bw_log),
339 },
340 {
341 .name = "write_lat_log",
342 .type = FIO_OPT_STR_SET,
343 .off1 = td_var_offset(write_lat_log),
344 },
345 {
346 .name = NULL,
347 },
348};
349
Jens Axboeb4692822006-10-27 13:43:22 +0200350#define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
351#define FIO_CMD_OPTS (16)
352#define FIO_GETOPT_JOB (0x89988998)
353
354/*
355 * Command line options. These will contain the above, plus a few
356 * extra that only pertain to fio itself and not jobs.
357 */
358static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
359 {
360 .name = "output",
361 .has_arg = required_argument,
362 .val = 'o',
363 },
364 {
365 .name = "timeout",
366 .has_arg = required_argument,
367 .val = 't',
368 },
369 {
370 .name = "latency-log",
371 .has_arg = required_argument,
372 .val = 'l',
373 },
374 {
375 .name = "bandwidth-log",
376 .has_arg = required_argument,
377 .val = 'b',
378 },
379 {
380 .name = "minimal",
381 .has_arg = optional_argument,
382 .val = 'm',
383 },
384 {
385 .name = "version",
386 .has_arg = no_argument,
387 .val = 'v',
388 },
389 {
390 .name = NULL,
391 },
392};
393
Jens Axboe972cfd22006-06-09 11:08:56 +0200394static int def_timeout = DEF_TIMEOUT;
Jens Axboe972cfd22006-06-09 11:08:56 +0200395
Jens Axboeb4692822006-10-27 13:43:22 +0200396static char fio_version_string[] = "fio 1.7";
Jens Axboeebac4652005-12-08 15:25:21 +0100397
Jens Axboe972cfd22006-06-09 11:08:56 +0200398static char **ini_file;
Jens Axboeebac4652005-12-08 15:25:21 +0100399static int max_jobs = MAX_JOBS;
400
401struct thread_data def_thread;
402struct thread_data *threads = NULL;
403
404int rate_quit = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100405int exitall_on_terminate = 0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200406int terse_output = 0;
Jens Axboec04f7ec2006-05-31 10:13:16 +0200407unsigned long long mlock_size = 0;
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200408FILE *f_out = NULL;
409FILE *f_err = NULL;
Jens Axboeebac4652005-12-08 15:25:21 +0100410
Jens Axboeec94ec52006-10-20 10:59:19 +0200411static int write_lat_log = DEF_WRITE_LAT_LOG;
412static int write_bw_log = DEF_WRITE_BW_LOG;
413
Jens Axboe906c8d72006-06-13 09:37:56 +0200414/*
415 * Return a free job structure.
416 */
Jens Axboeebac4652005-12-08 15:25:21 +0100417static struct thread_data *get_new_job(int global, struct thread_data *parent)
418{
419 struct thread_data *td;
420
421 if (global)
422 return &def_thread;
423 if (thread_number >= max_jobs)
424 return NULL;
425
426 td = &threads[thread_number++];
Jens Axboeddaeaa52006-06-08 11:00:58 +0200427 *td = *parent;
Jens Axboeebac4652005-12-08 15:25:21 +0100428
Jens Axboeebac4652005-12-08 15:25:21 +0100429 td->thread_number = thread_number;
Jens Axboeebac4652005-12-08 15:25:21 +0100430 return td;
431}
432
433static void put_job(struct thread_data *td)
434{
Jens Axboe549577a2006-10-30 12:23:41 +0100435 if (td == &def_thread)
436 return;
437
Jens Axboeebac4652005-12-08 15:25:21 +0100438 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
439 thread_number--;
440}
441
Jens Axboedad915e2006-10-27 11:10:18 +0200442/*
443 * Lazy way of fixing up options that depend on each other. We could also
444 * define option callback handlers, but this is easier.
445 */
Jens Axboee1f36502006-10-27 10:54:08 +0200446static void fixup_options(struct thread_data *td)
447{
Jens Axboee1f36502006-10-27 10:54:08 +0200448 if (!td->rwmixread && td->rwmixwrite)
449 td->rwmixread = 100 - td->rwmixwrite;
Jens Axboedad915e2006-10-27 11:10:18 +0200450
Jens Axboe076efc72006-10-27 11:24:25 +0200451 if (td->write_iolog_file && td->read_iolog_file) {
452 log_err("fio: read iolog overrides write_iolog\n");
453 free(td->write_iolog_file);
454 td->write_iolog_file = NULL;
455 }
Jens Axboe16b462a2006-10-30 12:35:18 +0100456
457 if (td->io_ops->flags & FIO_SYNCIO)
458 td->iodepth = 1;
459 else {
460 if (!td->iodepth)
461 td->iodepth = td->nr_files;
462 }
463
464 /*
465 * only really works for sequential io for now, and with 1 file
466 */
467 if (td->zone_size && !td->sequential && td->nr_files == 1)
468 td->zone_size = 0;
469
470 /*
471 * Reads can do overwrites, we always need to pre-create the file
472 */
473 if (td_read(td) || td_rw(td))
474 td->overwrite = 1;
475
476 if (!td->min_bs)
477 td->min_bs = td->bs;
478 if (!td->max_bs)
479 td->max_bs = td->bs;
480 if (td_read(td) && !td_rw(td))
481 td->verify = 0;
Jens Axboee1f36502006-10-27 10:54:08 +0200482}
483
Jens Axboe906c8d72006-06-13 09:37:56 +0200484/*
485 * Adds a job to the list of things todo. Sanitizes the various options
486 * to make sure we don't have conflicts, and initializes various
487 * members of td.
488 */
Jens Axboe75154842006-06-01 13:56:09 +0200489static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
Jens Axboeebac4652005-12-08 15:25:21 +0100490{
Jens Axboe3d60d1e2006-05-25 06:31:06 +0200491 char *ddir_str[] = { "read", "write", "randread", "randwrite",
492 "rw", NULL, "randrw" };
Jens Axboeebac4652005-12-08 15:25:21 +0100493 struct stat sb;
Jens Axboe53cdc682006-10-18 11:50:58 +0200494 int numjobs, ddir, i;
495 struct fio_file *f;
Jens Axboeebac4652005-12-08 15:25:21 +0100496
497#ifndef FIO_HAVE_LIBAIO
498 if (td->io_engine == FIO_LIBAIO) {
Jens Axboe3b70d7e2006-06-08 21:48:46 +0200499 log_err("Linux libaio not available\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100500 return 1;
501 }
502#endif
503#ifndef FIO_HAVE_POSIXAIO
504 if (td->io_engine == FIO_POSIXAIO) {
Jens Axboe3b70d7e2006-06-08 21:48:46 +0200505 log_err("posix aio not available\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100506 return 1;
507 }
508#endif
Jens Axboeebac4652005-12-08 15:25:21 +0100509
510 /*
511 * the def_thread is just for options, it's not a real job
512 */
513 if (td == &def_thread)
514 return 0;
515
Jens Axboedf641192006-10-12 07:55:41 +0200516 /*
517 * Set default io engine, if none set
518 */
519 if (!td->io_ops) {
520 td->io_ops = load_ioengine(td, DEF_IO_ENGINE_NAME);
521 if (!td->io_ops) {
522 log_err("default engine %s not there?\n", DEF_IO_ENGINE_NAME);
523 return 1;
524 }
525 }
526
Jens Axboe16b462a2006-10-30 12:35:18 +0100527 fixup_options(td);
Jens Axboe9cc935a2006-06-13 09:11:18 +0200528
Jens Axboeebac4652005-12-08 15:25:21 +0100529 td->filetype = FIO_TYPE_FILE;
Jens Axboe0af7b542006-02-17 10:10:12 +0100530 if (!stat(jobname, &sb)) {
531 if (S_ISBLK(sb.st_mode))
532 td->filetype = FIO_TYPE_BD;
533 else if (S_ISCHR(sb.st_mode))
534 td->filetype = FIO_TYPE_CHAR;
535 }
Jens Axboeebac4652005-12-08 15:25:21 +0100536
Jens Axboeb2a15192006-10-18 14:10:42 +0200537 if (td->odirect)
538 td->io_ops->flags |= FIO_RAWIO;
539
Jens Axboe13f8e2d2006-10-24 09:29:45 +0200540 if (td->filename)
541 td->nr_uniq_files = 1;
542 else
543 td->nr_uniq_files = td->nr_files;
544
545 if (td->filetype == FIO_TYPE_FILE || td->filename) {
Jens Axboee9c047a2006-06-07 21:13:04 +0200546 char tmp[PATH_MAX];
Jens Axboe53cdc682006-10-18 11:50:58 +0200547 int len = 0;
548 int i;
Jens Axboee9c047a2006-06-07 21:13:04 +0200549
Jens Axboeef899b62006-06-06 09:31:00 +0200550 if (td->directory && td->directory[0] != '\0')
Jens Axboe53cdc682006-10-18 11:50:58 +0200551 sprintf(tmp, "%s/", td->directory);
Jens Axboeebac4652005-12-08 15:25:21 +0100552
Jens Axboe53cdc682006-10-18 11:50:58 +0200553 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
554
555 for_each_file(td, f, i) {
556 memset(f, 0, sizeof(*f));
557 f->fd = -1;
558
Jens Axboe13f8e2d2006-10-24 09:29:45 +0200559 if (td->filename)
560 sprintf(tmp + len, "%s", td->filename);
561 else
562 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
Jens Axboe53cdc682006-10-18 11:50:58 +0200563 f->file_name = strdup(tmp);
564 }
565 } else {
566 td->nr_files = 1;
567 td->files = malloc(sizeof(struct fio_file));
568 f = &td->files[0];
569
570 memset(f, 0, sizeof(*f));
571 f->fd = -1;
572 f->file_name = strdup(jobname);
573 }
574
575 for_each_file(td, f, i) {
576 f->file_size = td->total_file_size / td->nr_files;
577 f->file_offset = td->start_offset;
578 }
579
Jens Axboebbfd6b02006-06-07 19:42:54 +0200580 fio_sem_init(&td->mutex, 0);
Jens Axboeebac4652005-12-08 15:25:21 +0100581
582 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
583 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
584 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
585
Jens Axboeebac4652005-12-08 15:25:21 +0100586 if (td->stonewall && td->thread_number > 1)
587 groupid++;
588
589 td->groupid = groupid;
590
591 if (setup_rate(td))
592 goto err;
593
Jens Axboeec94ec52006-10-20 10:59:19 +0200594 if (td->write_lat_log) {
Jens Axboeebac4652005-12-08 15:25:21 +0100595 setup_log(&td->slat_log);
596 setup_log(&td->clat_log);
597 }
Jens Axboeec94ec52006-10-20 10:59:19 +0200598 if (td->write_bw_log)
Jens Axboeebac4652005-12-08 15:25:21 +0100599 setup_log(&td->bw_log);
600
Jens Axboeb4692822006-10-27 13:43:22 +0200601 if (!td->name)
602 td->name = strdup(jobname);
Jens Axboe01452052006-06-07 10:29:47 +0200603
Jens Axboe3d60d1e2006-05-25 06:31:06 +0200604 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
Jens Axboe75154842006-06-01 13:56:09 +0200605
Jens Axboec6ae0a52006-06-12 11:04:44 +0200606 if (!terse_output) {
Jens Axboeb990b5c2006-09-14 09:48:22 +0200607 if (!job_add_num) {
Jens Axboe2866c822006-10-09 15:57:48 +0200608 if (td->io_ops->flags & FIO_CPUIO)
Jens Axboeb990b5c2006-09-14 09:48:22 +0200609 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
610 else
Jens Axboe2866c822006-10-09 15:57:48 +0200611 fprintf(f_out, "%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_ops->name, td->iodepth);
Jens Axboeb990b5c2006-09-14 09:48:22 +0200612 } else if (job_add_num == 1)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200613 fprintf(f_out, "...\n");
614 }
Jens Axboeebac4652005-12-08 15:25:21 +0100615
616 /*
617 * recurse add identical jobs, clear numjobs and stonewall options
618 * as they don't apply to sub-jobs
619 */
620 numjobs = td->numjobs;
621 while (--numjobs) {
622 struct thread_data *td_new = get_new_job(0, td);
623
624 if (!td_new)
625 goto err;
626
627 td_new->numjobs = 1;
628 td_new->stonewall = 0;
Jens Axboe75154842006-06-01 13:56:09 +0200629 job_add_num = numjobs - 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100630
Jens Axboe75154842006-06-01 13:56:09 +0200631 if (add_job(td_new, jobname, job_add_num))
Jens Axboeebac4652005-12-08 15:25:21 +0100632 goto err;
633 }
634 return 0;
635err:
636 put_job(td);
637 return -1;
638}
639
Jens Axboe906c8d72006-06-13 09:37:56 +0200640/*
641 * Initialize the various random states we need (random io, block size ranges,
642 * read/write mix, etc).
643 */
Jens Axboeebac4652005-12-08 15:25:21 +0100644int init_random_state(struct thread_data *td)
645{
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200646 unsigned long seeds[4];
Jens Axboe53cdc682006-10-18 11:50:58 +0200647 int fd, num_maps, blocks, i;
Jens Axboe0ab8db82006-10-18 17:16:23 +0200648 struct fio_file *f;
Jens Axboeebac4652005-12-08 15:25:21 +0100649
Jens Axboef48b4672006-10-27 11:30:07 +0200650 if (td->io_ops->flags & FIO_CPUIO)
651 return 0;
652
Jens Axboe1ac267b2006-05-31 20:29:00 +0200653 fd = open("/dev/urandom", O_RDONLY);
Jens Axboeebac4652005-12-08 15:25:21 +0100654 if (fd == -1) {
655 td_verror(td, errno);
656 return 1;
657 }
658
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200659 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
Jens Axboeebac4652005-12-08 15:25:21 +0100660 td_verror(td, EIO);
661 close(fd);
662 return 1;
663 }
664
665 close(fd);
666
Jens Axboe6dfd46b2006-06-07 13:57:06 +0200667 os_random_seed(seeds[0], &td->bsrange_state);
668 os_random_seed(seeds[1], &td->verify_state);
669 os_random_seed(seeds[2], &td->rwmix_state);
Jens Axboeebac4652005-12-08 15:25:21 +0100670
671 if (td->sequential)
672 return 0;
673
Jens Axboe9ebc27e2006-06-12 10:21:50 +0200674 if (td->rand_repeatable)
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200675 seeds[3] = DEF_RANDSEED;
Jens Axboeebac4652005-12-08 15:25:21 +0100676
Jens Axboe0ab8db82006-10-18 17:16:23 +0200677 for_each_file(td, f, i) {
Jens Axboe53cdc682006-10-18 11:50:58 +0200678 blocks = (f->file_size + td->min_bs - 1) / td->min_bs;
679 num_maps = blocks / BLOCKS_PER_MAP;
680 f->file_map = malloc(num_maps * sizeof(long));
681 f->num_maps = num_maps;
682 memset(f->file_map, 0, num_maps * sizeof(long));
683 }
Jens Axboeebac4652005-12-08 15:25:21 +0100684
Jens Axboe6dfd46b2006-06-07 13:57:06 +0200685 os_random_seed(seeds[3], &td->random_state);
Jens Axboeebac4652005-12-08 15:25:21 +0100686 return 0;
687}
688
689static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
690{
691#ifdef FIO_HAVE_CPU_AFFINITY
692 unsigned int i;
693
694 CPU_ZERO(&cpumask);
695
696 for (i = 0; i < sizeof(int) * 8; i++) {
697 if ((1 << i) & cpu)
698 CPU_SET(i, &cpumask);
699 }
700#endif
701}
702
Jens Axboeebac4652005-12-08 15:25:21 +0100703static int is_empty_or_comment(char *line)
704{
705 unsigned int i;
706
707 for (i = 0; i < strlen(line); i++) {
708 if (line[i] == ';')
709 return 1;
710 if (!isspace(line[i]) && !iscntrl(line[i]))
711 return 0;
712 }
713
714 return 1;
715}
716
Jens Axboeb4692822006-10-27 13:43:22 +0200717static int str_rw_cb(void *data, const char *mem)
Jens Axboeebac4652005-12-08 15:25:21 +0100718{
Jens Axboecb2c86f2006-10-26 13:48:34 +0200719 struct thread_data *td = data;
720
Jens Axboeebac4652005-12-08 15:25:21 +0100721 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
722 td->ddir = DDIR_READ;
723 td->sequential = 1;
724 return 0;
725 } else if (!strncmp(mem, "randread", 8)) {
726 td->ddir = DDIR_READ;
727 td->sequential = 0;
728 return 0;
729 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
730 td->ddir = DDIR_WRITE;
731 td->sequential = 1;
732 return 0;
733 } else if (!strncmp(mem, "randwrite", 9)) {
734 td->ddir = DDIR_WRITE;
735 td->sequential = 0;
736 return 0;
Jens Axboe3d60d1e2006-05-25 06:31:06 +0200737 } else if (!strncmp(mem, "rw", 2)) {
738 td->ddir = 0;
739 td->iomix = 1;
740 td->sequential = 1;
741 return 0;
742 } else if (!strncmp(mem, "randrw", 6)) {
743 td->ddir = 0;
744 td->iomix = 1;
745 td->sequential = 0;
746 return 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100747 }
748
Jens Axboe3b70d7e2006-06-08 21:48:46 +0200749 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100750 return 1;
751}
752
Jens Axboeb4692822006-10-27 13:43:22 +0200753static int str_verify_cb(void *data, const char *mem)
Jens Axboeebac4652005-12-08 15:25:21 +0100754{
Jens Axboecb2c86f2006-10-26 13:48:34 +0200755 struct thread_data *td = data;
756
Jens Axboeebac4652005-12-08 15:25:21 +0100757 if (!strncmp(mem, "0", 1)) {
758 td->verify = VERIFY_NONE;
759 return 0;
760 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
761 td->verify = VERIFY_MD5;
762 return 0;
763 } else if (!strncmp(mem, "crc32", 5)) {
764 td->verify = VERIFY_CRC32;
765 return 0;
766 }
767
Jens Axboe3b70d7e2006-06-08 21:48:46 +0200768 log_err("fio: verify types: md5, crc32\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100769 return 1;
770}
771
Jens Axboeb4692822006-10-27 13:43:22 +0200772static int str_mem_cb(void *data, const char *mem)
Jens Axboeebac4652005-12-08 15:25:21 +0100773{
Jens Axboecb2c86f2006-10-26 13:48:34 +0200774 struct thread_data *td = data;
775
Jens Axboeebac4652005-12-08 15:25:21 +0100776 if (!strncmp(mem, "malloc", 6)) {
777 td->mem_type = MEM_MALLOC;
778 return 0;
779 } else if (!strncmp(mem, "shm", 3)) {
780 td->mem_type = MEM_SHM;
781 return 0;
782 } else if (!strncmp(mem, "mmap", 4)) {
783 td->mem_type = MEM_MMAP;
784 return 0;
785 }
786
Jens Axboe3b70d7e2006-06-08 21:48:46 +0200787 log_err("fio: mem type: malloc, shm, mmap\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100788 return 1;
789}
790
Jens Axboeb4692822006-10-27 13:43:22 +0200791static int str_ioengine_cb(void *data, const char *str)
Jens Axboeebac4652005-12-08 15:25:21 +0100792{
Jens Axboecb2c86f2006-10-26 13:48:34 +0200793 struct thread_data *td = data;
794
Jens Axboe2866c822006-10-09 15:57:48 +0200795 td->io_ops = load_ioengine(td, str);
796 if (td->io_ops)
Jens Axboeebac4652005-12-08 15:25:21 +0100797 return 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100798
Jens Axboeb990b5c2006-09-14 09:48:22 +0200799 log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice, cpu\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100800 return 1;
801}
802
Jens Axboee1f36502006-10-27 10:54:08 +0200803static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
804{
805 mlock_size = *val;
806 return 0;
807}
808
809static int str_prioclass_cb(void *data, unsigned int *val)
810{
811 struct thread_data *td = data;
812
813 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
814 return 0;
815}
816
817static int str_prio_cb(void *data, unsigned int *val)
818{
819 struct thread_data *td = data;
820
821 td->ioprio |= *val;
822 return 0;
823}
824
825static int str_exitall_cb(void)
826{
827 exitall_on_terminate = 1;
828 return 0;
829}
830
831static int str_cpumask_cb(void *data, unsigned int *val)
832{
833 struct thread_data *td = data;
834
835 fill_cpu_mask(td->cpumask, *val);
836 return 0;
837}
838
Jens Axboe07261982006-06-07 10:51:12 +0200839/*
840 * This is our [ini] type file parser.
841 */
Jens Axboe0c7e37a2006-06-13 14:53:38 +0200842int parse_jobs_ini(char *file, int stonewall_flag)
Jens Axboeebac4652005-12-08 15:25:21 +0100843{
Jens Axboee1f36502006-10-27 10:54:08 +0200844 unsigned int global;
Jens Axboeebac4652005-12-08 15:25:21 +0100845 struct thread_data *td;
Jens Axboeef899b62006-06-06 09:31:00 +0200846 char *string, *name, *tmpbuf;
Jens Axboeebac4652005-12-08 15:25:21 +0100847 fpos_t off;
848 FILE *f;
849 char *p;
Jens Axboe0c7e37a2006-06-13 14:53:38 +0200850 int ret = 0, stonewall;
Jens Axboeebac4652005-12-08 15:25:21 +0100851
852 f = fopen(file, "r");
853 if (!f) {
Jens Axboeaea47d42006-05-26 19:27:29 +0200854 perror("fopen job file");
Jens Axboeebac4652005-12-08 15:25:21 +0100855 return 1;
856 }
857
858 string = malloc(4096);
859 name = malloc(256);
Jens Axboeef899b62006-06-06 09:31:00 +0200860 tmpbuf = malloc(4096);
Jens Axboeebac4652005-12-08 15:25:21 +0100861
Jens Axboe0c7e37a2006-06-13 14:53:38 +0200862 stonewall = stonewall_flag;
Jens Axboeebac4652005-12-08 15:25:21 +0100863 while ((p = fgets(string, 4096, f)) != NULL) {
Jens Axboe45410ac2006-06-07 11:10:39 +0200864 if (ret)
865 break;
Jens Axboeebac4652005-12-08 15:25:21 +0100866 if (is_empty_or_comment(p))
867 continue;
868 if (sscanf(p, "[%s]", name) != 1)
869 continue;
870
871 global = !strncmp(name, "global", 6);
872
873 name[strlen(name) - 1] = '\0';
874
875 td = get_new_job(global, &def_thread);
Jens Axboe45410ac2006-06-07 11:10:39 +0200876 if (!td) {
877 ret = 1;
878 break;
879 }
Jens Axboeebac4652005-12-08 15:25:21 +0100880
Jens Axboe972cfd22006-06-09 11:08:56 +0200881 /*
882 * Seperate multiple job files by a stonewall
883 */
Jens Axboef9481912006-06-09 11:37:28 +0200884 if (!global && stonewall) {
Jens Axboe972cfd22006-06-09 11:08:56 +0200885 td->stonewall = stonewall;
886 stonewall = 0;
887 }
888
Jens Axboeebac4652005-12-08 15:25:21 +0100889 fgetpos(f, &off);
890 while ((p = fgets(string, 4096, f)) != NULL) {
891 if (is_empty_or_comment(p))
892 continue;
893 if (strstr(p, "["))
894 break;
Jens Axboee1f36502006-10-27 10:54:08 +0200895
Jens Axboeb6754f92006-05-30 14:29:32 +0200896 strip_blank_front(&p);
Jens Axboe4ae3f762006-05-30 13:35:14 +0200897 strip_blank_end(p);
Jens Axboeaea47d42006-05-26 19:27:29 +0200898
Jens Axboee1f36502006-10-27 10:54:08 +0200899 fgetpos(f, &off);
Jens Axboeebac4652005-12-08 15:25:21 +0100900
Jens Axboe45410ac2006-06-07 11:10:39 +0200901 /*
902 * Don't break here, continue parsing options so we
903 * dump all the bad ones. Makes trial/error fixups
904 * easier on the user.
905 */
Jens Axboee1f36502006-10-27 10:54:08 +0200906 ret = parse_option(p, options, td);
Jens Axboeebac4652005-12-08 15:25:21 +0100907 }
Jens Axboeebac4652005-12-08 15:25:21 +0100908
Jens Axboe45410ac2006-06-07 11:10:39 +0200909 if (!ret) {
910 fsetpos(f, &off);
911 ret = add_job(td, name, 0);
912 }
913 if (ret)
914 break;
Jens Axboeebac4652005-12-08 15:25:21 +0100915 }
916
917 free(string);
918 free(name);
Jens Axboeef899b62006-06-06 09:31:00 +0200919 free(tmpbuf);
Jens Axboeebac4652005-12-08 15:25:21 +0100920 fclose(f);
Jens Axboe45410ac2006-06-07 11:10:39 +0200921 return ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100922}
923
924static int fill_def_thread(void)
925{
926 memset(&def_thread, 0, sizeof(def_thread));
927
928 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
929 perror("sched_getaffinity");
930 return 1;
931 }
932
933 /*
934 * fill globals
935 */
936 def_thread.ddir = DDIR_READ;
Jens Axboe3d60d1e2006-05-25 06:31:06 +0200937 def_thread.iomix = 0;
Jens Axboe9ebc27e2006-06-12 10:21:50 +0200938 def_thread.bs = DEF_BS;
Jens Axboe16b462a2006-10-30 12:35:18 +0100939 def_thread.min_bs = 0;
940 def_thread.max_bs = 0;
Jens Axboe9ebc27e2006-06-12 10:21:50 +0200941 def_thread.odirect = DEF_ODIRECT;
Jens Axboeebac4652005-12-08 15:25:21 +0100942 def_thread.ratecycle = DEF_RATE_CYCLE;
Jens Axboe9ebc27e2006-06-12 10:21:50 +0200943 def_thread.sequential = DEF_SEQUENTIAL;
Jens Axboe972cfd22006-06-09 11:08:56 +0200944 def_thread.timeout = def_timeout;
Jens Axboeebac4652005-12-08 15:25:21 +0100945 def_thread.overwrite = DEF_OVERWRITE;
946 def_thread.invalidate_cache = DEF_INVALIDATE;
947 def_thread.sync_io = DEF_SYNCIO;
948 def_thread.mem_type = MEM_MALLOC;
949 def_thread.bw_avg_time = DEF_BWAVGTIME;
950 def_thread.create_serialize = DEF_CREATE_SER;
951 def_thread.create_fsync = DEF_CREATE_FSYNC;
952 def_thread.loops = DEF_LOOPS;
953 def_thread.verify = DEF_VERIFY;
954 def_thread.stonewall = DEF_STONEWALL;
955 def_thread.numjobs = DEF_NUMJOBS;
956 def_thread.use_thread = DEF_USE_THREAD;
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200957 def_thread.rwmixcycle = DEF_RWMIX_CYCLE;
958 def_thread.rwmixread = DEF_RWMIX_READ;
Jens Axboeb6f4d882006-06-02 10:32:51 +0200959 def_thread.nice = DEF_NICE;
Jens Axboe9ebc27e2006-06-12 10:21:50 +0200960 def_thread.rand_repeatable = DEF_RAND_REPEAT;
Jens Axboe53cdc682006-10-18 11:50:58 +0200961 def_thread.nr_files = DEF_NR_FILES;
Jens Axboef6cbb262006-10-18 14:16:42 +0200962 def_thread.unlink = DEF_UNLINK;
Jens Axboeec94ec52006-10-20 10:59:19 +0200963 def_thread.write_bw_log = write_bw_log;
964 def_thread.write_lat_log = write_lat_log;
Jens Axboeebac4652005-12-08 15:25:21 +0100965#ifdef FIO_HAVE_DISK_UTIL
966 def_thread.do_disk_util = 1;
967#endif
968
969 return 0;
970}
971
Jens Axboe0ab8db82006-10-18 17:16:23 +0200972static void usage(void)
Jens Axboe4785f992006-05-26 03:59:10 +0200973{
974 printf("%s\n", fio_version_string);
Jens Axboeb4692822006-10-27 13:43:22 +0200975 printf("\t--output\tWrite output to file\n");
976 printf("\t--timeout\tRuntime in seconds\n");
977 printf("\t--latency-log\tGenerate per-job latency logs\n");
978 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
979 printf("\t--minimal\tMinimal (terse) output\n");
980 printf("\t--version\tPrint version info and exit\n");
Jens Axboe4785f992006-05-26 03:59:10 +0200981}
982
Jens Axboe972cfd22006-06-09 11:08:56 +0200983static int parse_cmd_line(int argc, char *argv[])
Jens Axboeebac4652005-12-08 15:25:21 +0100984{
Jens Axboeb4692822006-10-27 13:43:22 +0200985 struct thread_data *td = NULL;
Jens Axboec2b1e752006-10-30 09:03:13 +0100986 int c, ini_idx = 0, lidx, ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100987
Jens Axboeb4692822006-10-27 13:43:22 +0200988 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
Jens Axboeebac4652005-12-08 15:25:21 +0100989 switch (c) {
Jens Axboeb4692822006-10-27 13:43:22 +0200990 case 't':
991 def_timeout = atoi(optarg);
992 break;
993 case 'l':
994 write_lat_log = 1;
995 break;
996 case 'w':
997 write_bw_log = 1;
998 break;
999 case 'o':
1000 f_out = fopen(optarg, "w+");
1001 if (!f_out) {
1002 perror("fopen output");
1003 exit(1);
1004 }
1005 f_err = f_out;
1006 break;
1007 case 'm':
1008 terse_output = 1;
1009 break;
1010 case 'h':
1011 usage();
1012 exit(0);
1013 case 'v':
1014 printf("%s\n", fio_version_string);
1015 exit(0);
1016 case FIO_GETOPT_JOB: {
1017 const char *opt = long_options[lidx].name;
1018 char *val = optarg;
1019
Jens Axboec2b1e752006-10-30 09:03:13 +01001020 if (!strncmp(opt, "name", 4) && td) {
1021 ret = add_job(td, td->name ?: "fio", 0);
1022 if (ret) {
1023 put_job(td);
1024 return 0;
1025 }
1026 td = NULL;
1027 }
Jens Axboeb4692822006-10-27 13:43:22 +02001028 if (!td) {
Jens Axboe38d0adb2006-10-30 12:21:25 +01001029 int global = !strncmp(val, "global", 6);
Jens Axboec2b1e752006-10-30 09:03:13 +01001030
1031 td = get_new_job(global, &def_thread);
Jens Axboeb4692822006-10-27 13:43:22 +02001032 if (!td)
1033 return 0;
1034 }
Jens Axboe38d0adb2006-10-30 12:21:25 +01001035
1036 parse_cmd_option(opt, val, options, td);
Jens Axboeb4692822006-10-27 13:43:22 +02001037 break;
1038 }
1039 default:
1040 printf("optarg <<%s>>\n", argv[optind]);
1041 break;
Jens Axboeebac4652005-12-08 15:25:21 +01001042 }
1043 }
Jens Axboec9fad892006-05-27 17:26:50 +02001044
Jens Axboeb4692822006-10-27 13:43:22 +02001045 if (td) {
Jens Axboec2b1e752006-10-30 09:03:13 +01001046 ret = add_job(td, td->name ?: "fio", 0);
Jens Axboeb4692822006-10-27 13:43:22 +02001047 if (ret)
1048 put_job(td);
Jens Axboe972cfd22006-06-09 11:08:56 +02001049 }
Jens Axboe774a6172006-08-24 08:44:26 +02001050
Jens Axboeb4692822006-10-27 13:43:22 +02001051 while (optind < argc) {
1052 ini_idx++;
1053 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1054 ini_file[ini_idx - 1] = strdup(argv[optind]);
1055 optind++;
Jens Axboeeb8bbf42006-06-08 21:40:11 +02001056 }
Jens Axboe972cfd22006-06-09 11:08:56 +02001057
1058 return ini_idx;
Jens Axboeebac4652005-12-08 15:25:21 +01001059}
1060
1061static void free_shm(void)
1062{
1063 struct shmid_ds sbuf;
1064
1065 if (threads) {
Jens Axboe2c0ecd22006-06-08 13:25:41 +02001066 shmdt((void *) threads);
Jens Axboeebac4652005-12-08 15:25:21 +01001067 threads = NULL;
1068 shmctl(shm_id, IPC_RMID, &sbuf);
1069 }
1070}
1071
Jens Axboe906c8d72006-06-13 09:37:56 +02001072/*
1073 * The thread area is shared between the main process and the job
1074 * threads/processes. So setup a shared memory segment that will hold
1075 * all the job info.
1076 */
Jens Axboeebac4652005-12-08 15:25:21 +01001077static int setup_thread_area(void)
1078{
1079 /*
1080 * 1024 is too much on some machines, scale max_jobs if
1081 * we get a failure that looks like too large a shm segment
1082 */
1083 do {
Jens Axboe906c8d72006-06-13 09:37:56 +02001084 size_t size = max_jobs * sizeof(struct thread_data);
Jens Axboeebac4652005-12-08 15:25:21 +01001085
Jens Axboe906c8d72006-06-13 09:37:56 +02001086 shm_id = shmget(0, size, IPC_CREAT | 0600);
Jens Axboeebac4652005-12-08 15:25:21 +01001087 if (shm_id != -1)
1088 break;
1089 if (errno != EINVAL) {
1090 perror("shmget");
1091 break;
1092 }
1093
1094 max_jobs >>= 1;
1095 } while (max_jobs);
1096
1097 if (shm_id == -1)
1098 return 1;
1099
1100 threads = shmat(shm_id, NULL, 0);
1101 if (threads == (void *) -1) {
1102 perror("shmat");
1103 return 1;
1104 }
1105
1106 atexit(free_shm);
1107 return 0;
1108}
1109
Jens Axboeb4692822006-10-27 13:43:22 +02001110/*
1111 * Copy the fio options into the long options map, so we mirror
1112 * job and cmd line options.
1113 */
1114static void dupe_job_options(void)
1115{
1116 struct fio_option *o;
1117 unsigned int i;
1118
1119 i = 0;
1120 while (long_options[i].name)
1121 i++;
1122
1123 o = &options[0];
1124 while (o->name) {
1125 long_options[i].name = o->name;
1126 long_options[i].val = FIO_GETOPT_JOB;
1127 if (o->type == FIO_OPT_STR_SET)
1128 long_options[i].has_arg = no_argument;
1129 else
1130 long_options[i].has_arg = required_argument;
1131
1132 i++;
1133 o++;
1134 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1135 }
1136}
1137
Jens Axboeebac4652005-12-08 15:25:21 +01001138int parse_options(int argc, char *argv[])
1139{
Jens Axboe972cfd22006-06-09 11:08:56 +02001140 int job_files, i;
1141
Jens Axboeb4692822006-10-27 13:43:22 +02001142 f_out = stdout;
1143 f_err = stderr;
1144
1145 dupe_job_options();
1146
Jens Axboeebac4652005-12-08 15:25:21 +01001147 if (setup_thread_area())
1148 return 1;
1149 if (fill_def_thread())
1150 return 1;
1151
Jens Axboe972cfd22006-06-09 11:08:56 +02001152 job_files = parse_cmd_line(argc, argv);
Jens Axboeebac4652005-12-08 15:25:21 +01001153
Jens Axboe972cfd22006-06-09 11:08:56 +02001154 for (i = 0; i < job_files; i++) {
1155 if (fill_def_thread())
1156 return 1;
Jens Axboe0c7e37a2006-06-13 14:53:38 +02001157 if (parse_jobs_ini(ini_file[i], i))
Jens Axboe972cfd22006-06-09 11:08:56 +02001158 return 1;
Jens Axboe88c6ed82006-06-09 11:28:10 +02001159 free(ini_file[i]);
Jens Axboe972cfd22006-06-09 11:08:56 +02001160 }
Jens Axboeebac4652005-12-08 15:25:21 +01001161
Jens Axboe88c6ed82006-06-09 11:28:10 +02001162 free(ini_file);
Jens Axboeb4692822006-10-27 13:43:22 +02001163
1164 if (!thread_number) {
1165 log_err("No jobs defined(s)\n");
1166 usage();
1167 return 1;
1168 }
1169
Jens Axboeebac4652005-12-08 15:25:21 +01001170 return 0;
1171}