splice: Get rid of duplicate f_mode checks
PATCH 1/5 splice: Get rid of duplicate f_mode checks
The do_splice() function was only called from sys_splice() but it already checks the f_mode both for in and out.
--- fs/splice.c | 9 --------- 1 file changed, 9 deletions(-)
fs/splice.c +0 -9
@@ -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 ;
Signature · 1 line
1.7.9.2
PATCH 2/5 splice: Add sync parameter to wakeup_pipe_readers()
So that it can handle both of sync and normal wakeups in one place. And convert a sync user to reuse it.
--- fs/splice.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
fs/splice.c +11 -10
@@ -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; }
Signature · 1 line
1.7.9.2
PATCH 3/5 splice: Add sync parameter to wakeup_pipe_writers()
In reply to Namhyung KimSo 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.
--- fs/splice.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/splice.c +10 -6
@@ -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; }
Signature · 1 line
1.7.9.2
PATCH 4/5 splice: Use sync wakeup for splice_from_pipe_next()
In reply to Namhyung KimSync 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.
--- fs/splice.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/splice.c +1 -1
@@ -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; }
Signature · 1 line
1.7.9.2
PATCH 5/5 pipe: Do not use sync wakeups
In reply to Namhyung KimSync 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.
--- fs/pipe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/pipe.c +3 -3
@@ -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 ); }
Signature · 1 line
1.7.9.2