[CRIU] Re: [PATCH 4/4] protobuf: Use RegFileEntry instead of reg_file_entry structure v2

Cyrill Gorcunov gorcunov at openvz.org
Sat Jul 7 07:32:25 EDT 2012


On Sat, Jul 07, 2012 at 01:03:27AM +0400, Cyrill Gorcunov wrote:
> 
> This patch switches reg_file_entry structure with RegFileEntry
> protobuf entry. Note that there a few nits remains
> 
>  - old fown_t structure doesn't scale well with FownEntry from
>    RegFileEntry, so to not mess with rest of crtools code
>    I've added a couple of opencoded copy operands, will clean
>    this aspect up once rest of code is converted
> 
>  - the "show" procedure doesn't print fown for same reason
> 
> v2:
>  - rename fown_t to fown_entry in .proto

An updated one enveloped.

	Cyrill
-------------- next part --------------
>From 1e18fce93c9eed7dddd4c62a5456336f550be764 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Wed, 4 Jul 2012 20:38:54 +0400
Subject: [PATCH 5/5] protobuf: Use RegFileEntry instead of reg_file_entry
 structure v3
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.7.7.6"

This is a multi-part message in MIME format.
--------------1.7.7.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


This patch switches reg_file_entry structure with RegFileEntry
protobuf entry. Note that there a few nits remains

 - old fown_t structure doesn't scale well with FownEntry from
   RegFileEntry, so to not mess with rest of crtools code
   I've added a couple of opencoded copy operands, will clean
   this aspect up once rest of code is converted

 - the "show" procedure doesn't print fown for same reason

v2:
 - rename fown_t to fown_entry in .proto
v3:
 - don't print nil symbol on show

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-show.c              |   29 ++++++++---------------
 fifo.c                 |    4 ++-
 files-reg.c            |   60 +++++++++++++++++++++++++++++------------------
 include/files-reg.h    |    6 ++--
 include/image.h        |    9 -------
 protobuf/Makefile      |    2 +
 protobuf/fown.proto    |    7 +++++
 protobuf/regfile.proto |    9 +++++++
 8 files changed, 71 insertions(+), 55 deletions(-)
 create mode 100644 protobuf/fown.proto
 create mode 100644 protobuf/regfile.proto


--------------1.7.7.6
Content-Type: text/x-patch; name="0005-protobuf-Use-RegFileEntry-instead-of-reg_file_entry-.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0005-protobuf-Use-RegFileEntry-instead-of-reg_file_entry-.patch"

diff --git a/cr-show.c b/cr-show.c
index 88d350f..a925243 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -26,6 +26,7 @@
 
 #include "protobuf.h"
 #include "protobuf/fdinfo.pb-c.h"
+#include "protobuf/regfile.pb-c.h"
 
 #define DEF_PAGES_PER_LINE	6
 
@@ -104,34 +105,24 @@ void show_fown_cont(fown_t *fown)
 
 void show_reg_files(int fd_reg_files, struct cr_options *o)
 {
-	struct reg_file_entry rfe;
+	local_buf[0] = 0;
 
 	pr_img_head(CR_FD_REG_FILES);
-
 	while (1) {
+		RegFileEntry *rfe;
 		int ret;
 
-		ret = read_img_eof(fd_reg_files, &rfe);
+		ret = pb_read_eof(fd_reg_files, &rfe, reg_file_entry);
 		if (ret <= 0)
-			goto out;
-
-		pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx ", rfe.id, rfe.flags, rfe.pos);
-		show_fown_cont(&rfe.fown);
-
-		if (rfe.len) {
-			int ret = read(fd_reg_files, local_buf, rfe.len);
-			if (ret != rfe.len) {
-				pr_perror("Can't read %d bytes", rfe.len);
-				goto out;
-			}
-			local_buf[rfe.len] = 0;
-			pr_msg(" --> %s", local_buf);
-		}
+			break;
 
+		pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx",
+		       rfe->id, rfe->flags, rfe->pos);
+		if (rfe->name)
+			pr_msg(" --> %s", rfe->name);
 		pr_msg("\n");
+		reg_file_entry__free_unpacked(rfe, NULL);
 	}
