diff --git a/fs/aio.c b/fs/aio.c index 24ba228..89cb7db 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -335,9 +335,11 @@ static void free_ioctx(struct kioctx *ctx) kunmap_atomic(ring); while (atomic_read(&ctx->reqs_available) < ctx->nr) { - wait_event(ctx->wait, head != ctx->shadow_tail); + wait_event(ctx->wait, + (head != ctx->shadow_tail) || + (atomic_read(&ctx->reqs_available) != ctx->nr)); - avail = (head < ctx->shadow_tail ? ctx->shadow_tail : ctx->nr) - head; + avail = (head <= ctx->shadow_tail ? ctx->shadow_tail : ctx->nr) - head; atomic_add(avail, &ctx->reqs_available); head += avail; @@ -753,6 +755,7 @@ void batch_complete_aio(struct batch_complete *batch) * with free_ioctx() */ atomic_inc(&req->ki_ctx->reqs_available); + wake_up(&req->ki_ctx->wait); aio_put_req(req); continue; }