Skip to content

Commit

Permalink
pipe: Make pipe-data entry always be present in the image
Browse files Browse the repository at this point in the history
It contains info about the pipe itself, not jut one of its
ends. Thus if we want to add more (e.g. -- its size) we'll
have to put it there and thus have it always present.

Signed-off-by: Pavel Emelyanov <[email protected]>
  • Loading branch information
xemul committed Jan 11, 2013
1 parent 0edb637 commit 42d7bc0
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions pipes.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ static void show_saved_pipe_fds(struct pipe_info *pi)

static int pipe_data_read(int fd, struct pipe_data_rst *r)
{
unsigned long bytes = r->pde->bytes;

if (!bytes)
return 0;

/*
* We potentially allocate more memory than required for data,
* but this is OK. Look at restore_pipe_data -- it vmsplice-s
Expand All @@ -53,14 +58,14 @@ static int pipe_data_read(int fd, struct pipe_data_rst *r)
* anyway we don't increase memory consumption :)
*/

r->data = mmap(NULL, r->pde->bytes, PROT_READ | PROT_WRITE,
r->data = mmap(NULL, bytes, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANON, 0, 0);
if (r->data == MAP_FAILED) {
pr_perror("Can't map mem for pipe buffers");
return -1;
}

return read_img_buf(fd, r->data, r->pde->bytes);
return read_img_buf(fd, r->data, bytes);
}

int collect_pipe_data(int img_type, struct pipe_data_rst **hash)
Expand Down Expand Up @@ -161,6 +166,9 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash
return 0;
}

if (!pd->pde->bytes)
return 0;

if (!pd->data) {
pr_err("Double data restore occurred on %#x\n", id);
return -1;
Expand Down Expand Up @@ -348,6 +356,7 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms
int pipe_size, i, bytes;
int steal_pipe[2];
int ret = -1;
PipeDataEntry pde = PIPE_DATA_ENTRY__INIT;

if (p->flags & O_WRONLY)
return 0;
Expand Down Expand Up @@ -380,15 +389,23 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms
}

bytes = tee(lfd, steal_pipe[1], pipe_size, SPLICE_F_NONBLOCK);
if (bytes > 0) {
PipeDataEntry pde = PIPE_DATA_ENTRY__INIT;
int wrote;
if (bytes < 0) {
if (errno != EAGAIN) {
pr_perror("Can't pick pipe data");
goto err_close;
}

pde.pipe_id = pipe_id(p);
pde.bytes = bytes;
bytes = 0;
}

if (pb_write_one(img, &pde, PB_PIPES_DATA))
goto err_close;
pde.pipe_id = pipe_id(p);
pde.bytes = bytes;

if (pb_write_one(img, &pde, PB_PIPES_DATA))
goto err_close;

if (bytes) {
int wrote;

wrote = splice(steal_pipe[0], NULL, img, NULL, bytes, 0);
if (wrote < 0) {
Expand All @@ -399,11 +416,6 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms
pipe_id(p), bytes, wrote);
goto err_close;
}
} else if (bytes < 0) {
if (errno != EAGAIN) {
pr_perror("Can't pick pipe data");
goto err_close;
}
}

ret = 0;
Expand Down

0 comments on commit 42d7bc0

Please sign in to comment.