Commit 923f4f23 authored by Ingo Molnar's avatar Ingo Molnar Committed by Jens Axboe

[PATCH] pipe.c/fifo.c code cleanups

more code cleanups after the macro conversion:

 - standardize on 'struct pipe_inode_info *pipe' variable names
 - introduce 'pipe' temporaries to reduce mass inode->i_pipe dereferencing
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarJens Axboe <axboe@suse.de>
parent 9aeedfc4
...@@ -33,14 +33,17 @@ static void wake_up_partner(struct inode* inode) ...@@ -33,14 +33,17 @@ static void wake_up_partner(struct inode* inode)
static int fifo_open(struct inode *inode, struct file *filp) static int fifo_open(struct inode *inode, struct file *filp)
{ {
struct pipe_inode_info *pipe;
int ret; int ret;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
if (!inode->i_pipe) { pipe = inode->i_pipe;
if (!pipe) {
ret = -ENOMEM; ret = -ENOMEM;
inode->i_pipe = alloc_pipe_info(inode); pipe = alloc_pipe_info(inode);
if (!inode->i_pipe) if (!pipe)
goto err_nocleanup; goto err_nocleanup;
inode->i_pipe = pipe;
} }
filp->f_version = 0; filp->f_version = 0;
...@@ -55,18 +58,18 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -55,18 +58,18 @@ static int fifo_open(struct inode *inode, struct file *filp)
* opened, even when there is no process writing the FIFO. * opened, even when there is no process writing the FIFO.
*/ */
filp->f_op = &read_fifo_fops; filp->f_op = &read_fifo_fops;
inode->i_pipe->r_counter++; pipe->r_counter++;
if (inode->i_pipe->readers++ == 0) if (pipe->readers++ == 0)
wake_up_partner(inode); wake_up_partner(inode);
if (!inode->i_pipe->writers) { if (!pipe->writers) {
if ((filp->f_flags & O_NONBLOCK)) { if ((filp->f_flags & O_NONBLOCK)) {
/* suppress POLLHUP until we have /* suppress POLLHUP until we have
* seen a writer */ * seen a writer */
filp->f_version = inode->i_pipe->w_counter; filp->f_version = pipe->w_counter;
} else } else
{ {
wait_for_partner(inode, &inode->i_pipe->w_counter); wait_for_partner(inode, &pipe->w_counter);
if(signal_pending(current)) if(signal_pending(current))
goto err_rd; goto err_rd;
} }
...@@ -80,16 +83,16 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -80,16 +83,16 @@ static int fifo_open(struct inode *inode, struct file *filp)
* errno=ENXIO when there is no process reading the FIFO. * errno=ENXIO when there is no process reading the FIFO.
*/ */
ret = -ENXIO; ret = -ENXIO;
if ((filp->f_flags & O_NONBLOCK) && !inode->i_pipe->readers) if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
goto err; goto err;
filp->f_op = &write_fifo_fops; filp->f_op = &write_fifo_fops;
inode->i_pipe->w_counter++; pipe->w_counter++;
if (!inode->i_pipe->writers++) if (!pipe->writers++)
wake_up_partner(inode); wake_up_partner(inode);
if (!inode->i_pipe->readers) { if (!pipe->readers) {
wait_for_partner(inode, &inode->i_pipe->r_counter); wait_for_partner(inode, &pipe->r_counter);
if (signal_pending(current)) if (signal_pending(current))
goto err_wr; goto err_wr;
} }
...@@ -104,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -104,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
*/ */
filp->f_op = &rdwr_fifo_fops; filp->f_op = &rdwr_fifo_fops;
inode->i_pipe->readers++; pipe->readers++;
inode->i_pipe->writers++; pipe->writers++;
inode->i_pipe->r_counter++; pipe->r_counter++;
inode->i_pipe->w_counter++; pipe->w_counter++;
if (inode->i_pipe->readers == 1 || inode->i_pipe->writers == 1) if (pipe->readers == 1 || pipe->writers == 1)
wake_up_partner(inode); wake_up_partner(inode);
break; break;
...@@ -122,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp) ...@@ -122,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
return 0; return 0;
err_rd: err_rd:
if (!--inode->i_pipe->readers) if (!--pipe->readers)
wake_up_interruptible(&inode->i_pipe->wait); wake_up_interruptible(&pipe->wait);
ret = -ERESTARTSYS; ret = -ERESTARTSYS;
goto err; goto err;
err_wr: err_wr:
if (!--inode->i_pipe->writers) if (!--pipe->writers)
wake_up_interruptible(&inode->i_pipe->wait); wake_up_interruptible(&pipe->wait);
ret = -ERESTARTSYS; ret = -ERESTARTSYS;
goto err; goto err;
err: err:
if (!inode->i_pipe->readers && !inode->i_pipe->writers) if (!pipe->readers && !pipe->writers)
free_pipe_info(inode); free_pipe_info(inode);
err_nocleanup: err_nocleanup:
......
This diff is collapsed.
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