Move ->commit() call to td_io_getevents()

If we need to complete some events (min > 0), make sure we
have committed a pending batch.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/io_u.c b/io_u.c
index 372f46a..ede61a8 100644
--- a/io_u.c
+++ b/io_u.c
@@ -572,13 +572,7 @@
 	struct timespec *tvp = NULL;
 	int ret;
 
-	if (min_events > 0) {
-		ret = td_io_commit(td);
-		if (ret < 0) {
-			td_verror(td, -ret, "td_io_commit");
-			return ret;
-		}
-	} else {
+	if (!min_events) {
 		struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, };
 
 		tvp = &ts;
diff --git a/ioengines.c b/ioengines.c
index 0b3ec16..727981f 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -182,6 +182,12 @@
 int td_io_getevents(struct thread_data *td, int min, int max,
 		    struct timespec *t)
 {
+	if (min > 0 && td->io_ops->commit) {
+		int r = td->io_ops->commit(td);
+
+		if (r < 0)
+			return r;
+	}
 	if (td->io_ops->getevents)
 		return td->io_ops->getevents(td, min, max, t);