Skip to content

Commit

Permalink
aio: io_getevents() should return if io_destroy() is invoked
Browse files Browse the repository at this point in the history
This patch wakes up a thread waiting in io_getevents if another thread
destroys the context.  This was tested using a small program that spawns a
thread to wait in io_getevents while the parent thread destroys the io context
and then waits for the getevents thread to exit.  Without this patch, the
program hangs indefinitely.  With the patch, the program exits as expected.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Cc: Zach Brown <zach.brown@oracle.com>
Cc: Christopher Smith <x@xman.org>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
JeffMoyer authored and torvalds committed Apr 28, 2008
1 parent 180c06e commit e92adcb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,10 @@ static int read_events(struct kioctx *ctx,
break;
if (min_nr <= i)
break;
ret = 0;
if (unlikely(ctx->dead)) {
ret = -EINVAL;
break;
}
if (to.timed_out) /* Only check after read evt */
break;
/* Try to only show up in io wait if there are ops
Expand Down Expand Up @@ -1231,6 +1234,13 @@ static void io_destroy(struct kioctx *ioctx)

aio_cancel_all(ioctx);
wait_for_all_aios(ioctx);

/*
* Wake up any waiters. The setting of ctx->dead must be seen
* by other CPUs at this point. Right now, we rely on the
* locking done by the above calls to ensure this consistency.
*/
wake_up(&ioctx->wait);
put_ioctx(ioctx); /* once for the lookup */
}

Expand Down

0 comments on commit e92adcb

Please sign in to comment.