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 #ifdef FIO_HAVE_LIBAIO
230 static int str_libaio_cb(void *data, const char *str)
232 struct thread_data *td = data;
234 if (!strcmp(str, "userspace_reap")) {
235 td->o.userspace_libaio_reap = 1;
239 log_err("fio: bad libaio sub-option: %s\n", str);
244 static int str_mem_cb(void *data, const char *mem)
246 struct thread_data *td = data;
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");
259 static int str_verify_cb(void *data, const char *mem)
261 struct thread_data *td = data;
263 if (td->o.verify != VERIFY_CRC32C_INTEL)
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;
274 static int fio_clock_source_cb(void *data, const char *str)
276 struct thread_data *td = data;
278 fio_clock_source = td->o.clocksource;
283 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
289 static int str_rwmix_read_cb(void *data, unsigned long long *val)
291 struct thread_data *td = data;
293 td->o.rwmix[DDIR_READ] = *val;
294 td->o.rwmix[DDIR_WRITE] = 100 - *val;
298 static int str_rwmix_write_cb(void *data, unsigned long long *val)
300 struct thread_data *td = data;
302 td->o.rwmix[DDIR_WRITE] = *val;
303 td->o.rwmix[DDIR_READ] = 100 - *val;
307 #ifdef FIO_HAVE_IOPRIO
308 static int str_prioclass_cb(void *data, unsigned long long *val)
310 struct thread_data *td = data;
314 * mask off old class bits, str_prio_cb() may have set a default class
316 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
319 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
324 static int str_prio_cb(void *data, unsigned long long *val)
326 struct thread_data *td = data;
331 * If no class is set, assume BE
333 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
334 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
341 static int str_exitall_cb(void)
343 exitall_on_terminate = 1;
347 #ifdef FIO_HAVE_CPU_AFFINITY
348 static int str_cpumask_cb(void *data, unsigned long long *val)
350 struct thread_data *td = data;
355 ret = fio_cpuset_init(&td->o.cpumask);
357 log_err("fio: cpuset_init failed\n");
358 td_verror(td, ret, "fio_cpuset_init");
362 max_cpu = cpus_online();
364 for (i = 0; i < sizeof(int) * 8; i++) {
365 if ((1 << i) & *val) {
367 log_err("fio: CPU %d too large (max=%ld)\n", i,
371 dprint(FD_PARSE, "set cpu allowed %d\n", i);
372 fio_cpu_set(&td->o.cpumask, i);
376 td->o.cpumask_set = 1;
380 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
387 ret = fio_cpuset_init(mask);
389 log_err("fio: cpuset_init failed\n");
390 td_verror(td, ret, "fio_cpuset_init");
394 p = str = strdup(input);
396 strip_blank_front(&str);
397 strip_blank_end(str);
399 max_cpu = cpus_online();
401 while ((cpu = strsep(&str, ",")) != NULL) {
410 while ((cpu2 = strsep(&str2, "-")) != NULL) {
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);
427 if (icpu > max_cpu) {
428 log_err("fio: CPU %d too large (max=%ld)\n",
434 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
435 fio_cpu_set(mask, icpu);
444 td->o.cpumask_set = 1;
448 static int str_cpus_allowed_cb(void *data, const char *input)
450 struct thread_data *td = data;
453 ret = set_cpus_allowed(td, &td->o.cpumask, input);
455 td->o.cpumask_set = 1;
460 static int str_verify_cpus_allowed_cb(void *data, const char *input)
462 struct thread_data *td = data;
465 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
467 td->o.verify_cpumask_set = 1;
474 static int str_verify_trim_cb(void *data, unsigned long long *val)
476 struct thread_data *td = data;
478 td->o.trim_percentage = *val;
483 static int str_fst_cb(void *data, const char *str)
485 struct thread_data *td = data;
486 char *nr = get_opt_postfix(str);
488 td->file_service_nr = 1;
490 td->file_service_nr = atoi(nr);
497 #ifdef FIO_HAVE_SYNC_FILE_RANGE
498 static int str_sfr_cb(void *data, const char *str)
500 struct thread_data *td = data;
501 char *nr = get_opt_postfix(str);
503 td->sync_file_range_nr = 1;
505 td->sync_file_range_nr = atoi(nr);
513 static int check_dir(struct thread_data *td, char *fname)
516 char file[PATH_MAX], *dir;
519 if (td->o.directory) {
520 strcpy(file, td->o.directory);
525 sprintf(file + elen, "%s", fname);
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...
534 if (lstat(dir, &sb) < 0) {
537 log_err("fio: %s is not a directory\n", dir);
538 td_verror(td, ret, "lstat");
542 if (!S_ISDIR(sb.st_mode)) {
543 log_err("fio: %s is not a directory\n", dir);
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.
557 static char *get_next_file_name(char **ptr)
562 if (!str || !strlen(str))
568 * No colon, we are done
570 p = strchr(str, ':');
577 * We got a colon, but it's the first character. Skip and
585 if (*(p - 1) != '\\') {
591 memmove(p - 1, p, strlen(p) + 1);
598 static int str_hostname_cb(void *data, const char *input)
600 struct thread_data *td = data;
602 td->o.filename = strdup(input);
606 static int str_filename_cb(void *data, const char *input)
608 struct thread_data *td = data;
609 char *fname, *str, *p;
611 p = str = strdup(input);
613 strip_blank_front(&str);
614 strip_blank_end(str);
616 if (!td->files_index)
619 while ((fname = get_next_file_name(&str)) != NULL) {
622 if (check_dir(td, fname)) {
634 static int str_directory_cb(void *data, const char fio_unused *str)
636 struct thread_data *td = data;
639 if (lstat(td->o.directory, &sb) < 0) {
642 log_err("fio: %s is not a directory\n", td->o.directory);
643 td_verror(td, ret, "lstat");
646 if (!S_ISDIR(sb.st_mode)) {
647 log_err("fio: %s is not a directory\n", td->o.directory);
654 static int str_opendir_cb(void *data, const char fio_unused *str)
656 struct thread_data *td = data;
658 if (!td->files_index)
661 return add_dir_files(td, td->o.opendir);
664 static int str_verify_offset_cb(void *data, unsigned long long *off)
666 struct thread_data *td = data;
668 if (*off && *off < sizeof(struct verify_header)) {
669 log_err("fio: verify_offset too small\n");
673 td->o.verify_offset = *off;
677 static int str_verify_pattern_cb(void *data, const char *input)
679 struct thread_data *td = data;
681 int i = 0, j = 0, len, k, base = 10;
684 loc1 = strstr(input, "0x");
685 loc2 = strstr(input, "0X");
688 off = strtol(input, NULL, base);
689 if (off != LONG_MAX || errno != ERANGE) {
691 td->o.verify_pattern[i] = off & 0xff;
700 j = loc1 - input + 2;
702 j = loc2 - input + 2;
705 if (len - j < MAX_PATTERN_SIZE * 2) {
707 off = converthexchartoint(input[k--]);
709 off += (converthexchartoint(input[k--])
711 td->o.verify_pattern[i++] = (char) off;
715 td->o.verify_pattern_bytes = i;
717 * VERIFY_META could already be set
719 if (td->o.verify == VERIFY_NONE)
720 td->o.verify = VERIFY_PATTERN;
724 static int str_lockfile_cb(void *data, const char *str)
726 struct thread_data *td = data;
727 char *nr = get_opt_postfix(str);
729 td->o.lockfile_batch = 1;
731 td->o.lockfile_batch = atoi(nr);
738 static int str_write_bw_log_cb(void *data, const char *str)
740 struct thread_data *td = data;
743 td->o.bw_log_file = strdup(str);
745 td->o.write_bw_log = 1;
749 static int str_write_lat_log_cb(void *data, const char *str)
751 struct thread_data *td = data;
754 td->o.lat_log_file = strdup(str);
756 td->o.write_lat_log = 1;
760 static int str_write_iops_log_cb(void *data, const char *str)
762 struct thread_data *td = data;
765 td->o.iops_log_file = strdup(str);
767 td->o.write_iops_log = 1;
771 static int str_gtod_reduce_cb(void *data, int *il)
773 struct thread_data *td = data;
776 td->o.disable_lat = !!val;
777 td->o.disable_clat = !!val;
778 td->o.disable_slat = !!val;
779 td->o.disable_bw = !!val;
781 td->tv_cache_mask = 63;
786 static int str_gtod_cpu_cb(void *data, long long *il)
788 struct thread_data *td = data;
791 td->o.gtod_cpu = val;
792 td->o.gtod_offload = 1;
796 static int str_size_cb(void *data, unsigned long long *__val)
798 struct thread_data *td = data;
799 unsigned long long v = *__val;
801 if (parse_is_percent(v)) {
803 td->o.size_percent = -1ULL - v;
810 static int rw_verify(struct fio_option *o, void *data)
812 struct thread_data *td = data;
814 if (read_only && td_write(td)) {
815 log_err("fio: job <%s> has write bit set, but fio is in"
816 " read-only mode\n", td->o.name);
823 static int gtod_cpu_verify(struct fio_option *o, void *data)
825 #ifndef FIO_HAVE_CPU_AFFINITY
826 struct thread_data *td = data;
828 if (td->o.gtod_cpu) {
829 log_err("fio: platform must support CPU affinity for"
830 "gettimeofday() offloading\n");
838 static int kb_base_verify(struct fio_option *o, void *data)
840 struct thread_data *td = data;
842 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
843 log_err("fio: kb_base set to nonsensical value: %u\n",
852 * Map of job/command line options
854 static struct fio_option options[FIO_MAX_OPTS] = {
856 .name = "description",
857 .type = FIO_OPT_STR_STORE,
858 .off1 = td_var_offset(description),
859 .help = "Text job description",
863 .type = FIO_OPT_STR_STORE,
864 .off1 = td_var_offset(name),
865 .help = "Name of this job",
869 .type = FIO_OPT_STR_STORE,
870 .off1 = td_var_offset(directory),
871 .cb = str_directory_cb,
872 .help = "Directory to store files in",
876 .type = FIO_OPT_STR_STORE,
877 .off1 = td_var_offset(filename),
878 .cb = str_filename_cb,
879 .prio = -1, /* must come after "directory" */
880 .help = "File(s) to use for the workload",
884 .type = FIO_OPT_STR_STORE,
885 .cb = str_hostname_cb,
886 .help = "Hostname for net IO engine",
891 .off1 = td_var_offset(kb_base),
892 .verify = kb_base_verify,
895 .help = "How many bytes per KB for reporting (1000 or 1024)",
900 .cb = str_lockfile_cb,
901 .off1 = td_var_offset(file_lock_mode),
902 .help = "Lock file when doing IO to it",
903 .parent = "filename",
907 .oval = FILE_LOCK_NONE,
908 .help = "No file locking",
910 { .ival = "exclusive",
911 .oval = FILE_LOCK_EXCLUSIVE,
912 .help = "Exclusive file lock",
916 .oval = FILE_LOCK_READWRITE,
917 .help = "Read vs write lock",
923 .type = FIO_OPT_STR_STORE,
924 .off1 = td_var_offset(opendir),
925 .cb = str_opendir_cb,
926 .help = "Recursively add files from this directory and down",
930 .alias = "readwrite",
933 .off1 = td_var_offset(td_ddir),
934 .help = "IO direction",
939 .oval = TD_DDIR_READ,
940 .help = "Sequential read",
943 .oval = TD_DDIR_WRITE,
944 .help = "Sequential write",
946 { .ival = "randread",
947 .oval = TD_DDIR_RANDREAD,
948 .help = "Random read",
950 { .ival = "randwrite",
951 .oval = TD_DDIR_RANDWRITE,
952 .help = "Random write",
956 .help = "Sequential read and write mix",
959 .oval = TD_DDIR_RANDRW,
960 .help = "Random read and write mix"
965 .name = "rw_sequencer",
967 .off1 = td_var_offset(rw_seq),
968 .help = "IO offset generator modifier",
971 { .ival = "sequential",
973 .help = "Generate sequential offsets",
975 { .ival = "identical",
976 .oval = RW_SEQ_IDENT,
977 .help = "Generate identical offsets",
984 .type = FIO_OPT_STR_STORE,
985 .off1 = td_var_offset(ioengine),
986 .help = "IO engine to use",
987 .def = FIO_PREFERRED_ENGINE,
990 .help = "Use read/write",
993 .help = "Use pread/pwrite",
996 .help = "Use readv/writev",
998 #ifdef FIO_HAVE_LIBAIO
1000 .help = "Linux native asynchronous IO",
1001 .cb = str_libaio_cb,
1004 #ifdef FIO_HAVE_POSIXAIO
1005 { .ival = "posixaio",
1006 .help = "POSIX asynchronous IO",
1009 #ifdef FIO_HAVE_SOLARISAIO
1010 { .ival = "solarisaio",
1011 .help = "Solaris native asynchronous IO",
1014 #ifdef FIO_HAVE_WINDOWSAIO
1015 { .ival = "windowsaio",
1016 .help = "Windows native asynchronous IO"
1020 .help = "Memory mapped IO"
1022 #ifdef FIO_HAVE_SPLICE
1024 .help = "splice/vmsplice based IO",
1026 { .ival = "netsplice",
1027 .help = "splice/vmsplice to/from the network",
1030 #ifdef FIO_HAVE_SGIO
1032 .help = "SCSI generic v3 IO",
1036 .help = "Testing engine (no data transfer)",
1039 .help = "Network IO",
1041 #ifdef FIO_HAVE_SYSLET
1042 { .ival = "syslet-rw",
1043 .help = "syslet enabled async pread/pwrite IO",
1047 .help = "CPU cycle burner engine",
1049 #ifdef FIO_HAVE_GUASI
1051 .help = "GUASI IO engine",
1054 #ifdef FIO_HAVE_BINJECT
1055 { .ival = "binject",
1056 .help = "binject direct inject block engine",
1059 #ifdef FIO_HAVE_RDMA
1061 .help = "RDMA IO engine",
1064 { .ival = "external",
1065 .help = "Load external engine (append name)",
1071 .type = FIO_OPT_INT,
1072 .off1 = td_var_offset(iodepth),
1073 .help = "Number of IO buffers to keep in flight",
1078 .name = "iodepth_batch",
1079 .alias = "iodepth_batch_submit",
1080 .type = FIO_OPT_INT,
1081 .off1 = td_var_offset(iodepth_batch),
1082 .help = "Number of IO buffers to submit in one go",
1083 .parent = "iodepth",
1088 .name = "iodepth_batch_complete",
1089 .type = FIO_OPT_INT,
1090 .off1 = td_var_offset(iodepth_batch_complete),
1091 .help = "Number of IO buffers to retrieve in one go",
1092 .parent = "iodepth",
1097 .name = "iodepth_low",
1098 .type = FIO_OPT_INT,
1099 .off1 = td_var_offset(iodepth_low),
1100 .help = "Low water mark for queuing depth",
1101 .parent = "iodepth",
1105 .type = FIO_OPT_STR_VAL,
1107 .help = "Total size of device or files",
1110 .name = "fill_device",
1112 .type = FIO_OPT_BOOL,
1113 .off1 = td_var_offset(fill_device),
1114 .help = "Write until an ENOSPC error occurs",
1119 .type = FIO_OPT_STR_VAL,
1120 .off1 = td_var_offset(file_size_low),
1121 .off2 = td_var_offset(file_size_high),
1123 .help = "Size of individual files",
1127 .alias = "fileoffset",
1128 .type = FIO_OPT_STR_VAL,
1129 .off1 = td_var_offset(start_offset),
1130 .help = "Start IO from this offset",
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_INTEL,
1495 .help = "Use hw crc32c checksums for verification",
1498 .oval = VERIFY_CRC32C,
1499 .help = "Use crc32c checksums for verification",
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 = "Give size of an IO zone",
1707 .type = FIO_OPT_STR_VAL,
1708 .off1 = td_var_offset(zone_skip),
1709 .help = "Space between IO zones",
1714 .type = FIO_OPT_STR_VAL,
1715 .cb = str_lockmem_cb,
1716 .help = "Lock down this amount of memory",
1720 .name = "rwmixread",
1721 .type = FIO_OPT_INT,
1722 .cb = str_rwmix_read_cb,
1724 .help = "Percentage of mixed workload that is reads",
1728 .name = "rwmixwrite",
1729 .type = FIO_OPT_INT,
1730 .cb = str_rwmix_write_cb,
1732 .help = "Percentage of mixed workload that is writes",
1736 .name = "rwmixcycle",
1737 .type = FIO_OPT_DEPRECATED,
1741 .type = FIO_OPT_INT,
1742 .off1 = td_var_offset(nice),
1743 .help = "Set job CPU nice value",
1748 #ifdef FIO_HAVE_IOPRIO
1751 .type = FIO_OPT_INT,
1753 .help = "Set job IO priority value",
1758 .name = "prioclass",
1759 .type = FIO_OPT_INT,
1760 .cb = str_prioclass_cb,
1761 .help = "Set job IO priority class",
1767 .name = "thinktime",
1768 .type = FIO_OPT_INT,
1769 .off1 = td_var_offset(thinktime),
1770 .help = "Idle time between IO buffers (usec)",
1774 .name = "thinktime_spin",
1775 .type = FIO_OPT_INT,
1776 .off1 = td_var_offset(thinktime_spin),
1777 .help = "Start think time by spinning this amount (usec)",
1779 .parent = "thinktime",
1782 .name = "thinktime_blocks",
1783 .type = FIO_OPT_INT,
1784 .off1 = td_var_offset(thinktime_blocks),
1785 .help = "IO buffer period between 'thinktime'",
1787 .parent = "thinktime",
1791 .type = FIO_OPT_INT,
1792 .off1 = td_var_offset(rate[0]),
1793 .off2 = td_var_offset(rate[1]),
1794 .help = "Set bandwidth rate",
1798 .type = FIO_OPT_INT,
1799 .off1 = td_var_offset(ratemin[0]),
1800 .off2 = td_var_offset(ratemin[1]),
1801 .help = "Job must meet this rate or it will be shutdown",
1805 .name = "rate_iops",
1806 .type = FIO_OPT_INT,
1807 .off1 = td_var_offset(rate_iops[0]),
1808 .off2 = td_var_offset(rate_iops[1]),
1809 .help = "Limit IO used to this number of IO operations/sec",
1812 .name = "rate_iops_min",
1813 .type = FIO_OPT_INT,
1814 .off1 = td_var_offset(rate_iops_min[0]),
1815 .off2 = td_var_offset(rate_iops_min[1]),
1816 .help = "Job must meet this rate or it will be shut down",
1817 .parent = "rate_iops",
1820 .name = "ratecycle",
1821 .type = FIO_OPT_INT,
1822 .off1 = td_var_offset(ratecycle),
1823 .help = "Window average for rate limits (msec)",
1828 .name = "invalidate",
1829 .type = FIO_OPT_BOOL,
1830 .off1 = td_var_offset(invalidate_cache),
1831 .help = "Invalidate buffer/page cache prior to running job",
1836 .type = FIO_OPT_BOOL,
1837 .off1 = td_var_offset(sync_io),
1838 .help = "Use O_SYNC for buffered writes",
1840 .parent = "buffered",
1843 .name = "bwavgtime",
1844 .type = FIO_OPT_INT,
1845 .off1 = td_var_offset(bw_avg_time),
1846 .help = "Time window over which to calculate bandwidth"
1849 .parent = "write_bw_log",
1852 .name = "iopsavgtime",
1853 .type = FIO_OPT_INT,
1854 .off1 = td_var_offset(iops_avg_time),
1855 .help = "Time window over which to calculate IOPS (msec)",
1857 .parent = "write_iops_log",
1860 .name = "create_serialize",
1861 .type = FIO_OPT_BOOL,
1862 .off1 = td_var_offset(create_serialize),
1863 .help = "Serialize creating of job files",
1867 .name = "create_fsync",
1868 .type = FIO_OPT_BOOL,
1869 .off1 = td_var_offset(create_fsync),
1870 .help = "fsync file after creation",
1874 .name = "create_on_open",
1875 .type = FIO_OPT_BOOL,
1876 .off1 = td_var_offset(create_on_open),
1877 .help = "Create files when they are opened for IO",
1882 .type = FIO_OPT_BOOL,
1883 .off1 = td_var_offset(pre_read),
1884 .help = "Pre-read files before starting official testing",
1889 .type = FIO_OPT_INT,
1890 .off1 = td_var_offset(cpuload),
1891 .help = "Use this percentage of CPU",
1894 .name = "cpuchunks",
1895 .type = FIO_OPT_INT,
1896 .off1 = td_var_offset(cpucycle),
1897 .help = "Length of the CPU burn cycles (usecs)",
1899 .parent = "cpuload",
1901 #ifdef FIO_HAVE_CPU_AFFINITY
1904 .type = FIO_OPT_INT,
1905 .cb = str_cpumask_cb,
1906 .help = "CPU affinity mask",
1909 .name = "cpus_allowed",
1910 .type = FIO_OPT_STR,
1911 .cb = str_cpus_allowed_cb,
1912 .help = "Set CPUs allowed",
1916 .name = "end_fsync",
1917 .type = FIO_OPT_BOOL,
1918 .off1 = td_var_offset(end_fsync),
1919 .help = "Include fsync at the end of job",
1923 .name = "fsync_on_close",
1924 .type = FIO_OPT_BOOL,
1925 .off1 = td_var_offset(fsync_on_close),
1926 .help = "fsync files on close",
1931 .type = FIO_OPT_BOOL,
1932 .off1 = td_var_offset(unlink),
1933 .help = "Unlink created files after job has completed",
1938 .type = FIO_OPT_STR_SET,
1939 .cb = str_exitall_cb,
1940 .help = "Terminate all jobs when one exits",
1943 .name = "stonewall",
1944 .alias = "wait_for_previous",
1945 .type = FIO_OPT_STR_SET,
1946 .off1 = td_var_offset(stonewall),
1947 .help = "Insert a hard barrier between this job and previous",
1950 .name = "new_group",
1951 .type = FIO_OPT_STR_SET,
1952 .off1 = td_var_offset(new_group),
1953 .help = "Mark the start of a new group (for reporting)",
1957 .type = FIO_OPT_STR_SET,
1958 .off1 = td_var_offset(use_thread),
1959 .help = "Use threads instead of forks",
1962 .name = "write_bw_log",
1963 .type = FIO_OPT_STR,
1964 .off1 = td_var_offset(write_bw_log),
1965 .cb = str_write_bw_log_cb,
1966 .help = "Write log of bandwidth during run",
1969 .name = "write_lat_log",
1970 .type = FIO_OPT_STR,
1971 .off1 = td_var_offset(write_lat_log),
1972 .cb = str_write_lat_log_cb,
1973 .help = "Write log of latency during run",
1976 .name = "write_iops_log",
1977 .type = FIO_OPT_STR,
1978 .off1 = td_var_offset(write_iops_log),
1979 .cb = str_write_iops_log_cb,
1980 .help = "Write log of IOPS during run",
1983 .name = "hugepage-size",
1984 .type = FIO_OPT_INT,
1985 .off1 = td_var_offset(hugepage_size),
1986 .help = "When using hugepages, specify size of each page",
1987 .def = __fio_stringify(FIO_HUGE_PAGE),
1990 .name = "group_reporting",
1991 .type = FIO_OPT_STR_SET,
1992 .off1 = td_var_offset(group_reporting),
1993 .help = "Do reporting on a per-group basis",
1996 .name = "zero_buffers",
1997 .type = FIO_OPT_STR_SET,
1998 .off1 = td_var_offset(zero_buffers),
1999 .help = "Init IO buffers to all zeroes",
2002 .name = "refill_buffers",
2003 .type = FIO_OPT_STR_SET,
2004 .off1 = td_var_offset(refill_buffers),
2005 .help = "Refill IO buffers on every IO submit",
2008 .name = "scramble_buffers",
2009 .type = FIO_OPT_BOOL,
2010 .off1 = td_var_offset(scramble_buffers),
2011 .help = "Slightly scramble buffers on every IO submit",
2015 .name = "clat_percentiles",
2016 .type = FIO_OPT_BOOL,
2017 .off1 = td_var_offset(clat_percentiles),
2018 .help = "Enable the reporting of completion latency percentiles",
2022 .name = "percentile_list",
2023 .type = FIO_OPT_FLOAT_LIST,
2024 .off1 = td_var_offset(percentile_list),
2025 .off2 = td_var_offset(overwrite_plist),
2026 .help = "Specify a custom list of percentiles to report",
2027 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2032 #ifdef FIO_HAVE_DISK_UTIL
2034 .name = "disk_util",
2035 .type = FIO_OPT_BOOL,
2036 .off1 = td_var_offset(do_disk_util),
2037 .help = "Log disk utilization statistics",
2042 .name = "gtod_reduce",
2043 .type = FIO_OPT_BOOL,
2044 .help = "Greatly reduce number of gettimeofday() calls",
2045 .cb = str_gtod_reduce_cb,
2049 .name = "disable_lat",
2050 .type = FIO_OPT_BOOL,
2051 .off1 = td_var_offset(disable_lat),
2052 .help = "Disable latency numbers",
2053 .parent = "gtod_reduce",
2057 .name = "disable_clat",
2058 .type = FIO_OPT_BOOL,
2059 .off1 = td_var_offset(disable_clat),
2060 .help = "Disable completion latency numbers",
2061 .parent = "gtod_reduce",
2065 .name = "disable_slat",
2066 .type = FIO_OPT_BOOL,
2067 .off1 = td_var_offset(disable_slat),
2068 .help = "Disable submission latency numbers",
2069 .parent = "gtod_reduce",
2073 .name = "disable_bw_measurement",
2074 .type = FIO_OPT_BOOL,
2075 .off1 = td_var_offset(disable_bw),
2076 .help = "Disable bandwidth logging",
2077 .parent = "gtod_reduce",
2082 .type = FIO_OPT_INT,
2083 .cb = str_gtod_cpu_cb,
2084 .help = "Set up dedicated gettimeofday() thread on this CPU",
2085 .verify = gtod_cpu_verify,
2088 .name = "continue_on_error",
2089 .type = FIO_OPT_BOOL,
2090 .off1 = td_var_offset(continue_on_error),
2091 .help = "Continue on non-fatal errors during IO",
2096 .type = FIO_OPT_STR_STORE,
2097 .off1 = td_var_offset(profile),
2098 .help = "Select a specific builtin performance test",
2102 .type = FIO_OPT_STR_STORE,
2103 .off1 = td_var_offset(cgroup),
2104 .help = "Add job to cgroup of this name",
2107 .name = "cgroup_weight",
2108 .type = FIO_OPT_INT,
2109 .off1 = td_var_offset(cgroup_weight),
2110 .help = "Use given weight for cgroup",
2115 .name = "cgroup_nodelete",
2116 .type = FIO_OPT_BOOL,
2117 .off1 = td_var_offset(cgroup_nodelete),
2118 .help = "Do not delete cgroups after job completion",
2123 .type = FIO_OPT_INT,
2124 .off1 = td_var_offset(uid),
2125 .help = "Run job with this user ID",
2129 .type = FIO_OPT_INT,
2130 .off1 = td_var_offset(gid),
2131 .help = "Run job with this group ID",
2138 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2141 lopt->name = (char *) name;
2142 lopt->val = FIO_GETOPT_JOB;
2143 if (o->type == FIO_OPT_STR_SET)
2144 lopt->has_arg = no_argument;
2146 lopt->has_arg = required_argument;
2149 void fio_options_dup_and_init(struct option *long_options)
2151 struct fio_option *o;
2154 options_init(options);
2157 while (long_options[i].name)
2162 add_to_lopt(&long_options[i], o, o->name);
2165 add_to_lopt(&long_options[i], o, o->alias);
2170 assert(i < FIO_NR_OPTIONS);
2174 struct fio_keyword {
2180 static struct fio_keyword fio_keywords[] = {
2182 .word = "$pagesize",
2183 .desc = "Page size in the system",
2186 .word = "$mb_memory",
2187 .desc = "Megabytes of memory online",
2191 .desc = "Number of CPUs online in the system",
2198 void fio_keywords_init(void)
2200 unsigned long long mb_memory;
2204 sprintf(buf, "%lu", page_size);
2205 fio_keywords[0].replace = strdup(buf);
2207 mb_memory = os_phys_mem() / (1024 * 1024);
2208 sprintf(buf, "%llu", mb_memory);
2209 fio_keywords[1].replace = strdup(buf);
2212 sprintf(buf, "%lu", l);
2213 fio_keywords[2].replace = strdup(buf);
2218 static char *bc_calc(char *str)
2220 char *buf, *tmp, opt[80];
2225 * No math, just return string
2227 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2232 * Split option from value, we only need to calculate the value
2234 tmp = strchr(str, '=');
2239 memset(opt, 0, sizeof(opt));
2240 strncpy(opt, str, tmp - str);
2244 sprintf(buf, "which %s > /dev/null", BC_APP);
2246 log_err("fio: bc is needed for performing math\n");
2251 sprintf(buf, "echo %s | %s", tmp, BC_APP);
2252 f = popen(buf, "r");
2258 ret = fread(buf, 1, 128, f);
2264 buf[ret - 1] = '\0';
2273 * Look for reserved variable names and replace them with real values
2275 static char *fio_keyword_replace(char *opt)
2280 for (i = 0; fio_keywords[i].word != NULL; i++) {
2281 struct fio_keyword *kw = &fio_keywords[i];
2283 while ((s = strstr(opt, kw->word)) != NULL) {
2284 char *new = malloc(strlen(opt) + 1);
2290 * Copy part of the string before the keyword and
2291 * sprintf() the replacement after it.
2293 memcpy(new, opt, olen);
2294 len = sprintf(new + olen, "%s", kw->replace);
2297 * If there's more in the original string, copy that
2300 opt += strlen(kw->word) + olen;
2302 memcpy(new + olen + len, opt, opt - o_org - 1);
2305 * replace opt and free the old opt
2311 * Check for potential math and invoke bc, if possible
2320 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2324 sort_options(opts, options, num_opts);
2326 for (ret = 0, i = 0; i < num_opts; i++) {
2327 opts[i] = fio_keyword_replace(opts[i]);
2328 ret |= parse_option(opts[i], options, td);
2334 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2336 return parse_cmd_option(opt, val, options, td);
2339 void fio_fill_default_options(struct thread_data *td)
2341 fill_default_options(td, options);
2344 int fio_show_option_help(const char *opt)
2346 return show_cmd_help(options, opt);
2349 static void __options_mem(struct thread_data *td, int alloc)
2351 struct thread_options *o = &td->o;
2352 struct fio_option *opt;
2356 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2357 if (opt->type != FIO_OPT_STR_STORE)
2360 ptr = (void *) o + opt->off1;
2363 *ptr = strdup(*ptr);
2373 * dupe FIO_OPT_STR_STORE options
2375 void options_mem_dupe(struct thread_data *td)
2377 __options_mem(td, 1);
2380 void options_mem_free(struct thread_data fio_unused *td)
2383 __options_mem(td, 0);
2387 unsigned int fio_get_kb_base(void *data)
2389 struct thread_data *td = data;
2390 unsigned int kb_base = 0;
2393 kb_base = td->o.kb_base;
2400 int add_option(struct fio_option *o)
2402 struct fio_option *__o;
2411 memcpy(&options[opt_index], o, sizeof(*o));
2415 void invalidate_profile_options(const char *prof_name)
2417 struct fio_option *o;
2421 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2422 o->type = FIO_OPT_INVALID;
2423 o->prof_name = NULL;
2429 void add_opt_posval(const char *optname, const char *ival, const char *help)
2431 struct fio_option *o;
2434 o = find_option(options, optname);
2438 for (i = 0; i < PARSE_MAX_VP; i++) {
2439 if (o->posval[i].ival)
2442 o->posval[i].ival = ival;
2443 o->posval[i].help = help;
2448 void del_opt_posval(const char *optname, const char *ival)
2450 struct fio_option *o;
2453 o = find_option(options, optname);
2457 for (i = 0; i < PARSE_MAX_VP; i++) {
2458 if (!o->posval[i].ival)
2460 if (strcmp(o->posval[i].ival, ival))
2463 o->posval[i].ival = NULL;
2464 o->posval[i].help = NULL;