Commit 6feebf3a authored by Andrei Vagin's avatar Andrei Vagin

page-pipe: move code to resize a pipe in a separate function

v2: and move it upper, because it is going to be used in ppb_alloc()
Acked-by: 's avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent e3c6784b
...@@ -28,6 +28,41 @@ static inline void iov_init(struct iovec *iov, unsigned long addr) ...@@ -28,6 +28,41 @@ static inline void iov_init(struct iovec *iov, unsigned long addr)
iov->iov_len = PAGE_SIZE; iov->iov_len = PAGE_SIZE;
} }
static int __ppb_resize_pipe(struct page_pipe_buf *ppb, unsigned long new_size)
{
int ret;
ret = fcntl(ppb->p[0], F_SETPIPE_SZ, new_size * PAGE_SIZE);
if (ret < 0)
return -1;
ret /= PAGE_SIZE;
BUG_ON(ret < ppb->pipe_size);
pr_debug("Grow pipe %x -> %x\n", ppb->pipe_size, ret);
ppb->pipe_size = ret;
return 0;
}
static inline int ppb_resize_pipe(struct page_pipe_buf *ppb)
{
unsigned long new_size = ppb->pipe_size << 1;
int ret;
if (ppb->pages_in < ppb->pipe_size)
return 0;
if (new_size > PIPE_MAX_SIZE)
return 1;
ret = __ppb_resize_pipe(ppb, new_size);
if (ret < 0)
return 1; /* need to add another buf */
return 0;
}
static struct page_pipe_buf *ppb_alloc(struct page_pipe *pp) static struct page_pipe_buf *ppb_alloc(struct page_pipe *pp)
{ {
struct page_pipe_buf *ppb; struct page_pipe_buf *ppb;
...@@ -69,23 +104,6 @@ static void ppb_init(struct page_pipe_buf *ppb, unsigned int pages_in, ...@@ -69,23 +104,6 @@ static void ppb_init(struct page_pipe_buf *ppb, unsigned int pages_in,
ppb->iov = iov; ppb->iov = iov;
} }
static int ppb_resize_pipe(struct page_pipe_buf *ppb, unsigned long new_size)
{
int ret;
ret = fcntl(ppb->p[0], F_SETPIPE_SZ, new_size * PAGE_SIZE);
if (ret < 0)
return -1;
ret /= PAGE_SIZE;
BUG_ON(ret < ppb->pipe_size);
pr_debug("Grow pipe %x -> %x\n", ppb->pipe_size, ret);
ppb->pipe_size = ret;
return 0;
}
static int page_pipe_grow(struct page_pipe *pp, unsigned int flags) static int page_pipe_grow(struct page_pipe *pp, unsigned int flags)
{ {
struct page_pipe_buf *ppb; struct page_pipe_buf *ppb;
...@@ -195,17 +213,8 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp ...@@ -195,17 +213,8 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp
if (ppb->flags != flags) if (ppb->flags != flags)
return 1; return 1;
if (ppb->pages_in == ppb->pipe_size) { if (ppb_resize_pipe(ppb) == 1)
unsigned long new_size = ppb->pipe_size << 1; return 1;
int ret;
if (new_size > PIPE_MAX_SIZE)
return 1;
ret = ppb_resize_pipe(ppb, new_size);
if (ret < 0)
return 1; /* need to add another buf */
}
if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr)) if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr))
goto out; goto out;
......
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