X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=2cc7158ead7eb1a8cf16020106c5002aaee9b441;hp=4ceaef6b376716b2ffa0b77aa308e1d741e2c18a;hb=3a03f0cf8005221d90045bed762e7d5e38f944fb;hpb=47534cda051d15767f175967b91ef56771adb0e0 diff --git a/filesetup.c b/filesetup.c index 4ceaef6b..2cc7158e 100644 --- a/filesetup.c +++ b/filesetup.c @@ -15,7 +15,6 @@ #include "os/os.h" #include "hash.h" #include "lib/axmap.h" -#include "lib/memalign.h" #ifdef CONFIG_LINUX_FALLOCATE #include @@ -39,7 +38,7 @@ static inline void clear_error(struct thread_data *td) td->verror[0] = '\0'; } -static inline int native_fallocate(struct thread_data *td, struct fio_file *f) +static int native_fallocate(struct thread_data *td, struct fio_file *f) { bool success; @@ -50,12 +49,12 @@ static inline int native_fallocate(struct thread_data *td, struct fio_file *f) !success ? "un": ""); if (success) - return 0; + return false; if (errno == ENOSYS) dprint(FD_FILE, "native fallocate is not implemented\n"); - return -1; + return true; } static void fallocate_file(struct thread_data *td, struct fio_file *f) @@ -67,10 +66,7 @@ static void fallocate_file(struct thread_data *td, struct fio_file *f) switch (td->o.fallocate_mode) { case FIO_FALLOCATE_NATIVE: - r = native_fallocate(td, f); - if (r != 0 && errno != ENOSYS) - log_err("fio: native_fallocate call failed: %s\n", - strerror(errno)); + native_fallocate(td, f); break; case FIO_FALLOCATE_NONE: break; @@ -147,8 +143,6 @@ static int extend_file(struct thread_data *td, struct fio_file *f) flags |= O_CREAT; if (new_layout) flags |= O_TRUNC; - if (td->o.odirect) - flags |= OS_O_DIRECT; #ifdef WIN32 flags |= _O_BINARY; @@ -162,14 +156,8 @@ static int extend_file(struct thread_data *td, struct fio_file *f) if (err == ENOENT && !td->o.allow_create) log_err("fio: file creation disallowed by " "allow_file_create=0\n"); - else { - if (err == EINVAL && (flags & OS_O_DIRECT)) - log_err("fio: looks like your filesystem " - "does not support " - "direct=1/buffered=0\n"); - + else td_verror(td, err, "open"); - } return 1; } @@ -196,17 +184,14 @@ static int extend_file(struct thread_data *td, struct fio_file *f) } } - if (td->o.odirect && !OS_O_DIRECT && fio_set_directio(td, f)) - goto err; - left = f->real_file_size; bs = td->o.max_bs[DDIR_WRITE]; if (bs > left) bs = left; - b = fio_memalign(page_size, bs); + b = malloc(bs); if (!b) { - td_verror(td, errno, "fio_memalign"); + td_verror(td, errno, "malloc"); goto err; } @@ -259,35 +244,36 @@ static int extend_file(struct thread_data *td, struct fio_file *f) f->io_size = f->real_file_size; } - fio_memfree(b, bs); + free(b); done: return 0; err: close(f->fd); f->fd = -1; if (b) - fio_memfree(b, bs); + free(b); return 1; } -static int pre_read_file(struct thread_data *td, struct fio_file *f) +static bool pre_read_file(struct thread_data *td, struct fio_file *f) { - int ret = 0, r, did_open = 0, old_runstate; + int r, did_open = 0, old_runstate; unsigned long long left; unsigned int bs; + bool ret = true; char *b; if (td_ioengine_flagged(td, FIO_PIPEIO) || td_ioengine_flagged(td, FIO_NOIO)) - return 0; + return true; if (f->filetype == FIO_TYPE_CHAR) - return 0; + return true; if (!fio_file_open(f)) { if (td->io_ops->open_file(td, f)) { log_err("fio: cannot pre-read, failed to open file\n"); - return 1; + return false; } did_open = 1; } @@ -302,7 +288,7 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) b = malloc(bs); if (!b) { td_verror(td, errno, "malloc"); - ret = 1; + ret = false; goto error; } memset(b, 0, bs); @@ -310,7 +296,7 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) if (lseek(f->fd, f->file_offset, SEEK_SET) < 0) { td_verror(td, errno, "lseek"); log_err("fio: failed to lseek pre-read file\n"); - ret = 1; + ret = false; goto error; } @@ -881,12 +867,10 @@ uint64_t get_start_offset(struct thread_data *td, struct fio_file *f) if (o->start_offset_percent > 0) { /* - * if blockalign is provided, find the min across read, write, - * and trim + * if offset_align is provided, set initial offset */ - if (fio_option_is_set(o, ba)) { - align_bs = (unsigned long long) min(o->ba[DDIR_READ], o->ba[DDIR_WRITE]); - align_bs = min((unsigned long long) o->ba[DDIR_TRIM], align_bs); + if (fio_option_is_set(o, start_offset_align)) { + align_bs = o->start_offset_align; } else { /* else take the minimum block size */ align_bs = td_min_bs(td); @@ -1191,7 +1175,7 @@ err_out: return 1; } -int pre_read_files(struct thread_data *td) +bool pre_read_files(struct thread_data *td) { struct fio_file *f; unsigned int i; @@ -1199,14 +1183,14 @@ int pre_read_files(struct thread_data *td) dprint(FD_FILE, "pre_read files\n"); for_each_file(td, f, i) { - if (pre_read_file(td, f)) - return -1; + if (!pre_read_file(td, f)) + return false; } - return 0; + return true; } -static int __init_rand_distribution(struct thread_data *td, struct fio_file *f) +static void __init_rand_distribution(struct thread_data *td, struct fio_file *f) { unsigned int range_size, seed; unsigned long nranges; @@ -1227,8 +1211,6 @@ static int __init_rand_distribution(struct thread_data *td, struct fio_file *f) pareto_init(&f->zipf, nranges, td->o.pareto_h.u.f, seed); else if (td->o.random_distribution == FIO_RAND_DIST_GAUSS) gauss_init(&f->gauss, nranges, td->o.gauss_dev.u.f, seed); - - return 1; } static int init_rand_distribution(struct thread_data *td) @@ -1354,6 +1336,7 @@ void close_and_free_files(struct thread_data *td) { struct fio_file *f; unsigned int i; + bool use_free = td_ioengine_flagged(td, FIO_NOFILEHASH); dprint(FD_FILE, "close files\n"); @@ -1373,13 +1356,19 @@ void close_and_free_files(struct thread_data *td) td_io_unlink_file(td, f); } - sfree(f->file_name); + if (use_free) + free(f->file_name); + else + sfree(f->file_name); f->file_name = NULL; if (fio_file_axmap(f)) { axmap_free(f->io_axmap); f->io_axmap = NULL; } - sfree(f); + if (use_free) + free(f); + else + sfree(f); } td->o.filename = NULL; @@ -1493,7 +1482,10 @@ static struct fio_file *alloc_new_file(struct thread_data *td) { struct fio_file *f; - f = smalloc(sizeof(*f)); + if (td_ioengine_flagged(td, FIO_NOFILEHASH)) + f = calloc(1, sizeof(*f)); + else + f = smalloc(sizeof(*f)); if (!f) { assert(0); return NULL; @@ -1525,6 +1517,42 @@ bool exists_and_not_regfile(const char *filename) return true; } +static int create_work_dirs(struct thread_data *td, const char *fname) +{ + char path[PATH_MAX]; + char *start, *end; + + if (td->o.directory) { + snprintf(path, PATH_MAX, "%s%c%s", td->o.directory, + FIO_OS_PATH_SEPARATOR, fname); + start = strstr(path, fname); + } else { + snprintf(path, PATH_MAX, "%s", fname); + start = path; + } + + end = start; + while ((end = strchr(end, FIO_OS_PATH_SEPARATOR)) != NULL) { + if (end == start) + break; + *end = '\0'; + errno = 0; +#ifdef CONFIG_HAVE_MKDIR_TWO + if (mkdir(path, 0600) && errno != EEXIST) { +#else + if (mkdir(path) && errno != EEXIST) { +#endif + log_err("fio: failed to create dir (%s): %d\n", + start, errno); + return 1; + } + *end = FIO_OS_PATH_SEPARATOR; + end++; + } + td->flags |= TD_F_DIRS_CREATED; + return 0; +} + int add_file(struct thread_data *td, const char *fname, int numjob, int inc) { int cur_files = td->files_index; @@ -1540,6 +1568,11 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) sprintf(file_name + len, "%s", fname); + if (strchr(fname, FIO_OS_PATH_SEPARATOR) && + !(td->flags & TD_F_DIRS_CREATED) && + create_work_dirs(td, fname)) + return 1; + /* clean cloned siblings using existing files */ if (numjob && is_already_allocated(file_name) && !exists_and_not_regfile(fname)) @@ -1576,7 +1609,10 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) if (td->io_ops && td_ioengine_flagged(td, FIO_DISKLESSIO)) f->real_file_size = -1ULL; - f->file_name = smalloc_strdup(file_name); + if (td_ioengine_flagged(td, FIO_NOFILEHASH)) + f->file_name = strdup(file_name); + else + f->file_name = smalloc_strdup(file_name); if (!f->file_name) assert(0); @@ -1600,7 +1636,8 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) if (f->filetype == FIO_TYPE_FILE) td->nr_normal_files++; - set_already_allocated(file_name); + if (td->o.numjobs > 1) + set_already_allocated(file_name); if (inc) td->o.nr_files++; @@ -1723,7 +1760,7 @@ static int recurse_dir(struct thread_data *td, const char *dirname) if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) continue; - sprintf(full_path, "%s%s%s", dirname, FIO_OS_PATH_SEPARATOR, dir->d_name); + sprintf(full_path, "%s%c%s", dirname, FIO_OS_PATH_SEPARATOR, dir->d_name); if (lstat(full_path, &sb) == -1) { if (errno != ENOENT) { @@ -1780,7 +1817,10 @@ void dup_files(struct thread_data *td, struct thread_data *org) __f = alloc_new_file(td); if (f->file_name) { - __f->file_name = smalloc_strdup(f->file_name); + if (td_ioengine_flagged(td, FIO_NOFILEHASH)) + __f->file_name = strdup(f->file_name); + else + __f->file_name = smalloc_strdup(f->file_name); if (!__f->file_name) assert(0); @@ -1862,7 +1902,7 @@ void filesetup_mem_free(void) int fio_set_directio(struct thread_data *td, struct fio_file *f) { #ifdef FIO_OS_DIRECTIO - int ret = fio_set_odirect(f->fd); + int ret = fio_set_odirect(f); if (ret) { td_verror(td, ret, "fio_set_directio"); @@ -1880,6 +1920,7 @@ int fio_set_directio(struct thread_data *td, struct fio_file *f) return 0; #else + log_err("fio: direct IO is not supported on this host operating system\n"); return -1; #endif }