Unverified Commit 5a957bba authored by Christian Brauner's avatar Christian Brauner
Browse files

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: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 5e9b50de
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -686,7 +686,7 @@ pipe_poll(struct file *filp, poll_table *wait)
	if (filp->f_mode & FMODE_READ) {
		if (!pipe_empty(head, tail))
			mask |= EPOLLIN | EPOLLRDNORM;
		if (!pipe->writers && filp->f_version != pipe->w_counter)
		if (!pipe->writers && filp->f_pipe != pipe->w_counter)
			mask |= EPOLLHUP;
	}

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

	f->private_data = inode->i_pipe;
	f->f_pipe = 0;

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

	filp->f_version = 0;
	filp->f_pipe = 0;

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