verify: fix integer sizes in verify state file
[fio.git] / fdp.c
diff --git a/fdp.c b/fdp.c
index 0f1aae5e4b9ba0be4e5ed52f35202bc39e60d3a6..49c80d2c613466cf9e5d98171dd4c4bf727ad7a9 100644 (file)
--- a/fdp.c
+++ b/fdp.c
@@ -9,8 +9,8 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include "file.h"
 #include "fio.h"
+#include "file.h"
 
 #include "pshared.h"
 #include "fdp.h"
@@ -20,16 +20,22 @@ static int fdp_ruh_info(struct thread_data *td, struct fio_file *f,
 {
        int ret = -EINVAL;
 
-       if (td->io_ops && td->io_ops->fdp_fetch_ruhs) {
+       if (!td->io_ops) {
+               log_err("fio: no ops set in fdp init?!\n");
+               return ret;
+       }
+
+       if (td->io_ops->fdp_fetch_ruhs) {
                ret = td->io_ops->fdp_fetch_ruhs(td, f, ruhs);
                if (ret < 0) {
                        td_verror(td, errno, "fdp fetch ruhs failed");
                        log_err("%s: fdp fetch ruhs failed (%d)\n",
                                f->file_name, errno);
                }
-       } else
+       } else {
                log_err("%s: engine (%s) lacks fetch ruhs\n",
                        f->file_name, td->io_ops->name);
+       }
 
        return ret;
 }
@@ -39,7 +45,7 @@ static int init_ruh_info(struct thread_data *td, struct fio_file *f)
        struct fio_ruhs_info *ruhs, *tmp;
        int i, ret;
 
-       ruhs = scalloc(1, sizeof(*ruhs) + 128 * sizeof(*ruhs->plis));
+       ruhs = scalloc(1, sizeof(*ruhs) + FDP_MAX_RUHS * sizeof(*ruhs->plis));
        if (!ruhs)
                return -ENOMEM;
 
@@ -50,8 +56,8 @@ static int init_ruh_info(struct thread_data *td, struct fio_file *f)
                goto out;
        }
 
-       if (ruhs->nr_ruhs > 128)
-               ruhs->nr_ruhs = 128;
+       if (ruhs->nr_ruhs > FDP_MAX_RUHS)
+               ruhs->nr_ruhs = FDP_MAX_RUHS;
 
        if (td->o.fdp_nrpli == 0) {
                f->ruhs_info = ruhs;
@@ -59,7 +65,7 @@ static int init_ruh_info(struct thread_data *td, struct fio_file *f)
        }
 
        for (i = 0; i < td->o.fdp_nrpli; i++) {
-               if (td->o.fdp_plis[i] > ruhs->nr_ruhs) {
+               if (td->o.fdp_plis[i] >= ruhs->nr_ruhs) {
                        ret = -EINVAL;
                        goto out;
                }
@@ -113,7 +119,16 @@ void fdp_fill_dspec_data(struct thread_data *td, struct io_u *io_u)
                return;
        }
 
-       dspec = ruhs->plis[ruhs->pli_loc++ % ruhs->nr_ruhs];
-       io_u->dtype = 2;
+       if (td->o.fdp_pli_select == FIO_FDP_RR) {
+               if (ruhs->pli_loc >= ruhs->nr_ruhs)
+                       ruhs->pli_loc = 0;
+
+               dspec = ruhs->plis[ruhs->pli_loc++];
+       } else {
+               ruhs->pli_loc = rand_between(&td->fdp_state, 0, ruhs->nr_ruhs - 1);
+               dspec = ruhs->plis[ruhs->pli_loc];
+       }
+
+       io_u->dtype = FDP_DIR_DTYPE;
        io_u->dspec = dspec;
 }