18 #include "crc/crc32c.h"
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
23 static char *get_opt_postfix(const char *str)
25 char *p = strstr(str, ":");
31 strip_blank_front(&p);
36 static int converthexchartoint(char a)
56 static int bs_cmp(const void *p1, const void *p2)
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
61 return bsp1->perc < bsp2->perc;
64 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
66 struct bssplit *bssplit;
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
72 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
78 while ((fname = strsep(&str, ":")) != NULL) {
85 * grow struct buffer, if needed
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));
93 perc_str = strstr(fname, "/");
97 perc = atoi(perc_str);
105 if (str_to_decimal(fname, &val, 1, td)) {
106 log_err("fio: bssplit conversion failed\n");
117 bssplit[i].perc = perc;
121 td->o.bssplit_nr[ddir] = i;
124 * Now check if the percentages add up, and how much is missing
126 perc = perc_missing = 0;
127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
130 if (bsp->perc == (unsigned char) -1)
137 log_err("fio: bssplit percentages add to more than 100%%\n");
142 * If values didn't have a percentage set, divide the remains between
146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
158 * now sort based on percentages, for ease of lookup
160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
166 static int str_bssplit_cb(void *data, const char *input)
168 struct thread_data *td = data;
169 char *str, *p, *odir;
172 p = str = strdup(input);
174 strip_blank_front(&str);
175 strip_blank_end(str);
177 odir = strchr(str, ',');
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
182 ret = bssplit_ddir(td, DDIR_READ, str);
189 ret = bssplit_ddir(td, DDIR_READ, str);
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
200 static int str_rw_cb(void *data, const char *str)
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
205 td->o.ddir_seq_nr = 1;
206 td->o.ddir_seq_add = 0;
212 td->o.ddir_seq_nr = atoi(nr);
216 if (str_to_decimal(nr, &val, 1, td)) {
217 log_err("fio: rw postfix parsing failed\n");
222 td->o.ddir_seq_add = val;
229 static int str_mem_cb(void *data, const char *mem)
231 struct thread_data *td = data;
233 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
234 td->mmapfile = get_opt_postfix(mem);
235 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
236 log_err("fio: mmaphuge:/path/to/file\n");
244 static int str_verify_cb(void *data, const char *mem)
246 struct thread_data *td = data;
248 if (td->o.verify == VERIFY_CRC32C_INTEL ||
249 td->o.verify == VERIFY_CRC32C) {
250 crc32c_intel_probe();
256 static int fio_clock_source_cb(void *data, const char *str)
258 struct thread_data *td = data;
260 fio_clock_source = td->o.clocksource;
265 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
271 static int str_rwmix_read_cb(void *data, unsigned long long *val)
273 struct thread_data *td = data;
275 td->o.rwmix[DDIR_READ] = *val;
276 td->o.rwmix[DDIR_WRITE] = 100 - *val;
280 static int str_rwmix_write_cb(void *data, unsigned long long *val)
282 struct thread_data *td = data;
284 td->o.rwmix[DDIR_WRITE] = *val;
285 td->o.rwmix[DDIR_READ] = 100 - *val;
289 #ifdef FIO_HAVE_IOPRIO
290 static int str_prioclass_cb(void *data, unsigned long long *val)
292 struct thread_data *td = data;
296 * mask off old class bits, str_prio_cb() may have set a default class
298 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
301 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
306 static int str_prio_cb(void *data, unsigned long long *val)
308 struct thread_data *td = data;
313 * If no class is set, assume BE
315 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
316 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
323 static int str_exitall_cb(void)
325 exitall_on_terminate = 1;
329 #ifdef FIO_HAVE_CPU_AFFINITY
330 static int str_cpumask_cb(void *data, unsigned long long *val)
332 struct thread_data *td = data;
337 ret = fio_cpuset_init(&td->o.cpumask);
339 log_err("fio: cpuset_init failed\n");
340 td_verror(td, ret, "fio_cpuset_init");
344 max_cpu = cpus_online();
346 for (i = 0; i < sizeof(int) * 8; i++) {
347 if ((1 << i) & *val) {
349 log_err("fio: CPU %d too large (max=%ld)\n", i,
353 dprint(FD_PARSE, "set cpu allowed %d\n", i);
354 fio_cpu_set(&td->o.cpumask, i);
358 td->o.cpumask_set = 1;
362 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
369 ret = fio_cpuset_init(mask);
371 log_err("fio: cpuset_init failed\n");
372 td_verror(td, ret, "fio_cpuset_init");
376 p = str = strdup(input);
378 strip_blank_front(&str);
379 strip_blank_end(str);
381 max_cpu = cpus_online();
383 while ((cpu = strsep(&str, ",")) != NULL) {
392 while ((cpu2 = strsep(&str2, "-")) != NULL) {
402 while (icpu <= icpu2) {
403 if (icpu >= FIO_MAX_CPUS) {
404 log_err("fio: your OS only supports up to"
405 " %d CPUs\n", (int) FIO_MAX_CPUS);
409 if (icpu > max_cpu) {
410 log_err("fio: CPU %d too large (max=%ld)\n",
416 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
417 fio_cpu_set(mask, icpu);
426 td->o.cpumask_set = 1;
430 static int str_cpus_allowed_cb(void *data, const char *input)
432 struct thread_data *td = data;
435 ret = set_cpus_allowed(td, &td->o.cpumask, input);
437 td->o.cpumask_set = 1;
442 static int str_verify_cpus_allowed_cb(void *data, const char *input)
444 struct thread_data *td = data;
447 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
449 td->o.verify_cpumask_set = 1;
456 static int str_verify_trim_cb(void *data, unsigned long long *val)
458 struct thread_data *td = data;
460 td->o.trim_percentage = *val;
465 static int str_fst_cb(void *data, const char *str)
467 struct thread_data *td = data;
468 char *nr = get_opt_postfix(str);
470 td->file_service_nr = 1;
472 td->file_service_nr = atoi(nr);
479 #ifdef FIO_HAVE_SYNC_FILE_RANGE
480 static int str_sfr_cb(void *data, const char *str)
482 struct thread_data *td = data;
483 char *nr = get_opt_postfix(str);
485 td->sync_file_range_nr = 1;
487 td->sync_file_range_nr = atoi(nr);
495 static int check_dir(struct thread_data *td, char *fname)
498 char file[PATH_MAX], *dir;
501 if (td->o.directory) {
502 strcpy(file, td->o.directory);
507 sprintf(file + elen, "%s", fname);
513 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
514 * yet, so we can't do this check right here...
516 if (lstat(dir, &sb) < 0) {
519 log_err("fio: %s is not a directory\n", dir);
520 td_verror(td, ret, "lstat");
524 if (!S_ISDIR(sb.st_mode)) {
525 log_err("fio: %s is not a directory\n", dir);
535 * Return next file in the string. Files are separated with ':'. If the ':'
536 * is escaped with a '\', then that ':' is part of the filename and does not
537 * indicate a new file.
539 static char *get_next_file_name(char **ptr)
544 if (!str || !strlen(str))
550 * No colon, we are done
552 p = strchr(str, ':');
559 * We got a colon, but it's the first character. Skip and
567 if (*(p - 1) != '\\') {
573 memmove(p - 1, p, strlen(p) + 1);
580 static int str_filename_cb(void *data, const char *input)
582 struct thread_data *td = data;
583 char *fname, *str, *p;
585 p = str = strdup(input);
587 strip_blank_front(&str);
588 strip_blank_end(str);
590 if (!td->files_index)
593 while ((fname = get_next_file_name(&str)) != NULL) {
596 if (check_dir(td, fname)) {
608 static int str_directory_cb(void *data, const char fio_unused *str)
610 struct thread_data *td = data;
613 if (lstat(td->o.directory, &sb) < 0) {
616 log_err("fio: %s is not a directory\n", td->o.directory);
617 td_verror(td, ret, "lstat");
620 if (!S_ISDIR(sb.st_mode)) {
621 log_err("fio: %s is not a directory\n", td->o.directory);
628 static int str_opendir_cb(void *data, const char fio_unused *str)
630 struct thread_data *td = data;
632 if (!td->files_index)
635 return add_dir_files(td, td->o.opendir);
638 static int str_verify_offset_cb(void *data, unsigned long long *off)
640 struct thread_data *td = data;
642 if (*off && *off < sizeof(struct verify_header)) {
643 log_err("fio: verify_offset too small\n");
647 td->o.verify_offset = *off;
651 static int str_verify_pattern_cb(void *data, const char *input)
653 struct thread_data *td = data;
655 int i = 0, j = 0, len, k, base = 10;
658 loc1 = strstr(input, "0x");
659 loc2 = strstr(input, "0X");
662 off = strtol(input, NULL, base);
663 if (off != LONG_MAX || errno != ERANGE) {
665 td->o.verify_pattern[i] = off & 0xff;
674 j = loc1 - input + 2;
676 j = loc2 - input + 2;
679 if (len - j < MAX_PATTERN_SIZE * 2) {
681 off = converthexchartoint(input[k--]);
683 off += (converthexchartoint(input[k--])
685 td->o.verify_pattern[i++] = (char) off;
691 * Fill the pattern all the way to the end. This greatly reduces
692 * the number of memcpy's we have to do when verifying the IO.
694 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
695 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
700 * The code in verify_io_u_pattern assumes a single byte pattern
701 * fills the whole verify pattern buffer.
703 memset(td->o.verify_pattern, td->o.verify_pattern[0],
707 td->o.verify_pattern_bytes = i;
710 * VERIFY_META could already be set
712 if (td->o.verify == VERIFY_NONE)
713 td->o.verify = VERIFY_PATTERN;
718 static int str_lockfile_cb(void *data, const char *str)
720 struct thread_data *td = data;
721 char *nr = get_opt_postfix(str);
723 td->o.lockfile_batch = 1;
725 td->o.lockfile_batch = atoi(nr);
732 static int str_write_bw_log_cb(void *data, const char *str)
734 struct thread_data *td = data;
737 td->o.bw_log_file = strdup(str);
739 td->o.write_bw_log = 1;
743 static int str_write_lat_log_cb(void *data, const char *str)
745 struct thread_data *td = data;
748 td->o.lat_log_file = strdup(str);
750 td->o.write_lat_log = 1;
754 static int str_write_iops_log_cb(void *data, const char *str)
756 struct thread_data *td = data;
759 td->o.iops_log_file = strdup(str);
761 td->o.write_iops_log = 1;
765 static int str_gtod_reduce_cb(void *data, int *il)
767 struct thread_data *td = data;
770 td->o.disable_lat = !!val;
771 td->o.disable_clat = !!val;
772 td->o.disable_slat = !!val;
773 td->o.disable_bw = !!val;
774 td->o.clat_percentiles = !val;
776 td->tv_cache_mask = 63;
781 static int str_gtod_cpu_cb(void *data, long long *il)
783 struct thread_data *td = data;
786 td->o.gtod_cpu = val;
787 td->o.gtod_offload = 1;
791 static int str_size_cb(void *data, unsigned long long *__val)
793 struct thread_data *td = data;
794 unsigned long long v = *__val;
796 if (parse_is_percent(v)) {
798 td->o.size_percent = -1ULL - v;
805 static int rw_verify(struct fio_option *o, void *data)
807 struct thread_data *td = data;
809 if (read_only && td_write(td)) {
810 log_err("fio: job <%s> has write bit set, but fio is in"
811 " read-only mode\n", td->o.name);
818 static int gtod_cpu_verify(struct fio_option *o, void *data)
820 #ifndef FIO_HAVE_CPU_AFFINITY
821 struct thread_data *td = data;
823 if (td->o.gtod_cpu) {
824 log_err("fio: platform must support CPU affinity for"
825 "gettimeofday() offloading\n");
833 static int kb_base_verify(struct fio_option *o, void *data)
835 struct thread_data *td = data;
837 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
838 log_err("fio: kb_base set to nonsensical value: %u\n",
847 * Map of job/command line options
849 static struct fio_option options[FIO_MAX_OPTS] = {
851 .name = "description",
852 .type = FIO_OPT_STR_STORE,
853 .off1 = td_var_offset(description),
854 .help = "Text job description",
858 .type = FIO_OPT_STR_STORE,
859 .off1 = td_var_offset(name),
860 .help = "Name of this job",
864 .type = FIO_OPT_STR_STORE,
865 .off1 = td_var_offset(directory),
866 .cb = str_directory_cb,
867 .help = "Directory to store files in",
871 .type = FIO_OPT_STR_STORE,
872 .off1 = td_var_offset(filename),
873 .cb = str_filename_cb,
874 .prio = -1, /* must come after "directory" */
875 .help = "File(s) to use for the workload",
880 .off1 = td_var_offset(kb_base),
881 .verify = kb_base_verify,
884 .help = "How many bytes per KB for reporting (1000 or 1024)",
889 .cb = str_lockfile_cb,
890 .off1 = td_var_offset(file_lock_mode),
891 .help = "Lock file when doing IO to it",
892 .parent = "filename",
896 .oval = FILE_LOCK_NONE,
897 .help = "No file locking",
899 { .ival = "exclusive",
900 .oval = FILE_LOCK_EXCLUSIVE,
901 .help = "Exclusive file lock",
905 .oval = FILE_LOCK_READWRITE,
906 .help = "Read vs write lock",
912 .type = FIO_OPT_STR_STORE,
913 .off1 = td_var_offset(opendir),
914 .cb = str_opendir_cb,
915 .help = "Recursively add files from this directory and down",
919 .alias = "readwrite",
922 .off1 = td_var_offset(td_ddir),
923 .help = "IO direction",
928 .oval = TD_DDIR_READ,
929 .help = "Sequential read",
932 .oval = TD_DDIR_WRITE,
933 .help = "Sequential write",
935 { .ival = "randread",
936 .oval = TD_DDIR_RANDREAD,
937 .help = "Random read",
939 { .ival = "randwrite",
940 .oval = TD_DDIR_RANDWRITE,
941 .help = "Random write",
945 .help = "Sequential read and write mix",
947 { .ival = "readwrite",
949 .help = "Sequential read and write mix",
952 .oval = TD_DDIR_RANDRW,
953 .help = "Random read and write mix"
958 .name = "rw_sequencer",
960 .off1 = td_var_offset(rw_seq),
961 .help = "IO offset generator modifier",
964 { .ival = "sequential",
966 .help = "Generate sequential offsets",
968 { .ival = "identical",
969 .oval = RW_SEQ_IDENT,
970 .help = "Generate identical offsets",
977 .type = FIO_OPT_STR_STORE,
978 .off1 = td_var_offset(ioengine),
979 .help = "IO engine to use",
980 .def = FIO_PREFERRED_ENGINE,
983 .help = "Use read/write",
986 .help = "Use pread/pwrite",
989 .help = "Use readv/writev",
991 #ifdef FIO_HAVE_LIBAIO
993 .help = "Linux native asynchronous IO",
996 #ifdef FIO_HAVE_POSIXAIO
997 { .ival = "posixaio",
998 .help = "POSIX asynchronous IO",
1001 #ifdef FIO_HAVE_SOLARISAIO
1002 { .ival = "solarisaio",
1003 .help = "Solaris native asynchronous IO",
1006 #ifdef FIO_HAVE_WINDOWSAIO
1007 { .ival = "windowsaio",
1008 .help = "Windows native asynchronous IO"
1012 .help = "Memory mapped IO"
1014 #ifdef FIO_HAVE_SPLICE
1016 .help = "splice/vmsplice based IO",
1018 { .ival = "netsplice",
1019 .help = "splice/vmsplice to/from the network",
1022 #ifdef FIO_HAVE_SGIO
1024 .help = "SCSI generic v3 IO",
1028 .help = "Testing engine (no data transfer)",
1031 .help = "Network IO",
1033 #ifdef FIO_HAVE_SYSLET
1034 { .ival = "syslet-rw",
1035 .help = "syslet enabled async pread/pwrite IO",
1039 .help = "CPU cycle burner engine",
1041 #ifdef FIO_HAVE_GUASI
1043 .help = "GUASI IO engine",
1046 #ifdef FIO_HAVE_BINJECT
1047 { .ival = "binject",
1048 .help = "binject direct inject block engine",
1051 #ifdef FIO_HAVE_RDMA
1053 .help = "RDMA IO engine",
1056 { .ival = "external",
1057 .help = "Load external engine (append name)",
1063 .type = FIO_OPT_INT,
1064 .off1 = td_var_offset(iodepth),
1065 .help = "Number of IO buffers to keep in flight",
1070 .name = "iodepth_batch",
1071 .alias = "iodepth_batch_submit",
1072 .type = FIO_OPT_INT,
1073 .off1 = td_var_offset(iodepth_batch),
1074 .help = "Number of IO buffers to submit in one go",
1075 .parent = "iodepth",
1080 .name = "iodepth_batch_complete",
1081 .type = FIO_OPT_INT,
1082 .off1 = td_var_offset(iodepth_batch_complete),
1083 .help = "Number of IO buffers to retrieve in one go",
1084 .parent = "iodepth",
1089 .name = "iodepth_low",
1090 .type = FIO_OPT_INT,
1091 .off1 = td_var_offset(iodepth_low),
1092 .help = "Low water mark for queuing depth",
1093 .parent = "iodepth",
1097 .type = FIO_OPT_STR_VAL,
1099 .help = "Total size of device or files",
1102 .name = "fill_device",
1104 .type = FIO_OPT_BOOL,
1105 .off1 = td_var_offset(fill_device),
1106 .help = "Write until an ENOSPC error occurs",
1111 .type = FIO_OPT_STR_VAL,
1112 .off1 = td_var_offset(file_size_low),
1113 .off2 = td_var_offset(file_size_high),
1115 .help = "Size of individual files",
1119 .alias = "fileoffset",
1120 .type = FIO_OPT_STR_VAL,
1121 .off1 = td_var_offset(start_offset),
1122 .help = "Start IO from this offset",
1126 .name = "offset_increment",
1127 .type = FIO_OPT_STR_VAL,
1128 .off1 = td_var_offset(offset_increment),
1129 .help = "What is the increment from one offset to the next",
1135 .alias = "blocksize",
1136 .type = FIO_OPT_INT,
1137 .off1 = td_var_offset(bs[DDIR_READ]),
1138 .off2 = td_var_offset(bs[DDIR_WRITE]),
1140 .help = "Block size unit",
1146 .alias = "blockalign",
1147 .type = FIO_OPT_INT,
1148 .off1 = td_var_offset(ba[DDIR_READ]),
1149 .off2 = td_var_offset(ba[DDIR_WRITE]),
1151 .help = "IO block offset alignment",
1156 .alias = "blocksize_range",
1157 .type = FIO_OPT_RANGE,
1158 .off1 = td_var_offset(min_bs[DDIR_READ]),
1159 .off2 = td_var_offset(max_bs[DDIR_READ]),
1160 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1161 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1163 .help = "Set block size range (in more detail than bs)",
1168 .type = FIO_OPT_STR,
1169 .cb = str_bssplit_cb,
1170 .help = "Set a specific mix of block sizes",
1174 .name = "bs_unaligned",
1175 .alias = "blocksize_unaligned",
1176 .type = FIO_OPT_STR_SET,
1177 .off1 = td_var_offset(bs_unaligned),
1178 .help = "Don't sector align IO buffer sizes",
1182 .name = "randrepeat",
1183 .type = FIO_OPT_BOOL,
1184 .off1 = td_var_offset(rand_repeatable),
1185 .help = "Use repeatable random IO pattern",
1190 .name = "use_os_rand",
1191 .type = FIO_OPT_BOOL,
1192 .off1 = td_var_offset(use_os_rand),
1193 .help = "Set to use OS random generator",
1198 .name = "norandommap",
1199 .type = FIO_OPT_STR_SET,
1200 .off1 = td_var_offset(norandommap),
1201 .help = "Accept potential duplicate random blocks",
1205 .name = "softrandommap",
1206 .type = FIO_OPT_BOOL,
1207 .off1 = td_var_offset(softrandommap),
1208 .help = "Set norandommap if randommap allocation fails",
1209 .parent = "norandommap",
1214 .alias = "nr_files",
1215 .type = FIO_OPT_INT,
1216 .off1 = td_var_offset(nr_files),
1217 .help = "Split job workload between this number of files",
1221 .name = "openfiles",
1222 .type = FIO_OPT_INT,
1223 .off1 = td_var_offset(open_files),
1224 .help = "Number of files to keep open at the same time",
1227 .name = "file_service_type",
1228 .type = FIO_OPT_STR,
1230 .off1 = td_var_offset(file_service_type),
1231 .help = "How to select which file to service next",
1232 .def = "roundrobin",
1235 .oval = FIO_FSERVICE_RANDOM,
1236 .help = "Choose a file at random",
1238 { .ival = "roundrobin",
1239 .oval = FIO_FSERVICE_RR,
1240 .help = "Round robin select files",
1242 { .ival = "sequential",
1243 .oval = FIO_FSERVICE_SEQ,
1244 .help = "Finish one file before moving to the next",
1247 .parent = "nrfiles",
1249 #ifdef FIO_HAVE_FALLOCATE
1251 .name = "fallocate",
1252 .type = FIO_OPT_STR,
1253 .off1 = td_var_offset(fallocate_mode),
1254 .help = "Whether pre-allocation is performed when laying out files",
1258 .oval = FIO_FALLOCATE_NONE,
1259 .help = "Do not pre-allocate space",
1262 .oval = FIO_FALLOCATE_POSIX,
1263 .help = "Use posix_fallocate()",
1265 #ifdef FIO_HAVE_LINUX_FALLOCATE
1267 .oval = FIO_FALLOCATE_KEEP_SIZE,
1268 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1271 /* Compatibility with former boolean values */
1273 .oval = FIO_FALLOCATE_NONE,
1274 .help = "Alias for 'none'",
1277 .oval = FIO_FALLOCATE_POSIX,
1278 .help = "Alias for 'posix'",
1282 #endif /* FIO_HAVE_FALLOCATE */
1284 .name = "fadvise_hint",
1285 .type = FIO_OPT_BOOL,
1286 .off1 = td_var_offset(fadvise_hint),
1287 .help = "Use fadvise() to advise the kernel on IO pattern",
1292 .type = FIO_OPT_INT,
1293 .off1 = td_var_offset(fsync_blocks),
1294 .help = "Issue fsync for writes every given number of blocks",
1298 .name = "fdatasync",
1299 .type = FIO_OPT_INT,
1300 .off1 = td_var_offset(fdatasync_blocks),
1301 .help = "Issue fdatasync for writes every given number of blocks",
1305 .name = "write_barrier",
1306 .type = FIO_OPT_INT,
1307 .off1 = td_var_offset(barrier_blocks),
1308 .help = "Make every Nth write a barrier write",
1311 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1313 .name = "sync_file_range",
1315 { .ival = "wait_before",
1316 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1317 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1321 .oval = SYNC_FILE_RANGE_WRITE,
1322 .help = "SYNC_FILE_RANGE_WRITE",
1326 .ival = "wait_after",
1327 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1328 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1332 .type = FIO_OPT_STR_MULTI,
1334 .off1 = td_var_offset(sync_file_range),
1335 .help = "Use sync_file_range()",
1340 .type = FIO_OPT_BOOL,
1341 .off1 = td_var_offset(odirect),
1342 .help = "Use O_DIRECT IO (negates buffered)",
1347 .type = FIO_OPT_BOOL,
1348 .off1 = td_var_offset(odirect),
1350 .help = "Use buffered IO (negates direct)",
1354 .name = "overwrite",
1355 .type = FIO_OPT_BOOL,
1356 .off1 = td_var_offset(overwrite),
1357 .help = "When writing, set whether to overwrite current data",
1362 .type = FIO_OPT_INT,
1363 .off1 = td_var_offset(loops),
1364 .help = "Number of times to run the job",
1369 .type = FIO_OPT_INT,
1370 .off1 = td_var_offset(numjobs),
1371 .help = "Duplicate this job this many times",
1375 .name = "startdelay",
1376 .type = FIO_OPT_STR_VAL_TIME,
1377 .off1 = td_var_offset(start_delay),
1378 .help = "Only start job when this period has passed",
1384 .type = FIO_OPT_STR_VAL_TIME,
1385 .off1 = td_var_offset(timeout),
1386 .help = "Stop workload when this amount of time has passed",
1390 .name = "time_based",
1391 .type = FIO_OPT_STR_SET,
1392 .off1 = td_var_offset(time_based),
1393 .help = "Keep running until runtime/timeout is met",
1396 .name = "ramp_time",
1397 .type = FIO_OPT_STR_VAL_TIME,
1398 .off1 = td_var_offset(ramp_time),
1399 .help = "Ramp up time before measuring performance",
1402 .name = "clocksource",
1403 .type = FIO_OPT_STR,
1404 .cb = fio_clock_source_cb,
1405 .off1 = td_var_offset(clocksource),
1406 .help = "What type of timing source to use",
1408 { .ival = "gettimeofday",
1410 .help = "Use gettimeofday(2) for timing",
1412 { .ival = "clock_gettime",
1413 .oval = CS_CGETTIME,
1414 .help = "Use clock_gettime(2) for timing",
1416 #ifdef ARCH_HAVE_CPU_CLOCK
1418 .oval = CS_CPUCLOCK,
1419 .help = "Use CPU private clock",
1427 .type = FIO_OPT_STR,
1429 .off1 = td_var_offset(mem_type),
1430 .help = "Backing type for IO buffers",
1435 .help = "Use malloc(3) for IO buffers",
1439 .help = "Use shared memory segments for IO buffers",
1441 #ifdef FIO_HAVE_HUGETLB
1442 { .ival = "shmhuge",
1443 .oval = MEM_SHMHUGE,
1444 .help = "Like shm, but use huge pages",
1449 .help = "Use mmap(2) (file or anon) for IO buffers",
1451 #ifdef FIO_HAVE_HUGETLB
1452 { .ival = "mmaphuge",
1453 .oval = MEM_MMAPHUGE,
1454 .help = "Like mmap, but use huge pages",
1460 .name = "iomem_align",
1461 .alias = "mem_align",
1462 .type = FIO_OPT_INT,
1463 .off1 = td_var_offset(mem_align),
1465 .help = "IO memory buffer offset alignment",
1471 .type = FIO_OPT_STR,
1472 .off1 = td_var_offset(verify),
1473 .help = "Verify data written",
1474 .cb = str_verify_cb,
1478 .oval = VERIFY_NONE,
1479 .help = "Don't do IO verification",
1483 .help = "Use md5 checksums for verification",
1486 .oval = VERIFY_CRC64,
1487 .help = "Use crc64 checksums for verification",
1490 .oval = VERIFY_CRC32,
1491 .help = "Use crc32 checksums for verification",
1493 { .ival = "crc32c-intel",
1494 .oval = VERIFY_CRC32C,
1495 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1498 .oval = VERIFY_CRC32C,
1499 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1502 .oval = VERIFY_CRC16,
1503 .help = "Use crc16 checksums for verification",
1506 .oval = VERIFY_CRC7,
1507 .help = "Use crc7 checksums for verification",
1510 .oval = VERIFY_SHA1,
1511 .help = "Use sha1 checksums for verification",
1514 .oval = VERIFY_SHA256,
1515 .help = "Use sha256 checksums for verification",
1518 .oval = VERIFY_SHA512,
1519 .help = "Use sha512 checksums for verification",
1522 .oval = VERIFY_META,
1523 .help = "Use io information",
1527 .oval = VERIFY_NULL,
1528 .help = "Pretend to verify",
1533 .name = "do_verify",
1534 .type = FIO_OPT_BOOL,
1535 .off1 = td_var_offset(do_verify),
1536 .help = "Run verification stage after write",
1541 .name = "verifysort",
1542 .type = FIO_OPT_BOOL,
1543 .off1 = td_var_offset(verifysort),
1544 .help = "Sort written verify blocks for read back",
1549 .name = "verify_interval",
1550 .type = FIO_OPT_INT,
1551 .off1 = td_var_offset(verify_interval),
1552 .minval = 2 * sizeof(struct verify_header),
1553 .help = "Store verify buffer header every N bytes",
1557 .name = "verify_offset",
1558 .type = FIO_OPT_INT,
1559 .help = "Offset verify header location by N bytes",
1561 .cb = str_verify_offset_cb,
1565 .name = "verify_pattern",
1566 .type = FIO_OPT_STR,
1567 .cb = str_verify_pattern_cb,
1568 .help = "Fill pattern for IO buffers",
1572 .name = "verify_fatal",
1573 .type = FIO_OPT_BOOL,
1574 .off1 = td_var_offset(verify_fatal),
1576 .help = "Exit on a single verify failure, don't continue",
1580 .name = "verify_dump",
1581 .type = FIO_OPT_BOOL,
1582 .off1 = td_var_offset(verify_dump),
1584 .help = "Dump contents of good and bad blocks on failure",
1588 .name = "verify_async",
1589 .type = FIO_OPT_INT,
1590 .off1 = td_var_offset(verify_async),
1592 .help = "Number of async verifier threads to use",
1596 .name = "verify_backlog",
1597 .type = FIO_OPT_STR_VAL,
1598 .off1 = td_var_offset(verify_backlog),
1599 .help = "Verify after this number of blocks are written",
1603 .name = "verify_backlog_batch",
1604 .type = FIO_OPT_INT,
1605 .off1 = td_var_offset(verify_batch),
1606 .help = "Verify this number of IO blocks",
1609 #ifdef FIO_HAVE_CPU_AFFINITY
1611 .name = "verify_async_cpus",
1612 .type = FIO_OPT_STR,
1613 .cb = str_verify_cpus_allowed_cb,
1614 .help = "Set CPUs allowed for async verify threads",
1615 .parent = "verify_async",
1618 #ifdef FIO_HAVE_TRIM
1620 .name = "trim_percentage",
1621 .type = FIO_OPT_INT,
1622 .cb = str_verify_trim_cb,
1624 .help = "Number of verify blocks to discard/trim",
1629 .name = "trim_verify_zero",
1630 .type = FIO_OPT_INT,
1631 .help = "Verify that trim/discarded blocks are returned as zeroes",
1632 .off1 = td_var_offset(trim_zero),
1633 .parent = "trim_percentage",
1637 .name = "trim_backlog",
1638 .type = FIO_OPT_STR_VAL,
1639 .off1 = td_var_offset(trim_backlog),
1640 .help = "Trim after this number of blocks are written",
1641 .parent = "trim_percentage",
1644 .name = "trim_backlog_batch",
1645 .type = FIO_OPT_INT,
1646 .off1 = td_var_offset(trim_batch),
1647 .help = "Trim this number of IO blocks",
1648 .parent = "trim_percentage",
1652 .name = "write_iolog",
1653 .type = FIO_OPT_STR_STORE,
1654 .off1 = td_var_offset(write_iolog_file),
1655 .help = "Store IO pattern to file",
1658 .name = "read_iolog",
1659 .type = FIO_OPT_STR_STORE,
1660 .off1 = td_var_offset(read_iolog_file),
1661 .help = "Playback IO pattern from file",
1664 .name = "replay_no_stall",
1665 .type = FIO_OPT_INT,
1666 .off1 = td_var_offset(no_stall),
1668 .parent = "read_iolog",
1669 .help = "Playback IO pattern file as fast as possible without stalls",
1672 .name = "replay_redirect",
1673 .type = FIO_OPT_STR_STORE,
1674 .off1 = td_var_offset(replay_redirect),
1675 .parent = "read_iolog",
1676 .help = "Replay all I/O onto this device, regardless of trace device",
1679 .name = "exec_prerun",
1680 .type = FIO_OPT_STR_STORE,
1681 .off1 = td_var_offset(exec_prerun),
1682 .help = "Execute this file prior to running job",
1685 .name = "exec_postrun",
1686 .type = FIO_OPT_STR_STORE,
1687 .off1 = td_var_offset(exec_postrun),
1688 .help = "Execute this file after running job",
1690 #ifdef FIO_HAVE_IOSCHED_SWITCH
1692 .name = "ioscheduler",
1693 .type = FIO_OPT_STR_STORE,
1694 .off1 = td_var_offset(ioscheduler),
1695 .help = "Use this IO scheduler on the backing device",
1700 .type = FIO_OPT_STR_VAL,
1701 .off1 = td_var_offset(zone_size),
1702 .help = "Amount of data to read per zone",
1706 .name = "zonerange",
1707 .type = FIO_OPT_STR_VAL,
1708 .off1 = td_var_offset(zone_range),
1709 .help = "Give size of an IO zone",
1714 .type = FIO_OPT_STR_VAL,
1715 .off1 = td_var_offset(zone_skip),
1716 .help = "Space between IO zones",
1721 .type = FIO_OPT_STR_VAL,
1722 .cb = str_lockmem_cb,
1723 .help = "Lock down this amount of memory",
1727 .name = "rwmixread",
1728 .type = FIO_OPT_INT,
1729 .cb = str_rwmix_read_cb,
1731 .help = "Percentage of mixed workload that is reads",
1735 .name = "rwmixwrite",
1736 .type = FIO_OPT_INT,
1737 .cb = str_rwmix_write_cb,
1739 .help = "Percentage of mixed workload that is writes",
1743 .name = "rwmixcycle",
1744 .type = FIO_OPT_DEPRECATED,
1748 .type = FIO_OPT_INT,
1749 .off1 = td_var_offset(nice),
1750 .help = "Set job CPU nice value",
1755 #ifdef FIO_HAVE_IOPRIO
1758 .type = FIO_OPT_INT,
1760 .help = "Set job IO priority value",
1765 .name = "prioclass",
1766 .type = FIO_OPT_INT,
1767 .cb = str_prioclass_cb,
1768 .help = "Set job IO priority class",
1774 .name = "thinktime",
1775 .type = FIO_OPT_INT,
1776 .off1 = td_var_offset(thinktime),
1777 .help = "Idle time between IO buffers (usec)",
1781 .name = "thinktime_spin",
1782 .type = FIO_OPT_INT,
1783 .off1 = td_var_offset(thinktime_spin),
1784 .help = "Start think time by spinning this amount (usec)",
1786 .parent = "thinktime",
1789 .name = "thinktime_blocks",
1790 .type = FIO_OPT_INT,
1791 .off1 = td_var_offset(thinktime_blocks),
1792 .help = "IO buffer period between 'thinktime'",
1794 .parent = "thinktime",
1798 .type = FIO_OPT_INT,
1799 .off1 = td_var_offset(rate[0]),
1800 .off2 = td_var_offset(rate[1]),
1801 .help = "Set bandwidth rate",
1805 .type = FIO_OPT_INT,
1806 .off1 = td_var_offset(ratemin[0]),
1807 .off2 = td_var_offset(ratemin[1]),
1808 .help = "Job must meet this rate or it will be shutdown",
1812 .name = "rate_iops",
1813 .type = FIO_OPT_INT,
1814 .off1 = td_var_offset(rate_iops[0]),
1815 .off2 = td_var_offset(rate_iops[1]),
1816 .help = "Limit IO used to this number of IO operations/sec",
1819 .name = "rate_iops_min",
1820 .type = FIO_OPT_INT,
1821 .off1 = td_var_offset(rate_iops_min[0]),
1822 .off2 = td_var_offset(rate_iops_min[1]),
1823 .help = "Job must meet this rate or it will be shut down",
1824 .parent = "rate_iops",
1827 .name = "ratecycle",
1828 .type = FIO_OPT_INT,
1829 .off1 = td_var_offset(ratecycle),
1830 .help = "Window average for rate limits (msec)",
1835 .name = "invalidate",
1836 .type = FIO_OPT_BOOL,
1837 .off1 = td_var_offset(invalidate_cache),
1838 .help = "Invalidate buffer/page cache prior to running job",
1843 .type = FIO_OPT_BOOL,
1844 .off1 = td_var_offset(sync_io),
1845 .help = "Use O_SYNC for buffered writes",
1847 .parent = "buffered",
1850 .name = "bwavgtime",
1851 .type = FIO_OPT_INT,
1852 .off1 = td_var_offset(bw_avg_time),
1853 .help = "Time window over which to calculate bandwidth"
1856 .parent = "write_bw_log",
1859 .name = "iopsavgtime",
1860 .type = FIO_OPT_INT,
1861 .off1 = td_var_offset(iops_avg_time),
1862 .help = "Time window over which to calculate IOPS (msec)",
1864 .parent = "write_iops_log",
1867 .name = "create_serialize",
1868 .type = FIO_OPT_BOOL,
1869 .off1 = td_var_offset(create_serialize),
1870 .help = "Serialize creating of job files",
1874 .name = "create_fsync",
1875 .type = FIO_OPT_BOOL,
1876 .off1 = td_var_offset(create_fsync),
1877 .help = "fsync file after creation",
1881 .name = "create_on_open",
1882 .type = FIO_OPT_BOOL,
1883 .off1 = td_var_offset(create_on_open),
1884 .help = "Create files when they are opened for IO",
1889 .type = FIO_OPT_BOOL,
1890 .off1 = td_var_offset(pre_read),
1891 .help = "Pre-read files before starting official testing",
1896 .type = FIO_OPT_INT,
1897 .off1 = td_var_offset(cpuload),
1898 .help = "Use this percentage of CPU",
1901 .name = "cpuchunks",
1902 .type = FIO_OPT_INT,
1903 .off1 = td_var_offset(cpucycle),
1904 .help = "Length of the CPU burn cycles (usecs)",
1906 .parent = "cpuload",
1908 #ifdef FIO_HAVE_CPU_AFFINITY
1911 .type = FIO_OPT_INT,
1912 .cb = str_cpumask_cb,
1913 .help = "CPU affinity mask",
1916 .name = "cpus_allowed",
1917 .type = FIO_OPT_STR,
1918 .cb = str_cpus_allowed_cb,
1919 .help = "Set CPUs allowed",
1923 .name = "end_fsync",
1924 .type = FIO_OPT_BOOL,
1925 .off1 = td_var_offset(end_fsync),
1926 .help = "Include fsync at the end of job",
1930 .name = "fsync_on_close",
1931 .type = FIO_OPT_BOOL,
1932 .off1 = td_var_offset(fsync_on_close),
1933 .help = "fsync files on close",
1938 .type = FIO_OPT_BOOL,
1939 .off1 = td_var_offset(unlink),
1940 .help = "Unlink created files after job has completed",
1945 .type = FIO_OPT_STR_SET,
1946 .cb = str_exitall_cb,
1947 .help = "Terminate all jobs when one exits",
1950 .name = "stonewall",
1951 .alias = "wait_for_previous",
1952 .type = FIO_OPT_STR_SET,
1953 .off1 = td_var_offset(stonewall),
1954 .help = "Insert a hard barrier between this job and previous",
1957 .name = "new_group",
1958 .type = FIO_OPT_STR_SET,
1959 .off1 = td_var_offset(new_group),
1960 .help = "Mark the start of a new group (for reporting)",
1964 .type = FIO_OPT_STR_SET,
1965 .off1 = td_var_offset(use_thread),
1966 .help = "Use threads instead of forks",
1969 .name = "write_bw_log",
1970 .type = FIO_OPT_STR,
1971 .off1 = td_var_offset(write_bw_log),
1972 .cb = str_write_bw_log_cb,
1973 .help = "Write log of bandwidth during run",
1976 .name = "write_lat_log",
1977 .type = FIO_OPT_STR,
1978 .off1 = td_var_offset(write_lat_log),
1979 .cb = str_write_lat_log_cb,
1980 .help = "Write log of latency during run",
1983 .name = "write_iops_log",
1984 .type = FIO_OPT_STR,
1985 .off1 = td_var_offset(write_iops_log),
1986 .cb = str_write_iops_log_cb,
1987 .help = "Write log of IOPS during run",
1990 .name = "log_avg_msec",
1991 .type = FIO_OPT_INT,
1992 .off1 = td_var_offset(log_avg_msec),
1993 .help = "Average bw/iops/lat logs over this period of time",
1997 .name = "hugepage-size",
1998 .type = FIO_OPT_INT,
1999 .off1 = td_var_offset(hugepage_size),
2000 .help = "When using hugepages, specify size of each page",
2001 .def = __fio_stringify(FIO_HUGE_PAGE),
2004 .name = "group_reporting",
2005 .type = FIO_OPT_STR_SET,
2006 .off1 = td_var_offset(group_reporting),
2007 .help = "Do reporting on a per-group basis",
2010 .name = "zero_buffers",
2011 .type = FIO_OPT_STR_SET,
2012 .off1 = td_var_offset(zero_buffers),
2013 .help = "Init IO buffers to all zeroes",
2016 .name = "refill_buffers",
2017 .type = FIO_OPT_STR_SET,
2018 .off1 = td_var_offset(refill_buffers),
2019 .help = "Refill IO buffers on every IO submit",
2022 .name = "scramble_buffers",
2023 .type = FIO_OPT_BOOL,
2024 .off1 = td_var_offset(scramble_buffers),
2025 .help = "Slightly scramble buffers on every IO submit",
2029 .name = "buffer_compress_percentage",
2030 .type = FIO_OPT_INT,
2031 .off1 = td_var_offset(compress_percentage),
2034 .help = "How compressible the buffer is (approximately)",
2037 .name = "buffer_compress_chunk",
2038 .type = FIO_OPT_INT,
2039 .off1 = td_var_offset(compress_chunk),
2040 .parent = "buffer_compress_percentage",
2041 .help = "Size of compressible region in buffer",
2044 .name = "clat_percentiles",
2045 .type = FIO_OPT_BOOL,
2046 .off1 = td_var_offset(clat_percentiles),
2047 .help = "Enable the reporting of completion latency percentiles",
2051 .name = "percentile_list",
2052 .type = FIO_OPT_FLOAT_LIST,
2053 .off1 = td_var_offset(percentile_list),
2054 .off2 = td_var_offset(overwrite_plist),
2055 .help = "Specify a custom list of percentiles to report",
2056 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2061 #ifdef FIO_HAVE_DISK_UTIL
2063 .name = "disk_util",
2064 .type = FIO_OPT_BOOL,
2065 .off1 = td_var_offset(do_disk_util),
2066 .help = "Log disk utilization statistics",
2071 .name = "gtod_reduce",
2072 .type = FIO_OPT_BOOL,
2073 .help = "Greatly reduce number of gettimeofday() calls",
2074 .cb = str_gtod_reduce_cb,
2078 .name = "disable_lat",
2079 .type = FIO_OPT_BOOL,
2080 .off1 = td_var_offset(disable_lat),
2081 .help = "Disable latency numbers",
2082 .parent = "gtod_reduce",
2086 .name = "disable_clat",
2087 .type = FIO_OPT_BOOL,
2088 .off1 = td_var_offset(disable_clat),
2089 .help = "Disable completion latency numbers",
2090 .parent = "gtod_reduce",
2094 .name = "disable_slat",
2095 .type = FIO_OPT_BOOL,
2096 .off1 = td_var_offset(disable_slat),
2097 .help = "Disable submission latency numbers",
2098 .parent = "gtod_reduce",
2102 .name = "disable_bw_measurement",
2103 .type = FIO_OPT_BOOL,
2104 .off1 = td_var_offset(disable_bw),
2105 .help = "Disable bandwidth logging",
2106 .parent = "gtod_reduce",
2111 .type = FIO_OPT_INT,
2112 .cb = str_gtod_cpu_cb,
2113 .help = "Set up dedicated gettimeofday() thread on this CPU",
2114 .verify = gtod_cpu_verify,
2117 .name = "continue_on_error",
2118 .type = FIO_OPT_STR,
2119 .off1 = td_var_offset(continue_on_error),
2120 .help = "Continue on non-fatal errors during IO",
2124 .oval = ERROR_TYPE_NONE,
2125 .help = "Exit when an error is encountered",
2128 .oval = ERROR_TYPE_READ,
2129 .help = "Continue on read errors only",
2132 .oval = ERROR_TYPE_WRITE,
2133 .help = "Continue on write errors only",
2136 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2137 .help = "Continue on any IO errors",
2140 .oval = ERROR_TYPE_VERIFY,
2141 .help = "Continue on verify errors only",
2144 .oval = ERROR_TYPE_ANY,
2145 .help = "Continue on all io and verify errors",
2148 .oval = ERROR_TYPE_NONE,
2149 .help = "Alias for 'none'",
2152 .oval = ERROR_TYPE_ANY,
2153 .help = "Alias for 'all'",
2159 .type = FIO_OPT_STR_STORE,
2160 .off1 = td_var_offset(profile),
2161 .help = "Select a specific builtin performance test",
2165 .type = FIO_OPT_STR_STORE,
2166 .off1 = td_var_offset(cgroup),
2167 .help = "Add job to cgroup of this name",
2170 .name = "cgroup_weight",
2171 .type = FIO_OPT_INT,
2172 .off1 = td_var_offset(cgroup_weight),
2173 .help = "Use given weight for cgroup",
2178 .name = "cgroup_nodelete",
2179 .type = FIO_OPT_BOOL,
2180 .off1 = td_var_offset(cgroup_nodelete),
2181 .help = "Do not delete cgroups after job completion",
2186 .type = FIO_OPT_INT,
2187 .off1 = td_var_offset(uid),
2188 .help = "Run job with this user ID",
2192 .type = FIO_OPT_INT,
2193 .off1 = td_var_offset(gid),
2194 .help = "Run job with this group ID",
2198 .type = FIO_OPT_INT,
2199 .off1 = td_var_offset(flow_id),
2200 .help = "The flow index ID to use",
2205 .type = FIO_OPT_INT,
2206 .off1 = td_var_offset(flow),
2207 .help = "Weight for flow control of this job",
2208 .parent = "flow_id",
2212 .name = "flow_watermark",
2213 .type = FIO_OPT_INT,
2214 .off1 = td_var_offset(flow_watermark),
2215 .help = "High watermark for flow control. This option"
2216 " should be set to the same value for all threads"
2217 " with non-zero flow.",
2218 .parent = "flow_id",
2222 .name = "flow_sleep",
2223 .type = FIO_OPT_INT,
2224 .off1 = td_var_offset(flow_sleep),
2225 .help = "How many microseconds to sleep after being held"
2226 " back by the flow control mechanism",
2227 .parent = "flow_id",
2235 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2236 const char *name, int val)
2238 lopt->name = (char *) name;
2240 if (o->type == FIO_OPT_STR_SET)
2241 lopt->has_arg = no_argument;
2243 lopt->has_arg = required_argument;
2246 static void options_to_lopts(struct fio_option *opts,
2247 struct option *long_options,
2248 int i, int option_type)
2250 struct fio_option *o = &opts[0];
2252 add_to_lopt(&long_options[i], o, o->name, option_type);
2255 add_to_lopt(&long_options[i], o, o->alias, option_type);
2260 assert(i < FIO_NR_OPTIONS);
2264 void fio_options_set_ioengine_opts(struct option *long_options,
2265 struct thread_data *td)
2270 while (long_options[i].name) {
2271 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2272 memset(&long_options[i], 0, sizeof(*long_options));
2279 * Just clear out the prior ioengine options.
2284 options_to_lopts(td->io_ops->options, long_options, i,
2285 FIO_GETOPT_IOENGINE);
2288 void fio_options_dup_and_init(struct option *long_options)
2292 options_init(options);
2295 while (long_options[i].name)
2298 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
2301 struct fio_keyword {
2307 static struct fio_keyword fio_keywords[] = {
2309 .word = "$pagesize",
2310 .desc = "Page size in the system",
2313 .word = "$mb_memory",
2314 .desc = "Megabytes of memory online",
2318 .desc = "Number of CPUs online in the system",
2325 void fio_keywords_init(void)
2327 unsigned long long mb_memory;
2331 sprintf(buf, "%lu", page_size);
2332 fio_keywords[0].replace = strdup(buf);
2334 mb_memory = os_phys_mem() / (1024 * 1024);
2335 sprintf(buf, "%llu", mb_memory);
2336 fio_keywords[1].replace = strdup(buf);
2339 sprintf(buf, "%lu", l);
2340 fio_keywords[2].replace = strdup(buf);
2345 static char *bc_calc(char *str)
2347 char buf[128], *tmp;
2352 * No math, just return string
2354 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2355 !strchr(str, '/')) || strchr(str, '\''))
2359 * Split option from value, we only need to calculate the value
2361 tmp = strchr(str, '=');
2368 * Prevent buffer overflows; such a case isn't reasonable anyway
2370 if (strlen(str) >= 128 || strlen(tmp) > 100)
2373 sprintf(buf, "which %s > /dev/null", BC_APP);
2375 log_err("fio: bc is needed for performing math\n");
2379 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2380 f = popen(buf, "r");
2385 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2391 buf[(tmp - str) + ret - 1] = '\0';
2392 memcpy(buf, str, tmp - str);
2398 * Return a copy of the input string with substrings of the form ${VARNAME}
2399 * substituted with the value of the environment variable VARNAME. The
2400 * substitution always occurs, even if VARNAME is empty or the corresponding
2401 * environment variable undefined.
2403 static char *option_dup_subs(const char *opt)
2405 char out[OPT_LEN_MAX+1];
2406 char in[OPT_LEN_MAX+1];
2409 char *ch1, *ch2, *env;
2410 ssize_t nchr = OPT_LEN_MAX;
2413 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2414 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2418 in[OPT_LEN_MAX] = '\0';
2419 strncpy(in, opt, OPT_LEN_MAX);
2421 while (*inptr && nchr > 0) {
2422 if (inptr[0] == '$' && inptr[1] == '{') {
2423 ch2 = strchr(inptr, '}');
2424 if (ch2 && inptr+1 < ch2) {
2431 envlen = strlen(env);
2432 if (envlen <= nchr) {
2433 memcpy(outptr, env, envlen);
2443 *outptr++ = *inptr++;
2452 * Look for reserved variable names and replace them with real values
2454 static char *fio_keyword_replace(char *opt)
2460 for (i = 0; fio_keywords[i].word != NULL; i++) {
2461 struct fio_keyword *kw = &fio_keywords[i];
2463 while ((s = strstr(opt, kw->word)) != NULL) {
2464 char *new = malloc(strlen(opt) + 1);
2470 * Copy part of the string before the keyword and
2471 * sprintf() the replacement after it.
2473 memcpy(new, opt, olen);
2474 len = sprintf(new + olen, "%s", kw->replace);
2477 * If there's more in the original string, copy that
2480 opt += strlen(kw->word) + olen;
2482 memcpy(new + olen + len, opt, opt - o_org - 1);
2485 * replace opt and free the old opt
2495 * Check for potential math and invoke bc, if possible
2503 static char **dup_and_sub_options(char **opts, int num_opts)
2506 char **opts_copy = malloc(num_opts * sizeof(*opts));
2507 for (i = 0; i < num_opts; i++) {
2508 opts_copy[i] = option_dup_subs(opts[i]);
2511 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2516 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2518 int i, ret, unknown;
2521 sort_options(opts, options, num_opts);
2522 opts_copy = dup_and_sub_options(opts, num_opts);
2524 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2525 struct fio_option *o;
2526 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2535 opts_copy[i] = NULL;
2542 ret |= ioengine_load(td);
2544 sort_options(opts_copy, td->io_ops->options, num_opts);
2547 for (i = 0; i < num_opts; i++) {
2548 struct fio_option *o = NULL;
2554 newret = parse_option(opts_copy[i], opts[i],
2555 td->io_ops->options, &o,
2560 log_err("Bad option <%s>\n", opts[i]);
2563 opts_copy[i] = NULL;
2571 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2573 return parse_cmd_option(opt, val, options, td);
2576 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2579 return parse_cmd_option(opt, val, td->io_ops->options, td);
2582 void fio_fill_default_options(struct thread_data *td)
2584 fill_default_options(td, options);
2587 int fio_show_option_help(const char *opt)
2589 return show_cmd_help(options, opt);
2592 void options_mem_dupe(void *data, struct fio_option *options)
2594 struct fio_option *o;
2597 for (o = &options[0]; o->name; o++) {
2598 if (o->type != FIO_OPT_STR_STORE)
2601 ptr = td_var(data, o->off1);
2603 *ptr = strdup(*ptr);
2608 * dupe FIO_OPT_STR_STORE options
2610 void fio_options_mem_dupe(struct thread_data *td)
2612 options_mem_dupe(&td->o, options);
2614 if (td->eo && td->io_ops) {
2615 void *oldeo = td->eo;
2617 td->eo = malloc(td->io_ops->option_struct_size);
2618 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2619 options_mem_dupe(td->eo, td->io_ops->options);
2623 unsigned int fio_get_kb_base(void *data)
2625 struct thread_data *td = data;
2626 unsigned int kb_base = 0;
2629 kb_base = td->o.kb_base;
2636 int add_option(struct fio_option *o)
2638 struct fio_option *__o;
2647 memcpy(&options[opt_index], o, sizeof(*o));
2651 void invalidate_profile_options(const char *prof_name)
2653 struct fio_option *o;
2657 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2658 o->type = FIO_OPT_INVALID;
2659 o->prof_name = NULL;
2665 void add_opt_posval(const char *optname, const char *ival, const char *help)
2667 struct fio_option *o;
2670 o = find_option(options, optname);
2674 for (i = 0; i < PARSE_MAX_VP; i++) {
2675 if (o->posval[i].ival)
2678 o->posval[i].ival = ival;
2679 o->posval[i].help = help;
2684 void del_opt_posval(const char *optname, const char *ival)
2686 struct fio_option *o;
2689 o = find_option(options, optname);
2693 for (i = 0; i < PARSE_MAX_VP; i++) {
2694 if (!o->posval[i].ival)
2696 if (strcmp(o->posval[i].ival, ival))
2699 o->posval[i].ival = NULL;
2700 o->posval[i].help = NULL;
2704 void fio_options_free(struct thread_data *td)
2706 options_free(options, td);
2707 if (td->eo && td->io_ops && td->io_ops->options) {
2708 options_free(td->io_ops->options, td->eo);