linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] splice: Get rid of duplicate f_mode checks
@ 2013-09-29  6:14 Namhyung Kim
  2013-09-29  6:14 ` [PATCH 2/5] splice: Add sync parameter to wakeup_pipe_readers() Namhyung Kim
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Namhyung Kim @ 2013-09-29  6:14 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel, Jens Axboe

The do_splice() function was only called from sys_splice() but it
already checks the f_mode both for in and out.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 fs/splice.c |    9 ---------
 1 file changed, 9 deletions(-)

diff --git a/fs/splice.c b/fs/splice.c
index 3b7ee656f3aa..320cc65585b2 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1333,12 +1333,6 @@ static long do_splice(struct file *in, loff_t __user *off_in,
 		if (off_in || off_out)
 			return -ESPIPE;
 
-		if (!(in->f_mode & FMODE_READ))
-			return -EBADF;
-
-		if (!(out->f_mode & FMODE_WRITE))
-			return -EBADF;
-
 		/* Splicing to self would be fun, but... */
 		if (ipipe == opipe)
 			return -EINVAL;
@@ -1358,9 +1352,6 @@ static long do_splice(struct file *in, loff_t __user *off_in,
 			offset = out->f_pos;
 		}
 
-		if (unlikely(!(out->f_mode & FMODE_WRITE)))
-			return -EBADF;
-
 		if (unlikely(out->f_flags & O_APPEND))
 			return -EINVAL;
 
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/5] splice: Add sync parameter to wakeup_pipe_readers()
  2013-09-29  6:14 [PATCH 1/5] splice: Get rid of duplicate f_mode checks Namhyung Kim
@ 2013-09-29  6:14 ` Namhyung Kim
  2013-09-29  6:14 ` [PATCH 3/5] splice: Add sync parameter to wakeup_pipe_writers() Namhyung Kim
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2013-09-29  6:14 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel, Jens Axboe

So that it can handle both of sync and normal wakeups in one place.
And convert a sync user to reuse it.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 fs/splice.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/fs/splice.c b/fs/splice.c
index 320cc65585b2..77251152e1b8 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -164,11 +164,15 @@ static const struct pipe_buf_operations user_page_pipe_buf_ops = {
 	.get = generic_pipe_buf_get,
 };
 
-static void wakeup_pipe_readers(struct pipe_inode_info *pipe)
+static void wakeup_pipe_readers(struct pipe_inode_info *pipe, bool sync)
 {
 	smp_mb();
-	if (waitqueue_active(&pipe->wait))
-		wake_up_interruptible(&pipe->wait);
+	if (waitqueue_active(&pipe->wait)) {
+		if (sync)
+			wake_up_interruptible_sync(&pipe->wait);
+		else
+			wake_up_interruptible(&pipe->wait);
+	}
 	kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
 }
 
@@ -243,10 +247,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
 		}
 
 		if (do_wakeup) {
-			smp_mb();
-			if (waitqueue_active(&pipe->wait))
-				wake_up_interruptible_sync(&pipe->wait);
-			kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
+			wakeup_pipe_readers(pipe, true);
 			do_wakeup = 0;
 		}
 
@@ -258,7 +259,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
 	pipe_unlock(pipe);
 
 	if (do_wakeup)
-		wakeup_pipe_readers(pipe);
+		wakeup_pipe_readers(pipe, false);
 
 	while (page_nr < spd_pages)
 		spd->spd_release(spd, page_nr++);
@@ -1931,7 +1932,7 @@ retry:
 	 * If we put data in the output pipe, wakeup any potential readers.
 	 */
 	if (ret > 0)
-		wakeup_pipe_readers(opipe);
+		wakeup_pipe_readers(opipe, false);
 
 	if (input_wakeup)
 		wakeup_pipe_writers(ipipe);
@@ -2012,7 +2013,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
 	 * If we put data in the output pipe, wakeup any potential readers.
 	 */
 	if (ret > 0)
-		wakeup_pipe_readers(opipe);
+		wakeup_pipe_readers(opipe, false);
 
 	return ret;
 }
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/5] splice: Add sync parameter to wakeup_pipe_writers()
  2013-09-29  6:14 [PATCH 1/5] splice: Get rid of duplicate f_mode checks Namhyung Kim
  2013-09-29  6:14 ` [PATCH 2/5] splice: Add sync parameter to wakeup_pipe_readers() Namhyung Kim
