blob: 4eb0df2def2e529ca5a3165e506d0775f8a10ab0 [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>
11#include <sys/ipc.h>
12#include <sys/shm.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15
16#include "fio.h"
Jens Axboecb2c86f2006-10-26 13:48:34 +020017#include "parse.h"
Jens Axboe2e5cdb12008-03-01 18:52:49 +010018#include "smalloc.h"
Jens Axboe380065a2008-03-01 18:56:24 +010019#include "filehash.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020020#include "verify.h"
Jens Axboe79d16312010-03-04 12:43:20 +010021#include "profile.h"
Jens Axboeebac4652005-12-08 15:25:21 +010022
Cigy Cyriacbf2e8212010-08-10 19:51:11 -040023#include "lib/getopt.h"
24
Jens Axboe723cd802011-09-16 08:44:10 +020025static char fio_version_string[] = "fio 1.58";
Jens Axboe214e1ec2007-03-15 10:48:13 +010026
Jens Axboeee738492007-01-10 11:23:16 +010027#define FIO_RANDSEED (0xb1899bedUL)
Jens Axboeebac4652005-12-08 15:25:21 +010028
Jens Axboe214e1ec2007-03-15 10:48:13 +010029static char **ini_file;
Jens Axboefca70352011-07-06 20:12:54 +020030static int max_jobs = FIO_MAX_JOBS;
Jens Axboecca73aa2007-04-04 11:09:19 +020031static int dump_cmdline;
Jens Axboe8c029372011-10-05 09:54:30 +020032static int def_timeout;
Jens Axboee1f36502006-10-27 10:54:08 +020033
Jens Axboebe4ecfd2008-12-08 14:10:52 +010034static struct thread_data def_thread;
Jens Axboe214e1ec2007-03-15 10:48:13 +010035struct thread_data *threads = NULL;
Jens Axboee1f36502006-10-27 10:54:08 +020036
Jens Axboe214e1ec2007-03-15 10:48:13 +010037int exitall_on_terminate = 0;
38int terse_output = 0;
Aaron Carrolle592a062007-09-14 09:49:41 +020039int eta_print;
Jens Axboe214e1ec2007-03-15 10:48:13 +010040unsigned long long mlock_size = 0;
41FILE *f_out = NULL;
42FILE *f_err = NULL;
Jens Axboead0a2732011-03-11 10:16:17 +010043char **job_sections = NULL;
44int nr_job_sections = 0;
Jens Axboe07b32322010-03-05 09:48:44 +010045char *exec_profile = NULL;
Jens Axboea9523c62011-01-17 16:49:54 -070046int warnings_fatal = 0;
Jens Axboef57a9c52011-09-09 21:01:37 +020047int terse_version = 2;
Jens Axboeee738492007-01-10 11:23:16 +010048
Jens Axboe214e1ec2007-03-15 10:48:13 +010049int write_bw_log = 0;
Jens Axboe4241ea82007-09-12 08:18:36 +020050int read_only = 0;
Jens Axboee1f36502006-10-27 10:54:08 +020051
Jens Axboe5ec10ea2008-03-06 15:42:00 +010052static int write_lat_log;
Jens Axboe214e1ec2007-03-15 10:48:13 +010053
54static int prev_group_jobs;
Jens Axboeb4692822006-10-27 13:43:22 +020055
Jens Axboeee56ad52008-02-01 10:30:20 +010056unsigned long fio_debug = 0;
Jens Axboe5e1d3062008-05-23 11:55:53 +020057unsigned int fio_debug_jobno = -1;
58unsigned int *fio_debug_jobp = NULL;
Jens Axboeee56ad52008-02-01 10:30:20 +010059
Jens Axboe4c6107f2011-01-18 05:22:22 -070060static char cmd_optstr[256];
61
Jens Axboeb4692822006-10-27 13:43:22 +020062/*
63 * Command line options. These will contain the above, plus a few
64 * extra that only pertain to fio itself and not jobs.
65 */
Jens Axboe5ec10ea2008-03-06 15:42:00 +010066static struct option l_opts[FIO_NR_OPTIONS] = {
Jens Axboeb4692822006-10-27 13:43:22 +020067 {
Jens Axboe08d2a192011-05-11 13:28:30 +020068 .name = (char *) "output",
Jens Axboeb4692822006-10-27 13:43:22 +020069 .has_arg = required_argument,
70 .val = 'o',
71 },
72 {
Jens Axboe08d2a192011-05-11 13:28:30 +020073 .name = (char *) "timeout",
Jens Axboeb4692822006-10-27 13:43:22 +020074 .has_arg = required_argument,
75 .val = 't',
76 },
77 {
Jens Axboe08d2a192011-05-11 13:28:30 +020078 .name = (char *) "latency-log",
Jens Axboeb4692822006-10-27 13:43:22 +020079 .has_arg = required_argument,
80 .val = 'l',
81 },
82 {
Jens Axboe08d2a192011-05-11 13:28:30 +020083 .name = (char *) "bandwidth-log",
Jens Axboeb4692822006-10-27 13:43:22 +020084 .has_arg = required_argument,
85 .val = 'b',
86 },
87 {
Jens Axboe08d2a192011-05-11 13:28:30 +020088 .name = (char *) "minimal",
Jens Axboeb4692822006-10-27 13:43:22 +020089 .has_arg = optional_argument,
90 .val = 'm',
91 },
92 {
Jens Axboe08d2a192011-05-11 13:28:30 +020093 .name = (char *) "version",
Jens Axboeb4692822006-10-27 13:43:22 +020094 .has_arg = no_argument,
95 .val = 'v',
96 },
97 {
Jens Axboe08d2a192011-05-11 13:28:30 +020098 .name = (char *) "help",
Jens Axboefd28ca42007-01-09 21:20:13 +010099 .has_arg = no_argument,
100 .val = 'h',
101 },
102 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200103 .name = (char *) "cmdhelp",
Jens Axboe320beef2007-03-01 10:44:12 +0100104 .has_arg = optional_argument,
Jens Axboefd28ca42007-01-09 21:20:13 +0100105 .val = 'c',
106 },
107 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200108 .name = (char *) "showcmd",
Jens Axboecca73aa2007-04-04 11:09:19 +0200109 .has_arg = no_argument,
Jens Axboe724e4432007-09-11 20:02:05 +0200110 .val = 's',
111 },
112 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200113 .name = (char *) "readonly",
Jens Axboe724e4432007-09-11 20:02:05 +0200114 .has_arg = no_argument,
115 .val = 'r',
Jens Axboecca73aa2007-04-04 11:09:19 +0200116 },
117 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200118 .name = (char *) "eta",
Aaron Carrolle592a062007-09-14 09:49:41 +0200119 .has_arg = required_argument,
120 .val = 'e',
121 },
122 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200123 .name = (char *) "debug",
Jens Axboeee56ad52008-02-01 10:30:20 +0100124 .has_arg = required_argument,
125 .val = 'd',
126 },
127 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200128 .name = (char *) "section",
Jens Axboe01f06b62008-02-18 20:53:47 +0100129 .has_arg = required_argument,
130 .val = 'x',
131 },
132 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200133 .name = (char *) "alloc-size",
Jens Axboe2b386d22008-03-26 10:32:57 +0100134 .has_arg = required_argument,
135 .val = 'a',
136 },
137 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200138 .name = (char *) "profile",
Jens Axboe9ac8a792009-11-13 21:23:07 +0100139 .has_arg = required_argument,
140 .val = 'p',
141 },
142 {
Jens Axboe08d2a192011-05-11 13:28:30 +0200143 .name = (char *) "warnings-fatal",
Jens Axboea9523c62011-01-17 16:49:54 -0700144 .has_arg = no_argument,
145 .val = 'w',
146 },
147 {
Jens Axboefca70352011-07-06 20:12:54 +0200148 .name = (char *) "max-jobs",
149 .has_arg = required_argument,
150 .val = 'j',
151 },
152 {
Jens Axboef57a9c52011-09-09 21:01:37 +0200153 .name = (char *) "terse-version",
154 .has_arg = required_argument,
155 .val = 'V',
156 },
157 {
Jens Axboeb4692822006-10-27 13:43:22 +0200158 .name = NULL,
159 },
160};
161
Joel Becker9728ce32007-03-01 08:24:39 +0100162FILE *get_f_out()
163{
164 return f_out;
165}
166
167FILE *get_f_err()
168{
169 return f_err;
170}
171
Jens Axboe906c8d72006-06-13 09:37:56 +0200172/*
173 * Return a free job structure.
174 */
Jens Axboeebac4652005-12-08 15:25:21 +0100175static struct thread_data *get_new_job(int global, struct thread_data *parent)
176{
177 struct thread_data *td;
178
179 if (global)
180 return &def_thread;
Bruce Crane61f1ec2011-01-14 18:30:26 +0100181 if (thread_number >= max_jobs) {
182 log_err("error: maximum number of jobs (%d) reached.\n",
183 max_jobs);
Jens Axboeebac4652005-12-08 15:25:21 +0100184 return NULL;
Bruce Crane61f1ec2011-01-14 18:30:26 +0100185 }
Jens Axboeebac4652005-12-08 15:25:21 +0100186
187 td = &threads[thread_number++];
Jens Axboeddaeaa52006-06-08 11:00:58 +0200188 *td = *parent;
Jens Axboeebac4652005-12-08 15:25:21 +0100189
Jens Axboee0b0d892009-12-08 10:10:14 +0100190 td->o.uid = td->o.gid = -1U;
191
Jens Axboecade3ef2007-03-23 15:29:45 +0100192 dup_files(td, parent);
Jens Axboed23bb322007-03-23 15:57:56 +0100193 options_mem_dupe(td);
Jens Axboecade3ef2007-03-23 15:29:45 +0100194
Jens Axboe15dc1932010-03-05 10:59:06 +0100195 profile_add_hooks(td);
196
Jens Axboeebac4652005-12-08 15:25:21 +0100197 td->thread_number = thread_number;
Jens Axboeebac4652005-12-08 15:25:21 +0100198 return td;
199}
200
201static void put_job(struct thread_data *td)
202{
Jens Axboe549577a2006-10-30 12:23:41 +0100203 if (td == &def_thread)
204 return;
Bruce Cran84dd1882011-05-05 08:14:09 -0600205
Jens Axboe58c55ba2010-03-09 12:20:08 +0100206 profile_td_exit(td);
Jens Axboe549577a2006-10-30 12:23:41 +0100207
Jens Axboe16edf252007-02-10 14:59:22 +0100208 if (td->error)
Jens Axboe6d861442007-03-15 09:22:23 +0100209 log_info("fio: %s\n", td->verror);
Jens Axboe16edf252007-02-10 14:59:22 +0100210
Jens Axboeebac4652005-12-08 15:25:21 +0100211 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
212 thread_number--;
213}
214
Jens Axboe581e7142009-06-09 12:47:16 +0200215static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
Jens Axboe127f6862007-03-15 12:09:57 +0100216{
Jens Axboe581e7142009-06-09 12:47:16 +0200217 unsigned int bs = td->o.min_bs[ddir];
Radha Ramachandranba3e4e02009-12-09 22:31:44 +0100218 unsigned long long bytes_per_sec;
Jens Axboe127f6862007-03-15 12:09:57 +0100219
Jens Axboeff58fce2010-08-25 12:02:08 +0200220 assert(ddir_rw(ddir));
221
Radha Ramachandranba3e4e02009-12-09 22:31:44 +0100222 if (td->o.rate[ddir])
223 bytes_per_sec = td->o.rate[ddir];
224 else
225 bytes_per_sec = td->o.rate_iops[ddir] * bs;
Jens Axboe127f6862007-03-15 12:09:57 +0100226
Radha Ramachandranba3e4e02009-12-09 22:31:44 +0100227 if (!bytes_per_sec) {
Jens Axboe127f6862007-03-15 12:09:57 +0100228 log_err("rate lower than supported\n");
229 return -1;
230 }
231
Radha Ramachandranba3e4e02009-12-09 22:31:44 +0100232 td->rate_nsec_cycle[ddir] = 1000000000ULL / bytes_per_sec;
Jens Axboe581e7142009-06-09 12:47:16 +0200233 td->rate_pending_usleep[ddir] = 0;
Jens Axboe127f6862007-03-15 12:09:57 +0100234 return 0;
235}
236
Jens Axboe581e7142009-06-09 12:47:16 +0200237static int setup_rate(struct thread_data *td)
238{
239 int ret = 0;
240
241 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
242 ret = __setup_rate(td, DDIR_READ);
243 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
244 ret |= __setup_rate(td, DDIR_WRITE);
245
246 return ret;
247}
248
Jens Axboe83472392009-02-19 21:32:12 +0100249static int fixed_block_size(struct thread_options *o)
250{
251 return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
252 o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
253 o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE];
254}
255
Jens Axboedad915e2006-10-27 11:10:18 +0200256/*
257 * Lazy way of fixing up options that depend on each other. We could also
258 * define option callback handlers, but this is easier.
259 */
Jens Axboe4e991c22007-03-15 11:41:11 +0100260static int fixup_options(struct thread_data *td)
Jens Axboee1f36502006-10-27 10:54:08 +0200261{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100262 struct thread_options *o = &td->o;
Jens Axboeff217452011-01-18 22:33:02 -0700263 int ret = 0;
Jens Axboedad915e2006-10-27 11:10:18 +0200264
Jens Axboef356d012009-01-05 09:56:29 +0100265#ifndef FIO_HAVE_PSHARED_MUTEX
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100266 if (!o->use_thread) {
Jens Axboef356d012009-01-05 09:56:29 +0100267 log_info("fio: this platform does not support process shared"
268 " mutexes, forcing use of threads. Use the 'thread'"
269 " option to get rid of this warning.\n");
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100270 o->use_thread = 1;
Jens Axboea9523c62011-01-17 16:49:54 -0700271 ret = warnings_fatal;
Jens Axboef356d012009-01-05 09:56:29 +0100272 }
273#endif
274
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100275 if (o->write_iolog_file && o->read_iolog_file) {
Jens Axboe076efc72006-10-27 11:24:25 +0200276 log_err("fio: read iolog overrides write_iolog\n");
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100277 free(o->write_iolog_file);
278 o->write_iolog_file = NULL;
Jens Axboea9523c62011-01-17 16:49:54 -0700279 ret = warnings_fatal;
Jens Axboe076efc72006-10-27 11:24:25 +0200280 }
Jens Axboe16b462a2006-10-30 12:35:18 +0100281
Jens Axboe16b462a2006-10-30 12:35:18 +0100282 /*
283 * only really works for sequential io for now, and with 1 file
284 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100285 if (o->zone_size && td_random(td) && o->open_files == 1)
286 o->zone_size = 0;
Jens Axboe16b462a2006-10-30 12:35:18 +0100287
288 /*
289 * Reads can do overwrites, we always need to pre-create the file
290 */
291 if (td_read(td) || td_rw(td))
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100292 o->overwrite = 1;
Jens Axboe16b462a2006-10-30 12:35:18 +0100293
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100294 if (!o->min_bs[DDIR_READ])
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100295 o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100296 if (!o->max_bs[DDIR_READ])
297 o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
298 if (!o->min_bs[DDIR_WRITE])
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100299 o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100300 if (!o->max_bs[DDIR_WRITE])
301 o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
Jens Axboea00735e2006-11-03 08:58:08 +0100302
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100303 o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
Jens Axboea00735e2006-11-03 08:58:08 +0100304
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100305 /*
306 * For random IO, allow blockalign offset other than min_bs.
307 */
308 if (!o->ba[DDIR_READ] || !td_random(td))
309 o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
310 if (!o->ba[DDIR_WRITE] || !td_random(td))
311 o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
312
313 if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
314 o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE]) &&
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100315 !o->norandommap) {
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100316 log_err("fio: Any use of blockalign= turns off randommap\n");
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100317 o->norandommap = 1;
Jens Axboea9523c62011-01-17 16:49:54 -0700318 ret = warnings_fatal;
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100319 }
320
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100321 if (!o->file_size_high)
322 o->file_size_high = o->file_size_low;
Jens Axboe9c60ce62007-03-15 09:14:47 +0100323
Jens Axboe83472392009-02-19 21:32:12 +0100324 if (o->norandommap && o->verify != VERIFY_NONE
325 && !fixed_block_size(o)) {
326 log_err("fio: norandommap given for variable block sizes, "
327 "verify disabled\n");
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100328 o->verify = VERIFY_NONE;
Jens Axboea9523c62011-01-17 16:49:54 -0700329 ret = warnings_fatal;
Jens Axboebb8895e2006-10-30 15:14:48 +0100330 }
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100331 if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
Jens Axboe690adba2006-10-30 15:25:09 +0100332 log_err("fio: bs_unaligned may not work with raw io\n");
Jens Axboee0a22332006-12-20 12:54:25 +0100333
334 /*
Jens Axboe48097d52007-02-17 06:30:44 +0100335 * thinktime_spin must be less than thinktime
336 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100337 if (o->thinktime_spin > o->thinktime)
338 o->thinktime_spin = o->thinktime;
Jens Axboee916b392007-02-20 14:37:26 +0100339
340 /*
341 * The low water mark cannot be bigger than the iodepth
342 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100343 if (o->iodepth_low > o->iodepth || !o->iodepth_low) {
Jens Axboe9467b772007-02-27 19:56:43 +0100344 /*
345 * syslet work around - if the workload is sequential,
346 * we want to let the queue drain all the way down to
347 * avoid seeking between async threads
348 */
349 if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100350 o->iodepth_low = 1;
Jens Axboe9467b772007-02-27 19:56:43 +0100351 else
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100352 o->iodepth_low = o->iodepth;
Jens Axboe9467b772007-02-27 19:56:43 +0100353 }
Jens Axboecb5ab512007-02-26 12:57:09 +0100354
355 /*
356 * If batch number isn't set, default to the same as iodepth
357 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100358 if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
359 o->iodepth_batch = o->iodepth;
Jens Axboeb5af8292007-03-08 12:43:13 +0100360
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100361 if (o->nr_files > td->files_index)
362 o->nr_files = td->files_index;
Jens Axboe9f9214f2007-03-13 14:02:16 +0100363
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100364 if (o->open_files > o->nr_files || !o->open_files)
365 o->open_files = o->nr_files;
Jens Axboe4e991c22007-03-15 11:41:11 +0100366
Jens Axboe581e7142009-06-09 12:47:16 +0200367 if (((o->rate[0] + o->rate[1]) && (o->rate_iops[0] + o->rate_iops[1]))||
368 ((o->ratemin[0] + o->ratemin[1]) && (o->rate_iops_min[0] +
369 o->rate_iops_min[1]))) {
Jens Axboe4e991c22007-03-15 11:41:11 +0100370 log_err("fio: rate and rate_iops are mutually exclusive\n");
Jens Axboea9523c62011-01-17 16:49:54 -0700371 ret = 1;
Jens Axboe4e991c22007-03-15 11:41:11 +0100372 }
Jens Axboe581e7142009-06-09 12:47:16 +0200373 if ((o->rate[0] < o->ratemin[0]) || (o->rate[1] < o->ratemin[1]) ||
374 (o->rate_iops[0] < o->rate_iops_min[0]) ||
375 (o->rate_iops[1] < o->rate_iops_min[1])) {
Jens Axboe4e991c22007-03-15 11:41:11 +0100376 log_err("fio: minimum rate exceeds rate\n");
Jens Axboea9523c62011-01-17 16:49:54 -0700377 ret = 1;
Jens Axboe4e991c22007-03-15 11:41:11 +0100378 }
379
Jens Axboecf4464c2007-04-17 20:14:42 +0200380 if (!o->timeout && o->time_based) {
381 log_err("fio: time_based requires a runtime/timeout setting\n");
382 o->time_based = 0;
Jens Axboea9523c62011-01-17 16:49:54 -0700383 ret = warnings_fatal;
Jens Axboecf4464c2007-04-17 20:14:42 +0200384 }
385
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100386 if (o->fill_device && !o->size)
Jens Axboe5921e802008-05-30 15:02:38 +0200387 o->size = -1ULL;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100388
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100389 if (o->verify != VERIFY_NONE) {
Jens Axboe996936f2011-01-18 05:41:39 -0700390 if (td_write(td) && o->do_verify && o->numjobs > 1) {
Jens Axboea9523c62011-01-17 16:49:54 -0700391 log_info("Multiple writers may overwrite blocks that "
392 "belong to other jobs. This can cause "
393 "verification failures.\n");
394 ret = warnings_fatal;
395 }
396
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100397 o->refill_buffers = 1;
Jens Axboe2f1b8e82010-06-18 09:22:56 +0200398 if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
399 !o->verify_interval)
400 o->verify_interval = o->min_bs[DDIR_WRITE];
Jens Axboed9905882010-03-18 20:43:00 +0100401 }
Jens Axboe41ccd842008-05-22 09:17:33 +0200402
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100403 if (o->pre_read) {
404 o->invalidate_cache = 0;
Jens Axboea9523c62011-01-17 16:49:54 -0700405 if (td->io_ops->flags & FIO_PIPEIO) {
Jens Axboe9c0d2242009-07-01 12:26:28 +0200406 log_info("fio: cannot pre-read files with an IO engine"
407 " that isn't seekable. Pre-read disabled.\n");
Jens Axboea9523c62011-01-17 16:49:54 -0700408 ret = warnings_fatal;
409 }
Jens Axboe9c0d2242009-07-01 12:26:28 +0200410 }
Jens Axboe34f1c042009-06-02 14:19:25 +0200411
Joshua Aunee72fa4d2010-02-11 00:59:18 -0700412#ifndef FIO_HAVE_FDATASYNC
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100413 if (o->fdatasync_blocks) {
Joshua Aunee72fa4d2010-02-11 00:59:18 -0700414 log_info("fio: this platform does not support fdatasync()"
415 " falling back to using fsync(). Use the 'fsync'"
416 " option instead of 'fdatasync' to get rid of"
417 " this warning\n");
Jens Axboe9bbf57c2010-03-18 20:45:43 +0100418 o->fsync_blocks = o->fdatasync_blocks;
419 o->fdatasync_blocks = 0;
Jens Axboea9523c62011-01-17 16:49:54 -0700420 ret = warnings_fatal;
Joshua Aunee72fa4d2010-02-11 00:59:18 -0700421 }
422#endif
423
Jens Axboea9523c62011-01-17 16:49:54 -0700424 return ret;
Jens Axboee1f36502006-10-27 10:54:08 +0200425}
426
Jens Axboe906c8d72006-06-13 09:37:56 +0200427/*
Jens Axboef8977ee2006-11-06 14:03:03 +0100428 * This function leaks the buffer
429 */
430static char *to_kmg(unsigned int val)
431{
432 char *buf = malloc(32);
Jens Axboef3502ba2007-02-14 01:27:09 +0100433 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
Jens Axboef8977ee2006-11-06 14:03:03 +0100434 char *p = post;
435
Jens Axboe245142f2006-11-08 12:49:21 +0100436 do {
Jens Axboef8977ee2006-11-06 14:03:03 +0100437 if (val & 1023)
438 break;
439
440 val >>= 10;
441 p++;
Jens Axboe245142f2006-11-08 12:49:21 +0100442 } while (*p);
Jens Axboef8977ee2006-11-06 14:03:03 +0100443
444 snprintf(buf, 31, "%u%c", val, *p);
445 return buf;
446}
447
Jens Axboe09629a92007-03-09 09:00:06 +0100448/* External engines are specified by "external:name.o") */
449static const char *get_engine_name(const char *str)
450{
451 char *p = strstr(str, ":");
452
453 if (!p)
454 return str;
455
456 p++;
457 strip_blank_front(&p);
458 strip_blank_end(p);
459 return p;
460}
461
Jens Axboee132cba2007-03-14 14:23:54 +0100462static int exists_and_not_file(const char *filename)
463{
464 struct stat sb;
465
466 if (lstat(filename, &sb) == -1)
467 return 0;
468
Bruce Cranecc314b2011-01-04 10:59:30 +0100469 /* \\.\ is the device namespace in Windows, where every file
470 * is a device node */
471 if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
Jens Axboee132cba2007-03-14 14:23:54 +0100472 return 0;
473
474 return 1;
475}
476
Jens Axboe4c07ad82011-03-28 09:51:09 +0200477static void td_fill_rand_seeds_os(struct thread_data *td)
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200478{
479 os_random_seed(td->rand_seeds[0], &td->bsrange_state);
480 os_random_seed(td->rand_seeds[1], &td->verify_state);
481 os_random_seed(td->rand_seeds[2], &td->rwmix_state);
482
483 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
484 os_random_seed(td->rand_seeds[3], &td->next_file_state);
485
486 os_random_seed(td->rand_seeds[5], &td->file_size_state);
Jens Axboe0d29de82010-09-01 13:54:15 +0200487 os_random_seed(td->rand_seeds[6], &td->trim_state);
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200488
489 if (!td_random(td))
490 return;
491
492 if (td->o.rand_repeatable)
493 td->rand_seeds[4] = FIO_RANDSEED * td->thread_number;
494
495 os_random_seed(td->rand_seeds[4], &td->random_state);
Jens Axboe4c07ad82011-03-28 09:51:09 +0200496}
497
498static void td_fill_rand_seeds_internal(struct thread_data *td)
499{
500 init_rand_seed(&td->__bsrange_state, td->rand_seeds[0]);
501 init_rand_seed(&td->__verify_state, td->rand_seeds[1]);
502 init_rand_seed(&td->__rwmix_state, td->rand_seeds[2]);
503
504 if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
505 init_rand_seed(&td->__next_file_state, td->rand_seeds[3]);
506
507 init_rand_seed(&td->__file_size_state, td->rand_seeds[5]);
508 init_rand_seed(&td->__trim_state, td->rand_seeds[6]);
509
510 if (!td_random(td))
511 return;
512
513 if (td->o.rand_repeatable)
514 td->rand_seeds[4] = FIO_RANDSEED * td->thread_number;
515
Jens Axboe2615cc42011-03-28 09:35:09 +0200516 init_rand_seed(&td->__random_state, td->rand_seeds[4]);
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200517}
518
Jens Axboe4c07ad82011-03-28 09:51:09 +0200519void td_fill_rand_seeds(struct thread_data *td)
520{
521 if (td->o.use_os_rand)
522 td_fill_rand_seeds_os(td);
523 else
524 td_fill_rand_seeds_internal(td);
Jens Axboe3545a102011-08-31 15:20:15 -0600525
526 init_rand_seed(&td->buf_state, td->rand_seeds[7]);
Jens Axboe4c07ad82011-03-28 09:51:09 +0200527}
528
Jens Axboef8977ee2006-11-06 14:03:03 +0100529/*
Jens Axboe9c60ce62007-03-15 09:14:47 +0100530 * Initialize the various random states we need (random io, block size ranges,
531 * read/write mix, etc).
532 */
533static int init_random_state(struct thread_data *td)
534{
Jens Axboe68727072007-03-15 20:49:25 +0100535 int fd;
Jens Axboe9c60ce62007-03-15 09:14:47 +0100536
537 fd = open("/dev/urandom", O_RDONLY);
538 if (fd == -1) {
539 td_verror(td, errno, "open");
540 return 1;
541 }
542
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200543 if (read(fd, td->rand_seeds, sizeof(td->rand_seeds)) <
544 (int) sizeof(td->rand_seeds)) {
Jens Axboe9c60ce62007-03-15 09:14:47 +0100545 td_verror(td, EIO, "read");
546 close(fd);
547 return 1;
548 }
549
550 close(fd);
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200551 td_fill_rand_seeds(td);
Jens Axboe9c60ce62007-03-15 09:14:47 +0100552 return 0;
553}
554
Jens Axboe9c60ce62007-03-15 09:14:47 +0100555/*
Jens Axboe906c8d72006-06-13 09:37:56 +0200556 * Adds a job to the list of things todo. Sanitizes the various options
557 * to make sure we don't have conflicts, and initializes various
558 * members of td.
559 */
Jens Axboe75154842006-06-01 13:56:09 +0200560static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
Jens Axboeebac4652005-12-08 15:25:21 +0100561{
Jens Axboe413dd452007-02-23 09:26:09 +0100562 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
563 "randread", "randwrite", "randrw" };
Jens Axboeaf52b342007-03-13 10:07:47 +0100564 unsigned int i;
Jens Axboe09629a92007-03-09 09:00:06 +0100565 const char *engine;
Jens Axboeaf52b342007-03-13 10:07:47 +0100566 char fname[PATH_MAX];
Jens Axboee132cba2007-03-14 14:23:54 +0100567 int numjobs, file_alloced;
Jens Axboeebac4652005-12-08 15:25:21 +0100568
Jens Axboeebac4652005-12-08 15:25:21 +0100569 /*
570 * the def_thread is just for options, it's not a real job
571 */
572 if (td == &def_thread)
573 return 0;
574
Jens Axboecca73aa2007-04-04 11:09:19 +0200575 /*
576 * if we are just dumping the output command line, don't add the job
577 */
578 if (dump_cmdline) {
579 put_job(td);
580 return 0;
581 }
582
Jens Axboe58c55ba2010-03-09 12:20:08 +0100583 if (profile_td_init(td))
Jens Axboe66251552011-05-12 10:14:57 +0200584 goto err;
Jens Axboe58c55ba2010-03-09 12:20:08 +0100585
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100586 engine = get_engine_name(td->o.ioengine);
Jens Axboe09629a92007-03-09 09:00:06 +0100587 td->io_ops = load_ioengine(td, engine);
588 if (!td->io_ops) {
589 log_err("fio: failed to load engine %s\n", engine);
Jens Axboe205927a2007-03-15 11:06:32 +0100590 goto err;
Jens Axboe09629a92007-03-09 09:00:06 +0100591 }
Jens Axboedf641192006-10-12 07:55:41 +0200592
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100593 if (td->o.use_thread)
Jens Axboe9cedf162007-03-12 11:29:30 +0100594 nr_thread++;
595 else
596 nr_process++;
597
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100598 if (td->o.odirect)
Jens Axboe690adba2006-10-30 15:25:09 +0100599 td->io_ops->flags |= FIO_RAWIO;
600
Jens Axboee132cba2007-03-14 14:23:54 +0100601 file_alloced = 0;
Jens Axboe691c8fb2008-03-07 14:26:26 +0100602 if (!td->o.filename && !td->files_index && !td->o.read_iolog_file) {
Jens Axboee132cba2007-03-14 14:23:54 +0100603 file_alloced = 1;
Jens Axboe80be24f2007-03-12 11:01:25 +0100604
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100605 if (td->o.nr_files == 1 && exists_and_not_file(jobname))
Jens Axboee132cba2007-03-14 14:23:54 +0100606 add_file(td, jobname);
Jens Axboe7b05a212007-03-13 11:17:07 +0100607 else {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100608 for (i = 0; i < td->o.nr_files; i++) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100609 sprintf(fname, "%s.%d.%d", jobname,
610 td->thread_number, i);
Jens Axboe7b05a212007-03-13 11:17:07 +0100611 add_file(td, fname);
612 }
Jens Axboeaf52b342007-03-13 10:07:47 +0100613 }
Jens Axboe0af7b542006-02-17 10:10:12 +0100614 }
Jens Axboeebac4652005-12-08 15:25:21 +0100615
Jens Axboe4e991c22007-03-15 11:41:11 +0100616 if (fixup_options(td))
617 goto err;
Jens Axboee0a22332006-12-20 12:54:25 +0100618
Jens Axboe07eb79d2007-04-12 13:02:38 +0200619 if (td->io_ops->flags & FIO_DISKLESSIO) {
620 struct fio_file *f;
621
622 for_each_file(td, f, i)
623 f->real_file_size = -1ULL;
624 }
625
Jens Axboecdd18ad2008-02-27 18:58:00 +0100626 td->mutex = fio_mutex_init(0);
Jens Axboeebac4652005-12-08 15:25:21 +0100627
Yu-ju Hong83349192011-08-13 00:53:44 +0200628 td->ts.clat_percentiles = td->o.clat_percentiles;
629 if (td->o.overwrite_plist)
630 td->ts.percentile_list = td->o.percentile_list;
631 else
632 td->ts.percentile_list = NULL;
633
Jens Axboe756867b2007-03-06 15:19:24 +0100634 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
635 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
Jens Axboe02af0982010-06-24 09:59:34 +0200636 td->ts.lat_stat[0].min_val = td->ts.lat_stat[1].min_val = ULONG_MAX;
Jens Axboe756867b2007-03-06 15:19:24 +0100637 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
Adam DeBellinscdd54112010-09-28 13:22:55 +0900638 td->ddir_seq_nr = td->o.ddir_seq_nr;
Jens Axboeebac4652005-12-08 15:25:21 +0100639
Jens Axboe755c3182009-08-25 22:14:29 +0200640 if ((td->o.stonewall || td->o.new_group) && prev_group_jobs) {
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100641 prev_group_jobs = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100642 groupid++;
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100643 }
Jens Axboeebac4652005-12-08 15:25:21 +0100644
645 td->groupid = groupid;
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100646 prev_group_jobs++;
Jens Axboeebac4652005-12-08 15:25:21 +0100647
Jens Axboe9c60ce62007-03-15 09:14:47 +0100648 if (init_random_state(td))
649 goto err;
650
Jens Axboeebac4652005-12-08 15:25:21 +0100651 if (setup_rate(td))
652 goto err;
653
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100654 if (td->o.write_lat_log) {
Jens Axboe02af0982010-06-24 09:59:34 +0200655 setup_log(&td->ts.lat_log);
Jens Axboe756867b2007-03-06 15:19:24 +0100656 setup_log(&td->ts.slat_log);
657 setup_log(&td->ts.clat_log);
Jens Axboeebac4652005-12-08 15:25:21 +0100658 }
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100659 if (td->o.write_bw_log)
Jens Axboe756867b2007-03-06 15:19:24 +0100660 setup_log(&td->ts.bw_log);
Jens Axboeebac4652005-12-08 15:25:21 +0100661
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100662 if (!td->o.name)
663 td->o.name = strdup(jobname);
Jens Axboe01452052006-06-07 10:29:47 +0200664
Jens Axboec6ae0a52006-06-12 11:04:44 +0200665 if (!terse_output) {
Jens Axboeb990b5c2006-09-14 09:48:22 +0200666 if (!job_add_num) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100667 if (!strcmp(td->io_ops->name, "cpuio")) {
668 log_info("%s: ioengine=cpu, cpuload=%u,"
669 " cpucycle=%u\n", td->o.name,
670 td->o.cpuload,
671 td->o.cpucycle);
672 } else {
Jens Axboef8977ee2006-11-06 14:03:03 +0100673 char *c1, *c2, *c3, *c4;
674
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100675 c1 = to_kmg(td->o.min_bs[DDIR_READ]);
676 c2 = to_kmg(td->o.max_bs[DDIR_READ]);
677 c3 = to_kmg(td->o.min_bs[DDIR_WRITE]);
678 c4 = to_kmg(td->o.max_bs[DDIR_WRITE]);
Jens Axboef8977ee2006-11-06 14:03:03 +0100679
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100680 log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s,"
681 " ioengine=%s, iodepth=%u\n",
682 td->o.name, td->groupid,
683 ddir_str[td->o.td_ddir],
684 c1, c2, c3, c4,
685 td->io_ops->name,
686 td->o.iodepth);
Jens Axboef8977ee2006-11-06 14:03:03 +0100687
688 free(c1);
689 free(c2);
690 free(c3);
691 free(c4);
692 }
Jens Axboeb990b5c2006-09-14 09:48:22 +0200693 } else if (job_add_num == 1)
Jens Axboe6d861442007-03-15 09:22:23 +0100694 log_info("...\n");
Jens Axboec6ae0a52006-06-12 11:04:44 +0200695 }
Jens Axboeebac4652005-12-08 15:25:21 +0100696
697 /*
698 * recurse add identical jobs, clear numjobs and stonewall options
699 * as they don't apply to sub-jobs
700 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100701 numjobs = td->o.numjobs;
Jens Axboeebac4652005-12-08 15:25:21 +0100702 while (--numjobs) {
703 struct thread_data *td_new = get_new_job(0, td);
704
705 if (!td_new)
706 goto err;
707
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100708 td_new->o.numjobs = 1;
709 td_new->o.stonewall = 0;
Jens Axboe92c1d412007-03-28 10:04:08 +0200710 td_new->o.new_group = 0;
Jens Axboee132cba2007-03-14 14:23:54 +0100711
712 if (file_alloced) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100713 td_new->o.filename = NULL;
Jens Axboee132cba2007-03-14 14:23:54 +0100714 td_new->files_index = 0;
Jens Axboe4e6ea2f2009-03-04 20:17:22 +0100715 td_new->files_size = 0;
Jens Axboee132cba2007-03-14 14:23:54 +0100716 td_new->files = NULL;
717 }
718
Jens Axboe75154842006-06-01 13:56:09 +0200719 job_add_num = numjobs - 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100720
Jens Axboe75154842006-06-01 13:56:09 +0200721 if (add_job(td_new, jobname, job_add_num))
Jens Axboeebac4652005-12-08 15:25:21 +0100722 goto err;
723 }
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100724
Jens Axboeebac4652005-12-08 15:25:21 +0100725 return 0;
726err:
727 put_job(td);
728 return -1;
729}
730
Jens Axboe79d16312010-03-04 12:43:20 +0100731/*
732 * Parse as if 'o' was a command line
733 */
734void add_job_opts(const char **o)
735{
736 struct thread_data *td, *td_parent;
737 int i, in_global = 1;
738 char jobname[32];
739
740 i = 0;
741 td_parent = td = NULL;
742 while (o[i]) {
743 if (!strncmp(o[i], "name", 4)) {
744 in_global = 0;
745 if (td)
746 add_job(td, jobname, 0);
747 td = NULL;
748 sprintf(jobname, "%s", o[i] + 5);
749 }
750 if (in_global && !td_parent)
751 td_parent = get_new_job(1, &def_thread);
752 else if (!in_global && !td) {
753 if (!td_parent)
754 td_parent = &def_thread;
755 td = get_new_job(0, td_parent);
756 }
757 if (in_global)
758 fio_options_parse(td_parent, (char **) &o[i], 1);
759 else
760 fio_options_parse(td, (char **) &o[i], 1);
761 i++;
762 }
763
764 if (td)
765 add_job(td, jobname, 0);
766}
767
Jens Axboe01f06b62008-02-18 20:53:47 +0100768static int skip_this_section(const char *name)
769{
Jens Axboead0a2732011-03-11 10:16:17 +0100770 int i;
771
772 if (!nr_job_sections)
Jens Axboe01f06b62008-02-18 20:53:47 +0100773 return 0;
774 if (!strncmp(name, "global", 6))
775 return 0;
776
Jens Axboead0a2732011-03-11 10:16:17 +0100777 for (i = 0; i < nr_job_sections; i++)
778 if (!strcmp(job_sections[i], name))
779 return 0;
780
781 return 1;
Jens Axboe01f06b62008-02-18 20:53:47 +0100782}
783
Jens Axboeebac4652005-12-08 15:25:21 +0100784static int is_empty_or_comment(char *line)
785{
786 unsigned int i;
787
788 for (i = 0; i < strlen(line); i++) {
789 if (line[i] == ';')
790 return 1;
Ingo Molnar5cc2da32007-02-20 10:19:44 +0100791 if (line[i] == '#')
792 return 1;
Jens Axboe76cd9372011-07-08 21:14:57 +0200793 if (!isspace((int) line[i]) && !iscntrl((int) line[i]))
Jens Axboeebac4652005-12-08 15:25:21 +0100794 return 0;
795 }
796
797 return 1;
798}
799
Jens Axboe313cb202006-12-21 09:50:00 +0100800/*
Jens Axboe07261982006-06-07 10:51:12 +0200801 * This is our [ini] type file parser.
802 */
Jens Axboe1e97cce2006-12-05 11:44:16 +0100803static int parse_jobs_ini(char *file, int stonewall_flag)
Jens Axboeebac4652005-12-08 15:25:21 +0100804{
Jens Axboee1f36502006-10-27 10:54:08 +0200805 unsigned int global;
Jens Axboeebac4652005-12-08 15:25:21 +0100806 struct thread_data *td;
Jens Axboefee3bb42006-10-30 13:32:08 +0100807 char *string, *name;
Jens Axboeebac4652005-12-08 15:25:21 +0100808 FILE *f;
809 char *p;
Jens Axboe0c7e37a2006-06-13 14:53:38 +0200810 int ret = 0, stonewall;
Jens Axboe097b2992007-04-19 09:41:45 +0200811 int first_sect = 1;
Jens Axboeccf8f122007-09-27 10:48:55 +0200812 int skip_fgets = 0;
Jens Axboe01f06b62008-02-18 20:53:47 +0100813 int inside_skip = 0;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200814 char **opts;
815 int i, alloc_opts, num_opts;
Jens Axboeebac4652005-12-08 15:25:21 +0100816
Aaron Carroll5a729cb2007-09-27 09:03:55 +0200817 if (!strcmp(file, "-"))
818 f = stdin;
819 else
820 f = fopen(file, "r");
821
Jens Axboeebac4652005-12-08 15:25:21 +0100822 if (!f) {
Jens Axboeaea47d42006-05-26 19:27:29 +0200823 perror("fopen job file");
Jens Axboeebac4652005-12-08 15:25:21 +0100824 return 1;
825 }
826
827 string = malloc(4096);
Jens Axboe7f7e6e52007-07-19 14:50:05 +0200828
829 /*
830 * it's really 256 + small bit, 280 should suffice
831 */
832 name = malloc(280);
833 memset(name, 0, 280);
Jens Axboeebac4652005-12-08 15:25:21 +0100834
Jens Axboe3b8b7132008-06-10 19:46:23 +0200835 alloc_opts = 8;
836 opts = malloc(sizeof(char *) * alloc_opts);
Jens Axboeb7c63022008-06-11 11:47:56 +0200837 num_opts = 0;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200838
Jens Axboe0c7e37a2006-06-13 14:53:38 +0200839 stonewall = stonewall_flag;
Jens Axboe7c124ac2006-10-30 13:36:52 +0100840 do {
Jens Axboeccf8f122007-09-27 10:48:55 +0200841 /*
842 * if skip_fgets is set, we already have loaded a line we
843 * haven't handled.
844 */
845 if (!skip_fgets) {
846 p = fgets(string, 4095, f);
847 if (!p)
848 break;
849 }
gurudas paicdc7f192007-03-29 10:10:56 +0200850
Jens Axboeccf8f122007-09-27 10:48:55 +0200851 skip_fgets = 0;
gurudas paicdc7f192007-03-29 10:10:56 +0200852 strip_blank_front(&p);
Jens Axboe6c7c7da2007-03-29 14:12:57 -0800853 strip_blank_end(p);
gurudas paicdc7f192007-03-29 10:10:56 +0200854
Jens Axboeebac4652005-12-08 15:25:21 +0100855 if (is_empty_or_comment(p))
856 continue;
Bruce Cran84dd1882011-05-05 08:14:09 -0600857 if (sscanf(p, "[%255[^\n]]", name) != 1) {
Jens Axboe01f06b62008-02-18 20:53:47 +0100858 if (inside_skip)
859 continue;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100860 log_err("fio: option <%s> outside of [] job section\n",
861 p);
Jens Axboe088b4202007-07-19 14:53:01 +0200862 break;
Jens Axboe6c7c7da2007-03-29 14:12:57 -0800863 }
Jens Axboeebac4652005-12-08 15:25:21 +0100864
Jens Axboe7a4b80a2010-05-22 20:43:11 +0200865 name[strlen(name) - 1] = '\0';
866
Jens Axboe01f06b62008-02-18 20:53:47 +0100867 if (skip_this_section(name)) {
868 inside_skip = 1;
869 continue;
870 } else
871 inside_skip = 0;
872
Jens Axboeebac4652005-12-08 15:25:21 +0100873 global = !strncmp(name, "global", 6);
874
Jens Axboecca73aa2007-04-04 11:09:19 +0200875 if (dump_cmdline) {
Jens Axboe097b2992007-04-19 09:41:45 +0200876 if (first_sect)
877 log_info("fio ");
Jens Axboecca73aa2007-04-04 11:09:19 +0200878 if (!global)
879 log_info("--name=%s ", name);
Jens Axboe097b2992007-04-19 09:41:45 +0200880 first_sect = 0;
Jens Axboecca73aa2007-04-04 11:09:19 +0200881 }
882
Jens Axboeebac4652005-12-08 15:25:21 +0100883 td = get_new_job(global, &def_thread);
Jens Axboe45410ac2006-06-07 11:10:39 +0200884 if (!td) {
885 ret = 1;
886 break;
887 }
Jens Axboeebac4652005-12-08 15:25:21 +0100888
Jens Axboe972cfd22006-06-09 11:08:56 +0200889 /*
890 * Seperate multiple job files by a stonewall
891 */
Jens Axboef9481912006-06-09 11:37:28 +0200892 if (!global && stonewall) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100893 td->o.stonewall = stonewall;
Jens Axboe972cfd22006-06-09 11:08:56 +0200894 stonewall = 0;
895 }
896
Jens Axboe3b8b7132008-06-10 19:46:23 +0200897 num_opts = 0;
898 memset(opts, 0, alloc_opts * sizeof(char *));
899
Jens Axboeebac4652005-12-08 15:25:21 +0100900 while ((p = fgets(string, 4096, f)) != NULL) {
901 if (is_empty_or_comment(p))
902 continue;
Jens Axboee1f36502006-10-27 10:54:08 +0200903
Jens Axboeb6754f92006-05-30 14:29:32 +0200904 strip_blank_front(&p);
Jens Axboe7c124ac2006-10-30 13:36:52 +0100905
Jens Axboeccf8f122007-09-27 10:48:55 +0200906 /*
907 * new section, break out and make sure we don't
908 * fgets() a new line at the top.
909 */
910 if (p[0] == '[') {
911 skip_fgets = 1;
Jens Axboe7c124ac2006-10-30 13:36:52 +0100912 break;
Jens Axboeccf8f122007-09-27 10:48:55 +0200913 }
Jens Axboe7c124ac2006-10-30 13:36:52 +0100914
Jens Axboe4ae3f762006-05-30 13:35:14 +0200915 strip_blank_end(p);
Jens Axboeaea47d42006-05-26 19:27:29 +0200916
Jens Axboe3b8b7132008-06-10 19:46:23 +0200917 if (num_opts == alloc_opts) {
918 alloc_opts <<= 1;
919 opts = realloc(opts,
920 alloc_opts * sizeof(char *));
921 }
922
923 opts[num_opts] = strdup(p);
924 num_opts++;
Jens Axboeebac4652005-12-08 15:25:21 +0100925 }
Jens Axboeebac4652005-12-08 15:25:21 +0100926
Jens Axboe3b8b7132008-06-10 19:46:23 +0200927 ret = fio_options_parse(td, opts, num_opts);
928 if (!ret) {
929 if (dump_cmdline)
930 for (i = 0; i < num_opts; i++)
931 log_info("--%s ", opts[i]);
932
Jens Axboe45410ac2006-06-07 11:10:39 +0200933 ret = add_job(td, name, 0);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200934 } else {
Jens Axboeb1508cf2006-11-02 09:12:40 +0100935 log_err("fio: job %s dropped\n", name);
936 put_job(td);
Jens Axboe45410ac2006-06-07 11:10:39 +0200937 }
Jens Axboe3b8b7132008-06-10 19:46:23 +0200938
939 for (i = 0; i < num_opts; i++)
940 free(opts[i]);
941 num_opts = 0;
Jens Axboe7c124ac2006-10-30 13:36:52 +0100942 } while (!ret);
Jens Axboeebac4652005-12-08 15:25:21 +0100943
Jens Axboecca73aa2007-04-04 11:09:19 +0200944 if (dump_cmdline)
945 log_info("\n");
946
Jens Axboe3b8b7132008-06-10 19:46:23 +0200947 for (i = 0; i < num_opts; i++)
948 free(opts[i]);
949
Jens Axboeebac4652005-12-08 15:25:21 +0100950 free(string);
951 free(name);
Jens Axboe25775942008-06-10 20:26:06 +0200952 free(opts);
Aaron Carroll5a729cb2007-09-27 09:03:55 +0200953 if (f != stdin)
954 fclose(f);
Jens Axboe45410ac2006-06-07 11:10:39 +0200955 return ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100956}
957
958static int fill_def_thread(void)
959{
960 memset(&def_thread, 0, sizeof(def_thread));
961
Jens Axboe375b2692007-05-22 09:13:02 +0200962 fio_getaffinity(getpid(), &def_thread.o.cpumask);
Jens Axboe8c029372011-10-05 09:54:30 +0200963 def_thread.o.timeout = def_timeout;
Jens Axboeebac4652005-12-08 15:25:21 +0100964
965 /*
Jens Axboeee738492007-01-10 11:23:16 +0100966 * fill default options
Jens Axboeebac4652005-12-08 15:25:21 +0100967 */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100968 fio_fill_default_options(&def_thread);
Jens Axboeebac4652005-12-08 15:25:21 +0100969 return 0;
970}
971
Jens Axboeebac4652005-12-08 15:25:21 +0100972static void free_shm(void)
973{
974 struct shmid_ds sbuf;
975
976 if (threads) {
Jens Axboe5e1d3062008-05-23 11:55:53 +0200977 void *tp = threads;
978
Jens Axboeebac4652005-12-08 15:25:21 +0100979 threads = NULL;
Jens Axboe5e1d3062008-05-23 11:55:53 +0200980 file_hash_exit();
981 fio_debug_jobp = NULL;
982 shmdt(tp);
Jens Axboeebac4652005-12-08 15:25:21 +0100983 shmctl(shm_id, IPC_RMID, &sbuf);
984 }
Jens Axboe2e5cdb12008-03-01 18:52:49 +0100985
986 scleanup();
Jens Axboeebac4652005-12-08 15:25:21 +0100987}
988
Jens Axboe906c8d72006-06-13 09:37:56 +0200989/*
990 * The thread area is shared between the main process and the job
991 * threads/processes. So setup a shared memory segment that will hold
Jens Axboe380065a2008-03-01 18:56:24 +0100992 * all the job info. We use the end of the region for keeping track of
993 * open files across jobs, for file sharing.
Jens Axboe906c8d72006-06-13 09:37:56 +0200994 */
Jens Axboeebac4652005-12-08 15:25:21 +0100995static int setup_thread_area(void)
996{
Jens Axboe380065a2008-03-01 18:56:24 +0100997 void *hash;
998
Jens Axboeebac4652005-12-08 15:25:21 +0100999 /*
1000 * 1024 is too much on some machines, scale max_jobs if
1001 * we get a failure that looks like too large a shm segment
1002 */
1003 do {
Jens Axboe906c8d72006-06-13 09:37:56 +02001004 size_t size = max_jobs * sizeof(struct thread_data);
Jens Axboeebac4652005-12-08 15:25:21 +01001005
Jens Axboe380065a2008-03-01 18:56:24 +01001006 size += file_hash_size;
Jens Axboe5e1d3062008-05-23 11:55:53 +02001007 size += sizeof(unsigned int);
Jens Axboe380065a2008-03-01 18:56:24 +01001008
Jens Axboe906c8d72006-06-13 09:37:56 +02001009 shm_id = shmget(0, size, IPC_CREAT | 0600);
Jens Axboeebac4652005-12-08 15:25:21 +01001010 if (shm_id != -1)
1011 break;
1012 if (errno != EINVAL) {
1013 perror("shmget");
1014 break;
1015 }
1016
1017 max_jobs >>= 1;
1018 } while (max_jobs);
1019
1020 if (shm_id == -1)
1021 return 1;
1022
1023 threads = shmat(shm_id, NULL, 0);
1024 if (threads == (void *) -1) {
1025 perror("shmat");
1026 return 1;
1027 }
1028
Jens Axboe1f809d12007-10-25 18:34:02 +02001029 memset(threads, 0, max_jobs * sizeof(struct thread_data));
Jens Axboe380065a2008-03-01 18:56:24 +01001030 hash = (void *) threads + max_jobs * sizeof(struct thread_data);
Jens Axboe5e1d3062008-05-23 11:55:53 +02001031 fio_debug_jobp = (void *) hash + file_hash_size;
1032 *fio_debug_jobp = -1;
Jens Axboe380065a2008-03-01 18:56:24 +01001033 file_hash_init(hash);
Jens Axboeebac4652005-12-08 15:25:21 +01001034 atexit(free_shm);
1035 return 0;
1036}
1037
Jens Axboe45378b32007-12-19 13:54:38 +01001038static void usage(const char *name)
Jens Axboeb4692822006-10-27 13:43:22 +02001039{
Bruce Cran43617622011-07-30 12:55:52 +02001040 printf("%s\n", fio_version_string);
Jens Axboe45378b32007-12-19 13:54:38 +01001041 printf("%s [options] [job options] <job file(s)>\n", name);
Jens Axboeee56ad52008-02-01 10:30:20 +01001042 printf("\t--debug=options\tEnable debug logging\n");
Jens Axboe214e1ec2007-03-15 10:48:13 +01001043 printf("\t--output\tWrite output to file\n");
1044 printf("\t--timeout\tRuntime in seconds\n");
1045 printf("\t--latency-log\tGenerate per-job latency logs\n");
1046 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1047 printf("\t--minimal\tMinimal (terse) output\n");
1048 printf("\t--version\tPrint version info and exit\n");
Jens Axboef57a9c52011-09-09 21:01:37 +02001049 printf("\t--terse-version=x Terse version output format\n");
Jens Axboe214e1ec2007-03-15 10:48:13 +01001050 printf("\t--help\t\tPrint this page\n");
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001051 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of"
1052 " them\n");
Jens Axboecca73aa2007-04-04 11:09:19 +02001053 printf("\t--showcmd\tTurn a job file into command line options\n");
Aaron Carrolle592a062007-09-14 09:49:41 +02001054 printf("\t--eta=when\tWhen ETA estimate should be printed\n");
1055 printf("\t \tMay be \"always\", \"never\" or \"auto\"\n");
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001056 printf("\t--readonly\tTurn on safety read-only checks, preventing"
1057 " writes\n");
Jens Axboe01f06b62008-02-18 20:53:47 +01001058 printf("\t--section=name\tOnly run specified section in job file\n");
Jens Axboe2b386d22008-03-26 10:32:57 +01001059 printf("\t--alloc-size=kb\tSet smalloc pool to this size in kb"
1060 " (def 1024)\n");
Jens Axboea9523c62011-01-17 16:49:54 -07001061 printf("\t--warnings-fatal Fio parser warnings are fatal\n");
Jens Axboefca70352011-07-06 20:12:54 +02001062 printf("\t--max-jobs\tMaximum number of threads/processes to support\n");
Jens Axboeaa58d252010-06-09 09:49:38 +02001063 printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
1064 printf("\n Jens Axboe <jaxboe@fusionio.com>\n");
Jens Axboeb4692822006-10-27 13:43:22 +02001065}
1066
Jens Axboe79e48f72008-02-01 20:37:09 +01001067#ifdef FIO_INC_DEBUG
Jens Axboeee56ad52008-02-01 10:30:20 +01001068struct debug_level debug_levels[] = {
Jens Axboebd6f78b2008-02-01 20:27:52 +01001069 { .name = "process", .shift = FD_PROCESS, },
1070 { .name = "file", .shift = FD_FILE, },
1071 { .name = "io", .shift = FD_IO, },
1072 { .name = "mem", .shift = FD_MEM, },
1073 { .name = "blktrace", .shift = FD_BLKTRACE },
1074 { .name = "verify", .shift = FD_VERIFY },
Jens Axboe84422ac2008-02-19 20:10:26 +01001075 { .name = "random", .shift = FD_RANDOM },
Jens Axboea3d741f2008-02-27 18:32:33 +01001076 { .name = "parse", .shift = FD_PARSE },
Jens Axboecd991b92008-03-07 13:19:35 +01001077 { .name = "diskutil", .shift = FD_DISKUTIL },
Jens Axboe5e1d3062008-05-23 11:55:53 +02001078 { .name = "job", .shift = FD_JOB },
Jens Axboe29adda32009-01-05 19:06:39 +01001079 { .name = "mutex", .shift = FD_MUTEX },
Jens Axboe79d16312010-03-04 12:43:20 +01001080 { .name = "profile", .shift = FD_PROFILE },
Jens Axboec223da82010-03-24 13:23:53 +01001081 { .name = "time", .shift = FD_TIME },
Jens Axboe02444ad2008-10-07 11:33:00 +02001082 { .name = NULL, },
Jens Axboeee56ad52008-02-01 10:30:20 +01001083};
1084
Jens Axboec09823a2008-02-19 20:16:57 +01001085static int set_debug(const char *string)
Jens Axboeee56ad52008-02-01 10:30:20 +01001086{
1087 struct debug_level *dl;
1088 char *p = (char *) string;
1089 char *opt;
1090 int i;
1091
1092 if (!strcmp(string, "?") || !strcmp(string, "help")) {
Jens Axboeee56ad52008-02-01 10:30:20 +01001093 log_info("fio: dumping debug options:");
1094 for (i = 0; debug_levels[i].name; i++) {
1095 dl = &debug_levels[i];
1096 log_info("%s,", dl->name);
1097 }
Jens Axboebd6f78b2008-02-01 20:27:52 +01001098 log_info("all\n");
Jens Axboec09823a2008-02-19 20:16:57 +01001099 return 1;
Jens Axboeee56ad52008-02-01 10:30:20 +01001100 }
1101
1102 while ((opt = strsep(&p, ",")) != NULL) {
1103 int found = 0;
1104
Jens Axboe5e1d3062008-05-23 11:55:53 +02001105 if (!strncmp(opt, "all", 3)) {
1106 log_info("fio: set all debug options\n");
1107 fio_debug = ~0UL;
1108 continue;
1109 }
1110
Jens Axboeee56ad52008-02-01 10:30:20 +01001111 for (i = 0; debug_levels[i].name; i++) {
1112 dl = &debug_levels[i];
Jens Axboe5e1d3062008-05-23 11:55:53 +02001113 found = !strncmp(opt, dl->name, strlen(dl->name));
1114 if (!found)
1115 continue;
1116
1117 if (dl->shift == FD_JOB) {
1118 opt = strchr(opt, ':');
1119 if (!opt) {
1120 log_err("fio: missing job number\n");
1121 break;
1122 }
1123 opt++;
1124 fio_debug_jobno = atoi(opt);
1125 log_info("fio: set debug jobno %d\n",
1126 fio_debug_jobno);
1127 } else {
Jens Axboeee56ad52008-02-01 10:30:20 +01001128 log_info("fio: set debug option %s\n", opt);
Jens Axboebd6f78b2008-02-01 20:27:52 +01001129 fio_debug |= (1UL << dl->shift);
Jens Axboeee56ad52008-02-01 10:30:20 +01001130 }
Jens Axboe5e1d3062008-05-23 11:55:53 +02001131 break;
Jens Axboeee56ad52008-02-01 10:30:20 +01001132 }
1133
1134 if (!found)
1135 log_err("fio: debug mask %s not found\n", opt);
1136 }
Jens Axboec09823a2008-02-19 20:16:57 +01001137 return 0;
Jens Axboeee56ad52008-02-01 10:30:20 +01001138}
Jens Axboe79e48f72008-02-01 20:37:09 +01001139#else
Jens Axboe69b98d42008-05-30 22:25:32 +02001140static int set_debug(const char *string)
Jens Axboe79e48f72008-02-01 20:37:09 +01001141{
1142 log_err("fio: debug tracing not included in build\n");
Jens Axboec09823a2008-02-19 20:16:57 +01001143 return 1;
Jens Axboe79e48f72008-02-01 20:37:09 +01001144}
1145#endif
Jens Axboeee56ad52008-02-01 10:30:20 +01001146
Jens Axboe4c6107f2011-01-18 05:22:22 -07001147static void fio_options_fill_optstring(void)
1148{
1149 char *ostr = cmd_optstr;
1150 int i, c;
1151
1152 c = i = 0;
1153 while (l_opts[i].name) {
1154 ostr[c++] = l_opts[i].val;
1155 if (l_opts[i].has_arg == required_argument)
1156 ostr[c++] = ':';
1157 else if (l_opts[i].has_arg == optional_argument) {
1158 ostr[c++] = ':';
1159 ostr[c++] = ':';
1160 }
1161 i++;
1162 }
1163 ostr[c] = '\0';
1164}
1165
Jens Axboe214e1ec2007-03-15 10:48:13 +01001166static int parse_cmd_line(int argc, char *argv[])
1167{
1168 struct thread_data *td = NULL;
Jens Axboec09823a2008-02-19 20:16:57 +01001169 int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0;
Jens Axboe4c6107f2011-01-18 05:22:22 -07001170 char *ostr = cmd_optstr;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001171
Jens Axboe4c6107f2011-01-18 05:22:22 -07001172 while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001173 switch (c) {
Jens Axboe2b386d22008-03-26 10:32:57 +01001174 case 'a':
1175 smalloc_pool_size = atoi(optarg);
1176 break;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001177 case 't':
Jens Axboe8c029372011-10-05 09:54:30 +02001178 def_timeout = atoi(optarg);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001179 break;
1180 case 'l':
1181 write_lat_log = 1;
1182 break;
Jens Axboe3d73e5a2010-03-25 10:38:07 +01001183 case 'b':
Jens Axboe214e1ec2007-03-15 10:48:13 +01001184 write_bw_log = 1;
1185 break;
1186 case 'o':
1187 f_out = fopen(optarg, "w+");
1188 if (!f_out) {
1189 perror("fopen output");
1190 exit(1);
1191 }
1192 f_err = f_out;
1193 break;
1194 case 'm':
1195 terse_output = 1;
1196 break;
1197 case 'h':
Jens Axboe45378b32007-12-19 13:54:38 +01001198 usage(argv[0]);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001199 exit(0);
1200 case 'c':
1201 exit(fio_show_option_help(optarg));
Jens Axboecca73aa2007-04-04 11:09:19 +02001202 case 's':
1203 dump_cmdline = 1;
1204 break;
Jens Axboe724e4432007-09-11 20:02:05 +02001205 case 'r':
1206 read_only = 1;
1207 break;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001208 case 'v':
Jens Axboeca740f42011-01-25 13:06:16 +01001209 log_info("%s\n", fio_version_string);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001210 exit(0);
Jens Axboef57a9c52011-09-09 21:01:37 +02001211 case 'V':
1212 terse_version = atoi(optarg);
1213 if (terse_version != 2) {
1214 log_err("fio: bad terse version format\n");
1215 exit_val = 1;
1216 do_exit++;
1217 }
1218 break;
Aaron Carrolle592a062007-09-14 09:49:41 +02001219 case 'e':
1220 if (!strcmp("always", optarg))
1221 eta_print = FIO_ETA_ALWAYS;
1222 else if (!strcmp("never", optarg))
1223 eta_print = FIO_ETA_NEVER;
1224 break;
Jens Axboeee56ad52008-02-01 10:30:20 +01001225 case 'd':
Jens Axboec09823a2008-02-19 20:16:57 +01001226 if (set_debug(optarg))
1227 do_exit++;
Jens Axboeee56ad52008-02-01 10:30:20 +01001228 break;
Jens Axboead0a2732011-03-11 10:16:17 +01001229 case 'x': {
1230 size_t new_size;
1231
Jens Axboe01f06b62008-02-18 20:53:47 +01001232 if (!strcmp(optarg, "global")) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001233 log_err("fio: can't use global as only "
1234 "section\n");
Jens Axboec09823a2008-02-19 20:16:57 +01001235 do_exit++;
1236 exit_val = 1;
Jens Axboe01f06b62008-02-18 20:53:47 +01001237 break;
1238 }
Jens Axboead0a2732011-03-11 10:16:17 +01001239 new_size = (nr_job_sections + 1) * sizeof(char *);
1240 job_sections = realloc(job_sections, new_size);
1241 job_sections[nr_job_sections] = strdup(optarg);
1242 nr_job_sections++;
Jens Axboe01f06b62008-02-18 20:53:47 +01001243 break;
Jens Axboead0a2732011-03-11 10:16:17 +01001244 }
Jens Axboe9ac8a792009-11-13 21:23:07 +01001245 case 'p':
Jens Axboe07b32322010-03-05 09:48:44 +01001246 exec_profile = strdup(optarg);
Jens Axboe9ac8a792009-11-13 21:23:07 +01001247 break;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001248 case FIO_GETOPT_JOB: {
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001249 const char *opt = l_opts[lidx].name;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001250 char *val = optarg;
1251
1252 if (!strncmp(opt, "name", 4) && td) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001253 ret = add_job(td, td->o.name ?: "fio", 0);
Jens Axboe66251552011-05-12 10:14:57 +02001254 if (ret)
Jens Axboe214e1ec2007-03-15 10:48:13 +01001255 return 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001256 td = NULL;
1257 }
1258 if (!td) {
Jens Axboe01f06b62008-02-18 20:53:47 +01001259 int is_section = !strncmp(opt, "name", 4);
Jens Axboe3106f222007-04-19 09:53:28 +02001260 int global = 0;
1261
Jens Axboe01f06b62008-02-18 20:53:47 +01001262 if (!is_section || !strncmp(val, "global", 6))
Jens Axboe3106f222007-04-19 09:53:28 +02001263 global = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001264
Jens Axboe01f06b62008-02-18 20:53:47 +01001265 if (is_section && skip_this_section(val))
1266 continue;
1267
Jens Axboe214e1ec2007-03-15 10:48:13 +01001268 td = get_new_job(global, &def_thread);
1269 if (!td)
1270 return 0;
1271 }
1272
1273 ret = fio_cmd_option_parse(td, opt, val);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001274 break;
1275 }
Jens Axboea9523c62011-01-17 16:49:54 -07001276 case 'w':
1277 warnings_fatal = 1;
1278 break;
Jens Axboefca70352011-07-06 20:12:54 +02001279 case 'j':
1280 max_jobs = atoi(optarg);
1281 if (!max_jobs || max_jobs > REAL_MAX_JOBS) {
1282 log_err("fio: invalid max jobs: %d\n", max_jobs);
1283 do_exit++;
1284 exit_val = 1;
1285 }
1286 break;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001287 default:
Jens Axboec09823a2008-02-19 20:16:57 +01001288 do_exit++;
1289 exit_val = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001290 break;
1291 }
1292 }
1293
Jens Axboec09823a2008-02-19 20:16:57 +01001294 if (do_exit)
1295 exit(exit_val);
Jens Axboe536582b2008-02-18 20:26:32 +01001296
Jens Axboe214e1ec2007-03-15 10:48:13 +01001297 if (td) {
Jens Axboe7d6a8902008-02-18 20:59:18 +01001298 if (!ret)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001299 ret = add_job(td, td->o.name ?: "fio", 0);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001300 }
1301
1302 while (optind < argc) {
1303 ini_idx++;
1304 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1305 ini_file[ini_idx - 1] = strdup(argv[optind]);
1306 optind++;
1307 }
1308
1309 return ini_idx;
1310}
1311
Jens Axboeebac4652005-12-08 15:25:21 +01001312int parse_options(int argc, char *argv[])
1313{
Jens Axboe972cfd22006-06-09 11:08:56 +02001314 int job_files, i;
1315
Jens Axboeb4692822006-10-27 13:43:22 +02001316 f_out = stdout;
1317 f_err = stderr;
1318
Jens Axboe4c6107f2011-01-18 05:22:22 -07001319 fio_options_fill_optstring();
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001320 fio_options_dup_and_init(l_opts);
Jens Axboeb4692822006-10-27 13:43:22 +02001321
Jens Axboeebac4652005-12-08 15:25:21 +01001322 if (setup_thread_area())
1323 return 1;
1324 if (fill_def_thread())
1325 return 1;
1326
Jens Axboe972cfd22006-06-09 11:08:56 +02001327 job_files = parse_cmd_line(argc, argv);
Jens Axboeebac4652005-12-08 15:25:21 +01001328
Jens Axboe972cfd22006-06-09 11:08:56 +02001329 for (i = 0; i < job_files; i++) {
1330 if (fill_def_thread())
1331 return 1;
Jens Axboe0c7e37a2006-06-13 14:53:38 +02001332 if (parse_jobs_ini(ini_file[i], i))
Jens Axboe972cfd22006-06-09 11:08:56 +02001333 return 1;
Jens Axboe88c6ed82006-06-09 11:28:10 +02001334 free(ini_file[i]);
Jens Axboe972cfd22006-06-09 11:08:56 +02001335 }
Jens Axboeebac4652005-12-08 15:25:21 +01001336
Jens Axboe88c6ed82006-06-09 11:28:10 +02001337 free(ini_file);
Jens Axboed23bb322007-03-23 15:57:56 +01001338 options_mem_free(&def_thread);
Jens Axboeb4692822006-10-27 13:43:22 +02001339
1340 if (!thread_number) {
Jens Axboecca73aa2007-04-04 11:09:19 +02001341 if (dump_cmdline)
1342 return 0;
Jens Axboe07b32322010-03-05 09:48:44 +01001343 if (exec_profile)
1344 return 0;
Jens Axboecca73aa2007-04-04 11:09:19 +02001345
Bruce Cran03e20d62011-01-02 20:14:54 +01001346 log_err("No jobs(s) defined\n\n");
Jens Axboe45378b32007-12-19 13:54:38 +01001347 usage(argv[0]);
Jens Axboeb4692822006-10-27 13:43:22 +02001348 return 1;
1349 }
1350
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001351 if (def_thread.o.gtod_offload) {
1352 fio_gtod_init();
1353 fio_gtod_offload = 1;
1354 fio_gtod_cpu = def_thread.o.gtod_cpu;
1355 }
1356
Jens Axboeca740f42011-01-25 13:06:16 +01001357 log_info("%s\n", fio_version_string);
Jens Axboeebac4652005-12-08 15:25:21 +01001358 return 0;
1359}