380df36afd29f527d33d3949930ebe5f33d676a9
[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 check_dir(struct thread_data *td, char *fname)
732 {
733 #if 0
734         char file[PATH_MAX], *dir;
735         int elen = 0;
736
737         if (td->o.directory) {
738                 strcpy(file, td->o.directory);
739                 strcat(file, "/");
740                 elen = strlen(file);
741         }
742
743         sprintf(file + elen, "%s", fname);
744         dir = dirname(file);
745
746         {
747         struct stat sb;
748         /*
749          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
750          * yet, so we can't do this check right here...
751          */
752         if (lstat(dir, &sb) < 0) {
753                 int ret = errno;
754
755                 log_err("fio: %s is not a directory\n", dir);
756                 td_verror(td, ret, "lstat");
757                 return 1;
758         }
759
760         if (!S_ISDIR(sb.st_mode)) {
761                 log_err("fio: %s is not a directory\n", dir);
762                 return 1;
763         }
764         }
765 #endif
766
767         return 0;
768 }
769
770 /*
771  * Return next file in the string. Files are separated with ':'. If the ':'
772  * is escaped with a '\', then that ':' is part of the filename and does not
773  * indicate a new file.
774  */
775 static char *get_next_file_name(char **ptr)
776 {
777         char *str = *ptr;
778         char *p, *start;
779
780         if (!str || !strlen(str))
781                 return NULL;
782
783         start = str;
784         do {
785                 /*
786                  * No colon, we are done
787                  */
788                 p = strchr(str, ':');
789                 if (!p) {
790                         *ptr = NULL;
791                         break;
792                 }
793
794                 /*
795                  * We got a colon, but it's the first character. Skip and
796                  * continue
797                  */
798                 if (p == start) {
799                         str = ++start;
800                         continue;
801                 }
802
803                 if (*(p - 1) != '\\') {
804                         *p = '\0';
805                         *ptr = p + 1;
806                         break;
807                 }
808
809                 memmove(p - 1, p, strlen(p) + 1);
810                 str = p;
811         } while (1);
812
813         return start;
814 }
815
816 static int str_filename_cb(void *data, const char *input)
817 {
818         struct thread_data *td = data;
819         char *fname, *str, *p;
820
821         p = str = strdup(input);
822
823         strip_blank_front(&str);
824         strip_blank_end(str);
825
826         if (!td->files_index)
827                 td->o.nr_files = 0;
828
829         while ((fname = get_next_file_name(&str)) != NULL) {
830                 if (!strlen(fname))
831                         break;
832                 if (check_dir(td, fname)) {
833                         free(p);
834                         return 1;
835                 }
836                 add_file(td, fname);
837                 td->o.nr_files++;
838         }
839
840         free(p);
841         return 0;
842 }
843
844 static int str_directory_cb(void *data, const char fio_unused *str)
845 {
846         struct thread_data *td = data;
847         struct stat sb;
848
849         if (lstat(td->o.directory, &sb) < 0) {
850                 int ret = errno;
851
852                 log_err("fio: %s is not a directory\n", td->o.directory);
853                 td_verror(td, ret, "lstat");
854                 return 1;
855         }
856         if (!S_ISDIR(sb.st_mode)) {
857                 log_err("fio: %s is not a directory\n", td->o.directory);
858                 return 1;
859         }
860
861         return 0;
862 }
863
864 static int str_opendir_cb(void *data, const char fio_unused *str)
865 {
866         struct thread_data *td = data;
867
868         if (!td->files_index)
869                 td->o.nr_files = 0;
870
871         return add_dir_files(td, td->o.opendir);
872 }
873
874 static int str_verify_offset_cb(void *data, unsigned long long *off)
875 {
876         struct thread_data *td = data;
877
878         if (*off && *off < sizeof(struct verify_header)) {
879                 log_err("fio: verify_offset too small\n");
880                 return 1;
881         }
882
883         td->o.verify_offset = *off;
884         return 0;
885 }
886
887 static int str_verify_pattern_cb(void *data, const char *input)
888 {
889         struct thread_data *td = data;
890         long off;
891         int i = 0, j = 0, len, k, base = 10;
892         char* loc1, * loc2;
893
894         loc1 = strstr(input, "0x");
895         loc2 = strstr(input, "0X");
896         if (loc1 || loc2)
897                 base = 16;
898         off = strtol(input, NULL, base);
899         if (off != LONG_MAX || errno != ERANGE) {
900                 while (off) {
901                         td->o.verify_pattern[i] = off & 0xff;
902                         off >>= 8;
903                         i++;
904                 }
905         } else {
906                 len = strlen(input);
907                 k = len - 1;
908                 if (base == 16) {
909                         if (loc1)
910                                 j = loc1 - input + 2;
911                         else
912                                 j = loc2 - input + 2;
913                 } else
914                         return 1;
915                 if (len - j < MAX_PATTERN_SIZE * 2) {
916                         while (k >= j) {
917                                 off = converthexchartoint(input[k--]);
918                                 if (k >= j)
919                                         off += (converthexchartoint(input[k--])
920                                                 * 16);
921                                 td->o.verify_pattern[i++] = (char) off;
922                         }
923                 }
924         }
925
926         /*
927          * Fill the pattern all the way to the end. This greatly reduces
928          * the number of memcpy's we have to do when verifying the IO.
929          */
930         while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
931                 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
932                 i *= 2;
933         }
934         if (i == 1) {
935                 /*
936                  * The code in verify_io_u_pattern assumes a single byte pattern
937                  * fills the whole verify pattern buffer.
938                  */
939                 memset(td->o.verify_pattern, td->o.verify_pattern[0],
940                        MAX_PATTERN_SIZE);
941         }
942
943         td->o.verify_pattern_bytes = i;
944
945         /*
946          * VERIFY_META could already be set
947          */
948         if (td->o.verify == VERIFY_NONE)
949                 td->o.verify = VERIFY_PATTERN;
950
951         return 0;
952 }
953
954 static int str_lockfile_cb(void *data, const char *str)
955 {
956         struct thread_data *td = data;
957         char *nr = get_opt_postfix(str);
958
959         td->o.lockfile_batch = 1;
960         if (nr) {
961                 td->o.lockfile_batch = atoi(nr);
962                 free(nr);
963         }
964
965         return 0;
966 }
967
968 static int str_write_bw_log_cb(void *data, const char *str)
969 {
970         struct thread_data *td = data;
971
972         if (str)
973                 td->o.bw_log_file = strdup(str);
974
975         td->o.write_bw_log = 1;
976         return 0;
977 }
978
979 static int str_write_lat_log_cb(void *data, const char *str)
980 {
981         struct thread_data *td = data;
982
983         if (str)
984                 td->o.lat_log_file = strdup(str);
985
986         td->o.write_lat_log = 1;
987         return 0;
988 }
989
990 static int str_write_iops_log_cb(void *data, const char *str)
991 {
992         struct thread_data *td = data;
993
994         if (str)
995                 td->o.iops_log_file = strdup(str);
996
997         td->o.write_iops_log = 1;
998         return 0;
999 }
1000
1001 static int str_gtod_reduce_cb(void *data, int *il)
1002 {
1003         struct thread_data *td = data;
1004         int val = *il;
1005
1006         td->o.disable_lat = !!val;
1007         td->o.disable_clat = !!val;
1008         td->o.disable_slat = !!val;
1009         td->o.disable_bw = !!val;
1010         td->o.clat_percentiles = !val;
1011         if (val)
1012                 td->tv_cache_mask = 63;
1013
1014         return 0;
1015 }
1016
1017 static int str_gtod_cpu_cb(void *data, long long *il)
1018 {
1019         struct thread_data *td = data;
1020         int val = *il;
1021
1022         td->o.gtod_cpu = val;
1023         td->o.gtod_offload = 1;
1024         return 0;
1025 }
1026
1027 static int str_size_cb(void *data, unsigned long long *__val)
1028 {
1029         struct thread_data *td = data;
1030         unsigned long long v = *__val;
1031
1032         if (parse_is_percent(v)) {
1033                 td->o.size = 0;
1034                 td->o.size_percent = -1ULL - v;
1035         } else
1036                 td->o.size = v;
1037
1038         return 0;
1039 }
1040
1041 static int rw_verify(struct fio_option *o, void *data)
1042 {
1043         struct thread_data *td = data;
1044
1045         if (read_only && td_write(td)) {
1046                 log_err("fio: job <%s> has write bit set, but fio is in"
1047                         " read-only mode\n", td->o.name);
1048                 return 1;
1049         }
1050
1051         return 0;
1052 }
1053
1054 static int gtod_cpu_verify(struct fio_option *o, void *data)
1055 {
1056 #ifndef FIO_HAVE_CPU_AFFINITY
1057         struct thread_data *td = data;
1058
1059         if (td->o.gtod_cpu) {
1060                 log_err("fio: platform must support CPU affinity for"
1061                         "gettimeofday() offloading\n");
1062                 return 1;
1063         }
1064 #endif
1065
1066         return 0;
1067 }
1068
1069 static int kb_base_verify(struct fio_option *o, void *data)
1070 {
1071         struct thread_data *td = data;
1072
1073         if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
1074                 log_err("fio: kb_base set to nonsensical value: %u\n",
1075                                 td->o.kb_base);
1076                 return 1;
1077         }
1078
1079         return 0;
1080 }
1081
1082 /*
1083  * Map of job/command line options
1084  */
1085 static struct fio_option options[FIO_MAX_OPTS] = {
1086         {
1087                 .name   = "description",
1088                 .type   = FIO_OPT_STR_STORE,
1089                 .off1   = td_var_offset(description),
1090                 .help   = "Text job description",
1091         },
1092         {
1093                 .name   = "name",
1094                 .type   = FIO_OPT_STR_STORE,
1095                 .off1   = td_var_offset(name),
1096                 .help   = "Name of this job",
1097         },
1098         {
1099                 .name   = "directory",
1100                 .type   = FIO_OPT_STR_STORE,
1101                 .off1   = td_var_offset(directory),
1102                 .cb     = str_directory_cb,
1103                 .help   = "Directory to store files in",
1104         },
1105         {
1106                 .name   = "filename",
1107                 .type   = FIO_OPT_STR_STORE,
1108                 .off1   = td_var_offset(filename),
1109                 .cb     = str_filename_cb,
1110                 .prio   = -1, /* must come after "directory" */
1111                 .help   = "File(s) to use for the workload",
1112         },
1113         {
1114                 .name   = "kb_base",
1115                 .type   = FIO_OPT_INT,
1116                 .off1   = td_var_offset(kb_base),
1117                 .verify = kb_base_verify,
1118                 .prio   = 1,
1119                 .def    = "1024",
1120                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
1121         },
1122         {
1123                 .name   = "lockfile",
1124                 .type   = FIO_OPT_STR,
1125                 .cb     = str_lockfile_cb,
1126                 .off1   = td_var_offset(file_lock_mode),
1127                 .help   = "Lock file when doing IO to it",
1128                 .parent = "filename",
1129                 .def    = "none",
1130                 .posval = {
1131                           { .ival = "none",
1132                             .oval = FILE_LOCK_NONE,
1133                             .help = "No file locking",
1134                           },
1135                           { .ival = "exclusive",
1136                             .oval = FILE_LOCK_EXCLUSIVE,
1137                             .help = "Exclusive file lock",
1138                           },
1139                           {
1140                             .ival = "readwrite",
1141                             .oval = FILE_LOCK_READWRITE,
1142                             .help = "Read vs write lock",
1143                           },
1144                 },
1145         },
1146         {
1147                 .name   = "opendir",
1148                 .type   = FIO_OPT_STR_STORE,
1149                 .off1   = td_var_offset(opendir),
1150                 .cb     = str_opendir_cb,
1151                 .help   = "Recursively add files from this directory and down",
1152         },
1153         {
1154                 .name   = "rw",
1155                 .alias  = "readwrite",
1156                 .type   = FIO_OPT_STR,
1157                 .cb     = str_rw_cb,
1158                 .off1   = td_var_offset(td_ddir),
1159                 .help   = "IO direction",
1160                 .def    = "read",
1161                 .verify = rw_verify,
1162                 .posval = {
1163                           { .ival = "read",
1164                             .oval = TD_DDIR_READ,
1165                             .help = "Sequential read",
1166                           },
1167                           { .ival = "write",
1168                             .oval = TD_DDIR_WRITE,
1169                             .help = "Sequential write",
1170                           },
1171                           { .ival = "trim",
1172                             .oval = TD_DDIR_TRIM,
1173                             .help = "Sequential trim",
1174                           },
1175                           { .ival = "randread",
1176                             .oval = TD_DDIR_RANDREAD,
1177                             .help = "Random read",
1178                           },
1179                           { .ival = "randwrite",
1180                             .oval = TD_DDIR_RANDWRITE,
1181                             .help = "Random write",
1182                           },
1183                           { .ival = "randtrim",
1184                             .oval = TD_DDIR_RANDTRIM,
1185                             .help = "Random trim",
1186                           },
1187                           { .ival = "rw",
1188                             .oval = TD_DDIR_RW,
1189                             .help = "Sequential read and write mix",
1190                           },
1191                           { .ival = "readwrite",
1192                             .oval = TD_DDIR_RW,
1193                             .help = "Sequential read and write mix",
1194                           },
1195                           { .ival = "randrw",
1196                             .oval = TD_DDIR_RANDRW,
1197                             .help = "Random read and write mix"
1198                           },
1199                 },
1200         },
1201         {
1202                 .name   = "rw_sequencer",
1203                 .type   = FIO_OPT_STR,
1204                 .off1   = td_var_offset(rw_seq),
1205                 .help   = "IO offset generator modifier",
1206                 .def    = "sequential",
1207                 .posval = {
1208                           { .ival = "sequential",
1209                             .oval = RW_SEQ_SEQ,
1210                             .help = "Generate sequential offsets",
1211                           },
1212                           { .ival = "identical",
1213                             .oval = RW_SEQ_IDENT,
1214                             .help = "Generate identical offsets",
1215                           },
1216                 },
1217         },
1218
1219         {
1220                 .name   = "ioengine",
1221                 .type   = FIO_OPT_STR_STORE,
1222                 .off1   = td_var_offset(ioengine),
1223                 .help   = "IO engine to use",
1224                 .def    = FIO_PREFERRED_ENGINE,
1225                 .posval = {
1226                           { .ival = "sync",
1227                             .help = "Use read/write",
1228                           },
1229                           { .ival = "psync",
1230                             .help = "Use pread/pwrite",
1231                           },
1232                           { .ival = "vsync",
1233                             .help = "Use readv/writev",
1234                           },
1235 #ifdef FIO_HAVE_LIBAIO
1236                           { .ival = "libaio",
1237                             .help = "Linux native asynchronous IO",
1238                           },
1239 #endif
1240 #ifdef FIO_HAVE_POSIXAIO
1241                           { .ival = "posixaio",
1242                             .help = "POSIX asynchronous IO",
1243                           },
1244 #endif
1245 #ifdef FIO_HAVE_SOLARISAIO
1246                           { .ival = "solarisaio",
1247                             .help = "Solaris native asynchronous IO",
1248                           },
1249 #endif
1250 #ifdef FIO_HAVE_WINDOWSAIO
1251                           { .ival = "windowsaio",
1252                             .help = "Windows native asynchronous IO"
1253                           },
1254 #endif
1255                           { .ival = "mmap",
1256                             .help = "Memory mapped IO"
1257                           },
1258 #ifdef FIO_HAVE_SPLICE
1259                           { .ival = "splice",
1260                             .help = "splice/vmsplice based IO",
1261                           },
1262                           { .ival = "netsplice",
1263                             .help = "splice/vmsplice to/from the network",
1264                           },
1265 #endif
1266 #ifdef FIO_HAVE_SGIO
1267                           { .ival = "sg",
1268                             .help = "SCSI generic v3 IO",
1269                           },
1270 #endif
1271                           { .ival = "null",
1272                             .help = "Testing engine (no data transfer)",
1273                           },
1274                           { .ival = "net",
1275                             .help = "Network IO",
1276                           },
1277 #ifdef FIO_HAVE_SYSLET
1278                           { .ival = "syslet-rw",
1279                             .help = "syslet enabled async pread/pwrite IO",
1280                           },
1281 #endif
1282                           { .ival = "cpuio",
1283                             .help = "CPU cycle burner engine",
1284                           },
1285 #ifdef FIO_HAVE_GUASI
1286                           { .ival = "guasi",
1287                             .help = "GUASI IO engine",
1288                           },
1289 #endif
1290 #ifdef FIO_HAVE_BINJECT
1291                           { .ival = "binject",
1292                             .help = "binject direct inject block engine",
1293                           },
1294 #endif
1295 #ifdef FIO_HAVE_RDMA
1296                           { .ival = "rdma",
1297                             .help = "RDMA IO engine",
1298                           },
1299 #endif
1300 #ifdef FIO_HAVE_FUSION_AW
1301                           { .ival = "fusion-aw-sync",
1302                             .help = "Fusion-io atomic write engine",
1303                           },
1304 #endif
1305 #ifdef FIO_HAVE_E4_ENG
1306                           { .ival = "e4defrag",
1307                             .help = "ext4 defrag engine",
1308                           },
1309 #endif
1310 #ifdef FIO_HAVE_FALLOC_ENG
1311                           { .ival = "falloc",
1312                             .help = "fallocate() file based engine",
1313                           },
1314 #endif
1315                           { .ival = "external",
1316                             .help = "Load external engine (append name)",
1317                           },
1318                 },
1319         },
1320         {
1321                 .name   = "iodepth",
1322                 .type   = FIO_OPT_INT,
1323                 .off1   = td_var_offset(iodepth),
1324                 .help   = "Number of IO buffers to keep in flight",
1325                 .minval = 1,
1326                 .def    = "1",
1327         },
1328         {
1329                 .name   = "iodepth_batch",
1330                 .alias  = "iodepth_batch_submit",
1331                 .type   = FIO_OPT_INT,
1332                 .off1   = td_var_offset(iodepth_batch),
1333                 .help   = "Number of IO buffers to submit in one go",
1334                 .parent = "iodepth",
1335                 .minval = 1,
1336                 .def    = "1",
1337         },
1338         {
1339                 .name   = "iodepth_batch_complete",
1340                 .type   = FIO_OPT_INT,
1341                 .off1   = td_var_offset(iodepth_batch_complete),
1342                 .help   = "Number of IO buffers to retrieve in one go",
1343                 .parent = "iodepth",
1344                 .minval = 0,
1345                 .def    = "1",
1346         },
1347         {
1348                 .name   = "iodepth_low",
1349                 .type   = FIO_OPT_INT,
1350                 .off1   = td_var_offset(iodepth_low),
1351                 .help   = "Low water mark for queuing depth",
1352                 .parent = "iodepth",
1353         },
1354         {
1355                 .name   = "size",
1356                 .type   = FIO_OPT_STR_VAL,
1357                 .cb     = str_size_cb,
1358                 .help   = "Total size of device or files",
1359         },
1360         {
1361                 .name   = "fill_device",
1362                 .alias  = "fill_fs",
1363                 .type   = FIO_OPT_BOOL,
1364                 .off1   = td_var_offset(fill_device),
1365                 .help   = "Write until an ENOSPC error occurs",
1366                 .def    = "0",
1367         },
1368         {
1369                 .name   = "filesize",
1370                 .type   = FIO_OPT_STR_VAL,
1371                 .off1   = td_var_offset(file_size_low),
1372                 .off2   = td_var_offset(file_size_high),
1373                 .minval = 1,
1374                 .help   = "Size of individual files",
1375         },
1376         {
1377                 .name   = "offset",
1378                 .alias  = "fileoffset",
1379                 .type   = FIO_OPT_STR_VAL,
1380                 .off1   = td_var_offset(start_offset),
1381                 .help   = "Start IO from this offset",
1382                 .def    = "0",
1383         },
1384         {
1385                 .name   = "offset_increment",
1386                 .type   = FIO_OPT_STR_VAL,
1387                 .off1   = td_var_offset(offset_increment),
1388                 .help   = "What is the increment from one offset to the next",
1389                 .parent = "offset",
1390                 .def    = "0",
1391         },
1392         {
1393                 .name   = "bs",
1394                 .alias  = "blocksize",
1395                 .type   = FIO_OPT_INT,
1396                 .off1   = td_var_offset(bs[DDIR_READ]),
1397                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1398                 .off3   = td_var_offset(bs[DDIR_TRIM]),
1399                 .minval = 1,
1400                 .help   = "Block size unit",
1401                 .def    = "4k",
1402                 .parent = "rw",
1403         },
1404         {
1405                 .name   = "ba",
1406                 .alias  = "blockalign",
1407                 .type   = FIO_OPT_INT,
1408                 .off1   = td_var_offset(ba[DDIR_READ]),
1409                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1410                 .off3   = td_var_offset(ba[DDIR_TRIM]),
1411                 .minval = 1,
1412                 .help   = "IO block offset alignment",
1413                 .parent = "rw",
1414         },
1415         {
1416                 .name   = "bsrange",
1417                 .alias  = "blocksize_range",
1418                 .type   = FIO_OPT_RANGE,
1419                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1420                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1421                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1422                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1423                 .off5   = td_var_offset(min_bs[DDIR_TRIM]),
1424                 .off6   = td_var_offset(max_bs[DDIR_TRIM]),
1425                 .minval = 1,
1426                 .help   = "Set block size range (in more detail than bs)",
1427                 .parent = "rw",
1428         },
1429         {
1430                 .name   = "bssplit",
1431                 .type   = FIO_OPT_STR,
1432                 .cb     = str_bssplit_cb,
1433                 .help   = "Set a specific mix of block sizes",
1434                 .parent = "rw",
1435         },
1436         {
1437                 .name   = "bs_unaligned",
1438                 .alias  = "blocksize_unaligned",
1439                 .type   = FIO_OPT_STR_SET,
1440                 .off1   = td_var_offset(bs_unaligned),
1441                 .help   = "Don't sector align IO buffer sizes",
1442                 .parent = "rw",
1443         },
1444         {
1445                 .name   = "randrepeat",
1446                 .type   = FIO_OPT_BOOL,
1447                 .off1   = td_var_offset(rand_repeatable),
1448                 .help   = "Use repeatable random IO pattern",
1449                 .def    = "1",
1450                 .parent = "rw",
1451         },
1452         {
1453                 .name   = "use_os_rand",
1454                 .type   = FIO_OPT_BOOL,
1455                 .off1   = td_var_offset(use_os_rand),
1456                 .help   = "Set to use OS random generator",
1457                 .def    = "0",
1458                 .parent = "rw",
1459         },
1460         {
1461                 .name   = "norandommap",
1462                 .type   = FIO_OPT_STR_SET,
1463                 .off1   = td_var_offset(norandommap),
1464                 .help   = "Accept potential duplicate random blocks",
1465                 .parent = "rw",
1466         },
1467         {
1468                 .name   = "softrandommap",
1469                 .type   = FIO_OPT_BOOL,
1470                 .off1   = td_var_offset(softrandommap),
1471                 .help   = "Set norandommap if randommap allocation fails",
1472                 .parent = "norandommap",
1473                 .def    = "0",
1474         },
1475         {
1476                 .name   = "nrfiles",
1477                 .alias  = "nr_files",
1478                 .type   = FIO_OPT_INT,
1479                 .off1   = td_var_offset(nr_files),
1480                 .help   = "Split job workload between this number of files",
1481                 .def    = "1",
1482         },
1483         {
1484                 .name   = "openfiles",
1485                 .type   = FIO_OPT_INT,
1486                 .off1   = td_var_offset(open_files),
1487                 .help   = "Number of files to keep open at the same time",
1488         },
1489         {
1490                 .name   = "file_service_type",
1491                 .type   = FIO_OPT_STR,
1492                 .cb     = str_fst_cb,
1493                 .off1   = td_var_offset(file_service_type),
1494                 .help   = "How to select which file to service next",
1495                 .def    = "roundrobin",
1496                 .posval = {
1497                           { .ival = "random",
1498                             .oval = FIO_FSERVICE_RANDOM,
1499                             .help = "Choose a file at random",
1500                           },
1501                           { .ival = "roundrobin",
1502                             .oval = FIO_FSERVICE_RR,
1503                             .help = "Round robin select files",
1504                           },
1505                           { .ival = "sequential",
1506                             .oval = FIO_FSERVICE_SEQ,
1507                             .help = "Finish one file before moving to the next",
1508                           },
1509                 },
1510                 .parent = "nrfiles",
1511         },
1512 #ifdef FIO_HAVE_FALLOCATE
1513         {
1514                 .name   = "fallocate",
1515                 .type   = FIO_OPT_STR,
1516                 .off1   = td_var_offset(fallocate_mode),
1517                 .help   = "Whether pre-allocation is performed when laying out files",
1518                 .def    = "posix",
1519                 .posval = {
1520                           { .ival = "none",
1521                             .oval = FIO_FALLOCATE_NONE,
1522                             .help = "Do not pre-allocate space",
1523                           },
1524                           { .ival = "posix",
1525                             .oval = FIO_FALLOCATE_POSIX,
1526                             .help = "Use posix_fallocate()",
1527                           },
1528 #ifdef FIO_HAVE_LINUX_FALLOCATE
1529                           { .ival = "keep",
1530                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1531                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1532                           },
1533 #endif
1534                           /* Compatibility with former boolean values */
1535                           { .ival = "0",
1536                             .oval = FIO_FALLOCATE_NONE,
1537                             .help = "Alias for 'none'",
1538                           },
1539                           { .ival = "1",
1540                             .oval = FIO_FALLOCATE_POSIX,
1541                             .help = "Alias for 'posix'",
1542                           },
1543                 },
1544         },
1545 #endif  /* FIO_HAVE_FALLOCATE */
1546         {
1547                 .name   = "fadvise_hint",
1548                 .type   = FIO_OPT_BOOL,
1549                 .off1   = td_var_offset(fadvise_hint),
1550                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1551                 .def    = "1",
1552         },
1553         {
1554                 .name   = "fsync",
1555                 .type   = FIO_OPT_INT,
1556                 .off1   = td_var_offset(fsync_blocks),
1557                 .help   = "Issue fsync for writes every given number of blocks",
1558                 .def    = "0",
1559         },
1560         {
1561                 .name   = "fdatasync",
1562                 .type   = FIO_OPT_INT,
1563                 .off1   = td_var_offset(fdatasync_blocks),
1564                 .help   = "Issue fdatasync for writes every given number of blocks",
1565                 .def    = "0",
1566         },
1567         {
1568                 .name   = "write_barrier",
1569                 .type   = FIO_OPT_INT,
1570                 .off1   = td_var_offset(barrier_blocks),
1571                 .help   = "Make every Nth write a barrier write",
1572                 .def    = "0",
1573         },
1574 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1575         {
1576                 .name   = "sync_file_range",
1577                 .posval = {
1578                           { .ival = "wait_before",
1579                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1580                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1581                             .or   = 1,
1582                           },
1583                           { .ival = "write",
1584                             .oval = SYNC_FILE_RANGE_WRITE,
1585                             .help = "SYNC_FILE_RANGE_WRITE",
1586                             .or   = 1,
1587                           },
1588                           {
1589                             .ival = "wait_after",
1590                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1591                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1592                             .or   = 1,
1593                           },
1594                 },
1595                 .type   = FIO_OPT_STR_MULTI,
1596                 .cb     = str_sfr_cb,
1597                 .off1   = td_var_offset(sync_file_range),
1598                 .help   = "Use sync_file_range()",
1599         },
1600 #endif
1601         {
1602                 .name   = "direct",
1603                 .type   = FIO_OPT_BOOL,
1604                 .off1   = td_var_offset(odirect),
1605                 .help   = "Use O_DIRECT IO (negates buffered)",
1606                 .def    = "0",
1607         },
1608         {
1609                 .name   = "buffered",
1610                 .type   = FIO_OPT_BOOL,
1611                 .off1   = td_var_offset(odirect),
1612                 .neg    = 1,
1613                 .help   = "Use buffered IO (negates direct)",
1614                 .def    = "1",
1615         },
1616         {
1617                 .name   = "overwrite",
1618                 .type   = FIO_OPT_BOOL,
1619                 .off1   = td_var_offset(overwrite),
1620                 .help   = "When writing, set whether to overwrite current data",
1621                 .def    = "0",
1622         },
1623         {
1624                 .name   = "loops",
1625                 .type   = FIO_OPT_INT,
1626                 .off1   = td_var_offset(loops),
1627                 .help   = "Number of times to run the job",
1628                 .def    = "1",
1629         },
1630         {
1631                 .name   = "numjobs",
1632                 .type   = FIO_OPT_INT,
1633                 .off1   = td_var_offset(numjobs),
1634                 .help   = "Duplicate this job this many times",
1635                 .def    = "1",
1636         },
1637         {
1638                 .name   = "startdelay",
1639                 .type   = FIO_OPT_STR_VAL_TIME,
1640                 .off1   = td_var_offset(start_delay),
1641                 .help   = "Only start job when this period has passed",
1642                 .def    = "0",
1643         },
1644         {
1645                 .name   = "runtime",
1646                 .alias  = "timeout",
1647                 .type   = FIO_OPT_STR_VAL_TIME,
1648                 .off1   = td_var_offset(timeout),
1649                 .help   = "Stop workload when this amount of time has passed",
1650                 .def    = "0",
1651         },
1652         {
1653                 .name   = "time_based",
1654                 .type   = FIO_OPT_STR_SET,
1655                 .off1   = td_var_offset(time_based),
1656                 .help   = "Keep running until runtime/timeout is met",
1657         },
1658         {
1659                 .name   = "ramp_time",
1660                 .type   = FIO_OPT_STR_VAL_TIME,
1661                 .off1   = td_var_offset(ramp_time),
1662                 .help   = "Ramp up time before measuring performance",
1663         },
1664         {
1665                 .name   = "clocksource",
1666                 .type   = FIO_OPT_STR,
1667                 .cb     = fio_clock_source_cb,
1668                 .off1   = td_var_offset(clocksource),
1669                 .help   = "What type of timing source to use",
1670                 .posval = {
1671                           { .ival = "gettimeofday",
1672                             .oval = CS_GTOD,
1673                             .help = "Use gettimeofday(2) for timing",
1674                           },
1675                           { .ival = "clock_gettime",
1676                             .oval = CS_CGETTIME,
1677                             .help = "Use clock_gettime(2) for timing",
1678                           },
1679 #ifdef ARCH_HAVE_CPU_CLOCK
1680                           { .ival = "cpu",
1681                             .oval = CS_CPUCLOCK,
1682                             .help = "Use CPU private clock",
1683                           },
1684 #endif
1685                 },
1686         },
1687         {
1688                 .name   = "mem",
1689                 .alias  = "iomem",
1690                 .type   = FIO_OPT_STR,
1691                 .cb     = str_mem_cb,
1692                 .off1   = td_var_offset(mem_type),
1693                 .help   = "Backing type for IO buffers",
1694                 .def    = "malloc",
1695                 .posval = {
1696                           { .ival = "malloc",
1697                             .oval = MEM_MALLOC,
1698                             .help = "Use malloc(3) for IO buffers",
1699                           },
1700                           { .ival = "shm",
1701                             .oval = MEM_SHM,
1702                             .help = "Use shared memory segments for IO buffers",
1703                           },
1704 #ifdef FIO_HAVE_HUGETLB
1705                           { .ival = "shmhuge",
1706                             .oval = MEM_SHMHUGE,
1707                             .help = "Like shm, but use huge pages",
1708                           },
1709 #endif
1710                           { .ival = "mmap",
1711                             .oval = MEM_MMAP,
1712                             .help = "Use mmap(2) (file or anon) for IO buffers",
1713                           },
1714 #ifdef FIO_HAVE_HUGETLB
1715                           { .ival = "mmaphuge",
1716                             .oval = MEM_MMAPHUGE,
1717                             .help = "Like mmap, but use huge pages",
1718                           },
1719 #endif
1720                   },
1721         },
1722         {
1723                 .name   = "iomem_align",
1724                 .alias  = "mem_align",
1725                 .type   = FIO_OPT_INT,
1726                 .off1   = td_var_offset(mem_align),
1727                 .minval = 0,
1728                 .help   = "IO memory buffer offset alignment",
1729                 .def    = "0",
1730                 .parent = "iomem",
1731         },
1732         {
1733                 .name   = "verify",
1734                 .type   = FIO_OPT_STR,
1735                 .off1   = td_var_offset(verify),
1736                 .help   = "Verify data written",
1737                 .cb     = str_verify_cb,
1738                 .def    = "0",
1739                 .posval = {
1740                           { .ival = "0",
1741                             .oval = VERIFY_NONE,
1742                             .help = "Don't do IO verification",
1743                           },
1744                           { .ival = "md5",
1745                             .oval = VERIFY_MD5,
1746                             .help = "Use md5 checksums for verification",
1747                           },
1748                           { .ival = "crc64",
1749                             .oval = VERIFY_CRC64,
1750                             .help = "Use crc64 checksums for verification",
1751                           },
1752                           { .ival = "crc32",
1753                             .oval = VERIFY_CRC32,
1754                             .help = "Use crc32 checksums for verification",
1755                           },
1756                           { .ival = "crc32c-intel",
1757                             .oval = VERIFY_CRC32C,
1758                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1759                           },
1760                           { .ival = "crc32c",
1761                             .oval = VERIFY_CRC32C,
1762                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1763                           },
1764                           { .ival = "crc16",
1765                             .oval = VERIFY_CRC16,
1766                             .help = "Use crc16 checksums for verification",
1767                           },
1768                           { .ival = "crc7",
1769                             .oval = VERIFY_CRC7,
1770                             .help = "Use crc7 checksums for verification",
1771                           },
1772                           { .ival = "sha1",
1773                             .oval = VERIFY_SHA1,
1774                             .help = "Use sha1 checksums for verification",
1775                           },
1776                           { .ival = "sha256",
1777                             .oval = VERIFY_SHA256,
1778                             .help = "Use sha256 checksums for verification",
1779                           },
1780                           { .ival = "sha512",
1781                             .oval = VERIFY_SHA512,
1782                             .help = "Use sha512 checksums for verification",
1783                           },
1784                           { .ival = "meta",
1785                             .oval = VERIFY_META,
1786                             .help = "Use io information",
1787                           },
1788                           {
1789                             .ival = "null",
1790                             .oval = VERIFY_NULL,
1791                             .help = "Pretend to verify",
1792                           },
1793                 },
1794         },
1795         {
1796                 .name   = "do_verify",
1797                 .type   = FIO_OPT_BOOL,
1798                 .off1   = td_var_offset(do_verify),
1799                 .help   = "Run verification stage after write",
1800                 .def    = "1",
1801                 .parent = "verify",
1802         },
1803         {
1804                 .name   = "verifysort",
1805                 .type   = FIO_OPT_BOOL,
1806                 .off1   = td_var_offset(verifysort),
1807                 .help   = "Sort written verify blocks for read back",
1808                 .def    = "1",
1809                 .parent = "verify",
1810         },
1811         {
1812                 .name   = "verify_interval",
1813                 .type   = FIO_OPT_INT,
1814                 .off1   = td_var_offset(verify_interval),
1815                 .minval = 2 * sizeof(struct verify_header),
1816                 .help   = "Store verify buffer header every N bytes",
1817                 .parent = "verify",
1818         },
1819         {
1820                 .name   = "verify_offset",
1821                 .type   = FIO_OPT_INT,
1822                 .help   = "Offset verify header location by N bytes",
1823                 .def    = "0",
1824                 .cb     = str_verify_offset_cb,
1825                 .parent = "verify",
1826         },
1827         {
1828                 .name   = "verify_pattern",
1829                 .type   = FIO_OPT_STR,
1830                 .cb     = str_verify_pattern_cb,
1831                 .help   = "Fill pattern for IO buffers",
1832                 .parent = "verify",
1833         },
1834         {
1835                 .name   = "verify_fatal",
1836                 .type   = FIO_OPT_BOOL,
1837                 .off1   = td_var_offset(verify_fatal),
1838                 .def    = "0",
1839                 .help   = "Exit on a single verify failure, don't continue",
1840                 .parent = "verify",
1841         },
1842         {
1843                 .name   = "verify_dump",
1844                 .type   = FIO_OPT_BOOL,
1845                 .off1   = td_var_offset(verify_dump),
1846                 .def    = "0",
1847                 .help   = "Dump contents of good and bad blocks on failure",
1848                 .parent = "verify",
1849         },
1850         {
1851                 .name   = "verify_async",
1852                 .type   = FIO_OPT_INT,
1853                 .off1   = td_var_offset(verify_async),
1854                 .def    = "0",
1855                 .help   = "Number of async verifier threads to use",
1856                 .parent = "verify",
1857         },
1858         {
1859                 .name   = "verify_backlog",
1860                 .type   = FIO_OPT_STR_VAL,
1861                 .off1   = td_var_offset(verify_backlog),
1862                 .help   = "Verify after this number of blocks are written",
1863                 .parent = "verify",
1864         },
1865         {
1866                 .name   = "verify_backlog_batch",
1867                 .type   = FIO_OPT_INT,
1868                 .off1   = td_var_offset(verify_batch),
1869                 .help   = "Verify this number of IO blocks",
1870                 .parent = "verify",
1871         },
1872 #ifdef FIO_HAVE_CPU_AFFINITY
1873         {
1874                 .name   = "verify_async_cpus",
1875                 .type   = FIO_OPT_STR,
1876                 .cb     = str_verify_cpus_allowed_cb,
1877                 .help   = "Set CPUs allowed for async verify threads",
1878                 .parent = "verify_async",
1879         },
1880 #endif
1881 #ifdef FIO_HAVE_TRIM
1882         {
1883                 .name   = "trim_percentage",
1884                 .type   = FIO_OPT_INT,
1885                 .cb     = str_verify_trim_cb,
1886                 .maxval = 100,
1887                 .help   = "Number of verify blocks to discard/trim",
1888                 .parent = "verify",
1889                 .def    = "0",
1890         },
1891         {
1892                 .name   = "trim_verify_zero",
1893                 .type   = FIO_OPT_INT,
1894                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
1895                 .off1   = td_var_offset(trim_zero),
1896                 .parent = "trim_percentage",
1897                 .def    = "1",
1898         },
1899         {
1900                 .name   = "trim_backlog",
1901                 .type   = FIO_OPT_STR_VAL,
1902                 .off1   = td_var_offset(trim_backlog),
1903                 .help   = "Trim after this number of blocks are written",
1904                 .parent = "trim_percentage",
1905         },
1906         {
1907                 .name   = "trim_backlog_batch",
1908                 .type   = FIO_OPT_INT,
1909                 .off1   = td_var_offset(trim_batch),
1910                 .help   = "Trim this number of IO blocks",
1911                 .parent = "trim_percentage",
1912         },
1913 #endif
1914         {
1915                 .name   = "write_iolog",
1916                 .type   = FIO_OPT_STR_STORE,
1917                 .off1   = td_var_offset(write_iolog_file),
1918                 .help   = "Store IO pattern to file",
1919         },
1920         {
1921                 .name   = "read_iolog",
1922                 .type   = FIO_OPT_STR_STORE,
1923                 .off1   = td_var_offset(read_iolog_file),
1924                 .help   = "Playback IO pattern from file",
1925         },
1926         {
1927                 .name   = "replay_no_stall",
1928                 .type   = FIO_OPT_INT,
1929                 .off1   = td_var_offset(no_stall),
1930                 .def    = "0",
1931                 .parent = "read_iolog",
1932                 .help   = "Playback IO pattern file as fast as possible without stalls",
1933         },
1934         {
1935                 .name   = "replay_redirect",
1936                 .type   = FIO_OPT_STR_STORE,
1937                 .off1   = td_var_offset(replay_redirect),
1938                 .parent = "read_iolog",
1939                 .help   = "Replay all I/O onto this device, regardless of trace device",
1940         },
1941         {
1942                 .name   = "exec_prerun",
1943                 .type   = FIO_OPT_STR_STORE,
1944                 .off1   = td_var_offset(exec_prerun),
1945                 .help   = "Execute this file prior to running job",
1946         },
1947         {
1948                 .name   = "exec_postrun",
1949                 .type   = FIO_OPT_STR_STORE,
1950                 .off1   = td_var_offset(exec_postrun),
1951                 .help   = "Execute this file after running job",
1952         },
1953 #ifdef FIO_HAVE_IOSCHED_SWITCH
1954         {
1955                 .name   = "ioscheduler",
1956                 .type   = FIO_OPT_STR_STORE,
1957                 .off1   = td_var_offset(ioscheduler),
1958                 .help   = "Use this IO scheduler on the backing device",
1959         },
1960 #endif
1961         {
1962                 .name   = "zonesize",
1963                 .type   = FIO_OPT_STR_VAL,
1964                 .off1   = td_var_offset(zone_size),
1965                 .help   = "Amount of data to read per zone",
1966                 .def    = "0",
1967         },
1968         {
1969                 .name   = "zonerange",
1970                 .type   = FIO_OPT_STR_VAL,
1971                 .off1   = td_var_offset(zone_range),
1972                 .help   = "Give size of an IO zone",
1973                 .def    = "0",
1974         },
1975         {
1976                 .name   = "zoneskip",
1977                 .type   = FIO_OPT_STR_VAL,
1978                 .off1   = td_var_offset(zone_skip),
1979                 .help   = "Space between IO zones",
1980                 .def    = "0",
1981         },
1982         {
1983                 .name   = "lockmem",
1984                 .type   = FIO_OPT_STR_VAL,
1985                 .cb     = str_lockmem_cb,
1986                 .help   = "Lock down this amount of memory",
1987                 .def    = "0",
1988         },
1989         {
1990                 .name   = "rwmixread",
1991                 .type   = FIO_OPT_INT,
1992                 .cb     = str_rwmix_read_cb,
1993                 .maxval = 100,
1994                 .help   = "Percentage of mixed workload that is reads",
1995                 .def    = "50",
1996         },
1997         {
1998                 .name   = "rwmixwrite",
1999                 .type   = FIO_OPT_INT,
2000                 .cb     = str_rwmix_write_cb,
2001                 .maxval = 100,
2002                 .help   = "Percentage of mixed workload that is writes",
2003                 .def    = "50",
2004         },
2005         {
2006                 .name   = "rwmixcycle",
2007                 .type   = FIO_OPT_DEPRECATED,
2008         },
2009         {
2010                 .name   = "nice",
2011                 .type   = FIO_OPT_INT,
2012                 .off1   = td_var_offset(nice),
2013                 .help   = "Set job CPU nice value",
2014                 .minval = -19,
2015                 .maxval = 20,
2016                 .def    = "0",
2017         },
2018 #ifdef FIO_HAVE_IOPRIO
2019         {
2020                 .name   = "prio",
2021                 .type   = FIO_OPT_INT,
2022                 .cb     = str_prio_cb,
2023                 .help   = "Set job IO priority value",
2024                 .minval = 0,
2025                 .maxval = 7,
2026         },
2027         {
2028                 .name   = "prioclass",
2029                 .type   = FIO_OPT_INT,
2030                 .cb     = str_prioclass_cb,
2031                 .help   = "Set job IO priority class",
2032                 .minval = 0,
2033                 .maxval = 3,
2034         },
2035 #endif
2036         {
2037                 .name   = "thinktime",
2038                 .type   = FIO_OPT_INT,
2039                 .off1   = td_var_offset(thinktime),
2040                 .help   = "Idle time between IO buffers (usec)",
2041                 .def    = "0",
2042         },
2043         {
2044                 .name   = "thinktime_spin",
2045                 .type   = FIO_OPT_INT,
2046                 .off1   = td_var_offset(thinktime_spin),
2047                 .help   = "Start think time by spinning this amount (usec)",
2048                 .def    = "0",
2049                 .parent = "thinktime",
2050         },
2051         {
2052                 .name   = "thinktime_blocks",
2053                 .type   = FIO_OPT_INT,
2054                 .off1   = td_var_offset(thinktime_blocks),
2055                 .help   = "IO buffer period between 'thinktime'",
2056                 .def    = "1",
2057                 .parent = "thinktime",
2058         },
2059         {
2060                 .name   = "rate",
2061                 .type   = FIO_OPT_INT,
2062                 .off1   = td_var_offset(rate[DDIR_READ]),
2063                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2064                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2065                 .help   = "Set bandwidth rate",
2066         },
2067         {
2068                 .name   = "ratemin",
2069                 .type   = FIO_OPT_INT,
2070                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2071                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2072                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2073                 .help   = "Job must meet this rate or it will be shutdown",
2074                 .parent = "rate",
2075         },
2076         {
2077                 .name   = "rate_iops",
2078                 .type   = FIO_OPT_INT,
2079                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2080                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2081                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2082                 .help   = "Limit IO used to this number of IO operations/sec",
2083         },
2084         {
2085                 .name   = "rate_iops_min",
2086                 .type   = FIO_OPT_INT,
2087                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2088                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2089                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2090                 .help   = "Job must meet this rate or it will be shut down",
2091                 .parent = "rate_iops",
2092         },
2093         {
2094                 .name   = "ratecycle",
2095                 .type   = FIO_OPT_INT,
2096                 .off1   = td_var_offset(ratecycle),
2097                 .help   = "Window average for rate limits (msec)",
2098                 .def    = "1000",
2099                 .parent = "rate",
2100         },
2101         {
2102                 .name   = "max_latency",
2103                 .type   = FIO_OPT_INT,
2104                 .off1   = td_var_offset(max_latency),
2105                 .help   = "Maximum tolerated IO latency (usec)",
2106         },
2107         {
2108                 .name   = "invalidate",
2109                 .type   = FIO_OPT_BOOL,
2110                 .off1   = td_var_offset(invalidate_cache),
2111                 .help   = "Invalidate buffer/page cache prior to running job",
2112                 .def    = "1",
2113         },
2114         {
2115                 .name   = "sync",
2116                 .type   = FIO_OPT_BOOL,
2117                 .off1   = td_var_offset(sync_io),
2118                 .help   = "Use O_SYNC for buffered writes",
2119                 .def    = "0",
2120                 .parent = "buffered",
2121         },
2122         {
2123                 .name   = "bwavgtime",
2124                 .type   = FIO_OPT_INT,
2125                 .off1   = td_var_offset(bw_avg_time),
2126                 .help   = "Time window over which to calculate bandwidth"
2127                           " (msec)",
2128                 .def    = "500",
2129                 .parent = "write_bw_log",
2130         },
2131         {
2132                 .name   = "iopsavgtime",
2133                 .type   = FIO_OPT_INT,
2134                 .off1   = td_var_offset(iops_avg_time),
2135                 .help   = "Time window over which to calculate IOPS (msec)",
2136                 .def    = "500",
2137                 .parent = "write_iops_log",
2138         },
2139         {
2140                 .name   = "create_serialize",
2141                 .type   = FIO_OPT_BOOL,
2142                 .off1   = td_var_offset(create_serialize),
2143                 .help   = "Serialize creating of job files",
2144                 .def    = "1",
2145         },
2146         {
2147                 .name   = "create_fsync",
2148                 .type   = FIO_OPT_BOOL,
2149                 .off1   = td_var_offset(create_fsync),
2150                 .help   = "fsync file after creation",
2151                 .def    = "1",
2152         },
2153         {
2154                 .name   = "create_on_open",
2155                 .type   = FIO_OPT_BOOL,
2156                 .off1   = td_var_offset(create_on_open),
2157                 .help   = "Create files when they are opened for IO",
2158                 .def    = "0",
2159         },
2160         {
2161                 .name   = "create_only",
2162                 .type   = FIO_OPT_BOOL,
2163                 .off1   = td_var_offset(create_only),
2164                 .help   = "Only perform file creation phase",
2165                 .def    = "0",
2166         },
2167         {
2168                 .name   = "pre_read",
2169                 .type   = FIO_OPT_BOOL,
2170                 .off1   = td_var_offset(pre_read),
2171                 .help   = "Pre-read files before starting official testing",
2172                 .def    = "0",
2173         },
2174         {
2175                 .name   = "cpuload",
2176                 .type   = FIO_OPT_INT,
2177                 .off1   = td_var_offset(cpuload),
2178                 .help   = "Use this percentage of CPU",
2179         },
2180         {
2181                 .name   = "cpuchunks",
2182                 .type   = FIO_OPT_INT,
2183                 .off1   = td_var_offset(cpucycle),
2184                 .help   = "Length of the CPU burn cycles (usecs)",
2185                 .def    = "50000",
2186                 .parent = "cpuload",
2187         },
2188 #ifdef FIO_HAVE_CPU_AFFINITY
2189         {
2190                 .name   = "cpumask",
2191                 .type   = FIO_OPT_INT,
2192                 .cb     = str_cpumask_cb,
2193                 .help   = "CPU affinity mask",
2194         },
2195         {
2196                 .name   = "cpus_allowed",
2197                 .type   = FIO_OPT_STR,
2198                 .cb     = str_cpus_allowed_cb,
2199                 .help   = "Set CPUs allowed",
2200         },
2201 #endif
2202 #ifdef FIO_HAVE_LIBNUMA
2203         {
2204                 .name   = "numa_cpu_nodes",
2205                 .type   = FIO_OPT_STR,
2206                 .cb     = str_numa_cpunodes_cb,
2207                 .help   = "NUMA CPU nodes bind",
2208         },
2209         {
2210                 .name   = "numa_mem_policy",
2211                 .type   = FIO_OPT_STR,
2212                 .cb     = str_numa_mpol_cb,
2213                 .help   = "NUMA memory policy setup",
2214         },
2215 #endif
2216         {
2217                 .name   = "end_fsync",
2218                 .type   = FIO_OPT_BOOL,
2219                 .off1   = td_var_offset(end_fsync),
2220                 .help   = "Include fsync at the end of job",
2221                 .def    = "0",
2222         },
2223         {
2224                 .name   = "fsync_on_close",
2225                 .type   = FIO_OPT_BOOL,
2226                 .off1   = td_var_offset(fsync_on_close),
2227                 .help   = "fsync files on close",
2228                 .def    = "0",
2229         },
2230         {
2231                 .name   = "unlink",
2232                 .type   = FIO_OPT_BOOL,
2233                 .off1   = td_var_offset(unlink),
2234                 .help   = "Unlink created files after job has completed",
2235                 .def    = "0",
2236         },
2237         {
2238                 .name   = "exitall",
2239                 .type   = FIO_OPT_STR_SET,
2240                 .cb     = str_exitall_cb,
2241                 .help   = "Terminate all jobs when one exits",
2242         },
2243         {
2244                 .name   = "stonewall",
2245                 .alias  = "wait_for_previous",
2246                 .type   = FIO_OPT_STR_SET,
2247                 .off1   = td_var_offset(stonewall),
2248                 .help   = "Insert a hard barrier between this job and previous",
2249         },
2250         {
2251                 .name   = "new_group",
2252                 .type   = FIO_OPT_STR_SET,
2253                 .off1   = td_var_offset(new_group),
2254                 .help   = "Mark the start of a new group (for reporting)",
2255         },
2256         {
2257                 .name   = "thread",
2258                 .type   = FIO_OPT_STR_SET,
2259                 .off1   = td_var_offset(use_thread),
2260                 .help   = "Use threads instead of forks",
2261         },
2262         {
2263                 .name   = "write_bw_log",
2264                 .type   = FIO_OPT_STR,
2265                 .off1   = td_var_offset(write_bw_log),
2266                 .cb     = str_write_bw_log_cb,
2267                 .help   = "Write log of bandwidth during run",
2268         },
2269         {
2270                 .name   = "write_lat_log",
2271                 .type   = FIO_OPT_STR,
2272                 .off1   = td_var_offset(write_lat_log),
2273                 .cb     = str_write_lat_log_cb,
2274                 .help   = "Write log of latency during run",
2275         },
2276         {
2277                 .name   = "write_iops_log",
2278                 .type   = FIO_OPT_STR,
2279                 .off1   = td_var_offset(write_iops_log),
2280                 .cb     = str_write_iops_log_cb,
2281                 .help   = "Write log of IOPS during run",
2282         },
2283         {
2284                 .name   = "log_avg_msec",
2285                 .type   = FIO_OPT_INT,
2286                 .off1   = td_var_offset(log_avg_msec),
2287                 .help   = "Average bw/iops/lat logs over this period of time",
2288                 .def    = "0",
2289         },
2290         {
2291                 .name   = "hugepage-size",
2292                 .type   = FIO_OPT_INT,
2293                 .off1   = td_var_offset(hugepage_size),
2294                 .help   = "When using hugepages, specify size of each page",
2295                 .def    = __fio_stringify(FIO_HUGE_PAGE),
2296         },
2297         {
2298                 .name   = "group_reporting",
2299                 .type   = FIO_OPT_STR_SET,
2300                 .off1   = td_var_offset(group_reporting),
2301                 .help   = "Do reporting on a per-group basis",
2302         },
2303         {
2304                 .name   = "zero_buffers",
2305                 .type   = FIO_OPT_STR_SET,
2306                 .off1   = td_var_offset(zero_buffers),
2307                 .help   = "Init IO buffers to all zeroes",
2308         },
2309         {
2310                 .name   = "refill_buffers",
2311                 .type   = FIO_OPT_STR_SET,
2312                 .off1   = td_var_offset(refill_buffers),
2313                 .help   = "Refill IO buffers on every IO submit",
2314         },
2315         {
2316                 .name   = "scramble_buffers",
2317                 .type   = FIO_OPT_BOOL,
2318                 .off1   = td_var_offset(scramble_buffers),
2319                 .help   = "Slightly scramble buffers on every IO submit",
2320                 .def    = "1",
2321         },
2322         {
2323                 .name   = "buffer_compress_percentage",
2324                 .type   = FIO_OPT_INT,
2325                 .off1   = td_var_offset(compress_percentage),
2326                 .maxval = 100,
2327                 .minval = 1,
2328                 .help   = "How compressible the buffer is (approximately)",
2329         },
2330         {
2331                 .name   = "buffer_compress_chunk",
2332                 .type   = FIO_OPT_INT,
2333                 .off1   = td_var_offset(compress_chunk),
2334                 .parent = "buffer_compress_percentage",
2335                 .help   = "Size of compressible region in buffer",
2336         },
2337         {
2338                 .name   = "clat_percentiles",
2339                 .type   = FIO_OPT_BOOL,
2340                 .off1   = td_var_offset(clat_percentiles),
2341                 .help   = "Enable the reporting of completion latency percentiles",
2342                 .def    = "1",
2343         },
2344         {
2345                 .name   = "percentile_list",
2346                 .type   = FIO_OPT_FLOAT_LIST,
2347                 .off1   = td_var_offset(percentile_list),
2348                 .off2   = td_var_offset(overwrite_plist),
2349                 .help   = "Specify a custom list of percentiles to report",
2350                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2351                 .minfp  = 0.0,
2352                 .maxfp  = 100.0,
2353         },
2354
2355 #ifdef FIO_HAVE_DISK_UTIL
2356         {
2357                 .name   = "disk_util",
2358                 .type   = FIO_OPT_BOOL,
2359                 .off1   = td_var_offset(do_disk_util),
2360                 .help   = "Log disk utilization statistics",
2361                 .def    = "1",
2362         },
2363 #endif
2364         {
2365                 .name   = "gtod_reduce",
2366                 .type   = FIO_OPT_BOOL,
2367                 .help   = "Greatly reduce number of gettimeofday() calls",
2368                 .cb     = str_gtod_reduce_cb,
2369                 .def    = "0",
2370         },
2371         {
2372                 .name   = "disable_lat",
2373                 .type   = FIO_OPT_BOOL,
2374                 .off1   = td_var_offset(disable_lat),
2375                 .help   = "Disable latency numbers",
2376                 .parent = "gtod_reduce",
2377                 .def    = "0",
2378         },
2379         {
2380                 .name   = "disable_clat",
2381                 .type   = FIO_OPT_BOOL,
2382                 .off1   = td_var_offset(disable_clat),
2383                 .help   = "Disable completion latency numbers",
2384                 .parent = "gtod_reduce",
2385                 .def    = "0",
2386         },
2387         {
2388                 .name   = "disable_slat",
2389                 .type   = FIO_OPT_BOOL,
2390                 .off1   = td_var_offset(disable_slat),
2391                 .help   = "Disable submission latency numbers",
2392                 .parent = "gtod_reduce",
2393                 .def    = "0",
2394         },
2395         {
2396                 .name   = "disable_bw_measurement",
2397                 .type   = FIO_OPT_BOOL,
2398                 .off1   = td_var_offset(disable_bw),
2399                 .help   = "Disable bandwidth logging",
2400                 .parent = "gtod_reduce",
2401                 .def    = "0",
2402         },
2403         {
2404                 .name   = "gtod_cpu",
2405                 .type   = FIO_OPT_INT,
2406                 .cb     = str_gtod_cpu_cb,
2407                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2408                 .verify = gtod_cpu_verify,
2409         },
2410         {
2411                 .name   = "continue_on_error",
2412                 .type   = FIO_OPT_STR,
2413                 .off1   = td_var_offset(continue_on_error),
2414                 .help   = "Continue on non-fatal errors during IO",
2415                 .def    = "none",
2416                 .posval = {
2417                           { .ival = "none",
2418                             .oval = ERROR_TYPE_NONE,
2419                             .help = "Exit when an error is encountered",
2420                           },
2421                           { .ival = "read",
2422                             .oval = ERROR_TYPE_READ,
2423                             .help = "Continue on read errors only",
2424                           },
2425                           { .ival = "write",
2426                             .oval = ERROR_TYPE_WRITE,
2427                             .help = "Continue on write errors only",
2428                           },
2429                           { .ival = "io",
2430                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2431                             .help = "Continue on any IO errors",
2432                           },
2433                           { .ival = "verify",
2434                             .oval = ERROR_TYPE_VERIFY,
2435                             .help = "Continue on verify errors only",
2436                           },
2437                           { .ival = "all",
2438                             .oval = ERROR_TYPE_ANY,
2439                             .help = "Continue on all io and verify errors",
2440                           },
2441                           { .ival = "0",
2442                             .oval = ERROR_TYPE_NONE,
2443                             .help = "Alias for 'none'",
2444                           },
2445                           { .ival = "1",
2446                             .oval = ERROR_TYPE_ANY,
2447                             .help = "Alias for 'all'",
2448                           },
2449                 },
2450         },
2451         {
2452                 .name   = "ignore_error",
2453                 .type   = FIO_OPT_STR,
2454                 .cb     = str_ignore_error_cb,
2455                 .help   = "Set a specific list of errors to ignore",
2456                 .parent = "rw",
2457         },
2458         {
2459                 .name   = "error_dump",
2460                 .type   = FIO_OPT_BOOL,
2461                 .off1   = td_var_offset(error_dump),
2462                 .def    = "0",
2463                 .help   = "Dump info on each error",
2464         },
2465
2466         {
2467                 .name   = "profile",
2468                 .type   = FIO_OPT_STR_STORE,
2469                 .off1   = td_var_offset(profile),
2470                 .help   = "Select a specific builtin performance test",
2471         },
2472         {
2473                 .name   = "cgroup",
2474                 .type   = FIO_OPT_STR_STORE,
2475                 .off1   = td_var_offset(cgroup),
2476                 .help   = "Add job to cgroup of this name",
2477         },
2478         {
2479                 .name   = "cgroup_weight",
2480                 .type   = FIO_OPT_INT,
2481                 .off1   = td_var_offset(cgroup_weight),
2482                 .help   = "Use given weight for cgroup",
2483                 .minval = 100,
2484                 .maxval = 1000,
2485         },
2486         {
2487                 .name   = "cgroup_nodelete",
2488                 .type   = FIO_OPT_BOOL,
2489                 .off1   = td_var_offset(cgroup_nodelete),
2490                 .help   = "Do not delete cgroups after job completion",
2491                 .def    = "0",
2492         },
2493         {
2494                 .name   = "uid",
2495                 .type   = FIO_OPT_INT,
2496                 .off1   = td_var_offset(uid),
2497                 .help   = "Run job with this user ID",
2498         },
2499         {
2500                 .name   = "gid",
2501                 .type   = FIO_OPT_INT,
2502                 .off1   = td_var_offset(gid),
2503                 .help   = "Run job with this group ID",
2504         },
2505         {
2506                 .name   = "flow_id",
2507                 .type   = FIO_OPT_INT,
2508                 .off1   = td_var_offset(flow_id),
2509                 .help   = "The flow index ID to use",
2510                 .def    = "0",
2511         },
2512         {
2513                 .name   = "flow",
2514                 .type   = FIO_OPT_INT,
2515                 .off1   = td_var_offset(flow),
2516                 .help   = "Weight for flow control of this job",
2517                 .parent = "flow_id",
2518                 .def    = "0",
2519         },
2520         {
2521                 .name   = "flow_watermark",
2522                 .type   = FIO_OPT_INT,
2523                 .off1   = td_var_offset(flow_watermark),
2524                 .help   = "High watermark for flow control. This option"
2525                         " should be set to the same value for all threads"
2526                         " with non-zero flow.",
2527                 .parent = "flow_id",
2528                 .def    = "1024",
2529         },
2530         {
2531                 .name   = "flow_sleep",
2532                 .type   = FIO_OPT_INT,
2533                 .off1   = td_var_offset(flow_sleep),
2534                 .help   = "How many microseconds to sleep after being held"
2535                         " back by the flow control mechanism",
2536                 .parent = "flow_id",
2537                 .def    = "0",
2538         },
2539         {
2540                 .name = NULL,
2541         },
2542 };
2543
2544 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2545                         const char *name, int val)
2546 {
2547         lopt->name = (char *) name;
2548         lopt->val = val;
2549         if (o->type == FIO_OPT_STR_SET)
2550                 lopt->has_arg = no_argument;
2551         else
2552                 lopt->has_arg = required_argument;
2553 }
2554
2555 static void options_to_lopts(struct fio_option *opts,
2556                               struct option *long_options,
2557                               int i, int option_type)
2558 {
2559         struct fio_option *o = &opts[0];
2560         while (o->name) {
2561                 add_to_lopt(&long_options[i], o, o->name, option_type);
2562                 if (o->alias) {
2563                         i++;
2564                         add_to_lopt(&long_options[i], o, o->alias, option_type);
2565                 }
2566
2567                 i++;
2568                 o++;
2569                 assert(i < FIO_NR_OPTIONS);
2570         }
2571 }
2572
2573 void fio_options_set_ioengine_opts(struct option *long_options,
2574                                    struct thread_data *td)
2575 {
2576         unsigned int i;
2577
2578         i = 0;
2579         while (long_options[i].name) {
2580                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2581                         memset(&long_options[i], 0, sizeof(*long_options));
2582                         break;
2583                 }
2584                 i++;
2585         }
2586
2587         /*
2588          * Just clear out the prior ioengine options.
2589          */
2590         if (!td || !td->eo)
2591                 return;
2592
2593         options_to_lopts(td->io_ops->options, long_options, i,
2594                          FIO_GETOPT_IOENGINE);
2595 }
2596
2597 void fio_options_dup_and_init(struct option *long_options)
2598 {
2599         unsigned int i;
2600
2601         options_init(options);
2602
2603         i = 0;
2604         while (long_options[i].name)
2605                 i++;
2606
2607         options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
2608 }
2609
2610 struct fio_keyword {
2611         const char *word;
2612         const char *desc;
2613         char *replace;
2614 };
2615
2616 static struct fio_keyword fio_keywords[] = {
2617         {
2618                 .word   = "$pagesize",
2619                 .desc   = "Page size in the system",
2620         },
2621         {
2622                 .word   = "$mb_memory",
2623                 .desc   = "Megabytes of memory online",
2624         },
2625         {
2626                 .word   = "$ncpus",
2627                 .desc   = "Number of CPUs online in the system",
2628         },
2629         {
2630                 .word   = NULL,
2631         },
2632 };
2633
2634 void fio_keywords_init(void)
2635 {
2636         unsigned long long mb_memory;
2637         char buf[128];
2638         long l;
2639
2640         sprintf(buf, "%lu", (unsigned long) page_size);
2641         fio_keywords[0].replace = strdup(buf);
2642
2643         mb_memory = os_phys_mem() / (1024 * 1024);
2644         sprintf(buf, "%llu", mb_memory);
2645         fio_keywords[1].replace = strdup(buf);
2646
2647         l = cpus_online();
2648         sprintf(buf, "%lu", l);
2649         fio_keywords[2].replace = strdup(buf);
2650 }
2651
2652 #define BC_APP          "bc"
2653
2654 static char *bc_calc(char *str)
2655 {
2656         char buf[128], *tmp;
2657         FILE *f;
2658         int ret;
2659
2660         /*
2661          * No math, just return string
2662          */
2663         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2664              !strchr(str, '/')) || strchr(str, '\''))
2665                 return str;
2666
2667         /*
2668          * Split option from value, we only need to calculate the value
2669          */
2670         tmp = strchr(str, '=');
2671         if (!tmp)
2672                 return str;
2673
2674         tmp++;
2675
2676         /*
2677          * Prevent buffer overflows; such a case isn't reasonable anyway
2678          */
2679         if (strlen(str) >= 128 || strlen(tmp) > 100)
2680                 return str;
2681
2682         sprintf(buf, "which %s > /dev/null", BC_APP);
2683         if (system(buf)) {
2684                 log_err("fio: bc is needed for performing math\n");
2685                 return NULL;
2686         }
2687
2688         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2689         f = popen(buf, "r");
2690         if (!f) {
2691                 return NULL;
2692         }
2693
2694         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2695         if (ret <= 0) {
2696                 return NULL;
2697         }
2698
2699         pclose(f);
2700         buf[(tmp - str) + ret - 1] = '\0';
2701         memcpy(buf, str, tmp - str);
2702         free(str);
2703         return strdup(buf);
2704 }
2705
2706 /*
2707  * Return a copy of the input string with substrings of the form ${VARNAME}
2708  * substituted with the value of the environment variable VARNAME.  The
2709  * substitution always occurs, even if VARNAME is empty or the corresponding
2710  * environment variable undefined.
2711  */
2712 static char *option_dup_subs(const char *opt)
2713 {
2714         char out[OPT_LEN_MAX+1];
2715         char in[OPT_LEN_MAX+1];
2716         char *outptr = out;
2717         char *inptr = in;
2718         char *ch1, *ch2, *env;
2719         ssize_t nchr = OPT_LEN_MAX;
2720         size_t envlen;
2721
2722         if (strlen(opt) + 1 > OPT_LEN_MAX) {
2723                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2724                 return NULL;
2725         }
2726
2727         in[OPT_LEN_MAX] = '\0';
2728         strncpy(in, opt, OPT_LEN_MAX);
2729
2730         while (*inptr && nchr > 0) {
2731                 if (inptr[0] == '$' && inptr[1] == '{') {
2732                         ch2 = strchr(inptr, '}');
2733                         if (ch2 && inptr+1 < ch2) {
2734                                 ch1 = inptr+2;
2735                                 inptr = ch2+1;
2736                                 *ch2 = '\0';
2737
2738                                 env = getenv(ch1);
2739                                 if (env) {
2740                                         envlen = strlen(env);
2741                                         if (envlen <= nchr) {
2742                                                 memcpy(outptr, env, envlen);
2743                                                 outptr += envlen;
2744                                                 nchr -= envlen;
2745                                         }
2746                                 }
2747
2748                                 continue;
2749                         }
2750                 }
2751
2752                 *outptr++ = *inptr++;
2753                 --nchr;
2754         }
2755
2756         *outptr = '\0';
2757         return strdup(out);
2758 }
2759
2760 /*
2761  * Look for reserved variable names and replace them with real values
2762  */
2763 static char *fio_keyword_replace(char *opt)
2764 {
2765         char *s;
2766         int i;
2767         int docalc = 0;
2768
2769         for (i = 0; fio_keywords[i].word != NULL; i++) {
2770                 struct fio_keyword *kw = &fio_keywords[i];
2771
2772                 while ((s = strstr(opt, kw->word)) != NULL) {
2773                         char *new = malloc(strlen(opt) + 1);
2774                         char *o_org = opt;
2775                         int olen = s - opt;
2776                         int len;
2777
2778                         /*
2779                          * Copy part of the string before the keyword and
2780                          * sprintf() the replacement after it.
2781                          */
2782                         memcpy(new, opt, olen);
2783                         len = sprintf(new + olen, "%s", kw->replace);
2784
2785                         /*
2786                          * If there's more in the original string, copy that
2787                          * in too
2788                          */
2789                         opt += strlen(kw->word) + olen;
2790                         if (strlen(opt))
2791                                 memcpy(new + olen + len, opt, opt - o_org - 1);
2792
2793                         /*
2794                          * replace opt and free the old opt
2795                          */
2796                         opt = new;
2797                         free(o_org);
2798
2799                         docalc = 1;
2800                 }
2801         }
2802
2803         /*
2804          * Check for potential math and invoke bc, if possible
2805          */
2806         if (docalc)
2807                 opt = bc_calc(opt);
2808
2809         return opt;
2810 }
2811
2812 static char **dup_and_sub_options(char **opts, int num_opts)
2813 {
2814         int i;
2815         char **opts_copy = malloc(num_opts * sizeof(*opts));
2816         for (i = 0; i < num_opts; i++) {
2817                 opts_copy[i] = option_dup_subs(opts[i]);
2818                 if (!opts_copy[i])
2819                         continue;
2820                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2821         }
2822         return opts_copy;
2823 }
2824
2825 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2826 {
2827         int i, ret, unknown;
2828         char **opts_copy;
2829
2830         sort_options(opts, options, num_opts);
2831         opts_copy = dup_and_sub_options(opts, num_opts);
2832
2833         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2834                 struct fio_option *o;
2835                 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2836                                           td);
2837
2838                 if (opts_copy[i]) {
2839                         if (newret && !o) {
2840                                 unknown++;
2841                                 continue;
2842                         }
2843                         free(opts_copy[i]);
2844                         opts_copy[i] = NULL;
2845                 }
2846
2847                 ret |= newret;
2848         }
2849
2850         if (unknown) {
2851                 ret |= ioengine_load(td);
2852                 if (td->eo) {
2853                         sort_options(opts_copy, td->io_ops->options, num_opts);
2854                         opts = opts_copy;
2855                 }
2856                 for (i = 0; i < num_opts; i++) {
2857                         struct fio_option *o = NULL;
2858                         int newret = 1;
2859                         if (!opts_copy[i])
2860                                 continue;
2861
2862                         if (td->eo)
2863                                 newret = parse_option(opts_copy[i], opts[i],
2864                                                       td->io_ops->options, &o,
2865                                                       td->eo);
2866
2867                         ret |= newret;
2868                         if (!o)
2869                                 log_err("Bad option <%s>\n", opts[i]);
2870
2871                         free(opts_copy[i]);
2872                         opts_copy[i] = NULL;
2873                 }
2874         }
2875
2876         free(opts_copy);
2877         return ret;
2878 }
2879
2880 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2881 {
2882         return parse_cmd_option(opt, val, options, td);
2883 }
2884
2885 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2886                                 char *val)
2887 {
2888         return parse_cmd_option(opt, val, td->io_ops->options, td);
2889 }
2890
2891 void fio_fill_default_options(struct thread_data *td)
2892 {
2893         fill_default_options(td, options);
2894 }
2895
2896 int fio_show_option_help(const char *opt)
2897 {
2898         return show_cmd_help(options, opt);
2899 }
2900
2901 void options_mem_dupe(void *data, struct fio_option *options)
2902 {
2903         struct fio_option *o;
2904         char **ptr;
2905
2906         for (o = &options[0]; o->name; o++) {
2907                 if (o->type != FIO_OPT_STR_STORE)
2908                         continue;
2909
2910                 ptr = td_var(data, o->off1);
2911                 if (*ptr)
2912                         *ptr = strdup(*ptr);
2913         }
2914 }
2915
2916 /*
2917  * dupe FIO_OPT_STR_STORE options
2918  */
2919 void fio_options_mem_dupe(struct thread_data *td)
2920 {
2921         options_mem_dupe(&td->o, options);
2922
2923         if (td->eo && td->io_ops) {
2924                 void *oldeo = td->eo;
2925
2926                 td->eo = malloc(td->io_ops->option_struct_size);
2927                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2928                 options_mem_dupe(td->eo, td->io_ops->options);
2929         }
2930 }
2931
2932 unsigned int fio_get_kb_base(void *data)
2933 {
2934         struct thread_data *td = data;
2935         unsigned int kb_base = 0;
2936
2937         if (td)
2938                 kb_base = td->o.kb_base;
2939         if (!kb_base)
2940                 kb_base = 1024;
2941
2942         return kb_base;
2943 }
2944
2945 int add_option(struct fio_option *o)
2946 {
2947         struct fio_option *__o;
2948         int opt_index = 0;
2949
2950         __o = options;
2951         while (__o->name) {
2952                 opt_index++;
2953                 __o++;
2954         }
2955
2956         memcpy(&options[opt_index], o, sizeof(*o));
2957         return 0;
2958 }
2959
2960 void invalidate_profile_options(const char *prof_name)
2961 {
2962         struct fio_option *o;
2963
2964         o = options;
2965         while (o->name) {
2966                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2967                         o->type = FIO_OPT_INVALID;
2968                         o->prof_name = NULL;
2969                 }
2970                 o++;
2971         }
2972 }
2973
2974 void add_opt_posval(const char *optname, const char *ival, const char *help)
2975 {
2976         struct fio_option *o;
2977         unsigned int i;
2978
2979         o = find_option(options, optname);
2980         if (!o)
2981                 return;
2982
2983         for (i = 0; i < PARSE_MAX_VP; i++) {
2984                 if (o->posval[i].ival)
2985                         continue;
2986
2987                 o->posval[i].ival = ival;
2988                 o->posval[i].help = help;
2989                 break;
2990         }
2991 }
2992
2993 void del_opt_posval(const char *optname, const char *ival)
2994 {
2995         struct fio_option *o;
2996         unsigned int i;
2997
2998         o = find_option(options, optname);
2999         if (!o)
3000                 return;
3001
3002         for (i = 0; i < PARSE_MAX_VP; i++) {
3003                 if (!o->posval[i].ival)
3004                         continue;
3005                 if (strcmp(o->posval[i].ival, ival))
3006                         continue;
3007
3008                 o->posval[i].ival = NULL;
3009                 o->posval[i].help = NULL;
3010         }
3011 }
3012
3013 void fio_options_free(struct thread_data *td)
3014 {
3015         options_free(options, td);
3016         if (td->eo && td->io_ops && td->io_ops->options) {
3017                 options_free(td->io_ops->options, td->eo);
3018                 free(td->eo);
3019                 td->eo = NULL;
3020         }
3021 }