Commit ebec73f4 authored by Al Viro's avatar Al Viro

introduce variants of pipe_lock/pipe_unlock for real pipes/FIFOs

fs/pipe.c file_operations methods *know* that pipe is not an internal one;
no need to check pipe->inode for those callers.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent de32ec4c
...@@ -75,6 +75,16 @@ void pipe_unlock(struct pipe_inode_info *pipe) ...@@ -75,6 +75,16 @@ void pipe_unlock(struct pipe_inode_info *pipe)
} }
EXPORT_SYMBOL(pipe_unlock); EXPORT_SYMBOL(pipe_unlock);
static inline void __pipe_lock(struct pipe_inode_info *pipe)
{
mutex_lock_nested(&pipe->mutex, I_MUTEX_PARENT);
}
static inline void __pipe_unlock(struct pipe_inode_info *pipe)
{
mutex_unlock(&pipe->mutex);
}
void pipe_double_lock(struct pipe_inode_info *pipe1, void pipe_double_lock(struct pipe_inode_info *pipe1,
struct pipe_inode_info *pipe2) struct pipe_inode_info *pipe2)
{ {
...@@ -376,7 +386,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov, ...@@ -376,7 +386,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
do_wakeup = 0; do_wakeup = 0;
ret = 0; ret = 0;
pipe_lock(pipe); __pipe_lock(pipe);
for (;;) { for (;;) {
int bufs = pipe->nrbufs; int bufs = pipe->nrbufs;
if (bufs) { if (bufs) {
...@@ -464,7 +474,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov, ...@@ -464,7 +474,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
} }
pipe_wait(pipe); pipe_wait(pipe);
} }
pipe_unlock(pipe); __pipe_unlock(pipe);
/* Signal writers asynchronously that there is more room. */ /* Signal writers asynchronously that there is more room. */
if (do_wakeup) { if (do_wakeup) {
...@@ -500,7 +510,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov, ...@@ -500,7 +510,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
do_wakeup = 0; do_wakeup = 0;
ret = 0; ret = 0;
pipe_lock(pipe); __pipe_lock(pipe);
if (!pipe->readers) { if (!pipe->readers) {
send_sig(SIGPIPE, current, 0); send_sig(SIGPIPE, current, 0);
...@@ -647,7 +657,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov, ...@@ -647,7 +657,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
pipe->waiting_writers--; pipe->waiting_writers--;
} }
out: out:
pipe_unlock(pipe); __pipe_unlock(pipe);
if (do_wakeup) { if (do_wakeup) {
wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM); wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
...@@ -667,7 +677,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -667,7 +677,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
switch (cmd) { switch (cmd) {
case FIONREAD: case FIONREAD:
pipe_lock(pipe); __pipe_lock(pipe);
count = 0; count = 0;
buf = pipe->curbuf; buf = pipe->curbuf;
nrbufs = pipe->nrbufs; nrbufs = pipe->nrbufs;
...@@ -675,7 +685,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -675,7 +685,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
count += pipe->bufs[buf].len; count += pipe->bufs[buf].len;
buf = (buf+1) & (pipe->buffers - 1); buf = (buf+1) & (pipe->buffers - 1);
} }
pipe_unlock(pipe); __pipe_unlock(pipe);
return put_user(count, (int __user *)arg); return put_user(count, (int __user *)arg);
default: default:
...@@ -721,7 +731,7 @@ pipe_release(struct inode *inode, struct file *file) ...@@ -721,7 +731,7 @@ pipe_release(struct inode *inode, struct file *file)
struct pipe_inode_info *pipe = inode->i_pipe; struct pipe_inode_info *pipe = inode->i_pipe;
int kill = 0; int kill = 0;
pipe_lock(pipe); __pipe_lock(pipe);
if (file->f_mode & FMODE_READ) if (file->f_mode & FMODE_READ)
pipe->readers--; pipe->readers--;
if (file->f_mode & FMODE_WRITE) if (file->f_mode & FMODE_WRITE)
...@@ -738,7 +748,7 @@ pipe_release(struct inode *inode, struct file *file) ...@@ -738,7 +748,7 @@ pipe_release(struct inode *inode, struct file *file)
kill = 1; kill = 1;
} }
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
pipe_unlock(pipe); __pipe_unlock(pipe);
if (kill) if (kill)
__free_pipe_info(pipe); __free_pipe_info(pipe);
...@@ -752,7 +762,7 @@ pipe_fasync(int fd, struct file *filp, int on) ...@@ -752,7 +762,7 @@ pipe_fasync(int fd, struct file *filp, int on)
struct pipe_inode_info *pipe = filp->private_data; struct pipe_inode_info *pipe = filp->private_data;
int retval = 0; int retval = 0;
pipe_lock(pipe); __pipe_lock(pipe);
if (filp->f_mode & FMODE_READ) if (filp->f_mode & FMODE_READ)
retval = fasync_helper(fd, filp, on, &pipe->fasync_readers); retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
if ((filp->f_mode & FMODE_WRITE) && retval >= 0) { if ((filp->f_mode & FMODE_WRITE) && retval >= 0) {
...@@ -761,7 +771,7 @@ pipe_fasync(int fd, struct file *filp, int on) ...@@ -761,7 +771,7 @@ pipe_fasync(int fd, struct file *filp, int on)
/* this can happen only if on == T */ /* this can happen only if on == T */
fasync_helper(-1, filp, 0, &pipe->fasync_readers); fasync_helper(-1, filp, 0, &pipe->fasync_readers);
} }
pipe_unlock(pipe); __pipe_unlock(pipe);
return retval; return retval;
} }
...@@ -1040,7 +1050,7 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -1040,7 +1050,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
filp->private_data = pipe; filp->private_data = pipe;
/* OK, we have a pipe and it's pinned down */ /* OK, we have a pipe and it's pinned down */
pipe_lock(pipe); __pipe_lock(pipe);
/* We can only do regular read/write on fifos */ /* We can only do regular read/write on fifos */
filp->f_mode &= (FMODE_READ | FMODE_WRITE); filp->f_mode &= (FMODE_READ | FMODE_WRITE);
...@@ -1110,7 +1120,7 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -1110,7 +1120,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
} }
/* Ok! */ /* Ok! */
pipe_unlock(pipe); __pipe_unlock(pipe);
return 0; return 0;
err_rd: err_rd:
...@@ -1132,7 +1142,7 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -1132,7 +1142,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
kill = 1; kill = 1;
} }
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
pipe_unlock(pipe); __pipe_unlock(pipe);
if (kill) if (kill)
__free_pipe_info(pipe); __free_pipe_info(pipe);
return ret; return ret;
...@@ -1248,7 +1258,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -1248,7 +1258,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
if (!pipe) if (!pipe)
return -EBADF; return -EBADF;
pipe_lock(pipe); __pipe_lock(pipe);
switch (cmd) { switch (cmd) {
case F_SETPIPE_SZ: { case F_SETPIPE_SZ: {
...@@ -1277,7 +1287,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -1277,7 +1287,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
} }
out: out:
pipe_unlock(pipe); __pipe_unlock(pipe);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment