engines/libaio: modify getevents and commit error handling

If we get some error other than -EAGAIN in getevents(), treat
it as fatal and break.

If we get -ENOMEM on submission, reap events if we can. If we
have no pending events, treat it as a fatal error and break.

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/engines/libaio.c b/engines/libaio.c
index 31c850e..6c5d73e 100644
--- a/engines/libaio.c
+++ b/engines/libaio.c
@@ -167,6 +167,8 @@
 			events += r;
 		else if (r == -EAGAIN)
 			usleep(100);
+		else
+			break;
 	} while (events < min);
 
 	return r < 0 ? r : events;
@@ -283,6 +285,15 @@
 			}
 			usleep(1);
 			continue;
+		} else if (ret == -ENOMEM) {
+			/*
+			 * If we get -ENOMEM, reap events if we can. If
+			 * we cannot, treat it as a fatal event since there's
+			 * nothing we can do about it.
+			 */
+			if (ld->queued)
+				ret = 0;
+			break;
 		} else
 			break;
 	} while (ld->queued);