int _starpu_mkpath(const char *s, mode_t mode) { char *q, *r = NULL, *path = NULL, *up = NULL; int rv; rv = -1; if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0 #ifdef __MINGW32__ /* C:/ or C:\ */ || (s[0] && s[1] == ':' && (s[2] == '/' || s[2] == '\\') && !s[3]) #endif ) return 0; if ((path = strdup(s)) == NULL) STARPU_ABORT(); if ((q = strdup(s)) == NULL) STARPU_ABORT(); if ((r = dirname(q)) == NULL) goto out; if ((up = strdup(r)) == NULL) STARPU_ABORT(); if ((_starpu_mkpath(up, mode) == -1) && (errno != EEXIST)) goto out; if ((mkdir(path, mode) == -1) && (errno != EEXIST)) rv = -1; else rv = 0; out: if (up) free(up); free(q); free(path); return rv; }
void _starpu_swap_init(void) { char *backend; char *path; starpu_ssize_t size; struct starpu_disk_ops *ops; int dd; path = getenv("STARPU_DISK_SWAP"); if (!path) return; backend = getenv("STARPU_DISK_SWAP_BACKEND"); if (!backend) { _starpu_mkpath(path, S_IRWXU); ops = &starpu_disk_unistd_ops; } else if (!strcmp(backend, "stdio")) { _starpu_mkpath(path, S_IRWXU); ops = &starpu_disk_stdio_ops; } else if (!strcmp(backend, "unistd")) { _starpu_mkpath(path, S_IRWXU); ops = &starpu_disk_unistd_ops; } else if (!strcmp(backend, "unistd_o_direct")) { #ifdef STARPU_LINUX_SYS _starpu_mkpath(path, S_IRWXU); ops = &starpu_disk_unistd_o_direct_ops; #else _STARPU_DISP("Warning: o_direct support is not compiled in, could not enable disk swap"); return; #endif } else if (!strcmp(backend, "leveldb")) { #ifdef STARPU_HAVE_LEVELDB ops = &starpu_disk_leveldb_ops; #else _STARPU_DISP("Warning: leveldb support is not compiled in, could not enable disk swap"); return; #endif } else { _STARPU_DISP("Warning: unknown disk swap backend %s, could not enable disk swap", backend); return; } size = starpu_get_env_number_default("STARPU_DISK_SWAP_SIZE", -1); dd = starpu_disk_register(ops, path, size); if (dd < 0) { _STARPU_DISP("Warning: could not enable disk swap %s on %s with size %ld, could not enable disk swap", backend, path, (long) size); return; } }