[CRIU] [PATCH 1/5] pipes: Make dump_one_pipe_data/restore_pipe_data
being non-static
Cyrill Gorcunov
gorcunov at openvz.org
Tue Jun 26 04:07:18 EDT 2012
To reuse with fifo data restore.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/pipes.h | 4 ++++
pipes.c | 43 +++++++++++++++++++++----------------------
2 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/include/pipes.h b/include/pipes.h
index 67b17a2..17bb11d 100644
--- a/include/pipes.h
+++ b/include/pipes.h
@@ -4,4 +4,8 @@ extern int collect_pipes(void);
extern void mark_pipe_master(void);
int dump_pipe(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset);
+
+extern int dump_one_pipe_data(int img, int lfd, u32 id, const struct fd_parms *p);
+extern int restore_pipe_data(int img, int pfd, u32 id, int bytes, off_t off);
+
#endif
diff --git a/pipes.c b/pipes.c
index 7a2c6a2..6378ecb 100644
--- a/pipes.c
+++ b/pipes.c
@@ -124,28 +124,24 @@ void mark_pipe_master(void)
handle_pipes_data();
}
-static int restore_pipe_data(int pfd, struct pipe_info *pi)
+int restore_pipe_data(int img, int pfd, u32 id, int bytes, off_t off)
{
- int fd, size = 0, ret;
+ int size = 0, ret;
- fd = open_image_ro(CR_FD_PIPES_DATA);
- if (fd < 0)
- return -1;
+ lseek(img, off, SEEK_SET);
- lseek(fd, pi->off, SEEK_SET);
+ pr_info("\t\tSplicing data size=%d off=%ld\n", bytes, off);
- pr_info("\t\tSplicing data size=%d off=%ld\n", pi->bytes, pi->off);
-
- while (size != pi->bytes) {
- ret = splice(fd, NULL, pfd, NULL, pi->bytes - size, 0);
+ while (size != bytes) {
+ ret = splice(img, NULL, pfd, NULL, bytes - size, 0);
if (ret < 0) {
- pr_perror("%#x: Error splicing data", pi->pe.id);
+ pr_perror("%#x: Error splicing data", id);
goto err;
}
if (ret == 0) {
pr_err("%#x: Wanted to restore %d bytes, but got %d\n",
- pi->pe.id, pi->bytes, size);
+ id, bytes, size);
ret = -1;
goto err;
}
@@ -155,7 +151,6 @@ static int restore_pipe_data(int pfd, struct pipe_info *pi)
ret = 0;
err:
- close(fd);
return ret;
}
@@ -194,7 +189,7 @@ static int recv_pipe_fd(struct pipe_info *pi)
static int open_pipe(struct file_desc *d)
{
struct pipe_info *pi, *p;
- int ret, tmp;
+ int ret, tmp, img;
int pfd[2];
int sock;
@@ -210,9 +205,13 @@ static int open_pipe(struct file_desc *d)
return -1;
}
- ret = restore_pipe_data(pfd[1], pi);
+ img = open_image_ro(CR_FD_PIPES_DATA);
+ if (img < 0)
+ return -1;
+ ret = restore_pipe_data(img, pfd[1], pi->pe.id, pi->bytes, pi->off);
if (ret)
return -1;
+ close(img);
sock = socket(PF_UNIX, SOCK_DGRAM, 0);
if (sock < 0) {
@@ -304,7 +303,7 @@ int collect_pipes(void)
static u32 pipes_with_data[1024]; /* pipes for which data already dumped */
static int nr_pipes;
-static int dump_one_pipe_data(int lfd, u32 id, const struct fd_parms *p)
+int dump_one_pipe_data(int img, int lfd, u32 id, const struct fd_parms *p)
{
int pipe_size, i, bytes;
int steal_pipe[2];
@@ -342,7 +341,6 @@ static int dump_one_pipe_data(int lfd, u32 id, const struct fd_parms *p)
bytes = tee(lfd, steal_pipe[1], pipe_size, SPLICE_F_NONBLOCK);
if (bytes > 0) {
- int fd_pipes_data = fdset_fd(glob_fdset, CR_FD_PIPES_DATA);
struct pipe_data_entry pde;
int wrote;
@@ -353,7 +351,7 @@ static int dump_one_pipe_data(int lfd, u32 id, const struct fd_parms *p)
if (bytes > PIPE_MAX_NONALIG_SIZE) {
off_t off;
- off = lseek(fd_pipes_data, 0, SEEK_CUR);
+ off = lseek(img, 0, SEEK_CUR);
off += sizeof(pde);
off &= ~PAGE_MASK;
@@ -363,14 +361,14 @@ static int dump_one_pipe_data(int lfd, u32 id, const struct fd_parms *p)
pr_info("\toff %#lx %#x bytes %#x\n", off, pde.off, bytes);
}
- if (write_img(fd_pipes_data, &pde))
+ if (write_img(img, &pde))
goto err_close;
/* Don't forget to advance position if a hole needed */
if (pde.off)
- lseek(fd_pipes_data, pde.off, SEEK_CUR);
+ lseek(img, pde.off, SEEK_CUR);
- wrote = splice(steal_pipe[0], NULL, fd_pipes_data, NULL, bytes, 0);
+ wrote = splice(steal_pipe[0], NULL, img, NULL, bytes, 0);
if (wrote < 0) {
pr_perror("Can't push pipe data");
goto err_close;
@@ -396,6 +394,7 @@ err:
static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p)
{
+ int fd_pipes_data = fdset_fd(glob_fdset, CR_FD_PIPES_DATA);
struct pipe_entry pe;
pr_info("Dumping pipe %d with id %#x pipe_id %#x\n",
@@ -409,7 +408,7 @@ static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p)
if (write_img(fdset_fd(glob_fdset, CR_FD_PIPES), &pe))
return -1;
- return dump_one_pipe_data(lfd, id, p);
+ return dump_one_pipe_data(fd_pipes_data, lfd, id, p);
}
static const struct fdtype_ops pipe_ops = {
--
1.7.7.6
More information about the CRIU
mailing list