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)
251 if (!crc32c_intel_works()) {
252 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
253 td->o.verify = VERIFY_CRC32C;
259 static int fio_clock_source_cb(void *data, const char *str)
261 struct thread_data *td = data;
263 fio_clock_source = td->o.clocksource;
268 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
274 static int str_rwmix_read_cb(void *data, unsigned long long *val)
276 struct thread_data *td = data;
278 td->o.rwmix[DDIR_READ] = *val;
279 td->o.rwmix[DDIR_WRITE] = 100 - *val;
283 static int str_rwmix_write_cb(void *data, unsigned long long *val)
285 struct thread_data *td = data;
287 td->o.rwmix[DDIR_WRITE] = *val;
288 td->o.rwmix[DDIR_READ] = 100 - *val;
292 #ifdef FIO_HAVE_IOPRIO
293 static int str_prioclass_cb(void *data, unsigned long long *val)
295 struct thread_data *td = data;
299 * mask off old class bits, str_prio_cb() may have set a default class
301 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
304 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
309 static int str_prio_cb(void *data, unsigned long long *val)
311 struct thread_data *td = data;
316 * If no class is set, assume BE
318 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
319 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
326 static int str_exitall_cb(void)
328 exitall_on_terminate = 1;
332 #ifdef FIO_HAVE_CPU_AFFINITY
333 static int str_cpumask_cb(void *data, unsigned long long *val)
335 struct thread_data *td = data;
340 ret = fio_cpuset_init(&td->o.cpumask);
342 log_err("fio: cpuset_init failed\n");
343 td_verror(td, ret, "fio_cpuset_init");
347 max_cpu = cpus_online();
349 for (i = 0; i < sizeof(int) * 8; i++) {
350 if ((1 << i) & *val) {
352 log_err("fio: CPU %d too large (max=%ld)\n", i,
356 dprint(FD_PARSE, "set cpu allowed %d\n", i);
357 fio_cpu_set(&td->o.cpumask, i);
361 td->o.cpumask_set = 1;
365 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
372 ret = fio_cpuset_init(mask);
374 log_err("fio: cpuset_init failed\n");
375 td_verror(td, ret, "fio_cpuset_init");
379 p = str = strdup(input);
381 strip_blank_front(&str);
382 strip_blank_end(str);
384 max_cpu = cpus_online();
386 while ((cpu = strsep(&str, ",")) != NULL) {
395 while ((cpu2 = strsep(&str2, "-")) != NULL) {
405 while (icpu <= icpu2) {
406 if (icpu >= FIO_MAX_CPUS) {
407 log_err("fio: your OS only supports up to"
408 " %d CPUs\n", (int) FIO_MAX_CPUS);
412 if (icpu > max_cpu) {
413 log_err("fio: CPU %d too large (max=%ld)\n",
419 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
420 fio_cpu_set(mask, icpu);
429 td->o.cpumask_set = 1;
433 static int str_cpus_allowed_cb(void *data, const char *input)
435 struct thread_data *td = data;
438 ret = set_cpus_allowed(td, &td->o.cpumask, input);
440 td->o.cpumask_set = 1;
445 static int str_verify_cpus_allowed_cb(void *data, const char *input)
447 struct thread_data *td = data;
450 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
452 td->o.verify_cpumask_set = 1;
459 static int str_verify_trim_cb(void *data, unsigned long long *val)
461 struct thread_data *td = data;
463 td->o.trim_percentage = *val;
468 static int str_fst_cb(void *data, const char *str)
470 struct thread_data *td = data;
471 char *nr = get_opt_postfix(str);
473 td->file_service_nr = 1;
475 td->file_service_nr = atoi(nr);
482 #ifdef FIO_HAVE_SYNC_FILE_RANGE
483 static int str_sfr_cb(void *data, const char *str)
485 struct thread_data *td = data;
486 char *nr = get_opt_postfix(str);
488 td->sync_file_range_nr = 1;
490 td->sync_file_range_nr = atoi(nr);
498 static int check_dir(struct thread_data *td, char *fname)
501 char file[PATH_MAX], *dir;
504 if (td->o.directory) {
505 strcpy(file, td->o.directory);
510 sprintf(file + elen, "%s", fname);
516 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
517 * yet, so we can't do this check right here...
519 if (lstat(dir, &sb) < 0) {
522 log_err("fio: %s is not a directory\n", dir);
523 td_verror(td, ret, "lstat");
527 if (!S_ISDIR(sb.st_mode)) {
528 log_err("fio: %s is not a directory\n", dir);
538 * Return next file in the string. Files are separated with ':'. If the ':'
539 * is escaped with a '\', then that ':' is part of the filename and does not
540 * indicate a new file.
542 static char *get_next_file_name(char **ptr)
547 if (!str || !strlen(str))
553 * No colon, we are done
555 p = strchr(str, ':');
562 * We got a colon, but it's the first character. Skip and
570 if (*(p - 1) != '\\') {
576 memmove(p - 1, p, strlen(p) + 1);
583 static int str_filename_cb(void *data, const char *input)
585 struct thread_data *td = data;
586 char *fname, *str, *p;
588 p = str = strdup(input);
590 strip_blank_front(&str);
591 strip_blank_end(str);
593 if (!td->files_index)
596 while ((fname = get_next_file_name(&str)) != NULL) {
599 if (check_dir(td, fname)) {
611 static int str_directory_cb(void *data, const char fio_unused *str)
613 struct thread_data *td = data;
616 if (lstat(td->o.directory, &sb) < 0) {
619 log_err("fio: %s is not a directory\n", td->o.directory);
620 td_verror(td, ret, "lstat");
623 if (!S_ISDIR(sb.st_mode)) {
624 log_err("fio: %s is not a directory\n", td->o.directory);
631 static int str_opendir_cb(void *data, const char fio_unused *str)
633 struct thread_data *td = data;
635 if (!td->files_index)
638 return add_dir_files(td, td->o.opendir);
641 static int str_verify_offset_cb(void *data, unsigned long long *off)
643 struct thread_data *td = data;
645 if (*off && *off < sizeof(struct verify_header)) {
646 log_err("fio: verify_offset too small\n");
650 td->o.verify_offset = *off;
654 static int str_verify_pattern_cb(void *data, const char *input)
656 struct thread_data *td = data;
658 int i = 0, j = 0, len, k, base = 10;
661 loc1 = strstr(input, "0x");
662 loc2 = strstr(input, "0X");
665 off = strtol(input, NULL, base);
666 if (off != LONG_MAX || errno != ERANGE) {
668 td->o.verify_pattern[i] = off & 0xff;
677 j = loc1 - input + 2;
679 j = loc2 - input + 2;
682 if (len - j < MAX_PATTERN_SIZE * 2) {
684 off = converthexchartoint(input[k--]);
686 off += (converthexchartoint(input[k--])
688 td->o.verify_pattern[i++] = (char) off;
694 * Fill the pattern all the way to the end. This greatly reduces
695 * the number of memcpy's we have to do when verifying the IO.
697 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
698 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
703 * The code in verify_io_u_pattern assumes a single byte pattern
704 * fills the whole verify pattern buffer.
706 memset(td->o.verify_pattern, td->o.verify_pattern[0],
710 td->o.verify_pattern_bytes = i;
713 * VERIFY_META could already be set
715 if (td->o.verify == VERIFY_NONE)
716 td->o.verify = VERIFY_PATTERN;
721 static int str_lockfile_cb(void *data, const char *str)
723 struct thread_data *td = data;
724 char *nr = get_opt_postfix(str);
726 td->o.lockfile_batch = 1;
728 td->o.lockfile_batch = atoi(nr);
735 static int str_write_bw_log_cb(void *data, const char *str)
737 struct thread_data *td = data;
740 td->o.bw_log_file = strdup(str);
742 td->o.write_bw_log = 1;
746 static int str_write_lat_log_cb(void *data, const char *str)
748 struct thread_data *td = data;
751 td->o.lat_log_file = strdup(str);
753 td->o.write_lat_log = 1;
757 static int str_write_iops_log_cb(void *data, const char *str)
759 struct thread_data *td = data;
762 td->o.iops_log_file = strdup(str);
764 td->o.write_iops_log = 1;
768 static int str_gtod_reduce_cb(void *data, int *il)
770 struct thread_data *td = data;
773 td->o.disable_lat = !!val;
774 td->o.disable_clat = !!val;
775 td->o.disable_slat = !!val;
776 td->o.disable_bw = !!val;
777 td->o.clat_percentiles = !val;
779 td->tv_cache_mask = 63;
784 static int str_gtod_cpu_cb(void *data, long long *il)
786 struct thread_data *td = data;
789 td->o.gtod_cpu = val;
790 td->o.gtod_offload = 1;
794 static int str_size_cb(void *data, unsigned long long *__val)
796 struct thread_data *td = data;
797 unsigned long long v = *__val;
799 if (parse_is_percent(v)) {
801 td->o.size_percent = -1ULL - v;
808 static int rw_verify(struct fio_option *o, void *data)
810 struct thread_data *td = data;
812 if (read_only && td_write(td)) {
813 log_err("fio: job <%s> has write bit set, but fio is in"
814 " read-only mode\n", td->o.name);
821 static int gtod_cpu_verify(struct fio_option *o, void *data)
823 #ifndef FIO_HAVE_CPU_AFFINITY
824 struct thread_data *td = data;
826 if (td->o.gtod_cpu) {
827 log_err("fio: platform must support CPU affinity for"
828 "gettimeofday() offloading\n");
836 static int kb_base_verify(struct fio_option *o, void *data)
838 struct thread_data *td = data;
840 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
841 log_err("fio: kb_base set to nonsensical value: %u\n",
850 * Map of job/command line options
852 static struct fio_option options[FIO_MAX_OPTS] = {
854 .name = "description",
855 .type = FIO_OPT_STR_STORE,
856 .off1 = td_var_offset(description),
857 .help = "Text job description",
861 .type = FIO_OPT_STR_STORE,
862 .off1 = td_var_offset(name),
863 .help = "Name of this job",
867 .type = FIO_OPT_STR_STORE,
868 .off1 = td_var_offset(directory),
869 .cb = str_directory_cb,
870 .help = "Directory to store files in",
874 .type = FIO_OPT_STR_STORE,
875 .off1 = td_var_offset(filename),
876 .cb = str_filename_cb,
877 .prio = -1, /* must come after "directory" */
878 .help = "File(s) to use for the workload",
883 .off1 = td_var_offset(kb_base),
884 .verify = kb_base_verify,
887 .help = "How many bytes per KB for reporting (1000 or 1024)",
892 .cb = str_lockfile_cb,
893 .off1 = td_var_offset(file_lock_mode),
894 .help = "Lock file when doing IO to it",
895 .parent = "filename",
899 .oval = FILE_LOCK_NONE,
900 .help = "No file locking",
902 { .ival = "exclusive",
903 .oval = FILE_LOCK_EXCLUSIVE,
904 .help = "Exclusive file lock",
908 .oval = FILE_LOCK_READWRITE,
909 .help = "Read vs write lock",
915 .type = FIO_OPT_STR_STORE,
916 .off1 = td_var_offset(opendir),
917 .cb = str_opendir_cb,
918 .help = "Recursively add files from this directory and down",
922 .alias = "readwrite",
925 .off1 = td_var_offset(td_ddir),
926 .help = "IO direction",
931 .oval = TD_DDIR_READ,
932 .help = "Sequential read",
935 .oval = TD_DDIR_WRITE,
936 .help = "Sequential write",
938 { .ival = "randread",
939 .oval = TD_DDIR_RANDREAD,
940 .help = "Random read",
942 { .ival = "randwrite",
943 .oval = TD_DDIR_RANDWRITE,
944 .help = "Random write",
948 .help = "Sequential read and write mix",
951 .oval = TD_DDIR_RANDRW,
952 .help = "Random read and write mix"
957 .name = "rw_sequencer",
959 .off1 = td_var_offset(rw_seq),
960 .help = "IO offset generator modifier",
963 { .ival = "sequential",
965 .help = "Generate sequential offsets",
967 { .ival = "identical",
968 .oval = RW_SEQ_IDENT,
969 .help = "Generate identical offsets",
976 .type = FIO_OPT_STR_STORE,
977 .off1 = td_var_offset(ioengine),
978 .help = "IO engine to use",
979 .def = FIO_PREFERRED_ENGINE,
982 .help = "Use read/write",
985 .help = "Use pread/pwrite",
988 .help = "Use readv/writev",
990 #ifdef FIO_HAVE_LIBAIO
992 .help = "Linux native asynchronous IO",
995 #ifdef FIO_HAVE_POSIXAIO
996 { .ival = "posixaio",
997 .help = "POSIX asynchronous IO",
1000 #ifdef FIO_HAVE_SOLARISAIO
1001 { .ival = "solarisaio",
1002 .help = "Solaris native asynchronous IO",
1005 #ifdef FIO_HAVE_WINDOWSAIO
1006 { .ival = "windowsaio",
1007 .help = "Windows native asynchronous IO"
1011 .help = "Memory mapped IO"
1013 #ifdef FIO_HAVE_SPLICE
1015 .help = "splice/vmsplice based IO",
1017 { .ival = "netsplice",
1018 .help = "splice/vmsplice to/from the network",
1021 #ifdef FIO_HAVE_SGIO
1023 .help = "SCSI generic v3 IO",
1027 .help = "Testing engine (no data transfer)",
1030 .help = "Network IO",
1032 #ifdef FIO_HAVE_SYSLET
1033 { .ival = "syslet-rw",
1034 .help = "syslet enabled async pread/pwrite IO",
1038 .help = "CPU cycle burner engine",
1040 #ifdef FIO_HAVE_GUASI
1042 .help = "GUASI IO engine",
1045 #ifdef FIO_HAVE_BINJECT
1046 { .ival = "binject",
1047 .help = "binject direct inject block engine",
1050 #ifdef FIO_HAVE_RDMA
1052 .help = "RDMA IO engine",
1055 { .ival = "external",
1056 .help = "Load external engine (append name)",
1062 .type = FIO_OPT_INT,
1063 .off1 = td_var_offset(iodepth),
1064 .help = "Number of IO buffers to keep in flight",
1069 .name = "iodepth_batch",
1070 .alias = "iodepth_batch_submit",
1071 .type = FIO_OPT_INT,
1072 .off1 = td_var_offset(iodepth_batch),
1073 .help = "Number of IO buffers to submit in one go",
1074 .parent = "iodepth",
1079 .name = "iodepth_batch_complete",
1080 .type = FIO_OPT_INT,
1081 .off1 = td_var_offset(iodepth_batch_complete),
1082 .help = "Number of IO buffers to retrieve in one go",
1083 .parent = "iodepth",
1088 .name = "iodepth_low",
1089 .type = FIO_OPT_INT,
1090 .off1 = td_var_offset(iodepth_low),
1091 .help = "Low water mark for queuing depth",
1092 .parent = "iodepth",
1096 .type = FIO_OPT_STR_VAL,
1098 .help = "Total size of device or files",
1101 .name = "fill_device",
1103 .type = FIO_OPT_BOOL,
1104 .off1 = td_var_offset(fill_device),
1105 .help = "Write until an ENOSPC error occurs",
1110 .type = FIO_OPT_STR_VAL,
1111 .off1 = td_var_offset(file_size_low),
1112 .off2 = td_var_offset(file_size_high),
1114 .help = "Size of individual files",
1118 .alias = "fileoffset",
1119 .type = FIO_OPT_STR_VAL,
1120 .off1 = td_var_offset(start_offset),
1121 .help = "Start IO from this offset",
1126 .alias = "blocksize",
1127 .type = FIO_OPT_INT,
1128 .off1 = td_var_offset(bs[DDIR_READ]),
1129 .off2 = td_var_offset(bs[DDIR_WRITE]),
1131 .help = "Block size unit",
1137 .alias = "blockalign",
1138 .type = FIO_OPT_INT,
1139 .off1 = td_var_offset(ba[DDIR_READ]),
1140 .off2 = td_var_offset(ba[DDIR_WRITE]),
1142 .help = "IO block offset alignment",
1147 .alias = "blocksize_range",
1148 .type = FIO_OPT_RANGE,
1149 .off1 = td_var_offset(min_bs[DDIR_READ]),
1150 .off2 = td_var_offset(max_bs[DDIR_READ]),
1151 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1152 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1154 .help = "Set block size range (in more detail than bs)",
1159 .type = FIO_OPT_STR,
1160 .cb = str_bssplit_cb,
1161 .help = "Set a specific mix of block sizes",
1165 .name = "bs_unaligned",
1166 .alias = "blocksize_unaligned",
1167 .type = FIO_OPT_STR_SET,
1168 .off1 = td_var_offset(bs_unaligned),
1169 .help = "Don't sector align IO buffer sizes",
1173 .name = "randrepeat",
1174 .type = FIO_OPT_BOOL,
1175 .off1 = td_var_offset(rand_repeatable),
1176 .help = "Use repeatable random IO pattern",
1181 .name = "use_os_rand",
1182 .type = FIO_OPT_BOOL,
1183 .off1 = td_var_offset(use_os_rand),
1184 .help = "Set to use OS random generator",
1189 .name = "norandommap",
1190 .type = FIO_OPT_STR_SET,
1191 .off1 = td_var_offset(norandommap),
1192 .help = "Accept potential duplicate random blocks",
1196 .name = "softrandommap",
1197 .type = FIO_OPT_BOOL,
1198 .off1 = td_var_offset(softrandommap),
1199 .help = "Set norandommap if randommap allocation fails",
1200 .parent = "norandommap",
1205 .alias = "nr_files",
1206 .type = FIO_OPT_INT,
1207 .off1 = td_var_offset(nr_files),
1208 .help = "Split job workload between this number of files",
1212 .name = "openfiles",
1213 .type = FIO_OPT_INT,
1214 .off1 = td_var_offset(open_files),
1215 .help = "Number of files to keep open at the same time",
1218 .name = "file_service_type",
1219 .type = FIO_OPT_STR,
1221 .off1 = td_var_offset(file_service_type),
1222 .help = "How to select which file to service next",
1223 .def = "roundrobin",
1226 .oval = FIO_FSERVICE_RANDOM,
1227 .help = "Choose a file at random",
1229 { .ival = "roundrobin",
1230 .oval = FIO_FSERVICE_RR,
1231 .help = "Round robin select files",
1233 { .ival = "sequential",
1234 .oval = FIO_FSERVICE_SEQ,
1235 .help = "Finish one file before moving to the next",
1238 .parent = "nrfiles",
1240 #ifdef FIO_HAVE_FALLOCATE
1242 .name = "fallocate",
1243 .type = FIO_OPT_STR,
1244 .off1 = td_var_offset(fallocate_mode),
1245 .help = "Whether pre-allocation is performed when laying out files",
1249 .oval = FIO_FALLOCATE_NONE,
1250 .help = "Do not pre-allocate space",
1253 .oval = FIO_FALLOCATE_POSIX,
1254 .help = "Use posix_fallocate()",
1256 #ifdef FIO_HAVE_LINUX_FALLOCATE
1258 .oval = FIO_FALLOCATE_KEEP_SIZE,
1259 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1262 /* Compatibility with former boolean values */
1264 .oval = FIO_FALLOCATE_NONE,
1265 .help = "Alias for 'none'",
1268 .oval = FIO_FALLOCATE_POSIX,
1269 .help = "Alias for 'posix'",
1273 #endif /* FIO_HAVE_FALLOCATE */
1275 .name = "fadvise_hint",
1276 .type = FIO_OPT_BOOL,
1277 .off1 = td_var_offset(fadvise_hint),
1278 .help = "Use fadvise() to advise the kernel on IO pattern",
1283 .type = FIO_OPT_INT,
1284 .off1 = td_var_offset(fsync_blocks),
1285 .help = "Issue fsync for writes every given number of blocks",
1289 .name = "fdatasync",
1290 .type = FIO_OPT_INT,
1291 .off1 = td_var_offset(fdatasync_blocks),
1292 .help = "Issue fdatasync for writes every given number of blocks",
1296 .name = "write_barrier",
1297 .type = FIO_OPT_INT,
1298 .off1 = td_var_offset(barrier_blocks),
1299 .help = "Make every Nth write a barrier write",
1302 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1304 .name = "sync_file_range",
1306 { .ival = "wait_before",
1307 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1308 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1312 .oval = SYNC_FILE_RANGE_WRITE,
1313 .help = "SYNC_FILE_RANGE_WRITE",
1317 .ival = "wait_after",
1318 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1319 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1323 .type = FIO_OPT_STR_MULTI,
1325 .off1 = td_var_offset(sync_file_range),
1326 .help = "Use sync_file_range()",
1331 .type = FIO_OPT_BOOL,
1332 .off1 = td_var_offset(odirect),
1333 .help = "Use O_DIRECT IO (negates buffered)",
1338 .type = FIO_OPT_BOOL,
1339 .off1 = td_var_offset(odirect),
1341 .help = "Use buffered IO (negates direct)",
1345 .name = "overwrite",
1346 .type = FIO_OPT_BOOL,
1347 .off1 = td_var_offset(overwrite),
1348 .help = "When writing, set whether to overwrite current data",
1353 .type = FIO_OPT_INT,
1354 .off1 = td_var_offset(loops),
1355 .help = "Number of times to run the job",
1360 .type = FIO_OPT_INT,
1361 .off1 = td_var_offset(numjobs),
1362 .help = "Duplicate this job this many times",
1366 .name = "startdelay",
1367 .type = FIO_OPT_STR_VAL_TIME,
1368 .off1 = td_var_offset(start_delay),
1369 .help = "Only start job when this period has passed",
1375 .type = FIO_OPT_STR_VAL_TIME,
1376 .off1 = td_var_offset(timeout),
1377 .help = "Stop workload when this amount of time has passed",
1381 .name = "time_based",
1382 .type = FIO_OPT_STR_SET,
1383 .off1 = td_var_offset(time_based),
1384 .help = "Keep running until runtime/timeout is met",
1387 .name = "ramp_time",
1388 .type = FIO_OPT_STR_VAL_TIME,
1389 .off1 = td_var_offset(ramp_time),
1390 .help = "Ramp up time before measuring performance",
1393 .name = "clocksource",
1394 .type = FIO_OPT_STR,
1395 .cb = fio_clock_source_cb,
1396 .off1 = td_var_offset(clocksource),
1397 .help = "What type of timing source to use",
1399 { .ival = "gettimeofday",
1401 .help = "Use gettimeofday(2) for timing",
1403 { .ival = "clock_gettime",
1404 .oval = CS_CGETTIME,
1405 .help = "Use clock_gettime(2) for timing",
1407 #ifdef ARCH_HAVE_CPU_CLOCK
1409 .oval = CS_CPUCLOCK,
1410 .help = "Use CPU private clock",
1418 .type = FIO_OPT_STR,
1420 .off1 = td_var_offset(mem_type),
1421 .help = "Backing type for IO buffers",
1426 .help = "Use malloc(3) for IO buffers",
1430 .help = "Use shared memory segments for IO buffers",
1432 #ifdef FIO_HAVE_HUGETLB
1433 { .ival = "shmhuge",
1434 .oval = MEM_SHMHUGE,
1435 .help = "Like shm, but use huge pages",
1440 .help = "Use mmap(2) (file or anon) for IO buffers",
1442 #ifdef FIO_HAVE_HUGETLB
1443 { .ival = "mmaphuge",
1444 .oval = MEM_MMAPHUGE,
1445 .help = "Like mmap, but use huge pages",
1451 .name = "iomem_align",
1452 .alias = "mem_align",
1453 .type = FIO_OPT_INT,
1454 .off1 = td_var_offset(mem_align),
1456 .help = "IO memory buffer offset alignment",
1462 .type = FIO_OPT_STR,
1463 .off1 = td_var_offset(verify),
1464 .help = "Verify data written",
1465 .cb = str_verify_cb,
1469 .oval = VERIFY_NONE,
1470 .help = "Don't do IO verification",
1474 .help = "Use md5 checksums for verification",
1477 .oval = VERIFY_CRC64,
1478 .help = "Use crc64 checksums for verification",
1481 .oval = VERIFY_CRC32,
1482 .help = "Use crc32 checksums for verification",
1484 { .ival = "crc32c-intel",
1485 .oval = VERIFY_CRC32C_INTEL,
1486 .help = "Use hw crc32c checksums for verification",
1489 .oval = VERIFY_CRC32C,
1490 .help = "Use crc32c checksums for verification",
1493 .oval = VERIFY_CRC16,
1494 .help = "Use crc16 checksums for verification",
1497 .oval = VERIFY_CRC7,
1498 .help = "Use crc7 checksums for verification",
1501 .oval = VERIFY_SHA1,
1502 .help = "Use sha1 checksums for verification",
1505 .oval = VERIFY_SHA256,
1506 .help = "Use sha256 checksums for verification",
1509 .oval = VERIFY_SHA512,
1510 .help = "Use sha512 checksums for verification",
1513 .oval = VERIFY_META,
1514 .help = "Use io information",
1518 .oval = VERIFY_NULL,
1519 .help = "Pretend to verify",
1524 .name = "do_verify",
1525 .type = FIO_OPT_BOOL,
1526 .off1 = td_var_offset(do_verify),
1527 .help = "Run verification stage after write",
1532 .name = "verifysort",
1533 .type = FIO_OPT_BOOL,
1534 .off1 = td_var_offset(verifysort),
1535 .help = "Sort written verify blocks for read back",
1540 .name = "verify_interval",
1541 .type = FIO_OPT_INT,
1542 .off1 = td_var_offset(verify_interval),
1543 .minval = 2 * sizeof(struct verify_header),
1544 .help = "Store verify buffer header every N bytes",
1548 .name = "verify_offset",
1549 .type = FIO_OPT_INT,
1550 .help = "Offset verify header location by N bytes",
1552 .cb = str_verify_offset_cb,
1556 .name = "verify_pattern",
1557 .type = FIO_OPT_STR,
1558 .cb = str_verify_pattern_cb,
1559 .help = "Fill pattern for IO buffers",
1563 .name = "verify_fatal",
1564 .type = FIO_OPT_BOOL,
1565 .off1 = td_var_offset(verify_fatal),
1567 .help = "Exit on a single verify failure, don't continue",
1571 .name = "verify_dump",
1572 .type = FIO_OPT_BOOL,
1573 .off1 = td_var_offset(verify_dump),
1575 .help = "Dump contents of good and bad blocks on failure",
1579 .name = "verify_async",
1580 .type = FIO_OPT_INT,
1581 .off1 = td_var_offset(verify_async),
1583 .help = "Number of async verifier threads to use",
1587 .name = "verify_backlog",
1588 .type = FIO_OPT_STR_VAL,
1589 .off1 = td_var_offset(verify_backlog),
1590 .help = "Verify after this number of blocks are written",
1594 .name = "verify_backlog_batch",
1595 .type = FIO_OPT_INT,
1596 .off1 = td_var_offset(verify_batch),
1597 .help = "Verify this number of IO blocks",
1600 #ifdef FIO_HAVE_CPU_AFFINITY
1602 .name = "verify_async_cpus",
1603 .type = FIO_OPT_STR,
1604 .cb = str_verify_cpus_allowed_cb,
1605 .help = "Set CPUs allowed for async verify threads",
1606 .parent = "verify_async",
1609 #ifdef FIO_HAVE_TRIM
1611 .name = "trim_percentage",
1612 .type = FIO_OPT_INT,
1613 .cb = str_verify_trim_cb,
1615 .help = "Number of verify blocks to discard/trim",
1620 .name = "trim_verify_zero",
1621 .type = FIO_OPT_INT,
1622 .help = "Verify that trim/discarded blocks are returned as zeroes",
1623 .off1 = td_var_offset(trim_zero),
1624 .parent = "trim_percentage",
1628 .name = "trim_backlog",
1629 .type = FIO_OPT_STR_VAL,
1630 .off1 = td_var_offset(trim_backlog),
1631 .help = "Trim after this number of blocks are written",
1632 .parent = "trim_percentage",
1635 .name = "trim_backlog_batch",
1636 .type = FIO_OPT_INT,
1637 .off1 = td_var_offset(trim_batch),
1638 .help = "Trim this number of IO blocks",
1639 .parent = "trim_percentage",
1643 .name = "write_iolog",
1644 .type = FIO_OPT_STR_STORE,
1645 .off1 = td_var_offset(write_iolog_file),
1646 .help = "Store IO pattern to file",
1649 .name = "read_iolog",
1650 .type = FIO_OPT_STR_STORE,
1651 .off1 = td_var_offset(read_iolog_file),
1652 .help = "Playback IO pattern from file",
1655 .name = "replay_no_stall",
1656 .type = FIO_OPT_INT,
1657 .off1 = td_var_offset(no_stall),
1659 .parent = "read_iolog",
1660 .help = "Playback IO pattern file as fast as possible without stalls",
1663 .name = "replay_redirect",
1664 .type = FIO_OPT_STR_STORE,
1665 .off1 = td_var_offset(replay_redirect),
1666 .parent = "read_iolog",
1667 .help = "Replay all I/O onto this device, regardless of trace device",
1670 .name = "exec_prerun",
1671 .type = FIO_OPT_STR_STORE,
1672 .off1 = td_var_offset(exec_prerun),
1673 .help = "Execute this file prior to running job",
1676 .name = "exec_postrun",
1677 .type = FIO_OPT_STR_STORE,
1678 .off1 = td_var_offset(exec_postrun),
1679 .help = "Execute this file after running job",
1681 #ifdef FIO_HAVE_IOSCHED_SWITCH
1683 .name = "ioscheduler",
1684 .type = FIO_OPT_STR_STORE,
1685 .off1 = td_var_offset(ioscheduler),
1686 .help = "Use this IO scheduler on the backing device",
1691 .type = FIO_OPT_STR_VAL,
1692 .off1 = td_var_offset(zone_size),
1693 .help = "Amount of data to read per zone",
1697 .name = "zonerange",
1698 .type = FIO_OPT_STR_VAL,
1699 .off1 = td_var_offset(zone_range),
1700 .help = "Give size of an IO zone",
1705 .type = FIO_OPT_STR_VAL,
1706 .off1 = td_var_offset(zone_skip),
1707 .help = "Space between IO zones",
1712 .type = FIO_OPT_STR_VAL,
1713 .cb = str_lockmem_cb,
1714 .help = "Lock down this amount of memory",
1718 .name = "rwmixread",
1719 .type = FIO_OPT_INT,
1720 .cb = str_rwmix_read_cb,
1722 .help = "Percentage of mixed workload that is reads",
1726 .name = "rwmixwrite",
1727 .type = FIO_OPT_INT,
1728 .cb = str_rwmix_write_cb,
1730 .help = "Percentage of mixed workload that is writes",
1734 .name = "rwmixcycle",
1735 .type = FIO_OPT_DEPRECATED,
1739 .type = FIO_OPT_INT,
1740 .off1 = td_var_offset(nice),
1741 .help = "Set job CPU nice value",
1746 #ifdef FIO_HAVE_IOPRIO
1749 .type = FIO_OPT_INT,
1751 .help = "Set job IO priority value",
1756 .name = "prioclass",
1757 .type = FIO_OPT_INT,
1758 .cb = str_prioclass_cb,
1759 .help = "Set job IO priority class",
1765 .name = "thinktime",
1766 .type = FIO_OPT_INT,
1767 .off1 = td_var_offset(thinktime),
1768 .help = "Idle time between IO buffers (usec)",
1772 .name = "thinktime_spin",
1773 .type = FIO_OPT_INT,
1774 .off1 = td_var_offset(thinktime_spin),
1775 .help = "Start think time by spinning this amount (usec)",
1777 .parent = "thinktime",
1780 .name = "thinktime_blocks",
1781 .type = FIO_OPT_INT,
1782 .off1 = td_var_offset(thinktime_blocks),
1783 .help = "IO buffer period between 'thinktime'",
1785 .parent = "thinktime",
1789 .type = FIO_OPT_INT,
1790 .off1 = td_var_offset(rate[0]),
1791 .off2 = td_var_offset(rate[1]),
1792 .help = "Set bandwidth rate",
1796 .type = FIO_OPT_INT,
1797 .off1 = td_var_offset(ratemin[0]),
1798 .off2 = td_var_offset(ratemin[1]),
1799 .help = "Job must meet this rate or it will be shutdown",
1803 .name = "rate_iops",
1804 .type = FIO_OPT_INT,
1805 .off1 = td_var_offset(rate_iops[0]),
1806 .off2 = td_var_offset(rate_iops[1]),
1807 .help = "Limit IO used to this number of IO operations/sec",
1810 .name = "rate_iops_min",
1811 .type = FIO_OPT_INT,
1812 .off1 = td_var_offset(rate_iops_min[0]),
1813 .off2 = td_var_offset(rate_iops_min[1]),
1814 .help = "Job must meet this rate or it will be shut down",
1815 .parent = "rate_iops",
1818 .name = "ratecycle",
1819 .type = FIO_OPT_INT,
1820 .off1 = td_var_offset(ratecycle),
1821 .help = "Window average for rate limits (msec)",
1826 .name = "invalidate",
1827 .type = FIO_OPT_BOOL,
1828 .off1 = td_var_offset(invalidate_cache),
1829 .help = "Invalidate buffer/page cache prior to running job",
1834 .type = FIO_OPT_BOOL,
1835 .off1 = td_var_offset(sync_io),
1836 .help = "Use O_SYNC for buffered writes",
1838 .parent = "buffered",
1841 .name = "bwavgtime",
1842 .type = FIO_OPT_INT,
1843 .off1 = td_var_offset(bw_avg_time),
1844 .help = "Time window over which to calculate bandwidth"
1847 .parent = "write_bw_log",
1850 .name = "iopsavgtime",
1851 .type = FIO_OPT_INT,
1852 .off1 = td_var_offset(iops_avg_time),
1853 .help = "Time window over which to calculate IOPS (msec)",
1855 .parent = "write_iops_log",
1858 .name = "create_serialize",
1859 .type = FIO_OPT_BOOL,
1860 .off1 = td_var_offset(create_serialize),
1861 .help = "Serialize creating of job files",
1865 .name = "create_fsync",
1866 .type = FIO_OPT_BOOL,
1867 .off1 = td_var_offset(create_fsync),
1868 .help = "fsync file after creation",
1872 .name = "create_on_open",
1873 .type = FIO_OPT_BOOL,
1874 .off1 = td_var_offset(create_on_open),
1875 .help = "Create files when they are opened for IO",
1880 .type = FIO_OPT_BOOL,
1881 .off1 = td_var_offset(pre_read),
1882 .help = "Pre-read files before starting official testing",
1887 .type = FIO_OPT_INT,
1888 .off1 = td_var_offset(cpuload),
1889 .help = "Use this percentage of CPU",
1892 .name = "cpuchunks",
1893 .type = FIO_OPT_INT,
1894 .off1 = td_var_offset(cpucycle),
1895 .help = "Length of the CPU burn cycles (usecs)",
1897 .parent = "cpuload",
1899 #ifdef FIO_HAVE_CPU_AFFINITY
1902 .type = FIO_OPT_INT,
1903 .cb = str_cpumask_cb,
1904 .help = "CPU affinity mask",
1907 .name = "cpus_allowed",
1908 .type = FIO_OPT_STR,
1909 .cb = str_cpus_allowed_cb,
1910 .help = "Set CPUs allowed",
1914 .name = "end_fsync",
1915 .type = FIO_OPT_BOOL,
1916 .off1 = td_var_offset(end_fsync),
1917 .help = "Include fsync at the end of job",
1921 .name = "fsync_on_close",
1922 .type = FIO_OPT_BOOL,
1923 .off1 = td_var_offset(fsync_on_close),
1924 .help = "fsync files on close",
1929 .type = FIO_OPT_BOOL,
1930 .off1 = td_var_offset(unlink),
1931 .help = "Unlink created files after job has completed",
1936 .type = FIO_OPT_STR_SET,
1937 .cb = str_exitall_cb,
1938 .help = "Terminate all jobs when one exits",
1941 .name = "stonewall",
1942 .alias = "wait_for_previous",
1943 .type = FIO_OPT_STR_SET,
1944 .off1 = td_var_offset(stonewall),
1945 .help = "Insert a hard barrier between this job and previous",
1948 .name = "new_group",
1949 .type = FIO_OPT_STR_SET,
1950 .off1 = td_var_offset(new_group),
1951 .help = "Mark the start of a new group (for reporting)",
1955 .type = FIO_OPT_STR_SET,
1956 .off1 = td_var_offset(use_thread),
1957 .help = "Use threads instead of forks",
1960 .name = "write_bw_log",
1961 .type = FIO_OPT_STR,
1962 .off1 = td_var_offset(write_bw_log),
1963 .cb = str_write_bw_log_cb,
1964 .help = "Write log of bandwidth during run",
1967 .name = "write_lat_log",
1968 .type = FIO_OPT_STR,
1969 .off1 = td_var_offset(write_lat_log),
1970 .cb = str_write_lat_log_cb,
1971 .help = "Write log of latency during run",
1974 .name = "write_iops_log",
1975 .type = FIO_OPT_STR,
1976 .off1 = td_var_offset(write_iops_log),
1977 .cb = str_write_iops_log_cb,
1978 .help = "Write log of IOPS during run",
1981 .name = "log_avg_msec",
1982 .type = FIO_OPT_INT,
1983 .off1 = td_var_offset(log_avg_msec),
1984 .help = "Average bw/iops/lat logs over this period of time",
1988 .name = "hugepage-size",
1989 .type = FIO_OPT_INT,
1990 .off1 = td_var_offset(hugepage_size),
1991 .help = "When using hugepages, specify size of each page",
1992 .def = __fio_stringify(FIO_HUGE_PAGE),
1995 .name = "group_reporting",
1996 .type = FIO_OPT_STR_SET,
1997 .off1 = td_var_offset(group_reporting),
1998 .help = "Do reporting on a per-group basis",
2001 .name = "zero_buffers",
2002 .type = FIO_OPT_STR_SET,
2003 .off1 = td_var_offset(zero_buffers),
2004 .help = "Init IO buffers to all zeroes",
2007 .name = "refill_buffers",
2008 .type = FIO_OPT_STR_SET,
2009 .off1 = td_var_offset(refill_buffers),
2010 .help = "Refill IO buffers on every IO submit",
2013 .name = "scramble_buffers",
2014 .type = FIO_OPT_BOOL,
2015 .off1 = td_var_offset(scramble_buffers),
2016 .help = "Slightly scramble buffers on every IO submit",
2020 .name = "clat_percentiles",
2021 .type = FIO_OPT_BOOL,
2022 .off1 = td_var_offset(clat_percentiles),
2023 .help = "Enable the reporting of completion latency percentiles",
2027 .name = "percentile_list",
2028 .type = FIO_OPT_FLOAT_LIST,
2029 .off1 = td_var_offset(percentile_list),
2030 .off2 = td_var_offset(overwrite_plist),
2031 .help = "Specify a custom list of percentiles to report",
2032 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2037 #ifdef FIO_HAVE_DISK_UTIL
2039 .name = "disk_util",
2040 .type = FIO_OPT_BOOL,
2041 .off1 = td_var_offset(do_disk_util),
2042 .help = "Log disk utilization statistics",
2047 .name = "gtod_reduce",
2048 .type = FIO_OPT_BOOL,
2049 .help = "Greatly reduce number of gettimeofday() calls",
2050 .cb = str_gtod_reduce_cb,
2054 .name = "disable_lat",
2055 .type = FIO_OPT_BOOL,
2056 .off1 = td_var_offset(disable_lat),
2057 .help = "Disable latency numbers",
2058 .parent = "gtod_reduce",
2062 .name = "disable_clat",
2063 .type = FIO_OPT_BOOL,
2064 .off1 = td_var_offset(disable_clat),
2065 .help = "Disable completion latency numbers",
2066 .parent = "gtod_reduce",
2070 .name = "disable_slat",
2071 .type = FIO_OPT_BOOL,
2072 .off1 = td_var_offset(disable_slat),
2073 .help = "Disable submission latency numbers",
2074 .parent = "gtod_reduce",
2078 .name = "disable_bw_measurement",
2079 .type = FIO_OPT_BOOL,
2080 .off1 = td_var_offset(disable_bw),
2081 .help = "Disable bandwidth logging",
2082 .parent = "gtod_reduce",
2087 .type = FIO_OPT_INT,
2088 .cb = str_gtod_cpu_cb,
2089 .help = "Set up dedicated gettimeofday() thread on this CPU",
2090 .verify = gtod_cpu_verify,
2093 .name = "continue_on_error",
2094 .type = FIO_OPT_STR,
2095 .off1 = td_var_offset(continue_on_error),
2096 .help = "Continue on non-fatal errors during IO",
2100 .oval = ERROR_TYPE_NONE,
2101 .help = "Exit when an error is encountered",
2104 .oval = ERROR_TYPE_READ,
2105 .help = "Continue on read errors only",
2108 .oval = ERROR_TYPE_WRITE,
2109 .help = "Continue on write errors only",
2112 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2113 .help = "Continue on any IO errors",
2116 .oval = ERROR_TYPE_VERIFY,
2117 .help = "Continue on verify errors only",
2120 .oval = ERROR_TYPE_ANY,
2121 .help = "Continue on all io and verify errors",
2124 .oval = ERROR_TYPE_NONE,
2125 .help = "Alias for 'none'",
2128 .oval = ERROR_TYPE_ANY,
2129 .help = "Alias for 'all'",
2135 .type = FIO_OPT_STR_STORE,
2136 .off1 = td_var_offset(profile),
2137 .help = "Select a specific builtin performance test",
2141 .type = FIO_OPT_STR_STORE,
2142 .off1 = td_var_offset(cgroup),
2143 .help = "Add job to cgroup of this name",
2146 .name = "cgroup_weight",
2147 .type = FIO_OPT_INT,
2148 .off1 = td_var_offset(cgroup_weight),
2149 .help = "Use given weight for cgroup",
2154 .name = "cgroup_nodelete",
2155 .type = FIO_OPT_BOOL,
2156 .off1 = td_var_offset(cgroup_nodelete),
2157 .help = "Do not delete cgroups after job completion",
2162 .type = FIO_OPT_INT,
2163 .off1 = td_var_offset(uid),
2164 .help = "Run job with this user ID",
2168 .type = FIO_OPT_INT,
2169 .off1 = td_var_offset(gid),
2170 .help = "Run job with this group ID",
2177 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2178 const char *name, int val)
2180 lopt->name = (char *) name;
2182 if (o->type == FIO_OPT_STR_SET)
2183 lopt->has_arg = no_argument;
2185 lopt->has_arg = required_argument;
2188 static void options_to_lopts(struct fio_option *opts,
2189 struct option *long_options,
2190 int i, int option_type)
2192 struct fio_option *o = &opts[0];
2194 add_to_lopt(&long_options[i], o, o->name, option_type);
2197 add_to_lopt(&long_options[i], o, o->alias, option_type);
2202 assert(i < FIO_NR_OPTIONS);
2206 void fio_options_set_ioengine_opts(struct option *long_options,
2207 struct thread_data *td)
2212 while (long_options[i].name) {
2213 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2214 memset(&long_options[i], 0, sizeof(*long_options));
2221 * Just clear out the prior ioengine options.
2226 options_to_lopts(td->io_ops->options, long_options, i,
2227 FIO_GETOPT_IOENGINE);
2230 void fio_options_dup_and_init(struct option *long_options)
2234 options_init(options);
2237 while (long_options[i].name)
2240 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
2243 struct fio_keyword {
2249 static struct fio_keyword fio_keywords[] = {
2251 .word = "$pagesize",
2252 .desc = "Page size in the system",
2255 .word = "$mb_memory",
2256 .desc = "Megabytes of memory online",
2260 .desc = "Number of CPUs online in the system",
2267 void fio_keywords_init(void)
2269 unsigned long long mb_memory;
2273 sprintf(buf, "%lu", page_size);
2274 fio_keywords[0].replace = strdup(buf);
2276 mb_memory = os_phys_mem() / (1024 * 1024);
2277 sprintf(buf, "%llu", mb_memory);
2278 fio_keywords[1].replace = strdup(buf);
2281 sprintf(buf, "%lu", l);
2282 fio_keywords[2].replace = strdup(buf);
2287 static char *bc_calc(char *str)
2289 char buf[128], *tmp;
2294 * No math, just return string
2296 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2297 !strchr(str, '/')) || strchr(str, '\''))
2301 * Split option from value, we only need to calculate the value
2303 tmp = strchr(str, '=');
2310 * Prevent buffer overflows; such a case isn't reasonable anyway
2312 if (strlen(str) >= 128 || strlen(tmp) > 100)
2315 sprintf(buf, "which %s > /dev/null", BC_APP);
2317 log_err("fio: bc is needed for performing math\n");
2321 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2322 f = popen(buf, "r");
2327 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2333 buf[(tmp - str) + ret - 1] = '\0';
2334 memcpy(buf, str, tmp - str);
2340 * Return a copy of the input string with substrings of the form ${VARNAME}
2341 * substituted with the value of the environment variable VARNAME. The
2342 * substitution always occurs, even if VARNAME is empty or the corresponding
2343 * environment variable undefined.
2345 static char *option_dup_subs(const char *opt)
2347 char out[OPT_LEN_MAX+1];
2348 char in[OPT_LEN_MAX+1];
2351 char *ch1, *ch2, *env;
2352 ssize_t nchr = OPT_LEN_MAX;
2355 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2356 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2360 in[OPT_LEN_MAX] = '\0';
2361 strncpy(in, opt, OPT_LEN_MAX);
2363 while (*inptr && nchr > 0) {
2364 if (inptr[0] == '$' && inptr[1] == '{') {
2365 ch2 = strchr(inptr, '}');
2366 if (ch2 && inptr+1 < ch2) {
2373 envlen = strlen(env);
2374 if (envlen <= nchr) {
2375 memcpy(outptr, env, envlen);
2385 *outptr++ = *inptr++;
2394 * Look for reserved variable names and replace them with real values
2396 static char *fio_keyword_replace(char *opt)
2402 for (i = 0; fio_keywords[i].word != NULL; i++) {
2403 struct fio_keyword *kw = &fio_keywords[i];
2405 while ((s = strstr(opt, kw->word)) != NULL) {
2406 char *new = malloc(strlen(opt) + 1);
2412 * Copy part of the string before the keyword and
2413 * sprintf() the replacement after it.
2415 memcpy(new, opt, olen);
2416 len = sprintf(new + olen, "%s", kw->replace);
2419 * If there's more in the original string, copy that
2422 opt += strlen(kw->word) + olen;
2424 memcpy(new + olen + len, opt, opt - o_org - 1);
2427 * replace opt and free the old opt
2437 * Check for potential math and invoke bc, if possible
2445 static char **dup_and_sub_options(char **opts, int num_opts)
2448 char **opts_copy = malloc(num_opts * sizeof(*opts));
2449 for (i = 0; i < num_opts; i++) {
2450 opts_copy[i] = option_dup_subs(opts[i]);
2453 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2458 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2460 int i, ret, unknown;
2463 sort_options(opts, options, num_opts);
2464 opts_copy = dup_and_sub_options(opts, num_opts);
2466 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2467 struct fio_option *o;
2468 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2477 opts_copy[i] = NULL;
2484 ret |= ioengine_load(td);
2486 sort_options(opts_copy, td->io_ops->options, num_opts);
2489 for (i = 0; i < num_opts; i++) {
2490 struct fio_option *o = NULL;
2496 newret = parse_option(opts_copy[i], opts[i],
2497 td->io_ops->options, &o,
2502 log_err("Bad option <%s>\n", opts[i]);
2505 opts_copy[i] = NULL;
2513 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2515 return parse_cmd_option(opt, val, options, td);
2518 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2521 return parse_cmd_option(opt, val, td->io_ops->options, td);
2524 void fio_fill_default_options(struct thread_data *td)
2526 fill_default_options(td, options);
2529 int fio_show_option_help(const char *opt)
2531 return show_cmd_help(options, opt);
2534 void options_mem_dupe(void *data, struct fio_option *options)
2536 struct fio_option *o;
2539 for (o = &options[0]; o->name; o++) {
2540 if (o->type != FIO_OPT_STR_STORE)
2543 ptr = td_var(data, o->off1);
2545 *ptr = strdup(*ptr);
2550 * dupe FIO_OPT_STR_STORE options
2552 void fio_options_mem_dupe(struct thread_data *td)
2554 options_mem_dupe(&td->o, options);
2556 if (td->eo && td->io_ops) {
2557 void *oldeo = td->eo;
2559 td->eo = malloc(td->io_ops->option_struct_size);
2560 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2561 options_mem_dupe(td->eo, td->io_ops->options);
2565 unsigned int fio_get_kb_base(void *data)
2567 struct thread_data *td = data;
2568 unsigned int kb_base = 0;
2571 kb_base = td->o.kb_base;
2578 int add_option(struct fio_option *o)
2580 struct fio_option *__o;
2589 memcpy(&options[opt_index], o, sizeof(*o));
2593 void invalidate_profile_options(const char *prof_name)
2595 struct fio_option *o;
2599 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2600 o->type = FIO_OPT_INVALID;
2601 o->prof_name = NULL;
2607 void add_opt_posval(const char *optname, const char *ival, const char *help)
2609 struct fio_option *o;
2612 o = find_option(options, optname);
2616 for (i = 0; i < PARSE_MAX_VP; i++) {
2617 if (o->posval[i].ival)
2620 o->posval[i].ival = ival;
2621 o->posval[i].help = help;
2626 void del_opt_posval(const char *optname, const char *ival)
2628 struct fio_option *o;
2631 o = find_option(options, optname);
2635 for (i = 0; i < PARSE_MAX_VP; i++) {
2636 if (!o->posval[i].ival)
2638 if (strcmp(o->posval[i].ival, ival))
2641 o->posval[i].ival = NULL;
2642 o->posval[i].help = NULL;
2646 void fio_options_free(struct thread_data *td)
2648 options_free(options, td);
2649 if (td->eo && td->io_ops && td->io_ops->options) {
2650 options_free(td->io_ops->options, td->eo);