Don't populate random data for verify reads
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index efe838998d7a0d2dccecefab2e04c0f4ea430673..8c2f33b5e85e1e16bb3d6aea7564cbd5181a5e62 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -95,7 +95,7 @@ static unsigned long long last_block(struct thread_data *td, struct fio_file *f,
        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];
+       max_blocks = max_size / (unsigned long long) td->o.ba[ddir];
        if (!max_blocks)
                return 0;
 
@@ -113,7 +113,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) {
+       while ((*b) * min_bs < f->real_file_size &&
+               (*b) * min_bs < f->io_size) {
                if (f->file_map[i] != (unsigned int) -1) {
                        *b += ffz(f->file_map[i]);
                        if (*b > last_block(td, f, ddir))
@@ -212,7 +213,7 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u)
                        b = (f->last_pos - f->file_offset) / td->o.min_bs[ddir];
        }
 
-       io_u->offset = b * td->o.min_bs[ddir];
+       io_u->offset = b * td->o.ba[ddir];
        if (io_u->offset >= f->io_size) {
                dprint(FD_IO, "get_next_offset: offset %llu >= io_size %llu\n",
                                        io_u->offset, f->io_size);
@@ -248,7 +249,7 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u)
                buflen = minbs;
        else {
                r = os_random_long(&td->bsrange_state);
-               if (!td->o.bssplit_nr) {
+               if (!td->o.bssplit_nr[ddir]) {
                        buflen = 1 + (unsigned int) ((double) maxbs *
                                        (r / (OS_RAND_MAX + 1.0)));
                        if (buflen < minbs)
@@ -257,8 +258,8 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u)
                        long perc = 0;
                        unsigned int i;
 
-                       for (i = 0; i < td->o.bssplit_nr; i++) {
-                               struct bssplit *bsp = &td->o.bssplit[i];
+                       for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
+                               struct bssplit *bsp = &td->o.bssplit[ddir][i];
 
                                buflen = bsp->bs;
                                perc += bsp->perc;
@@ -628,6 +629,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf,
 
        do {
                long r = os_random_long(&td->next_file_state);
+               int opened = 0;
 
                fno = (unsigned int) ((double) td->o.nr_files
                        * (r / (OS_RAND_MAX + 1.0)));
@@ -635,10 +637,21 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf,
                if (f->flags & FIO_FILE_DONE)
                        continue;
 
+               if (!(f->flags & FIO_FILE_OPEN)) {
+                       int err;
+
+                       err = td_io_open_file(td, f);
+                       if (err)
+                               continue;
+                       opened = 1;
+               }
+
                if ((!goodf || (f->flags & goodf)) && !(f->flags & badf)) {
                        dprint(FD_FILE, "get_next_file_rand: %p\n", f);
                        return f;
                }
+               if (opened)
+                       td_io_close_file(td, f);
        } while (1);
 }
 
@@ -652,20 +665,39 @@ static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf,
        struct fio_file *f;
 
        do {
+               int opened = 0;
+
                f = td->files[td->next_file];
 
                td->next_file++;
                if (td->next_file >= td->o.nr_files)
                        td->next_file = 0;
 
+               dprint(FD_FILE, "trying file %s %x\n", f->file_name, f->flags);
                if (f->flags & FIO_FILE_DONE) {
                        f = NULL;
                        continue;
                }
 
+               if (!(f->flags & FIO_FILE_OPEN)) {
+                       int err;
+
+                       err = td_io_open_file(td, f);
+                       if (err) {
+                               dprint(FD_FILE, "error %d on open of %s\n",
+                                       err, f->file_name);
+                               continue;
+                       }
+                       opened = 1;
+               }
+
+               dprint(FD_FILE, "goodf=%x, badf=%x, ff=%x\n", goodf, badf, f->flags);
                if ((!goodf || (f->flags & goodf)) && !(f->flags & badf))
                        break;
 
+               if (opened)
+                       td_io_close_file(td, f);
+
                f = NULL;
        } while (td->next_file != old_next_file);
 
@@ -679,7 +711,7 @@ static struct fio_file *get_next_file(struct thread_data *td)
 
        assert(td->o.nr_files <= td->files_index);
 
-       if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files) {
+       if (td->nr_done_files >= td->o.nr_files) {
                dprint(FD_FILE, "get_next_file: nr_open=%d, nr_done=%d,"
                                " nr_files=%d\n", td->nr_open_files,
                                                  td->nr_done_files,
@@ -708,21 +740,6 @@ out:
        return f;
 }
 
-static struct fio_file *find_next_new_file(struct thread_data *td)
-{
-       struct fio_file *f;
-
-       if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files)
-               return NULL;
-
-       if (td->o.file_service_type == FIO_FSERVICE_RR)
-               f = get_next_file_rr(td, 0, FIO_FILE_OPEN);
-       else
-               f = get_next_file_rand(td, 0, FIO_FILE_OPEN);
-
-       return f;
-}
-
 static int set_io_u_file(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f;
@@ -732,46 +749,18 @@ static int set_io_u_file(struct thread_data *td, struct io_u *io_u)
                if (!f)
                        return 1;
 
-set_file:
                io_u->file = f;
                get_file(f);
 
                if (!fill_io_u(td, io_u))
                        break;
 
-               /*
-                * optimization to prevent close/open of the same file. This
-                * way we preserve queueing etc.
-                */
-               if (td->o.nr_files == 1 && td->o.time_based) {
-                       put_file_log(td, f);
-                       fio_file_reset(f);
-                       goto set_file;
-               }
-
-               /*
-                * td_io_close() does a put_file() as well, so no need to
-                * do that here.
-                */
-               dprint(FD_FILE, "%s: is done\n", f->file_name);
-               io_u->file = NULL;
+               put_file_log(td, f);
                td_io_close_file(td, f);
+               io_u->file = NULL;
                f->flags |= FIO_FILE_DONE;
                td->nr_done_files++;
-
-               /*
-                * probably not the right place to do this, but see
-                * if we need to open a new file
-                */
-               if (td->nr_open_files < td->o.open_files &&
-                   td->o.open_files != td->o.nr_files) {
-                       f = find_next_new_file(td);
-
-                       if (!f || td_io_open_file(td, f))
-                               return 1;
-
-                       goto set_file;
-               }
+               dprint(FD_FILE, "%s: is done (%d of %d)\n", f->file_name, td->nr_done_files, td->o.nr_files);
        } while (1);
 
        return 0;
@@ -849,7 +838,7 @@ struct io_u *get_io_u(struct thread_data *td)
 
                f->last_pos = io_u->offset + io_u->buflen;
 
-               if (td->o.verify != VERIFY_NONE)
+               if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_WRITE)
                        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);