verify: always log IO in the order they are issued
[fio.git] / iolog.c
diff --git a/iolog.c b/iolog.c
index b73c208e468e5e948c799d4a2d8d9beb72c60f49..5fd9416c036ec2454030b4ddf6772eab487efa30 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -110,7 +110,7 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u)
 {
        struct io_piece *ipo;
        unsigned long elapsed;
-       
+
        while (!flist_empty(&td->io_log_list)) {
                int ret;
 
@@ -141,11 +141,10 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u)
                        elapsed = mtime_since_genesis();
                        if (ipo->delay > elapsed)
                                usec_sleep(td, (ipo->delay - elapsed) * 1000);
-                               
                }
 
                free(ipo);
-               
+
                if (io_u->ddir != DDIR_WAIT)
                        return 0;
        }
@@ -189,6 +188,10 @@ void log_io_piece(struct thread_data *td, struct io_u *io_u)
        ipo->file = io_u->file;
        ipo->offset = io_u->offset;
        ipo->len = io_u->buflen;
+       ipo->numberio = io_u->numberio;
+       ipo->flags = IP_F_IN_FLIGHT;
+
+       io_u->ipo = ipo;
 
        if (io_u_should_trim(td, io_u)) {
                flist_add_tail(&ipo->trim_list, &td->trim_list);
@@ -209,7 +212,7 @@ void log_io_piece(struct thread_data *td, struct io_u *io_u)
         * drop the old one, which we rely on the rb insert/lookup for
         * handling.
         */
-       if ((!td_random(td) || !td->o.overwrite) &&
+       if (((!td->o.verifysort) || !td_random(td) || !td->o.overwrite) &&
              (file_randommap(td, ipo->file) || td->o.verify == VERIFY_NONE)) {
                INIT_FLIST_HEAD(&ipo->list);
                flist_add_tail(&ipo->list, &td->io_hist_list);
@@ -373,7 +376,7 @@ static int read_iolog2(struct thread_data *td, FILE *f)
                        ipo->fileno = fileno;
                        ipo->file_action = file_action;
                }
-                       
+
                queue_io_piece(td, ipo);
        }
 
@@ -481,27 +484,33 @@ int init_iolog(struct thread_data *td)
        int ret = 0;
 
        if (td->o.read_iolog_file) {
+               int need_swap;
+
                /*
                 * Check if it's a blktrace file and load that if possible.
                 * Otherwise assume it's a normal log file and load that.
                 */
-               if (is_blktrace(td->o.read_iolog_file))
-                       ret = load_blktrace(td, td->o.read_iolog_file);
+               if (is_blktrace(td->o.read_iolog_file, &need_swap))
+                       ret = load_blktrace(td, td->o.read_iolog_file, need_swap);
                else
                        ret = init_iolog_read(td);
        } else if (td->o.write_iolog_file)
                ret = init_iolog_write(td);
 
+       if (ret)
+               td_verror(td, EINVAL, "failed initializing iolog");
+
        return ret;
 }
 
-void setup_log(struct io_log **log, unsigned long avg_msec)
+void setup_log(struct io_log **log, unsigned long avg_msec, int log_type)
 {
        struct io_log *l = malloc(sizeof(*l));
 
        memset(l, 0, sizeof(*l));
        l->nr_samples = 0;
        l->max_samples = 1024;
+       l->log_type = log_type;
        l->log = malloc(l->max_samples * sizeof(struct io_sample));
        l->avg_msec = avg_msec;
        *log = l;
@@ -519,10 +528,10 @@ void __finish_log(struct io_log *log, const char *name)
        }
 
        for (i = 0; i < log->nr_samples; i++) {
-               fprintf(f, "%lu, %lu, %u, %u\n", log->log[i].time,
-                                               log->log[i].val,
-                                               log->log[i].ddir,
-                                               log->log[i].bs);
+               fprintf(f, "%lu, %lu, %u, %u\n",
+                               (unsigned long) log->log[i].time,
+                               (unsigned long) log->log[i].val,
+                               log->log[i].ddir, log->log[i].bs);
        }
 
        fclose(f);
@@ -537,7 +546,13 @@ void finish_log_named(struct thread_data *td, struct io_log *log,
 
        snprintf(file_name, sizeof(file_name), "%s_%s.log", prefix, postfix);
        p = basename(file_name);
-       __finish_log(log, p);
+
+       if (td->client_type == FIO_CLIENT_TYPE_GUI) {
+               fio_send_iolog(td, log, p);
+               free(log->log);
+               free(log);
+       } else
+               __finish_log(log, p);
 }
 
 void finish_log(struct thread_data *td, struct io_log *log, const char *name)