[CRIU] Re: [PATCH 1/8] protobuf: Convert struct pipe_data_entry to PB engine

Cyrill Gorcunov gorcunov at openvz.org
Tue Jul 17 06:43:02 EDT 2012


On Tue, Jul 17, 2012 at 02:28:56PM +0400, Cyrill Gorcunov wrote:
> On Tue, Jul 17, 2012 at 02:23:01PM +0400, Pavel Emelyanov wrote:
> > >> There will be a xfree(r->pde) on EOF. Why doesn't it crash?
> > > 
> > > it'll be xfree(NULL) then (since pb_read sets r->pde = NULL).
> > 
> > If pipe_data_read fails this will be non NULL :\
> 
> crap, indeed, will fix, thanks!

Fix enveloped.

	Cyrill
-------------- next part --------------
>From 66b5c9b9c3b234865399895a539f357cab30337f Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Tue, 10 Jul 2012 19:52:20 +0400
Subject: [PATCH] protobuf: Convert struct pipe_data_entry to PB engine

Note, at moment we don't use "data" from proto declaration,
it's reserved to implement later (simply because it's easier
to use current code for a while).

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-show.c                |   10 ++++++----
 include/image.h          |    6 ------
 include/pipes.h          |    5 ++++-
 pipes.c                  |   17 +++++++----------
 protobuf/Makefile        |    1 +
 protobuf/pipe-data.proto |    4 ++++
 6 files changed, 22 insertions(+), 21 deletions(-)
 create mode 100644 protobuf/pipe-data.proto

diff --git a/cr-show.c b/cr-show.c
index 3b5b5cb..8bdfd31 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -34,6 +34,7 @@
 #include "protobuf/fs.pb-c.h"
 #include "protobuf/pstree.pb-c.h"
 #include "protobuf/pipe.pb-c.h"
+#include "protobuf/pipe-data.pb-c.h"
 
 #define DEF_PAGES_PER_LINE	6
 
@@ -185,13 +186,14 @@ void show_ghost_file(int fd, struct cr_options *o)
 
 void __show_pipes_data(int fd, struct cr_options *o)
 {
-	struct pipe_data_entry e;
+	PipeDataEntry *e;
 
 	while (1) {
-		if (read_img_eof(fd, &e) <= 0)
+		if (pb_read_eof(fd, &e, pipe_data_entry) <= 0)
 			break;
-		pr_msg("pipeid: 0x%8x bytes: 0x%8x\n", e.pipe_id, e.bytes);
-		lseek(fd, e.bytes, SEEK_CUR);
+		pr_msg("pipeid: 0x%8x bytes: 0x%8x\n", e->pipe_id, e->bytes);
+		lseek(fd, e->bytes, SEEK_CUR);
+		pipe_data_entry__free_unpacked(e, NULL);
 	}
 }
 
diff --git a/include/image.h b/include/image.h
index b0874b1..36d4f6c 100644
--- a/include/image.h
+++ b/include/image.h
@@ -75,12 +75,6 @@ typedef struct {
  */
 #define REMAP_GHOST	(1 << 31)
 
-struct pipe_data_entry {
-	u32	pipe_id;
-	u32	bytes;
-	u8	data[0];
-} __packed;
-
 #define USK_EXTERN	(1 << 0)
 
 struct sk_opts_entry {
diff --git a/include/pipes.h b/include/pipes.h
index d365b05..641d207 100644
--- a/include/pipes.h
+++ b/include/pipes.h
@@ -1,5 +1,8 @@
 #ifndef __CR_PIPES_H__
 #define __CR_PIPES_H__
+
+#include "../protobuf/pipe-data.pb-c.h"
+
 extern int collect_pipes(void);
 extern void mark_pipe_master(void);
 int dump_pipe(struct fd_parms *p, int lfd,
@@ -21,7 +24,7 @@ struct pipe_data_dump {
 extern int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms *p);
 
 struct pipe_data_rst {
-	struct pipe_data_entry	*pde;
+	PipeDataEntry		*pde;
 	void *data;
 	struct pipe_data_rst	*next;
 };
diff --git a/pipes.c b/pipes.c
index a78c5c6..22e0ea2 100644
--- a/pipes.c
+++ b/pipes.c
@@ -13,6 +13,7 @@
 
 #include "protobuf.h"
 #include "protobuf/pipe.pb-c.h"
+#include "protobuf/pipe-data.pb-c.h"
 
 /*
  * The sequence of objects which should be restored:
@@ -76,11 +77,8 @@ int collect_pipe_data(int img_type, struct pipe_data_rst **hash)
 		r = xmalloc(sizeof(*r));
 		if (!r)
 			break;
-		r->pde = xmalloc(sizeof(*r->pde));
-		if (!r->pde)
-			break;
 
-		ret = read_img_eof(fd, r->pde);
+		ret = pb_read_eof(fd, &r->pde, pipe_data_entry);
 		if (ret <= 0)
 			break;
 
@@ -96,10 +94,9 @@ int collect_pipe_data(int img_type, struct pipe_data_rst **hash)
 				r->pde->pipe_id, ret);
 	}
 
-	if (r) {
-		xfree(r->pde);
-		xfree(r);
-	}
+	if (r && r->pde)
+		pipe_data_entry__free_unpacked(r->pde, NULL);
+	xfree(r);
 
 	close(fd);
 	return ret;
@@ -394,13 +391,13 @@ 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) {
-		struct pipe_data_entry pde;
+		PipeDataEntry pde = PIPE_DATA_ENTRY__INIT;
 		int wrote;
 
 		pde.pipe_id	= pipe_id(p);
 		pde.bytes	= bytes;
 
-		if (write_img(img, &pde))
+		if (pb_write(img, &pde, pipe_data_entry))
 			goto err_close;
 
 		wrote = splice(steal_pipe[0], NULL, img, NULL, bytes, 0);
diff --git a/protobuf/Makefile b/protobuf/Makefile
index e0c48b5..4b7c520 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -35,6 +35,7 @@ PROTO_FILES	+= pipe.proto
 PROTO_FILES	+= tcp-stream.proto
 PROTO_FILES	+= sk-packet.proto
 PROTO_FILES	+= mnt.proto
+PROTO_FILES	+= pipe-data.proto
 
 HDRS	:= $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
 SRCS	:= $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
diff --git a/protobuf/pipe-data.proto b/protobuf/pipe-data.proto
new file mode 100644
index 0000000..6fe57d6
--- /dev/null
+++ b/protobuf/pipe-data.proto
@@ -0,0 +1,4 @@
+message pipe_data_entry {
+	required uint32	pipe_id		= 1;
+	required uint32	bytes		= 2;
+}
-- 
1.7.7.6



More information about the CRIU mailing list