diff mbox series

[3/5] pipe: use IOCB_NOWAIT instead of O_NONBLOCK

Message ID 20190511165727.31599-3-source@stbuehler.de (mailing list archive)
State RFC
Headers show
Series [1/5] fs: RWF flags override default IOCB flags from file flags | expand

Commit Message

Stefan Bühler May 11, 2019, 4:57 p.m. UTC
Fix pipe read_iter/write_iter implementations to handle IOCB_NOWAIT; for
simple reads IOCB_NOWAIT will be set if O_NONBLOCK was set.

Signed-off-by: Stefan Bühler <source@stbuehler.de>
---
 fs/pipe.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/fs/pipe.c b/fs/pipe.c
index 41065901106b..a122331cf30f 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -335,13 +335,13 @@  pipe_read(struct kiocb *iocb, struct iov_iter *to)
 			break;
 		if (!pipe->waiting_writers) {
 			/* syscall merging: Usually we must not sleep
-			 * if O_NONBLOCK is set, or if we got some data.
+			 * if IOCB_NOWAIT is set, or if we got some data.
 			 * But if a writer sleeps in kernel space, then
 			 * we can wait for that data without violating POSIX.
 			 */
 			if (ret)
 				break;
-			if (filp->f_flags & O_NONBLOCK) {
+			if (iocb->ki_flags & IOCB_NOWAIT) {
 				ret = -EAGAIN;
 				break;
 			}
@@ -446,7 +446,7 @@  pipe_write(struct kiocb *iocb, struct iov_iter *from)
 				pipe->tmp_page = page;
 			}
 			/* Always wake up, even if the copy fails. Otherwise
-			 * we lock up (O_NONBLOCK-)readers that sleep due to
+			 * we lock up (IOCB_NOWAIT-)readers that sleep due to
 			 * syscall merging.
 			 * FIXME! Is this really true?
 			 */
@@ -477,7 +477,7 @@  pipe_write(struct kiocb *iocb, struct iov_iter *from)
 		}
 		if (bufs < pipe->buffers)
 			continue;
-		if (filp->f_flags & O_NONBLOCK) {
+		if (iocb->ki_flags & IOCB_NOWAIT) {
 			if (!ret)
 				ret = -EAGAIN;
 			break;
@@ -780,6 +780,7 @@  int create_pipe_files(struct file **res, int flags)
 		iput(inode);
 		return PTR_ERR(f);
 	}
+	f->f_mode |= FMODE_NOWAIT;
 
 	f->private_data = inode->i_pipe;
 
@@ -791,6 +792,7 @@  int create_pipe_files(struct file **res, int flags)
 		return PTR_ERR(res[0]);
 	}
 	res[0]->private_data = inode->i_pipe;
+	res[0]->f_mode |= FMODE_NOWAIT;
 	res[1] = f;
 	return 0;
 }
@@ -996,6 +998,8 @@  static int fifo_open(struct inode *inode, struct file *filp)
 		goto err;
 	}
 
+	filp->f_mode |= FMODE_NOWAIT;
+
 	/* Ok! */
 	__pipe_unlock(pipe);
 	return 0;