Indicate 'V' verify state always
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 6e25c5fe6feb6df17a530b283612e695224437c6..6a72ce773820d0a19cad1497dd41e0a64ae31128 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -36,6 +36,7 @@
 
 #include "fio.h"
 #include "hash.h"
+#include "smalloc.h"
 
 unsigned long page_mask;
 unsigned long page_size;
@@ -49,7 +50,7 @@ int nr_thread = 0;
 int shm_id = 0;
 int temp_stall_ts;
 
-static struct fio_sem *startup_sem;
+static struct fio_mutex *startup_mutex;
 static volatile int fio_abort;
 static int exit_value;
 
@@ -60,6 +61,9 @@ struct io_log *agg_io_log[2];
 
 static inline void td_set_runstate(struct thread_data *td, int runstate)
 {
+       if (td->runstate == runstate)
+               return;
+
        dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", td->pid, td->runstate,
                                                                runstate);
        td->runstate = runstate;
@@ -82,8 +86,12 @@ static void terminate_threads(int group_id)
                         */
                        if (td->runstate < TD_RUNNING)
                                kill(td->pid, SIGQUIT);
-                       else if (td->io_ops->flags & FIO_SIGQUIT)
-                               kill(td->pid, SIGQUIT);
+                       else {
+                               struct ioengine_ops *ops = td->io_ops;
+
+                               if (ops && (ops->flags & FIO_SIGQUIT))
+                                       kill(td->pid, SIGQUIT);
+                       }
                }
        }
 }
@@ -355,7 +363,6 @@ static void do_verify(struct thread_data *td)
                                io_u->xfer_buflen = io_u->resid;
                                io_u->xfer_buf += bytes;
                                io_u->offset += bytes;
-                               f->last_completed_pos = io_u->offset;
 
                                td->ts.short_io_u[io_u->ddir]++;
 
@@ -457,8 +464,11 @@ static void do_io(struct thread_data *td)
                 * Add verification end_io handler, if asked to verify
                 * a previously written file.
                 */
-               if (td->o.verify != VERIFY_NONE)
+               if (td->o.verify != VERIFY_NONE) {
                        io_u->end_io = verify_io_u;
+                       td_set_runstate(td, TD_VERIFYING);
+               } else
+                       td_set_runstate(td, TD_RUNNING);
 
                ret = td_io_queue(td, io_u);
                switch (ret) {
@@ -481,7 +491,6 @@ static void do_io(struct thread_data *td)
                                io_u->xfer_buflen = io_u->resid;
                                io_u->xfer_buf += bytes;
                                io_u->offset += bytes;
-                               f->last_completed_pos = io_u->offset;
 
                                td->ts.short_io_u[io_u->ddir]++;
 
@@ -783,8 +792,7 @@ static int clear_io_state(struct thread_data *td)
        if (td->o.time_based || td->o.loops)
                td->nr_done_files = 0;
 
-       for_each_file(td, f, i)
-               td_io_close_file(td, f);
+       close_files(td);
 
        ret = 0;
        for_each_file(td, f, i) {
@@ -822,14 +830,14 @@ static void *thread_main(void *data)
        td->io_hist_tree = RB_ROOT;
 
        td_set_runstate(td, TD_INITIALIZED);
-       fio_sem_up(startup_sem);
-       fio_sem_down(td->mutex);
+       fio_mutex_up(startup_mutex);
+       fio_mutex_down(td->mutex);
 
        /*
-        * the ->mutex semaphore is now no longer used, close it to avoid
+        * the ->mutex mutex is now no longer used, close it to avoid
         * eating a file descriptor
         */
-       fio_sem_remove(td->mutex);
+       fio_mutex_remove(td->mutex);
 
        /*
         * May alter parameters that init_io_u() will use, so we need to
@@ -962,7 +970,7 @@ static void *thread_main(void *data)
 err:
        if (td->error)
                printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror);
-       close_files(td);
+       close_and_free_files(td);
        close_ioengine(td);
        cleanup_io_u(td);
 
@@ -1152,7 +1160,18 @@ static void run_threads(void)
                                log_err("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror);
                        td_set_runstate(td, TD_REAPED);
                        todo--;
-               }
+               } else {
+                       struct fio_file *f;
+                       unsigned int i;
+
+                       /*
+                        * for sharing to work, each job must always open
+                        * its own files. so close them, if we opened them
+                        * for creation
+                        */
+                       for_each_file(td, f, i)
+                               td_io_close_file(td, f);
+               }
 
                init_disk_util(td);
        }
@@ -1213,7 +1232,7 @@ static void run_threads(void)
                                        exit(ret);
                                }
                        }
-                       fio_sem_down(startup_sem);
+                       fio_mutex_down(startup_mutex);
                }
 
                /*
@@ -1268,7 +1287,7 @@ static void run_threads(void)
                        m_rate += td->o.ratemin;
                        t_rate += td->o.rate;
                        todo--;
-                       fio_sem_up(td->mutex);
+                       fio_mutex_up(td->mutex);
                }
 
                reap_threads(&nr_running, &t_rate, &m_rate);
@@ -1290,6 +1309,8 @@ int main(int argc, char *argv[])
 {
        long ps;
 
+       sinit();
+
        /*
         * We need locale for number printing, if it isn't set then just
         * go with the US format.
@@ -1317,7 +1338,7 @@ int main(int argc, char *argv[])
                setup_log(&agg_io_log[DDIR_WRITE]);
        }
 
-       startup_sem = fio_sem_init(0);
+       startup_mutex = fio_mutex_init(0);
 
        set_genesis_time();
 
@@ -1333,6 +1354,6 @@ int main(int argc, char *argv[])
                }
        }
 
-       fio_sem_remove(startup_sem);
+       fio_mutex_remove(startup_mutex);
        return exit_value;
 }