[CRIU] Re: [RFC] sa_entry converted

Cyrill Gorcunov gorcunov at openvz.org
Tue Jul 17 12:21:05 EDT 2012


On Tue, Jul 17, 2012 at 06:50:31PM +0400, Cyrill Gorcunov wrote:
> Guys, what do you thing on the patch enveloped?
> I mean about the approach.

Here the same for itimer_entry (note I've fixed a nit
in sa_entry patch, so if approach will be fine for you
guys, i'll resend these patches).

	Cyrill
-------------- next part --------------
>From cae2d201b39fa587bd7ac5fbf74fd3ac7b28ff8f Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Tue, 17 Jul 2012 19:53:01 +0400
Subject: [PATCH 2/2] protobuf: Convert itimer_entry to PB format

Similar to sa_entry we use PB ABI here in parasite code.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-restore.c           |   38 ++++++++++++++++++++++++++------------
 cr-show.c              |   26 ++++++++++++++++++++------
 include/image.h        |    7 -------
 include/protobuf-abi.h |   19 +++++++++++++++++++
 parasite.c             |    4 ++--
 protobuf/Makefile      |    1 +
 protobuf/itimer.proto  |    9 +++++++++
 7 files changed, 77 insertions(+), 27 deletions(-)
 create mode 100644 protobuf/itimer.proto

diff --git a/cr-restore.c b/cr-restore.c
index e96f741..6e46b8d 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -51,6 +51,7 @@
 
 #include "protobuf.h"
 #include "protobuf/sa.pb-c.h"
+#include "protobuf/itimer.pb-c.h"
 
 static struct pstree_item *me;
 
@@ -937,7 +938,7 @@ static inline int timeval_valid(struct timeval *tv)
 	return (tv->tv_sec >= 0) && ((unsigned long)tv->tv_usec < USEC_PER_SEC);
 }
 
