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