Allow profiles to override internal io_u functions
[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 #include <fcntl.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12
13 #include "fio.h"
14 #include "verify.h"
15 #include "parse.h"
16 #include "lib/fls.h"
17 #include "options.h"
18
19 /*
20  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
21  */
22 static char *get_opt_postfix(const char *str)
23 {
24         char *p = strstr(str, ":");
25
26         if (!p)
27                 return NULL;
28
29         p++;
30         strip_blank_front(&p);
31         strip_blank_end(p);
32         return strdup(p);
33 }
34
35 static int converthexchartoint(char a)
36 {
37         int base;
38
39         switch(a) {
40         case '0'...'9':
41                 base = '0';
42                 break;
43         case 'A'...'F':
44                 base = 'A' - 10;
45                 break;
46         case 'a'...'f':
47                 base = 'a' - 10;
48                 break;
49         default:
50                 base = 0;
51         }
52         return (a - base);
53 }
54
55 static int bs_cmp(const void *p1, const void *p2)
56 {
57         const struct bssplit *bsp1 = p1;
58         const struct bssplit *bsp2 = p2;
59
60         return bsp1->perc < bsp2->perc;
61 }
62
63 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
64 {
65         struct bssplit *bssplit;
66         unsigned int i, perc, perc_missing;
67         unsigned int max_bs, min_bs;
68         long long val;
69         char *fname;
70
71         td->o.bssplit_nr[ddir] = 4;
72         bssplit = malloc(4 * sizeof(struct bssplit));
73
74         i = 0;
75         max_bs = 0;
76         min_bs = -1;
77         while ((fname = strsep(&str, ":")) != NULL) {
78                 char *perc_str;
79
80                 if (!strlen(fname))
81                         break;
82
83                 /*
84                  * grow struct buffer, if needed
85                  */
86                 if (i == td->o.bssplit_nr[ddir]) {
87                         td->o.bssplit_nr[ddir] <<= 1;
88                         bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
89                                                   * sizeof(struct bssplit));
90                 }
91
92                 perc_str = strstr(fname, "/");
93                 if (perc_str) {
94                         *perc_str = '\0';
95                         perc_str++;
96                         perc = atoi(perc_str);
97                         if (perc > 100)
98                                 perc = 100;
99                         else if (!perc)
100                                 perc = -1;
101                 } else
102                         perc = -1;
103
104                 if (str_to_decimal(fname, &val, 1, td)) {
105                         log_err("fio: bssplit conversion failed\n");
106                         free(td->o.bssplit);
107                         return 1;
108                 }
109
110                 if (val > max_bs)
111                         max_bs = val;
112                 if (val < min_bs)
113                         min_bs = val;
114
115                 bssplit[i].bs = val;
116                 bssplit[i].perc = perc;
117                 i++;
118         }
119
120         td->o.bssplit_nr[ddir] = i;
121
122         /*
123          * Now check if the percentages add up, and how much is missing
124          */
125         perc = perc_missing = 0;
126         for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
127                 struct bssplit *bsp = &bssplit[i];
128
129                 if (bsp->perc == (unsigned char) -1)
130                         perc_missing++;
131                 else
132                         perc += bsp->perc;
133         }
134
135         if (perc > 100) {
136                 log_err("fio: bssplit percentages add to more than 100%%\n");
137                 free(bssplit);
138                 return 1;
139         }
140         /*
141          * If values didn't have a percentage set, divide the remains between
142          * them.
143          */
144         if (perc_missing) {
145                 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
146                         struct bssplit *bsp = &bssplit[i];
147
148                         if (bsp->perc == (unsigned char) -1)
149                                 bsp->perc = (100 - perc) / perc_missing;
150                 }
151         }
152
153         td->o.min_bs[ddir] = min_bs;
154         td->o.max_bs[ddir] = max_bs;
155
156         /*
157          * now sort based on percentages, for ease of lookup
158          */
159         qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
160         td->o.bssplit[ddir] = bssplit;
161         return 0;
162
163 }
164
165 static int str_bssplit_cb(void *data, const char *input)
166 {
167         struct thread_data *td = data;
168         char *str, *p, *odir;
169         int ret = 0;
170
171         p = str = strdup(input);
172
173         strip_blank_front(&str);
174         strip_blank_end(str);
175
176         odir = strchr(str, ',');
177         if (odir) {
178                 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
179                 if (!ret) {
180                         *odir = '\0';
181                         ret = bssplit_ddir(td, DDIR_READ, str);
182                 }
183         } else {
184                 char *op;
185
186                 op = strdup(str);
187
188                 ret = bssplit_ddir(td, DDIR_READ, str);
189                 if (!ret)
190                         ret = bssplit_ddir(td, DDIR_WRITE, op);
191
192                 free(op);
193         }
194
195         free(p);
196         return ret;
197 }
198
199 static int str_rw_cb(void *data, const char *str)
200 {
201         struct thread_data *td = data;
202         char *nr = get_opt_postfix(str);
203
204         td->o.ddir_nr = 1;
205         if (nr) {
206                 td->o.ddir_nr = atoi(nr);
207                 free(nr);
208         }
209
210         return 0;
211 }
212
213 static int str_mem_cb(void *data, const char *mem)
214 {
215         struct thread_data *td = data;
216
217         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
218                 td->mmapfile = get_opt_postfix(mem);
219                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
220                         log_err("fio: mmaphuge:/path/to/file\n");
221                         return 1;
222                 }
223         }
224
225         return 0;
226 }
227
228 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
229 {
230         mlock_size = *val;
231         return 0;
232 }
233
234 static int str_rwmix_read_cb(void *data, unsigned int *val)
235 {
236         struct thread_data *td = data;
237
238         td->o.rwmix[DDIR_READ] = *val;
239         td->o.rwmix[DDIR_WRITE] = 100 - *val;
240         return 0;
241 }
242
243 static int str_rwmix_write_cb(void *data, unsigned int *val)
244 {
245         struct thread_data *td = data;
246
247         td->o.rwmix[DDIR_WRITE] = *val;
248         td->o.rwmix[DDIR_READ] = 100 - *val;
249         return 0;
250 }
251
252 #ifdef FIO_HAVE_IOPRIO
253 static int str_prioclass_cb(void *data, unsigned int *val)
254 {
255         struct thread_data *td = data;
256         unsigned short mask;
257
258         /*
259          * mask off old class bits, str_prio_cb() may have set a default class
260          */
261         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
262         td->ioprio &= mask;
263
264         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
265         td->ioprio_set = 1;
266         return 0;
267 }
268
269 static int str_prio_cb(void *data, unsigned int *val)
270 {
271         struct thread_data *td = data;
272
273         td->ioprio |= *val;
274
275         /*
276          * If no class is set, assume BE
277          */
278         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
279                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
280
281         td->ioprio_set = 1;
282         return 0;
283 }
284 #endif
285
286 static int str_exitall_cb(void)
287 {
288         exitall_on_terminate = 1;
289         return 0;
290 }
291
292 #ifdef FIO_HAVE_CPU_AFFINITY
293 static int str_cpumask_cb(void *data, unsigned int *val)
294 {
295         struct thread_data *td = data;
296         unsigned int i;
297         long max_cpu;
298         int ret;
299
300         ret = fio_cpuset_init(&td->o.cpumask);
301         if (ret < 0) {
302                 log_err("fio: cpuset_init failed\n");
303                 td_verror(td, ret, "fio_cpuset_init");
304                 return 1;
305         }
306
307         max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
308
309         for (i = 0; i < sizeof(int) * 8; i++) {
310                 if ((1 << i) & *val) {
311                         if (i > max_cpu) {
312                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
313                                                                 max_cpu);
314                                 return 1;
315                         }
316                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
317                         fio_cpu_set(&td->o.cpumask, i);
318                 }
319         }
320
321         td->o.cpumask_set = 1;
322         return 0;
323 }
324
325 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
326                             const char *input)
327 {
328         char *cpu, *str, *p;
329         long max_cpu;
330         int ret = 0;
331
332         ret = fio_cpuset_init(mask);
333         if (ret < 0) {
334                 log_err("fio: cpuset_init failed\n");
335                 td_verror(td, ret, "fio_cpuset_init");
336                 return 1;
337         }
338
339         p = str = strdup(input);
340
341         strip_blank_front(&str);
342         strip_blank_end(str);
343
344         max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
345
346         while ((cpu = strsep(&str, ",")) != NULL) {
347                 char *str2, *cpu2;
348                 int icpu, icpu2;
349
350                 if (!strlen(cpu))
351                         break;
352
353                 str2 = cpu;
354                 icpu2 = -1;
355                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
356                         if (!strlen(cpu2))
357                                 break;
358
359                         icpu2 = atoi(cpu2);
360                 }
361
362                 icpu = atoi(cpu);
363                 if (icpu2 == -1)
364                         icpu2 = icpu;
365                 while (icpu <= icpu2) {
366                         if (icpu >= FIO_MAX_CPUS) {
367                                 log_err("fio: your OS only supports up to"
368                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
369                                 ret = 1;
370                                 break;
371                         }
372                         if (icpu > max_cpu) {
373                                 log_err("fio: CPU %d too large (max=%ld)\n",
374                                                         icpu, max_cpu);
375                                 ret = 1;
376                                 break;
377                         }
378
379                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
380                         fio_cpu_set(mask, icpu);
381                         icpu++;
382                 }
383                 if (ret)
384                         break;
385         }
386
387         free(p);
388         if (!ret)
389                 td->o.cpumask_set = 1;
390         return ret;
391 }
392
393 static int str_cpus_allowed_cb(void *data, const char *input)
394 {
395         struct thread_data *td = data;
396         int ret;
397
398         ret = set_cpus_allowed(td, &td->o.cpumask, input);
399         if (!ret)
400                 td->o.cpumask_set = 1;
401
402         return ret;
403 }
404
405 static int str_verify_cpus_allowed_cb(void *data, const char *input)
406 {
407         struct thread_data *td = data;
408         int ret;
409
410         ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
411         if (!ret)
412                 td->o.verify_cpumask_set = 1;
413
414         return ret;
415 }
416 #endif
417
418 static int str_fst_cb(void *data, const char *str)
419 {
420         struct thread_data *td = data;
421         char *nr = get_opt_postfix(str);
422
423         td->file_service_nr = 1;
424         if (nr) {
425                 td->file_service_nr = atoi(nr);
426                 free(nr);
427         }
428
429         return 0;
430 }
431
432 static int check_dir(struct thread_data *td, char *fname)
433 {
434         char file[PATH_MAX], *dir;
435         int elen = 0;
436
437         if (td->o.directory) {
438                 strcpy(file, td->o.directory);
439                 strcat(file, "/");
440                 elen = strlen(file);
441         }
442
443         sprintf(file + elen, "%s", fname);
444         dir = dirname(file);
445
446 #if 0
447         {
448         struct stat sb;
449         /*
450          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
451          * yet, so we can't do this check right here...
452          */
453         if (lstat(dir, &sb) < 0) {
454                 int ret = errno;
455
456                 log_err("fio: %s is not a directory\n", dir);
457                 td_verror(td, ret, "lstat");
458                 return 1;
459         }
460
461         if (!S_ISDIR(sb.st_mode)) {
462                 log_err("fio: %s is not a directory\n", dir);
463                 return 1;
464         }
465         }
466 #endif
467
468         return 0;
469 }
470
471 /*
472  * Return next file in the string. Files are separated with ':'. If the ':'
473  * is escaped with a '\', then that ':' is part of the filename and does not
474  * indicate a new file.
475  */
476 static char *get_next_file_name(char **ptr)
477 {
478         char *str = *ptr;
479         char *p, *start;
480
481         if (!str || !strlen(str))
482                 return NULL;
483
484         start = str;
485         do {
486                 /*
487                  * No colon, we are done
488                  */
489                 p = strchr(str, ':');
490                 if (!p) {
491                         *ptr = NULL;
492                         break;
493                 }
494
495                 /*
496                  * We got a colon, but it's the first character. Skip and
497                  * continue
498                  */
499                 if (p == start) {
500                         str = ++start;
501                         continue;
502                 }
503
504                 if (*(p - 1) != '\\') {
505                         *p = '\0';
506                         *ptr = p + 1;
507                         break;
508                 }
509
510                 memmove(p - 1, p, strlen(p) + 1);
511                 str = p;
512         } while (1);
513
514         return start;
515 }
516
517 static int str_filename_cb(void *data, const char *input)
518 {
519         struct thread_data *td = data;
520         char *fname, *str, *p;
521
522         p = str = strdup(input);
523
524         strip_blank_front(&str);
525         strip_blank_end(str);
526
527         if (!td->files_index)
528                 td->o.nr_files = 0;
529
530         while ((fname = get_next_file_name(&str)) != NULL) {
531                 if (!strlen(fname))
532                         break;
533                 if (check_dir(td, fname)) {
534                         free(p);
535                         return 1;
536                 }
537                 add_file(td, fname);
538                 td->o.nr_files++;
539         }
540
541         free(p);
542         return 0;
543 }
544
545 static int str_directory_cb(void *data, const char fio_unused *str)
546 {
547         struct thread_data *td = data;
548         struct stat sb;
549
550         if (lstat(td->o.directory, &sb) < 0) {
551                 int ret = errno;
552
553                 log_err("fio: %s is not a directory\n", td->o.directory);
554                 td_verror(td, ret, "lstat");
555                 return 1;
556         }
557         if (!S_ISDIR(sb.st_mode)) {
558                 log_err("fio: %s is not a directory\n", td->o.directory);
559                 return 1;
560         }
561
562         return 0;
563 }
564
565 static int str_opendir_cb(void *data, const char fio_unused *str)
566 {
567         struct thread_data *td = data;
568
569         if (!td->files_index)
570                 td->o.nr_files = 0;
571
572         return add_dir_files(td, td->o.opendir);
573 }
574
575 static int str_verify_offset_cb(void *data, unsigned int *off)
576 {
577         struct thread_data *td = data;
578
579         if (*off && *off < sizeof(struct verify_header)) {
580                 log_err("fio: verify_offset too small\n");
581                 return 1;
582         }
583
584         td->o.verify_offset = *off;
585         return 0;
586 }
587
588 static int str_verify_pattern_cb(void *data, const char *input)
589 {
590         struct thread_data *td = data;
591         long off;
592         int i = 0, j = 0, len, k, base = 10;
593         char* loc1, * loc2;
594
595         loc1 = strstr(input, "0x");
596         loc2 = strstr(input, "0X");
597         if (loc1 || loc2)
598                 base = 16;
599         off = strtol(input, NULL, base);
600         if (off != LONG_MAX || errno != ERANGE) {
601                 while (off) {
602                         td->o.verify_pattern[i] = off & 0xff;
603                         off >>= 8;
604                         i++;
605                 }
606         } else {
607                 len = strlen(input);
608                 k = len - 1;
609                 if (base == 16) {
610                         if (loc1)
611                                 j = loc1 - input + 2;
612                         else
613                                 j = loc2 - input + 2;
614                 } else
615                         return 1;
616                 if (len - j < MAX_PATTERN_SIZE * 2) {
617                         while (k >= j) {
618                                 off = converthexchartoint(input[k--]);
619                                 if (k >= j)
620                                         off += (converthexchartoint(input[k--])
621                                                 * 16);
622                                 td->o.verify_pattern[i++] = (char) off;
623                         }
624                 }
625         }
626         td->o.verify_pattern_bytes = i;
627         return 0;
628 }
629
630 static int str_lockfile_cb(void *data, const char *str)
631 {
632         struct thread_data *td = data;
633         char *nr = get_opt_postfix(str);
634
635         td->o.lockfile_batch = 1;
636         if (nr) {
637                 td->o.lockfile_batch = atoi(nr);
638                 free(nr);
639         }
640
641         return 0;
642 }
643
644 static int str_write_bw_log_cb(void *data, const char *str)
645 {
646         struct thread_data *td = data;
647
648         if (str)
649                 td->o.bw_log_file = strdup(str);
650
651         td->o.write_bw_log = 1;
652         return 0;
653 }
654
655 static int str_write_lat_log_cb(void *data, const char *str)
656 {
657         struct thread_data *td = data;
658
659         if (str)
660                 td->o.lat_log_file = strdup(str);
661
662         td->o.write_lat_log = 1;
663         return 0;
664 }
665
666 static int str_gtod_reduce_cb(void *data, int *il)
667 {
668         struct thread_data *td = data;
669         int val = *il;
670
671         td->o.disable_clat = !!val;
672         td->o.disable_slat = !!val;
673         td->o.disable_bw = !!val;
674         if (val)
675                 td->tv_cache_mask = 63;
676
677         return 0;
678 }
679
680 static int str_gtod_cpu_cb(void *data, int *il)
681 {
682         struct thread_data *td = data;
683         int val = *il;
684
685         td->o.gtod_cpu = val;
686         td->o.gtod_offload = 1;
687         return 0;
688 }
689
690 static int rw_verify(struct fio_option *o, void *data)
691 {
692         struct thread_data *td = data;
693
694         if (read_only && td_write(td)) {
695                 log_err("fio: job <%s> has write bit set, but fio is in"
696                         " read-only mode\n", td->o.name);
697                 return 1;
698         }
699
700         return 0;
701 }
702
703 static int gtod_cpu_verify(struct fio_option *o, void *data)
704 {
705 #ifndef FIO_HAVE_CPU_AFFINITY
706         struct thread_data *td = data;
707
708         if (td->o.gtod_cpu) {
709                 log_err("fio: platform must support CPU affinity for"
710                         "gettimeofday() offloading\n");
711                 return 1;
712         }
713 #endif
714
715         return 0;
716 }
717
718 static int kb_base_verify(struct fio_option *o, void *data)
719 {
720         struct thread_data *td = data;
721
722         if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
723                 log_err("fio: kb_base set to nonsensical value: %u\n",
724                                 td->o.kb_base);
725                 return 1;
726         }
727
728         return 0;
729 }
730
731 #define __stringify_1(x)        #x
732 #define __stringify(x)          __stringify_1(x)
733
734 /*
735  * Map of job/command line options
736  */
737 static struct fio_option options[FIO_MAX_OPTS] = {
738         {
739                 .name   = "description",
740                 .type   = FIO_OPT_STR_STORE,
741                 .off1   = td_var_offset(description),
742                 .help   = "Text job description",
743         },
744         {
745                 .name   = "name",
746                 .type   = FIO_OPT_STR_STORE,
747                 .off1   = td_var_offset(name),
748                 .help   = "Name of this job",
749         },
750         {
751                 .name   = "directory",
752                 .type   = FIO_OPT_STR_STORE,
753                 .off1   = td_var_offset(directory),
754                 .cb     = str_directory_cb,
755                 .help   = "Directory to store files in",
756         },
757         {
758                 .name   = "filename",
759                 .type   = FIO_OPT_STR_STORE,
760                 .off1   = td_var_offset(filename),
761                 .cb     = str_filename_cb,
762                 .prio   = -1, /* must come after "directory" */
763                 .help   = "File(s) to use for the workload",
764         },
765         {
766                 .name   = "kb_base",
767                 .type   = FIO_OPT_INT,
768                 .off1   = td_var_offset(kb_base),
769                 .verify = kb_base_verify,
770                 .prio   = 1,
771                 .def    = "1024",
772                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
773         },
774         {
775                 .name   = "lockfile",
776                 .type   = FIO_OPT_STR,
777                 .cb     = str_lockfile_cb,
778                 .off1   = td_var_offset(file_lock_mode),
779                 .help   = "Lock file when doing IO to it",
780                 .parent = "filename",
781                 .def    = "none",
782                 .posval = {
783                           { .ival = "none",
784                             .oval = FILE_LOCK_NONE,
785                             .help = "No file locking",
786                           },
787                           { .ival = "exclusive",
788                             .oval = FILE_LOCK_EXCLUSIVE,
789                             .help = "Exclusive file lock",
790                           },
791                           {
792                             .ival = "readwrite",
793                             .oval = FILE_LOCK_READWRITE,
794                             .help = "Read vs write lock",
795                           },
796                 },
797         },
798         {
799                 .name   = "opendir",
800                 .type   = FIO_OPT_STR_STORE,
801                 .off1   = td_var_offset(opendir),
802                 .cb     = str_opendir_cb,
803                 .help   = "Recursively add files from this directory and down",
804         },
805         {
806                 .name   = "rw",
807                 .alias  = "readwrite",
808                 .type   = FIO_OPT_STR,
809                 .cb     = str_rw_cb,
810                 .off1   = td_var_offset(td_ddir),
811                 .help   = "IO direction",
812                 .def    = "read",
813                 .verify = rw_verify,
814                 .posval = {
815                           { .ival = "read",
816                             .oval = TD_DDIR_READ,
817                             .help = "Sequential read",
818                           },
819                           { .ival = "write",
820                             .oval = TD_DDIR_WRITE,
821                             .help = "Sequential write",
822                           },
823                           { .ival = "randread",
824                             .oval = TD_DDIR_RANDREAD,
825                             .help = "Random read",
826                           },
827                           { .ival = "randwrite",
828                             .oval = TD_DDIR_RANDWRITE,
829                             .help = "Random write",
830                           },
831                           { .ival = "rw",
832                             .oval = TD_DDIR_RW,
833                             .help = "Sequential read and write mix",
834                           },
835                           { .ival = "randrw",
836                             .oval = TD_DDIR_RANDRW,
837                             .help = "Random read and write mix"
838                           },
839                 },
840         },
841         {
842                 .name   = "ioengine",
843                 .type   = FIO_OPT_STR_STORE,
844                 .off1   = td_var_offset(ioengine),
845                 .help   = "IO engine to use",
846                 .def    = "sync",
847                 .posval = {
848                           { .ival = "sync",
849                             .help = "Use read/write",
850                           },
851                           { .ival = "psync",
852                             .help = "Use pread/pwrite",
853                           },
854                           { .ival = "vsync",
855                              .help = "Use readv/writev",
856                           },
857 #ifdef FIO_HAVE_LIBAIO
858                           { .ival = "libaio",
859                             .help = "Linux native asynchronous IO",
860                           },
861 #endif
862 #ifdef FIO_HAVE_POSIXAIO
863                           { .ival = "posixaio",
864                             .help = "POSIX asynchronous IO",
865                           },
866 #endif
867 #ifdef FIO_HAVE_SOLARISAIO
868                           { .ival = "solarisaio",
869                             .help = "Solaris native asynchronous IO",
870                           },
871 #endif
872                           { .ival = "mmap",
873                             .help = "Memory mapped IO",
874                           },
875 #ifdef FIO_HAVE_SPLICE
876                           { .ival = "splice",
877                             .help = "splice/vmsplice based IO",
878                           },
879                           { .ival = "netsplice",
880                             .help = "splice/vmsplice to/from the network",
881                           },
882 #endif
883 #ifdef FIO_HAVE_SGIO
884                           { .ival = "sg",
885                             .help = "SCSI generic v3 IO",
886                           },
887 #endif
888                           { .ival = "null",
889                             .help = "Testing engine (no data transfer)",
890                           },
891                           { .ival = "net",
892                             .help = "Network IO",
893                           },
894 #ifdef FIO_HAVE_SYSLET
895                           { .ival = "syslet-rw",
896                             .help = "syslet enabled async pread/pwrite IO",
897                           },
898 #endif
899                           { .ival = "cpuio",
900                             .help = "CPU cycler burner engine",
901                           },
902 #ifdef FIO_HAVE_GUASI
903                           { .ival = "guasi",
904                             .help = "GUASI IO engine",
905                           },
906 #endif
907                           { .ival = "external",
908                             .help = "Load external engine (append name)",
909                           },
910                 },
911         },
912         {
913                 .name   = "iodepth",
914                 .type   = FIO_OPT_INT,
915                 .off1   = td_var_offset(iodepth),
916                 .help   = "Amount of IO buffers to keep in flight",
917                 .minval = 1,
918                 .def    = "1",
919         },
920         {
921                 .name   = "iodepth_batch",
922                 .alias  = "iodepth_batch_submit",
923                 .type   = FIO_OPT_INT,
924                 .off1   = td_var_offset(iodepth_batch),
925                 .help   = "Number of IO buffers to submit in one go",
926                 .parent = "iodepth",
927                 .minval = 1,
928                 .def    = "1",
929         },
930         {
931                 .name   = "iodepth_batch_complete",
932                 .type   = FIO_OPT_INT,
933                 .off1   = td_var_offset(iodepth_batch_complete),
934                 .help   = "Number of IO buffers to retrieve in one go",
935                 .parent = "iodepth",
936                 .minval = 0,
937                 .def    = "1",
938         },
939         {
940                 .name   = "iodepth_low",
941                 .type   = FIO_OPT_INT,
942                 .off1   = td_var_offset(iodepth_low),
943                 .help   = "Low water mark for queuing depth",
944                 .parent = "iodepth",
945         },
946         {
947                 .name   = "size",
948                 .type   = FIO_OPT_STR_VAL,
949                 .off1   = td_var_offset(size),
950                 .minval = 1,
951                 .help   = "Total size of device or files",
952         },
953         {
954                 .name   = "fill_device",
955                 .type   = FIO_OPT_BOOL,
956                 .off1   = td_var_offset(fill_device),
957                 .help   = "Write until an ENOSPC error occurs",
958                 .def    = "0",
959         },
960         {
961                 .name   = "filesize",
962                 .type   = FIO_OPT_STR_VAL,
963                 .off1   = td_var_offset(file_size_low),
964                 .off2   = td_var_offset(file_size_high),
965                 .minval = 1,
966                 .help   = "Size of individual files",
967         },
968         {
969                 .name   = "offset",
970                 .alias  = "fileoffset",
971                 .type   = FIO_OPT_STR_VAL,
972                 .off1   = td_var_offset(start_offset),
973                 .help   = "Start IO from this offset",
974                 .def    = "0",
975         },
976         {
977                 .name   = "bs",
978                 .alias  = "blocksize",
979                 .type   = FIO_OPT_INT,
980                 .off1   = td_var_offset(bs[DDIR_READ]),
981                 .off2   = td_var_offset(bs[DDIR_WRITE]),
982                 .minval = 1,
983                 .help   = "Block size unit",
984                 .def    = "4k",
985                 .parent = "rw",
986         },
987         {
988                 .name   = "ba",
989                 .alias  = "blockalign",
990                 .type   = FIO_OPT_INT,
991                 .off1   = td_var_offset(ba[DDIR_READ]),
992                 .off2   = td_var_offset(ba[DDIR_WRITE]),
993                 .minval = 1,
994                 .help   = "IO block offset alignment",
995                 .parent = "rw",
996         },
997         {
998                 .name   = "bsrange",
999                 .alias  = "blocksize_range",
1000                 .type   = FIO_OPT_RANGE,
1001                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1002                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1003                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1004                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1005                 .minval = 1,
1006                 .help   = "Set block size range (in more detail than bs)",
1007                 .parent = "rw",
1008         },
1009         {
1010                 .name   = "bssplit",
1011                 .type   = FIO_OPT_STR,
1012                 .cb     = str_bssplit_cb,
1013                 .help   = "Set a specific mix of block sizes",
1014                 .parent = "rw",
1015         },
1016         {
1017                 .name   = "bs_unaligned",
1018                 .alias  = "blocksize_unaligned",
1019                 .type   = FIO_OPT_STR_SET,
1020                 .off1   = td_var_offset(bs_unaligned),
1021                 .help   = "Don't sector align IO buffer sizes",
1022                 .parent = "rw",
1023         },
1024         {
1025                 .name   = "randrepeat",
1026                 .type   = FIO_OPT_BOOL,
1027                 .off1   = td_var_offset(rand_repeatable),
1028                 .help   = "Use repeatable random IO pattern",
1029                 .def    = "1",
1030                 .parent = "rw",
1031         },
1032         {
1033                 .name   = "norandommap",
1034                 .type   = FIO_OPT_STR_SET,
1035                 .off1   = td_var_offset(norandommap),
1036                 .help   = "Accept potential duplicate random blocks",
1037                 .parent = "rw",
1038         },
1039         {
1040                 .name   = "softrandommap",
1041                 .type   = FIO_OPT_BOOL,
1042                 .off1   = td_var_offset(softrandommap),
1043                 .help   = "Set norandommap if randommap allocation fails",
1044                 .parent = "norandommap",
1045                 .def    = "0",
1046         },
1047         {
1048                 .name   = "nrfiles",
1049                 .type   = FIO_OPT_INT,
1050                 .off1   = td_var_offset(nr_files),
1051                 .help   = "Split job workload between this number of files",
1052                 .def    = "1",
1053         },
1054         {
1055                 .name   = "openfiles",
1056                 .type   = FIO_OPT_INT,
1057                 .off1   = td_var_offset(open_files),
1058                 .help   = "Number of files to keep open at the same time",
1059         },
1060         {
1061                 .name   = "file_service_type",
1062                 .type   = FIO_OPT_STR,
1063                 .cb     = str_fst_cb,
1064                 .off1   = td_var_offset(file_service_type),
1065                 .help   = "How to select which file to service next",
1066                 .def    = "roundrobin",
1067                 .posval = {
1068                           { .ival = "random",
1069                             .oval = FIO_FSERVICE_RANDOM,
1070                             .help = "Choose a file at random",
1071                           },
1072                           { .ival = "roundrobin",
1073                             .oval = FIO_FSERVICE_RR,
1074                             .help = "Round robin select files",
1075                           },
1076                           { .ival = "sequential",
1077                             .oval = FIO_FSERVICE_SEQ,
1078                             .help = "Finish one file before moving to the next",
1079                           },
1080                 },
1081                 .parent = "nrfiles",
1082         },
1083 #ifdef FIO_HAVE_FALLOCATE
1084         {
1085                 .name   = "fallocate",
1086                 .type   = FIO_OPT_BOOL,
1087                 .off1   = td_var_offset(fallocate),
1088                 .help   = "Use fallocate() when laying out files",
1089                 .def    = "1",
1090         },
1091 #endif
1092         {
1093                 .name   = "fadvise_hint",
1094                 .type   = FIO_OPT_BOOL,
1095                 .off1   = td_var_offset(fadvise_hint),
1096                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1097                 .def    = "1",
1098         },
1099         {
1100                 .name   = "fsync",
1101                 .type   = FIO_OPT_INT,
1102                 .off1   = td_var_offset(fsync_blocks),
1103                 .help   = "Issue fsync for writes every given number of blocks",
1104                 .def    = "0",
1105         },
1106         {
1107                 .name   = "fdatasync",
1108                 .type   = FIO_OPT_INT,
1109                 .off1   = td_var_offset(fdatasync_blocks),
1110                 .help   = "Issue fdatasync for writes every given number of blocks",
1111                 .def    = "0",
1112         },
1113         {
1114                 .name   = "direct",
1115                 .type   = FIO_OPT_BOOL,
1116                 .off1   = td_var_offset(odirect),
1117                 .help   = "Use O_DIRECT IO (negates buffered)",
1118                 .def    = "0",
1119         },
1120         {
1121                 .name   = "buffered",
1122                 .type   = FIO_OPT_BOOL,
1123                 .off1   = td_var_offset(odirect),
1124                 .neg    = 1,
1125                 .help   = "Use buffered IO (negates direct)",
1126                 .def    = "1",
1127         },
1128         {
1129                 .name   = "overwrite",
1130                 .type   = FIO_OPT_BOOL,
1131                 .off1   = td_var_offset(overwrite),
1132                 .help   = "When writing, set whether to overwrite current data",
1133                 .def    = "0",
1134         },
1135         {
1136                 .name   = "loops",
1137                 .type   = FIO_OPT_INT,
1138                 .off1   = td_var_offset(loops),
1139                 .help   = "Number of times to run the job",
1140                 .def    = "1",
1141         },
1142         {
1143                 .name   = "numjobs",
1144                 .type   = FIO_OPT_INT,
1145                 .off1   = td_var_offset(numjobs),
1146                 .help   = "Duplicate this job this many times",
1147                 .def    = "1",
1148         },
1149         {
1150                 .name   = "startdelay",
1151                 .type   = FIO_OPT_INT,
1152                 .off1   = td_var_offset(start_delay),
1153                 .help   = "Only start job when this period has passed",
1154                 .def    = "0",
1155         },
1156         {
1157                 .name   = "runtime",
1158                 .alias  = "timeout",
1159                 .type   = FIO_OPT_STR_VAL_TIME,
1160                 .off1   = td_var_offset(timeout),
1161                 .help   = "Stop workload when this amount of time has passed",
1162                 .def    = "0",
1163         },
1164         {
1165                 .name   = "time_based",
1166                 .type   = FIO_OPT_STR_SET,
1167                 .off1   = td_var_offset(time_based),
1168                 .help   = "Keep running until runtime/timeout is met",
1169         },
1170         {
1171                 .name   = "ramp_time",
1172                 .type   = FIO_OPT_STR_VAL_TIME,
1173                 .off1   = td_var_offset(ramp_time),
1174                 .help   = "Ramp up time before measuring performance",
1175         },
1176         {
1177                 .name   = "mem",
1178                 .alias  = "iomem",
1179                 .type   = FIO_OPT_STR,
1180                 .cb     = str_mem_cb,
1181                 .off1   = td_var_offset(mem_type),
1182                 .help   = "Backing type for IO buffers",
1183                 .def    = "malloc",
1184                 .posval = {
1185                           { .ival = "malloc",
1186                             .oval = MEM_MALLOC,
1187                             .help = "Use malloc(3) for IO buffers",
1188                           },
1189                           { .ival = "shm",
1190                             .oval = MEM_SHM,
1191                             .help = "Use shared memory segments for IO buffers",
1192                           },
1193 #ifdef FIO_HAVE_HUGETLB
1194                           { .ival = "shmhuge",
1195                             .oval = MEM_SHMHUGE,
1196                             .help = "Like shm, but use huge pages",
1197                           },
1198 #endif
1199                           { .ival = "mmap",
1200                             .oval = MEM_MMAP,
1201                             .help = "Use mmap(2) (file or anon) for IO buffers",
1202                           },
1203 #ifdef FIO_HAVE_HUGETLB
1204                           { .ival = "mmaphuge",
1205                             .oval = MEM_MMAPHUGE,
1206                             .help = "Like mmap, but use huge pages",
1207                           },
1208 #endif
1209                   },
1210         },
1211         {
1212                 .name   = "iomem_align",
1213                 .alias  = "mem_align",
1214                 .type   = FIO_OPT_INT,
1215                 .off1   = td_var_offset(mem_align),
1216                 .minval = 0,
1217                 .help   = "IO memory buffer offset alignment",
1218                 .def    = "0",
1219                 .parent = "iomem",
1220         },
1221         {
1222                 .name   = "verify",
1223                 .type   = FIO_OPT_STR,
1224                 .off1   = td_var_offset(verify),
1225                 .help   = "Verify data written",
1226                 .def    = "0",
1227                 .posval = {
1228                           { .ival = "0",
1229                             .oval = VERIFY_NONE,
1230                             .help = "Don't do IO verification",
1231                           },
1232                           { .ival = "md5",
1233                             .oval = VERIFY_MD5,
1234                             .help = "Use md5 checksums for verification",
1235                           },
1236                           { .ival = "crc64",
1237                             .oval = VERIFY_CRC64,
1238                             .help = "Use crc64 checksums for verification",
1239                           },
1240                           { .ival = "crc32",
1241                             .oval = VERIFY_CRC32,
1242                             .help = "Use crc32 checksums for verification",
1243                           },
1244                           { .ival = "crc32c-intel",
1245                             .oval = VERIFY_CRC32C_INTEL,
1246                             .help = "Use hw crc32c checksums for verification",
1247                           },
1248                           { .ival = "crc32c",
1249                             .oval = VERIFY_CRC32C,
1250                             .help = "Use crc32c checksums for verification",
1251                           },
1252                           { .ival = "crc16",
1253                             .oval = VERIFY_CRC16,
1254                             .help = "Use crc16 checksums for verification",
1255                           },
1256                           { .ival = "crc7",
1257                             .oval = VERIFY_CRC7,
1258                             .help = "Use crc7 checksums for verification",
1259                           },
1260                           { .ival = "sha1",
1261                             .oval = VERIFY_SHA1,
1262                             .help = "Use sha1 checksums for verification",
1263                           },
1264                           { .ival = "sha256",
1265                             .oval = VERIFY_SHA256,
1266                             .help = "Use sha256 checksums for verification",
1267                           },
1268                           { .ival = "sha512",
1269                             .oval = VERIFY_SHA512,
1270                             .help = "Use sha512 checksums for verification",
1271                           },
1272                           { .ival = "meta",
1273                             .oval = VERIFY_META,
1274                             .help = "Use io information",
1275                           },
1276                           {
1277                             .ival = "null",
1278                             .oval = VERIFY_NULL,
1279                             .help = "Pretend to verify",
1280                           },
1281                 },
1282         },
1283         {
1284                 .name   = "do_verify",
1285                 .type   = FIO_OPT_BOOL,
1286                 .off1   = td_var_offset(do_verify),
1287                 .help   = "Run verification stage after write",
1288                 .def    = "1",
1289                 .parent = "verify",
1290         },
1291         {
1292                 .name   = "verifysort",
1293                 .type   = FIO_OPT_BOOL,
1294                 .off1   = td_var_offset(verifysort),
1295                 .help   = "Sort written verify blocks for read back",
1296                 .def    = "1",
1297                 .parent = "verify",
1298         },
1299         {
1300                 .name   = "verify_interval",
1301                 .type   = FIO_OPT_INT,
1302                 .off1   = td_var_offset(verify_interval),
1303                 .minval = 2 * sizeof(struct verify_header),
1304                 .help   = "Store verify buffer header every N bytes",
1305                 .parent = "verify",
1306         },
1307         {
1308                 .name   = "verify_offset",
1309                 .type   = FIO_OPT_INT,
1310                 .help   = "Offset verify header location by N bytes",
1311                 .def    = "0",
1312                 .cb     = str_verify_offset_cb,
1313                 .parent = "verify",
1314         },
1315         {
1316                 .name   = "verify_pattern",
1317                 .type   = FIO_OPT_STR,
1318                 .cb     = str_verify_pattern_cb,
1319                 .help   = "Fill pattern for IO buffers",
1320                 .parent = "verify",
1321         },
1322         {
1323                 .name   = "verify_fatal",
1324                 .type   = FIO_OPT_BOOL,
1325                 .off1   = td_var_offset(verify_fatal),
1326                 .def    = "0",
1327                 .help   = "Exit on a single verify failure, don't continue",
1328                 .parent = "verify",
1329         },
1330         {
1331                 .name   = "verify_async",
1332                 .type   = FIO_OPT_INT,
1333                 .off1   = td_var_offset(verify_async),
1334                 .def    = "0",
1335                 .help   = "Number of async verifier threads to use",
1336                 .parent = "verify",
1337         },
1338 #ifdef FIO_HAVE_CPU_AFFINITY
1339         {
1340                 .name   = "verify_async_cpus",
1341                 .type   = FIO_OPT_STR,
1342                 .cb     = str_verify_cpus_allowed_cb,
1343                 .help   = "Set CPUs allowed for async verify threads",
1344                 .parent = "verify_async",
1345         },
1346 #endif
1347         {
1348                 .name   = "write_iolog",
1349                 .type   = FIO_OPT_STR_STORE,
1350                 .off1   = td_var_offset(write_iolog_file),
1351                 .help   = "Store IO pattern to file",
1352         },
1353         {
1354                 .name   = "read_iolog",
1355                 .type   = FIO_OPT_STR_STORE,
1356                 .off1   = td_var_offset(read_iolog_file),
1357                 .help   = "Playback IO pattern from file",
1358         },
1359         {
1360                 .name   = "exec_prerun",
1361                 .type   = FIO_OPT_STR_STORE,
1362                 .off1   = td_var_offset(exec_prerun),
1363                 .help   = "Execute this file prior to running job",
1364         },
1365         {
1366                 .name   = "exec_postrun",
1367                 .type   = FIO_OPT_STR_STORE,
1368                 .off1   = td_var_offset(exec_postrun),
1369                 .help   = "Execute this file after running job",
1370         },
1371 #ifdef FIO_HAVE_IOSCHED_SWITCH
1372         {
1373                 .name   = "ioscheduler",
1374                 .type   = FIO_OPT_STR_STORE,
1375                 .off1   = td_var_offset(ioscheduler),
1376                 .help   = "Use this IO scheduler on the backing device",
1377         },
1378 #endif
1379         {
1380                 .name   = "zonesize",
1381                 .type   = FIO_OPT_STR_VAL,
1382                 .off1   = td_var_offset(zone_size),
1383                 .help   = "Give size of an IO zone",
1384                 .def    = "0",
1385         },
1386         {
1387                 .name   = "zoneskip",
1388                 .type   = FIO_OPT_STR_VAL,
1389                 .off1   = td_var_offset(zone_skip),
1390                 .help   = "Space between IO zones",
1391                 .def    = "0",
1392         },
1393         {
1394                 .name   = "lockmem",
1395                 .type   = FIO_OPT_STR_VAL,
1396                 .cb     = str_lockmem_cb,
1397                 .help   = "Lock down this amount of memory",
1398                 .def    = "0",
1399         },
1400         {
1401                 .name   = "rwmixread",
1402                 .type   = FIO_OPT_INT,
1403                 .cb     = str_rwmix_read_cb,
1404                 .maxval = 100,
1405                 .help   = "Percentage of mixed workload that is reads",
1406                 .def    = "50",
1407         },
1408         {
1409                 .name   = "rwmixwrite",
1410                 .type   = FIO_OPT_INT,
1411                 .cb     = str_rwmix_write_cb,
1412                 .maxval = 100,
1413                 .help   = "Percentage of mixed workload that is writes",
1414                 .def    = "50",
1415         },
1416         {
1417                 .name   = "rwmixcycle",
1418                 .type   = FIO_OPT_DEPRECATED,
1419         },
1420         {
1421                 .name   = "nice",
1422                 .type   = FIO_OPT_INT,
1423                 .off1   = td_var_offset(nice),
1424                 .help   = "Set job CPU nice value",
1425                 .minval = -19,
1426                 .maxval = 20,
1427                 .def    = "0",
1428         },
1429 #ifdef FIO_HAVE_IOPRIO
1430         {
1431                 .name   = "prio",
1432                 .type   = FIO_OPT_INT,
1433                 .cb     = str_prio_cb,
1434                 .help   = "Set job IO priority value",
1435                 .minval = 0,
1436                 .maxval = 7,
1437         },
1438         {
1439                 .name   = "prioclass",
1440                 .type   = FIO_OPT_INT,
1441                 .cb     = str_prioclass_cb,
1442                 .help   = "Set job IO priority class",
1443                 .minval = 0,
1444                 .maxval = 3,
1445         },
1446 #endif
1447         {
1448                 .name   = "thinktime",
1449                 .type   = FIO_OPT_INT,
1450                 .off1   = td_var_offset(thinktime),
1451                 .help   = "Idle time between IO buffers (usec)",
1452                 .def    = "0",
1453         },
1454         {
1455                 .name   = "thinktime_spin",
1456                 .type   = FIO_OPT_INT,
1457                 .off1   = td_var_offset(thinktime_spin),
1458                 .help   = "Start think time by spinning this amount (usec)",
1459                 .def    = "0",
1460                 .parent = "thinktime",
1461         },
1462         {
1463                 .name   = "thinktime_blocks",
1464                 .type   = FIO_OPT_INT,
1465                 .off1   = td_var_offset(thinktime_blocks),
1466                 .help   = "IO buffer period between 'thinktime'",
1467                 .def    = "1",
1468                 .parent = "thinktime",
1469         },
1470         {
1471                 .name   = "rate",
1472                 .type   = FIO_OPT_INT,
1473                 .off1   = td_var_offset(rate[0]),
1474                 .off2   = td_var_offset(rate[1]),
1475                 .help   = "Set bandwidth rate",
1476         },
1477         {
1478                 .name   = "ratemin",
1479                 .type   = FIO_OPT_INT,
1480                 .off1   = td_var_offset(ratemin[0]),
1481                 .off2   = td_var_offset(ratemin[1]),
1482                 .help   = "Job must meet this rate or it will be shutdown",
1483                 .parent = "rate",
1484         },
1485         {
1486                 .name   = "rate_iops",
1487                 .type   = FIO_OPT_INT,
1488                 .off1   = td_var_offset(rate_iops[0]),
1489                 .off2   = td_var_offset(rate_iops[1]),
1490                 .help   = "Limit IO used to this number of IO operations/sec",
1491         },
1492         {
1493                 .name   = "rate_iops_min",
1494                 .type   = FIO_OPT_INT,
1495                 .off1   = td_var_offset(rate_iops_min[0]),
1496                 .off2   = td_var_offset(rate_iops_min[1]),
1497                 .help   = "Job must meet this rate or it will be shutdown",
1498                 .parent = "rate_iops",
1499         },
1500         {
1501                 .name   = "ratecycle",
1502                 .type   = FIO_OPT_INT,
1503                 .off1   = td_var_offset(ratecycle),
1504                 .help   = "Window average for rate limits (msec)",
1505                 .def    = "1000",
1506                 .parent = "rate",
1507         },
1508         {
1509                 .name   = "invalidate",
1510                 .type   = FIO_OPT_BOOL,
1511                 .off1   = td_var_offset(invalidate_cache),
1512                 .help   = "Invalidate buffer/page cache prior to running job",
1513                 .def    = "1",
1514         },
1515         {
1516                 .name   = "sync",
1517                 .type   = FIO_OPT_BOOL,
1518                 .off1   = td_var_offset(sync_io),
1519                 .help   = "Use O_SYNC for buffered writes",
1520                 .def    = "0",
1521                 .parent = "buffered",
1522         },
1523         {
1524                 .name   = "bwavgtime",
1525                 .type   = FIO_OPT_INT,
1526                 .off1   = td_var_offset(bw_avg_time),
1527                 .help   = "Time window over which to calculate bandwidth"
1528                           " (msec)",
1529                 .def    = "500",
1530         },
1531         {
1532                 .name   = "create_serialize",
1533                 .type   = FIO_OPT_BOOL,
1534                 .off1   = td_var_offset(create_serialize),
1535                 .help   = "Serialize creating of job files",
1536                 .def    = "1",
1537         },
1538         {
1539                 .name   = "create_fsync",
1540                 .type   = FIO_OPT_BOOL,
1541                 .off1   = td_var_offset(create_fsync),
1542                 .help   = "Fsync file after creation",
1543                 .def    = "1",
1544         },
1545         {
1546                 .name   = "create_on_open",
1547                 .type   = FIO_OPT_BOOL,
1548                 .off1   = td_var_offset(create_on_open),
1549                 .help   = "Create files when they are opened for IO",
1550                 .def    = "0",
1551         },
1552         {
1553                 .name   = "pre_read",
1554                 .type   = FIO_OPT_BOOL,
1555                 .off1   = td_var_offset(pre_read),
1556                 .help   = "Preread files before starting official testing",
1557                 .def    = "0",
1558         },
1559         {
1560                 .name   = "cpuload",
1561                 .type   = FIO_OPT_INT,
1562                 .off1   = td_var_offset(cpuload),
1563                 .help   = "Use this percentage of CPU",
1564         },
1565         {
1566                 .name   = "cpuchunks",
1567                 .type   = FIO_OPT_INT,
1568                 .off1   = td_var_offset(cpucycle),
1569                 .help   = "Length of the CPU burn cycles (usecs)",
1570                 .def    = "50000",
1571                 .parent = "cpuload",
1572         },
1573 #ifdef FIO_HAVE_CPU_AFFINITY
1574         {
1575                 .name   = "cpumask",
1576                 .type   = FIO_OPT_INT,
1577                 .cb     = str_cpumask_cb,
1578                 .help   = "CPU affinity mask",
1579         },
1580         {
1581                 .name   = "cpus_allowed",
1582                 .type   = FIO_OPT_STR,
1583                 .cb     = str_cpus_allowed_cb,
1584                 .help   = "Set CPUs allowed",
1585         },
1586 #endif
1587         {
1588                 .name   = "end_fsync",
1589                 .type   = FIO_OPT_BOOL,
1590                 .off1   = td_var_offset(end_fsync),
1591                 .help   = "Include fsync at the end of job",
1592                 .def    = "0",
1593         },
1594         {
1595                 .name   = "fsync_on_close",
1596                 .type   = FIO_OPT_BOOL,
1597                 .off1   = td_var_offset(fsync_on_close),
1598                 .help   = "fsync files on close",
1599                 .def    = "0",
1600         },
1601         {
1602                 .name   = "unlink",
1603                 .type   = FIO_OPT_BOOL,
1604                 .off1   = td_var_offset(unlink),
1605                 .help   = "Unlink created files after job has completed",
1606                 .def    = "0",
1607         },
1608         {
1609                 .name   = "exitall",
1610                 .type   = FIO_OPT_STR_SET,
1611                 .cb     = str_exitall_cb,
1612                 .help   = "Terminate all jobs when one exits",
1613         },
1614         {
1615                 .name   = "stonewall",
1616                 .type   = FIO_OPT_STR_SET,
1617                 .off1   = td_var_offset(stonewall),
1618                 .help   = "Insert a hard barrier between this job and previous",
1619         },
1620         {
1621                 .name   = "new_group",
1622                 .type   = FIO_OPT_STR_SET,
1623                 .off1   = td_var_offset(new_group),
1624                 .help   = "Mark the start of a new group (for reporting)",
1625         },
1626         {
1627                 .name   = "thread",
1628                 .type   = FIO_OPT_STR_SET,
1629                 .off1   = td_var_offset(use_thread),
1630                 .help   = "Use threads instead of forks",
1631         },
1632         {
1633                 .name   = "write_bw_log",
1634                 .type   = FIO_OPT_STR,
1635                 .off1   = td_var_offset(write_bw_log),
1636                 .cb     = str_write_bw_log_cb,
1637                 .help   = "Write log of bandwidth during run",
1638         },
1639         {
1640                 .name   = "write_lat_log",
1641                 .type   = FIO_OPT_STR,
1642                 .off1   = td_var_offset(write_lat_log),
1643                 .cb     = str_write_lat_log_cb,
1644                 .help   = "Write log of latency during run",
1645         },
1646         {
1647                 .name   = "hugepage-size",
1648                 .type   = FIO_OPT_INT,
1649                 .off1   = td_var_offset(hugepage_size),
1650                 .help   = "When using hugepages, specify size of each page",
1651                 .def    = __stringify(FIO_HUGE_PAGE),
1652         },
1653         {
1654                 .name   = "group_reporting",
1655                 .type   = FIO_OPT_STR_SET,
1656                 .off1   = td_var_offset(group_reporting),
1657                 .help   = "Do reporting on a per-group basis",
1658         },
1659         {
1660                 .name   = "zero_buffers",
1661                 .type   = FIO_OPT_STR_SET,
1662                 .off1   = td_var_offset(zero_buffers),
1663                 .help   = "Init IO buffers to all zeroes",
1664         },
1665         {
1666                 .name   = "refill_buffers",
1667                 .type   = FIO_OPT_STR_SET,
1668                 .off1   = td_var_offset(refill_buffers),
1669                 .help   = "Refill IO buffers on every IO submit",
1670         },
1671 #ifdef FIO_HAVE_DISK_UTIL
1672         {
1673                 .name   = "disk_util",
1674                 .type   = FIO_OPT_BOOL,
1675                 .off1   = td_var_offset(do_disk_util),
1676                 .help   = "Log disk utilization statistics",
1677                 .def    = "1",
1678         },
1679 #endif
1680         {
1681                 .name   = "gtod_reduce",
1682                 .type   = FIO_OPT_BOOL,
1683                 .help   = "Greatly reduce number of gettimeofday() calls",
1684                 .cb     = str_gtod_reduce_cb,
1685                 .def    = "0",
1686         },
1687         {
1688                 .name   = "disable_clat",
1689                 .type   = FIO_OPT_BOOL,
1690                 .off1   = td_var_offset(disable_clat),
1691                 .help   = "Disable completion latency numbers",
1692                 .parent = "gtod_reduce",
1693                 .def    = "0",
1694         },
1695         {
1696                 .name   = "disable_slat",
1697                 .type   = FIO_OPT_BOOL,
1698                 .off1   = td_var_offset(disable_slat),
1699                 .help   = "Disable submissionn latency numbers",
1700                 .parent = "gtod_reduce",
1701                 .def    = "0",
1702         },
1703         {
1704                 .name   = "disable_bw_measurement",
1705                 .type   = FIO_OPT_BOOL,
1706                 .off1   = td_var_offset(disable_bw),
1707                 .help   = "Disable bandwidth logging",
1708                 .parent = "gtod_reduce",
1709                 .def    = "0",
1710         },
1711         {
1712                 .name   = "gtod_cpu",
1713                 .type   = FIO_OPT_INT,
1714                 .cb     = str_gtod_cpu_cb,
1715                 .help   = "Setup dedicated gettimeofday() thread on this CPU",
1716                 .verify = gtod_cpu_verify,
1717         },
1718         {
1719                 .name   = "continue_on_error",
1720                 .type   = FIO_OPT_BOOL,
1721                 .off1   = td_var_offset(continue_on_error),
1722                 .help   = "Continue on non-fatal errors during I/O",
1723                 .def    = "0",
1724         },
1725         {
1726                 .name   = "profile",
1727                 .type   = FIO_OPT_STR_STORE,
1728                 .off1   = td_var_offset(profile),
1729                 .help   = "Select a specific builtin performance test",
1730         },
1731         {
1732                 .name   = "cgroup",
1733                 .type   = FIO_OPT_STR_STORE,
1734                 .off1   = td_var_offset(cgroup),
1735                 .help   = "Add job to cgroup of this name",
1736         },
1737         {
1738                 .name   = "cgroup_weight",
1739                 .type   = FIO_OPT_INT,
1740                 .off1   = td_var_offset(cgroup_weight),
1741                 .help   = "Use given weight for cgroup",
1742                 .minval = 100,
1743                 .maxval = 1000,
1744         },
1745         {
1746                 .name   = "uid",
1747                 .type   = FIO_OPT_INT,
1748                 .off1   = td_var_offset(uid),
1749                 .help   = "Run job with this user ID",
1750         },
1751         {
1752                 .name   = "gid",
1753                 .type   = FIO_OPT_INT,
1754                 .off1   = td_var_offset(gid),
1755                 .help   = "Run job with this group ID",
1756         },
1757         {
1758                 .name = NULL,
1759         },
1760 };
1761
1762 static void add_to_lopt(struct option *lopt, struct fio_option *o)
1763 {
1764         lopt->name = (char *) o->name;
1765         lopt->val = FIO_GETOPT_JOB;
1766         if (o->type == FIO_OPT_STR_SET)
1767                 lopt->has_arg = no_argument;
1768         else
1769                 lopt->has_arg = required_argument;
1770 }
1771
1772 void fio_options_dup_and_init(struct option *long_options)
1773 {
1774         struct fio_option *o;
1775         unsigned int i;
1776
1777         options_init(options);
1778
1779         i = 0;
1780         while (long_options[i].name)
1781                 i++;
1782
1783         o = &options[0];
1784         while (o->name) {
1785                 add_to_lopt(&long_options[i], o);
1786
1787                 i++;
1788                 o++;
1789                 assert(i < FIO_NR_OPTIONS);
1790         }
1791 }
1792
1793 struct fio_keyword {
1794         const char *word;
1795         const char *desc;
1796         char *replace;
1797 };
1798
1799 static struct fio_keyword fio_keywords[] = {
1800         {
1801                 .word   = "$pagesize",
1802                 .desc   = "Page size in the system",
1803         },
1804         {
1805                 .word   = "$mb_memory",
1806                 .desc   = "Megabytes of memory online",
1807         },
1808         {
1809                 .word   = "$ncpus",
1810                 .desc   = "Number of CPUs online in the system",
1811         },
1812         {
1813                 .word   = NULL,
1814         },
1815 };
1816
1817 void fio_keywords_init(void)
1818 {
1819         unsigned long long mb_memory;
1820         char buf[128];
1821         long l;
1822
1823         sprintf(buf, "%lu", page_size);
1824         fio_keywords[0].replace = strdup(buf);
1825
1826         mb_memory = os_phys_mem() / page_size;
1827         sprintf(buf, "%llu", mb_memory);
1828         fio_keywords[1].replace = strdup(buf);
1829
1830         l = sysconf(_SC_NPROCESSORS_ONLN);
1831         sprintf(buf, "%lu", l);
1832         fio_keywords[2].replace = strdup(buf);
1833 }
1834
1835 #define BC_APP          "bc"
1836
1837 static char *bc_calc(char *str)
1838 {
1839         char *buf, *tmp, opt[80];
1840         FILE *f;
1841         int ret;
1842
1843         /*
1844          * No math, just return string
1845          */
1846         if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1847             !strchr(str, '/'))
1848                 return str;
1849
1850         /*
1851          * Split option from value, we only need to calculate the value
1852          */
1853         tmp = strchr(str, '=');
1854         if (!tmp)
1855                 return str;
1856
1857         tmp++;
1858         memset(opt, 0, sizeof(opt));
1859         strncpy(opt, str, tmp - str);
1860
1861         buf = malloc(128);
1862
1863         sprintf(buf, "which %s > /dev/null", BC_APP);
1864         if (system(buf)) {
1865                 log_err("fio: bc is needed for performing math\n");
1866                 free(buf);
1867                 return NULL;
1868         }
1869
1870         sprintf(buf, "echo %s | %s", tmp, BC_APP);
1871         f = popen(buf, "r");
1872         if (!f) {
1873                 free(buf);
1874                 return NULL;
1875         }
1876
1877         ret = fread(buf, 1, 128, f);
1878         if (ret <= 0) {
1879                 free(buf);
1880                 return NULL;
1881         }
1882
1883         buf[ret - 1] = '\0';
1884         strcat(opt, buf);
1885         strcpy(buf, opt);
1886         pclose(f);
1887         free(str);
1888         return buf;
1889 }
1890
1891 /*
1892  * Look for reserved variable names and replace them with real values
1893  */
1894 static char *fio_keyword_replace(char *opt)
1895 {
1896         char *s;
1897         int i;
1898
1899         for (i = 0; fio_keywords[i].word != NULL; i++) {
1900                 struct fio_keyword *kw = &fio_keywords[i];
1901
1902                 while ((s = strstr(opt, kw->word)) != NULL) {
1903                         char *new = malloc(strlen(opt) + 1);
1904                         char *o_org = opt;
1905                         int olen = s - opt;
1906                         int len;
1907
1908                         /*
1909                          * Copy part of the string before the keyword and
1910                          * sprintf() the replacement after it.
1911                          */
1912                         memcpy(new, opt, olen);
1913                         len = sprintf(new + olen, "%s", kw->replace);
1914
1915                         /*
1916                          * If there's more in the original string, copy that
1917                          * in too
1918                          */
1919                         opt += strlen(kw->word) + olen;
1920                         if (strlen(opt))
1921                                 memcpy(new + olen + len, opt, opt - o_org - 1);
1922
1923                         /*
1924                          * replace opt and free the old opt
1925                          */
1926                         opt = new;
1927                         //free(o_org);
1928
1929                         /*
1930                          * Check for potential math and invoke bc, if possible
1931                          */
1932                         opt = bc_calc(opt);
1933                 }
1934         }
1935
1936         return opt;
1937 }
1938
1939 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1940 {
1941         int i, ret;
1942
1943         sort_options(opts, options, num_opts);
1944
1945         for (ret = 0, i = 0; i < num_opts; i++) {
1946                 opts[i] = fio_keyword_replace(opts[i]);
1947                 ret |= parse_option(opts[i], options, td);
1948         }
1949
1950         return ret;
1951 }
1952
1953 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1954 {
1955         return parse_cmd_option(opt, val, options, td);
1956 }
1957
1958 void fio_fill_default_options(struct thread_data *td)
1959 {
1960         fill_default_options(td, options);
1961 }
1962
1963 int fio_show_option_help(const char *opt)
1964 {
1965         return show_cmd_help(options, opt);
1966 }
1967
1968 static void __options_mem(struct thread_data *td, int alloc)
1969 {
1970         struct thread_options *o = &td->o;
1971         struct fio_option *opt;
1972         char **ptr;
1973         int i;
1974
1975         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1976                 if (opt->type != FIO_OPT_STR_STORE)
1977                         continue;
1978
1979                 ptr = (void *) o + opt->off1;
1980                 if (*ptr) {
1981                         if (alloc)
1982                                 *ptr = strdup(*ptr);
1983                         else {
1984                                 free(*ptr);
1985                                 *ptr = NULL;
1986                         }
1987                 }
1988         }
1989 }
1990
1991 /*
1992  * dupe FIO_OPT_STR_STORE options
1993  */
1994 void options_mem_dupe(struct thread_data *td)
1995 {
1996         __options_mem(td, 1);
1997 }
1998
1999 void options_mem_free(struct thread_data fio_unused *td)
2000 {
2001 #if 0
2002         __options_mem(td, 0);
2003 #endif
2004 }
2005
2006 unsigned int fio_get_kb_base(void *data)
2007 {
2008         struct thread_data *td = data;
2009         unsigned int kb_base = 0;
2010
2011         if (td)
2012                 kb_base = td->o.kb_base;
2013         if (!kb_base)
2014                 kb_base = 1024;
2015
2016         return kb_base;
2017 }
2018
2019 int add_option(struct fio_option *o)
2020 {
2021         struct fio_option *__o;
2022         int opt_index = 0;
2023
2024         __o = options;
2025         while (__o->name) {
2026                 opt_index++;
2027                 __o++;
2028         }
2029
2030         memcpy(&options[opt_index], o, sizeof(*o));
2031         return 0;
2032 }
2033
2034 void invalidate_profile_options(const char *prof_name)
2035 {
2036         struct fio_option *o;
2037
2038         o = options;
2039         while (o->name) {
2040                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2041                         o->type = FIO_OPT_INVALID;
2042                         o->prof_name = NULL;
2043                 }
2044                 o++;
2045         }
2046 }
2047
2048 void add_opt_posval(const char *optname, const char *ival, const char *help)
2049 {
2050         struct fio_option *o;
2051         unsigned int i;
2052
2053         o = find_option(options, optname);
2054         if (!o)
2055                 return;
2056
2057         for (i = 0; i < PARSE_MAX_VP; i++) {
2058                 if (o->posval[i].ival)
2059                         continue;
2060
2061                 o->posval[i].ival = ival;
2062                 o->posval[i].help = help;
2063                 break;
2064         }
2065 }
2066
2067 void del_opt_posval(const char *optname, const char *ival)
2068 {
2069         struct fio_option *o;
2070         unsigned int i;
2071
2072         o = find_option(options, optname);
2073         if (!o)
2074                 return;
2075
2076         for (i = 0; i < PARSE_MAX_VP; i++) {
2077                 if (!o->posval[i].ival)
2078                         continue;
2079                 if (strcmp(o->posval[i].ival, ival))
2080                         continue;
2081
2082                 o->posval[i].ival = NULL;
2083                 o->posval[i].help = NULL;
2084         }
2085 }