-static inline int itimer_restore_and_fix(char *n, struct itimer_entry *ie,
+static inline int itimer_restore_and_fix(char *n, ItimerEntry *ie,
 		struct itimerval *val)
 {
 	if (ie->isec == 0 && ie->iusec == 0) {
@@ -980,23 +981,36 @@ static inline int itimer_restore_and_fix(char *n, struct itimer_entry *ie,
 static int prepare_itimers(int pid, struct task_restore_core_args *args)
 {
 	int fd, ret = -1;
-	struct itimer_entry ie[3];
+	ItimerEntry *ie;
 
 	fd = open_image_ro(CR_FD_ITIMERS, pid);
 	if (fd < 0)
 		return fd;
 
-	if (read_img_buf(fd, ie, sizeof(ie)) > 0) {
-		ret = itimer_restore_and_fix("real",
-				&ie[0], &args->itimers[0]);
-		if (!ret)
-			ret = itimer_restore_and_fix("virt",
-					&ie[1], &args->itimers[1]);
-		if (!ret)
-			ret = itimer_restore_and_fix("prof",
-					&ie[2], &args->itimers[2]);
-	}
+	ret = pb_read(fd, &ie, itimer_entry);
+	if (ret < 0)
+		goto out;
+	ret = itimer_restore_and_fix("real", ie, &args->itimers[0]);
+	itimer_entry__free_unpacked(ie, NULL);
+	if (ret < 0)
+		goto out;
 
+	ret = pb_read(fd, &ie, itimer_entry);
+	if (ret < 0)
+		goto out;
+	ret = itimer_restore_and_fix("virt", ie, &args->itimers[1]);
+	itimer_entry__free_unpacked(ie, NULL);
+	if (ret < 0)
+		goto out;
+
+	ret = pb_read(fd, &ie, itimer_entry);
+	if (ret < 0)
+		goto out;
+	ret = itimer_restore_and_fix("prof", ie, &args->itimers[2]);
+	itimer_entry__free_unpacked(ie, NULL);
+	if (ret < 0)
+		goto out;
+out:
 	close_safe(&fd);
 	return ret;
 }
diff --git a/cr-show.c b/cr-show.c
index b7281bc..d15bf10 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -36,6 +36,7 @@
 #include "protobuf/pipe.pb-c.h"
 #include "protobuf/pipe-data.pb-c.h"
 #include "protobuf/sa.pb-c.h"
+#include "protobuf/itimer.pb-c.h"
 
 #define DEF_PAGES_PER_LINE	6
 
@@ -376,7 +377,7 @@ out:
 	pr_img_tail(CR_FD_SIGACT);
 }
 
-static void show_itimer(char *n, struct itimer_entry *ie)
+static void show_itimer(char *n, ItimerEntry *ie)
 {
 	pr_msg("%s: int %lu.%lu val %lu.%lu\n", n,
 	       (unsigned long)ie->isec, (unsigned long)ie->iusec,
@@ -385,15 +386,28 @@ static void show_itimer(char *n, struct itimer_entry *ie)
 
 void show_itimers(int fd, struct cr_options *o)
 {
-	struct itimer_entry ie[3];
+	ItimerEntry *ie;
+	int ret;
 
 	pr_img_head(CR_FD_ITIMERS);
-	if (read_img_buf(fd, ie, sizeof(ie)) < 0)
+
+	ret = pb_read(fd, &ie, itimer_entry);
+	if (ret < 0)
 		goto out;
+	show_itimer("real", ie);
+	itimer_entry__free_unpacked(ie, NULL);
 
-	show_itimer("real", &ie[0]);
-	show_itimer("virt", &ie[1]);
-	show_itimer("prof", &ie[2]);
+	ret = pb_read(fd, &ie, itimer_entry);
+	if (ret < 0)
+		goto out;
+	show_itimer("virt", ie);
+	itimer_entry__free_unpacked(ie, NULL);
+
+	ret = pb_read(fd, &ie, itimer_entry);
+	if (ret < 0)
+		goto out;
+	show_itimer("prof", ie);
+	itimer_entry__free_unpacked(ie, NULL);
 out:
 	pr_img_tail(CR_FD_ITIMERS);
 }
diff --git a/include/image.h b/include/image.h
index f13c839..1841b02 100644
--- a/include/image.h
+++ b/include/image.h
@@ -103,13 +103,6 @@ struct page_entry {
 	u8	data[PAGE_IMAGE_SIZE];
 } __packed;
 
-struct itimer_entry {
-	u64		isec;
-	u64		iusec;
-	u64		vsec;
-	u64		vusec;
-} __packed;
-
 #define CR_CAP_SIZE	2
 
 struct creds_entry {
diff --git a/include/protobuf-abi.h b/include/protobuf-abi.h
index eae6277..33b6727 100644
--- a/include/protobuf-abi.h
+++ b/include/protobuf-abi.h
@@ -33,4 +33,23 @@ struct pb_sa_entry {
 	.__tag_pad_4	= (4 << 3) | CR_PB_U64,		\
 }
 
+struct pb_itimer_entry {
+	u8		__tag_pad_1;
+	u64	isec;
+	u8		__tag_pad_2;
+	u64	iusec;
+	u8		__tag_pad_3;
+	u64	vsec;
+	u8		__tag_pad_4;
+	u64	vusec;
+} __packed;
+
+#define PB_ITIMER_ENTRY__INIT				\
+{							\
+	.__tag_pad_1	= (1 << 3) | CR_PB_U64,		\
+	.__tag_pad_2	= (2 << 3) | CR_PB_U64,		\
+	.__tag_pad_3	= (3 << 3) | CR_PB_U64,		\
+	.__tag_pad_4	= (4 << 3) | CR_PB_U64,		\
+}
+
 #endif /* PROTOBUF_ABI_H__ */
diff --git a/parasite.c b/parasite.c
index a8af63b..4ee3b0d 100644
--- a/parasite.c
+++ b/parasite.c
@@ -319,7 +319,7 @@ static int dump_itimer(int which, int fd)
 {
 	struct itimerval val;
 	int ret;
-	struct itimer_entry ie;
+	struct pb_itimer_entry ie = PB_ITIMER_ENTRY__INIT;
 
 	ret = sys_getitimer(which, &val);
 	if (ret < 0) {
@@ -332,7 +332,7 @@ static int dump_itimer(int which, int fd)
 	ie.vsec = val.it_value.tv_sec;
 	ie.vusec = val.it_value.tv_sec;
 
-	ret = sys_write_safe(fd, &ie, sizeof(ie));
+	ret = __pb_write_object_with_header(fd, &ie, sizeof(ie));
 	if (ret)
 		return ret;
 
diff --git a/protobuf/Makefile b/protobuf/Makefile
index 5c1636b..d347629 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -45,6 +45,7 @@ PROTO_FILES	+= ipc-shm.proto
 PROTO_FILES	+= ipc-msg.proto
 PROTO_FILES	+= ipc-sem.proto
 PROTO_FILES	+= sa.proto
+PROTO_FILES	+= itimer.proto
 
 HDRS	:= $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
 SRCS	:= $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
diff --git a/protobuf/itimer.proto b/protobuf/itimer.proto
new file mode 100644
index 0000000..969c7c6
--- /dev/null
+++ b/protobuf/itimer.proto
@@ -0,0 +1,9 @@
+/*
+ * Don't forget to update protobuf-abi.h if change the message
+ */
+message itimer_entry {
+	required fixed64	isec		= 1;
+	required fixed64	iusec		= 2;
+	required fixed64	vsec		= 3;
+	required fixed64	vusec		= 4;
+}
-- 
1.7.7.6



More information about the CRIU mailing list