Abstract out the data offset calculation
[fio.git] / options.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <getopt.h>
7 #include <assert.h>
8
9 #include "fio.h"
10 #include "parse.h"
11
12 #define td_var_offset(var)      ((size_t) &((struct thread_options *)0)->var)
13
14 /*
15  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
16  */
17 static char *get_opt_postfix(const char *str)
18 {
19         char *p = strstr(str, ":");
20
21         if (!p)
22                 return NULL;
23
24         p++;
25         strip_blank_front(&p);
26         strip_blank_end(p);
27         return strdup(p);
28 }
29
30 static int str_rw_cb(void *data, const char *str)
31 {
32         struct thread_data *td = data;
33         char *nr = get_opt_postfix(str);
34
35         td->o.ddir_nr = 1;
36         if (nr)
37                 td->o.ddir_nr = atoi(nr);
38
39         return 0;
40 }
41
42 static int str_mem_cb(void *data, const char *mem)
43 {
44         struct thread_data *td = data;
45
46         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
47                 td->mmapfile = get_opt_postfix(mem);
48                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
49                         log_err("fio: mmaphuge:/path/to/file\n");
50                         return 1;
51                 }
52         }
53
54         return 0;
55 }
56
57 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
58 {
59         mlock_size = *val;
60         return 0;
61 }
62
63 #ifdef FIO_HAVE_IOPRIO
64 static int str_prioclass_cb(void *data, unsigned int *val)
65 {
66         struct thread_data *td = data;
67         unsigned short mask;
68
69         /*
70          * mask off old class bits, str_prio_cb() may have set a default class
71          */
72         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
73         td->ioprio &= mask;
74
75         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
76         return 0;
77 }
78
79 static int str_prio_cb(void *data, unsigned int *val)
80 {
81         struct thread_data *td = data;
82
83         td->ioprio |= *val;
84
85         /*
86          * If no class is set, assume BE
87          */
88         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
89                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
90
91         return 0;
92 }
93 #endif
94
95 static int str_exitall_cb(void)
96 {
97         exitall_on_terminate = 1;
98         return 0;
99 }
100
101 #ifdef FIO_HAVE_CPU_AFFINITY
102 static int str_cpumask_cb(void *data, unsigned int *val)
103 {
104         struct thread_data *td = data;
105         unsigned int i;
106
107         CPU_ZERO(&td->o.cpumask);
108
109         for (i = 0; i < sizeof(int) * 8; i++)
110                 if ((1 << i) & *val)
111                         CPU_SET(*val, &td->o.cpumask);
112
113         td->o.cpumask_set = 1;
114         return 0;
115 }
116
117 static int str_cpus_allowed_cb(void *data, const char *input)
118 {
119         struct thread_data *td = data;
120         char *cpu, *str, *p;
121
122         CPU_ZERO(&td->o.cpumask);
123
124         p = str = strdup(input);
125
126         strip_blank_front(&str);
127         strip_blank_end(str);
128
129         while ((cpu = strsep(&str, ",")) != NULL) {
130                 if (!strlen(cpu))
131                         break;
132                 CPU_SET(atoi(cpu), &td->o.cpumask);
133         }
134
135         free(p);
136         td->o.cpumask_set = 1;
137         exit(0);
138         return 0;
139 }
140 #endif
141
142 static int str_fst_cb(void *data, const char *str)
143 {
144         struct thread_data *td = data;
145         char *nr = get_opt_postfix(str);
146
147         td->file_service_nr = 1;
148         if (nr)
149                 td->file_service_nr = atoi(nr);
150
151         return 0;
152 }
153
154 static int str_filename_cb(void *data, const char *input)
155 {
156         struct thread_data *td = data;
157         char *fname, *str, *p;
158
159         p = str = strdup(input);
160
161         strip_blank_front(&str);
162         strip_blank_end(str);
163
164         if (!td->files_index)
165                 td->o.nr_files = 0;
166
167         while ((fname = strsep(&str, ":")) != NULL) {
168                 if (!strlen(fname))
169                         break;
170                 add_file(td, fname);
171                 td->o.nr_files++;
172         }
173
174         free(p);
175         return 0;
176 }
177
178 static int str_directory_cb(void *data, const char fio_unused *str)
179 {
180         struct thread_data *td = data;
181         struct stat sb;
182
183         if (lstat(td->o.directory, &sb) < 0) {
184                 log_err("fio: %s is not a directory\n", td->o.directory);
185                 td_verror(td, errno, "lstat");
186                 return 1;
187         }
188         if (!S_ISDIR(sb.st_mode)) {
189                 log_err("fio: %s is not a directory\n", td->o.directory);
190                 return 1;
191         }
192
193         return 0;
194 }
195
196 static int str_opendir_cb(void *data, const char fio_unused *str)
197 {
198         struct thread_data *td = data;
199
200         if (!td->files_index)
201                 td->o.nr_files = 0;
202
203         return add_dir_files(td, td->o.opendir);
204 }
205
206 static int str_header_offset_cb(void *data, unsigned int *off)
207 {
208         struct thread_data *td = data;
209         if (*off && *off < sizeof(struct verify_header)) {
210                 log_err("fio: header_offset too small\n");
211                 return 1;
212         }
213         td->o.header_offset = *off;
214         return 0;
215 }
216
217
218 #define __stringify_1(x)        #x
219 #define __stringify(x)          __stringify_1(x)
220
221 /*
222  * Map of job/command line options
223  */
224 static struct fio_option options[] = {
225         {
226                 .name   = "description",
227                 .type   = FIO_OPT_STR_STORE,
228                 .off1   = td_var_offset(description),
229                 .help   = "Text job description",
230         },
231         {
232                 .name   = "name",
233                 .type   = FIO_OPT_STR_STORE,
234                 .off1   = td_var_offset(name),
235                 .help   = "Name of this job",
236         },
237         {
238                 .name   = "directory",
239                 .type   = FIO_OPT_STR_STORE,
240                 .off1   = td_var_offset(directory),
241                 .cb     = str_directory_cb,
242                 .help   = "Directory to store files in",
243         },
244         {
245                 .name   = "filename",
246                 .type   = FIO_OPT_STR_STORE,
247                 .off1   = td_var_offset(filename),
248                 .cb     = str_filename_cb,
249                 .help   = "File(s) to use for the workload",
250         },
251         {
252                 .name   = "opendir",
253                 .type   = FIO_OPT_STR_STORE,
254                 .off1   = td_var_offset(opendir),
255                 .cb     = str_opendir_cb,
256                 .help   = "Recursively add files from this directory and down",
257         },
258         {
259                 .name   = "rw",
260                 .alias  = "readwrite",
261                 .type   = FIO_OPT_STR,
262                 .cb     = str_rw_cb,
263                 .off1   = td_var_offset(td_ddir),
264                 .help   = "IO direction",
265                 .def    = "read",
266                 .posval = {
267                           { .ival = "read",
268                             .oval = TD_DDIR_READ,
269                             .help = "Sequential read",
270                           },
271                           { .ival = "write",
272                             .oval = TD_DDIR_WRITE,
273                             .help = "Sequential write",
274                           },
275                           { .ival = "randread",
276                             .oval = TD_DDIR_RANDREAD,
277                             .help = "Random read",
278                           },
279                           { .ival = "randwrite",
280                             .oval = TD_DDIR_RANDWRITE,
281                             .help = "Random write",
282                           },
283                           { .ival = "rw",
284                             .oval = TD_DDIR_RW,
285                             .help = "Sequential read and write mix",
286                           },
287                           { .ival = "randrw",
288                             .oval = TD_DDIR_RANDRW,
289                             .help = "Random read and write mix"
290                           },
291                 },
292         },
293         {
294                 .name   = "fadvise_hint",
295                 .type   = FIO_OPT_BOOL,
296                 .off1   = td_var_offset(fadvise_hint),
297                 .help   = "Use fadvise() to advise the kernel on IO pattern",
298                 .def    = "1",
299         },
300         {
301                 .name   = "ioengine",
302                 .type   = FIO_OPT_STR_STORE,
303                 .off1   = td_var_offset(ioengine),
304                 .help   = "IO engine to use",
305                 .def    = "sync",
306                 .posval = {
307                           { .ival = "sync",
308                             .help = "Use read/write",
309                           },
310 #ifdef FIO_HAVE_LIBAIO
311                           { .ival = "libaio",
312                             .help = "Linux native asynchronous IO",
313                           },
314 #endif
315 #ifdef FIO_HAVE_POSIXAIO
316                           { .ival = "posixaio",
317                             .help = "POSIX asynchronous IO",
318                           },
319 #endif
320                           { .ival = "mmap",
321                             .help = "Memory mapped IO",
322                           },
323 #ifdef FIO_HAVE_SPLICE
324                           { .ival = "splice",
325                             .help = "splice/vmsplice based IO",
326                           },
327                           { .ival = "netsplice",
328                             .help = "splice/vmsplice to/from the network",
329                           },
330 #endif
331 #ifdef FIO_HAVE_SGIO
332                           { .ival = "sg",
333                             .help = "SCSI generic v3 IO",
334                           },
335 #endif
336                           { .ival = "null",
337                             .help = "Testing engine (no data transfer)",
338                           },
339                           { .ival = "net",
340                             .help = "Network IO",
341                           },
342 #ifdef FIO_HAVE_SYSLET
343                           { .ival = "syslet-rw",
344                             .help = "syslet enabled async pread/pwrite IO",
345                           },
346 #endif
347                           { .ival = "cpuio",
348                             .help = "CPU cycler burner engine",
349                           },
350 #ifdef FIO_HAVE_GUASI
351                           { .ival = "guasi",
352                             .help = "GUASI IO engine",
353                           },
354 #endif
355                           { .ival = "external",
356                             .help = "Load external engine (append name)",
357                           },
358                 },
359         },
360         {
361                 .name   = "iodepth",
362                 .type   = FIO_OPT_INT,
363                 .off1   = td_var_offset(iodepth),
364                 .help   = "Amount of IO buffers to keep in flight",
365                 .def    = "1",
366         },
367         {
368                 .name   = "iodepth_batch",
369                 .type   = FIO_OPT_INT,
370                 .off1   = td_var_offset(iodepth_batch),
371                 .help   = "Number of IO to submit in one go",
372         },
373         {
374                 .name   = "iodepth_low",
375                 .type   = FIO_OPT_INT,
376                 .off1   = td_var_offset(iodepth_low),
377                 .help   = "Low water mark for queuing depth",
378         },
379         {
380                 .name   = "size",
381                 .type   = FIO_OPT_STR_VAL,
382                 .off1   = td_var_offset(size),
383                 .minval = 1,
384                 .help   = "Total size of device or files",
385         },
386         {
387                 .name   = "filesize",
388                 .type   = FIO_OPT_STR_VAL,
389                 .off1   = td_var_offset(file_size_low),
390                 .off2   = td_var_offset(file_size_high),
391                 .minval = 1,
392                 .help   = "Size of individual files",
393         },
394         {
395                 .name   = "bs",
396                 .alias  = "blocksize",
397                 .type   = FIO_OPT_STR_VAL_INT,
398                 .off1   = td_var_offset(bs[DDIR_READ]),
399                 .off2   = td_var_offset(bs[DDIR_WRITE]),
400                 .minval = 1,
401                 .help   = "Block size unit",
402                 .def    = "4k",
403         },
404         {
405                 .name   = "bsrange",
406                 .alias  = "blocksize_range",
407                 .type   = FIO_OPT_RANGE,
408                 .off1   = td_var_offset(min_bs[DDIR_READ]),
409                 .off2   = td_var_offset(max_bs[DDIR_READ]),
410                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
411                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
412                 .minval = 1,
413                 .help   = "Set block size range (in more detail than bs)",
414         },
415         {
416                 .name   = "bs_unaligned",
417                 .alias  = "blocksize_unaligned",
418                 .type   = FIO_OPT_STR_SET,
419                 .off1   = td_var_offset(bs_unaligned),
420                 .help   = "Don't sector align IO buffer sizes",
421         },
422         {
423                 .name   = "offset",
424                 .type   = FIO_OPT_STR_VAL,
425                 .off1   = td_var_offset(start_offset),
426                 .help   = "Start IO from this offset",
427                 .def    = "0",
428         },
429         {
430                 .name   = "randrepeat",
431                 .type   = FIO_OPT_BOOL,
432                 .off1   = td_var_offset(rand_repeatable),
433                 .help   = "Use repeatable random IO pattern",
434                 .def    = "1",
435         },
436         {
437                 .name   = "norandommap",
438                 .type   = FIO_OPT_STR_SET,
439                 .off1   = td_var_offset(norandommap),
440                 .help   = "Accept potential duplicate random blocks",
441         },
442         {
443                 .name   = "nrfiles",
444                 .type   = FIO_OPT_INT,
445                 .off1   = td_var_offset(nr_files),
446                 .help   = "Split job workload between this number of files",
447                 .def    = "1",
448         },
449         {
450                 .name   = "openfiles",
451                 .type   = FIO_OPT_INT,
452                 .off1   = td_var_offset(open_files),
453                 .help   = "Number of files to keep open at the same time",
454         },
455         {
456                 .name   = "file_service_type",
457                 .type   = FIO_OPT_STR,
458                 .cb     = str_fst_cb,
459                 .off1   = td_var_offset(file_service_type),
460                 .help   = "How to select which file to service next",
461                 .def    = "roundrobin",
462                 .posval = {
463                           { .ival = "random",
464                             .oval = FIO_FSERVICE_RANDOM,
465                             .help = "Choose a file at random",
466                           },
467                           { .ival = "roundrobin",
468                             .oval = FIO_FSERVICE_RR,
469                             .help = "Round robin select files",
470                           },
471                 },
472         },
473         {
474                 .name   = "fsync",
475                 .type   = FIO_OPT_INT,
476                 .off1   = td_var_offset(fsync_blocks),
477                 .help   = "Issue fsync for writes every given number of blocks",
478                 .def    = "0",
479         },
480         {
481                 .name   = "direct",
482                 .type   = FIO_OPT_BOOL,
483                 .off1   = td_var_offset(odirect),
484                 .help   = "Use O_DIRECT IO (negates buffered)",
485                 .def    = "0",
486         },
487         {
488                 .name   = "buffered",
489                 .type   = FIO_OPT_BOOL,
490                 .off1   = td_var_offset(odirect),
491                 .neg    = 1,
492                 .help   = "Use buffered IO (negates direct)",
493                 .def    = "1",
494         },
495         {
496                 .name   = "overwrite",
497                 .type   = FIO_OPT_BOOL,
498                 .off1   = td_var_offset(overwrite),
499                 .help   = "When writing, set whether to overwrite current data",
500                 .def    = "0",
501         },
502         {
503                 .name   = "loops",
504                 .type   = FIO_OPT_INT,
505                 .off1   = td_var_offset(loops),
506                 .help   = "Number of times to run the job",
507                 .def    = "1",
508         },
509         {
510                 .name   = "numjobs",
511                 .type   = FIO_OPT_INT,
512                 .off1   = td_var_offset(numjobs),
513                 .help   = "Duplicate this job this many times",
514                 .def    = "1",
515         },
516         {
517                 .name   = "startdelay",
518                 .type   = FIO_OPT_INT,
519                 .off1   = td_var_offset(start_delay),
520                 .help   = "Only start job when this period has passed",
521                 .def    = "0",
522         },
523         {
524                 .name   = "runtime",
525                 .alias  = "timeout",
526                 .type   = FIO_OPT_STR_VAL_TIME,
527                 .off1   = td_var_offset(timeout),
528                 .help   = "Stop workload when this amount of time has passed",
529                 .def    = "0",
530         },
531         {
532                 .name   = "time_based",
533                 .type   = FIO_OPT_STR_SET,
534                 .off1   = td_var_offset(time_based),
535                 .help   = "Keep running until runtime/timeout is met",
536         },
537         {
538                 .name   = "mem",
539                 .alias  = "iomem",
540                 .type   = FIO_OPT_STR,
541                 .cb     = str_mem_cb,
542                 .off1   = td_var_offset(mem_type),
543                 .help   = "Backing type for IO buffers",
544                 .def    = "malloc",
545                 .posval = {
546                           { .ival = "malloc",
547                             .oval = MEM_MALLOC,
548                             .help = "Use malloc(3) for IO buffers",
549                           },
550                           { .ival = "shm",
551                             .oval = MEM_SHM,
552                             .help = "Use shared memory segments for IO buffers",
553                           },
554 #ifdef FIO_HAVE_HUGETLB
555                           { .ival = "shmhuge",
556                             .oval = MEM_SHMHUGE,
557                             .help = "Like shm, but use huge pages",
558                           },
559 #endif
560                           { .ival = "mmap",
561                             .oval = MEM_MMAP,
562                             .help = "Use mmap(2) (file or anon) for IO buffers",
563                           },
564 #ifdef FIO_HAVE_HUGETLB
565                           { .ival = "mmaphuge",
566                             .oval = MEM_MMAPHUGE,
567                             .help = "Like mmap, but use huge pages",
568                           },
569 #endif
570                   },
571         },
572         {
573                 .name   = "verify",
574                 .type   = FIO_OPT_STR,
575                 .off1   = td_var_offset(verify),
576                 .help   = "Verify data written",
577                 .def    = "0",
578                 .posval = {
579                           { .ival = "0",
580                             .oval = VERIFY_NONE,
581                             .help = "Don't do IO verification",
582                           },
583                           { .ival = "md5",
584                             .oval = VERIFY_MD5,
585                             .help = "Use md5 checksums for verification",
586                           },
587                           { .ival = "crc64",
588                             .oval = VERIFY_CRC64,
589                             .help = "Use crc64 checksums for verification",
590                           },
591                           { .ival = "crc32",
592                             .oval = VERIFY_CRC32,
593                             .help = "Use crc32 checksums for verification",
594                           },
595                           { .ival = "crc16",
596                             .oval = VERIFY_CRC16,
597                             .help = "Use crc16 checksums for verification",
598                           },
599                           { .ival = "crc7",
600                             .oval = VERIFY_CRC7,
601                             .help = "Use crc7 checksums for verification",
602                           },
603                           {
604                             .ival = "null",
605                             .oval = VERIFY_NULL,
606                             .help = "Pretend to verify",
607                           },
608                 },
609         },
610         {
611                 .name   = "verifysort",
612                 .type   = FIO_OPT_BOOL,
613                 .off1   = td_var_offset(verifysort),
614                 .help   = "Sort written verify blocks for read back",
615                 .def    = "1",
616         },
617         {
618                 .name   = "header_interval",
619                 .type   = FIO_OPT_STR_VAL_INT,
620                 .off1   = td_var_offset(header_interval),
621                 .help   = "Store buffer header every N bytes",
622                 .def    = "0",
623         },
624         {
625                 .name   = "header_offset",
626                 .type   = FIO_OPT_STR_VAL_INT,
627                 .help   = "Offset header location by N bytes",
628                 .def    = "0",
629                 .cb     = str_header_offset_cb, 
630         },
631         {
632                 .name   = "write_iolog",
633                 .type   = FIO_OPT_STR_STORE,
634                 .off1   = td_var_offset(write_iolog_file),
635                 .help   = "Store IO pattern to file",
636         },
637         {
638                 .name   = "read_iolog",
639                 .type   = FIO_OPT_STR_STORE,
640                 .off1   = td_var_offset(read_iolog_file),
641                 .help   = "Playback IO pattern from file",
642         },
643         {
644                 .name   = "exec_prerun",
645                 .type   = FIO_OPT_STR_STORE,
646                 .off1   = td_var_offset(exec_prerun),
647                 .help   = "Execute this file prior to running job",
648         },
649         {
650                 .name   = "exec_postrun",
651                 .type   = FIO_OPT_STR_STORE,
652                 .off1   = td_var_offset(exec_postrun),
653                 .help   = "Execute this file after running job",
654         },
655 #ifdef FIO_HAVE_IOSCHED_SWITCH
656         {
657                 .name   = "ioscheduler",
658                 .type   = FIO_OPT_STR_STORE,
659                 .off1   = td_var_offset(ioscheduler),
660                 .help   = "Use this IO scheduler on the backing device",
661         },
662 #endif
663         {
664                 .name   = "zonesize",
665                 .type   = FIO_OPT_STR_VAL,
666                 .off1   = td_var_offset(zone_size),
667                 .help   = "Give size of an IO zone",
668                 .def    = "0",
669         },
670         {
671                 .name   = "zoneskip",
672                 .type   = FIO_OPT_STR_VAL,
673                 .off1   = td_var_offset(zone_skip),
674                 .help   = "Space between IO zones",
675                 .def    = "0",
676         },
677         {
678                 .name   = "lockmem",
679                 .type   = FIO_OPT_STR_VAL,
680                 .cb     = str_lockmem_cb,
681                 .help   = "Lock down this amount of memory",
682                 .def    = "0",
683         },
684         {
685                 .name   = "rwmixcycle",
686                 .type   = FIO_OPT_INT,
687                 .off1   = td_var_offset(rwmixcycle),
688                 .help   = "Cycle period for mixed read/write workloads (msec)",
689                 .def    = "500",
690         },
691         {
692                 .name   = "rwmixread",
693                 .type   = FIO_OPT_INT,
694                 .off1   = td_var_offset(rwmix[DDIR_READ]),
695                 .maxval = 100,
696                 .help   = "Percentage of mixed workload that is reads",
697                 .def    = "50",
698         },
699         {
700                 .name   = "rwmixwrite",
701                 .type   = FIO_OPT_INT,
702                 .off1   = td_var_offset(rwmix[DDIR_WRITE]),
703                 .maxval = 100,
704                 .help   = "Percentage of mixed workload that is writes",
705                 .def    = "50",
706         },
707         {
708                 .name   = "nice",
709                 .type   = FIO_OPT_INT,
710                 .off1   = td_var_offset(nice),
711                 .help   = "Set job CPU nice value",
712                 .minval = -19,
713                 .maxval = 20,
714                 .def    = "0",
715         },
716 #ifdef FIO_HAVE_IOPRIO
717         {
718                 .name   = "prio",
719                 .type   = FIO_OPT_INT,
720                 .cb     = str_prio_cb,
721                 .help   = "Set job IO priority value",
722                 .minval = 0,
723                 .maxval = 7,
724         },
725         {
726                 .name   = "prioclass",
727                 .type   = FIO_OPT_INT,
728                 .cb     = str_prioclass_cb,
729                 .help   = "Set job IO priority class",
730                 .minval = 0,
731                 .maxval = 3,
732         },
733 #endif
734         {
735                 .name   = "thinktime",
736                 .type   = FIO_OPT_INT,
737                 .off1   = td_var_offset(thinktime),
738                 .help   = "Idle time between IO buffers (usec)",
739                 .def    = "0",
740         },
741         {
742                 .name   = "thinktime_spin",
743                 .type   = FIO_OPT_INT,
744                 .off1   = td_var_offset(thinktime_spin),
745                 .help   = "Start think time by spinning this amount (usec)",
746                 .def    = "0",
747         },
748         {
749                 .name   = "thinktime_blocks",
750                 .type   = FIO_OPT_INT,
751                 .off1   = td_var_offset(thinktime_blocks),
752                 .help   = "IO buffer period between 'thinktime'",
753                 .def    = "1",
754         },
755         {
756                 .name   = "rate",
757                 .type   = FIO_OPT_INT,
758                 .off1   = td_var_offset(rate),
759                 .help   = "Set bandwidth rate",
760         },
761         {
762                 .name   = "ratemin",
763                 .type   = FIO_OPT_INT,
764                 .off1   = td_var_offset(ratemin),
765                 .help   = "Job must meet this rate or it will be shutdown",
766         },
767         {
768                 .name   = "rate_iops",
769                 .type   = FIO_OPT_INT,
770                 .off1   = td_var_offset(rate_iops),
771                 .help   = "Limit IO used to this number of IO operations/sec",
772         },
773         {
774                 .name   = "rate_iops_min",
775                 .type   = FIO_OPT_INT,
776                 .off1   = td_var_offset(rate_iops_min),
777                 .help   = "Job must meet this rate or it will be shutdown",
778         },
779         {
780                 .name   = "ratecycle",
781                 .type   = FIO_OPT_INT,
782                 .off1   = td_var_offset(ratecycle),
783                 .help   = "Window average for rate limits (msec)",
784                 .def    = "1000",
785         },
786         {
787                 .name   = "invalidate",
788                 .type   = FIO_OPT_BOOL,
789                 .off1   = td_var_offset(invalidate_cache),
790                 .help   = "Invalidate buffer/page cache prior to running job",
791                 .def    = "1",
792         },
793         {
794                 .name   = "sync",
795                 .type   = FIO_OPT_BOOL,
796                 .off1   = td_var_offset(sync_io),
797                 .help   = "Use O_SYNC for buffered writes",
798                 .def    = "0",
799         },
800         {
801                 .name   = "bwavgtime",
802                 .type   = FIO_OPT_INT,
803                 .off1   = td_var_offset(bw_avg_time),
804                 .help   = "Time window over which to calculate bandwidth (msec)",
805                 .def    = "500",
806         },
807         {
808                 .name   = "create_serialize",
809                 .type   = FIO_OPT_BOOL,
810                 .off1   = td_var_offset(create_serialize),
811                 .help   = "Serialize creating of job files",
812                 .def    = "1",
813         },
814         {
815                 .name   = "create_fsync",
816                 .type   = FIO_OPT_BOOL,
817                 .off1   = td_var_offset(create_fsync),
818                 .help   = "Fsync file after creation",
819                 .def    = "1",
820         },
821         {
822                 .name   = "cpuload",
823                 .type   = FIO_OPT_INT,
824                 .off1   = td_var_offset(cpuload),
825                 .help   = "Use this percentage of CPU",
826         },
827         {
828                 .name   = "cpuchunks",
829                 .type   = FIO_OPT_INT,
830                 .off1   = td_var_offset(cpucycle),
831                 .help   = "Length of the CPU burn cycles (usecs)",
832                 .def    = "50000",
833         },
834 #ifdef FIO_HAVE_CPU_AFFINITY
835         {
836                 .name   = "cpumask",
837                 .type   = FIO_OPT_INT,
838                 .cb     = str_cpumask_cb,
839                 .help   = "CPU affinity mask",
840         },
841         {
842                 .name   = "cpus_allowed",
843                 .type   = FIO_OPT_STR,
844                 .cb     = str_cpus_allowed_cb,
845                 .help   = "Set CPUs allowed",
846         },
847 #endif
848         {
849                 .name   = "end_fsync",
850                 .type   = FIO_OPT_BOOL,
851                 .off1   = td_var_offset(end_fsync),
852                 .help   = "Include fsync at the end of job",
853                 .def    = "0",
854         },
855         {
856                 .name   = "fsync_on_close",
857                 .type   = FIO_OPT_BOOL,
858                 .off1   = td_var_offset(fsync_on_close),
859                 .help   = "fsync files on close",
860                 .def    = "0",
861         },
862         {
863                 .name   = "unlink",
864                 .type   = FIO_OPT_BOOL,
865                 .off1   = td_var_offset(unlink),
866                 .help   = "Unlink created files after job has completed",
867                 .def    = "0",
868         },
869         {
870                 .name   = "exitall",
871                 .type   = FIO_OPT_STR_SET,
872                 .cb     = str_exitall_cb,
873                 .help   = "Terminate all jobs when one exits",
874         },
875         {
876                 .name   = "stonewall",
877                 .type   = FIO_OPT_STR_SET,
878                 .off1   = td_var_offset(stonewall),
879                 .help   = "Insert a hard barrier between this job and previous",
880         },
881         {
882                 .name   = "new_group",
883                 .type   = FIO_OPT_STR_SET,
884                 .off1   = td_var_offset(new_group),
885                 .help   = "Mark the start of a new group (for reporting)",
886         },
887         {
888                 .name   = "thread",
889                 .type   = FIO_OPT_STR_SET,
890                 .off1   = td_var_offset(use_thread),
891                 .help   = "Use threads instead of forks",
892         },
893         {
894                 .name   = "write_bw_log",
895                 .type   = FIO_OPT_STR_SET,
896                 .off1   = td_var_offset(write_bw_log),
897                 .help   = "Write log of bandwidth during run",
898         },
899         {
900                 .name   = "write_lat_log",
901                 .type   = FIO_OPT_STR_SET,
902                 .off1   = td_var_offset(write_lat_log),
903                 .help   = "Write log of latency during run",
904         },
905         {
906                 .name   = "hugepage-size",
907                 .type   = FIO_OPT_STR_VAL,
908                 .off1   = td_var_offset(hugepage_size),
909                 .help   = "When using hugepages, specify size of each page",
910                 .def    = __stringify(FIO_HUGE_PAGE),
911         },
912         {
913                 .name   = "group_reporting",
914                 .type   = FIO_OPT_STR_SET,
915                 .off1   = td_var_offset(group_reporting),
916                 .help   = "Do reporting on a per-group basis",
917         },
918         {
919                 .name   = "zero_buffers",
920                 .type   = FIO_OPT_STR_SET,
921                 .off1   = td_var_offset(zero_buffers),
922                 .help   = "Init IO buffers to all zeroes",
923         },
924 #ifdef FIO_HAVE_DISK_UTIL
925         {
926                 .name   = "disk_util",
927                 .type   = FIO_OPT_BOOL,
928                 .off1   = td_var_offset(do_disk_util),
929                 .help   = "Log disk utilization stats",
930                 .def    = "1",
931         },
932 #endif
933         {
934                 .name = NULL,
935         },
936 };
937
938 void fio_options_dup_and_init(struct option *long_options)
939 {
940         struct fio_option *o;
941         unsigned int i;
942
943         options_init(options);
944
945         i = 0;
946         while (long_options[i].name)
947                 i++;
948
949         o = &options[0];
950         while (o->name) {
951                 long_options[i].name = o->name;
952                 long_options[i].val = FIO_GETOPT_JOB;
953                 if (o->type == FIO_OPT_STR_SET)
954                         long_options[i].has_arg = no_argument;
955                 else
956                         long_options[i].has_arg = required_argument;
957
958                 i++;
959                 o++;
960                 assert(i < FIO_NR_OPTIONS);
961         }
962 }
963
964 int fio_option_parse(struct thread_data *td, const char *opt)
965 {
966         return parse_option(opt, options, td);
967 }
968
969 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
970 {
971         return parse_cmd_option(opt, val, options, td);
972 }
973
974 void fio_fill_default_options(struct thread_data *td)
975 {
976         fill_default_options(td, options);
977 }
978
979 int fio_show_option_help(const char *opt)
980 {
981         return show_cmd_help(options, opt);
982 }
983
984 static void __options_mem(struct thread_data *td, int alloc)
985 {
986         struct thread_options *o = &td->o;
987         struct fio_option *opt;
988         char **ptr;
989         int i;
990
991         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
992                 if (opt->type != FIO_OPT_STR_STORE)
993                         continue;
994
995                 ptr = (void *) o + opt->off1;
996                 if (*ptr) {
997                         if (alloc)
998                                 *ptr = strdup(*ptr);
999                         else {
1000                                 free(*ptr);
1001                                 *ptr = NULL;
1002                         }
1003                 }
1004         }
1005 }
1006
1007 /*
1008  * dupe FIO_OPT_STR_STORE options
1009  */
1010 void options_mem_dupe(struct thread_data *td)
1011 {
1012         __options_mem(td, 1);
1013 }
1014
1015 void options_mem_free(struct thread_data fio_unused *td)
1016 {
1017 #if 0
1018         __options_mem(td, 0);
1019 #endif
1020 }