Fix refill buffers overwriting verify data
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index ce08c59ce84dea7f79487592e5a7d14febe61431..04900ee1def3ad28867d40ea829d05886d93381f 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -79,8 +79,16 @@ static inline unsigned long long last_block(struct thread_data *td,
                                            enum fio_ddir ddir)
 {
        unsigned long long max_blocks;
+       unsigned long long max_size;
 
-       max_blocks = f->io_size / (unsigned long long) td->o.min_bs[ddir];
+       /*
+        * Hmm, should we make sure that ->io_size <= ->real_file_size?
+        */
+       max_size = f->io_size;
+       if (max_size > f->real_file_size)
+               max_size = f->real_file_size;
+
+       max_blocks = max_size / (unsigned long long) td->o.min_bs[ddir];
        if (!max_blocks)
                return 0;
 
@@ -209,7 +217,7 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u)
 static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u)
 {
        const int ddir = io_u->ddir;
-       unsigned int buflen;
+       unsigned int buflen = buflen; /* silence dumb gcc warning */
        long r;
 
        if (td->o.min_bs[ddir] == td->o.max_bs[ddir])
@@ -250,7 +258,6 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u)
 
 static void set_rwmix_bytes(struct thread_data *td)
 {
-       unsigned long issues;
        unsigned int diff;
 
        /*
@@ -258,11 +265,8 @@ static void set_rwmix_bytes(struct thread_data *td)
         * buffered writes may issue a lot quicker than they complete,
         * whereas reads do not.
         */
-       issues = td->io_issues[td->rwmix_ddir] - td->rwmix_issues;
        diff = td->o.rwmix[td->rwmix_ddir ^ 1];
-
-       td->rwmix_issues = td->io_issues[td->rwmix_ddir]
-                               + (issues * ((100 - diff)) / diff);
+       td->rwmix_issues = (td->io_issues[td->rwmix_ddir] * diff) / 100;
 }
 
 static inline enum fio_ddir get_rand_ddir(struct thread_data *td)
@@ -272,7 +276,7 @@ static inline enum fio_ddir get_rand_ddir(struct thread_data *td)
 
        r = os_random_long(&td->rwmix_state);
        v = 1 + (int) (100.0 * (r / (RAND_MAX + 1.0)));
-       if (v < td->o.rwmix[DDIR_READ])
+       if (v <= td->o.rwmix[DDIR_READ])
                return DDIR_READ;
 
        return DDIR_WRITE;
@@ -814,6 +818,8 @@ struct io_u *get_io_u(struct thread_data *td)
 
                if (td->o.verify != VERIFY_NONE)
                        populate_verify_io_u(td, io_u);
+               else if (td->o.refill_buffers && io_u->ddir == DDIR_WRITE)
+                       io_u_fill_buffer(td, io_u, io_u->xfer_buflen);
        }
 
        /*
@@ -823,8 +829,6 @@ struct io_u *get_io_u(struct thread_data *td)
        io_u->xfer_buf = io_u->buf;
        io_u->xfer_buflen = io_u->buflen;
 
-       if (td->o.refill_buffers && io_u->ddir == DDIR_WRITE)
-               io_u_fill_buffer(td, io_u, io_u->xfer_buflen);
 out:
        if (!td_io_prep(td, io_u)) {
                fio_gettime(&io_u->start_time, NULL);