Commit 5a4c27a8 authored by Andrei Vagin's avatar Andrei Vagin

pipe: dump all data from a pipe

Currently we use an additional pipe to steal data from a pipe, but we
don't check that we steal all data. And the additional pipe can have a
smaller size.
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6dd3e4e3
...@@ -168,6 +168,16 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash ...@@ -168,6 +168,16 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash
return -1; return -1;
} }
if (pd->pde->has_size) {
pr_info("Restoring size %#x for %#x\n",
pd->pde->size, pd->pde->pipe_id);
ret = fcntl(pfd, F_SETPIPE_SZ, pd->pde->size);
if (ret < 0) {
pr_perror("Can't restore pipe size");
goto err;
}
}
iov.iov_base = pd->data; iov.iov_base = pd->data;
iov.iov_len = pd->pde->bytes; iov.iov_len = pd->pde->bytes;
...@@ -203,15 +213,6 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash ...@@ -203,15 +213,6 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash
pd->data = NULL; pd->data = NULL;
out: out:
ret = 0; ret = 0;
if (pd->pde->has_size) {
pr_info("Restoring size %#x for %#x\n",
pd->pde->size, pd->pde->pipe_id);
ret = fcntl(pfd, F_SETPIPE_SZ, pd->pde->size);
if (ret < 0)
pr_perror("Can't restore pipe size");
else
ret = 0;
}
err: err:
return ret; return ret;
} }
...@@ -442,6 +443,12 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms ...@@ -442,6 +443,12 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms
goto err; goto err;
} }
/* steal_pipe has to be able to fit all data from a target pipe */
if (fcntl(steal_pipe[1], F_SETPIPE_SZ, pipe_size) < 0) {
pr_perror("Unable to set a pipe size");
goto err;
}
bytes = tee(lfd, steal_pipe[1], pipe_size, SPLICE_F_NONBLOCK); bytes = tee(lfd, steal_pipe[1], pipe_size, SPLICE_F_NONBLOCK);
if (bytes < 0) { if (bytes < 0) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
......
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