io_uring: punt even fadvise() WILLNEED to async context
authorJens Axboe <axboe@kernel.dk>
Sat, 1 Feb 2020 16:22:49 +0000 (09:22 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 4 Feb 2020 00:27:47 +0000 (17:27 -0700)
Andres correctly points out that read-ahead can block, if it needs to
read in meta data (or even just through the page cache page allocations).
Play it safe for now and just ensure WILLNEED is also punted to async
context.

While in there, allow the file settings hints from non-blocking
context. They don't need to start/do IO, and we can safely do them
inline.

Fixes: 4840e418c2fc ("io_uring: add IORING_OP_FADVISE")
Reported-by: Andres Freund <andres@anarazel.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index b9c9e04cc1cbe70f0aba14e94e3bbc871502b8e9..1580f1e7ba1c7a48432ea58d9d92342ec2ef2dcb 100644 (file)
@@ -2730,9 +2730,16 @@ static int io_fadvise(struct io_kiocb *req, struct io_kiocb **nxt,
        struct io_fadvise *fa = &req->fadvise;
        int ret;
 
-       /* DONTNEED may block, others _should_ not */
-       if (fa->advice == POSIX_FADV_DONTNEED && force_nonblock)
-               return -EAGAIN;
+       if (force_nonblock) {
+               switch (fa->advice) {
+               case POSIX_FADV_NORMAL:
+               case POSIX_FADV_RANDOM:
+               case POSIX_FADV_SEQUENTIAL:
+                       break;
+               default:
+                       return -EAGAIN;
+               }
+       }
 
        ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice);
        if (ret < 0)