[PATCH] Note when thread is fsyncing
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index ccf0ad8a4dc24c28262014aabdfb42a174b680b8..44463350c2acf31dae7d0017d19f7397d4a8148d 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -57,6 +57,7 @@ enum {
        TD_INITIALIZED,
        TD_RUNNING,
        TD_VERIFYING,
+       TD_FSYNCING,
        TD_EXITED,
        TD_REAPED,
 };
@@ -360,11 +361,11 @@ static int get_rw_ddir(struct thread_data *td)
                 * Check if it's time to seed a new data direction.
                 */
                if (elapsed >= td->rwmixcycle) {
-                       unsigned long v;
+                       int v;
                        long r;
 
-                       r = os_random_long(&td->random_state);
-                       v = 100UL * r / (unsigned long) (RAND_MAX + 1.0);
+                       r = os_random_long(&td->rwmix_state);
+                       v = 1 + (int) (100.0 * (r / (RAND_MAX + 1.0)));
                        if (v < td->rwmixread)
                                td->rwmix_ddir = DDIR_READ;
                        else
@@ -747,6 +748,8 @@ static void do_io(struct thread_data *td)
        struct timeval s, e;
        unsigned long usec;
 
+       td_set_runstate(td, TD_RUNNING);
+
        while (td->this_io_bytes[td->ddir] < td->io_size) {
                struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
                struct timespec *timeout;
@@ -822,8 +825,10 @@ static void do_io(struct thread_data *td)
        if (td->cur_depth)
                cleanup_pending_aio(td);
 
-       if (should_fsync(td) && td->end_fsync)
+       if (should_fsync(td) && td->end_fsync) {
+               td_set_runstate(td, TD_FSYNCING);
                sync_td(td);
+       }
 }
 
 static void cleanup_io(struct thread_data *td)
@@ -933,22 +938,6 @@ static int init_io_u(struct thread_data *td)
        return 0;
 }
 
-static void cleanup_allocs(struct thread_data *td)
-{
-       if (td->directory)
-               free(td->directory);
-       if (td->iolog_file)
-               free(td->iolog_file);
-       if (td->exec_prerun)
-               free(td->exec_prerun);
-       if (td->exec_postrun)
-               free(td->exec_postrun);
-       if (td->ioscheduler)
-               free(td->ioscheduler);
-       if (td->sysfs_root)
-               free(td->sysfs_root);
-}
-
 static int create_file(struct thread_data *td, unsigned long long size,
                       int extend)
 {
@@ -1189,7 +1178,7 @@ static int setup_file(struct thread_data *td)
        }
 
        if (td->odirect)
-               flags |= O_DIRECT;
+               flags |= OS_O_DIRECT;
 
        if (td_write(td) || td_rw(td)) {
                if (td->filetype == FIO_TYPE_FILE) {
@@ -1404,7 +1393,6 @@ err:
        }
        if (td->mmap)
                munmap(td->mmap, td->file_size);
-       cleanup_allocs(td);
        cleanup_io(td);
        cleanup_io_u(td);
        td_set_runstate(td, TD_EXITED);
@@ -1464,6 +1452,9 @@ static void check_str_update(struct thread_data *td)
                case TD_VERIFYING:
                        c = 'V';
                        break;
+               case TD_FSYNCING:
+                       c = 'F';
+                       break;
                case TD_CREATED:
                        c = 'C';
                        break;
@@ -1566,7 +1557,7 @@ static int thread_eta(struct thread_data *td, unsigned long elapsed)
                        eta_sec = INT_MAX;
        } else {
                /*
-                * thread is already done
+                * thread is already done or waiting for fsync
                 */
                eta_sec = 0;
        }
@@ -1588,7 +1579,8 @@ static void print_thread_status(void)
        for (i = 0; i < thread_number; i++) {
                struct thread_data *td = &threads[i];
 
-               if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING){
+               if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING||
+                   td->runstate == TD_FSYNCING) {
                        nr_running++;
                        t_rate += td->rate;
                        m_rate += td->ratemin;