[CRIU] [PATCH 6/6] pipe/fifo: Collect data via cinfo engine

Pavel Emelyanov xemul at virtuozzo.com
Thu Mar 24 06:02:13 PDT 2016


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-restore.c    |  7 ++----
 criu/fifo.c          | 11 +++++++--
 criu/include/fifo.h  |  2 +-
 criu/include/pipes.h |  5 +++--
 criu/pipes.c         | 63 ++++++++++++++++++++--------------------------------
 5 files changed, 39 insertions(+), 49 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c7cf822..02c4314 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -182,6 +182,8 @@ static struct collect_image_info *cinfos[] = {
 	&ext_file_cinfo,
 	&timerfd_cinfo,
 	&file_locks_cinfo,
+	&pipe_data_cinfo,
+	&fifo_data_cinfo,
 	&sk_queues_cinfo,
 };
 
@@ -243,11 +245,6 @@ static int root_prepare_shared(void)
 			return -1;
 	}
 
-	if (collect_pipes())
-		return -1;
-	if (collect_fifo())
-		return -1;
-
 	if (tty_verify_active_pairs())
 		return -1;
 
diff --git a/criu/fifo.c b/criu/fifo.c
index 9da5a27..68f55b4 100644
--- a/criu/fifo.c
+++ b/criu/fifo.c
@@ -162,7 +162,14 @@ struct collect_image_info fifo_cinfo = {
 	.collect = collect_one_fifo,
 };
 
-int collect_fifo(void)
+static int collect_fifo_data(void *obj, ProtobufCMessage *msg, struct cr_img *img)
 {
-	return collect_pipe_data(CR_FD_FIFO_DATA, pd_hash_fifo);
+	return do_collect_pipe_data(obj, msg, img, pd_hash_fifo);
 }
+
+struct collect_image_info fifo_data_cinfo = {
+	.fd_type = CR_FD_FIFO_DATA,
+	.pb_type = PB_PIPE_DATA,
+	.priv_size = sizeof(struct pipe_data_rst),
+	.collect = collect_fifo_data,
+};
diff --git a/criu/include/fifo.h b/criu/include/fifo.h
index 7762654..9560a7b 100644
--- a/criu/include/fifo.h
+++ b/criu/include/fifo.h
@@ -6,6 +6,6 @@ struct cr_imgset;
 
 extern const struct fdtype_ops fifo_dump_ops;
 extern struct collect_image_info fifo_cinfo;
-extern int collect_fifo(void);
+extern struct collect_image_info fifo_data_cinfo;
 
 #endif /* __CR_FIFO_H__ */
diff --git a/criu/include/pipes.h b/criu/include/pipes.h
index b46be2d..a16069b 100644
--- a/criu/include/pipes.h
+++ b/criu/include/pipes.h
@@ -5,7 +5,7 @@
 #include "images/pipe.pb-c.h"
 
 extern struct collect_image_info pipe_cinfo;
-extern int collect_pipes(void);
+extern struct collect_image_info pipe_data_cinfo;
 extern const struct fdtype_ops pipe_dump_ops;
 
 static inline u32 pipe_id(const struct fd_parms *p)
@@ -33,7 +33,8 @@ struct pipe_data_rst {
 #define PIPE_DATA_HASH_SIZE	(1 << PIPE_DATA_HASH_BITS)
 #define PIPE_DATA_HASH_MASK	(PIPE_DATA_HASH_SIZE - 1)
 
-extern int collect_pipe_data(int img_type, struct pipe_data_rst **hash);
+extern int do_collect_pipe_data(struct pipe_data_rst *,
+		ProtobufCMessage *, struct cr_img *, struct pipe_data_rst **hash);
 extern int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash);
 
 /*
diff --git a/criu/pipes.c b/criu/pipes.c
index d5a760d..fa59071 100644
--- a/criu/pipes.c
+++ b/criu/pipes.c
@@ -54,44 +54,22 @@ static int pipe_data_read(struct cr_img *img, struct pipe_data_rst *r)
 	return read_img_buf(img, r->data, bytes);
 }
 
-int collect_pipe_data(int img_type, struct pipe_data_rst **hash)
+int do_collect_pipe_data(struct pipe_data_rst *r, ProtobufCMessage *msg,
+		struct cr_img *img, struct pipe_data_rst **hash)
 {
-	int ret;
-	struct cr_img *img;
-	struct pipe_data_rst *r = NULL;
-
-	img = open_image(img_type, O_RSTR);
-	if (!img)
-		return -1;
-
-	while (1) {
-		ret = -1;
-		r = xmalloc(sizeof(*r));
-		if (!r)
-			break;
-
-		ret = pb_read_one_eof(img, &r->pde, PB_PIPE_DATA);
-		if (ret <= 0)
-			break;
-
-		ret = pipe_data_read(img, r);
-		if (ret < 0)
-			break;
-
-		ret = r->pde->pipe_id & PIPE_DATA_HASH_MASK;
-		r->next = hash[ret];
-		hash[ret] = r;
-
-		pr_info("Collected pipe data for %#x (chain %u)\n",
-				r->pde->pipe_id, ret);
-	}
-
-	if (r && r->pde)
-		pipe_data_entry__free_unpacked(r->pde, NULL);
-	xfree(r);
-
-	close_image(img);
-	return ret;
+	int aux;
+
+	r->pde = pb_msg(msg, PipeDataEntry);
+	aux = pipe_data_read(img, r);
+	if (aux < 0)
+		return aux;
+
+	aux = r->pde->pipe_id & PIPE_DATA_HASH_MASK;
+	r->next = hash[aux];
+	hash[aux] = r;
+	pr_info("Collected pipe data for %#x (chain %u)\n",
+			r->pde->pipe_id, aux);
+	return 0;
 }
 
 /* Choose who will restore a pipe. */
@@ -418,11 +396,18 @@ struct collect_image_info pipe_cinfo = {
 	.collect = collect_one_pipe,
 };
 
-int collect_pipes(void)
+static int collect_pipe_data(void *obj, ProtobufCMessage *msg, struct cr_img *img)
 {
-	return collect_pipe_data(CR_FD_PIPES_DATA, pd_hash_pipes);
+	return do_collect_pipe_data(obj, msg, img, pd_hash_pipes);
 }
 
+struct collect_image_info pipe_data_cinfo = {
+	.fd_type = CR_FD_PIPES_DATA,
+	.pb_type = PB_PIPE_DATA,
+	.priv_size = sizeof(struct pipe_data_rst),
+	.collect = collect_pipe_data,
+};
+
 int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms *p)
 {
 	struct cr_img *img;
-- 
2.5.0



More information about the CRIU mailing list