Move completion handler into the io_u

This is needed for completions that happen outside of fio,
or more specifically, for syslet to enable completions in
a ->queue() hook combined with ->commit().

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/fio.c b/fio.c
index dbea661..7460492 100644
--- a/fio.c
+++ b/fio.c
@@ -159,7 +159,7 @@
 	/*
 	 * get immediately available events, if any
 	 */
-	r = io_u_queued_complete(td, 0, NULL);
+	r = io_u_queued_complete(td, 0);
 	if (r < 0)
 		return;
 
@@ -187,7 +187,7 @@
 	}
 
 	if (td->cur_depth)
-		r = io_u_queued_complete(td, td->cur_depth, NULL);
+		r = io_u_queued_complete(td, td->cur_depth);
 }
 
 /*
@@ -217,7 +217,7 @@
 		put_io_u(td, io_u);
 		return 1;
 	} else if (ret == FIO_Q_QUEUED) {
-		if (io_u_queued_complete(td, 1, NULL) < 0)
+		if (io_u_queued_complete(td, 1) < 0)
 			return 1;
 	} else if (ret == FIO_Q_COMPLETED) {
 		if (io_u->error) {
@@ -225,7 +225,7 @@
 			return 1;
 		}
 
-		if (io_u_sync_complete(td, io_u, NULL) < 0)
+		if (io_u_sync_complete(td, io_u) < 0)
 			return 1;
 	} else if (ret == FIO_Q_BUSY) {
 		if (td_io_commit(td))
@@ -282,6 +282,8 @@
 			put_io_u(td, io_u);
 			break;
 		}
+
+		io_u->end_io = verify_io_u;
 requeue:
 		ret = td_io_queue(td, io_u);
 
@@ -296,7 +298,7 @@
 				io_u->xfer_buf += bytes;
 				goto requeue;
 			}
-			ret = io_u_sync_complete(td, io_u, verify_io_u);
+			ret = io_u_sync_complete(td, io_u);
 			if (ret < 0)
 				break;
 			continue;
@@ -331,7 +333,7 @@
 		 * Reap required number of io units, if any, and do the
 		 * verification on them through the callback handler
 		 */
-		if (io_u_queued_complete(td, min_events, verify_io_u) < 0)
+		if (io_u_queued_complete(td, min_events) < 0)
 			break;
 	}
 
@@ -414,7 +416,7 @@
 				goto requeue;
 			}
 			fio_gettime(&comp_time, NULL);
-			bytes_done = io_u_sync_complete(td, io_u, NULL);
+			bytes_done = io_u_sync_complete(td, io_u);
 			if (bytes_done < 0)
 				ret = bytes_done;
 			break;
@@ -453,7 +455,7 @@
 			}
 
 			fio_gettime(&comp_time, NULL);
-			bytes_done = io_u_queued_complete(td, min_evts, NULL);
+			bytes_done = io_u_queued_complete(td, min_evts);
 			if (bytes_done < 0)
 				break;
 		}
diff --git a/fio.h b/fio.h
index 6abbd79..f2366c4 100644
--- a/fio.h
+++ b/fio.h
@@ -144,6 +144,11 @@
 	struct fio_file *file;
 
 	struct list_head list;
+
+	/*
+	 * Callback for io completion
+	 */
+	int (*end_io)(struct io_u *);
 };
 
 /*
@@ -544,11 +549,6 @@
 	struct timeval time;
 };
 
-/*
- * Callback for io completion
- */
-typedef int (endio_handler)(struct io_u *);
-
 #define DISK_UTIL_MSEC	(250)
 
 #ifndef min
@@ -663,8 +663,8 @@
 extern struct io_u *get_io_u(struct thread_data *);
 extern void put_io_u(struct thread_data *, struct io_u *);
 extern void requeue_io_u(struct thread_data *, struct io_u **);
-extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *, endio_handler *);
-extern long __must_check io_u_queued_complete(struct thread_data *, int, endio_handler *);
+extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
+extern long __must_check io_u_queued_complete(struct thread_data *, int);
 extern void io_u_queued(struct thread_data *, struct io_u *);
 extern void io_u_init_timeout(void);
 extern void io_u_set_timeout(struct thread_data *);
diff --git a/io_u.c b/io_u.c
index 48d4076..53e57b4 100644
--- a/io_u.c
+++ b/io_u.c
@@ -15,7 +15,6 @@
 
 struct io_completion_data {
 	int nr;				/* input */
-	endio_handler *handler;		/* input */
 
 	int error;			/* output */
 	unsigned long bytes_done[2];	/* output */
@@ -378,6 +377,7 @@
 		io_u->buflen = 0;
 		io_u->resid = 0;
 		io_u->file = NULL;
+		io_u->end_io = NULL;
 	}
 
 	if (io_u) {
@@ -510,8 +510,8 @@
 
 		icd->bytes_done[idx] += bytes;
 
-		if (icd->handler) {
-			ret = icd->handler(io_u);
+		if (io_u->end_io) {
+			ret = io_u->end_io(io_u);
 			if (ret && !icd->error)
 				icd->error = ret;
 		}
@@ -519,12 +519,10 @@
 		icd->error = io_u->error;
 }
 
-static void init_icd(struct io_completion_data *icd, endio_handler *handler,
-		     int nr)
+static void init_icd(struct io_completion_data *icd, int nr)
 {
 	fio_gettime(&icd->time, NULL);
 
-	icd->handler = handler;
 	icd->nr = nr;
 
 	icd->error = 0;
@@ -548,12 +546,11 @@
 /*
  * Complete a single io_u for the sync engines.
  */
-long io_u_sync_complete(struct thread_data *td, struct io_u *io_u,
-			endio_handler *handler)
+long io_u_sync_complete(struct thread_data *td, struct io_u *io_u)
 {
 	struct io_completion_data icd;
 
-	init_icd(&icd, handler, 1);
+	init_icd(&icd, 1);
 	io_completed(td, io_u, &icd);
 	put_io_u(td, io_u);
 
@@ -566,9 +563,7 @@
 /*
  * Called to complete min_events number of io for the async engines.
  */
-long io_u_queued_complete(struct thread_data *td, int min_events,
-			  endio_handler *handler)
-
+long io_u_queued_complete(struct thread_data *td, int min_events)
 {
 	struct io_completion_data icd;
 	struct timespec *tvp = NULL;
@@ -593,7 +588,7 @@
 	} else if (!ret)
 		return ret;
 
-	init_icd(&icd, handler, ret);
+	init_icd(&icd, ret);
 	ios_completed(td, &icd);
 	if (!icd.error)
 		return icd.bytes_done[0] + icd.bytes_done[1];