#include "verify.h"
#include "parse.h"
#include "lib/fls.h"
+#include "options.h"
-#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
+static FLIST_HEAD(ext_opt_list);
/*
* Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
},
.parent = "nrfiles",
},
+#ifdef FIO_HAVE_FALLOCATE
+ {
+ .name = "fallocate",
+ .type = FIO_OPT_BOOL,
+ .off1 = td_var_offset(fallocate),
+ .help = "Use fallocate() when laying out files",
+ .def = "1",
+ },
+#endif
{
.name = "fadvise_hint",
.type = FIO_OPT_BOOL,
.help = "Continue on non-fatal errors during I/O",
.def = "0",
},
+ {
+ .name = "profile",
+ .type = FIO_OPT_STR_STORE,
+ .off1 = td_var_offset(profile),
+ .help = "Select a specific builtin performance test",
+ },
+ {
+ .name = "cgroup",
+ .type = FIO_OPT_STR_STORE,
+ .off1 = td_var_offset(cgroup),
+ .help = "Add job to cgroup of this name",
+ },
+ {
+ .name = "cgroup_weight",
+ .type = FIO_OPT_INT,
+ .off1 = td_var_offset(cgroup_weight),
+ .help = "Use given weight for cgroup",
+ .minval = 100,
+ .maxval = 1000,
+ },
+ {
+ .name = "uid",
+ .type = FIO_OPT_INT,
+ .off1 = td_var_offset(uid),
+ .help = "Run job with this user ID",
+ },
+ {
+ .name = "gid",
+ .type = FIO_OPT_INT,
+ .off1 = td_var_offset(gid),
+ .help = "Run job with this group ID",
+ },
{
.name = NULL,
},
void fio_keywords_init(void)
{
- unsigned long mb_memory;
+ unsigned long long mb_memory;
char buf[128];
long l;
sprintf(buf, "%lu", page_size);
fio_keywords[0].replace = strdup(buf);
- l = sysconf(_SC_PHYS_PAGES);
- mb_memory = l * (page_size / 1024UL);
- sprintf(buf, "%lu", mb_memory);
+ mb_memory = os_phys_mem() / page_size;
+ sprintf(buf, "%llu", mb_memory);
fio_keywords[1].replace = strdup(buf);
l = sysconf(_SC_NPROCESSORS_ONLN);
fio_keywords[2].replace = strdup(buf);
}
+#define BC_APP "bc"
+
+static char *bc_calc(char *str)
+{
+ char *buf, *tmp, opt[80];
+ FILE *f;
+ int ret;
+
+ /*
+ * No math, just return string
+ */
+ if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
+ !strchr(str, '/'))
+ return str;
+
+ /*
+ * Split option from value, we only need to calculate the value
+ */
+ tmp = strchr(str, '=');
+ if (!tmp)
+ return str;
+
+ tmp++;
+ memset(opt, 0, sizeof(opt));
+ strncpy(opt, str, tmp - str);
+
+ buf = malloc(128);
+
+ sprintf(buf, "which %s > /dev/null", BC_APP);
+ if (system(buf)) {
+ log_err("fio: bc is needed for performing math\n");
+ free(buf);
+ return NULL;
+ }
+
+ sprintf(buf, "echo %s | %s", tmp, BC_APP);
+ f = popen(buf, "r");
+ if (!f) {
+ free(buf);
+ return NULL;
+ }
+
+ ret = fread(buf, 1, 128, f);
+ if (ret <= 0) {
+ free(buf);
+ return NULL;
+ }
+
+ buf[ret - 1] = '\0';
+ strcat(opt, buf);
+ strcpy(buf, opt);
+ pclose(f);
+ free(str);
+ return buf;
+}
+
/*
* Look for reserved variable names and replace them with real values
*/
* replace opt and free the old opt
*/
opt = new;
- free(o_org);
+ //free(o_org);
+
+ /*
+ * Check for potential math and invoke bc, if possible
+ */
+ opt = bc_calc(opt);
}
}
for (ret = 0, i = 0; i < num_opts; i++) {
opts[i] = fio_keyword_replace(opts[i]);
- ret |= parse_option(opts[i], options, td);
+ ret |= parse_option(opts[i], options, &ext_opt_list, td);
}
return ret;
int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
{
- return parse_cmd_option(opt, val, options, td);
+ return parse_cmd_option(opt, val, options, &ext_opt_list, td);
}
void fio_fill_default_options(struct thread_data *td)
int fio_show_option_help(const char *opt)
{
- return show_cmd_help(options, opt);
+ return show_cmd_help(options, &ext_opt_list, opt);
}
static void __options_mem(struct thread_data *td, int alloc)
return kb_base;
}
+
+void register_ext_option(struct ext_option *eopt)
+{
+ dprint(FD_PARSE, "register option '%s'\n", eopt->o.name);
+ option_init(&eopt->o);
+ flist_add_tail(&eopt->list, &ext_opt_list);
+}
+
+void prune_profile_options(const char *prof_name)
+{
+ struct ext_option *eo;
+ struct flist_head *n, *tmp;
+
+ flist_for_each_safe(n, tmp, &ext_opt_list) {
+ eo = flist_entry(n, struct ext_option, list);
+ if (strcmp(eo->prof_name, prof_name))
+ continue;
+ flist_del(&eo->list);
+ free(eo);
+ }
+}