Reduntant write bit checks
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index ef63ce6e4e47b384da36024e50a2c2504aa16b79..c39868dd95112a2dea7d3c497e08aeee39953d38 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -35,7 +35,6 @@
 #include <sys/mman.h>
 
 #include "fio.h"
-#include "os.h"
 
 unsigned long page_mask;
 unsigned long page_size;
@@ -70,10 +69,7 @@ static void terminate_threads(int group_id)
 
        for_each_td(td, i) {
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
-                       /*
-                        * if the thread is running, just let it exit
-                        */
-                       if (td->runstate < TD_RUNNING)
+                       if (td->runstate <= TD_RUNNING)
                                kill(td->pid, SIGQUIT);
                        td->terminate = 1;
                        td->o.start_delay = 0;
@@ -333,6 +329,7 @@ static void do_verify(struct thread_data *td)
                                ret = -io_u->error;
                        else if (io_u->resid) {
                                int bytes = io_u->xfer_buflen - io_u->resid;
+                               struct fio_file *f = io_u->file;
 
                                /*
                                 * zero read, fail
@@ -342,10 +339,20 @@ static void do_verify(struct thread_data *td)
                                        put_io_u(td, io_u);
                                        break;
                                }
+
                                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]++;
+
+                               if (io_u->offset == f->real_file_size)
+                                       goto sync_done;
+
                                requeue_io_u(td, &io_u);
                        } else {
+sync_done:
                                ret = io_u_sync_complete(td, io_u);
                                if (ret < 0)
                                        break;
@@ -440,6 +447,7 @@ static void do_io(struct thread_data *td)
                                ret = -io_u->error;
                        else if (io_u->resid) {
                                int bytes = io_u->xfer_buflen - io_u->resid;
+                               struct fio_file *f = io_u->file;
 
                                /*
                                 * zero read, fail
@@ -453,8 +461,11 @@ 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]++;
 
-                               if (io_u->offset == io_u->file->real_file_size)
+                               if (io_u->offset == f->real_file_size)
                                        goto sync_done;
 
                                requeue_io_u(td, &io_u);
@@ -630,7 +641,7 @@ static int init_io_u(struct thread_data *td)
                INIT_LIST_HEAD(&io_u->list);
 
                io_u->buf = p + max_bs * i;
-               if (td_write(td) || td_rw(td))
+               if (td_write(td))
                        fill_rand_buf(io_u, max_bs);
 
                io_u->index = i;
@@ -656,7 +667,11 @@ static int switch_ioscheduler(struct thread_data *td)
 
        f = fopen(tmp, "r+");
        if (!f) {
-               td_verror(td, errno, "fopen");
+               if (errno == ENOENT) {
+                       log_err("fio: os or kernel doesn't support IO scheduler switching\n");
+                       return 0;
+               }
+               td_verror(td, errno, "fopen iosched");
                return 1;
        }
 
@@ -984,6 +999,7 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
                /*
                 * thread is not dead, continue
                 */
+               pending++;
                continue;
 reaped:
                if (td->o.use_thread) {
@@ -996,6 +1012,7 @@ reaped:
                (*nr_running)--;
                (*m_rate) -= td->o.ratemin;
                (*t_rate) -= td->o.rate;
+               pending--;
 
                if (td->error)
                        exit_value++;
@@ -1203,10 +1220,8 @@ int main(int argc, char *argv[])
        if (parse_options(argc, argv))
                return 1;
 
-       if (!thread_number) {
-               log_err("Nothing to do\n");
-               return 1;
-       }
+       if (!thread_number)
+               return 0;
 
        ps = sysconf(_SC_PAGESIZE);
        if (ps < 0) {