+ } else {
+ /* There is another completion to reap */
+ events[i] = ring->events[head];
+ read_barrier();
+ ring->head = (head + 1) % ring->nr;
+ i++;
+ }
+ }
+
+ return i;
+}
+
+static int fio_libaio_getevents(struct thread_data *td, unsigned int min,
+ unsigned int max, const struct timespec *t)
+{
+ struct libaio_data *ld = td->io_ops_data;
+ struct libaio_options *o = td->eo;
+ unsigned actual_min = td->o.iodepth_batch_complete_min == 0 ? 0 : min;
+ struct timespec __lt, *lt = NULL;
+ int r, events = 0;
+
+ if (t) {
+ __lt = *t;
+ lt = &__lt;
+ }
+
+ do {
+ if (o->userspace_reap == 1
+ && actual_min == 0
+ && ((struct aio_ring *)(ld->aio_ctx))->magic
+ == AIO_RING_MAGIC) {
+ r = user_io_getevents(ld->aio_ctx, max,
+ ld->aio_events + events);
+ } else {
+ r = io_getevents(ld->aio_ctx, actual_min,
+ max, ld->aio_events + events, lt);
+ }
+ if (r > 0)
+ events += r;
+ else if ((min && r == 0) || r == -EAGAIN) {
+ fio_libaio_commit(td);