Add safe checks for valid pareto input value
[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 <assert.h>
7 #include <libgen.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11
12 #include "fio.h"
13 #include "verify.h"
14 #include "parse.h"
15 #include "lib/fls.h"
16 #include "options.h"
17
18 #include "crc/crc32c.h"
19
20 /*
21  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22  */
23 static char *get_opt_postfix(const char *str)
24 {
25         char *p = strstr(str, ":");
26
27         if (!p)
28                 return NULL;
29
30         p++;
31         strip_blank_front(&p);
32         strip_blank_end(p);
33         return strdup(p);
34 }
35
36 static int converthexchartoint(char a)
37 {
38         int base;
39
40         switch(a) {
41         case '0'...'9':
42                 base = '0';
43                 break;
44         case 'A'...'F':
45                 base = 'A' - 10;
46                 break;
47         case 'a'...'f':
48                 base = 'a' - 10;
49                 break;
50         default:
51                 base = 0;
52         }
53         return (a - base);
54 }
55
56 static int bs_cmp(const void *p1, const void *p2)
57 {
58         const struct bssplit *bsp1 = p1;
59         const struct bssplit *bsp2 = p2;
60
61         return bsp1->perc < bsp2->perc;
62 }
63
64 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
65 {
66         struct bssplit *bssplit;
67         unsigned int i, perc, perc_missing;
68         unsigned int max_bs, min_bs;
69         long long val;
70         char *fname;
71
72         td->o.bssplit_nr[ddir] = 4;
73         bssplit = malloc(4 * sizeof(struct bssplit));
74
75         i = 0;
76         max_bs = 0;
77         min_bs = -1;
78         while ((fname = strsep(&str, ":")) != NULL) {
79                 char *perc_str;
80
81                 if (!strlen(fname))
82                         break;
83
84                 /*
85                  * grow struct buffer, if needed
86                  */
87                 if (i == td->o.bssplit_nr[ddir]) {
88                         td->o.bssplit_nr[ddir] <<= 1;
89                         bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
90                                                   * sizeof(struct bssplit));
91                 }
92
93                 perc_str = strstr(fname, "/");
94                 if (perc_str) {
95                         *perc_str = '\0';
96                         perc_str++;
97                         perc = atoi(perc_str);
98                         if (perc > 100)
99                                 perc = 100;
100                         else if (!perc)
101                                 perc = -1;
102                 } else
103                         perc = -1;
104
105                 if (str_to_decimal(fname, &val, 1, td)) {
106                         log_err("fio: bssplit conversion failed\n");
107                         free(td->o.bssplit);
108                         return 1;
109                 }
110
111                 if (val > max_bs)
112                         max_bs = val;
113                 if (val < min_bs)
114                         min_bs = val;
115
116                 bssplit[i].bs = val;
117                 bssplit[i].perc = perc;
118                 i++;
119         }
120
121         td->o.bssplit_nr[ddir] = i;
122
123         /*
124          * Now check if the percentages add up, and how much is missing
125          */
126         perc = perc_missing = 0;
127         for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128                 struct bssplit *bsp = &bssplit[i];
129
130                 if (bsp->perc == (unsigned char) -1)
131                         perc_missing++;
132                 else
133                         perc += bsp->perc;
134         }
135
136         if (perc > 100) {
137                 log_err("fio: bssplit percentages add to more than 100%%\n");
138                 free(bssplit);
139                 return 1;
140         }
141         /*
142          * If values didn't have a percentage set, divide the remains between
143          * them.
144          */
145         if (perc_missing) {
146                 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147                         struct bssplit *bsp = &bssplit[i];
148
149                         if (bsp->perc == (unsigned char) -1)
150                                 bsp->perc = (100 - perc) / perc_missing;
151                 }
152         }
153
154         td->o.min_bs[ddir] = min_bs;
155         td->o.max_bs[ddir] = max_bs;
156
157         /*
158          * now sort based on percentages, for ease of lookup
159          */
160         qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161         td->o.bssplit[ddir] = bssplit;
162         return 0;
163
164 }
165
166 static int str_bssplit_cb(void *data, const char *input)
167 {
168         struct thread_data *td = data;
169         char *str, *p, *odir, *ddir;
170         int ret = 0;
171
172         p = str = strdup(input);
173
174         strip_blank_front(&str);
175         strip_blank_end(str);
176
177         odir = strchr(str, ',');
178         if (odir) {
179                 ddir = strchr(odir + 1, ',');
180                 if (ddir) {
181                         ret = bssplit_ddir(td, DDIR_TRIM, ddir + 1);
182                         if (!ret)
183                                 *ddir = '\0';
184                 } else {
185                         char *op;
186
187                         op = strdup(odir + 1);
188                         ret = bssplit_ddir(td, DDIR_TRIM, op);
189
190                         free(op);
191                 }
192                 if (!ret) 
193                         ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
194                 if (!ret) {
195                         *odir = '\0';
196                         ret = bssplit_ddir(td, DDIR_READ, str);
197                 }
198         } else {
199                 char *op;
200
201                 op = strdup(str);
202                 ret = bssplit_ddir(td, DDIR_WRITE, op);
203                 free(op);
204
205                 if (!ret) {
206                         op = strdup(str);
207                         ret = bssplit_ddir(td, DDIR_TRIM, op);
208                         free(op);
209                 }
210                 ret = bssplit_ddir(td, DDIR_READ, str);
211         }
212
213         free(p);
214         return ret;
215 }
216
217 static int str2error(char *str)
218 {
219         const char * err[] = {"EPERM", "ENOENT", "ESRCH", "EINTR", "EIO",
220                             "ENXIO", "E2BIG", "ENOEXEC", "EBADF",
221                             "ECHILD", "EAGAIN", "ENOMEM", "EACCES",
222                             "EFAULT", "ENOTBLK", "EBUSY", "EEXIST",
223                             "EXDEV", "ENODEV", "ENOTDIR", "EISDIR",
224                             "EINVAL", "ENFILE", "EMFILE", "ENOTTY",
225                             "ETXTBSY","EFBIG", "ENOSPC", "ESPIPE",
226                             "EROFS","EMLINK", "EPIPE", "EDOM", "ERANGE"};
227         int i = 0, num = sizeof(err) / sizeof(void *);
228
229         while( i < num) {
230                 if (!strcmp(err[i], str))
231                         return i + 1;
232                 i++;
233         }
234         return 0;
235 }
236
237 static int ignore_error_type(struct thread_data *td, int etype, char *str)
238 {
239         unsigned int i;
240         int *error;
241         char *fname;
242
243         if (etype >= ERROR_TYPE_CNT) {
244                 log_err("Illegal error type\n");
245                 return 1;
246         }
247
248         td->o.ignore_error_nr[etype] = 4;
249         error = malloc(4 * sizeof(struct bssplit));
250
251         i = 0;
252         while ((fname = strsep(&str, ":")) != NULL) {
253
254                 if (!strlen(fname))
255                         break;
256
257                 /*
258                  * grow struct buffer, if needed
259                  */
260                 if (i == td->o.ignore_error_nr[etype]) {
261                         td->o.ignore_error_nr[etype] <<= 1;
262                         error = realloc(error, td->o.ignore_error_nr[etype]
263                                                   * sizeof(int));
264                 }
265                 if (fname[0] == 'E') {
266                         error[i] = str2error(fname);
267                 } else {
268                         error[i] = atoi(fname);
269                         if (error[i] < 0)
270                                 error[i] = error[i];
271                 }
272                 if (!error[i]) {
273                         log_err("Unknown error %s, please use number value \n",
274                                   fname);
275                         return 1;
276                 }
277                 i++;
278         }
279         if (i) {
280                 td->o.continue_on_error |= 1 << etype;
281                 td->o.ignore_error_nr[etype] = i;
282                 td->o.ignore_error[etype] = error;
283         }
284         return 0;
285
286 }
287
288 static int str_ignore_error_cb(void *data, const char *input)
289 {
290         struct thread_data *td = data;
291         char *str, *p, *n;
292         int type = 0, ret = 1;
293         p = str = strdup(input);
294
295         strip_blank_front(&str);
296         strip_blank_end(str);
297
298         while (p) {
299                 n = strchr(p, ',');
300                 if (n)
301                         *n++ = '\0';
302                 ret = ignore_error_type(td, type, p);
303                 if (ret)
304                         break;
305                 p = n;
306                 type++;
307         }
308         free(str);
309         return ret;
310 }
311
312 static int str_rw_cb(void *data, const char *str)
313 {
314         struct thread_data *td = data;
315         char *nr = get_opt_postfix(str);
316
317         td->o.ddir_seq_nr = 1;
318         td->o.ddir_seq_add = 0;
319
320         if (!nr)
321                 return 0;
322
323         if (td_random(td))
324                 td->o.ddir_seq_nr = atoi(nr);
325         else {
326                 long long val;
327
328                 if (str_to_decimal(nr, &val, 1, td)) {
329                         log_err("fio: rw postfix parsing failed\n");
330                         free(nr);
331                         return 1;
332                 }
333
334                 td->o.ddir_seq_add = val;
335         }
336
337         free(nr);
338         return 0;
339 }
340
341 static int str_mem_cb(void *data, const char *mem)
342 {
343         struct thread_data *td = data;
344
345         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
346                 td->mmapfile = get_opt_postfix(mem);
347                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
348                         log_err("fio: mmaphuge:/path/to/file\n");
349                         return 1;
350                 }
351         }
352
353         return 0;
354 }
355
356 static int str_verify_cb(void *data, const char *mem)
357 {
358         struct thread_data *td = data;
359
360         if (td->o.verify == VERIFY_CRC32C_INTEL ||
361             td->o.verify == VERIFY_CRC32C) {
362                 crc32c_intel_probe();
363         }
364
365         return 0;
366 }
367
368 static int fio_clock_source_cb(void *data, const char *str)
369 {
370         struct thread_data *td = data;
371
372         fio_clock_source = td->o.clocksource;
373         fio_time_init();
374         return 0;
375 }
376
377 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
378 {
379         mlock_size = *val;
380         return 0;
381 }
382
383 static int str_rwmix_read_cb(void *data, unsigned long long *val)
384 {
385         struct thread_data *td = data;
386
387         td->o.rwmix[DDIR_READ] = *val;
388         td->o.rwmix[DDIR_WRITE] = 100 - *val;
389         return 0;
390 }
391
392 static int str_rwmix_write_cb(void *data, unsigned long long *val)
393 {
394         struct thread_data *td = data;
395
396         td->o.rwmix[DDIR_WRITE] = *val;
397         td->o.rwmix[DDIR_READ] = 100 - *val;
398         return 0;
399 }
400
401 #ifdef FIO_HAVE_IOPRIO
402 static int str_prioclass_cb(void *data, unsigned long long *val)
403 {
404         struct thread_data *td = data;
405         unsigned short mask;
406
407         /*
408          * mask off old class bits, str_prio_cb() may have set a default class
409          */
410         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
411         td->ioprio &= mask;
412
413         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
414         td->ioprio_set = 1;
415         return 0;
416 }
417
418 static int str_prio_cb(void *data, unsigned long long *val)
419 {
420         struct thread_data *td = data;
421
422         td->ioprio |= *val;
423
424         /*
425          * If no class is set, assume BE
426          */
427         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
428                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
429
430         td->ioprio_set = 1;
431         return 0;
432 }
433 #endif
434
435 static int str_exitall_cb(void)
436 {
437         exitall_on_terminate = 1;
438         return 0;
439 }
440
441 #ifdef FIO_HAVE_CPU_AFFINITY
442 static int str_cpumask_cb(void *data, unsigned long long *val)
443 {
444         struct thread_data *td = data;
445         unsigned int i;
446         long max_cpu;
447         int ret;
448
449         ret = fio_cpuset_init(&td->o.cpumask);
450         if (ret < 0) {
451                 log_err("fio: cpuset_init failed\n");
452                 td_verror(td, ret, "fio_cpuset_init");
453                 return 1;
454         }
455
456         max_cpu = cpus_online();
457
458         for (i = 0; i < sizeof(int) * 8; i++) {
459                 if ((1 << i) & *val) {
460                         if (i > max_cpu) {
461                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
462                                                                 max_cpu);
463                                 return 1;
464                         }
465                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
466                         fio_cpu_set(&td->o.cpumask, i);
467                 }
468         }
469
470         td->o.cpumask_set = 1;
471         return 0;
472 }
473
474 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
475                             const char *input)
476 {
477         char *cpu, *str, *p;
478         long max_cpu;
479         int ret = 0;
480
481         ret = fio_cpuset_init(mask);
482         if (ret < 0) {
483                 log_err("fio: cpuset_init failed\n");
484                 td_verror(td, ret, "fio_cpuset_init");
485                 return 1;
486         }
487
488         p = str = strdup(input);
489
490         strip_blank_front(&str);
491         strip_blank_end(str);
492
493         max_cpu = cpus_online();
494
495         while ((cpu = strsep(&str, ",")) != NULL) {
496                 char *str2, *cpu2;
497                 int icpu, icpu2;
498
499                 if (!strlen(cpu))
500                         break;
501
502                 str2 = cpu;
503                 icpu2 = -1;
504                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
505                         if (!strlen(cpu2))
506                                 break;
507
508                         icpu2 = atoi(cpu2);
509                 }
510
511                 icpu = atoi(cpu);
512                 if (icpu2 == -1)
513                         icpu2 = icpu;
514                 while (icpu <= icpu2) {
515                         if (icpu >= FIO_MAX_CPUS) {
516                                 log_err("fio: your OS only supports up to"
517                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
518                                 ret = 1;
519                                 break;
520                         }
521                         if (icpu > max_cpu) {
522                                 log_err("fio: CPU %d too large (max=%ld)\n",
523                                                         icpu, max_cpu);
524                                 ret = 1;
525                                 break;
526                         }
527
528                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
529                         fio_cpu_set(mask, icpu);
530                         icpu++;
531                 }
532                 if (ret)
533                         break;
534         }
535
536         free(p);
537         if (!ret)
538                 td->o.cpumask_set = 1;
539         return ret;
540 }
541
542 static int str_cpus_allowed_cb(void *data, const char *input)
543 {
544         struct thread_data *td = data;
545         int ret;
546
547         ret = set_cpus_allowed(td, &td->o.cpumask, input);
548         if (!ret)
549                 td->o.cpumask_set = 1;
550
551         return ret;
552 }
553
554 static int str_verify_cpus_allowed_cb(void *data, const char *input)
555 {
556         struct thread_data *td = data;
557         int ret;
558
559         ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
560         if (!ret)
561                 td->o.verify_cpumask_set = 1;
562
563         return ret;
564 }
565 #endif
566
567 #ifdef FIO_HAVE_LIBNUMA
568 static int str_numa_cpunodes_cb(void *data, char *input)
569 {
570         struct thread_data *td = data;
571
572         /* numa_parse_nodestring() parses a character string list
573          * of nodes into a bit mask. The bit mask is allocated by
574          * numa_allocate_nodemask(), so it should be freed by
575          * numa_free_nodemask().
576          */
577         td->o.numa_cpunodesmask = numa_parse_nodestring(input);
578         if (td->o.numa_cpunodesmask == NULL) {
579                 log_err("fio: numa_parse_nodestring failed\n");
580                 td_verror(td, 1, "str_numa_cpunodes_cb");
581                 return 1;
582         }
583
584         td->o.numa_cpumask_set = 1;
585         return 0;
586 }
587
588 static int str_numa_mpol_cb(void *data, char *input)
589 {
590         struct thread_data *td = data;
591         const char * const policy_types[] =
592                 { "default", "prefer", "bind", "interleave", "local" };
593         int i;
594
595         char *nodelist = strchr(input, ':');
596         if (nodelist) {
597                 /* NUL-terminate mode */
598                 *nodelist++ = '\0';
599         }
600
601         for (i = 0; i <= MPOL_LOCAL; i++) {
602                 if (!strcmp(input, policy_types[i])) {
603                         td->o.numa_mem_mode = i;
604                         break;
605                 }
606         }
607         if (i > MPOL_LOCAL) {
608                 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
609                 goto out;
610         }
611
612         switch (td->o.numa_mem_mode) {
613         case MPOL_PREFERRED:
614                 /*
615                  * Insist on a nodelist of one node only
616                  */
617                 if (nodelist) {
618                         char *rest = nodelist;
619                         while (isdigit(*rest))
620                                 rest++;
621                         if (*rest) {
622                                 log_err("fio: one node only for \'prefer\'\n");
623                                 goto out;
624                         }
625                 } else {
626                         log_err("fio: one node is needed for \'prefer\'\n");
627                         goto out;
628                 }
629                 break;
630         case MPOL_INTERLEAVE:
631                 /*
632                  * Default to online nodes with memory if no nodelist
633                  */
634                 if (!nodelist)
635                         nodelist = strdup("all");
636                 break;
637         case MPOL_LOCAL:
638         case MPOL_DEFAULT:
639                 /*
640                  * Don't allow a nodelist
641                  */
642                 if (nodelist) {
643                         log_err("fio: NO nodelist for \'local\'\n");
644                         goto out;
645                 }
646                 break;
647         case MPOL_BIND:
648                 /*
649                  * Insist on a nodelist
650                  */
651                 if (!nodelist) {
652                         log_err("fio: a nodelist is needed for \'bind\'\n");
653                         goto out;
654                 }
655                 break;
656         }
657
658
659         /* numa_parse_nodestring() parses a character string list
660          * of nodes into a bit mask. The bit mask is allocated by
661          * numa_allocate_nodemask(), so it should be freed by
662          * numa_free_nodemask().
663          */
664         switch (td->o.numa_mem_mode) {
665         case MPOL_PREFERRED:
666                 td->o.numa_mem_prefer_node = atoi(nodelist);
667                 break;
668         case MPOL_INTERLEAVE:
669         case MPOL_BIND:
670                 td->o.numa_memnodesmask = numa_parse_nodestring(nodelist);
671                 if (td->o.numa_memnodesmask == NULL) {
672                         log_err("fio: numa_parse_nodestring failed\n");
673                         td_verror(td, 1, "str_numa_memnodes_cb");
674                         return 1;
675                 }
676                 break;
677         case MPOL_LOCAL:
678         case MPOL_DEFAULT:
679         default:
680                 break;
681         }
682
683         td->o.numa_memmask_set = 1;
684         return 0;
685
686 out:
687         return 1;
688 }
689 #endif
690
691 #ifdef FIO_HAVE_TRIM
692 static int str_verify_trim_cb(void *data, unsigned long long *val)
693 {
694         struct thread_data *td = data;
695
696         td->o.trim_percentage = *val;
697         return 0;
698 }
699 #endif
700
701 static int str_fst_cb(void *data, const char *str)
702 {
703         struct thread_data *td = data;
704         char *nr = get_opt_postfix(str);
705
706         td->file_service_nr = 1;
707         if (nr) {
708                 td->file_service_nr = atoi(nr);
709                 free(nr);
710         }
711
712         return 0;
713 }
714
715 #ifdef FIO_HAVE_SYNC_FILE_RANGE
716 static int str_sfr_cb(void *data, const char *str)
717 {
718         struct thread_data *td = data;
719         char *nr = get_opt_postfix(str);
720
721         td->sync_file_range_nr = 1;
722         if (nr) {
723                 td->sync_file_range_nr = atoi(nr);
724                 free(nr);
725         }
726
727         return 0;
728 }
729 #endif
730
731 static int str_random_distribution_cb(void *data, const char *str)
732 {
733         struct thread_data *td = data;
734         double val;
735         char *nr;
736
737         if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
738                 val = 1.1;
739         else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
740                 val = 0.2;
741         else
742                 return 0;
743
744         nr = get_opt_postfix(str);
745         if (nr && !str_to_float(nr, &val)) {
746                 log_err("fio: random postfix parsing failed\n");
747                 free(nr);
748                 return 1;
749         }
750
751         free(nr);
752
753         if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
754                 td->o.zipf_theta = val;
755         else {
756                 if (val <= 0.00 || val >= 1.00) {
757                         log_err("fio: pareto input out of range (0 < input < 1.0)\n");
758                         return 1;
759                 }
760                 td->o.pareto_h = val;
761         }
762
763         return 0;
764 }
765
766 static int check_dir(struct thread_data *td, char *fname)
767 {
768 #if 0
769         char file[PATH_MAX], *dir;
770         int elen = 0;
771
772         if (td->o.directory) {
773                 strcpy(file, td->o.directory);
774                 strcat(file, "/");
775                 elen = strlen(file);
776         }
777
778         sprintf(file + elen, "%s", fname);
779         dir = dirname(file);
780
781         {
782         struct stat sb;
783         /*
784          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
785          * yet, so we can't do this check right here...
786          */
787         if (lstat(dir, &sb) < 0) {
788                 int ret = errno;
789
790                 log_err("fio: %s is not a directory\n", dir);
791                 td_verror(td, ret, "lstat");
792                 return 1;
793         }
794
795         if (!S_ISDIR(sb.st_mode)) {
796                 log_err("fio: %s is not a directory\n", dir);
797                 return 1;
798         }
799         }
800 #endif
801
802         return 0;
803 }
804
805 /*
806  * Return next file in the string. Files are separated with ':'. If the ':'
807  * is escaped with a '\', then that ':' is part of the filename and does not
808  * indicate a new file.
809  */
810 static char *get_next_file_name(char **ptr)
811 {
812         char *str = *ptr;
813         char *p, *start;
814
815         if (!str || !strlen(str))
816                 return NULL;
817
818         start = str;
819         do {
820                 /*
821                  * No colon, we are done
822                  */
823                 p = strchr(str, ':');
824                 if (!p) {
825                         *ptr = NULL;
826                         break;
827                 }
828
829                 /*
830                  * We got a colon, but it's the first character. Skip and
831                  * continue
832                  */
833                 if (p == start) {
834                         str = ++start;
835                         continue;
836                 }
837
838                 if (*(p - 1) != '\\') {
839                         *p = '\0';
840                         *ptr = p + 1;
841                         break;
842                 }
843
844                 memmove(p - 1, p, strlen(p) + 1);
845                 str = p;
846         } while (1);
847
848         return start;
849 }
850
851 static int str_filename_cb(void *data, const char *input)
852 {
853         struct thread_data *td = data;
854         char *fname, *str, *p;
855
856         p = str = strdup(input);
857
858         strip_blank_front(&str);
859         strip_blank_end(str);
860
861         if (!td->files_index)
862                 td->o.nr_files = 0;
863
864         while ((fname = get_next_file_name(&str)) != NULL) {
865                 if (!strlen(fname))
866                         break;
867                 if (check_dir(td, fname)) {
868                         free(p);
869                         return 1;
870                 }
871                 add_file(td, fname);
872                 td->o.nr_files++;
873         }
874
875         free(p);
876         return 0;
877 }
878
879 static int str_directory_cb(void *data, const char fio_unused *str)
880 {
881         struct thread_data *td = data;
882         struct stat sb;
883
884         if (lstat(td->o.directory, &sb) < 0) {
885                 int ret = errno;
886
887                 log_err("fio: %s is not a directory\n", td->o.directory);
888                 td_verror(td, ret, "lstat");
889                 return 1;
890         }
891         if (!S_ISDIR(sb.st_mode)) {
892                 log_err("fio: %s is not a directory\n", td->o.directory);
893                 return 1;
894         }
895
896         return 0;
897 }
898
899 static int str_opendir_cb(void *data, const char fio_unused *str)
900 {
901         struct thread_data *td = data;
902
903         if (!td->files_index)
904                 td->o.nr_files = 0;
905
906         return add_dir_files(td, td->o.opendir);
907 }
908
909 static int str_verify_offset_cb(void *data, unsigned long long *off)
910 {
911         struct thread_data *td = data;
912
913         if (*off && *off < sizeof(struct verify_header)) {
914                 log_err("fio: verify_offset too small\n");
915                 return 1;
916         }
917
918         td->o.verify_offset = *off;
919         return 0;
920 }
921
922 static int str_verify_pattern_cb(void *data, const char *input)
923 {
924         struct thread_data *td = data;
925         long off;
926         int i = 0, j = 0, len, k, base = 10;
927         char* loc1, * loc2;
928
929         loc1 = strstr(input, "0x");
930         loc2 = strstr(input, "0X");
931         if (loc1 || loc2)
932                 base = 16;
933         off = strtol(input, NULL, base);
934         if (off != LONG_MAX || errno != ERANGE) {
935                 while (off) {
936                         td->o.verify_pattern[i] = off & 0xff;
937                         off >>= 8;
938                         i++;
939                 }
940         } else {
941                 len = strlen(input);
942                 k = len - 1;
943                 if (base == 16) {
944                         if (loc1)
945                                 j = loc1 - input + 2;
946                         else
947                                 j = loc2 - input + 2;
948                 } else
949                         return 1;
950                 if (len - j < MAX_PATTERN_SIZE * 2) {
951                         while (k >= j) {
952                                 off = converthexchartoint(input[k--]);
953                                 if (k >= j)
954                                         off += (converthexchartoint(input[k--])
955                                                 * 16);
956                                 td->o.verify_pattern[i++] = (char) off;
957                         }
958                 }
959         }
960
961         /*
962          * Fill the pattern all the way to the end. This greatly reduces
963          * the number of memcpy's we have to do when verifying the IO.
964          */
965         while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
966                 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
967                 i *= 2;
968         }
969         if (i == 1) {
970                 /*
971                  * The code in verify_io_u_pattern assumes a single byte pattern
972                  * fills the whole verify pattern buffer.
973                  */
974                 memset(td->o.verify_pattern, td->o.verify_pattern[0],
975                        MAX_PATTERN_SIZE);
976         }
977
978         td->o.verify_pattern_bytes = i;
979
980         /*
981          * VERIFY_META could already be set
982          */
983         if (td->o.verify == VERIFY_NONE)
984                 td->o.verify = VERIFY_PATTERN;
985
986         return 0;
987 }
988
989 static int str_lockfile_cb(void *data, const char *str)
990 {
991         struct thread_data *td = data;
992         char *nr = get_opt_postfix(str);
993
994         td->o.lockfile_batch = 1;
995         if (nr) {
996                 td->o.lockfile_batch = atoi(nr);
997                 free(nr);
998         }
999
1000         return 0;
1001 }
1002
1003 static int str_write_bw_log_cb(void *data, const char *str)
1004 {
1005         struct thread_data *td = data;
1006
1007         if (str)
1008                 td->o.bw_log_file = strdup(str);
1009
1010         td->o.write_bw_log = 1;
1011         return 0;
1012 }
1013
1014 static int str_write_lat_log_cb(void *data, const char *str)
1015 {
1016         struct thread_data *td = data;
1017
1018         if (str)
1019                 td->o.lat_log_file = strdup(str);
1020
1021         td->o.write_lat_log = 1;
1022         return 0;
1023 }
1024
1025 static int str_write_iops_log_cb(void *data, const char *str)
1026 {
1027         struct thread_data *td = data;
1028
1029         if (str)
1030                 td->o.iops_log_file = strdup(str);
1031
1032         td->o.write_iops_log = 1;
1033         return 0;
1034 }
1035
1036 static int str_gtod_reduce_cb(void *data, int *il)
1037 {
1038         struct thread_data *td = data;
1039         int val = *il;
1040
1041         td->o.disable_lat = !!val;
1042         td->o.disable_clat = !!val;
1043         td->o.disable_slat = !!val;
1044         td->o.disable_bw = !!val;
1045         td->o.clat_percentiles = !val;
1046         if (val)
1047                 td->tv_cache_mask = 63;
1048
1049         return 0;
1050 }
1051
1052 static int str_gtod_cpu_cb(void *data, long long *il)
1053 {
1054         struct thread_data *td = data;
1055         int val = *il;
1056
1057         td->o.gtod_cpu = val;
1058         td->o.gtod_offload = 1;
1059         return 0;
1060 }
1061
1062 static int str_size_cb(void *data, unsigned long long *__val)
1063 {
1064         struct thread_data *td = data;
1065         unsigned long long v = *__val;
1066
1067         if (parse_is_percent(v)) {
1068                 td->o.size = 0;
1069                 td->o.size_percent = -1ULL - v;
1070         } else
1071                 td->o.size = v;
1072
1073         return 0;
1074 }
1075
1076 static int rw_verify(struct fio_option *o, void *data)
1077 {
1078         struct thread_data *td = data;
1079
1080         if (read_only && td_write(td)) {
1081                 log_err("fio: job <%s> has write bit set, but fio is in"
1082                         " read-only mode\n", td->o.name);
1083                 return 1;
1084         }
1085
1086         return 0;
1087 }
1088
1089 static int gtod_cpu_verify(struct fio_option *o, void *data)
1090 {
1091 #ifndef FIO_HAVE_CPU_AFFINITY
1092         struct thread_data *td = data;
1093
1094         if (td->o.gtod_cpu) {
1095                 log_err("fio: platform must support CPU affinity for"
1096                         "gettimeofday() offloading\n");
1097                 return 1;
1098         }
1099 #endif
1100
1101         return 0;
1102 }
1103
1104 static int kb_base_verify(struct fio_option *o, void *data)
1105 {
1106         struct thread_data *td = data;
1107
1108         if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
1109                 log_err("fio: kb_base set to nonsensical value: %u\n",
1110                                 td->o.kb_base);
1111                 return 1;
1112         }
1113
1114         return 0;
1115 }
1116
1117 /*
1118  * Map of job/command line options
1119  */
1120 static struct fio_option options[FIO_MAX_OPTS] = {
1121         {
1122                 .name   = "description",
1123                 .type   = FIO_OPT_STR_STORE,
1124                 .off1   = td_var_offset(description),
1125                 .help   = "Text job description",
1126         },
1127         {
1128                 .name   = "name",
1129                 .type   = FIO_OPT_STR_STORE,
1130                 .off1   = td_var_offset(name),
1131                 .help   = "Name of this job",
1132         },
1133         {
1134                 .name   = "directory",
1135                 .type   = FIO_OPT_STR_STORE,
1136                 .off1   = td_var_offset(directory),
1137                 .cb     = str_directory_cb,
1138                 .help   = "Directory to store files in",
1139         },
1140         {
1141                 .name   = "filename",
1142                 .type   = FIO_OPT_STR_STORE,
1143                 .off1   = td_var_offset(filename),
1144                 .cb     = str_filename_cb,
1145                 .prio   = -1, /* must come after "directory" */
1146                 .help   = "File(s) to use for the workload",
1147         },
1148         {
1149                 .name   = "kb_base",
1150                 .type   = FIO_OPT_INT,
1151                 .off1   = td_var_offset(kb_base),
1152                 .verify = kb_base_verify,
1153                 .prio   = 1,
1154                 .def    = "1024",
1155                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
1156         },
1157         {
1158                 .name   = "lockfile",
1159                 .type   = FIO_OPT_STR,
1160                 .cb     = str_lockfile_cb,
1161                 .off1   = td_var_offset(file_lock_mode),
1162                 .help   = "Lock file when doing IO to it",
1163                 .parent = "filename",
1164                 .def    = "none",
1165                 .posval = {
1166                           { .ival = "none",
1167                             .oval = FILE_LOCK_NONE,
1168                             .help = "No file locking",
1169                           },
1170                           { .ival = "exclusive",
1171                             .oval = FILE_LOCK_EXCLUSIVE,
1172                             .help = "Exclusive file lock",
1173                           },
1174                           {
1175                             .ival = "readwrite",
1176                             .oval = FILE_LOCK_READWRITE,
1177                             .help = "Read vs write lock",
1178                           },
1179                 },
1180         },
1181         {
1182                 .name   = "opendir",
1183                 .type   = FIO_OPT_STR_STORE,
1184                 .off1   = td_var_offset(opendir),
1185                 .cb     = str_opendir_cb,
1186                 .help   = "Recursively add files from this directory and down",
1187         },
1188         {
1189                 .name   = "rw",
1190                 .alias  = "readwrite",
1191                 .type   = FIO_OPT_STR,
1192                 .cb     = str_rw_cb,
1193                 .off1   = td_var_offset(td_ddir),
1194                 .help   = "IO direction",
1195                 .def    = "read",
1196                 .verify = rw_verify,
1197                 .posval = {
1198                           { .ival = "read",
1199                             .oval = TD_DDIR_READ,
1200                             .help = "Sequential read",
1201                           },
1202                           { .ival = "write",
1203                             .oval = TD_DDIR_WRITE,
1204                             .help = "Sequential write",
1205                           },
1206                           { .ival = "trim",
1207                             .oval = TD_DDIR_TRIM,
1208                             .help = "Sequential trim",
1209                           },
1210                           { .ival = "randread",
1211                             .oval = TD_DDIR_RANDREAD,
1212                             .help = "Random read",
1213                           },
1214                           { .ival = "randwrite",
1215                             .oval = TD_DDIR_RANDWRITE,
1216                             .help = "Random write",
1217                           },
1218                           { .ival = "randtrim",
1219                             .oval = TD_DDIR_RANDTRIM,
1220                             .help = "Random trim",
1221                           },
1222                           { .ival = "rw",
1223                             .oval = TD_DDIR_RW,
1224                             .help = "Sequential read and write mix",
1225                           },
1226                           { .ival = "readwrite",
1227                             .oval = TD_DDIR_RW,
1228                             .help = "Sequential read and write mix",
1229                           },
1230                           { .ival = "randrw",
1231                             .oval = TD_DDIR_RANDRW,
1232                             .help = "Random read and write mix"
1233                           },
1234                 },
1235         },
1236         {
1237                 .name   = "rw_sequencer",
1238                 .type   = FIO_OPT_STR,
1239                 .off1   = td_var_offset(rw_seq),
1240                 .help   = "IO offset generator modifier",
1241                 .def    = "sequential",
1242                 .posval = {
1243                           { .ival = "sequential",
1244                             .oval = RW_SEQ_SEQ,
1245                             .help = "Generate sequential offsets",
1246                           },
1247                           { .ival = "identical",
1248                             .oval = RW_SEQ_IDENT,
1249                             .help = "Generate identical offsets",
1250                           },
1251                 },
1252         },
1253
1254         {
1255                 .name   = "ioengine",
1256                 .type   = FIO_OPT_STR_STORE,
1257                 .off1   = td_var_offset(ioengine),
1258                 .help   = "IO engine to use",
1259                 .def    = FIO_PREFERRED_ENGINE,
1260                 .posval = {
1261                           { .ival = "sync",
1262                             .help = "Use read/write",
1263                           },
1264                           { .ival = "psync",
1265                             .help = "Use pread/pwrite",
1266                           },
1267                           { .ival = "vsync",
1268                             .help = "Use readv/writev",
1269                           },
1270 #ifdef FIO_HAVE_LIBAIO
1271                           { .ival = "libaio",
1272                             .help = "Linux native asynchronous IO",
1273                           },
1274 #endif
1275 #ifdef FIO_HAVE_POSIXAIO
1276                           { .ival = "posixaio",
1277                             .help = "POSIX asynchronous IO",
1278                           },
1279 #endif
1280 #ifdef FIO_HAVE_SOLARISAIO
1281                           { .ival = "solarisaio",
1282                             .help = "Solaris native asynchronous IO",
1283                           },
1284 #endif
1285 #ifdef FIO_HAVE_WINDOWSAIO
1286                           { .ival = "windowsaio",
1287                             .help = "Windows native asynchronous IO"
1288                           },
1289 #endif
1290                           { .ival = "mmap",
1291                             .help = "Memory mapped IO"
1292                           },
1293 #ifdef FIO_HAVE_SPLICE
1294                           { .ival = "splice",
1295                             .help = "splice/vmsplice based IO",
1296                           },
1297                           { .ival = "netsplice",
1298                             .help = "splice/vmsplice to/from the network",
1299                           },
1300 #endif
1301 #ifdef FIO_HAVE_SGIO
1302                           { .ival = "sg",
1303                             .help = "SCSI generic v3 IO",
1304                           },
1305 #endif
1306                           { .ival = "null",
1307                             .help = "Testing engine (no data transfer)",
1308                           },
1309                           { .ival = "net",
1310                             .help = "Network IO",
1311                           },
1312 #ifdef FIO_HAVE_SYSLET
1313                           { .ival = "syslet-rw",
1314                             .help = "syslet enabled async pread/pwrite IO",
1315                           },
1316 #endif
1317                           { .ival = "cpuio",
1318                             .help = "CPU cycle burner engine",
1319                           },
1320 #ifdef FIO_HAVE_GUASI
1321                           { .ival = "guasi",
1322                             .help = "GUASI IO engine",
1323                           },
1324 #endif
1325 #ifdef FIO_HAVE_BINJECT
1326                           { .ival = "binject",
1327                             .help = "binject direct inject block engine",
1328                           },
1329 #endif
1330 #ifdef FIO_HAVE_RDMA
1331                           { .ival = "rdma",
1332                             .help = "RDMA IO engine",
1333                           },
1334 #endif
1335 #ifdef FIO_HAVE_FUSION_AW
1336                           { .ival = "fusion-aw-sync",
1337                             .help = "Fusion-io atomic write engine",
1338                           },
1339 #endif
1340 #ifdef FIO_HAVE_E4_ENG
1341                           { .ival = "e4defrag",
1342                             .help = "ext4 defrag engine",
1343                           },
1344 #endif
1345 #ifdef FIO_HAVE_FALLOC_ENG
1346                           { .ival = "falloc",
1347                             .help = "fallocate() file based engine",
1348                           },
1349 #endif
1350                           { .ival = "external",
1351                             .help = "Load external engine (append name)",
1352                           },
1353                 },
1354         },
1355         {
1356                 .name   = "iodepth",
1357                 .type   = FIO_OPT_INT,
1358                 .off1   = td_var_offset(iodepth),
1359                 .help   = "Number of IO buffers to keep in flight",
1360                 .minval = 1,
1361                 .def    = "1",
1362         },
1363         {
1364                 .name   = "iodepth_batch",
1365                 .alias  = "iodepth_batch_submit",
1366                 .type   = FIO_OPT_INT,
1367                 .off1   = td_var_offset(iodepth_batch),
1368                 .help   = "Number of IO buffers to submit in one go",
1369                 .parent = "iodepth",
1370                 .minval = 1,
1371                 .def    = "1",
1372         },
1373         {
1374                 .name   = "iodepth_batch_complete",
1375                 .type   = FIO_OPT_INT,
1376                 .off1   = td_var_offset(iodepth_batch_complete),
1377                 .help   = "Number of IO buffers to retrieve in one go",
1378                 .parent = "iodepth",
1379                 .minval = 0,
1380                 .def    = "1",
1381         },
1382         {
1383                 .name   = "iodepth_low",
1384                 .type   = FIO_OPT_INT,
1385                 .off1   = td_var_offset(iodepth_low),
1386                 .help   = "Low water mark for queuing depth",
1387                 .parent = "iodepth",
1388         },
1389         {
1390                 .name   = "size",
1391                 .type   = FIO_OPT_STR_VAL,
1392                 .cb     = str_size_cb,
1393                 .help   = "Total size of device or files",
1394         },
1395         {
1396                 .name   = "fill_device",
1397                 .alias  = "fill_fs",
1398                 .type   = FIO_OPT_BOOL,
1399                 .off1   = td_var_offset(fill_device),
1400                 .help   = "Write until an ENOSPC error occurs",
1401                 .def    = "0",
1402         },
1403         {
1404                 .name   = "filesize",
1405                 .type   = FIO_OPT_STR_VAL,
1406                 .off1   = td_var_offset(file_size_low),
1407                 .off2   = td_var_offset(file_size_high),
1408                 .minval = 1,
1409                 .help   = "Size of individual files",
1410         },
1411         {
1412                 .name   = "offset",
1413                 .alias  = "fileoffset",
1414                 .type   = FIO_OPT_STR_VAL,
1415                 .off1   = td_var_offset(start_offset),
1416                 .help   = "Start IO from this offset",
1417                 .def    = "0",
1418         },
1419         {
1420                 .name   = "offset_increment",
1421                 .type   = FIO_OPT_STR_VAL,
1422                 .off1   = td_var_offset(offset_increment),
1423                 .help   = "What is the increment from one offset to the next",
1424                 .parent = "offset",
1425                 .def    = "0",
1426         },
1427         {
1428                 .name   = "bs",
1429                 .alias  = "blocksize",
1430                 .type   = FIO_OPT_INT,
1431                 .off1   = td_var_offset(bs[DDIR_READ]),
1432                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1433                 .off3   = td_var_offset(bs[DDIR_TRIM]),
1434                 .minval = 1,
1435                 .help   = "Block size unit",
1436                 .def    = "4k",
1437                 .parent = "rw",
1438         },
1439         {
1440                 .name   = "ba",
1441                 .alias  = "blockalign",
1442                 .type   = FIO_OPT_INT,
1443                 .off1   = td_var_offset(ba[DDIR_READ]),
1444                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1445                 .off3   = td_var_offset(ba[DDIR_TRIM]),
1446                 .minval = 1,
1447                 .help   = "IO block offset alignment",
1448                 .parent = "rw",
1449         },
1450         {
1451                 .name   = "bsrange",
1452                 .alias  = "blocksize_range",
1453                 .type   = FIO_OPT_RANGE,
1454                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1455                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1456                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1457                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1458                 .off5   = td_var_offset(min_bs[DDIR_TRIM]),
1459                 .off6   = td_var_offset(max_bs[DDIR_TRIM]),
1460                 .minval = 1,
1461                 .help   = "Set block size range (in more detail than bs)",
1462                 .parent = "rw",
1463         },
1464         {
1465                 .name   = "bssplit",
1466                 .type   = FIO_OPT_STR,
1467                 .cb     = str_bssplit_cb,
1468                 .help   = "Set a specific mix of block sizes",
1469                 .parent = "rw",
1470         },
1471         {
1472                 .name   = "bs_unaligned",
1473                 .alias  = "blocksize_unaligned",
1474                 .type   = FIO_OPT_STR_SET,
1475                 .off1   = td_var_offset(bs_unaligned),
1476                 .help   = "Don't sector align IO buffer sizes",
1477                 .parent = "rw",
1478         },
1479         {
1480                 .name   = "randrepeat",
1481                 .type   = FIO_OPT_BOOL,
1482                 .off1   = td_var_offset(rand_repeatable),
1483                 .help   = "Use repeatable random IO pattern",
1484                 .def    = "1",
1485                 .parent = "rw",
1486         },
1487         {
1488                 .name   = "use_os_rand",
1489                 .type   = FIO_OPT_BOOL,
1490                 .off1   = td_var_offset(use_os_rand),
1491                 .help   = "Set to use OS random generator",
1492                 .def    = "0",
1493                 .parent = "rw",
1494         },
1495         {
1496                 .name   = "norandommap",
1497                 .type   = FIO_OPT_STR_SET,
1498                 .off1   = td_var_offset(norandommap),
1499                 .help   = "Accept potential duplicate random blocks",
1500                 .parent = "rw",
1501         },
1502         {
1503                 .name   = "softrandommap",
1504                 .type   = FIO_OPT_BOOL,
1505                 .off1   = td_var_offset(softrandommap),
1506                 .help   = "Set norandommap if randommap allocation fails",
1507                 .parent = "norandommap",
1508                 .def    = "0",
1509         },
1510         {
1511                 .name   = "random_distribution",
1512                 .type   = FIO_OPT_STR,
1513                 .off1   = td_var_offset(random_distribution),
1514                 .cb     = str_random_distribution_cb,
1515                 .help   = "Random offset distribution generator",
1516                 .def    = "random",
1517                 .posval = {
1518                           { .ival = "random",
1519                             .oval = FIO_RAND_DIST_RANDOM,
1520                             .help = "Completely random",
1521                           },
1522                           { .ival = "zipf",
1523                             .oval = FIO_RAND_DIST_ZIPF,
1524                             .help = "Zipf distribution",
1525                           },
1526                           { .ival = "pareto",
1527                             .oval = FIO_RAND_DIST_PARETO,
1528                             .help = "Pareto distribution",
1529                           },
1530                 },
1531         },
1532         {
1533                 .name   = "nrfiles",
1534                 .alias  = "nr_files",
1535                 .type   = FIO_OPT_INT,
1536                 .off1   = td_var_offset(nr_files),
1537                 .help   = "Split job workload between this number of files",
1538                 .def    = "1",
1539         },
1540         {
1541                 .name   = "openfiles",
1542                 .type   = FIO_OPT_INT,
1543                 .off1   = td_var_offset(open_files),
1544                 .help   = "Number of files to keep open at the same time",
1545         },
1546         {
1547                 .name   = "file_service_type",
1548                 .type   = FIO_OPT_STR,
1549                 .cb     = str_fst_cb,
1550                 .off1   = td_var_offset(file_service_type),
1551                 .help   = "How to select which file to service next",
1552                 .def    = "roundrobin",
1553                 .posval = {
1554                           { .ival = "random",
1555                             .oval = FIO_FSERVICE_RANDOM,
1556                             .help = "Choose a file at random",
1557                           },
1558                           { .ival = "roundrobin",
1559                             .oval = FIO_FSERVICE_RR,
1560                             .help = "Round robin select files",
1561                           },
1562                           { .ival = "sequential",
1563                             .oval = FIO_FSERVICE_SEQ,
1564                             .help = "Finish one file before moving to the next",
1565                           },
1566                 },
1567                 .parent = "nrfiles",
1568         },
1569 #ifdef FIO_HAVE_FALLOCATE
1570         {
1571                 .name   = "fallocate",
1572                 .type   = FIO_OPT_STR,
1573                 .off1   = td_var_offset(fallocate_mode),
1574                 .help   = "Whether pre-allocation is performed when laying out files",
1575                 .def    = "posix",
1576                 .posval = {
1577                           { .ival = "none",
1578                             .oval = FIO_FALLOCATE_NONE,
1579                             .help = "Do not pre-allocate space",
1580                           },
1581                           { .ival = "posix",
1582                             .oval = FIO_FALLOCATE_POSIX,
1583                             .help = "Use posix_fallocate()",
1584                           },
1585 #ifdef FIO_HAVE_LINUX_FALLOCATE
1586                           { .ival = "keep",
1587                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1588                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1589                           },
1590 #endif
1591                           /* Compatibility with former boolean values */
1592                           { .ival = "0",
1593                             .oval = FIO_FALLOCATE_NONE,
1594                             .help = "Alias for 'none'",
1595                           },
1596                           { .ival = "1",
1597                             .oval = FIO_FALLOCATE_POSIX,
1598                             .help = "Alias for 'posix'",
1599                           },
1600                 },
1601         },
1602 #endif  /* FIO_HAVE_FALLOCATE */
1603         {
1604                 .name   = "fadvise_hint",
1605                 .type   = FIO_OPT_BOOL,
1606                 .off1   = td_var_offset(fadvise_hint),
1607                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1608                 .def    = "1",
1609         },
1610         {
1611                 .name   = "fsync",
1612                 .type   = FIO_OPT_INT,
1613                 .off1   = td_var_offset(fsync_blocks),
1614                 .help   = "Issue fsync for writes every given number of blocks",
1615                 .def    = "0",
1616         },
1617         {
1618                 .name   = "fdatasync",
1619                 .type   = FIO_OPT_INT,
1620                 .off1   = td_var_offset(fdatasync_blocks),
1621                 .help   = "Issue fdatasync for writes every given number of blocks",
1622                 .def    = "0",
1623         },
1624         {
1625                 .name   = "write_barrier",
1626                 .type   = FIO_OPT_INT,
1627                 .off1   = td_var_offset(barrier_blocks),
1628                 .help   = "Make every Nth write a barrier write",
1629                 .def    = "0",
1630         },
1631 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1632         {
1633                 .name   = "sync_file_range",
1634                 .posval = {
1635                           { .ival = "wait_before",
1636                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1637                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1638                             .or   = 1,
1639                           },
1640                           { .ival = "write",
1641                             .oval = SYNC_FILE_RANGE_WRITE,
1642                             .help = "SYNC_FILE_RANGE_WRITE",
1643                             .or   = 1,
1644                           },
1645                           {
1646                             .ival = "wait_after",
1647                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1648                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1649                             .or   = 1,
1650                           },
1651                 },
1652                 .type   = FIO_OPT_STR_MULTI,
1653                 .cb     = str_sfr_cb,
1654                 .off1   = td_var_offset(sync_file_range),
1655                 .help   = "Use sync_file_range()",
1656         },
1657 #endif
1658         {
1659                 .name   = "direct",
1660                 .type   = FIO_OPT_BOOL,
1661                 .off1   = td_var_offset(odirect),
1662                 .help   = "Use O_DIRECT IO (negates buffered)",
1663                 .def    = "0",
1664         },
1665         {
1666                 .name   = "buffered",
1667                 .type   = FIO_OPT_BOOL,
1668                 .off1   = td_var_offset(odirect),
1669                 .neg    = 1,
1670                 .help   = "Use buffered IO (negates direct)",
1671                 .def    = "1",
1672         },
1673         {
1674                 .name   = "overwrite",
1675                 .type   = FIO_OPT_BOOL,
1676                 .off1   = td_var_offset(overwrite),
1677                 .help   = "When writing, set whether to overwrite current data",
1678                 .def    = "0",
1679         },
1680         {
1681                 .name   = "loops",
1682                 .type   = FIO_OPT_INT,
1683                 .off1   = td_var_offset(loops),
1684                 .help   = "Number of times to run the job",
1685                 .def    = "1",
1686         },
1687         {
1688                 .name   = "numjobs",
1689                 .type   = FIO_OPT_INT,
1690                 .off1   = td_var_offset(numjobs),
1691                 .help   = "Duplicate this job this many times",
1692                 .def    = "1",
1693         },
1694         {
1695                 .name   = "startdelay",
1696                 .type   = FIO_OPT_STR_VAL_TIME,
1697                 .off1   = td_var_offset(start_delay),
1698                 .help   = "Only start job when this period has passed",
1699                 .def    = "0",
1700         },
1701         {
1702                 .name   = "runtime",
1703                 .alias  = "timeout",
1704                 .type   = FIO_OPT_STR_VAL_TIME,
1705                 .off1   = td_var_offset(timeout),
1706                 .help   = "Stop workload when this amount of time has passed",
1707                 .def    = "0",
1708         },
1709         {
1710                 .name   = "time_based",
1711                 .type   = FIO_OPT_STR_SET,
1712                 .off1   = td_var_offset(time_based),
1713                 .help   = "Keep running until runtime/timeout is met",
1714         },
1715         {
1716                 .name   = "ramp_time",
1717                 .type   = FIO_OPT_STR_VAL_TIME,
1718                 .off1   = td_var_offset(ramp_time),
1719                 .help   = "Ramp up time before measuring performance",
1720         },
1721         {
1722                 .name   = "clocksource",
1723                 .type   = FIO_OPT_STR,
1724                 .cb     = fio_clock_source_cb,
1725                 .off1   = td_var_offset(clocksource),
1726                 .help   = "What type of timing source to use",
1727                 .posval = {
1728                           { .ival = "gettimeofday",
1729                             .oval = CS_GTOD,
1730                             .help = "Use gettimeofday(2) for timing",
1731                           },
1732                           { .ival = "clock_gettime",
1733                             .oval = CS_CGETTIME,
1734                             .help = "Use clock_gettime(2) for timing",
1735                           },
1736 #ifdef ARCH_HAVE_CPU_CLOCK
1737                           { .ival = "cpu",
1738                             .oval = CS_CPUCLOCK,
1739                             .help = "Use CPU private clock",
1740                           },
1741 #endif
1742                 },
1743         },
1744         {
1745                 .name   = "mem",
1746                 .alias  = "iomem",
1747                 .type   = FIO_OPT_STR,
1748                 .cb     = str_mem_cb,
1749                 .off1   = td_var_offset(mem_type),
1750                 .help   = "Backing type for IO buffers",
1751                 .def    = "malloc",
1752                 .posval = {
1753                           { .ival = "malloc",
1754                             .oval = MEM_MALLOC,
1755                             .help = "Use malloc(3) for IO buffers",
1756                           },
1757                           { .ival = "shm",
1758                             .oval = MEM_SHM,
1759                             .help = "Use shared memory segments for IO buffers",
1760                           },
1761 #ifdef FIO_HAVE_HUGETLB
1762                           { .ival = "shmhuge",
1763                             .oval = MEM_SHMHUGE,
1764                             .help = "Like shm, but use huge pages",
1765                           },
1766 #endif
1767                           { .ival = "mmap",
1768                             .oval = MEM_MMAP,
1769                             .help = "Use mmap(2) (file or anon) for IO buffers",
1770                           },
1771 #ifdef FIO_HAVE_HUGETLB
1772                           { .ival = "mmaphuge",
1773                             .oval = MEM_MMAPHUGE,
1774                             .help = "Like mmap, but use huge pages",
1775                           },
1776 #endif
1777                   },
1778         },
1779         {
1780                 .name   = "iomem_align",
1781                 .alias  = "mem_align",
1782                 .type   = FIO_OPT_INT,
1783                 .off1   = td_var_offset(mem_align),
1784                 .minval = 0,
1785                 .help   = "IO memory buffer offset alignment",
1786                 .def    = "0",
1787                 .parent = "iomem",
1788         },
1789         {
1790                 .name   = "verify",
1791                 .type   = FIO_OPT_STR,
1792                 .off1   = td_var_offset(verify),
1793                 .help   = "Verify data written",
1794                 .cb     = str_verify_cb,
1795                 .def    = "0",
1796                 .posval = {
1797                           { .ival = "0",
1798                             .oval = VERIFY_NONE,
1799                             .help = "Don't do IO verification",
1800                           },
1801                           { .ival = "md5",
1802                             .oval = VERIFY_MD5,
1803                             .help = "Use md5 checksums for verification",
1804                           },
1805                           { .ival = "crc64",
1806                             .oval = VERIFY_CRC64,
1807                             .help = "Use crc64 checksums for verification",
1808                           },
1809                           { .ival = "crc32",
1810                             .oval = VERIFY_CRC32,
1811                             .help = "Use crc32 checksums for verification",
1812                           },
1813                           { .ival = "crc32c-intel",
1814                             .oval = VERIFY_CRC32C,
1815                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1816                           },
1817                           { .ival = "crc32c",
1818                             .oval = VERIFY_CRC32C,
1819                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1820                           },
1821                           { .ival = "crc16",
1822                             .oval = VERIFY_CRC16,
1823                             .help = "Use crc16 checksums for verification",
1824                           },
1825                           { .ival = "crc7",
1826                             .oval = VERIFY_CRC7,
1827                             .help = "Use crc7 checksums for verification",
1828                           },
1829                           { .ival = "sha1",
1830                             .oval = VERIFY_SHA1,
1831                             .help = "Use sha1 checksums for verification",
1832                           },
1833                           { .ival = "sha256",
1834                             .oval = VERIFY_SHA256,
1835                             .help = "Use sha256 checksums for verification",
1836                           },
1837                           { .ival = "sha512",
1838                             .oval = VERIFY_SHA512,
1839                             .help = "Use sha512 checksums for verification",
1840                           },
1841                           { .ival = "meta",
1842                             .oval = VERIFY_META,
1843                             .help = "Use io information",
1844                           },
1845                           {
1846                             .ival = "null",
1847                             .oval = VERIFY_NULL,
1848                             .help = "Pretend to verify",
1849                           },
1850                 },
1851         },
1852         {
1853                 .name   = "do_verify",
1854                 .type   = FIO_OPT_BOOL,
1855                 .off1   = td_var_offset(do_verify),
1856                 .help   = "Run verification stage after write",
1857                 .def    = "1",
1858                 .parent = "verify",
1859         },
1860         {
1861                 .name   = "verifysort",
1862                 .type   = FIO_OPT_BOOL,
1863                 .off1   = td_var_offset(verifysort),
1864                 .help   = "Sort written verify blocks for read back",
1865                 .def    = "1",
1866                 .parent = "verify",
1867         },
1868         {
1869                 .name   = "verify_interval",
1870                 .type   = FIO_OPT_INT,
1871                 .off1   = td_var_offset(verify_interval),
1872                 .minval = 2 * sizeof(struct verify_header),
1873                 .help   = "Store verify buffer header every N bytes",
1874                 .parent = "verify",
1875         },
1876         {
1877                 .name   = "verify_offset",
1878                 .type   = FIO_OPT_INT,
1879                 .help   = "Offset verify header location by N bytes",
1880                 .def    = "0",
1881                 .cb     = str_verify_offset_cb,
1882                 .parent = "verify",
1883         },
1884         {
1885                 .name   = "verify_pattern",
1886                 .type   = FIO_OPT_STR,
1887                 .cb     = str_verify_pattern_cb,
1888                 .help   = "Fill pattern for IO buffers",
1889                 .parent = "verify",
1890         },
1891         {
1892                 .name   = "verify_fatal",
1893                 .type   = FIO_OPT_BOOL,
1894                 .off1   = td_var_offset(verify_fatal),
1895                 .def    = "0",
1896                 .help   = "Exit on a single verify failure, don't continue",
1897                 .parent = "verify",
1898         },
1899         {
1900                 .name   = "verify_dump",
1901                 .type   = FIO_OPT_BOOL,
1902                 .off1   = td_var_offset(verify_dump),
1903                 .def    = "0",
1904                 .help   = "Dump contents of good and bad blocks on failure",
1905                 .parent = "verify",
1906         },
1907         {
1908                 .name   = "verify_async",
1909                 .type   = FIO_OPT_INT,
1910                 .off1   = td_var_offset(verify_async),
1911                 .def    = "0",
1912                 .help   = "Number of async verifier threads to use",
1913                 .parent = "verify",
1914         },
1915         {
1916                 .name   = "verify_backlog",
1917                 .type   = FIO_OPT_STR_VAL,
1918                 .off1   = td_var_offset(verify_backlog),
1919                 .help   = "Verify after this number of blocks are written",
1920                 .parent = "verify",
1921         },
1922         {
1923                 .name   = "verify_backlog_batch",
1924                 .type   = FIO_OPT_INT,
1925                 .off1   = td_var_offset(verify_batch),
1926                 .help   = "Verify this number of IO blocks",
1927                 .parent = "verify",
1928         },
1929 #ifdef FIO_HAVE_CPU_AFFINITY
1930         {
1931                 .name   = "verify_async_cpus",
1932                 .type   = FIO_OPT_STR,
1933                 .cb     = str_verify_cpus_allowed_cb,
1934                 .help   = "Set CPUs allowed for async verify threads",
1935                 .parent = "verify_async",
1936         },
1937 #endif
1938 #ifdef FIO_HAVE_TRIM
1939         {
1940                 .name   = "trim_percentage",
1941                 .type   = FIO_OPT_INT,
1942                 .cb     = str_verify_trim_cb,
1943                 .maxval = 100,
1944                 .help   = "Number of verify blocks to discard/trim",
1945                 .parent = "verify",
1946                 .def    = "0",
1947         },
1948         {
1949                 .name   = "trim_verify_zero",
1950                 .type   = FIO_OPT_INT,
1951                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
1952                 .off1   = td_var_offset(trim_zero),
1953                 .parent = "trim_percentage",
1954                 .def    = "1",
1955         },
1956         {
1957                 .name   = "trim_backlog",
1958                 .type   = FIO_OPT_STR_VAL,
1959                 .off1   = td_var_offset(trim_backlog),
1960                 .help   = "Trim after this number of blocks are written",
1961                 .parent = "trim_percentage",
1962         },
1963         {
1964                 .name   = "trim_backlog_batch",
1965                 .type   = FIO_OPT_INT,
1966                 .off1   = td_var_offset(trim_batch),
1967                 .help   = "Trim this number of IO blocks",
1968                 .parent = "trim_percentage",
1969         },
1970 #endif
1971         {
1972                 .name   = "write_iolog",
1973                 .type   = FIO_OPT_STR_STORE,
1974                 .off1   = td_var_offset(write_iolog_file),
1975                 .help   = "Store IO pattern to file",
1976         },
1977         {
1978                 .name   = "read_iolog",
1979                 .type   = FIO_OPT_STR_STORE,
1980                 .off1   = td_var_offset(read_iolog_file),
1981                 .help   = "Playback IO pattern from file",
1982         },
1983         {
1984                 .name   = "replay_no_stall",
1985                 .type   = FIO_OPT_INT,
1986                 .off1   = td_var_offset(no_stall),
1987                 .def    = "0",
1988                 .parent = "read_iolog",
1989                 .help   = "Playback IO pattern file as fast as possible without stalls",
1990         },
1991         {
1992                 .name   = "replay_redirect",
1993                 .type   = FIO_OPT_STR_STORE,
1994                 .off1   = td_var_offset(replay_redirect),
1995                 .parent = "read_iolog",
1996                 .help   = "Replay all I/O onto this device, regardless of trace device",
1997         },
1998         {
1999                 .name   = "exec_prerun",
2000                 .type   = FIO_OPT_STR_STORE,
2001                 .off1   = td_var_offset(exec_prerun),
2002                 .help   = "Execute this file prior to running job",
2003         },
2004         {
2005                 .name   = "exec_postrun",
2006                 .type   = FIO_OPT_STR_STORE,
2007                 .off1   = td_var_offset(exec_postrun),
2008                 .help   = "Execute this file after running job",
2009         },
2010 #ifdef FIO_HAVE_IOSCHED_SWITCH
2011         {
2012                 .name   = "ioscheduler",
2013                 .type   = FIO_OPT_STR_STORE,
2014                 .off1   = td_var_offset(ioscheduler),
2015                 .help   = "Use this IO scheduler on the backing device",
2016         },
2017 #endif
2018         {
2019                 .name   = "zonesize",
2020                 .type   = FIO_OPT_STR_VAL,
2021                 .off1   = td_var_offset(zone_size),
2022                 .help   = "Amount of data to read per zone",
2023                 .def    = "0",
2024         },
2025         {
2026                 .name   = "zonerange",
2027                 .type   = FIO_OPT_STR_VAL,
2028                 .off1   = td_var_offset(zone_range),
2029                 .help   = "Give size of an IO zone",
2030                 .def    = "0",
2031         },
2032         {
2033                 .name   = "zoneskip",
2034                 .type   = FIO_OPT_STR_VAL,
2035                 .off1   = td_var_offset(zone_skip),
2036                 .help   = "Space between IO zones",
2037                 .def    = "0",
2038         },
2039         {
2040                 .name   = "lockmem",
2041                 .type   = FIO_OPT_STR_VAL,
2042                 .cb     = str_lockmem_cb,
2043                 .help   = "Lock down this amount of memory",
2044                 .def    = "0",
2045         },
2046         {
2047                 .name   = "rwmixread",
2048                 .type   = FIO_OPT_INT,
2049                 .cb     = str_rwmix_read_cb,
2050                 .maxval = 100,
2051                 .help   = "Percentage of mixed workload that is reads",
2052                 .def    = "50",
2053         },
2054         {
2055                 .name   = "rwmixwrite",
2056                 .type   = FIO_OPT_INT,
2057                 .cb     = str_rwmix_write_cb,
2058                 .maxval = 100,
2059                 .help   = "Percentage of mixed workload that is writes",
2060                 .def    = "50",
2061         },
2062         {
2063                 .name   = "rwmixcycle",
2064                 .type   = FIO_OPT_DEPRECATED,
2065         },
2066         {
2067                 .name   = "nice",
2068                 .type   = FIO_OPT_INT,
2069                 .off1   = td_var_offset(nice),
2070                 .help   = "Set job CPU nice value",
2071                 .minval = -19,
2072                 .maxval = 20,
2073                 .def    = "0",
2074         },
2075 #ifdef FIO_HAVE_IOPRIO
2076         {
2077                 .name   = "prio",
2078                 .type   = FIO_OPT_INT,
2079                 .cb     = str_prio_cb,
2080                 .help   = "Set job IO priority value",
2081                 .minval = 0,
2082                 .maxval = 7,
2083         },
2084         {
2085                 .name   = "prioclass",
2086                 .type   = FIO_OPT_INT,
2087                 .cb     = str_prioclass_cb,
2088                 .help   = "Set job IO priority class",
2089                 .minval = 0,
2090                 .maxval = 3,
2091         },
2092 #endif
2093         {
2094                 .name   = "thinktime",
2095                 .type   = FIO_OPT_INT,
2096                 .off1   = td_var_offset(thinktime),
2097                 .help   = "Idle time between IO buffers (usec)",
2098                 .def    = "0",
2099         },
2100         {
2101                 .name   = "thinktime_spin",
2102                 .type   = FIO_OPT_INT,
2103                 .off1   = td_var_offset(thinktime_spin),
2104                 .help   = "Start think time by spinning this amount (usec)",
2105                 .def    = "0",
2106                 .parent = "thinktime",
2107         },
2108         {
2109                 .name   = "thinktime_blocks",
2110                 .type   = FIO_OPT_INT,
2111                 .off1   = td_var_offset(thinktime_blocks),
2112                 .help   = "IO buffer period between 'thinktime'",
2113                 .def    = "1",
2114                 .parent = "thinktime",
2115         },
2116         {
2117                 .name   = "rate",
2118                 .type   = FIO_OPT_INT,
2119                 .off1   = td_var_offset(rate[DDIR_READ]),
2120                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2121                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2122                 .help   = "Set bandwidth rate",
2123         },
2124         {
2125                 .name   = "ratemin",
2126                 .type   = FIO_OPT_INT,
2127                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2128                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2129                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2130                 .help   = "Job must meet this rate or it will be shutdown",
2131                 .parent = "rate",
2132         },
2133         {
2134                 .name   = "rate_iops",
2135                 .type   = FIO_OPT_INT,
2136                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2137                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2138                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2139                 .help   = "Limit IO used to this number of IO operations/sec",
2140         },
2141         {
2142                 .name   = "rate_iops_min",
2143                 .type   = FIO_OPT_INT,
2144                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2145                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2146                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2147                 .help   = "Job must meet this rate or it will be shut down",
2148                 .parent = "rate_iops",
2149         },
2150         {
2151                 .name   = "ratecycle",
2152                 .type   = FIO_OPT_INT,
2153                 .off1   = td_var_offset(ratecycle),
2154                 .help   = "Window average for rate limits (msec)",
2155                 .def    = "1000",
2156                 .parent = "rate",
2157         },
2158         {
2159                 .name   = "max_latency",
2160                 .type   = FIO_OPT_INT,
2161                 .off1   = td_var_offset(max_latency),
2162                 .help   = "Maximum tolerated IO latency (usec)",
2163         },
2164         {
2165                 .name   = "invalidate",
2166                 .type   = FIO_OPT_BOOL,
2167                 .off1   = td_var_offset(invalidate_cache),
2168                 .help   = "Invalidate buffer/page cache prior to running job",
2169                 .def    = "1",
2170         },
2171         {
2172                 .name   = "sync",
2173                 .type   = FIO_OPT_BOOL,
2174                 .off1   = td_var_offset(sync_io),
2175                 .help   = "Use O_SYNC for buffered writes",
2176                 .def    = "0",
2177                 .parent = "buffered",
2178         },
2179         {
2180                 .name   = "bwavgtime",
2181                 .type   = FIO_OPT_INT,
2182                 .off1   = td_var_offset(bw_avg_time),
2183                 .help   = "Time window over which to calculate bandwidth"
2184                           " (msec)",
2185                 .def    = "500",
2186                 .parent = "write_bw_log",
2187         },
2188         {
2189                 .name   = "iopsavgtime",
2190                 .type   = FIO_OPT_INT,
2191                 .off1   = td_var_offset(iops_avg_time),
2192                 .help   = "Time window over which to calculate IOPS (msec)",
2193                 .def    = "500",
2194                 .parent = "write_iops_log",
2195         },
2196         {
2197                 .name   = "create_serialize",
2198                 .type   = FIO_OPT_BOOL,
2199                 .off1   = td_var_offset(create_serialize),
2200                 .help   = "Serialize creating of job files",
2201                 .def    = "1",
2202         },
2203         {
2204                 .name   = "create_fsync",
2205                 .type   = FIO_OPT_BOOL,
2206                 .off1   = td_var_offset(create_fsync),
2207                 .help   = "fsync file after creation",
2208                 .def    = "1",
2209         },
2210         {
2211                 .name   = "create_on_open",
2212                 .type   = FIO_OPT_BOOL,
2213                 .off1   = td_var_offset(create_on_open),
2214                 .help   = "Create files when they are opened for IO",
2215                 .def    = "0",
2216         },
2217         {
2218                 .name   = "create_only",
2219                 .type   = FIO_OPT_BOOL,
2220                 .off1   = td_var_offset(create_only),
2221                 .help   = "Only perform file creation phase",
2222                 .def    = "0",
2223         },
2224         {
2225                 .name   = "pre_read",
2226                 .type   = FIO_OPT_BOOL,
2227                 .off1   = td_var_offset(pre_read),
2228                 .help   = "Pre-read files before starting official testing",
2229                 .def    = "0",
2230         },
2231         {
2232                 .name   = "cpuload",
2233                 .type   = FIO_OPT_INT,
2234                 .off1   = td_var_offset(cpuload),
2235                 .help   = "Use this percentage of CPU",
2236         },
2237         {
2238                 .name   = "cpuchunks",
2239                 .type   = FIO_OPT_INT,
2240                 .off1   = td_var_offset(cpucycle),
2241                 .help   = "Length of the CPU burn cycles (usecs)",
2242                 .def    = "50000",
2243                 .parent = "cpuload",
2244         },
2245 #ifdef FIO_HAVE_CPU_AFFINITY
2246         {
2247                 .name   = "cpumask",
2248                 .type   = FIO_OPT_INT,
2249                 .cb     = str_cpumask_cb,
2250                 .help   = "CPU affinity mask",
2251         },
2252         {
2253                 .name   = "cpus_allowed",
2254                 .type   = FIO_OPT_STR,
2255                 .cb     = str_cpus_allowed_cb,
2256                 .help   = "Set CPUs allowed",
2257         },
2258 #endif
2259 #ifdef FIO_HAVE_LIBNUMA
2260         {
2261                 .name   = "numa_cpu_nodes",
2262                 .type   = FIO_OPT_STR,
2263                 .cb     = str_numa_cpunodes_cb,
2264                 .help   = "NUMA CPU nodes bind",
2265         },
2266         {
2267                 .name   = "numa_mem_policy",
2268                 .type   = FIO_OPT_STR,
2269                 .cb     = str_numa_mpol_cb,
2270                 .help   = "NUMA memory policy setup",
2271         },
2272 #endif
2273         {
2274                 .name   = "end_fsync",
2275                 .type   = FIO_OPT_BOOL,
2276                 .off1   = td_var_offset(end_fsync),
2277                 .help   = "Include fsync at the end of job",
2278                 .def    = "0",
2279         },
2280         {
2281                 .name   = "fsync_on_close",
2282                 .type   = FIO_OPT_BOOL,
2283                 .off1   = td_var_offset(fsync_on_close),
2284                 .help   = "fsync files on close",
2285                 .def    = "0",
2286         },
2287         {
2288                 .name   = "unlink",
2289                 .type   = FIO_OPT_BOOL,
2290                 .off1   = td_var_offset(unlink),
2291                 .help   = "Unlink created files after job has completed",
2292                 .def    = "0",
2293         },
2294         {
2295                 .name   = "exitall",
2296                 .type   = FIO_OPT_STR_SET,
2297                 .cb     = str_exitall_cb,
2298                 .help   = "Terminate all jobs when one exits",
2299         },
2300         {
2301                 .name   = "stonewall",
2302                 .alias  = "wait_for_previous",
2303                 .type   = FIO_OPT_STR_SET,
2304                 .off1   = td_var_offset(stonewall),
2305                 .help   = "Insert a hard barrier between this job and previous",
2306         },
2307         {
2308                 .name   = "new_group",
2309                 .type   = FIO_OPT_STR_SET,
2310                 .off1   = td_var_offset(new_group),
2311                 .help   = "Mark the start of a new group (for reporting)",
2312         },
2313         {
2314                 .name   = "thread",
2315                 .type   = FIO_OPT_STR_SET,
2316                 .off1   = td_var_offset(use_thread),
2317                 .help   = "Use threads instead of forks",
2318         },
2319         {
2320                 .name   = "write_bw_log",
2321                 .type   = FIO_OPT_STR,
2322                 .off1   = td_var_offset(write_bw_log),
2323                 .cb     = str_write_bw_log_cb,
2324                 .help   = "Write log of bandwidth during run",
2325         },
2326         {
2327                 .name   = "write_lat_log",
2328                 .type   = FIO_OPT_STR,
2329                 .off1   = td_var_offset(write_lat_log),
2330                 .cb     = str_write_lat_log_cb,
2331                 .help   = "Write log of latency during run",
2332         },
2333         {
2334                 .name   = "write_iops_log",
2335                 .type   = FIO_OPT_STR,
2336                 .off1   = td_var_offset(write_iops_log),
2337                 .cb     = str_write_iops_log_cb,
2338                 .help   = "Write log of IOPS during run",
2339         },
2340         {
2341                 .name   = "log_avg_msec",
2342                 .type   = FIO_OPT_INT,
2343                 .off1   = td_var_offset(log_avg_msec),
2344                 .help   = "Average bw/iops/lat logs over this period of time",
2345                 .def    = "0",
2346         },
2347         {
2348                 .name   = "hugepage-size",
2349                 .type   = FIO_OPT_INT,
2350                 .off1   = td_var_offset(hugepage_size),
2351                 .help   = "When using hugepages, specify size of each page",
2352                 .def    = __fio_stringify(FIO_HUGE_PAGE),
2353         },
2354         {
2355                 .name   = "group_reporting",
2356                 .type   = FIO_OPT_STR_SET,
2357                 .off1   = td_var_offset(group_reporting),
2358                 .help   = "Do reporting on a per-group basis",
2359         },
2360         {
2361                 .name   = "zero_buffers",
2362                 .type   = FIO_OPT_STR_SET,
2363                 .off1   = td_var_offset(zero_buffers),
2364                 .help   = "Init IO buffers to all zeroes",
2365         },
2366         {
2367                 .name   = "refill_buffers",
2368                 .type   = FIO_OPT_STR_SET,
2369                 .off1   = td_var_offset(refill_buffers),
2370                 .help   = "Refill IO buffers on every IO submit",
2371         },
2372         {
2373                 .name   = "scramble_buffers",
2374                 .type   = FIO_OPT_BOOL,
2375                 .off1   = td_var_offset(scramble_buffers),
2376                 .help   = "Slightly scramble buffers on every IO submit",
2377                 .def    = "1",
2378         },
2379         {
2380                 .name   = "buffer_compress_percentage",
2381                 .type   = FIO_OPT_INT,
2382                 .off1   = td_var_offset(compress_percentage),
2383                 .maxval = 100,
2384                 .minval = 1,
2385                 .help   = "How compressible the buffer is (approximately)",
2386         },
2387         {
2388                 .name   = "buffer_compress_chunk",
2389                 .type   = FIO_OPT_INT,
2390                 .off1   = td_var_offset(compress_chunk),
2391                 .parent = "buffer_compress_percentage",
2392                 .help   = "Size of compressible region in buffer",
2393         },
2394         {
2395                 .name   = "clat_percentiles",
2396                 .type   = FIO_OPT_BOOL,
2397                 .off1   = td_var_offset(clat_percentiles),
2398                 .help   = "Enable the reporting of completion latency percentiles",
2399                 .def    = "1",
2400         },
2401         {
2402                 .name   = "percentile_list",
2403                 .type   = FIO_OPT_FLOAT_LIST,
2404                 .off1   = td_var_offset(percentile_list),
2405                 .off2   = td_var_offset(overwrite_plist),
2406                 .help   = "Specify a custom list of percentiles to report",
2407                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2408                 .minfp  = 0.0,
2409                 .maxfp  = 100.0,
2410         },
2411
2412 #ifdef FIO_HAVE_DISK_UTIL
2413         {
2414                 .name   = "disk_util",
2415                 .type   = FIO_OPT_BOOL,
2416                 .off1   = td_var_offset(do_disk_util),
2417                 .help   = "Log disk utilization statistics",
2418                 .def    = "1",
2419         },
2420 #endif
2421         {
2422                 .name   = "gtod_reduce",
2423                 .type   = FIO_OPT_BOOL,
2424                 .help   = "Greatly reduce number of gettimeofday() calls",
2425                 .cb     = str_gtod_reduce_cb,
2426                 .def    = "0",
2427         },
2428         {
2429                 .name   = "disable_lat",
2430                 .type   = FIO_OPT_BOOL,
2431                 .off1   = td_var_offset(disable_lat),
2432                 .help   = "Disable latency numbers",
2433                 .parent = "gtod_reduce",
2434                 .def    = "0",
2435         },
2436         {
2437                 .name   = "disable_clat",
2438                 .type   = FIO_OPT_BOOL,
2439                 .off1   = td_var_offset(disable_clat),
2440                 .help   = "Disable completion latency numbers",
2441                 .parent = "gtod_reduce",
2442                 .def    = "0",
2443         },
2444         {
2445                 .name   = "disable_slat",
2446                 .type   = FIO_OPT_BOOL,
2447                 .off1   = td_var_offset(disable_slat),
2448                 .help   = "Disable submission latency numbers",
2449                 .parent = "gtod_reduce",
2450                 .def    = "0",
2451         },
2452         {
2453                 .name   = "disable_bw_measurement",
2454                 .type   = FIO_OPT_BOOL,
2455                 .off1   = td_var_offset(disable_bw),
2456                 .help   = "Disable bandwidth logging",
2457                 .parent = "gtod_reduce",
2458                 .def    = "0",
2459         },
2460         {
2461                 .name   = "gtod_cpu",
2462                 .type   = FIO_OPT_INT,
2463                 .cb     = str_gtod_cpu_cb,
2464                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2465                 .verify = gtod_cpu_verify,
2466         },
2467         {
2468                 .name   = "continue_on_error",
2469                 .type   = FIO_OPT_STR,
2470                 .off1   = td_var_offset(continue_on_error),
2471                 .help   = "Continue on non-fatal errors during IO",
2472                 .def    = "none",
2473                 .posval = {
2474                           { .ival = "none",
2475                             .oval = ERROR_TYPE_NONE,
2476                             .help = "Exit when an error is encountered",
2477                           },
2478                           { .ival = "read",
2479                             .oval = ERROR_TYPE_READ,
2480                             .help = "Continue on read errors only",
2481                           },
2482                           { .ival = "write",
2483                             .oval = ERROR_TYPE_WRITE,
2484                             .help = "Continue on write errors only",
2485                           },
2486                           { .ival = "io",
2487                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2488                             .help = "Continue on any IO errors",
2489                           },
2490                           { .ival = "verify",
2491                             .oval = ERROR_TYPE_VERIFY,
2492                             .help = "Continue on verify errors only",
2493                           },
2494                           { .ival = "all",
2495                             .oval = ERROR_TYPE_ANY,
2496                             .help = "Continue on all io and verify errors",
2497                           },
2498                           { .ival = "0",
2499                             .oval = ERROR_TYPE_NONE,
2500                             .help = "Alias for 'none'",
2501                           },
2502                           { .ival = "1",
2503                             .oval = ERROR_TYPE_ANY,
2504                             .help = "Alias for 'all'",
2505                           },
2506                 },
2507         },
2508         {
2509                 .name   = "ignore_error",
2510                 .type   = FIO_OPT_STR,
2511                 .cb     = str_ignore_error_cb,
2512                 .help   = "Set a specific list of errors to ignore",
2513                 .parent = "rw",
2514         },
2515         {
2516                 .name   = "error_dump",
2517                 .type   = FIO_OPT_BOOL,
2518                 .off1   = td_var_offset(error_dump),
2519                 .def    = "0",
2520                 .help   = "Dump info on each error",
2521         },
2522
2523         {
2524                 .name   = "profile",
2525                 .type   = FIO_OPT_STR_STORE,
2526                 .off1   = td_var_offset(profile),
2527                 .help   = "Select a specific builtin performance test",
2528         },
2529         {
2530                 .name   = "cgroup",
2531                 .type   = FIO_OPT_STR_STORE,
2532                 .off1   = td_var_offset(cgroup),
2533                 .help   = "Add job to cgroup of this name",
2534         },
2535         {
2536                 .name   = "cgroup_weight",
2537                 .type   = FIO_OPT_INT,
2538                 .off1   = td_var_offset(cgroup_weight),
2539                 .help   = "Use given weight for cgroup",
2540                 .minval = 100,
2541                 .maxval = 1000,
2542         },
2543         {
2544                 .name   = "cgroup_nodelete",
2545                 .type   = FIO_OPT_BOOL,
2546                 .off1   = td_var_offset(cgroup_nodelete),
2547                 .help   = "Do not delete cgroups after job completion",
2548                 .def    = "0",
2549         },
2550         {
2551                 .name   = "uid",
2552                 .type   = FIO_OPT_INT,
2553                 .off1   = td_var_offset(uid),
2554                 .help   = "Run job with this user ID",
2555         },
2556         {
2557                 .name   = "gid",
2558                 .type   = FIO_OPT_INT,
2559                 .off1   = td_var_offset(gid),
2560                 .help   = "Run job with this group ID",
2561         },
2562         {
2563                 .name   = "flow_id",
2564                 .type   = FIO_OPT_INT,
2565                 .off1   = td_var_offset(flow_id),
2566                 .help   = "The flow index ID to use",
2567                 .def    = "0",
2568         },
2569         {
2570                 .name   = "flow",
2571                 .type   = FIO_OPT_INT,
2572                 .off1   = td_var_offset(flow),
2573                 .help   = "Weight for flow control of this job",
2574                 .parent = "flow_id",
2575                 .def    = "0",
2576         },
2577         {
2578                 .name   = "flow_watermark",
2579                 .type   = FIO_OPT_INT,
2580                 .off1   = td_var_offset(flow_watermark),
2581                 .help   = "High watermark for flow control. This option"
2582                         " should be set to the same value for all threads"
2583                         " with non-zero flow.",
2584                 .parent = "flow_id",
2585                 .def    = "1024",
2586         },
2587         {
2588                 .name   = "flow_sleep",
2589                 .type   = FIO_OPT_INT,
2590                 .off1   = td_var_offset(flow_sleep),
2591                 .help   = "How many microseconds to sleep after being held"
2592                         " back by the flow control mechanism",
2593                 .parent = "flow_id",
2594                 .def    = "0",
2595         },
2596         {
2597                 .name = NULL,
2598         },
2599 };
2600
2601 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2602                         const char *name, int val)
2603 {
2604         lopt->name = (char *) name;
2605         lopt->val = val;
2606         if (o->type == FIO_OPT_STR_SET)
2607                 lopt->has_arg = no_argument;
2608         else
2609                 lopt->has_arg = required_argument;
2610 }
2611
2612 static void options_to_lopts(struct fio_option *opts,
2613                               struct option *long_options,
2614                               int i, int option_type)
2615 {
2616         struct fio_option *o = &opts[0];
2617         while (o->name) {
2618                 add_to_lopt(&long_options[i], o, o->name, option_type);
2619                 if (o->alias) {
2620                         i++;
2621                         add_to_lopt(&long_options[i], o, o->alias, option_type);
2622                 }
2623
2624                 i++;
2625                 o++;
2626                 assert(i < FIO_NR_OPTIONS);
2627         }
2628 }
2629
2630 void fio_options_set_ioengine_opts(struct option *long_options,
2631                                    struct thread_data *td)
2632 {
2633         unsigned int i;
2634
2635         i = 0;
2636         while (long_options[i].name) {
2637                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2638                         memset(&long_options[i], 0, sizeof(*long_options));
2639                         break;
2640                 }
2641                 i++;
2642         }
2643
2644         /*
2645          * Just clear out the prior ioengine options.
2646          */
2647         if (!td || !td->eo)
2648                 return;
2649
2650         options_to_lopts(td->io_ops->options, long_options, i,
2651                          FIO_GETOPT_IOENGINE);
2652 }
2653
2654 void fio_options_dup_and_init(struct option *long_options)
2655 {
2656         unsigned int i;
2657
2658         options_init(options);
2659
2660         i = 0;
2661         while (long_options[i].name)
2662                 i++;
2663
2664         options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
2665 }
2666
2667 struct fio_keyword {
2668         const char *word;
2669         const char *desc;
2670         char *replace;
2671 };
2672
2673 static struct fio_keyword fio_keywords[] = {
2674         {
2675                 .word   = "$pagesize",
2676                 .desc   = "Page size in the system",
2677         },
2678         {
2679                 .word   = "$mb_memory",
2680                 .desc   = "Megabytes of memory online",
2681         },
2682         {
2683                 .word   = "$ncpus",
2684                 .desc   = "Number of CPUs online in the system",
2685         },
2686         {
2687                 .word   = NULL,
2688         },
2689 };
2690
2691 void fio_keywords_init(void)
2692 {
2693         unsigned long long mb_memory;
2694         char buf[128];
2695         long l;
2696
2697         sprintf(buf, "%lu", (unsigned long) page_size);
2698         fio_keywords[0].replace = strdup(buf);
2699
2700         mb_memory = os_phys_mem() / (1024 * 1024);
2701         sprintf(buf, "%llu", mb_memory);
2702         fio_keywords[1].replace = strdup(buf);
2703
2704         l = cpus_online();
2705         sprintf(buf, "%lu", l);
2706         fio_keywords[2].replace = strdup(buf);
2707 }
2708
2709 #define BC_APP          "bc"
2710
2711 static char *bc_calc(char *str)
2712 {
2713         char buf[128], *tmp;
2714         FILE *f;
2715         int ret;
2716
2717         /*
2718          * No math, just return string
2719          */
2720         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2721              !strchr(str, '/')) || strchr(str, '\''))
2722                 return str;
2723
2724         /*
2725          * Split option from value, we only need to calculate the value
2726          */
2727         tmp = strchr(str, '=');
2728         if (!tmp)
2729                 return str;
2730
2731         tmp++;
2732
2733         /*
2734          * Prevent buffer overflows; such a case isn't reasonable anyway
2735          */
2736         if (strlen(str) >= 128 || strlen(tmp) > 100)
2737                 return str;
2738
2739         sprintf(buf, "which %s > /dev/null", BC_APP);
2740         if (system(buf)) {
2741                 log_err("fio: bc is needed for performing math\n");
2742                 return NULL;
2743         }
2744
2745         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2746         f = popen(buf, "r");
2747         if (!f) {
2748                 return NULL;
2749         }
2750
2751         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2752         if (ret <= 0) {
2753                 return NULL;
2754         }
2755
2756         pclose(f);
2757         buf[(tmp - str) + ret - 1] = '\0';
2758         memcpy(buf, str, tmp - str);
2759         free(str);
2760         return strdup(buf);
2761 }
2762
2763 /*
2764  * Return a copy of the input string with substrings of the form ${VARNAME}
2765  * substituted with the value of the environment variable VARNAME.  The
2766  * substitution always occurs, even if VARNAME is empty or the corresponding
2767  * environment variable undefined.
2768  */
2769 static char *option_dup_subs(const char *opt)
2770 {
2771         char out[OPT_LEN_MAX+1];
2772         char in[OPT_LEN_MAX+1];
2773         char *outptr = out;
2774         char *inptr = in;
2775         char *ch1, *ch2, *env;
2776         ssize_t nchr = OPT_LEN_MAX;
2777         size_t envlen;
2778
2779         if (strlen(opt) + 1 > OPT_LEN_MAX) {
2780                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2781                 return NULL;
2782         }
2783
2784         in[OPT_LEN_MAX] = '\0';
2785         strncpy(in, opt, OPT_LEN_MAX);
2786
2787         while (*inptr && nchr > 0) {
2788                 if (inptr[0] == '$' && inptr[1] == '{') {
2789                         ch2 = strchr(inptr, '}');
2790                         if (ch2 && inptr+1 < ch2) {
2791                                 ch1 = inptr+2;
2792                                 inptr = ch2+1;
2793                                 *ch2 = '\0';
2794
2795                                 env = getenv(ch1);
2796                                 if (env) {
2797                                         envlen = strlen(env);
2798                                         if (envlen <= nchr) {
2799                                                 memcpy(outptr, env, envlen);
2800                                                 outptr += envlen;
2801                                                 nchr -= envlen;
2802                                         }
2803                                 }
2804
2805                                 continue;
2806                         }
2807                 }
2808
2809                 *outptr++ = *inptr++;
2810                 --nchr;
2811         }
2812
2813         *outptr = '\0';
2814         return strdup(out);
2815 }
2816
2817 /*
2818  * Look for reserved variable names and replace them with real values
2819  */
2820 static char *fio_keyword_replace(char *opt)
2821 {
2822         char *s;
2823         int i;
2824         int docalc = 0;
2825
2826         for (i = 0; fio_keywords[i].word != NULL; i++) {
2827                 struct fio_keyword *kw = &fio_keywords[i];
2828
2829                 while ((s = strstr(opt, kw->word)) != NULL) {
2830                         char *new = malloc(strlen(opt) + 1);
2831                         char *o_org = opt;
2832                         int olen = s - opt;
2833                         int len;
2834
2835                         /*
2836                          * Copy part of the string before the keyword and
2837                          * sprintf() the replacement after it.
2838                          */
2839                         memcpy(new, opt, olen);
2840                         len = sprintf(new + olen, "%s", kw->replace);
2841
2842                         /*
2843                          * If there's more in the original string, copy that
2844                          * in too
2845                          */
2846                         opt += strlen(kw->word) + olen;
2847                         if (strlen(opt))
2848                                 memcpy(new + olen + len, opt, opt - o_org - 1);
2849
2850                         /*
2851                          * replace opt and free the old opt
2852                          */
2853                         opt = new;
2854                         free(o_org);
2855
2856                         docalc = 1;
2857                 }
2858         }
2859
2860         /*
2861          * Check for potential math and invoke bc, if possible
2862          */
2863         if (docalc)
2864                 opt = bc_calc(opt);
2865
2866         return opt;
2867 }
2868
2869 static char **dup_and_sub_options(char **opts, int num_opts)
2870 {
2871         int i;
2872         char **opts_copy = malloc(num_opts * sizeof(*opts));
2873         for (i = 0; i < num_opts; i++) {
2874                 opts_copy[i] = option_dup_subs(opts[i]);
2875                 if (!opts_copy[i])
2876                         continue;
2877                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2878         }
2879         return opts_copy;
2880 }
2881
2882 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2883 {
2884         int i, ret, unknown;
2885         char **opts_copy;
2886
2887         sort_options(opts, options, num_opts);
2888         opts_copy = dup_and_sub_options(opts, num_opts);
2889
2890         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2891                 struct fio_option *o;
2892                 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2893                                           td);
2894
2895                 if (opts_copy[i]) {
2896                         if (newret && !o) {
2897                                 unknown++;
2898                                 continue;
2899                         }
2900                         free(opts_copy[i]);
2901                         opts_copy[i] = NULL;
2902                 }
2903
2904                 ret |= newret;
2905         }
2906
2907         if (unknown) {
2908                 ret |= ioengine_load(td);
2909                 if (td->eo) {
2910                         sort_options(opts_copy, td->io_ops->options, num_opts);
2911                         opts = opts_copy;
2912                 }
2913                 for (i = 0; i < num_opts; i++) {
2914                         struct fio_option *o = NULL;
2915                         int newret = 1;
2916                         if (!opts_copy[i])
2917                                 continue;
2918
2919                         if (td->eo)
2920                                 newret = parse_option(opts_copy[i], opts[i],
2921                                                       td->io_ops->options, &o,
2922                                                       td->eo);
2923
2924                         ret |= newret;
2925                         if (!o)
2926                                 log_err("Bad option <%s>\n", opts[i]);
2927
2928                         free(opts_copy[i]);
2929                         opts_copy[i] = NULL;
2930                 }
2931         }
2932
2933         free(opts_copy);
2934         return ret;
2935 }
2936
2937 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2938 {
2939         return parse_cmd_option(opt, val, options, td);
2940 }
2941
2942 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2943                                 char *val)
2944 {
2945         return parse_cmd_option(opt, val, td->io_ops->options, td);
2946 }
2947
2948 void fio_fill_default_options(struct thread_data *td)
2949 {
2950         fill_default_options(td, options);
2951 }
2952
2953 int fio_show_option_help(const char *opt)
2954 {
2955         return show_cmd_help(options, opt);
2956 }
2957
2958 void options_mem_dupe(void *data, struct fio_option *options)
2959 {
2960         struct fio_option *o;
2961         char **ptr;
2962
2963         for (o = &options[0]; o->name; o++) {
2964                 if (o->type != FIO_OPT_STR_STORE)
2965                         continue;
2966
2967                 ptr = td_var(data, o->off1);
2968                 if (*ptr)
2969                         *ptr = strdup(*ptr);
2970         }
2971 }
2972
2973 /*
2974  * dupe FIO_OPT_STR_STORE options
2975  */
2976 void fio_options_mem_dupe(struct thread_data *td)
2977 {
2978         options_mem_dupe(&td->o, options);
2979
2980         if (td->eo && td->io_ops) {
2981                 void *oldeo = td->eo;
2982
2983                 td->eo = malloc(td->io_ops->option_struct_size);
2984                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2985                 options_mem_dupe(td->eo, td->io_ops->options);
2986         }
2987 }
2988
2989 unsigned int fio_get_kb_base(void *data)
2990 {
2991         struct thread_data *td = data;
2992         unsigned int kb_base = 0;
2993
2994         if (td)
2995                 kb_base = td->o.kb_base;
2996         if (!kb_base)
2997                 kb_base = 1024;
2998
2999         return kb_base;
3000 }
3001
3002 int add_option(struct fio_option *o)
3003 {
3004         struct fio_option *__o;
3005         int opt_index = 0;
3006
3007         __o = options;
3008         while (__o->name) {
3009                 opt_index++;
3010                 __o++;
3011         }
3012
3013         memcpy(&options[opt_index], o, sizeof(*o));
3014         return 0;
3015 }
3016
3017 void invalidate_profile_options(const char *prof_name)
3018 {
3019         struct fio_option *o;
3020
3021         o = options;
3022         while (o->name) {
3023                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3024                         o->type = FIO_OPT_INVALID;
3025                         o->prof_name = NULL;
3026                 }
3027                 o++;
3028         }
3029 }
3030
3031 void add_opt_posval(const char *optname, const char *ival, const char *help)
3032 {
3033         struct fio_option *o;
3034         unsigned int i;
3035
3036         o = find_option(options, optname);
3037         if (!o)
3038                 return;
3039
3040         for (i = 0; i < PARSE_MAX_VP; i++) {
3041                 if (o->posval[i].ival)
3042                         continue;
3043
3044                 o->posval[i].ival = ival;
3045                 o->posval[i].help = help;
3046                 break;
3047         }
3048 }
3049
3050 void del_opt_posval(const char *optname, const char *ival)
3051 {
3052         struct fio_option *o;
3053         unsigned int i;
3054
3055         o = find_option(options, optname);
3056         if (!o)
3057                 return;
3058
3059         for (i = 0; i < PARSE_MAX_VP; i++) {
3060                 if (!o->posval[i].ival)
3061                         continue;
3062                 if (strcmp(o->posval[i].ival, ival))
3063                         continue;
3064
3065                 o->posval[i].ival = NULL;
3066                 o->posval[i].help = NULL;
3067         }
3068 }
3069
3070 void fio_options_free(struct thread_data *td)
3071 {
3072         options_free(options, td);
3073         if (td->eo && td->io_ops && td->io_ops->options) {
3074                 options_free(td->io_ops->options, td->eo);
3075                 free(td->eo);
3076                 td->eo = NULL;
3077         }
3078 }