Skip to content

Commit

Permalink
[PATCH] introduce a "kernel-internal pipe object" abstraction
Browse files Browse the repository at this point in the history
separate out the 'internal pipe object' abstraction, and make it
usable to splice. This cleans up and fixes several aspects of the
internal splice APIs and the pipe code:

 - pipes: the allocation and freeing of pipe_inode_info is now more symmetric
   and more streamlined with existing kernel practices.

 - splice: small micro-optimization: less pointer dereferencing in splice
   methods

Signed-off-by: Ingo Molnar <mingo@elte.hu>

Update XFS for the ->splice_read/->splice_write changes.

Signed-off-by: Jens Axboe <axboe@suse.de>
  • Loading branch information
Ingo Molnar authored and Jens Axboe committed Apr 10, 2006
1 parent 0b749ce commit 3a326a2
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 106 deletions.
12 changes: 7 additions & 5 deletions fs/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#include <linux/fs.h>
#include <linux/pipe_fs_i.h>

static void wait_for_partner(struct inode* inode, unsigned int* cnt)
static void wait_for_partner(struct inode* inode, unsigned int *cnt)
{
int cur = *cnt;
while(cur == *cnt) {
pipe_wait(inode);
if(signal_pending(current))

while (cur == *cnt) {
pipe_wait(inode->i_pipe);
if (signal_pending(current))
break;
}
}
Expand All @@ -37,7 +38,8 @@ static int fifo_open(struct inode *inode, struct file *filp)
mutex_lock(PIPE_MUTEX(*inode));
if (!inode->i_pipe) {
ret = -ENOMEM;
if(!pipe_new(inode))
inode->i_pipe = alloc_pipe_info(inode);
if (!inode->i_pipe)
goto err_nocleanup;
}
filp->f_version = 0;
Expand Down
51 changes: 26 additions & 25 deletions fs/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@
*/

/* Drop the inode semaphore and wait for a pipe event, atomically */
void pipe_wait(struct inode * inode)
void pipe_wait(struct pipe_inode_info *pipe)
{
DEFINE_WAIT(wait);

/*
* Pipes are system-local resources, so sleeping on them
* is considered a noninteractive wait:
*/
prepare_to_wait(PIPE_WAIT(*inode), &wait, TASK_INTERRUPTIBLE|TASK_NONINTERACTIVE);
mutex_unlock(PIPE_MUTEX(*inode));
prepare_to_wait(&pipe->wait, &wait, TASK_INTERRUPTIBLE|TASK_NONINTERACTIVE);
if (pipe->inode)
mutex_unlock(&pipe->inode->i_mutex);
schedule();
finish_wait(PIPE_WAIT(*inode), &wait);
mutex_lock(PIPE_MUTEX(*inode));
finish_wait(&pipe->wait, &wait);
if (pipe->inode)
mutex_lock(&pipe->inode->i_mutex);
}

static int
Expand Down Expand Up @@ -223,7 +225,7 @@ pipe_readv(struct file *filp, const struct iovec *_iov,
wake_up_interruptible_sync(PIPE_WAIT(*inode));
kill_fasync(PIPE_FASYNC_WRITERS(*inode), SIGIO, POLL_OUT);
}
pipe_wait(inode);
pipe_wait(inode->i_pipe);
}
mutex_unlock(PIPE_MUTEX(*inode));
/* Signal writers asynchronously that there is more room. */
Expand Down Expand Up @@ -370,7 +372,7 @@ pipe_writev(struct file *filp, const struct iovec *_iov,
do_wakeup = 0;
}
PIPE_WAITING_WRITERS(*inode)++;
pipe_wait(inode);
pipe_wait(inode->i_pipe);
PIPE_WAITING_WRITERS(*inode)--;
}
out:
Expand Down Expand Up @@ -675,6 +677,20 @@ static struct file_operations rdwr_pipe_fops = {
.fasync = pipe_rdwr_fasync,
};

struct pipe_inode_info * alloc_pipe_info(struct inode *inode)
{
struct pipe_inode_info *info;

info = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL);
if (info) {
init_waitqueue_head(&info->wait);
info->r_counter = info->w_counter = 1;
info->inode = inode;
}

return info;
}

void free_pipe_info(struct inode *inode)
{
int i;
Expand All @@ -691,23 +707,6 @@ void free_pipe_info(struct inode *inode)
kfree(info);
}

struct inode* pipe_new(struct inode* inode)
{
struct pipe_inode_info *info;

info = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL);
if (!info)
goto fail_page;
inode->i_pipe = info;

init_waitqueue_head(PIPE_WAIT(*inode));
PIPE_RCOUNTER(*inode) = PIPE_WCOUNTER(*inode) = 1;

return inode;
fail_page:
return NULL;
}

static struct vfsmount *pipe_mnt __read_mostly;
static int pipefs_delete_dentry(struct dentry *dentry)
{
Expand All @@ -724,8 +723,10 @@ static struct inode * get_pipe_inode(void)
if (!inode)
goto fail_inode;

if(!pipe_new(inode))
inode->i_pipe = alloc_pipe_info(inode);
if (!inode->i_pipe)
goto fail_iput;

PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 1;
inode->i_fop = &rdwr_pipe_fops;

Expand Down
Loading

0 comments on commit 3a326a2

Please sign in to comment.