Add ->done variable to force exit when we know we are done
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index ead118ec35a0d02572a5366f4fe065a904c0cf05..bc837c444b91c7b8ad3c6c4a56317856f9bdf1ff 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -638,7 +638,11 @@ static int init_io_u(struct thread_data *td)
        if (allocate_io_mem(td))
                return 1;
 
-       p = ALIGN(td->orig_buffer);
+       if (td->o.odirect)
+               p = ALIGN(td->orig_buffer);
+       else
+               p = td->orig_buffer;
+
        for (i = 0; i < max_units; i++) {
                if (td->terminate)
                        return 1;
@@ -720,6 +724,8 @@ static int keep_running(struct thread_data *td)
 {
        unsigned long long io_done;
 
+       if (td->done)
+               return 0;
        if (td->o.time_based)
                return 1;
        if (td->o.loops) {
@@ -727,7 +733,7 @@ static int keep_running(struct thread_data *td)
                return 1;
        }
 
-       io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
+       io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE] + td->io_skip_bytes;
        if (io_done < td->o.size)
                return 1;
 
@@ -749,7 +755,8 @@ static int clear_io_state(struct thread_data *td)
 
        td->last_was_sync = 0;
 
-       td->nr_done_files = 0;
+       if (td->o.time_based)
+               td->nr_done_files = 0;
 
        for_each_file(td, f, i)
                td_io_close_file(td, f);
@@ -916,8 +923,6 @@ static void *thread_main(void *data)
                finish_log(td, td->ts.slat_log, "slat");
        if (td->ts.clat_log)
                finish_log(td, td->ts.clat_log, "clat");
-       if (td->o.write_iolog_file)
-               write_iolog_close(td);
        if (td->o.exec_postrun) {
                if (system(td->o.exec_postrun) < 0)
                        log_err("fio: postrun %s failed\n", td->o.exec_postrun);
@@ -932,6 +937,13 @@ err:
        close_files(td);
        close_ioengine(td);
        cleanup_io_u(td);
+
+       /*
+        * do this very late, it will log file closing as well
+        */
+       if (td->o.write_iolog_file)
+               write_iolog_close(td);
+
        options_mem_free(td);
        td_set_runstate(td, TD_EXITED);
        return (void *) (unsigned long) td->error;