X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=options.c;h=3c37e9105698cbabb0f46d66816de93762d8cd3e;hp=c56b9dfb63e8795e6b2dd623add21cb6c0c99a4e;hb=3c48c2c1c702047f8a92fa21fdd1471781b9dab4;hpb=757aff4f5cdf8bc1e0720c01564838aed968c1db diff --git a/options.c b/options.c index c56b9dfb..3c37e910 100644 --- a/options.c +++ b/options.c @@ -5,6 +5,10 @@ #include #include #include +#include +#include +#include +#include #include "fio.h" #include "parse.h" @@ -28,6 +32,122 @@ static char *get_opt_postfix(const char *str) return strdup(p); } +static int bs_cmp(const void *p1, const void *p2) +{ + const struct bssplit *bsp1 = p1; + const struct bssplit *bsp2 = p2; + + return bsp1->perc < bsp2->perc; +} + +static int str_bssplit_cb(void *data, const char *input) +{ + struct thread_data *td = data; + char *fname, *str, *p; + unsigned int i, perc, perc_missing; + unsigned int max_bs, min_bs; + long long val; + + p = str = strdup(input); + + strip_blank_front(&str); + strip_blank_end(str); + + td->o.bssplit_nr = 4; + td->o.bssplit = malloc(4 * sizeof(struct bssplit)); + + i = 0; + max_bs = 0; + min_bs = -1; + while ((fname = strsep(&str, ":")) != NULL) { + char *perc_str; + + if (!strlen(fname)) + break; + + /* + * grow struct buffer, if needed + */ + if (i == td->o.bssplit_nr) { + td->o.bssplit_nr <<= 1; + td->o.bssplit = realloc(td->o.bssplit, + td->o.bssplit_nr + * sizeof(struct bssplit)); + } + + perc_str = strstr(fname, "/"); + if (perc_str) { + *perc_str = '\0'; + perc_str++; + perc = atoi(perc_str); + if (perc > 100) + perc = 100; + else if (!perc) + perc = -1; + } else + perc = -1; + + if (str_to_decimal(fname, &val, 1)) { + log_err("fio: bssplit conversion failed\n"); + free(td->o.bssplit); + return 1; + } + + if (val > max_bs) + max_bs = val; + if (val < min_bs) + min_bs = val; + + td->o.bssplit[i].bs = val; + td->o.bssplit[i].perc = perc; + i++; + } + + td->o.bssplit_nr = i; + + /* + * Now check if the percentages add up, and how much is missing + */ + perc = perc_missing = 0; + for (i = 0; i < td->o.bssplit_nr; i++) { + struct bssplit *bsp = &td->o.bssplit[i]; + + if (bsp->perc == (unsigned char) -1) + perc_missing++; + else + perc += bsp->perc; + } + + if (perc > 100) { + log_err("fio: bssplit percentages add to more than 100%%\n"); + free(td->o.bssplit); + return 1; + } + /* + * If values didn't have a percentage set, divide the remains between + * them. + */ + if (perc_missing) { + for (i = 0; i < td->o.bssplit_nr; i++) { + struct bssplit *bsp = &td->o.bssplit[i]; + + if (bsp->perc == (unsigned char) -1) + bsp->perc = (100 - perc) / perc_missing; + } + } + + td->o.min_bs[DDIR_READ] = td->o.min_bs[DDIR_WRITE] = min_bs; + td->o.max_bs[DDIR_READ] = td->o.max_bs[DDIR_WRITE] = max_bs; + + /* + * now sort based on percentages, for ease of lookup + */ + qsort(td->o.bssplit, td->o.bssplit_nr, sizeof(struct bssplit), bs_cmp); + + free(p); + return 0; +} + static int str_rw_cb(void *data, const char *str) { struct thread_data *td = data; @@ -61,6 +181,24 @@ static int str_lockmem_cb(void fio_unused *data, unsigned long *val) return 0; } +static int str_rwmix_read_cb(void *data, unsigned int *val) +{ + struct thread_data *td = data; + + td->o.rwmix[DDIR_READ] = *val; + td->o.rwmix[DDIR_WRITE] = 100 - *val; + return 0; +} + +static int str_rwmix_write_cb(void *data, unsigned int *val) +{ + struct thread_data *td = data; + + td->o.rwmix[DDIR_WRITE] = *val; + td->o.rwmix[DDIR_READ] = 100 - *val; + return 0; +} + #ifdef FIO_HAVE_IOPRIO static int str_prioclass_cb(void *data, unsigned int *val) { @@ -137,7 +275,6 @@ static int str_cpus_allowed_cb(void *data, const char *input) free(p); td->o.cpumask_set = 1; - exit(0); return 0; } #endif @@ -154,6 +291,45 @@ static int str_fst_cb(void *data, const char *str) return 0; } +static int check_dir(struct thread_data *td, char *fname) +{ + char file[PATH_MAX], *dir; + int elen = 0; + + if (td->o.directory) { + strcpy(file, td->o.directory); + strcat(file, "/"); + elen = strlen(file); + } + + sprintf(file + elen, "%s", fname); + dir = dirname(file); + +#if 0 + { + struct stat sb; + /* + * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded + * yet, so we can't do this check right here... + */ + if (lstat(dir, &sb) < 0) { + int ret = errno; + + log_err("fio: %s is not a directory\n", dir); + td_verror(td, ret, "lstat"); + return 1; + } + + if (!S_ISDIR(sb.st_mode)) { + log_err("fio: %s is not a directory\n", dir); + return 1; + } + } +#endif + + return 0; +} + static int str_filename_cb(void *data, const char *input) { struct thread_data *td = data; @@ -170,6 +346,10 @@ static int str_filename_cb(void *data, const char *input) while ((fname = strsep(&str, ":")) != NULL) { if (!strlen(fname)) break; + if (check_dir(td, fname)) { + free(p); + return 1; + } add_file(td, fname); td->o.nr_files++; } @@ -184,8 +364,10 @@ static int str_directory_cb(void *data, const char fio_unused *str) struct stat sb; if (lstat(td->o.directory, &sb) < 0) { + int ret = errno; + log_err("fio: %s is not a directory\n", td->o.directory); - td_verror(td, errno, "lstat"); + td_verror(td, ret, "lstat"); return 1; } if (!S_ISDIR(sb.st_mode)) { @@ -219,27 +401,12 @@ static int str_verify_offset_cb(void *data, unsigned int *off) return 0; } -static int str_verify_cb(void *data, const char *mem) +static int str_verify_pattern_cb(void *data, unsigned int *off) { struct thread_data *td = data; - unsigned int nr, msb; - char *pat; - - if (td->o.verify != VERIFY_PATTERN) - return 0; - - pat = get_opt_postfix(mem); - if (!pat) { - log_err("fio: missing pattern\n"); - return 1; - } + unsigned int msb; - if (strstr(pat, "0x") || strstr(pat, "0X")) - nr = strtol(pat, NULL, 16); - else - nr = strtol(pat, NULL, 16); - - msb = fls(nr); + msb = __fls(*off); if (msb <= 8) td->o.verify_pattern_bytes = 1; else if (msb <= 16) @@ -249,7 +416,19 @@ static int str_verify_cb(void *data, const char *mem) else td->o.verify_pattern_bytes = 4; - td->o.verify_pattern = nr; + td->o.verify_pattern = *off; + return 0; +} + +static int str_lockfile_cb(void *data, const char *str) +{ + struct thread_data *td = data; + char *nr = get_opt_postfix(str); + + td->o.lockfile_batch = 1; + if (nr) + td->o.lockfile_batch = atoi(nr); + return 0; } @@ -286,6 +465,30 @@ static struct fio_option options[] = { .cb = str_filename_cb, .help = "File(s) to use for the workload", }, + { + .name = "lockfile", + .type = FIO_OPT_STR, + .cb = str_lockfile_cb, + .off1 = td_var_offset(file_lock_mode), + .help = "Lock file when doing IO to it", + .parent = "filename", + .def = "none", + .posval = { + { .ival = "none", + .oval = FILE_LOCK_NONE, + .help = "No file locking", + }, + { .ival = "exclusive", + .oval = FILE_LOCK_EXCLUSIVE, + .help = "Exclusive file lock", + }, + { + .ival = "readwrite", + .oval = FILE_LOCK_READWRITE, + .help = "Read vs write lock", + }, + }, + }, { .name = "opendir", .type = FIO_OPT_STR_STORE, @@ -341,6 +544,9 @@ static struct fio_option options[] = { { .ival = "psync", .help = "Use pread/pwrite", }, + { .ival = "vsync", + .help = "Use readv/writev", + }, #ifdef FIO_HAVE_LIBAIO { .ival = "libaio", .help = "Linux native asynchronous IO", @@ -350,6 +556,11 @@ static struct fio_option options[] = { { .ival = "posixaio", .help = "POSIX asynchronous IO", }, +#endif +#ifdef FIO_HAVE_SOLARISAIO + { .ival = "solarisaio", + .help = "Solaris native asynchronous IO", + }, #endif { .ival = "mmap", .help = "Memory mapped IO", @@ -405,6 +616,8 @@ static struct fio_option options[] = { .off1 = td_var_offset(iodepth_batch), .help = "Number of IO to submit in one go", .parent = "iodepth", + .minval = 1, + .def = "1", }, { .name = "iodepth_low", @@ -420,6 +633,13 @@ static struct fio_option options[] = { .minval = 1, .help = "Total size of device or files", }, + { + .name = "fill_device", + .type = FIO_OPT_BOOL, + .off1 = td_var_offset(fill_device), + .help = "Write until an ENOSPC error occurs", + .def = "0", + }, { .name = "filesize", .type = FIO_OPT_STR_VAL, @@ -459,6 +679,13 @@ static struct fio_option options[] = { .help = "Set block size range (in more detail than bs)", .parent = "rw", }, + { + .name = "bssplit", + .type = FIO_OPT_STR, + .cb = str_bssplit_cb, + .help = "Set a specific mix of block sizes", + .parent = "rw", + }, { .name = "bs_unaligned", .alias = "blocksize_unaligned", @@ -482,6 +709,14 @@ static struct fio_option options[] = { .help = "Accept potential duplicate random blocks", .parent = "rw", }, + { + .name = "softrandommap", + .type = FIO_OPT_BOOL, + .off1 = td_var_offset(softrandommap), + .help = "Allow randommap to fail and continue witout", + .parent = "norandommap", + .def = "0", + }, { .name = "nrfiles", .type = FIO_OPT_INT, @@ -624,7 +859,6 @@ static struct fio_option options[] = { .name = "verify", .type = FIO_OPT_STR, .off1 = td_var_offset(verify), - .cb = str_verify_cb, .help = "Verify data written", .def = "0", .posval = { @@ -664,10 +898,6 @@ static struct fio_option options[] = { .oval = VERIFY_META, .help = "Use io information", }, - { .ival = "pattern", - .oval = VERIFY_PATTERN, - .help = "Verify a specific buffer pattern", - }, { .ival = "null", .oval = VERIFY_NULL, @@ -704,7 +934,14 @@ static struct fio_option options[] = { .type = FIO_OPT_STR_VAL_INT, .help = "Offset verify header location by N bytes", .def = "0", - .cb = str_verify_offset_cb, + .cb = str_verify_offset_cb, + .parent = "verify", + }, + { + .name = "verify_pattern", + .type = FIO_OPT_INT, + .cb = str_verify_pattern_cb, + .help = "Fill pattern for IO buffers", .parent = "verify", }, { @@ -771,7 +1008,7 @@ static struct fio_option options[] = { { .name = "rwmixread", .type = FIO_OPT_INT, - .off1 = td_var_offset(rwmix[DDIR_READ]), + .cb = str_rwmix_read_cb, .maxval = 100, .help = "Percentage of mixed workload that is reads", .def = "50", @@ -779,18 +1016,14 @@ static struct fio_option options[] = { { .name = "rwmixwrite", .type = FIO_OPT_INT, - .off1 = td_var_offset(rwmix[DDIR_WRITE]), + .cb = str_rwmix_write_cb, .maxval = 100, .help = "Percentage of mixed workload that is writes", .def = "50", }, { .name = "rwmixcycle", - .type = FIO_OPT_INT, - .off1 = td_var_offset(rwmixcycle), - .help = "Cycle period for mixed read/write workloads (msec)", - .def = "500", - .parent = "rwmixread", + .type = FIO_OPT_DEPRECATED, }, { .name = "nice", @@ -895,7 +1128,8 @@ static struct fio_option options[] = { .name = "bwavgtime", .type = FIO_OPT_INT, .off1 = td_var_offset(bw_avg_time), - .help = "Time window over which to calculate bandwidth (msec)", + .help = "Time window over which to calculate bandwidth" + " (msec)", .def = "500", }, { @@ -999,7 +1233,7 @@ static struct fio_option options[] = { }, { .name = "hugepage-size", - .type = FIO_OPT_STR_VAL, + .type = FIO_OPT_STR_VAL_INT, .off1 = td_var_offset(hugepage_size), .help = "When using hugepages, specify size of each page", .def = __stringify(FIO_HUGE_PAGE), @@ -1016,6 +1250,12 @@ static struct fio_option options[] = { .off1 = td_var_offset(zero_buffers), .help = "Init IO buffers to all zeroes", }, + { + .name = "refill_buffers", + .type = FIO_OPT_STR_SET, + .off1 = td_var_offset(refill_buffers), + .help = "Refill IO buffers on every IO submit", + }, #ifdef FIO_HAVE_DISK_UTIL { .name = "disk_util", @@ -1043,7 +1283,7 @@ void fio_options_dup_and_init(struct option *long_options) o = &options[0]; while (o->name) { - long_options[i].name = o->name; + long_options[i].name = (char *) o->name; long_options[i].val = FIO_GETOPT_JOB; if (o->type == FIO_OPT_STR_SET) long_options[i].has_arg = no_argument;