Fix another typo in gtod_reduce()
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index ea6c251859969b3e86775ea2ba4260de73d00194..b84b3e2307daa67f6723b1556cd9731c67ad5f36 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -11,6 +11,7 @@
 #include "trim.h"
 #include "lib/rand.h"
 #include "lib/axmap.h"
+#include "err.h"
 
 struct io_completion_data {
        int nr;                         /* input */
@@ -985,6 +986,9 @@ static struct fio_file *get_next_file_rand(struct thread_data *td,
                if (!fio_file_open(f)) {
                        int err;
 
+                       if (td->nr_open_files >= td->o.open_files)
+                               return ERR_PTR(-EBUSY);
+
                        err = td_io_open_file(td, f);
                        if (err)
                                continue;
@@ -1027,6 +1031,9 @@ static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf,
                if (!fio_file_open(f)) {
                        int err;
 
+                       if (td->nr_open_files >= td->o.open_files)
+                               return ERR_PTR(-EBUSY);
+
                        err = td_io_open_file(td, f);
                        if (err) {
                                dprint(FD_FILE, "error %d on open of %s\n",
@@ -1080,6 +1087,9 @@ static struct fio_file *__get_next_file(struct thread_data *td)
        else
                f = get_next_file_rand(td, FIO_FILE_open, FIO_FILE_closing);
 
+       if (IS_ERR(f))
+               return f;
+
        td->file_service_file = f;
        td->file_service_left = td->file_service_nr - 1;
 out:
@@ -1099,14 +1109,14 @@ static struct fio_file *get_next_file(struct thread_data *td)
        return __get_next_file(td);
 }
 
-static int set_io_u_file(struct thread_data *td, struct io_u *io_u)
+static long set_io_u_file(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f;
 
        do {
                f = get_next_file(td);
-               if (!f)
-                       return 1;
+               if (IS_ERR_OR_NULL(f))
+                       return PTR_ERR(f);
 
                io_u->file = f;
                get_file(f);
@@ -1285,6 +1295,7 @@ again:
                io_u->acct_ddir = -1;
                td->cur_depth++;
                io_u->flags |= IO_U_F_IN_CUR_DEPTH;
+               io_u->ipo = NULL;
        } else if (td->o.verify_async) {
                /*
                 * We ran out, wait for async verify threads to finish and
@@ -1399,6 +1410,7 @@ struct io_u *get_io_u(struct thread_data *td)
        struct fio_file *f;
        struct io_u *io_u;
        int do_scramble = 0;
+       long ret = 0;
 
        io_u = __get_io_u(td);
        if (!io_u) {
@@ -1424,11 +1436,17 @@ struct io_u *get_io_u(struct thread_data *td)
                if (read_iolog_get(td, io_u))
                        goto err_put;
        } else if (set_io_u_file(td, io_u)) {
+               ret = -EBUSY;
                dprint(FD_IO, "io_u %p, setting file failed\n", io_u);
                goto err_put;
        }
 
        f = io_u->file;
+       if (!f) {
+               dprint(FD_IO, "io_u %p, setting file failed\n", io_u);
+               goto err_put;
+       }
+
        assert(fio_file_open(f));
 
        if (ddir_rw(io_u->ddir)) {
@@ -1477,7 +1495,7 @@ out:
 err_put:
        dprint(FD_IO, "get_io_u failed\n");
        put_io_u(td, io_u);
-       return NULL;
+       return ERR_PTR(ret);
 }
 
 void io_u_log_error(struct thread_data *td, struct io_u *io_u)
@@ -1503,13 +1521,19 @@ void io_u_log_error(struct thread_data *td, struct io_u *io_u)
                td_verror(td, io_u->error, "io_u error");
 }
 
+static inline int gtod_reduce(struct thread_data *td)
+{
+       return td->o.disable_clat && td->o.disable_lat && td->o.disable_slat
+               && td->o.disable_bw;
+}
+
 static void account_io_completion(struct thread_data *td, struct io_u *io_u,
                                  struct io_completion_data *icd,
                                  const enum fio_ddir idx, unsigned int bytes)
 {
        unsigned long lusec = 0;
 
-       if (!td->o.disable_clat || !td->o.disable_bw)
+       if (!gtod_reduce(td))
                lusec = utime_since(&io_u->issue_time, &icd->time);
 
        if (!td->o.disable_lat) {
@@ -1541,7 +1565,8 @@ static void account_io_completion(struct thread_data *td, struct io_u *io_u,
        if (!td->o.disable_bw)
                add_bw_sample(td, idx, bytes, &icd->time);
 
-       add_iops_sample(td, idx, bytes, &icd->time);
+       if (!gtod_reduce(td))
+               add_iops_sample(td, idx, bytes, &icd->time);
 
        if (td->o.number_ios && !--td->o.number_ios)
                td->done = 1;
@@ -1568,6 +1593,15 @@ static void io_completed(struct thread_data *td, struct io_u *io_u,
        td_io_u_lock(td);
        assert(io_u->flags & IO_U_F_FLIGHT);
        io_u->flags &= ~(IO_U_F_FLIGHT | IO_U_F_BUSY_OK);
+
+       /*
+        * Mark IO ok to verify
+        */
+       if (io_u->ipo) {
+               io_u->ipo->flags &= ~IP_F_IN_FLIGHT;
+               write_barrier();
+       }
+
        td_io_u_unlock(td);
 
        if (ddir_sync(io_u->ddir)) {
@@ -1623,12 +1657,6 @@ static void io_completed(struct thread_data *td, struct io_u *io_u,
                                         utime_since_now(&td->start));
                }
 
-               if (td_write(td) && idx == DDIR_WRITE &&
-                   td->o.do_verify &&
-                   td->o.verify != VERIFY_NONE &&
-                   !td->o.experimental_verify)
-                       log_io_piece(td, io_u);
-
                icd->bytes_done[idx] += bytes;
 
                if (io_u->end_io) {
@@ -1659,7 +1687,8 @@ static void init_icd(struct thread_data *td, struct io_completion_data *icd,
                     int nr)
 {
        int ddir;
-       if (!td->o.disable_clat || !td->o.disable_bw)
+
+       if (!gtod_reduce(td))
                fio_gettime(&icd->time, NULL);
 
        icd->nr = nr;
@@ -1770,7 +1799,9 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u)
 void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
                    unsigned int max_bs)
 {
-       if (!td->o.zero_buffers) {
+       if (td->o.buffer_pattern_bytes)
+               fill_buffer_pattern(td, buf, max_bs);
+       else if (!td->o.zero_buffers) {
                unsigned int perc = td->o.compress_percentage;
 
                if (perc) {