Skip to content

Commit ae03c53

Browse files
committed
Merge branch 'work.splice' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull splice updates from Al Viro: "Christoph's assorted splice cleanups" * 'work.splice' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: fs: rename pipe_buf ->steal to ->try_steal fs: make the pipe_buf_operations ->confirm operation optional fs: make the pipe_buf_operations ->steal operation optional trace: remove tracing_pipe_buf_ops pipe: merge anon_pipe_buf*_ops fs: simplify do_splice_from fs: simplify do_splice_to
2 parents 039aeb9 + c928f64 commit ae03c53

File tree

8 files changed

+77
-170
lines changed

8 files changed

+77
-170
lines changed

drivers/char/virtio_console.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
871871
return 0;
872872

873873
/* Try lock this page */
874-
if (pipe_buf_steal(pipe, buf) == 0) {
874+
if (pipe_buf_try_steal(pipe, buf)) {
875875
/* Get reference and unlock page for moving */
876876
get_page(buf->page);
877877
unlock_page(buf->page);

fs/fuse/dev.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
805805
if (cs->len != PAGE_SIZE)
806806
goto out_fallback;
807807

808-
if (pipe_buf_steal(cs->pipe, buf) != 0)
808+
if (!pipe_buf_try_steal(cs->pipe, buf))
809809
goto out_fallback;
810810

811811
newpage = buf->page;

fs/pipe.c

+21-75
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,20 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe,
140140
put_page(page);
141141
}
142142

143-
static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
144-
struct pipe_buffer *buf)
143+
static bool anon_pipe_buf_try_steal(struct pipe_inode_info *pipe,
144+
struct pipe_buffer *buf)
145145
{
146146
struct page *page = buf->page;
147147

148-
if (page_count(page) == 1) {
149-
memcg_kmem_uncharge_page(page, 0);
150-
__SetPageLocked(page);
151-
return 0;
152-
}
153-
return 1;
148+
if (page_count(page) != 1)
149+
return false;
150+
memcg_kmem_uncharge_page(page, 0);
151+
__SetPageLocked(page);
152+
return true;
154153
}
155154

156155
/**
157-
* generic_pipe_buf_steal - attempt to take ownership of a &pipe_buffer
156+
* generic_pipe_buf_try_steal - attempt to take ownership of a &pipe_buffer
158157
* @pipe: the pipe that the buffer belongs to
159158
* @buf: the buffer to attempt to steal
160159
*
@@ -165,8 +164,8 @@ static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
165164
* he wishes; the typical use is insertion into a different file
166165
* page cache.
167166
*/
168-
int generic_pipe_buf_steal(struct pipe_inode_info *pipe,
169-
struct pipe_buffer *buf)
167+
bool generic_pipe_buf_try_steal(struct pipe_inode_info *pipe,
168+
struct pipe_buffer *buf)
170169
{
171170
struct page *page = buf->page;
172171

@@ -177,12 +176,11 @@ int generic_pipe_buf_steal(struct pipe_inode_info *pipe,
177176
*/
178177
if (page_count(page) == 1) {
179178
lock_page(page);
180-
return 0;
179+
return true;
181180
}
182-
183-
return 1;
181+
return false;
184182
}
185-
EXPORT_SYMBOL(generic_pipe_buf_steal);
183+
EXPORT_SYMBOL(generic_pipe_buf_try_steal);
186184

187185
/**
188186
* generic_pipe_buf_get - get a reference to a &struct pipe_buffer
@@ -200,22 +198,6 @@ bool generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
200198
}
201199
EXPORT_SYMBOL(generic_pipe_buf_get);
202200

203-
/**
204-
* generic_pipe_buf_confirm - verify contents of the pipe buffer
205-
* @info: the pipe that the buffer belongs to
206-
* @buf: the buffer to confirm
207-
*
208-
* Description:
209-
* This function does nothing, because the generic pipe code uses
210-
* pages that are always good when inserted into the pipe.
211-
*/
212-
int generic_pipe_buf_confirm(struct pipe_inode_info *info,
213-
struct pipe_buffer *buf)
214-
{
215-
return 0;
216-
}
217-
EXPORT_SYMBOL(generic_pipe_buf_confirm);
218-
219201
/**
220202
* generic_pipe_buf_release - put a reference to a &struct pipe_buffer
221203
* @pipe: the pipe that the buffer belongs to
@@ -231,48 +213,12 @@ void generic_pipe_buf_release(struct pipe_inode_info *pipe,
231213
}
232214
EXPORT_SYMBOL(generic_pipe_buf_release);
233215

234-
/* New data written to a pipe may be appended to a buffer with this type. */
235216
static const struct pipe_buf_operations anon_pipe_buf_ops = {
236-
.confirm = generic_pipe_buf_confirm,
237-
.release = anon_pipe_buf_release,
238-
.steal = anon_pipe_buf_steal,
239-
.get = generic_pipe_buf_get,
240-
};
241-
242-
static const struct pipe_buf_operations anon_pipe_buf_nomerge_ops = {
243-
.confirm = generic_pipe_buf_confirm,
244-
.release = anon_pipe_buf_release,
245-
.steal = anon_pipe_buf_steal,
246-
.get = generic_pipe_buf_get,
247-
};
248-
249-
static const struct pipe_buf_operations packet_pipe_buf_ops = {
250-
.confirm = generic_pipe_buf_confirm,
251-
.release = anon_pipe_buf_release,
252-
.steal = anon_pipe_buf_steal,
253-
.get = generic_pipe_buf_get,
217+
.release = anon_pipe_buf_release,
218+
.try_steal = anon_pipe_buf_try_steal,
219+
.get = generic_pipe_buf_get,
254220
};
255221

256-
/**
257-
* pipe_buf_mark_unmergeable - mark a &struct pipe_buffer as unmergeable
258-
* @buf: the buffer to mark
259-
*
260-
* Description:
261-
* This function ensures that no future writes will be merged into the
262-
* given &struct pipe_buffer. This is necessary when multiple pipe buffers
263-
* share the same backing page.
264-
*/
265-
void pipe_buf_mark_unmergeable(struct pipe_buffer *buf)
266-
{
267-
if (buf->ops == &anon_pipe_buf_ops)
268-
buf->ops = &anon_pipe_buf_nomerge_ops;
269-
}
270-
271-
static bool pipe_buf_can_merge(struct pipe_buffer *buf)
272-
{
273-
return buf->ops == &anon_pipe_buf_ops;
274-
}
275-
276222
/* Done while waiting without holding the pipe lock - thus the READ_ONCE() */
277223
static inline bool pipe_readable(const struct pipe_inode_info *pipe)
278224
{
@@ -478,7 +424,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
478424
struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask];
479425
int offset = buf->offset + buf->len;
480426

481-
if (pipe_buf_can_merge(buf) && offset + chars <= PAGE_SIZE) {
427+
if ((buf->flags & PIPE_BUF_FLAG_CAN_MERGE) &&
428+
offset + chars <= PAGE_SIZE) {
482429
ret = pipe_buf_confirm(pipe, buf);
483430
if (ret)
484431
goto out;
@@ -541,11 +488,10 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
541488
buf->ops = &anon_pipe_buf_ops;
542489
buf->offset = 0;
543490
buf->len = 0;
544-
buf->flags = 0;
545-
if (is_packetized(filp)) {
546-
buf->ops = &packet_pipe_buf_ops;
491+
if (is_packetized(filp))
547492
buf->flags = PIPE_BUF_FLAG_PACKET;
548-
}
493+
else
494+
buf->flags = PIPE_BUF_FLAG_CAN_MERGE;
549495
pipe->tmp_page = NULL;
550496

551497
copied = copy_page_from_iter(page, 0, PAGE_SIZE, from);

fs/splice.c

+29-52
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
* addition of remove_mapping(). If success is returned, the caller may
4545
* attempt to reuse this page for another destination.
4646
*/
47-
static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,
48-
struct pipe_buffer *buf)
47+
static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,
48+
struct pipe_buffer *buf)
4949
{
5050
struct page *page = buf->page;
5151
struct address_space *mapping;
@@ -76,7 +76,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,
7676
*/
7777
if (remove_mapping(mapping, page)) {
7878
buf->flags |= PIPE_BUF_FLAG_LRU;
79-
return 0;
79+
return true;
8080
}
8181
}
8282

@@ -86,7 +86,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,
8686
*/
8787
out_unlock:
8888
unlock_page(page);
89-
return 1;
89+
return false;
9090
}
9191

9292
static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe,
@@ -139,27 +139,26 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,
139139
}
140140

141141
const struct pipe_buf_operations page_cache_pipe_buf_ops = {
142-
.confirm = page_cache_pipe_buf_confirm,
143-
.release = page_cache_pipe_buf_release,
144-
.steal = page_cache_pipe_buf_steal,
145-
.get = generic_pipe_buf_get,
142+
.confirm = page_cache_pipe_buf_confirm,
143+
.release = page_cache_pipe_buf_release,
144+
.try_steal = page_cache_pipe_buf_try_steal,
145+
.get = generic_pipe_buf_get,
146146
};
147147

148-
static int user_page_pipe_buf_steal(struct pipe_inode_info *pipe,
149-
struct pipe_buffer *buf)
148+
static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe,
149+
struct pipe_buffer *buf)
150150
{
151151
if (!(buf->flags & PIPE_BUF_FLAG_GIFT))
152-
return 1;
152+
return false;
153153

154154
buf->flags |= PIPE_BUF_FLAG_LRU;
155-
return generic_pipe_buf_steal(pipe, buf);
155+
return generic_pipe_buf_try_steal(pipe, buf);
156156
}
157157

