Fix race on io_u->flags
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/io_u.c b/io_u.c
index 232f6a6..4be958d 100644
--- a/io_u.c
+++ b/io_u.c
@@ -413,7 +413,6 @@
{
td_io_u_lock(td);
- assert((io_u->flags & IO_U_F_FREE) == 0);
io_u->flags |= IO_U_F_FREE;
io_u->flags &= ~IO_U_F_FREE_DEF;
@@ -861,8 +860,7 @@
if (io_u) {
assert(io_u->flags & IO_U_F_FREE);
- io_u->flags &= ~IO_U_F_FREE;
- io_u->flags &= ~IO_U_F_FREE_DEF;
+ io_u->flags &= ~(IO_U_F_FREE | IO_U_F_FREE_DEF);
io_u->error = 0;
flist_del(&io_u->list);
@@ -971,8 +969,10 @@
dprint_io_u(io_u, "io complete");
+ td_io_u_lock(td);
assert(io_u->flags & IO_U_F_FLIGHT);
io_u->flags &= ~IO_U_F_FLIGHT;
+ td_io_u_unlock(td);
if (ddir_sync(io_u->ddir)) {
td->last_was_sync = 1;
diff --git a/verify.c b/verify.c
index 7d675e4..84e888b 100644
--- a/verify.c
+++ b/verify.c
@@ -444,10 +444,10 @@
}
flist_del(&io_u->list);
flist_add_tail(&io_u->list, &td->verify_list);
+ io_u->flags |= IO_U_F_FREE_DEF;
pthread_mutex_unlock(&td->io_u_lock);
pthread_cond_signal(&td->verify_cond);
- io_u->flags |= IO_U_F_FREE_DEF;
return 0;
}