Fix bad references to 'sgio'
[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 #include <libgen.h>
9
10 #include "fio.h"
11 #include "parse.h"
12 #include "fls.h"
13
14 #define td_var_offset(var)      ((size_t) &((struct thread_options *)0)->var)
15
16 /*
17  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
18  */
19 static char *get_opt_postfix(const char *str)
20 {
21         char *p = strstr(str, ":");
22
23         if (!p)
24                 return NULL;
25
26         p++;
27         strip_blank_front(&p);
28         strip_blank_end(p);
29         return strdup(p);
30 }
31
32 static int bs_cmp(const void *p1, const void *p2)
33 {
34         const struct bssplit *bsp1 = p1;
35         const struct bssplit *bsp2 = p2;
36
37         return bsp1->perc < bsp2->perc;
38 }
39
40 static int str_bssplit_cb(void *data, const char *input)
41 {
42         struct thread_data *td = data;
43         char *fname, *str, *p;
44         unsigned int i, perc, perc_missing;
45         unsigned int max_bs, min_bs;
46         long long val;
47
48         p = str = strdup(input);
49
50         strip_blank_front(&str);
51         strip_blank_end(str);
52
53         td->o.bssplit_nr = 4;
54         td->o.bssplit = malloc(4 * sizeof(struct bssplit));
55
56         i = 0;
57         max_bs = 0;
58         min_bs = -1;
59         while ((fname = strsep(&str, ":")) != NULL) {
60                 char *perc_str;
61
62                 if (!strlen(fname))
63                         break;
64
65                 /*
66                  * grow struct buffer, if needed
67                  */
68                 if (i == td->o.bssplit_nr) {
69                         td->o.bssplit_nr <<= 1;
70                         td->o.bssplit = realloc(td->o.bssplit,
71                                                 td->o.bssplit_nr
72                                                   * sizeof(struct bssplit));
73                 }
74
75                 perc_str = strstr(fname, "/");
76                 if (perc_str) {
77                         *perc_str = '\0';
78                         perc_str++;
79                         perc = atoi(perc_str);
80                         if (perc > 100)
81                                 perc = 100;
82                         else if (!perc)
83                                 perc = -1;
84                 } else
85                         perc = -1;
86
87                 if (str_to_decimal(fname, &val, 1)) {
88                         log_err("fio: bssplit conversion failed\n");
89                         free(td->o.bssplit);
90                         return 1;
91                 }
92
93                 if (val > max_bs)
94                         max_bs = val;
95                 if (val < min_bs)
96                         min_bs = val;
97
98                 td->o.bssplit[i].bs = val;
99                 td->o.bssplit[i].perc = perc;
100                 i++;
101         }
102
103         td->o.bssplit_nr = i;
104
105         /*
106          * Now check if the percentages add up, and how much is missing
107          */
108         perc = perc_missing = 0;
109         for (i = 0; i < td->o.bssplit_nr; i++) {
110                 struct bssplit *bsp = &td->o.bssplit[i];
111
112                 if (bsp->perc == (unsigned char) -1)
113                         perc_missing++;
114                 else
115                         perc += bsp->perc;
116         }
117
118         if (perc > 100) {
119                 log_err("fio: bssplit percentages add to more than 100%%\n");
120                 free(td->o.bssplit);
121                 return 1;
122         }
123         /*
124          * If values didn't have a percentage set, divide the remains between
125          * them.
126          */
127         if (perc_missing) {
128                 for (i = 0; i < td->o.bssplit_nr; i++) {
129                         struct bssplit *bsp = &td->o.bssplit[i];
130
131                         if (bsp->perc == (unsigned char) -1)
132                                 bsp->perc = (100 - perc) / perc_missing;
133                 }
134         }
135
136         td->o.min_bs[DDIR_READ] = td->o.min_bs[DDIR_WRITE] = min_bs;
137         td->o.max_bs[DDIR_READ] = td->o.max_bs[DDIR_WRITE] = max_bs;
138
139         /*
140          * now sort based on percentages, for ease of lookup
141          */
142         qsort(td->o.bssplit, td->o.bssplit_nr, sizeof(struct bssplit), bs_cmp);
143
144         free(p);
145         return 0;
146 }
147
148 static int str_rw_cb(void *data, const char *str)
149 {
150         struct thread_data *td = data;
151         char *nr = get_opt_postfix(str);
152
153         td->o.ddir_nr = 1;
154         if (nr)
155                 td->o.ddir_nr = atoi(nr);
156
157         return 0;
158 }
159
160 static int str_mem_cb(void *data, const char *mem)
161 {
162         struct thread_data *td = data;
163
164         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
165                 td->mmapfile = get_opt_postfix(mem);
166                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
167                         log_err("fio: mmaphuge:/path/to/file\n");
168                         return 1;
169                 }
170         }
171
172         return 0;
173 }
174
175 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
176 {
177         mlock_size = *val;
178         return 0;
179 }
180
181 static int str_rwmix_read_cb(void *data, unsigned int *val)
182 {
183         struct thread_data *td = data;
184
185         td->o.rwmix[DDIR_READ] = *val;
186         td->o.rwmix[DDIR_WRITE] = 100 - *val;
187         return 0;
188 }
189
190 static int str_rwmix_write_cb(void *data, unsigned int *val)
191 {
192         struct thread_data *td = data;
193
194         td->o.rwmix[DDIR_WRITE] = *val;
195         td->o.rwmix[DDIR_READ] = 100 - *val;
196         return 0;
197 }
198
199 #ifdef FIO_HAVE_IOPRIO
200 static int str_prioclass_cb(void *data, unsigned int *val)
201 {
202         struct thread_data *td = data;
203         unsigned short mask;
204
205         /*
206          * mask off old class bits, str_prio_cb() may have set a default class
207          */
208         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
209         td->ioprio &= mask;
210
211         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
212         td->ioprio_set = 1;
213         return 0;
214 }
215
216 static int str_prio_cb(void *data, unsigned int *val)
217 {
218         struct thread_data *td = data;
219
220         td->ioprio |= *val;
221
222         /*
223          * If no class is set, assume BE
224          */
225         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
226                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
227
228         td->ioprio_set = 1;
229         return 0;
230 }
231 #endif
232
233 static int str_exitall_cb(void)
234 {
235         exitall_on_terminate = 1;
236         return 0;
237 }
238
239 #ifdef FIO_HAVE_CPU_AFFINITY
240 static int str_cpumask_cb(void *data, unsigned int *val)
241 {
242         struct thread_data *td = data;
243         unsigned int i;
244
245         CPU_ZERO(&td->o.cpumask);
246
247         for (i = 0; i < sizeof(int) * 8; i++)
248                 if ((1 << i) & *val)
249                         CPU_SET(*val, &td->o.cpumask);
250
251         td->o.cpumask_set = 1;
252         return 0;
253 }
254
255 static int str_cpus_allowed_cb(void *data, const char *input)
256 {
257         struct thread_data *td = data;
258         char *cpu, *str, *p;
259
260         CPU_ZERO(&td->o.cpumask);
261
262         p = str = strdup(input);
263
264         strip_blank_front(&str);
265         strip_blank_end(str);
266
267         while ((cpu = strsep(&str, ",")) != NULL) {
268                 if (!strlen(cpu))
269                         break;
270                 CPU_SET(atoi(cpu), &td->o.cpumask);
271         }
272
273         free(p);
274         td->o.cpumask_set = 1;
275         return 0;
276 }
277 #endif
278
279 static int str_fst_cb(void *data, const char *str)
280 {
281         struct thread_data *td = data;
282         char *nr = get_opt_postfix(str);
283
284         td->file_service_nr = 1;
285         if (nr)
286                 td->file_service_nr = atoi(nr);
287
288         return 0;
289 }
290
291 static int check_dir(struct thread_data *td, char *fname)
292 {
293         char file[PATH_MAX], *dir;
294         int elen = 0;
295
296         if (td->o.directory) {
297                 strcpy(file, td->o.directory);
298                 strcat(file, "/");
299                 elen = strlen(file);
300         }
301
302         sprintf(file + elen, "%s", fname);
303         dir = dirname(file);
304
305 #if 0
306         {
307         struct stat sb;
308         /*
309          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
310          * yet, so we can't do this check right here...
311          */
312         if (lstat(dir, &sb) < 0) {
313                 int ret = errno;
314
315                 log_err("fio: %s is not a directory\n", dir);
316                 td_verror(td, ret, "lstat");
317                 return 1;
318         }
319
320         if (!S_ISDIR(sb.st_mode)) {
321                 log_err("fio: %s is not a directory\n", dir);
322                 return 1;
323         }
324         }
325 #endif
326
327         return 0;
328 }
329
330 static int str_filename_cb(void *data, const char *input)
331 {
332         struct thread_data *td = data;
333         char *fname, *str, *p;
334
335         p = str = strdup(input);
336
337         strip_blank_front(&str);
338         strip_blank_end(str);
339
340         if (!td->files_index)
341                 td->o.nr_files = 0;
342
343         while ((fname = strsep(&str, ":")) != NULL) {
344                 if (!strlen(fname))
345                         break;
346                 if (check_dir(td, fname)) {
347                         free(p);
348                         return 1;
349                 }
350                 add_file(td, fname);
351                 td->o.nr_files++;
352         }
353
354         free(p);
355         return 0;
356 }
357
358 static int str_directory_cb(void *data, const char fio_unused *str)
359 {
360         struct thread_data *td = data;
361         struct stat sb;
362
363         if (lstat(td->o.directory, &sb) < 0) {
364                 int ret = errno;
365
366                 log_err("fio: %s is not a directory\n", td->o.directory);
367                 td_verror(td, ret, "lstat");
368                 return 1;
369         }
370         if (!S_ISDIR(sb.st_mode)) {
371                 log_err("fio: %s is not a directory\n", td->o.directory);
372                 return 1;
373         }
374
375         return 0;
376 }
377
378 static int str_opendir_cb(void *data, const char fio_unused *str)
379 {
380         struct thread_data *td = data;
381
382         if (!td->files_index)
383                 td->o.nr_files = 0;
384
385         return add_dir_files(td, td->o.opendir);
386 }
387
388 static int str_verify_offset_cb(void *data, unsigned int *off)
389 {
390         struct thread_data *td = data;
391
392         if (*off && *off < sizeof(struct verify_header)) {
393                 log_err("fio: verify_offset too small\n");
394                 return 1;
395         }
396
397         td->o.verify_offset = *off;
398         return 0;
399 }
400
401 static int str_verify_pattern_cb(void *data, unsigned int *off)
402 {
403         struct thread_data *td = data;
404         unsigned int msb;
405
406         msb = fls(*off);
407         if (msb <= 8)
408                 td->o.verify_pattern_bytes = 1;
409         else if (msb <= 16)
410                 td->o.verify_pattern_bytes = 2;
411         else if (msb <= 24)
412                 td->o.verify_pattern_bytes = 3;
413         else
414                 td->o.verify_pattern_bytes = 4;
415
416         td->o.verify_pattern = *off;
417         return 0;
418 }
419
420 static int str_lockfile_cb(void *data, const char *str)
421 {
422         struct thread_data *td = data;
423         char *nr = get_opt_postfix(str);
424
425         td->o.lockfile_batch = 1;
426         if (nr)
427                 td->o.lockfile_batch = atoi(nr);
428
429         return 0;
430 }
431
432 #define __stringify_1(x)        #x
433 #define __stringify(x)          __stringify_1(x)
434
435 /*
436  * Map of job/command line options
437  */
438 static struct fio_option options[] = {
439         {
440                 .name   = "description",
441                 .type   = FIO_OPT_STR_STORE,
442                 .off1   = td_var_offset(description),
443                 .help   = "Text job description",
444         },
445         {
446                 .name   = "name",
447                 .type   = FIO_OPT_STR_STORE,
448                 .off1   = td_var_offset(name),
449                 .help   = "Name of this job",
450         },
451         {
452                 .name   = "directory",
453                 .type   = FIO_OPT_STR_STORE,
454                 .off1   = td_var_offset(directory),
455                 .cb     = str_directory_cb,
456                 .help   = "Directory to store files in",
457         },
458         {
459                 .name   = "filename",
460                 .type   = FIO_OPT_STR_STORE,
461                 .off1   = td_var_offset(filename),
462                 .cb     = str_filename_cb,
463                 .help   = "File(s) to use for the workload",
464         },
465         {
466                 .name   = "lockfile",
467                 .type   = FIO_OPT_STR,
468                 .cb     = str_lockfile_cb,
469                 .off1   = td_var_offset(file_lock_mode),
470                 .help   = "Lock file when doing IO to it",
471                 .parent = "filename",
472                 .def    = "none",
473                 .posval = {
474                           { .ival = "none",
475                             .oval = FILE_LOCK_NONE,
476                             .help = "No file locking",
477                           },
478                           { .ival = "exclusive",
479                             .oval = FILE_LOCK_EXCLUSIVE,
480                             .help = "Exclusive file lock",
481                           },
482                           {
483                             .ival = "readwrite",
484                             .oval = FILE_LOCK_READWRITE,
485                             .help = "Read vs write lock",
486                           },
487                 },
488         },
489         {
490                 .name   = "opendir",
491                 .type   = FIO_OPT_STR_STORE,
492                 .off1   = td_var_offset(opendir),
493                 .cb     = str_opendir_cb,
494                 .help   = "Recursively add files from this directory and down",
495         },
496         {
497                 .name   = "rw",
498                 .alias  = "readwrite",
499                 .type   = FIO_OPT_STR,
500                 .cb     = str_rw_cb,
501                 .off1   = td_var_offset(td_ddir),
502                 .help   = "IO direction",
503                 .def    = "read",
504                 .posval = {
505                           { .ival = "read",
506                             .oval = TD_DDIR_READ,
507                             .help = "Sequential read",
508                           },
509                           { .ival = "write",
510                             .oval = TD_DDIR_WRITE,
511                             .help = "Sequential write",
512                           },
513                           { .ival = "randread",
514                             .oval = TD_DDIR_RANDREAD,
515                             .help = "Random read",
516                           },
517                           { .ival = "randwrite",
518                             .oval = TD_DDIR_RANDWRITE,
519                             .help = "Random write",
520                           },
521                           { .ival = "rw",
522                             .oval = TD_DDIR_RW,
523                             .help = "Sequential read and write mix",
524                           },
525                           { .ival = "randrw",
526                             .oval = TD_DDIR_RANDRW,
527                             .help = "Random read and write mix"
528                           },
529                 },
530         },
531         {
532                 .name   = "ioengine",
533                 .type   = FIO_OPT_STR_STORE,
534                 .off1   = td_var_offset(ioengine),
535                 .help   = "IO engine to use",
536                 .def    = "sync",
537                 .posval = {
538                           { .ival = "sync",
539                             .help = "Use read/write",
540                           },
541                           { .ival = "psync",
542                             .help = "Use pread/pwrite",
543                           },
544                           { .ival = "vsync",
545                              .help = "Use readv/writev",
546                           },
547 #ifdef FIO_HAVE_LIBAIO
548                           { .ival = "libaio",
549                             .help = "Linux native asynchronous IO",
550                           },
551 #endif
552 #ifdef FIO_HAVE_POSIXAIO
553                           { .ival = "posixaio",
554                             .help = "POSIX asynchronous IO",
555                           },
556 #endif
557                           { .ival = "mmap",
558                             .help = "Memory mapped IO",
559                           },
560 #ifdef FIO_HAVE_SPLICE
561                           { .ival = "splice",
562                             .help = "splice/vmsplice based IO",
563                           },
564                           { .ival = "netsplice",
565                             .help = "splice/vmsplice to/from the network",
566                           },
567 #endif
568 #ifdef FIO_HAVE_SGIO
569                           { .ival = "sg",
570                             .help = "SCSI generic v3 IO",
571                           },
572 #endif
573                           { .ival = "null",
574                             .help = "Testing engine (no data transfer)",
575                           },
576                           { .ival = "net",
577                             .help = "Network IO",
578                           },
579 #ifdef FIO_HAVE_SYSLET
580                           { .ival = "syslet-rw",
581                             .help = "syslet enabled async pread/pwrite IO",
582                           },
583 #endif
584                           { .ival = "cpuio",
585                             .help = "CPU cycler burner engine",
586                           },
587 #ifdef FIO_HAVE_GUASI
588                           { .ival = "guasi",
589                             .help = "GUASI IO engine",
590                           },
591 #endif
592                           { .ival = "external",
593                             .help = "Load external engine (append name)",
594                           },
595                 },
596         },
597         {
598                 .name   = "iodepth",
599                 .type   = FIO_OPT_INT,
600                 .off1   = td_var_offset(iodepth),
601                 .help   = "Amount of IO buffers to keep in flight",
602                 .minval = 1,
603                 .def    = "1",
604         },
605         {
606                 .name   = "iodepth_batch",
607                 .type   = FIO_OPT_INT,
608                 .off1   = td_var_offset(iodepth_batch),
609                 .help   = "Number of IO to submit in one go",
610                 .parent = "iodepth",
611                 .minval = 1,
612                 .def    = "1",
613         },
614         {
615                 .name   = "iodepth_low",
616                 .type   = FIO_OPT_INT,
617                 .off1   = td_var_offset(iodepth_low),
618                 .help   = "Low water mark for queuing depth",
619                 .parent = "iodepth",
620         },
621         {
622                 .name   = "size",
623                 .type   = FIO_OPT_STR_VAL,
624                 .off1   = td_var_offset(size),
625                 .minval = 1,
626                 .help   = "Total size of device or files",
627         },
628         {
629                 .name   = "fill_device",
630                 .type   = FIO_OPT_BOOL,
631                 .off1   = td_var_offset(fill_device),
632                 .help   = "Write until an ENOSPC error occurs",
633                 .def    = "0",
634         },
635         {
636                 .name   = "filesize",
637                 .type   = FIO_OPT_STR_VAL,
638                 .off1   = td_var_offset(file_size_low),
639                 .off2   = td_var_offset(file_size_high),
640                 .minval = 1,
641                 .help   = "Size of individual files",
642         },
643         {
644                 .name   = "offset",
645                 .alias  = "fileoffset",
646                 .type   = FIO_OPT_STR_VAL,
647                 .off1   = td_var_offset(start_offset),
648                 .help   = "Start IO from this offset",
649                 .def    = "0",
650         },
651         {
652                 .name   = "bs",
653                 .alias  = "blocksize",
654                 .type   = FIO_OPT_STR_VAL_INT,
655                 .off1   = td_var_offset(bs[DDIR_READ]),
656                 .off2   = td_var_offset(bs[DDIR_WRITE]),
657                 .minval = 1,
658                 .help   = "Block size unit",
659                 .def    = "4k",
660                 .parent = "rw",
661         },
662         {
663                 .name   = "bsrange",
664                 .alias  = "blocksize_range",
665                 .type   = FIO_OPT_RANGE,
666                 .off1   = td_var_offset(min_bs[DDIR_READ]),
667                 .off2   = td_var_offset(max_bs[DDIR_READ]),
668                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
669                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
670                 .minval = 1,
671                 .help   = "Set block size range (in more detail than bs)",
672                 .parent = "rw",
673         },
674         {
675                 .name   = "bssplit",
676                 .type   = FIO_OPT_STR,
677                 .cb     = str_bssplit_cb,
678                 .help   = "Set a specific mix of block sizes",
679                 .parent = "rw",
680         },
681         {
682                 .name   = "bs_unaligned",
683                 .alias  = "blocksize_unaligned",
684                 .type   = FIO_OPT_STR_SET,
685                 .off1   = td_var_offset(bs_unaligned),
686                 .help   = "Don't sector align IO buffer sizes",
687                 .parent = "rw",
688         },
689         {
690                 .name   = "randrepeat",
691                 .type   = FIO_OPT_BOOL,
692                 .off1   = td_var_offset(rand_repeatable),
693                 .help   = "Use repeatable random IO pattern",
694                 .def    = "1",
695                 .parent = "rw",
696         },
697         {
698                 .name   = "norandommap",
699                 .type   = FIO_OPT_STR_SET,
700                 .off1   = td_var_offset(norandommap),
701                 .help   = "Accept potential duplicate random blocks",
702                 .parent = "rw",
703         },
704         {
705                 .name   = "softrandommap",
706                 .type   = FIO_OPT_BOOL,
707                 .off1   = td_var_offset(softrandommap),
708                 .help   = "Allow randommap to fail and continue witout",
709                 .parent = "norandommap",
710                 .def    = "0",
711         },
712         {
713                 .name   = "nrfiles",
714                 .type   = FIO_OPT_INT,
715                 .off1   = td_var_offset(nr_files),
716                 .help   = "Split job workload between this number of files",
717                 .def    = "1",
718         },
719         {
720                 .name   = "openfiles",
721                 .type   = FIO_OPT_INT,
722                 .off1   = td_var_offset(open_files),
723                 .help   = "Number of files to keep open at the same time",
724         },
725         {
726                 .name   = "file_service_type",
727                 .type   = FIO_OPT_STR,
728                 .cb     = str_fst_cb,
729                 .off1   = td_var_offset(file_service_type),
730                 .help   = "How to select which file to service next",
731                 .def    = "roundrobin",
732                 .posval = {
733                           { .ival = "random",
734                             .oval = FIO_FSERVICE_RANDOM,
735                             .help = "Choose a file at random",
736                           },
737                           { .ival = "roundrobin",
738                             .oval = FIO_FSERVICE_RR,
739                             .help = "Round robin select files",
740                           },
741                 },
742                 .parent = "nrfiles",
743         },
744         {
745                 .name   = "fadvise_hint",
746                 .type   = FIO_OPT_BOOL,
747                 .off1   = td_var_offset(fadvise_hint),
748                 .help   = "Use fadvise() to advise the kernel on IO pattern",
749                 .def    = "1",
750         },
751         {
752                 .name   = "fsync",
753                 .type   = FIO_OPT_INT,
754                 .off1   = td_var_offset(fsync_blocks),
755                 .help   = "Issue fsync for writes every given number of blocks",
756                 .def    = "0",
757         },
758         {
759                 .name   = "direct",
760                 .type   = FIO_OPT_BOOL,
761                 .off1   = td_var_offset(odirect),
762                 .help   = "Use O_DIRECT IO (negates buffered)",
763                 .def    = "0",
764         },
765         {
766                 .name   = "buffered",
767                 .type   = FIO_OPT_BOOL,
768                 .off1   = td_var_offset(odirect),
769                 .neg    = 1,
770                 .help   = "Use buffered IO (negates direct)",
771                 .def    = "1",
772         },
773         {
774                 .name   = "overwrite",
775                 .type   = FIO_OPT_BOOL,
776                 .off1   = td_var_offset(overwrite),
777                 .help   = "When writing, set whether to overwrite current data",
778                 .def    = "0",
779         },
780         {
781                 .name   = "loops",
782                 .type   = FIO_OPT_INT,
783                 .off1   = td_var_offset(loops),
784                 .help   = "Number of times to run the job",
785                 .def    = "1",
786         },
787         {
788                 .name   = "numjobs",
789                 .type   = FIO_OPT_INT,
790                 .off1   = td_var_offset(numjobs),
791                 .help   = "Duplicate this job this many times",
792                 .def    = "1",
793         },
794         {
795                 .name   = "startdelay",
796                 .type   = FIO_OPT_INT,
797                 .off1   = td_var_offset(start_delay),
798                 .help   = "Only start job when this period has passed",
799                 .def    = "0",
800         },
801         {
802                 .name   = "runtime",
803                 .alias  = "timeout",
804                 .type   = FIO_OPT_STR_VAL_TIME,
805                 .off1   = td_var_offset(timeout),
806                 .help   = "Stop workload when this amount of time has passed",
807                 .def    = "0",
808         },
809         {
810                 .name   = "time_based",
811                 .type   = FIO_OPT_STR_SET,
812                 .off1   = td_var_offset(time_based),
813                 .help   = "Keep running until runtime/timeout is met",
814         },
815         {
816                 .name   = "mem",
817                 .alias  = "iomem",
818                 .type   = FIO_OPT_STR,
819                 .cb     = str_mem_cb,
820                 .off1   = td_var_offset(mem_type),
821                 .help   = "Backing type for IO buffers",
822                 .def    = "malloc",
823                 .posval = {
824                           { .ival = "malloc",
825                             .oval = MEM_MALLOC,
826                             .help = "Use malloc(3) for IO buffers",
827                           },
828                           { .ival = "shm",
829                             .oval = MEM_SHM,
830                             .help = "Use shared memory segments for IO buffers",
831                           },
832 #ifdef FIO_HAVE_HUGETLB
833                           { .ival = "shmhuge",
834                             .oval = MEM_SHMHUGE,
835                             .help = "Like shm, but use huge pages",
836                           },
837 #endif
838                           { .ival = "mmap",
839                             .oval = MEM_MMAP,
840                             .help = "Use mmap(2) (file or anon) for IO buffers",
841                           },
842 #ifdef FIO_HAVE_HUGETLB
843                           { .ival = "mmaphuge",
844                             .oval = MEM_MMAPHUGE,
845                             .help = "Like mmap, but use huge pages",
846                           },
847 #endif
848                   },
849         },
850         {
851                 .name   = "verify",
852                 .type   = FIO_OPT_STR,
853                 .off1   = td_var_offset(verify),
854                 .help   = "Verify data written",
855                 .def    = "0",
856                 .posval = {
857                           { .ival = "0",
858                             .oval = VERIFY_NONE,
859                             .help = "Don't do IO verification",
860                           },
861                           { .ival = "md5",
862                             .oval = VERIFY_MD5,
863                             .help = "Use md5 checksums for verification",
864                           },
865                           { .ival = "crc64",
866                             .oval = VERIFY_CRC64,
867                             .help = "Use crc64 checksums for verification",
868                           },
869                           { .ival = "crc32",
870                             .oval = VERIFY_CRC32,
871                             .help = "Use crc32 checksums for verification",
872                           },
873                           { .ival = "crc16",
874                             .oval = VERIFY_CRC16,
875                             .help = "Use crc16 checksums for verification",
876                           },
877                           { .ival = "crc7",
878                             .oval = VERIFY_CRC7,
879                             .help = "Use crc7 checksums for verification",
880                           },
881                           { .ival = "sha256",
882                             .oval = VERIFY_SHA256,
883                             .help = "Use sha256 checksums for verification",
884                           },
885                           { .ival = "sha512",
886                             .oval = VERIFY_SHA512,
887                             .help = "Use sha512 checksums for verification",
888                           },
889                           { .ival = "meta",
890                             .oval = VERIFY_META,
891                             .help = "Use io information",
892                           },
893                           {
894                             .ival = "null",
895                             .oval = VERIFY_NULL,
896                             .help = "Pretend to verify",
897                           },
898                 },
899         },
900         {
901                 .name   = "do_verify",
902                 .type   = FIO_OPT_BOOL,
903                 .off1   = td_var_offset(do_verify),
904                 .help   = "Run verification stage after write",
905                 .def    = "1",
906                 .parent = "verify",
907         },
908         {
909                 .name   = "verifysort",
910                 .type   = FIO_OPT_BOOL,
911                 .off1   = td_var_offset(verifysort),
912                 .help   = "Sort written verify blocks for read back",
913                 .def    = "1",
914                 .parent = "verify",
915         },
916         {
917                 .name   = "verify_interval",
918                 .type   = FIO_OPT_STR_VAL_INT,
919                 .off1   = td_var_offset(verify_interval),
920                 .minval = 2 * sizeof(struct verify_header),
921                 .help   = "Store verify buffer header every N bytes",
922                 .parent = "verify",
923         },
924         {
925                 .name   = "verify_offset",
926                 .type   = FIO_OPT_STR_VAL_INT,
927                 .help   = "Offset verify header location by N bytes",
928                 .def    = "0",
929                 .cb     = str_verify_offset_cb,
930                 .parent = "verify",
931         },
932         {
933                 .name   = "verify_pattern",
934                 .type   = FIO_OPT_INT,
935                 .cb     = str_verify_pattern_cb,
936                 .help   = "Fill pattern for IO buffers",
937                 .parent = "verify",
938         },
939         {
940                 .name   = "verify_fatal",
941                 .type   = FIO_OPT_BOOL,
942                 .off1   = td_var_offset(verify_fatal),
943                 .def    = "0",
944                 .help   = "Exit on a single verify failure, don't continue",
945                 .parent = "verify",
946         },
947         {
948                 .name   = "write_iolog",
949                 .type   = FIO_OPT_STR_STORE,
950                 .off1   = td_var_offset(write_iolog_file),
951                 .help   = "Store IO pattern to file",
952         },
953         {
954                 .name   = "read_iolog",
955                 .type   = FIO_OPT_STR_STORE,
956                 .off1   = td_var_offset(read_iolog_file),
957                 .help   = "Playback IO pattern from file",
958         },
959         {
960                 .name   = "exec_prerun",
961                 .type   = FIO_OPT_STR_STORE,
962                 .off1   = td_var_offset(exec_prerun),
963                 .help   = "Execute this file prior to running job",
964         },
965         {
966                 .name   = "exec_postrun",
967                 .type   = FIO_OPT_STR_STORE,
968                 .off1   = td_var_offset(exec_postrun),
969                 .help   = "Execute this file after running job",
970         },
971 #ifdef FIO_HAVE_IOSCHED_SWITCH
972         {
973                 .name   = "ioscheduler",
974                 .type   = FIO_OPT_STR_STORE,
975                 .off1   = td_var_offset(ioscheduler),
976                 .help   = "Use this IO scheduler on the backing device",
977         },
978 #endif
979         {
980                 .name   = "zonesize",
981                 .type   = FIO_OPT_STR_VAL,
982                 .off1   = td_var_offset(zone_size),
983                 .help   = "Give size of an IO zone",
984                 .def    = "0",
985         },
986         {
987                 .name   = "zoneskip",
988                 .type   = FIO_OPT_STR_VAL,
989                 .off1   = td_var_offset(zone_skip),
990                 .help   = "Space between IO zones",
991                 .def    = "0",
992         },
993         {
994                 .name   = "lockmem",
995                 .type   = FIO_OPT_STR_VAL,
996                 .cb     = str_lockmem_cb,
997                 .help   = "Lock down this amount of memory",
998                 .def    = "0",
999         },
1000         {
1001                 .name   = "rwmixread",
1002                 .type   = FIO_OPT_INT,
1003                 .cb     = str_rwmix_read_cb,
1004                 .maxval = 100,
1005                 .help   = "Percentage of mixed workload that is reads",
1006                 .def    = "50",
1007         },
1008         {
1009                 .name   = "rwmixwrite",
1010                 .type   = FIO_OPT_INT,
1011                 .cb     = str_rwmix_write_cb,
1012                 .maxval = 100,
1013                 .help   = "Percentage of mixed workload that is writes",
1014                 .def    = "50",
1015         },
1016         {
1017                 .name   = "rwmixcycle",
1018                 .type   = FIO_OPT_DEPRECATED,
1019         },
1020         {
1021                 .name   = "nice",
1022                 .type   = FIO_OPT_INT,
1023                 .off1   = td_var_offset(nice),
1024                 .help   = "Set job CPU nice value",
1025                 .minval = -19,
1026                 .maxval = 20,
1027                 .def    = "0",
1028         },
1029 #ifdef FIO_HAVE_IOPRIO
1030         {
1031                 .name   = "prio",
1032                 .type   = FIO_OPT_INT,
1033                 .cb     = str_prio_cb,
1034                 .help   = "Set job IO priority value",
1035                 .minval = 0,
1036                 .maxval = 7,
1037         },
1038         {
1039                 .name   = "prioclass",
1040                 .type   = FIO_OPT_INT,
1041                 .cb     = str_prioclass_cb,
1042                 .help   = "Set job IO priority class",
1043                 .minval = 0,
1044                 .maxval = 3,
1045         },
1046 #endif
1047         {
1048                 .name   = "thinktime",
1049                 .type   = FIO_OPT_INT,
1050                 .off1   = td_var_offset(thinktime),
1051                 .help   = "Idle time between IO buffers (usec)",
1052                 .def    = "0",
1053         },
1054         {
1055                 .name   = "thinktime_spin",
1056                 .type   = FIO_OPT_INT,
1057                 .off1   = td_var_offset(thinktime_spin),
1058                 .help   = "Start think time by spinning this amount (usec)",
1059                 .def    = "0",
1060                 .parent = "thinktime",
1061         },
1062         {
1063                 .name   = "thinktime_blocks",
1064                 .type   = FIO_OPT_INT,
1065                 .off1   = td_var_offset(thinktime_blocks),
1066                 .help   = "IO buffer period between 'thinktime'",
1067                 .def    = "1",
1068                 .parent = "thinktime",
1069         },
1070         {
1071                 .name   = "rate",
1072                 .type   = FIO_OPT_INT,
1073                 .off1   = td_var_offset(rate),
1074                 .help   = "Set bandwidth rate",
1075         },
1076         {
1077                 .name   = "ratemin",
1078                 .type   = FIO_OPT_INT,
1079                 .off1   = td_var_offset(ratemin),
1080                 .help   = "Job must meet this rate or it will be shutdown",
1081                 .parent = "rate",
1082         },
1083         {
1084                 .name   = "rate_iops",
1085                 .type   = FIO_OPT_INT,
1086                 .off1   = td_var_offset(rate_iops),
1087                 .help   = "Limit IO used to this number of IO operations/sec",
1088         },
1089         {
1090                 .name   = "rate_iops_min",
1091                 .type   = FIO_OPT_INT,
1092                 .off1   = td_var_offset(rate_iops_min),
1093                 .help   = "Job must meet this rate or it will be shutdown",
1094                 .parent = "rate_iops",
1095         },
1096         {
1097                 .name   = "ratecycle",
1098                 .type   = FIO_OPT_INT,
1099                 .off1   = td_var_offset(ratecycle),
1100                 .help   = "Window average for rate limits (msec)",
1101                 .def    = "1000",
1102                 .parent = "rate",
1103         },
1104         {
1105                 .name   = "invalidate",
1106                 .type   = FIO_OPT_BOOL,
1107                 .off1   = td_var_offset(invalidate_cache),
1108                 .help   = "Invalidate buffer/page cache prior to running job",
1109                 .def    = "1",
1110         },
1111         {
1112                 .name   = "sync",
1113                 .type   = FIO_OPT_BOOL,
1114                 .off1   = td_var_offset(sync_io),
1115                 .help   = "Use O_SYNC for buffered writes",
1116                 .def    = "0",
1117                 .parent = "buffered",
1118         },
1119         {
1120                 .name   = "bwavgtime",
1121                 .type   = FIO_OPT_INT,
1122                 .off1   = td_var_offset(bw_avg_time),
1123                 .help   = "Time window over which to calculate bandwidth"
1124                           " (msec)",
1125                 .def    = "500",
1126         },
1127         {
1128                 .name   = "create_serialize",
1129                 .type   = FIO_OPT_BOOL,
1130                 .off1   = td_var_offset(create_serialize),
1131                 .help   = "Serialize creating of job files",
1132                 .def    = "1",
1133         },
1134         {
1135                 .name   = "create_fsync",
1136                 .type   = FIO_OPT_BOOL,
1137                 .off1   = td_var_offset(create_fsync),
1138                 .help   = "Fsync file after creation",
1139                 .def    = "1",
1140         },
1141         {
1142                 .name   = "cpuload",
1143                 .type   = FIO_OPT_INT,
1144                 .off1   = td_var_offset(cpuload),
1145                 .help   = "Use this percentage of CPU",
1146         },
1147         {
1148                 .name   = "cpuchunks",
1149                 .type   = FIO_OPT_INT,
1150                 .off1   = td_var_offset(cpucycle),
1151                 .help   = "Length of the CPU burn cycles (usecs)",
1152                 .def    = "50000",
1153                 .parent = "cpuload",
1154         },
1155 #ifdef FIO_HAVE_CPU_AFFINITY
1156         {
1157                 .name   = "cpumask",
1158                 .type   = FIO_OPT_INT,
1159                 .cb     = str_cpumask_cb,
1160                 .help   = "CPU affinity mask",
1161         },
1162         {
1163                 .name   = "cpus_allowed",
1164                 .type   = FIO_OPT_STR,
1165                 .cb     = str_cpus_allowed_cb,
1166                 .help   = "Set CPUs allowed",
1167         },
1168 #endif
1169         {
1170                 .name   = "end_fsync",
1171                 .type   = FIO_OPT_BOOL,
1172                 .off1   = td_var_offset(end_fsync),
1173                 .help   = "Include fsync at the end of job",
1174                 .def    = "0",
1175         },
1176         {
1177                 .name   = "fsync_on_close",
1178                 .type   = FIO_OPT_BOOL,
1179                 .off1   = td_var_offset(fsync_on_close),
1180                 .help   = "fsync files on close",
1181                 .def    = "0",
1182         },
1183         {
1184                 .name   = "unlink",
1185                 .type   = FIO_OPT_BOOL,
1186                 .off1   = td_var_offset(unlink),
1187                 .help   = "Unlink created files after job has completed",
1188                 .def    = "0",
1189         },
1190         {
1191                 .name   = "exitall",
1192                 .type   = FIO_OPT_STR_SET,
1193                 .cb     = str_exitall_cb,
1194                 .help   = "Terminate all jobs when one exits",
1195         },
1196         {
1197                 .name   = "stonewall",
1198                 .type   = FIO_OPT_STR_SET,
1199                 .off1   = td_var_offset(stonewall),
1200                 .help   = "Insert a hard barrier between this job and previous",
1201         },
1202         {
1203                 .name   = "new_group",
1204                 .type   = FIO_OPT_STR_SET,
1205                 .off1   = td_var_offset(new_group),
1206                 .help   = "Mark the start of a new group (for reporting)",
1207         },
1208         {
1209                 .name   = "thread",
1210                 .type   = FIO_OPT_STR_SET,
1211                 .off1   = td_var_offset(use_thread),
1212                 .help   = "Use threads instead of forks",
1213         },
1214         {
1215                 .name   = "write_bw_log",
1216                 .type   = FIO_OPT_STR_SET,
1217                 .off1   = td_var_offset(write_bw_log),
1218                 .help   = "Write log of bandwidth during run",
1219         },
1220         {
1221                 .name   = "write_lat_log",
1222                 .type   = FIO_OPT_STR_SET,
1223                 .off1   = td_var_offset(write_lat_log),
1224                 .help   = "Write log of latency during run",
1225         },
1226         {
1227                 .name   = "hugepage-size",
1228                 .type   = FIO_OPT_STR_VAL_INT,
1229                 .off1   = td_var_offset(hugepage_size),
1230                 .help   = "When using hugepages, specify size of each page",
1231                 .def    = __stringify(FIO_HUGE_PAGE),
1232         },
1233         {
1234                 .name   = "group_reporting",
1235                 .type   = FIO_OPT_STR_SET,
1236                 .off1   = td_var_offset(group_reporting),
1237                 .help   = "Do reporting on a per-group basis",
1238         },
1239         {
1240                 .name   = "zero_buffers",
1241                 .type   = FIO_OPT_STR_SET,
1242                 .off1   = td_var_offset(zero_buffers),
1243                 .help   = "Init IO buffers to all zeroes",
1244         },
1245         {
1246                 .name   = "refill_buffers",
1247                 .type   = FIO_OPT_STR_SET,
1248                 .off1   = td_var_offset(refill_buffers),
1249                 .help   = "Refill IO buffers on every IO submit",
1250         },
1251 #ifdef FIO_HAVE_DISK_UTIL
1252         {
1253                 .name   = "disk_util",
1254                 .type   = FIO_OPT_BOOL,
1255                 .off1   = td_var_offset(do_disk_util),
1256                 .help   = "Log disk utilization stats",
1257                 .def    = "1",
1258         },
1259 #endif
1260         {
1261                 .name = NULL,
1262         },
1263 };
1264
1265 void fio_options_dup_and_init(struct option *long_options)
1266 {
1267         struct fio_option *o;
1268         unsigned int i;
1269
1270         options_init(options);
1271
1272         i = 0;
1273         while (long_options[i].name)
1274                 i++;
1275
1276         o = &options[0];
1277         while (o->name) {
1278                 long_options[i].name = o->name;
1279                 long_options[i].val = FIO_GETOPT_JOB;
1280                 if (o->type == FIO_OPT_STR_SET)
1281                         long_options[i].has_arg = no_argument;
1282                 else
1283                         long_options[i].has_arg = required_argument;
1284
1285                 i++;
1286                 o++;
1287                 assert(i < FIO_NR_OPTIONS);
1288         }
1289 }
1290
1291 int fio_option_parse(struct thread_data *td, const char *opt)
1292 {
1293         return parse_option(opt, options, td);
1294 }
1295
1296 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1297 {
1298         return parse_cmd_option(opt, val, options, td);
1299 }
1300
1301 void fio_fill_default_options(struct thread_data *td)
1302 {
1303         fill_default_options(td, options);
1304 }
1305
1306 int fio_show_option_help(const char *opt)
1307 {
1308         return show_cmd_help(options, opt);
1309 }
1310
1311 static void __options_mem(struct thread_data *td, int alloc)
1312 {
1313         struct thread_options *o = &td->o;
1314         struct fio_option *opt;
1315         char **ptr;
1316         int i;
1317
1318         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1319                 if (opt->type != FIO_OPT_STR_STORE)
1320                         continue;
1321
1322                 ptr = (void *) o + opt->off1;
1323                 if (*ptr) {
1324                         if (alloc)
1325                                 *ptr = strdup(*ptr);
1326                         else {
1327                                 free(*ptr);
1328                                 *ptr = NULL;
1329                         }
1330                 }
1331         }
1332 }
1333
1334 /*
1335  * dupe FIO_OPT_STR_STORE options
1336  */
1337 void options_mem_dupe(struct thread_data *td)
1338 {
1339         __options_mem(td, 1);
1340 }
1341
1342 void options_mem_free(struct thread_data fio_unused *td)
1343 {
1344 #if 0
1345         __options_mem(td, 0);
1346 #endif
1347 }