Fix problem with f->last_completed_pos not being correct on requeues
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index a945b856eaf86afe018cb181e083df7a1636712e..296ac343fb437bd14bca2ca1691ae8b66c8670b4 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -332,6 +332,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
@@ -345,8 +346,9 @@ 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;
 
-                               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);
@@ -446,6 +448,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
@@ -459,8 +462,9 @@ 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;
 
-                               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);
@@ -662,7 +666,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;
        }
 
@@ -990,6 +998,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) {
@@ -1002,6 +1011,7 @@ reaped:
                (*nr_running)--;
                (*m_rate) -= td->o.ratemin;
                (*t_rate) -= td->o.rate;
+               pending--;
 
                if (td->error)
                        exit_value++;
@@ -1209,10 +1219,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) {