filesetup: pre_read_files() can use a bool
authorJens Axboe <axboe@kernel.dk>
Thu, 2 Nov 2017 14:59:07 +0000 (08:59 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 2 Nov 2017 14:59:07 +0000 (08:59 -0600)
This flips the success return from 0 to true.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
file.h
filesetup.c

index c14f37ca55e809f534652ae6e289a214486277d3..6dbe59b250de15a9c7b2d53664e6e82dfcb90898 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1698,10 +1698,8 @@ static void *thread_main(void *data)
        if (o->exec_prerun && exec_string(o, o->exec_prerun, (const char *)"prerun"))
                goto err;
 
-       if (o->pre_read) {
-               if (pre_read_files(td) < 0)
-                       goto err;
-       }
+       if (o->pre_read && !pre_read_files(td))
+               goto err;
 
        fio_verify_init(td);
 
diff --git a/file.h b/file.h
index e3864ee505971ed3733efbf055887df92f94e8af..90fb00a35930f6793153d6cd18ca7698a59b4779 100644 (file)
--- a/file.h
+++ b/file.h
@@ -198,7 +198,7 @@ extern int __must_check generic_get_file_size(struct thread_data *, struct fio_f
 }
 #endif
 extern int __must_check file_lookup_open(struct fio_file *f, int flags);
-extern int __must_check pre_read_files(struct thread_data *);
+extern bool __must_check pre_read_files(struct thread_data *);
 extern unsigned long long get_rand_file_size(struct thread_data *td);
 extern int add_file(struct thread_data *, const char *, int, int);
 extern int add_file_exclusive(struct thread_data *, const char *);
index e7abac14947a719ef80aab27b6ea7b4d39d33ebe..0437a776d9c0d4b55564bc659cc04d0828c105c0 100644 (file)
@@ -255,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;
        }
@@ -287,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);
@@ -295,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;
        }
 
@@ -1174,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;
@@ -1182,11 +1183,11 @@ 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)