From a917a8b3dfeefdd7007ba2f46f21fc145574309d Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 2 Sep 2010 13:23:20 +0200 Subject: [PATCH] Trim/discard fixes Signed-off-by: Jens Axboe --- fio.c | 4 ++++ io_u.c | 1 + iolog.h | 2 +- trim.c | 18 +++++++++--------- verify.c | 10 ++++++++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/fio.c b/fio.c index c8de2ee7..04247925 100644 --- 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 ea0d46c5..a630817f 100644 --- 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 c59e6aa0..c35ce1e6 100644 --- 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 cf42625b..3da1e749 100644 --- 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; } diff --git a/verify.c b/verify.c index 073eec53..f537553a 100644 --- 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) { -- 2.25.1