[PATCH] fio: random verify fixes, still some problems left
authorJens Axboe <axboe@suse.de>
Fri, 4 Nov 2005 13:31:16 +0000 (14:31 +0100)
committerJens Axboe <axboe@suse.de>
Fri, 4 Nov 2005 13:31:16 +0000 (14:31 +0100)
If the bsrange option is used, it tends to screw up.

fio.c

diff --git a/fio.c b/fio.c
index d5c65ddff9d932cb59f4a17d89cc9399fdf6194b..ad09746ecc61ca3f5bd53c11ebcb58a89dccc15e 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -607,11 +607,22 @@ static void fill_random_bytes(struct thread_data *td,
        }
 }
 
+static void hexdump(void *buffer, int len)
+{
+       unsigned char *p = buffer;
+       int i;
+
+       for (i = 0; i < len; i++)
+               printf("%02x", p[i]);
+       printf("\n");
+}
+
 static int verify_io_u(struct io_u *io_u)
 {
        struct verify_header *hdr = (struct verify_header *) io_u->buf;
        unsigned char *p = (unsigned char *) io_u->buf;
        struct md5_ctx md5_ctx;
+       int ret;
 
        if (hdr->fio_magic != FIO_HDR_MAGIC)
                return 1;
@@ -620,7 +631,13 @@ static int verify_io_u(struct io_u *io_u)
        p += sizeof(*hdr);
        md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr));
 
-       return memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash));
+       ret = memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash));
+       if (ret) {
+               hexdump(hdr->md5_digest, sizeof(hdr->md5_digest));
+               hexdump(md5_ctx.hash, sizeof(md5_ctx.hash));
+       }
+
+       return ret;
 }
 
 /*
@@ -682,7 +699,7 @@ static struct io_u *get_io_u(struct thread_data *td)
                return NULL;
        }
 
-       if (!td_read(td) && td->verify)
+       if (td->verify)
                populate_io_u(td, io_u);
 
        if (td->use_aio) {
@@ -719,6 +736,71 @@ static int get_next_verify(struct thread_data *td,
        return 0;
 }
 
+static void prune_io_piece_log(struct thread_data *td)
+{
+       struct io_piece *ipo;
+
+       while (!list_empty(&td->io_hist_list)) {
+               ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
+
+               list_del(&ipo->list);
+               free(ipo);
+       }
+}
+
+/*
+ * if ipo's overlap, kill old ipo
+ */
+static int ipo_overlap(struct io_piece *old, struct io_piece *new)
+{
+       unsigned long long old_end = old->offset + old->len;
+       unsigned long long new_end = new->offset + new->len;
+
+       if ((new->offset > old->offset && new->offset < old_end) ||
+           (new_end > old->offset && new_end < old_end)) {
+               list_add(&new->list, &old->list);
+               list_del(&old->list);
+               free(old);
+               return 1;
+       }
+
+       return 0;
+}
+
+/*
+ * log a succesful write, so we can unwind the log for verify
+ */
+static void log_io_piece(struct thread_data *td, struct io_u *io_u)
+{
+       struct io_piece *ipo = malloc(sizeof(*ipo));
+       struct list_head *entry;
+
+       INIT_LIST_HEAD(&ipo->list);
+       ipo->offset = io_u->offset;
+       ipo->len = io_u->buflen;
+
+       if (td->sequential) {
+               list_add_tail(&ipo->list, &td->io_hist_list);
+               return;
+       }
+
+       /*
+        * for random io, sort the list so verify will run faster
+        */
+       entry = &td->io_hist_list;
+       while ((entry = entry->prev) != &td->io_hist_list) {
+               struct io_piece *__ipo = list_entry(entry, struct io_piece, list);
+
+               if (ipo_overlap(__ipo, ipo))
+                       return;
+
+               if (__ipo->offset < ipo->offset)
+                       break;
+       }
+
+       list_add(&ipo->list, entry);
+}
+
 static void do_sync_verify(struct thread_data *td)
 {
        struct timeval t;
@@ -778,43 +860,6 @@ out:
        put_io_u(td, io_u);
 }
 
-/*
- * log a succesful write, so we can unwind the log for verify
- */
-static void log_io_piece(struct thread_data *td, struct io_u *io_u)
-{
-       struct io_piece *ipo = malloc(sizeof(*ipo));
-       struct list_head *entry;
-
-       INIT_LIST_HEAD(&ipo->list);
-       ipo->offset = io_u->offset;
-       ipo->len = io_u->buflen;
-
-       if (td->sequential) {
-               list_add_tail(&ipo->list, &td->io_hist_list);
-               return;
-       }
-
-       /*
-        * for random io, sort the list so verify will run faster
-        */
-       entry = &td->io_hist_list;
-       while ((entry = entry->prev) != &td->io_hist_list) {
-               struct io_piece *__ipo = list_entry(entry, struct io_piece, list);
-
-               if (__ipo->offset == ipo->offset &&
-                   __ipo->len == ipo->len) {
-                       free(ipo);
-                       ipo = NULL;
-                       break;
-               } else if (__ipo->offset < ipo->offset)
-                       break;
-       }
-
-       if (ipo)
-               list_add(&ipo->list, entry);
-}
-
 static void do_sync_io(struct thread_data *td)
 {
        unsigned long msec, usec;
@@ -1402,6 +1447,9 @@ static int setup_file(struct thread_data *td)
 
 static void clear_io_state(struct thread_data *td)
 {
+       if (!td->use_aio)
+               lseek(td->fd, SEEK_SET, 0);
+
        td->cur_off = 0;
        td->last_kb = 0;
        td->stat_io_kb = 0;
@@ -1463,6 +1511,7 @@ static void *thread_main(int shm_id, int offset, char *argv[])
                        memcpy(&td->lastrate, &td->stat_sample_time, sizeof(td->lastrate));
 
                clear_io_state(td);
+               prune_io_piece_log(td);
 
                if (!td->use_aio)
                        do_sync_io(td);