[PATCH] ETA fixes
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index e42c6795eae975fe8390a5fd484fb86717aeaaec..6344b58b9194055fa1bb03e1b7945772d2afc787 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1209,6 +1209,7 @@ static int file_size(struct thread_data *td)
        if (!td->file_size || td->file_size > td->real_file_size)
                td->file_size = td->real_file_size;
 
+       td->file_size -= td->file_offset;
        return 0;
 }
 
@@ -1231,6 +1232,7 @@ static int bdev_size(struct thread_data *td)
        if (!td->file_size || td->file_size > td->real_file_size)
                td->file_size = td->real_file_size;
 
+       td->file_size -= td->file_offset;
        return 0;
 }
 
@@ -1248,8 +1250,8 @@ static int get_file_size(struct thread_data *td)
        if (ret)
                return ret;
 
-       if (td->file_offset + td->file_size > td->real_file_size) {
-               fprintf(stderr, "Client%d: offset extends end (%Lu > %Lu)\n", td->thread_number, td->file_offset + td->file_size, td->real_file_size);
+       if (td->file_offset > td->real_file_size) {
+               fprintf(stderr, "Client%d: offset extends end (%Lu > %Lu)\n", td->thread_number, td->file_offset, td->real_file_size);
                return 1;
        }
 
@@ -1942,6 +1944,7 @@ static int thread_eta(struct thread_data *td, unsigned long elapsed)
 
        if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
                double perc;
+
                bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
                perc = (double) bytes_done / (double) bytes_total;
                if (perc > 1.0)
@@ -1949,7 +1952,7 @@ static int thread_eta(struct thread_data *td, unsigned long elapsed)
 
                eta_sec = (elapsed * (1.0 / perc)) - elapsed;
 
-               if (eta_sec > (td->timeout - elapsed))
+               if (td->timeout && eta_sec > (td->timeout - elapsed))
                        eta_sec = td->timeout - elapsed;
        } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED) {
                int t_eta = 0, r_eta = 0;
@@ -2005,6 +2008,8 @@ static void print_thread_status(void)
 
                if (elapsed >= 3)
                        eta_secs[i] = thread_eta(td, elapsed);
+               else
+                       eta_secs[i] = INT_MAX;
 
                check_str_update(td);
        }
@@ -2024,10 +2029,7 @@ static void print_thread_status(void)
                }
        }
 
-       if (eta_sec == INT_MAX)
-               eta_sec = 0;
-
-       if (eta_sec) {
+       if (eta_sec != INT_MAX && elapsed) {
                perc = (double) elapsed / (double) (elapsed + eta_sec);
                eta_to_str(eta_str, eta_sec);
        }
@@ -2035,7 +2037,7 @@ static void print_thread_status(void)
        printf("Threads now running (%d)", nr_running);
        if (m_rate || t_rate)
                printf(", commitrate %d/%dKiB/sec", t_rate, m_rate);
-       if (eta_sec) {
+       if (eta_sec != INT_MAX) {
                perc *= 100.0;
                printf(": [%s] [%3.2f%% done] [eta %s]", run_str, perc,eta_str);
        }