[PATCH 2/2] pipe: avoid repeat check of pipe->readers with pipe lock held

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change to pipe->readers is protected by pipe_lock. Only recheck
pipe->reader after relock to avoid repeat check of pipe->readers with
pipe lock held.

Signed-off-by: Kemeng Shi <shikemeng@xxxxxxxxxxxxxxx>
---
 fs/pipe.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/pipe.c b/fs/pipe.c
index b19875720ff1..e9c63f66d1c7 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -479,13 +479,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 	}
 
 	for (;;) {
-		if (!pipe->readers) {
-			send_sig(SIGPIPE, current, 0);
-			if (!ret)
-				ret = -EPIPE;
-			break;
-		}
-
 		head = pipe->head;
 		if (!pipe_full(head, pipe->tail, pipe->max_usage)) {
 			unsigned int mask = pipe->ring_size - 1;
@@ -573,6 +566,12 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 		__pipe_lock(pipe);
 		was_empty = pipe_empty(pipe->head, pipe->tail);
 		wake_next_writer = true;
+		if (!pipe->readers) {
+			send_sig(SIGPIPE, current, 0);
+			if (!ret)
+				ret = -EPIPE;
+			break;
+		}
 	}
 out:
 	if (pipe_full(pipe->head, pipe->tail, pipe->max_usage))
-- 
2.30.0




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux