Commit 92acdc4f authored by Al Viro's avatar Al Viro

ITER_PIPE: clean iov_iter_revert()

Fold pipe_truncate() into it, clean up.  We can release buffers
in the same loop where we walk backwards to the iterator beginning
looking for the place where the new position will be.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 2c855de9
...@@ -816,32 +816,6 @@ size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t byt ...@@ -816,32 +816,6 @@ size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t byt
} }
EXPORT_SYMBOL(copy_page_from_iter_atomic); EXPORT_SYMBOL(copy_page_from_iter_atomic);
static inline void pipe_truncate(struct iov_iter *i)
{
struct pipe_inode_info *pipe = i->pipe;
unsigned int p_tail = pipe->tail;
unsigned int p_head = pipe->head;
unsigned int p_mask = pipe->ring_size - 1;
if (!pipe_empty(p_head, p_tail)) {
struct pipe_buffer *buf;
unsigned int i_head = i->head;
size_t off = i->iov_offset;
if (off) {
buf = &pipe->bufs[i_head & p_mask];
buf->len = off - buf->offset;
i_head++;
}
while (p_head != i_head) {
p_head--;
pipe_buf_release(pipe, &pipe->bufs[p_head & p_mask]);
}
pipe->head = p_head;
}
}
static void pipe_advance(struct iov_iter *i, size_t size) static void pipe_advance(struct iov_iter *i, size_t size)
{ {
struct pipe_inode_info *pipe = i->pipe; struct pipe_inode_info *pipe = i->pipe;
...@@ -936,28 +910,22 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll) ...@@ -936,28 +910,22 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)
i->count += unroll; i->count += unroll;
if (unlikely(iov_iter_is_pipe(i))) { if (unlikely(iov_iter_is_pipe(i))) {
struct pipe_inode_info *pipe = i->pipe; struct pipe_inode_info *pipe = i->pipe;
unsigned int p_mask = pipe->ring_size - 1; unsigned int head = pipe->head;
unsigned int i_head = i->head;
size_t off = i->iov_offset; while (head > i->start_head) {
while (1) { struct pipe_buffer *b = pipe_buf(pipe, --head);
struct pipe_buffer *b = &pipe->bufs[i_head & p_mask]; if (unroll < b->len) {
size_t n = off - b->offset; b->len -= unroll;
if (unroll < n) { i->iov_offset = b->offset + b->len;
off -= unroll; i->head = head;
break; return;
}
unroll -= n;
if (!unroll && i_head == i->start_head) {
off = 0;
break;
} }
i_head--; unroll -= b->len;
b = &pipe->bufs[i_head & p_mask]; pipe_buf_release(pipe, b);
off = b->offset + b->len; pipe->head--;
} }
i->iov_offset = off; i->iov_offset = 0;
i->head = i_head; i->head = head;
pipe_truncate(i);
return; return;
} }
if (unlikely(iov_iter_is_discard(i))) if (unlikely(iov_iter_is_discard(i)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment