[CRIU] [PATCH] protobuf: add payload print support in generic show function

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Jul 26 04:43:37 EDT 2012


This patch also updates pipe data and sockets queues payload handlers to
output data in "-c" option was passed to crtools.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 cr-show.c          |   13 +++++++++----
 include/protobuf.h |   11 ++++++-----
 protobuf.c         |   11 +++++++----
 sk-queue.c         |   13 +++++++++----
 4 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/cr-show.c b/cr-show.c
index 24e52d8..fd573e1 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -81,16 +81,21 @@ void show_ghost_file(int fd, struct cr_options *o)
 	pb_show_vertical(fd, ghost_file_entry);
 }
 
-static void pipe_data_handler(int fd, void *obj)
+static void pipe_data_handler(int fd, void *obj, int show_pages_content)
 {
 	PipeDataEntry *e = obj;
-	pr_msg("\n");
-	print_image_data(fd, e->bytes);
+
+	if (show_pages_content) {
+		pr_msg("\n");
+		print_image_data(fd, e->bytes);
+	} else
+		lseek(fd, e->bytes, SEEK_CUR);
 }
 
 void show_pipes_data(int fd, struct cr_options *o)
 {
-	pb_show_plain_payload(fd, pipe_data_entry, pipe_data_handler);
+	pb_show_plain_payload(fd, pipe_data_entry,
+			pipe_data_handler, o->show_pages_content);
 }
 
 void show_pipes(int fd_pipes, struct cr_options *o)
diff --git a/include/protobuf.h b/include/protobuf.h
index 0958fb5..e13c3e4 100644
--- a/include/protobuf.h
+++ b/include/protobuf.h
@@ -60,22 +60,23 @@ extern int pb_write_object_with_header(int fd, void *obj,
 
 extern void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *d,
 		pb_unpack_t unpack, pb_free_t free, int single_entry,
-		void (*payload_hadler)(int fd, void *obj));
+		void (*payload_hadler)(int fd, void *obj, int flags),
+		int flags);
 
 /* Don't have objects at hands to also do typechecking here */
-#define pb_show_plain_payload(__fd, __proto_message_name, payload_hadler)		\
+#define pb_show_plain_payload(__fd, __proto_message_name, payload_hadler, flags)	\
 	do_pb_show_plain(__fd, &__proto_message_name##__descriptor,	\
 			(pb_unpack_t)__proto_message_name##__unpack,			\
 			(pb_free_t)__proto_message_name##__free_unpacked,		\
-			0, payload_hadler)
+			0, payload_hadler, flags)
 
 #define pb_show_plain(__fd, __proto_message_name)			\
-	pb_show_plain_payload(__fd, __proto_message_name, NULL)
+	pb_show_plain_payload(__fd, __proto_message_name, NULL, 0)
 
 #define pb_show_vertical(__fd, __proto_message_name)			\
 	do_pb_show_plain(__fd, &__proto_message_name##__descriptor,	\
 			(pb_unpack_t)__proto_message_name##__unpack,			\
 			(pb_free_t)__proto_message_name##__free_unpacked,		\
-			1, NULL)
+			1, NULL, 0)
 
 #endif /* PROTOBUF_H__ */
diff --git a/protobuf.c b/protobuf.c
index 42e836b..f5b5bd4 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -210,14 +210,17 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
 	}
 }
 
-static inline void pb_no_payload(int fd, void *obj) { }
+static inline void pb_no_payload(int fd, void *obj, int flags) { }
 
 void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
 		pb_unpack_t unpack, pb_free_t free, int single_entry,
-		void (*payload_hadler)(int fd, void *obj))
+		void (*payload_hadler)(int fd, void *obj, int flags),
+		int flags)
 {
 	pb_pr_ctl_t ctl = {NULL, single_entry, 0};
-	void (*handle_payload)(int fd, void *obj) = (payload_hadler) ? : pb_no_payload;
+	void (*handle_payload)(int fd, void *obj, int flags);
+
+	handle_payload = (payload_hadler) ? : pb_no_payload;
 
 	while (1) {
 		void *obj;
@@ -227,7 +230,7 @@ void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
 
 		ctl.arg = (void *)md;
 		pb_show_msg(obj, &ctl);
-		handle_payload(fd, obj);
+		handle_payload(fd, obj, flags);
 		free(obj, NULL);
 		if (single_entry)
 			break;
diff --git a/sk-queue.c b/sk-queue.c
index 55f3bf0..40b1438 100644
--- a/sk-queue.c
+++ b/sk-queue.c
@@ -168,16 +168,21 @@ err_brk:
 	return ret;
 }
 
-static void sk_queue_data_handler(int fd, void *obj)
+static void sk_queue_data_handler(int fd, void *obj, int show_pages_content)
 {
 	SkPacketEntry *e = obj;
-	pr_msg("\n");
-	print_image_data(fd, e->length);
+
+	if (show_pages_content) {
+		pr_msg("\n");
+		print_image_data(fd, e->length);
+	} else
+		lseek(fd, e->length, SEEK_CUR);
 }
 
 void show_sk_queues(int fd, struct cr_options *o)
 {
-	pb_show_plain_payload(fd, sk_packet_entry, sk_queue_data_handler);
+	pb_show_plain_payload(fd, sk_packet_entry,
+			sk_queue_data_handler, o->show_pages_content);
 }
 
 int restore_sk_queue(int fd, unsigned int peer_id)



More information about the CRIU mailing list