[PATCH] fsync and stonewall fix
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 0221ca5b959440952783ffcd7fb98e957e9d02d8..d005625a5dc7af2b03e257dabcdc4d4f395c7234 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -452,7 +452,7 @@ static void do_io(struct thread_data *td)
                        usec_sleep(td, td->thinktime);
        }
 
                        usec_sleep(td, td->thinktime);
        }
 
-       if (!ret) {
+       if (!td->error) {
                if (td->cur_depth)
                        cleanup_pending_aio(td);
 
                if (td->cur_depth)
                        cleanup_pending_aio(td);
 
@@ -751,12 +751,12 @@ static void *fork_main(int shmid, int offset)
 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 {
        struct thread_data *td;
 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 {
        struct thread_data *td;
-       int i, cputhreads;
+       int i, cputhreads, pending;
 
        /*
         * reap exited threads (TD_EXITED -> TD_REAPED)
         */
 
        /*
         * reap exited threads (TD_EXITED -> TD_REAPED)
         */
-       cputhreads = 0;
+       pending = cputhreads = 0;
        for_each_td(td, i) {
                /*
                 * ->io_ops is NULL for a thread that has closed its
        for_each_td(td, i) {
                /*
                 * ->io_ops is NULL for a thread that has closed its
@@ -765,8 +765,12 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
                if (td->io_ops && td->io_ops->flags & FIO_CPUIO)
                        cputhreads++;
 
                if (td->io_ops && td->io_ops->flags & FIO_CPUIO)
                        cputhreads++;
 
-               if (td->runstate != TD_EXITED)
+               if (td->runstate != TD_EXITED) {
+                       if (td->runstate < TD_RUNNING)
+                               pending++;
+
                        continue;
                        continue;
+               }
 
                td_set_runstate(td, TD_REAPED);
 
 
                td_set_runstate(td, TD_REAPED);
 
@@ -783,7 +787,7 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
                (*t_rate) -= td->rate;
        }
 
                (*t_rate) -= td->rate;
        }
 
-       if (*nr_running == cputhreads)
+       if (*nr_running == cputhreads && !pending)
                terminate_threads(TERMINATE_ALL);
 }
 
                terminate_threads(TERMINATE_ALL);
 }