A bunch of fixes
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 1c79d6823ae95079f0b445ceac9ed7507bb9be3b..841b59a5ae3111c588338b10ef9c2477d6f5740e 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -60,6 +60,8 @@ struct io_log *agg_io_log[2];
 
 static inline void td_set_runstate(struct thread_data *td, int runstate)
 {
+       dprint(FD_PROCESS, "%d: runstate %d -> %d\n", td->pid, td->runstate,
+                                                       runstate);
        td->runstate = runstate;
 }
 
@@ -70,6 +72,7 @@ static void terminate_threads(int group_id)
 
        for_each_td(td, i) {
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
+                       dprint(FD_PROCESS, "setting terminate on %d\n",td->pid);
                        /*
                         * if the thread is running, just let it exit
                         */
@@ -590,6 +593,12 @@ sync_done:
                }
        } else
                cleanup_pending_aio(td);
+
+       /*
+        * stop job if we failed doing any IO
+        */
+       if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
+               td->done = 1;
 }
 
 static void cleanup_io_u(struct thread_data *td)
@@ -768,7 +777,10 @@ static int clear_io_state(struct thread_data *td)
 
        td->last_was_sync = 0;
 
-       if (td->o.time_based)
+       /*
+        * reset file done count if we are to start over
+        */
+       if (td->o.time_based || td->o.loops)
                td->nr_done_files = 0;
 
        for_each_file(td, f, i)
@@ -800,6 +812,8 @@ static void *thread_main(void *data)
 
        td->pid = getpid();
 
+       dprint(FD_PROCESS, "jobs pid=%d started\n", td->pid);
+
        INIT_LIST_HEAD(&td->io_u_freelist);
        INIT_LIST_HEAD(&td->io_u_busylist);
        INIT_LIST_HEAD(&td->io_u_requeues);
@@ -1062,8 +1076,11 @@ reaped:
                if (td->o.use_thread) {
                        long ret;
 
-                       if (pthread_join(td->thread, (void *) &ret))
+                       dprint(FD_PROCESS, "joining tread %d\n", td->pid);
+                       if (pthread_join(td->thread, (void *) &ret)) {
+                               dprint(FD_PROCESS, "join failed %ld\n", ret);
                                perror("pthread_join");
+                       }
                }
 
                (*nr_running)--;
@@ -1178,12 +1195,14 @@ static void run_threads(void)
                        nr_started++;
 
                        if (td->o.use_thread) {
+                               dprint(FD_PROCESS, "will pthread_create\n");
                                if (pthread_create(&td->thread, NULL, thread_main, td)) {
                                        perror("thread_create");
                                        nr_started--;
                                        break;
                                }
                        } else {
+                               dprint(FD_PROCESS, "will fork\n");
                                if (!fork()) {
                                        int ret = fork_main(shm_id, i);