[PATCH] File creation and info fixes
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index f9b7e02ffb60a586ebf6d19c2e548df65e29367b..9a1da292f9d5b5ab580948955f36794f921ecd7a 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -563,7 +563,16 @@ void do_verify(struct thread_data *td)
        struct io_u *io_u, *v_io_u = NULL;
        struct io_completion_data icd;
        struct fio_file *f;
        struct io_u *io_u, *v_io_u = NULL;
        struct io_completion_data icd;
        struct fio_file *f;
-       int ret;
+       int ret, i;
+
+       /*
+        * sync io first and invalidate cache, to make sure we really
+        * read from disk.
+        */
+       for_each_file(td, f, i) {
+               td_io_sync(td, f);
+               file_invalidate_cache(td, f);
+       }
 
        td_set_runstate(td, TD_VERIFYING);
 
 
        td_set_runstate(td, TD_VERIFYING);
 
@@ -679,14 +688,14 @@ static void do_io(struct thread_data *td)
        struct timeval s, e;
        unsigned long usec;
        struct fio_file *f;
        struct timeval s, e;
        unsigned long usec;
        struct fio_file *f;
-       int i;
+       int i, ret = 0;
 
        td_set_runstate(td, TD_RUNNING);
 
        while (td->this_io_bytes[td->ddir] < td->io_size) {
                struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
                struct timespec *timeout;
 
        td_set_runstate(td, TD_RUNNING);
 
        while (td->this_io_bytes[td->ddir] < td->io_size) {
                struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
                struct timespec *timeout;
-               int ret, min_evts = 0;
+               int min_evts = 0;
                struct io_u *io_u;
 
                if (td->terminate)
                struct io_u *io_u;
 
                if (td->terminate)
@@ -719,9 +728,10 @@ static void do_io(struct thread_data *td)
                        min_evts = 1;
                }
 
                        min_evts = 1;
                }
 
+
                ret = td_io_getevents(td, min_evts, td->cur_depth, timeout);
                if (ret < 0) {
                ret = td_io_getevents(td, min_evts, td->cur_depth, timeout);
                if (ret < 0) {
-                       td_verror(td, ret);
+                       td_verror(td, -ret);
                        break;
                } else if (!ret)
                        continue;
                        break;
                } else if (!ret)
                        continue;
@@ -759,13 +769,15 @@ static void do_io(struct thread_data *td)
                        td_io_sync(td, f);
        }
 
                        td_io_sync(td, f);
        }
 
-       if (td->cur_depth)
-               cleanup_pending_aio(td);
+       if (!ret) {
+               if (td->cur_depth)
+                       cleanup_pending_aio(td);
 
 
-       if (should_fsync(td) && td->end_fsync) {
-               td_set_runstate(td, TD_FSYNCING);
-               for_each_file(td, f, i)
-                       td_io_sync(td, f);
+               if (should_fsync(td) && td->end_fsync) {
+                       td_set_runstate(td, TD_FSYNCING);
+                       for_each_file(td, f, i)
+                               td_io_sync(td, f);
+               }
        }
 }
 
        }
 }
 
@@ -1086,7 +1098,11 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
        for (i = 0, cputhreads = 0; i < thread_number; i++) {
                struct thread_data *td = &threads[i];
 
        for (i = 0, cputhreads = 0; i < thread_number; i++) {
                struct thread_data *td = &threads[i];
 
-               if (td->io_ops->flags & FIO_CPUIO)
+               /*
+                * ->io_ops is NULL for a thread that has closed its
+                * io engine
+                */
+               if (td->io_ops && td->io_ops->flags & FIO_CPUIO)
                        cputhreads++;
 
                if (td->runstate != TD_EXITED)
                        cputhreads++;
 
                if (td->runstate != TD_EXITED)