aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Moyer <[email protected]>2008-04-28 02:12:04 -0700
committerLinus Torvalds <[email protected]>2008-04-28 08:58:17 -0700
commite92adcba261fd391591bb63c1703185a04a41554 (patch)
tree83cd94eaa57931da66137a65089a0bcdddf20533
parent180c06efce691f2b721dd0d965079827bdd7ee03 (diff)
aio: io_getevents() should return if io_destroy() is invoked
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 <[email protected]> Cc: Zach Brown <[email protected]> Cc: Christopher Smith <[email protected]> Cc: Benjamin LaHaise <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
-rw-r--r--fs/aio.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/fs/aio.c b/fs/aio.c
index 228368610dfa..ae94e1dea266 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1166,7 +1166,10 @@ retry:
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
@@ -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 */
}