158158
static const struct pipe_buf_operations user_page_pipe_buf_ops = {
159-
.confirm = generic_pipe_buf_confirm,
160-
.release = page_cache_pipe_buf_release,
161-
.steal = user_page_pipe_buf_steal,
162-
.get = generic_pipe_buf_get,
159+
.release = page_cache_pipe_buf_release,
160+
.try_steal = user_page_pipe_buf_try_steal,
161+
.get = generic_pipe_buf_get,
163162
};
164163

165164
static void wakeup_pipe_readers(struct pipe_inode_info *pipe)
@@ -331,24 +330,15 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
331330
EXPORT_SYMBOL(generic_file_splice_read);
332331

333332
const struct pipe_buf_operations default_pipe_buf_ops = {
334-
.confirm = generic_pipe_buf_confirm,
335-
.release = generic_pipe_buf_release,
336-
.steal = generic_pipe_buf_steal,
337-
.get = generic_pipe_buf_get,
333+
.release = generic_pipe_buf_release,
334+
.try_steal = generic_pipe_buf_try_steal,
335+
.get = generic_pipe_buf_get,
338336
};
339337

340-
int generic_pipe_buf_nosteal(struct pipe_inode_info *pipe,
341-
struct pipe_buffer *buf)
342-
{
343-
return 1;
344-
}
345-
346338
/* Pipe buffer operations for a socket and similar. */
347339
const struct pipe_buf_operations nosteal_pipe_buf_ops = {
348-
.confirm = generic_pipe_buf_confirm,
349-
.release = generic_pipe_buf_release,
350-
.steal = generic_pipe_buf_nosteal,
351-
.get = generic_pipe_buf_get,
340+
.release = generic_pipe_buf_release,
341+
.get = generic_pipe_buf_get,
352342
};
353343
EXPORT_SYMBOL(nosteal_pipe_buf_ops);
354344

@@ -852,15 +842,9 @@ EXPORT_SYMBOL(generic_splice_sendpage);
852842
static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
853843
loff_t *ppos, size_t len, unsigned int flags)
854844
{
855-
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
856-
loff_t *, size_t, unsigned int);
857-
858845
if (out->f_op->splice_write)
859-
splice_write = out->f_op->splice_write;
860-
else
861-
splice_write = default_file_splice_write;
862-
863-
return splice_write(pipe, out, ppos, len, flags);
846+
return out->f_op->splice_write(pipe, out, ppos, len, flags);
847+
return default_file_splice_write(pipe, out, ppos, len, flags);
864848
}
865849

866850
/*
@@ -870,8 +854,6 @@ static long do_splice_to(struct file *in, loff_t *ppos,
870854
struct pipe_inode_info *pipe, size_t len,
871855
unsigned int flags)
872856
{
873-
ssize_t (*splice_read)(struct file *, loff_t *,
874-
struct pipe_inode_info *, size_t, unsigned int);
875857
int ret;
876858

877859
if (unlikely(!(in->f_mode & FMODE_READ)))
@@ -885,11 +867,8 @@ static long do_splice_to(struct file *in, loff_t *ppos,
885867
len = MAX_RW_COUNT;
886868

887869
if (in->f_op->splice_read)
888-
splice_read = in->f_op->splice_read;
889-
else
890-
splice_read = default_file_splice_read;
891-
892-
return splice_read(in, ppos, pipe, len, flags);
870+
return in->f_op->splice_read(in, ppos, pipe, len, flags);
871+
return default_file_splice_read(in, ppos, pipe, len, flags);
893872
}
894873

895874
/**
@@ -1626,12 +1605,11 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,
16261605
*obuf = *ibuf;
16271606

16281607
/*
1629-
* Don't inherit the gift flag, we need to
1608+
* Don't inherit the gift and merge flags, we need to
16301609
* prevent multiple steals of this page.
16311610
*/
16321611
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
1633-
1634-
pipe_buf_mark_unmergeable(obuf);
1612+
obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE;
16351613

16361614
obuf->len = len;
16371615
ibuf->offset += len;
@@ -1719,12 +1697,11 @@ static int link_pipe(struct pipe_inode_info *ipipe,
17191697
*obuf = *ibuf;
17201698

17211699
/*
1722-
* Don't inherit the gift flag, we need to
1723-
* prevent multiple steals of this page.
1700+
* Don't inherit the gift and merge flag, we need to prevent
1701+
* multiple steals of this page.
17241702
*/
17251703
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
1726-
1727-
pipe_buf_mark_unmergeable(obuf);
1704+
obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE;
17281705

17291706
if (obuf->len > len)
17301707
obuf->len = len;

0 commit comments

Comments
 (0)