mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 05:18:00 +00:00
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: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
0cb37add6a
commit
7758a4e7f3
@ -28,6 +28,41 @@ static inline void iov_init(struct iovec *iov, unsigned long addr)
|
||||
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)
|
||||
{
|
||||
struct page_pipe_buf *ppb;
|
||||
@ -69,23 +104,6 @@ static void ppb_init(struct page_pipe_buf *ppb, unsigned int pages_in,
|
||||
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)
|
||||
{
|
||||
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
|
||||
if (ppb->flags != flags)
|
||||
return 1;
|
||||
|
||||
if (ppb->pages_in == ppb->pipe_size) {
|
||||
unsigned long new_size = ppb->pipe_size << 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_resize_pipe(ppb) == 1)
|
||||
return 1;
|
||||
|
||||
if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr))
|
||||
goto out;
|
||||
|
Loading…
x
Reference in New Issue
Block a user