Trim/discard fixes
authorJens Axboe <jaxboe@fusionio.com>
Thu, 2 Sep 2010 11:23:20 +0000 (13:23 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Thu, 2 Sep 2010 11:23:20 +0000 (13:23 +0200)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
fio.c
io_u.c
iolog.h
trim.c
verify.c

diff --git a/fio.c b/fio.c
index c8de2ee7a7e3a3f94a0f1af8dc01080c01e22be1..04247925115cddd9625b67b643ddd5d21d18f9d5 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -38,6 +38,7 @@
 #include "hash.h"
 #include "smalloc.h"
 #include "verify.h"
+#include "trim.h"
 #include "diskutil.h"
 #include "cgroup.h"
 #include "profile.h"
@@ -579,6 +580,7 @@ static void do_io(struct thread_data *td)
                td_set_runstate(td, TD_RUNNING);
 
        while ( (td->o.read_iolog_file && !flist_empty(&td->io_log_list)) ||
+               (!flist_empty(&td->trim_list)) ||
                ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) ) {
                struct timeval comp_time;
                unsigned long bytes_done[2] = { 0, 0 };
@@ -734,6 +736,8 @@ sync_done:
                }
        }
 
+       assert(!td->trim_entries);
+
        if (td->o.fill_device && td->error == ENOSPC) {
                td->error = 0;
                td->terminate = 1;
diff --git a/io_u.c b/io_u.c
index ea0d46c5db3dd0d4e32da6b726b0abda9e249bd9..a630817f6f41a3b036530affb0a06dce8908b5f0 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -964,6 +964,7 @@ again:
        if (io_u) {
                assert(io_u->flags & IO_U_F_FREE);
                io_u->flags &= ~(IO_U_F_FREE | IO_U_F_FREE_DEF);
+               io_u->flags &= ~IO_U_F_TRIMMED;
 
                io_u->error = 0;
                flist_del(&io_u->list);
diff --git a/iolog.h b/iolog.h
index c59e6aa0eea4018d1874bb78b53574e354799e2a..c35ce1e694511b2eb08300e8b3744410d3f7a298 100644 (file)
--- a/iolog.h
+++ b/iolog.h
@@ -53,7 +53,7 @@ struct io_piece {
        };
        unsigned long long offset;
        unsigned long len;
-       unsigned long flags;
+       unsigned int flags;
        enum fio_ddir ddir;
        union {
                unsigned long delay;
diff --git a/trim.c b/trim.c
index cf42625b20f26c51f95af6e3d45ba29f838543c5..3da1e749206dc02aaaf633ee25562f3b08c6ee59 100644 (file)
--- a/trim.c
+++ b/trim.c
@@ -21,12 +21,15 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u)
        if (io_u->file)
                return 0;
        if (flist_empty(&td->trim_list))
-               return 0;
+               return 1;
 
        assert(td->trim_entries);
        ipo = flist_entry(td->trim_list.next, struct io_piece, trim_list);
        remove_trim_entry(td, ipo);
-       ipo->flags |= IP_F_TRIMMED;
+
+       io_u->offset = ipo->offset;
+       io_u->buflen = ipo->len;
+       io_u->file = ipo->file;
 
        /*
         * If not verifying that trimmed ranges return zeroed data,
@@ -40,11 +43,9 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u)
                        rb_erase(&ipo->rb_node, &td->io_hist_tree);
                }
                td->io_hist_len--;
-       }
-
-       io_u->offset = ipo->offset;
-       io_u->buflen = ipo->len;
-       io_u->file = ipo->file;
+               free(ipo);
+       } else
+               ipo->flags |= IP_F_TRIMMED;
 
        if (!fio_file_open(io_u->file)) {
                int r = td_io_open_file(td, io_u->file);
@@ -56,13 +57,12 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u)
                }
        }
 
-       get_file(ipo->file);
+       get_file(io_u->file);
        assert(fio_file_open(io_u->file));
        io_u->ddir = DDIR_TRIM;
        io_u->xfer_buf = NULL;
        io_u->xfer_buflen = io_u->buflen;
 
-       free(ipo);
        dprint(FD_VERIFY, "get_next_trim: ret io_u %p\n", io_u);
        return 0;
 }
index 073eec534107c560cfc4963669f2caeb61c1d345..f537553af92acf7e830b878d9ffd5e9173e04c35 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -498,8 +498,10 @@ static int verify_trimmed_io_u(struct thread_data *td, struct io_u *io_u)
        if (!ret)
                return 0;
 
-       log_err("trims: verify failed at file %s offset %llu, length %lu\n",
-                       io_u->file->file_name, io_u->offset, io_u->buflen);
+       log_err("trim: verify failed at file %s offset %llu, length %lu"
+               ", block offset %lu\n",
+                       io_u->file->file_name, io_u->offset, io_u->buflen,
+                       (p - io_u->buf));
        return ret;
 }
 
@@ -816,9 +818,13 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u)
 
                ipo = rb_entry(n, struct io_piece, rb_node);
                rb_erase(n, &td->io_hist_tree);
+               assert(ipo->flags & IP_F_ONRB);
+               ipo->flags &= ~IP_F_ONRB;
        } else if (!flist_empty(&td->io_hist_list)) {
                ipo = flist_entry(td->io_hist_list.next, struct io_piece, list);
                flist_del(&ipo->list);
+               assert(ipo->flags & IP_F_ONLIST);
+               ipo->flags &= ~IP_F_ONLIST;
        }
 
        if (ipo) {