@ 2013-09-29  6:14 ` Namhyung Kim
  2013-09-29  6:14 ` [PATCH 4/5] splice: Use sync wakeup for splice_from_pipe_next() Namhyung Kim
  2013-09-29  6:14 ` [PATCH 5/5] pipe: Do not use sync wakeups Namhyung Kim
  3 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2013-09-29  6:14 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel, Jens Axboe

So that it can handle both of sync and normal wakeups in one place.
Although it doesn't have any sync user, it'll be introduced soon.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 fs/splice.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/splice.c b/fs/splice.c
index 77251152e1b8..0325e8b0d816 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -765,11 +765,15 @@ out:
 }
 EXPORT_SYMBOL(pipe_to_file);
 
-static void wakeup_pipe_writers(struct pipe_inode_info *pipe)
+static void wakeup_pipe_writers(struct pipe_inode_info *pipe, bool sync)
 {
 	smp_mb();
-	if (waitqueue_active(&pipe->wait))
-		wake_up_interruptible(&pipe->wait);
+	if (waitqueue_active(&pipe->wait)) {
+		if (sync)
+			wake_up_interruptible_sync(&pipe->wait);
+		else
+			wake_up_interruptible(&pipe->wait);
+	}
 	kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
 }
 
@@ -868,7 +872,7 @@ int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
 			return -ERESTARTSYS;
 
 		if (sd->need_wakeup) {
-			wakeup_pipe_writers(pipe);
+			wakeup_pipe_writers(pipe, false);
 			sd->need_wakeup = false;
 		}
 
@@ -908,7 +912,7 @@ EXPORT_SYMBOL(splice_from_pipe_begin);
 void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd)
 {
 	if (sd->need_wakeup)
-		wakeup_pipe_writers(pipe);
+		wakeup_pipe_writers(pipe, false);
 }
 EXPORT_SYMBOL(splice_from_pipe_end);
 
@@ -1935,7 +1939,7 @@ retry:
 		wakeup_pipe_readers(opipe, false);
 
 	if (input_wakeup)
-		wakeup_pipe_writers(ipipe);
+		wakeup_pipe_writers(ipipe, false);
 
 	return ret;
 }
-- 
1.7.9.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/5] splice: Use sync wakeup for splice_from_pipe_next()
  2013-09-29  6:14 [PATCH 1/5] splice: Get rid of duplicate f_mode checks Namhyung Kim
  2013-09-29  6:14 ` [PATCH 2/5] splice: Add sync parameter to wakeup_pipe_readers() Namhyung Kim
  2013-09-29  6:14 ` [PATCH 3/5] splice: Add sync parameter to wakeup_pipe_writers() Namhyung Kim
@ 2013-09-29  6:14 ` Namhyung Kim
  2013-09-29  6:14 ` [PATCH 5/5] pipe: Do not use sync wakeups Namhyung Kim
  3 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2013-09-29  6:14 UTC (permalink / raw)
  To: Alexander Viro
  Cc: linux-fsdevel, linux-kernel, Jens Axboe, Ingo Molnar,
	Peter Zijlstra

Sync wakeup is a hint to the scheduler that means a waker would go to
sleep right soon.  In splice_from_pipe_next(), it calls pipe_wait()
after calling wakeup_pipe_writers() so it'd be better using sync
wakeup rather than normal one.

Cc: Jens Axboe <axboe@kernel.dk>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 fs/splice.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/splice.c b/fs/splice.c
index 0325e8b0d816..9fb7dc5ef061 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -872,7 +872,7 @@ int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
 			return -ERESTARTSYS;
 
 		if (sd->need_wakeup) {
-			wakeup_pipe_writers(pipe, false);
+			wakeup_pipe_writers(pipe, true);
 			sd->need_wakeup = false;
 		}
 
-- 
1.7.9.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 5/5] pipe: Do not use sync wakeups
  2013-09-29  6:14 [PATCH 1/5] splice: Get rid of duplicate f_mode checks Namhyung Kim
                   ` (2 preceding siblings ...)
  2013-09-29  6:14 ` [PATCH 4/5] splice: Use sync wakeup for splice_from_pipe_next() Namhyung Kim
@ 2013-09-29  6:14 ` Namhyung Kim
  3 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2013-09-29  6:14 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel, Ingo Molnar, Peter Zijlstra

Sync wakeup is a hint to the scheduler that means a waker would go to
sleep right soon.  So don't use the sync wakeup unless it guarantees
to sleep.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 fs/pipe.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/pipe.c b/fs/pipe.c
index d2c45e14e6d8..58f4b9b009da 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -479,7 +479,7 @@ redo:
 
 	/* Signal writers asynchronously that there is more room. */
 	if (do_wakeup) {
-		wake_up_interruptible_sync_poll(&pipe->wait, POLLOUT | POLLWRNORM);
+		wake_up_interruptible_poll(&pipe->wait, POLLOUT | POLLWRNORM);
 		kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
 	}
 	if (ret > 0)
@@ -660,7 +660,7 @@ redo2:
 out:
 	__pipe_unlock(pipe);
 	if (do_wakeup) {
-		wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
+		wake_up_interruptible_poll(&pipe->wait, POLLIN | POLLRDNORM);
 		kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
 	}
 	if (ret > 0) {
@@ -739,7 +739,7 @@ pipe_release(struct inode *inode, struct file *file)
 		pipe->writers--;
 
 	if (pipe->readers || pipe->writers) {
-		wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
+		wake_up_interruptible_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
 		kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
 		kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
 	}
-- 
1.7.9.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-09-29  6:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-29  6:14 [PATCH 1/5] splice: Get rid of duplicate f_mode checks Namhyung Kim
2013-09-29  6:14 ` [PATCH 2/5] splice: Add sync parameter to wakeup_pipe_readers() Namhyung Kim
2013-09-29  6:14 ` [PATCH 3/5] splice: Add sync parameter to wakeup_pipe_writers() Namhyung Kim
2013-09-29  6:14 ` [PATCH 4/5] splice: Use sync wakeup for splice_from_pipe_next() Namhyung Kim
2013-09-29  6:14 ` [PATCH 5/5] pipe: Do not use sync wakeups Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).