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