Merge branch 'windows_mkdir' of https://github.com/sitsofe/fio
authorJens Axboe <axboe@kernel.dk>
Thu, 19 Dec 2019 03:13:58 +0000 (20:13 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 19 Dec 2019 03:13:58 +0000 (20:13 -0700)
* 'windows_mkdir' of https://github.com/sitsofe/fio:
  filesetup: fix directory creation issues

configure
filesetup.c
options.c
os/os-windows.h
os/os.h

index e32d5dcf8735d16c129f529ddacb0965cee71f62..a1279693a550ac45ffd4da9e1c3722c17100f9ca 100755 (executable)
--- a/configure
+++ b/configure
@@ -2316,22 +2316,6 @@ if test "$enable_cuda" = "yes" && compile_prog "" "-lcuda" "cuda"; then
 fi
 print_config "cuda" "$cuda"
 
-##########################################
-# mkdir() probe. mingw apparently has a one-argument mkdir :/
-mkdir_two="no"
-cat > $TMPC << EOF
-#include <sys/stat.h>
-#include <sys/types.h>
-int main(int argc, char **argv)
-{
-  return mkdir("/tmp/bla", 0600);
-}
-EOF
-if compile_prog "" "" "mkdir(a, b)"; then
-  mkdir_two="yes"
-fi
-print_config "mkdir(a, b)" "$mkdir_two"
-
 ##########################################
 # check for cc -march=native
 build_native="no"
@@ -2705,9 +2689,6 @@ fi
 if test "$cuda" = "yes" ; then
   output_sym "CONFIG_CUDA"
 fi
-if test "$mkdir_two" = "yes" ; then
-  output_sym "CONFIG_HAVE_MKDIR_TWO"
-fi
 if test "$march_set" = "no" && test "$build_native" = "yes" ; then
   output_sym "CONFIG_BUILD_NATIVE"
 fi
index ed3646a4bbe75e598e556970084bcb328c30fa3e..b45a58265a140700bfb96b4e6dd0930e4ed1a6c2 100644 (file)
@@ -918,26 +918,18 @@ static bool 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;
-       }
+       snprintf(path, PATH_MAX, "%s", fname);
+       start = path;
 
        end = start;
        while ((end = strchr(end, FIO_OS_PATH_SEPARATOR)) != NULL) {
-               if (end == start)
-                       break;
+               if (end == start) {
+                       end++;
+                       continue;
+               }
                *end = '\0';
                errno = 0;
-#ifdef CONFIG_HAVE_MKDIR_TWO
-               if (mkdir(path, 0600) && errno != EEXIST) {
-#else
-               if (mkdir(path) && errno != EEXIST) {
-#endif
+               if (fio_mkdir(path, 0700) && errno != EEXIST) {
                        log_err("fio: failed to create dir (%s): %d\n",
                                start, errno);
                        return false;
index fad1857e20fbfb34eb1c804981b17d86bf4b43fc..e4262def7285a68e80e9c1a295e6a4bd6dd8456a 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1235,7 +1235,8 @@ int set_name_idx(char *target, size_t tlen, char *input, int index,
                len = snprintf(target, tlen, "%s/%s.", fname,
                                client_sockaddr_str);
        } else
-               len = snprintf(target, tlen, "%s/", fname);
+               len = snprintf(target, tlen, "%s%c", fname,
+                               FIO_OS_PATH_SEPARATOR);
 
        target[tlen - 1] = '\0';
        free(p);
index 3e9f73413b26a5f2c5e778b63df4281f2e7df994..6061d8c70761447ef53ed841d3f9316313845ad4 100644 (file)
@@ -35,6 +35,7 @@ int rand_r(unsigned *);
 #define FIO_HAVE_CPU_AFFINITY
 #define FIO_HAVE_CHARDEV_SIZE
 #define FIO_HAVE_GETTID
+#define FIO_EMULATED_MKDIR_TWO
 
 #define FIO_PREFERRED_ENGINE           "windowsaio"
 #define FIO_PREFERRED_CLOCK_SOURCE     CS_CGETTIME
@@ -197,6 +198,24 @@ static inline int fio_set_sched_idle(void)
        return (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE))? 0 : -1;
 }
 
+static inline int fio_mkdir(const char *path, mode_t mode) {
+       DWORD dwAttr = GetFileAttributesA(path);
+
+       if (dwAttr != INVALID_FILE_ATTRIBUTES &&
+           (dwAttr & FILE_ATTRIBUTE_DIRECTORY)) {
+               errno = EEXIST;
+               return -1;
+       }
+
+       if (CreateDirectoryA(path, NULL) == 0) {
+               log_err("CreateDirectoryA = %d\n", GetLastError());
+               errno = win_to_posix_error(GetLastError());
+               return -1;
+       }
+
+       return 0;
+}
+
 #ifdef CONFIG_WINDOWS_XP
 #include "os-windows-xp.h"
 #else
diff --git a/os/os.h b/os/os.h
index dadcd87bcd9625daad0728ffd2d8ce4bbd473e47..9a280e541f1b505a45622f7649279650c0c1165c 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -407,4 +407,8 @@ static inline bool os_cpu_has(cpu_features feature)
 }
 #endif
 
+#ifndef FIO_EMULATED_MKDIR_TWO
+# define fio_mkdir(path, mode) mkdir(path, mode)
 #endif
+
+#endif /* FIO_OS_H */