filesetup: __init_rand_distribution() can be void
[fio.git] / filesetup.c
index b390caa295263e1327d56cc250dee84485edf46a..2cc7158ead7eb1a8cf16020106c5002aaee9b441 100644 (file)
@@ -38,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;
 
@@ -49,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)
@@ -66,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;
@@ -258,24 +255,25 @@ err:
        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;
        }
@@ -290,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);
@@ -298,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;
        }
 
@@ -869,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);
@@ -1179,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;
@@ -1187,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;
@@ -1215,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)
@@ -1523,43 +1517,40 @@ bool exists_and_not_regfile(const char *filename)
        return true;
 }
 
-static void create_work_dirs(struct thread_data *td, const char *fname)
+static int 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);
-               }
+               snprintf(path, PATH_MAX, "%s%c%s", td->o.directory,
+                        FIO_OS_PATH_SEPARATOR, fname);
+               start = strstr(path, fname);
        } else {
-               dirfd = AT_FDCWD;
-               need_close = false;
+               snprintf(path, PATH_MAX, "%s", fname);
+               start = path;
        }
 
-       memcpy(path, fname, PATH_MAX);
-       start = end = path;
+       end = start;
        while ((end = strchr(end, FIO_OS_PATH_SEPARATOR)) != NULL) {
                if (end == start)
                        break;
                *end = '\0';
                errno = 0;
-               if (mkdirat(dirfd, start, 0600) && errno != EEXIST) {
+#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);
-                       assert(0);
+                       return 1;
                }
                *end = FIO_OS_PATH_SEPARATOR;
                end++;
        }
-       if (need_close)
-               close(dirfd);
        td->flags |= TD_F_DIRS_CREATED;
+       return 0;
 }
 
 int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
@@ -1578,8 +1569,9 @@ 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);
+           !(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) &&