Skip to content

Commit

Permalink
[PATCH] reuse xxx_fifo_fops for xxx_pipe_fops
Browse files Browse the repository at this point in the history
Merge fifo and pipe file_operations.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Denys Vlasenko authored and Al Viro committed Jul 27, 2008
1 parent d70b67c commit d2d9648
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 50 deletions.
8 changes: 4 additions & 4 deletions fs/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
* POSIX.1 says that O_NONBLOCK means return with the FIFO
* opened, even when there is no process writing the FIFO.
*/
filp->f_op = &read_fifo_fops;
filp->f_op = &read_pipefifo_fops;
pipe->r_counter++;
if (pipe->readers++ == 0)
wake_up_partner(inode);
Expand Down Expand Up @@ -86,7 +86,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
goto err;

filp->f_op = &write_fifo_fops;
filp->f_op = &write_pipefifo_fops;
pipe->w_counter++;
if (!pipe->writers++)
wake_up_partner(inode);
Expand All @@ -105,7 +105,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
* This implementation will NEVER block on a O_RDWR open, since
* the process can at least talk to itself.
*/
filp->f_op = &rdwr_fifo_fops;
filp->f_op = &rdwr_pipefifo_fops;

pipe->readers++;
pipe->writers++;
Expand Down Expand Up @@ -151,5 +151,5 @@ static int fifo_open(struct inode *inode, struct file *filp)
* depending on the access mode of the file...
*/
const struct file_operations def_fifo_fops = {
.open = fifo_open, /* will set read or write pipe_fops */
.open = fifo_open, /* will set read_ or write_pipefifo_fops */
};
51 changes: 8 additions & 43 deletions fs/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,45 +777,10 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
/*
* The file_operations structs are not static because they
* are also used in linux/fs/fifo.c to do operations on FIFOs.
*
* Pipes reuse fifos' file_operations structs.
*/
const struct file_operations read_fifo_fops = {
.llseek = no_llseek,
.read = do_sync_read,
.aio_read = pipe_read,
.write = bad_pipe_w,
.poll = pipe_poll,
.unlocked_ioctl = pipe_ioctl,
.open = pipe_read_open,
.release = pipe_read_release,
.fasync = pipe_read_fasync,
};

const struct file_operations write_fifo_fops = {
.llseek = no_llseek,
.read = bad_pipe_r,
.write = do_sync_write,
.aio_write = pipe_write,
.poll = pipe_poll,
.unlocked_ioctl = pipe_ioctl,
.open = pipe_write_open,
.release = pipe_write_release,
.fasync = pipe_write_fasync,
};

const struct file_operations rdwr_fifo_fops = {
.llseek = no_llseek,
.read = do_sync_read,
.aio_read = pipe_read,
.write = do_sync_write,
.aio_write = pipe_write,
.poll = pipe_poll,
.unlocked_ioctl = pipe_ioctl,
.open = pipe_rdwr_open,
.release = pipe_rdwr_release,
.fasync = pipe_rdwr_fasync,
};

static const struct file_operations read_pipe_fops = {
const struct file_operations read_pipefifo_fops = {
.llseek = no_llseek,
.read = do_sync_read,
.aio_read = pipe_read,
Expand All @@ -827,7 +792,7 @@ static const struct file_operations read_pipe_fops = {
.fasync = pipe_read_fasync,
};

static const struct file_operations write_pipe_fops = {
const struct file_operations write_pipefifo_fops = {
.llseek = no_llseek,
.read = bad_pipe_r,
.write = do_sync_write,
Expand All @@ -839,7 +804,7 @@ static const struct file_operations write_pipe_fops = {
.fasync = pipe_write_fasync,
};

static const struct file_operations rdwr_pipe_fops = {
const struct file_operations rdwr_pipefifo_fops = {
.llseek = no_llseek,
.read = do_sync_read,
.aio_read = pipe_read,
Expand Down Expand Up @@ -927,7 +892,7 @@ static struct inode * get_pipe_inode(void)
inode->i_pipe = pipe;

pipe->readers = pipe->writers = 1;
inode->i_fop = &rdwr_pipe_fops;
inode->i_fop = &rdwr_pipefifo_fops;

/*
* Mark the inode dirty from the very beginning,
Expand Down Expand Up @@ -978,7 +943,7 @@ struct file *create_write_pipe(int flags)
d_instantiate(dentry, inode);

err = -ENFILE;
f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipe_fops);
f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipefifo_fops);
if (!f)
goto err_dentry;
f->f_mapping = inode->i_mapping;
Expand Down Expand Up @@ -1020,7 +985,7 @@ struct file *create_read_pipe(struct file *wrf, int flags)

f->f_pos = 0;
f->f_flags = O_RDONLY | (flags & O_NONBLOCK);
f->f_op = &read_pipe_fops;
f->f_op = &read_pipefifo_fops;
f->f_mode = FMODE_READ;
f->f_version = 0;

Expand Down
6 changes: 3 additions & 3 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1696,9 +1696,9 @@ extern void init_special_inode(struct inode *, umode_t, dev_t);
extern void make_bad_inode(struct inode *);
extern int is_bad_inode(struct inode *);

extern const struct file_operations read_fifo_fops;
extern const struct file_operations write_fifo_fops;
extern const struct file_operations rdwr_fifo_fops;
extern const struct file_operations read_pipefifo_fops;
extern const struct file_operations write_pipefifo_fops;
extern const struct file_operations rdwr_pipefifo_fops;

extern int fs_may_remount_ro(struct super_block *);

Expand Down

0 comments on commit d2d9648

Please sign in to comment.