Skip to content

Commit 01e7187

Browse files
thejhAl Viro
authored and
Al Viro
committed
pipe: stop using ->can_merge
Al Viro pointed out that since there is only one pipe buffer type to which new data can be appended, it isn't necessary to have a ->can_merge field in struct pipe_buf_operations, we can just check for a magic type. Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a0ce2f0 commit 01e7187

File tree

6 files changed

+16
-19
lines changed

6 files changed

+16
-19
lines changed

fs/pipe.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -226,36 +226,48 @@ void generic_pipe_buf_release(struct pipe_inode_info *pipe,
226226
}
227227
EXPORT_SYMBOL(generic_pipe_buf_release);
228228

229+
/* New data written to a pipe may be appended to a buffer with this type. */
229230
static const struct pipe_buf_operations anon_pipe_buf_ops = {
230-
.can_merge = 1,
231231
.confirm = generic_pipe_buf_confirm,
232232
.release = anon_pipe_buf_release,
233233
.steal = anon_pipe_buf_steal,
234234
.get = generic_pipe_buf_get,
235235
};
236236

237237
static const struct pipe_buf_operations anon_pipe_buf_nomerge_ops = {
238-
.can_merge = 0,
239238
.confirm = generic_pipe_buf_confirm,
240239
.release = anon_pipe_buf_release,
241240
.steal = anon_pipe_buf_steal,
242241
.get = generic_pipe_buf_get,
243242
};
244243

245244
static const struct pipe_buf_operations packet_pipe_buf_ops = {
246-
.can_merge = 0,
247245
.confirm = generic_pipe_buf_confirm,
248246
.release = anon_pipe_buf_release,
249247
.steal = anon_pipe_buf_steal,
250248
.get = generic_pipe_buf_get,
251249
};
252250

251+
/**
252+
* pipe_buf_mark_unmergeable - mark a &struct pipe_buffer as unmergeable
253+
* @buf: the buffer to mark
254+
*
255+
* Description:
256+
* This function ensures that no future writes will be merged into the
257+
* given &struct pipe_buffer. This is necessary when multiple pipe buffers
258+
* share the same backing page.
259+
*/
253260
void pipe_buf_mark_unmergeable(struct pipe_buffer *buf)
254261
{
255262
if (buf->ops == &anon_pipe_buf_ops)
256263
buf->ops = &anon_pipe_buf_nomerge_ops;
257264
}
258265

266+
static bool pipe_buf_can_merge(struct pipe_buffer *buf)
267+
{
268+
return buf->ops == &anon_pipe_buf_ops;
269+
}
270+
259271
static ssize_t
260272
pipe_read(struct kiocb *iocb, struct iov_iter *to)
261273
{
@@ -393,7 +405,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
393405
struct pipe_buffer *buf = pipe->bufs + lastbuf;
394406
int offset = buf->offset + buf->len;
395407

396-
if (buf->ops->can_merge && offset + chars <= PAGE_SIZE) {
408+
if (pipe_buf_can_merge(buf) && offset + chars <= PAGE_SIZE) {
397409
ret = pipe_buf_confirm(pipe, buf);
398410
if (ret)
399411
goto out;

fs/splice.c

-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,
138138
}
139139

140140
const struct pipe_buf_operations page_cache_pipe_buf_ops = {
141-
.can_merge = 0,
142141
.confirm = page_cache_pipe_buf_confirm,
143142
.release = page_cache_pipe_buf_release,
144143
.steal = page_cache_pipe_buf_steal,
@@ -156,7 +155,6 @@ static int user_page_pipe_buf_steal(struct pipe_inode_info *pipe,
156155
}
157156

158157
static const struct pipe_buf_operations user_page_pipe_buf_ops = {
159-
.can_merge = 0,
160158
.confirm = generic_pipe_buf_confirm,
161159
.release = page_cache_pipe_buf_release,
162160
.steal = user_page_pipe_buf_steal,
@@ -326,7 +324,6 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
326324
EXPORT_SYMBOL(generic_file_splice_read);
327325

328326
const struct pipe_buf_operations default_pipe_buf_ops = {
329-
.can_merge = 0,
330327
.confirm = generic_pipe_buf_confirm,
331328
.release = generic_pipe_buf_release,
332329
.steal = generic_pipe_buf_steal,
@@ -341,7 +338,6 @@ static int generic_pipe_buf_nosteal(struct pipe_inode_info *pipe,
341338

342339
/* Pipe buffer operations for a socket and similar. */
343340
const struct pipe_buf_operations nosteal_pipe_buf_ops = {
344-
.can_merge = 0,
345341
.confirm = generic_pipe_buf_confirm,
346342
.release = generic_pipe_buf_release,
347343
.steal = generic_pipe_buf_nosteal,

include/linux/pipe_fs_i.h

-7
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ struct pipe_inode_info {
7373
* in fs/pipe.c for the pipe and generic variants of these hooks.
7474
*/
7575
struct pipe_buf_operations {
76-
/*
77-
* This is set to 1, if the generic pipe read/write may coalesce
78-
* data into an existing buffer. If this is set to 0, a new pipe
79-
* page segment is always used for new data.
80-
*/
81-
int can_merge;
82-
8376
/*
8477
* ->confirm() verifies that the data in the pipe buffer is there
8578
* and that the contents are good. If the pages in the pipe belong

kernel/relay.c

-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,6 @@ static void relay_pipe_buf_release(struct pipe_inode_info *pipe,
11751175
}
11761176

11771177
static const struct pipe_buf_operations relay_pipe_buf_ops = {
1178-
.can_merge = 0,
11791178
.confirm = generic_pipe_buf_confirm,
11801179
.release = relay_pipe_buf_release,
11811180
.steal = generic_pipe_buf_steal,

kernel/trace/trace.c

-2
Original file line numberDiff line numberDiff line change
@@ -5823,7 +5823,6 @@ static void tracing_spd_release_pipe(struct splice_pipe_desc *spd,
58235823
}
58245824

58255825
static const struct pipe_buf_operations tracing_pipe_buf_ops = {
5826-
.can_merge = 0,
58275826
.confirm = generic_pipe_buf_confirm,
58285827
.release = generic_pipe_buf_release,
58295828
.steal = generic_pipe_buf_steal,
@@ -6843,7 +6842,6 @@ static void buffer_pipe_buf_get(struct pipe_inode_info *pipe,
68436842

68446843
/* Pipe buffer operations for a buffer. */
68456844
static const struct pipe_buf_operations buffer_pipe_buf_ops = {
6846-
.can_merge = 0,
68476845
.confirm = generic_pipe_buf_confirm,
68486846
.release = buffer_pipe_buf_release,
68496847
.steal = generic_pipe_buf_steal,

net/smc/smc_rx.c

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ static int smc_rx_pipe_buf_nosteal(struct pipe_inode_info *pipe,
136136
}
137137

138138
static const struct pipe_buf_operations smc_pipe_ops = {
139-
.can_merge = 0,
140139
.confirm = generic_pipe_buf_confirm,
141140
.release = smc_rx_pipe_buf_release,
142141
.steal = smc_rx_pipe_buf_nosteal,

0 commit comments

Comments
 (0)