Skip to content

Commit 5a957bb

Browse files
committed
pipe: use f_pipe
Pipes use f_version to defer poll notifications until a write has been observed. Since multiple file's refer to the same struct pipe_inode_info in their ->private_data moving it into their isn't feasible since we would need to introduce an additional pointer indirection. However, since pipes don't require f_pos_lock we placed a new f_pipe member into a union with f_pos_lock that pipes can use. This is similar to what we already do for struct inode where we have additional fields per file type. This will allow us to fully remove f_version in the next step. Link: https://lore.kernel.org/r/20240830-vfs-file-f_version-v1-19-6d3e4816aa7b@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5e9b50d commit 5a957bb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/pipe.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pipe_poll(struct file *filp, poll_table *wait)
686686
if (filp->f_mode & FMODE_READ) {
687687
if (!pipe_empty(head, tail))
688688
mask |= EPOLLIN | EPOLLRDNORM;
689-
if (!pipe->writers && filp->f_version != pipe->w_counter)
689+
if (!pipe->writers && filp->f_pipe != pipe->w_counter)
690690
mask |= EPOLLHUP;
691691
}
692692

@@ -945,6 +945,7 @@ int create_pipe_files(struct file **res, int flags)
945945
}
946946

947947
f->private_data = inode->i_pipe;
948+
f->f_pipe = 0;
948949

949950
res[0] = alloc_file_clone(f, O_RDONLY | (flags & O_NONBLOCK),
950951
&pipefifo_fops);
@@ -954,6 +955,7 @@ int create_pipe_files(struct file **res, int flags)
954955
return PTR_ERR(res[0]);
955956
}
956957
res[0]->private_data = inode->i_pipe;
958+
res[0]->f_pipe = 0;
957959
res[1] = f;
958960
stream_open(inode, res[0]);
959961
stream_open(inode, res[1]);
@@ -1108,7 +1110,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
11081110
bool is_pipe = inode->i_sb->s_magic == PIPEFS_MAGIC;
11091111
int ret;
11101112

1111-
filp->f_version = 0;
1113+
filp->f_pipe = 0;
11121114

11131115
spin_lock(&inode->i_lock);
11141116
if (inode->i_pipe) {
@@ -1155,7 +1157,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
11551157
if ((filp->f_flags & O_NONBLOCK)) {
11561158
/* suppress EPOLLHUP until we have
11571159
* seen a writer */
1158-
filp->f_version = pipe->w_counter;
1160+
filp->f_pipe = pipe->w_counter;
11591161
} else {
11601162
if (wait_for_partner(pipe, &pipe->w_counter))
11611163
goto err_rd;

0 commit comments

Comments
 (0)