pipe: check for IOCB_NOWAIT alongside O_NONBLOCK
authorJens Axboe <axboe@kernel.dk>
Tue, 9 May 2023 15:12:24 +0000 (09:12 -0600)
committerChristian Brauner <brauner@kernel.org>
Fri, 12 May 2023 15:17:27 +0000 (17:17 +0200)
Pipe reads or writes need to enable nonblocking attempts, if either
O_NONBLOCK is set on the file, or IOCB_NOWAIT is set in the iocb being
passed in. The latter isn't currently true, ensure we check for both
before waiting on data or space.

Fixes: afed6271f5b0 ("pipe: set FMODE_NOWAIT on pipes")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Message-Id: <e5946d67-4e5e-b056-ba80-656bab12d9f6@kernel.dk>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/pipe.c

index ceb17d2dfa195a077d0f0014866b3bfc33f5aeac..2d88f73f585a21aaf5a5fa20df08e269bcec3909 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -342,7 +342,8 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
                        break;
                if (ret)
                        break;
-               if (filp->f_flags & O_NONBLOCK) {
+               if ((filp->f_flags & O_NONBLOCK) ||
+                   (iocb->ki_flags & IOCB_NOWAIT)) {
                        ret = -EAGAIN;
                        break;
                }
@@ -547,7 +548,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
                        continue;
 
                /* Wait for buffer space to become available. */
-               if (filp->f_flags & O_NONBLOCK) {
+               if ((filp->f_flags & O_NONBLOCK) ||
+                   (iocb->ki_flags & IOCB_NOWAIT)) {
                        if (!ret)
                                ret = -EAGAIN;
                        break;