Allow verification of random overwrites w/ba < bs
[fio.git] / iolog.c
diff --git a/iolog.c b/iolog.c
index 785e549acee76ed8f40de68615d355bcf32b33d7..b867583a27bc1f11e649ab8d88936507affcee53 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -60,14 +60,22 @@ void log_file(struct thread_data *td, struct fio_file *f,
 
 static void iolog_delay(struct thread_data *td, unsigned long delay)
 {
-       unsigned long usec = utime_since_now(&td->last_issue);
-       unsigned long this_delay;
+       uint64_t usec = utime_since_now(&td->last_issue);
+       uint64_t this_delay;
+       struct timeval tv;
 
+       if (delay < td->time_offset) {
+               td->time_offset = 0;
+               return;
+       }
+
+       delay -= td->time_offset;
        if (delay < usec)
                return;
 
        delay -= usec;
 
+       fio_gettime(&tv, NULL);
        while (delay && !td->terminate) {
                this_delay = delay;
                if (this_delay > 500000)
@@ -76,6 +84,12 @@ static void iolog_delay(struct thread_data *td, unsigned long delay)
                usec_sleep(td, this_delay);
                delay -= this_delay;
        }
+
+       usec = utime_since_now(&tv);
+       if (usec > delay)
+               td->time_offset = usec - delay;
+       else
+               td->time_offset = 0;
 }
 
 static int ipo_special(struct thread_data *td, struct io_piece *ipo)
@@ -236,6 +250,7 @@ restart:
        p = &td->io_hist_tree.rb_node;
        parent = NULL;
        while (*p) {
+               int overlap = 0;
                parent = *p;
 
                __ipo = rb_entry(parent, struct io_piece, rb_node);
@@ -243,11 +258,18 @@ restart:
                        p = &(*p)->rb_left;
                else if (ipo->file > __ipo->file)
                        p = &(*p)->rb_right;
-               else if (ipo->offset < __ipo->offset)
+               else if (ipo->offset < __ipo->offset) {
                        p = &(*p)->rb_left;
-               else if (ipo->offset > __ipo->offset)
+                       overlap = ipo->offset + ipo->len > __ipo->offset;
+               }
+               else if (ipo->offset > __ipo->offset) {
                        p = &(*p)->rb_right;
-               else {
+                       overlap = __ipo->offset + __ipo->len > ipo->offset;
+               }
+               else
+                       overlap = 1;
+
+               if (overlap) {
                        dprint(FD_IO, "iolog: overlap %llu/%lu, %llu/%lu",
                                __ipo->offset, __ipo->len,
                                ipo->offset, ipo->len);