[PATCH] Cleanup the io engine methods
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index dc228a8764f11e667f8bdfd04d854d3fd5d0d15a..1fb35fb181534b646d8b8a3545a616c7205d598c 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -219,8 +219,16 @@ static unsigned int get_next_buflen(struct thread_data *td)
                buflen = (buflen + td->min_bs - 1) & ~(td->min_bs - 1);
        }
 
-       if (buflen > td->io_size - td->this_io_bytes[td->ddir])
+       if (buflen > td->io_size - td->this_io_bytes[td->ddir]) {
+               /*
+                * if using direct/raw io, we may not be able to
+                * shrink the size. so just fail it.
+                */
+               if (td->io_ops->flags & FIO_RAWIO)
+                       return 0;
+
                buflen = td->io_size - td->this_io_bytes[td->ddir];
+       }
 
        return buflen;
 }
@@ -526,8 +534,14 @@ static struct io_u *get_io_u(struct thread_data *td, struct fio_file *f)
                return NULL;
        }
 
-       if (io_u->buflen + io_u->offset > f->file_size)
+       if (io_u->buflen + io_u->offset > f->file_size) {
+               if (td->io_ops->flags & FIO_RAWIO) {
+                       put_io_u(td, io_u);
+                       return NULL;
+               }
+
                io_u->buflen = f->file_size - io_u->offset;
+       }
 
        if (!io_u->buflen) {
                put_io_u(td, io_u);
@@ -577,11 +591,21 @@ static int get_next_verify(struct thread_data *td, struct io_u *io_u)
 
 static struct fio_file *get_next_file(struct thread_data *td)
 {
-       struct fio_file *f = &td->files[td->next_file];
+       int old_next_file = td->next_file;
+       struct fio_file *f;
 
-       td->next_file++;
-       if (td->next_file >= td->nr_files)
-               td->next_file = 0;
+       do {
+               f = &td->files[td->next_file];
+
+               td->next_file++;
+               if (td->next_file >= td->nr_files)
+                       td->next_file = 0;
+
+               if (f->fd != -1)
+                       break;
+
+               f = NULL;
+       } while (td->next_file != old_next_file);
 
        return f;
 }
@@ -594,13 +618,13 @@ static int td_io_sync(struct thread_data *td, struct fio_file *f)
        return 0;
 }
 
-static int io_u_getevents(struct thread_data *td, int min, int max,
+static int td_io_getevents(struct thread_data *td, int min, int max,
                          struct timespec *t)
 {
        return td->io_ops->getevents(td, min, max, t);
 }
 
-static int io_u_queue(struct thread_data *td, struct io_u *io_u)
+static int td_io_queue(struct thread_data *td, struct io_u *io_u)
 {
        gettimeofday(&io_u->issue_time, NULL);
 
@@ -670,7 +694,7 @@ static void cleanup_pending_aio(struct thread_data *td)
        /*
         * get immediately available events, if any
         */
-       r = io_u_getevents(td, 0, td->cur_depth, &ts);
+       r = td_io_getevents(td, 0, td->cur_depth, &ts);
        if (r > 0) {
                icd.nr = r;
                ios_completed(td, &icd);
@@ -690,7 +714,7 @@ static void cleanup_pending_aio(struct thread_data *td)
        }
 
        if (td->cur_depth) {
-               r = io_u_getevents(td, td->cur_depth, td->cur_depth, NULL);
+               r = td_io_getevents(td, td->cur_depth, td->cur_depth, NULL);
                if (r > 0) {
                        icd.nr = r;
                        ios_completed(td, &icd);
@@ -754,7 +778,7 @@ static void do_verify(struct thread_data *td)
                        break;
                }
 
-               ret = io_u_queue(td, io_u);
+               ret = td_io_queue(td, io_u);
                if (ret) {
                        put_io_u(td, io_u);
                        td_verror(td, ret);
@@ -768,7 +792,7 @@ static void do_verify(struct thread_data *td)
                if (do_io_u_verify(td, &v_io_u))
                        break;
 
-               ret = io_u_getevents(td, 1, 1, NULL);
+               ret = td_io_getevents(td, 1, 1, NULL);
                if (ret != 1) {
                        if (ret < 0)
                                td_verror(td, ret);
@@ -861,7 +885,7 @@ static void do_io(struct thread_data *td)
 
                memcpy(&s, &io_u->start_time, sizeof(s));
 
-               ret = io_u_queue(td, io_u);
+               ret = td_io_queue(td, io_u);
                if (ret) {
                        put_io_u(td, io_u);
                        td_verror(td, ret);
@@ -878,7 +902,7 @@ static void do_io(struct thread_data *td)
                        min_evts = 1;
                }
 
-               ret = io_u_getevents(td, min_evts, td->cur_depth, timeout);
+               ret = td_io_getevents(td, min_evts, td->cur_depth, timeout);
                if (ret < 0) {
                        td_verror(td, ret);
                        break;
@@ -928,7 +952,7 @@ static void do_io(struct thread_data *td)
        }
 }
 
-static int init_io(struct thread_data *td)
+static int td_io_init(struct thread_data *td)
 {
        if (td->io_ops->init)
                return td->io_ops->init(td);
@@ -1113,7 +1137,7 @@ static void *thread_main(void *data)
                goto err;
        }
 
-       if (init_io(td))
+       if (td_io_init(td))
                goto err;
 
        if (init_iolog(td))
@@ -1327,16 +1351,6 @@ static int thread_eta(struct thread_data *td, unsigned long elapsed)
 
        bytes_total = td->total_io_size;
 
-       /*
-        * if writing, bytes_total will be twice the size. If mixing,
-        * assume a 50/50 split and thus bytes_total will be 50% larger.
-        */
-       if (td->verify) {
-               if (td_rw(td))
-                       bytes_total = bytes_total * 3 / 2;
-               else
-                       bytes_total <<= 1;
-       }
        if (td->zone_size && td->zone_skip)
                bytes_total /= (td->zone_skip / td->zone_size);