-
-out:
 	pr_img_tail(CR_FD_REG_FILES);
 }
 
diff --git a/fifo.c b/fifo.c
index 22007c0..76f6fb9 100644
--- a/fifo.c
+++ b/fifo.c
@@ -12,6 +12,8 @@
 
 #include "fifo.h"
 
+#include "protobuf/regfile.pb-c.h"
+
 /*
  * FIFO checkpoint and restore is done in a bit unusual manner.
  * We use files-reg.c engine to save fifo path and flags,
@@ -89,7 +91,7 @@ static int do_open_fifo(struct reg_file_info *rfi, void *arg)
 		return -1;
 	}
 
-	new_fifo = open(rfi->path, rfi->rfe.flags);
+	new_fifo = open(rfi->path, rfi->rfe->flags);
 	if (new_fifo < 0) {
 		pr_perror("Can't open fifo %#x [%s]", info->fe.id, rfi->path);
 		goto out;
diff --git a/files-reg.c b/files-reg.c
index 0e38a78..66ced57 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -12,6 +12,9 @@
 #include "list.h"
 #include "util.h"
 
+#include "protobuf.h"
+#include "protobuf/regfile.pb-c.h"
+
 #include "files-reg.h"
 
 struct ghost_file {
@@ -161,7 +164,7 @@ static int collect_remaps(void)
 
 		rfe.remap_id &= ~REMAP_GHOST;
 		rfi = container_of(fdesc, struct reg_file_info, d);
-		pr_info("Configuring remap %#x -> %#x\n", rfi->rfe.id, rfe.remap_id);
+		pr_info("Configuring remap %#x -> %#x\n", rfi->rfe->id, rfe.remap_id);
 		ret = open_remap_ghost(rfi, &rfe);
 		if (ret < 0)
 			break;
@@ -290,13 +293,14 @@ static int check_path_remap(char *path, const struct stat *ost, int lfd, u32 id)
 	return 0;
 }
 
-
 int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 {
 	char fd_str[128];
 	char path[PATH_MAX];
 	int len, rfd;
-	struct reg_file_entry rfe;
+
+	RegFileEntry rfe = REG_FILE_ENTRY__INIT;
+	FownEntry fown = FOWN_ENTRY__INIT;
 
 	snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
 	len = readlink(fd_str, path, sizeof(path) - 1);
@@ -312,20 +316,21 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 	if (check_path_remap(path, &p->stat, lfd, id))
 		return -1;
 
-	rfe.len = len;
-	rfe.flags = p->flags;
-	rfe.pos = p->pos;
-	rfe.id = id;
-	rfe.fown = p->fown;
+	fown.uid	= p->fown.uid;
+	fown.euid	= p->fown.euid;
+	fown.signum	= p->fown.signum;
+	fown.pid_type	= p->fown.pid_type;
+	fown.pid	= p->fown.pid;
 
-	rfd = fdset_fd(glob_fdset, CR_FD_REG_FILES);
+	rfe.id		= id;
+	rfe.flags	= p->flags;
+	rfe.pos		= p->pos;
+	rfe.fown	= &fown;
+	rfe.name	= path;
 
-	if (write_img(rfd, &rfe))
-		return -1;
-	if (write_img_buf(rfd, path, len))
-		return -1;
+	rfd = fdset_fd(glob_fdset, CR_FD_REG_FILES);
 
-	return 0;
+	return pb_write(rfd, &rfe, reg_file_entry);
 }
 
 static const struct fdtype_ops regfile_ops = {
@@ -344,6 +349,7 @@ static int open_path(struct file_desc *d,
 		int(*open_cb)(struct reg_file_info *, void *), void *arg)
 {
 	struct reg_file_info *rfi;
+	fown_t fown;
 	int tmp;
 
 	rfi = container_of(d, struct reg_file_info, d);
@@ -364,9 +370,15 @@ static int open_path(struct file_desc *d,
 	if (rfi->remap_path)
 		unlink(rfi->path);
 
-	lseek(tmp, rfi->rfe.pos, SEEK_SET);
+	lseek(tmp, rfi->rfe->pos, SEEK_SET);
+
+	fown.uid	= rfi->rfe->fown->uid;
+	fown.euid	= rfi->rfe->fown->uid;
+	fown.signum	= rfi->rfe->fown->signum;
+	fown.pid_type	= rfi->rfe->fown->pid_type;
+	fown.pid	= rfi->rfe->fown->pid;
 
-	if (restore_fown(tmp, &rfi->rfe.fown))
+	if (restore_fown(tmp, &fown))
 		return -1;
 
 	return tmp;
@@ -387,7 +399,7 @@ int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void
 
 static int do_open_reg(struct reg_file_info *rfi, void *arg)
 {
-	return open(rfi->path, rfi->rfe.flags);
+	return open(rfi->path, rfi->rfe->flags);
 }
 
 static int open_fe_fd(struct file_desc *fd)
@@ -415,24 +427,26 @@ int collect_reg_files(void)
 		return -1;
 
 	while (1) {
+		RegFileEntry *rfe;
+
 		rfi = xmalloc(sizeof(*rfi));
 		ret = -1;
 		if (rfi == NULL)
 			break;
 
 		rfi->path = NULL;
-		ret = read_img_eof(fd, &rfi->rfe);
+
+		ret = pb_read_eof(fd, &rfe, reg_file_entry);
 		if (ret <= 0)
 			break;
 
-		ret = read_img_str(fd, &rfi->path, rfi->rfe.len);
-		if (ret < 0)
-			break;
+		rfi->rfe = rfe;
+		rfi->path = rfe->name;
 
 		rfi->remap_path = NULL;
 
-		pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe.id);
-		file_desc_add(&rfi->d, rfi->rfe.id, &reg_desc_ops);
+		pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe->id);
+		file_desc_add(&rfi->d, rfi->rfe->id, &reg_desc_ops);
 	}
 
 	if (rfi) {
diff --git a/include/files-reg.h b/include/files-reg.h
index 08d5170..2e1f6e9 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -5,14 +5,14 @@
 #include "files.h"
 #include "image.h"
 
+#include "../protobuf/regfile.pb-c.h"
+
 struct cr_fdset;
 struct fd_parms;
 
 struct reg_file_info {
 	struct file_desc	d;
-
-	struct reg_file_entry	rfe;
-
+	RegFileEntry		*rfe;
 	char			*remap_path;
 	char			*path;
 };
diff --git a/include/image.h b/include/image.h
index c522e25..8e5b764 100644
--- a/include/image.h
+++ b/include/image.h
@@ -69,15 +69,6 @@ typedef struct {
 	u32	pid;
 } __packed fown_t;
 
-struct reg_file_entry {
-	u32	id;
-	u16	flags;
-	u16	len;
-	u64	pos;
-	fown_t	fown;
-	u8	name[0];
-} __packed;
-
 struct remap_file_path_entry {
 	u32	orig_id;
 	u32	remap_id;
diff --git a/protobuf/Makefile b/protobuf/Makefile
index 324a962..c05755d 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -20,6 +20,8 @@ CFLAGS		+= $(WARNINGS) $(DEFINES)
 LIBRARY		:= protobuf-lib.o
 
 PROTO_FILES	+= fdinfo.proto
+PROTO_FILES	+= fown.proto
+PROTO_FILES	+= regfile.proto
 
 HDRS	:= $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
 SRCS	:= $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
diff --git a/protobuf/fown.proto b/protobuf/fown.proto
new file mode 100644
index 0000000..f83779e
--- /dev/null
+++ b/protobuf/fown.proto
@@ -0,0 +1,7 @@
+message fown_entry {
+	required uint32		uid		= 1;
+	required uint32		euid		= 2;
+	required uint32		signum		= 3;
+	required uint32		pid_type	= 4;
+	required uint32		pid		= 5;
+}
diff --git a/protobuf/regfile.proto b/protobuf/regfile.proto
new file mode 100644
index 0000000..d975ab0
--- /dev/null
+++ b/protobuf/regfile.proto
@@ -0,0 +1,9 @@
+import "fown.proto";
+
+message reg_file_entry {
+	required uint32		id	= 1;
+	required uint32		flags	= 2;
+	required uint64		pos	= 3;
+	required fown_entry	fown	= 5;
+	required string		name	= 6;
+}

--------------1.7.7.6--




More information about the CRIU mailing list