/* starts some io for a given file, returns zero if all went well */ int run_built(struct thread_info *t, int num_ios, struct iocb **my_iocbs) { int ret; struct timeval start_time; struct timeval stop_time; resubmit: gettimeofday(&start_time, NULL); ret = io_submit(t->io_ctx, num_ios, my_iocbs); gettimeofday(&stop_time, NULL); calc_latency(&start_time, &stop_time, &t->io_submit_latency); if (ret != num_ios) { /* some I/O got through */ if (ret > 0) { update_iou_counters(my_iocbs, ret, &stop_time); my_iocbs += ret; t->num_global_pending += ret; num_ios -= ret; } /* * we've used all the requests allocated in aio_init, wait and * retry */ if (ret > 0 || ret == -EAGAIN) { int old_ret = ret; if ((ret = read_some_events(t) > 0)) { goto resubmit; } else { fprintf(stderr, "ret was %d and now is %d\n", ret, old_ret); abort(); } } fprintf(stderr, "ret %d (%s) on io_submit\n", ret, strerror(-ret)); return -1; } update_iou_counters(my_iocbs, ret, &stop_time); t->num_global_pending += ret; return 0; }
/* * finds a free io unit, waiting for pending requests if required. returns * null if none could be found */ static struct io_unit *find_iou(struct thread_info *t, struct io_oper *oper) { struct io_unit *event_io; int nr; retry: if (t->free_ious) { event_io = t->free_ious; t->free_ious = t->free_ious->next; if (grab_iou(event_io, oper)) { fprintf(stderr, "io unit on free list but not free\n"); abort(); } return event_io; } nr = read_some_events(t); if (nr > 0) goto retry; else fprintf(stderr, "no free ious after read_some_events\n"); return NULL; }