X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=b390caa295263e1327d56cc250dee84485edf46a;hp=a7bbcede08d199cb7660a2771f4b715600ca8af3;hb=f1c71016a5b57412a7cacd138c1e1a786ca775f3;hpb=53a7af851836735f1ff59d2b9e1a743e7cc499e9 diff --git a/filesetup.c b/filesetup.c index a7bbcede..b390caa2 100644 --- a/filesetup.c +++ b/filesetup.c @@ -1523,6 +1523,45 @@ bool exists_and_not_regfile(const char *filename) return true; } +static void create_work_dirs(struct thread_data *td, const char *fname) +{ + char path[PATH_MAX]; + char *start, *end; + int dirfd; + bool need_close = true; + + if (td->o.directory) { + dirfd = open(td->o.directory, O_DIRECTORY | O_RDONLY); + if (dirfd < 0) { + log_err("fio: failed to open dir (%s): %d\n", + td->o.directory, errno); + assert(0); + } + } else { + dirfd = AT_FDCWD; + need_close = false; + } + + memcpy(path, fname, PATH_MAX); + start = end = path; + while ((end = strchr(end, FIO_OS_PATH_SEPARATOR)) != NULL) { + if (end == start) + break; + *end = '\0'; + errno = 0; + if (mkdirat(dirfd, start, 0600) && errno != EEXIST) { + log_err("fio: failed to create dir (%s): %d\n", + start, errno); + assert(0); + } + *end = FIO_OS_PATH_SEPARATOR; + end++; + } + if (need_close) + close(dirfd); + td->flags |= TD_F_DIRS_CREATED; +} + int add_file(struct thread_data *td, const char *fname, int numjob, int inc) { int cur_files = td->files_index; @@ -1538,6 +1577,10 @@ 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); + /* clean cloned siblings using existing files */ if (numjob && is_already_allocated(file_name) && !exists_and_not_regfile(fname))