Revamp file open/close handling
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index bf903d92c0c912aa05e8a3ecbe4e47bbc53f712c..43cc6af14e8ab632f731ae4106fce2b4e27ce5e7 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -67,7 +67,11 @@ static void terminate_threads(int group_id)
 
        for_each_td(td, i) {
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
-                       kill(td->pid, SIGQUIT);
+                       /*
+                        * if the thread is running, just let it exit
+                        */
+                       if (td->runstate < TD_RUNNING)
+                               kill(td->pid, SIGQUIT);
                        td->terminate = 1;
                        td->start_delay = 0;
                }
@@ -291,9 +295,8 @@ static void do_verify(struct thread_data *td)
                }
 
                io_u->end_io = verify_io_u;
-requeue:
-               ret = td_io_queue(td, io_u);
 
+               ret = td_io_queue(td, io_u);
                switch (ret) {
                case FIO_Q_COMPLETED:
                        if (io_u->error)
@@ -303,11 +306,12 @@ requeue:
 
                                io_u->xfer_buflen = io_u->resid;
                                io_u->xfer_buf += bytes;
-                               goto requeue;
+                               requeue_io_u(td, &io_u);
+                       } else {
+                               ret = io_u_sync_complete(td, io_u);
+                               if (ret < 0)
+                                       break;
                        }
-                       ret = io_u_sync_complete(td, io_u);
-                       if (ret < 0)
-                               break;
                        continue;
                case FIO_Q_QUEUED:
                        break;
@@ -414,9 +418,8 @@ static void do_io(struct thread_data *td)
                        put_io_u(td, io_u);
                        break;
                }
-requeue:
-               ret = td_io_queue(td, io_u);
 
+               ret = td_io_queue(td, io_u);
                switch (ret) {
                case FIO_Q_COMPLETED:
                        if (io_u->error)
@@ -426,12 +429,13 @@ requeue:
 
                                io_u->xfer_buflen = io_u->resid;
                                io_u->xfer_buf += bytes;
-                               goto requeue;
+                               requeue_io_u(td, &io_u);
+                       } else {
+                               fio_gettime(&comp_time, NULL);
+                               bytes_done = io_u_sync_complete(td, io_u);
+                               if (bytes_done < 0)
+                                       ret = bytes_done;
                        }
-                       fio_gettime(&comp_time, NULL);
-                       bytes_done = io_u_sync_complete(td, io_u);
-                       if (bytes_done < 0)
-                               ret = bytes_done;
                        break;
                case FIO_Q_QUEUED:
                        /*
@@ -730,16 +734,13 @@ static void *thread_main(void *data)
 
        if (!td->create_serialize && setup_files(td))
                goto err;
-       if (open_files(td))
-               goto err;
 
-       /*
-        * Do this late, as some IO engines would like to have the
-        * files setup prior to initializing structures.
-        */
        if (td_io_init(td))
                goto err;
 
+       if (open_files(td))
+               goto err;
+
        if (td->exec_prerun) {
                if (system(td->exec_prerun) < 0)
                        goto err;
@@ -788,9 +789,11 @@ static void *thread_main(void *data)
        }
 
        update_rusage_stat(td);
-       fio_gettime(&td->end_time, NULL);
-       td->runtime[0] = runtime[0] / 1000;
-       td->runtime[1] = runtime[1] / 1000;
+       td->ts.runtime[0] = runtime[0] / 1000;
+       td->ts.runtime[1] = runtime[1] / 1000;
+       td->ts.total_run_time = mtime_since_now(&td->epoch);
+       td->ts.io_bytes[0] = td->io_bytes[0];
+       td->ts.io_bytes[1] = td->io_bytes[1];
 
        if (td->ts.bw_log)
                finish_log(td, td->ts.bw_log, "bw");