Fix off-by-one in generic ffz
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index b10e83eee3b3871aa3ad7a957e3cc0ffec00ea00..c662470a09142fa83c3ba337a84b7125ace2ed12 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -32,7 +32,7 @@ static int random_map_free(struct fio_file *f, const unsigned long long block)
 
        dprint(FD_RANDOM, "free: b=%llu, idx=%u, bit=%u\n", block, idx, bit);
 
-       return (f->file_map[idx] & (1UL << bit)) == 0;
+       return (f->file_map[idx] & (1 << bit)) == 0;
 }
 
 /*
@@ -65,7 +65,7 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u)
 
                fio_assert(td, idx < f->num_maps);
 
-               f->file_map[idx] |= (1UL << bit);
+               f->file_map[idx] |= (1 << bit);
                block++;
                blocks++;
        }
@@ -107,8 +107,8 @@ static int get_next_free_block(struct thread_data *td, struct fio_file *f,
        i = f->last_free_lookup;
        *b = (i * BLOCKS_PER_MAP);
        while ((*b) * min_bs < f->real_file_size) {
-               if (f->file_map[i] != -1UL) {
-                       *b += fio_ffz(f->file_map[i]);
+               if (f->file_map[i] != (unsigned int) -1) {
+                       *b += ffz(f->file_map[i]);
                        if (*b > last_block(td, f, ddir))
                                break;
                        f->last_free_lookup = i;
@@ -350,6 +350,8 @@ void requeue_io_u(struct thread_data *td, struct io_u **io_u)
 {
        struct io_u *__io_u = *io_u;
 
+       dprint(FD_IO, "requeue %p\n", __io_u);
+
        __io_u->flags |= IO_U_F_FREE;
        if ((__io_u->flags & IO_U_F_FLIGHT) && (__io_u->ddir != DDIR_SYNC))
                td->io_issues[__io_u->ddir]--;
@@ -818,6 +820,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);
        }
 
        /*
@@ -827,8 +831,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);