[CRIU] [PATCH 5/5] protobuf: Use RegFileEntry instead of reg_file_entry structure

Cyrill Gorcunov gorcunov at openvz.org
Wed Jul 4 14:05:59 EDT 2012


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 FownT 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

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-show.c           |   29 +++++++--------------
 fifo.c              |    4 ++-
 files-reg.c         |   66 ++++++++++++++++++++++++++++++++++-----------------
 include/files-reg.h |    6 ++--
 include/image.h     |    9 -------
 5 files changed, 60 insertions(+), 54 deletions(-)

diff --git a/cr-show.c b/cr-show.c
index b5f5a88..dd712da 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -27,6 +27,7 @@
 #include "protobuf.h"
 #include "protobuf/image.base.pb-c.h"
 #include "protobuf/fdinfo.pb-c.h"
+#include "protobuf/regfile.pb-c.h"
 
 #define DEF_PAGES_PER_LINE	6
 
@@ -110,34 +111,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 = pbimg_read_obj_eof(fd_reg_files, &rfe,
+					 OBJ_HDR__OBJ_TYPE__OBJ_REGFILE,
+					 reg_file_entry__unpack);
 		if (ret <= 0)
-			goto out;
+			break;
 
-		pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx ", rfe.id, rfe.flags, rfe.pos);
-		show_fown_cont(&rfe.fown);
+		pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx --> %s\n",
+		       rfe->id, rfe->flags, rfe->pos, rfe->name);
 
-		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);
-		}
-
-		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..9f0ac8d 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -12,6 +12,10 @@
 #include "list.h"
 #include "util.h"
 
+#include "protobuf.h"
+#include "protobuf/image.base.pb-c.h"
+#include "protobuf/regfile.pb-c.h"
+
 #include "files-reg.h"
 
 struct ghost_file {
@@ -161,7 +165,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 +294,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;
+	FownT fown = FOWN_T__INIT;
 
 	snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
 	len = readlink(fd_str, path, sizeof(path) - 1);
@@ -312,19 +317,25 @@ 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.len		= len;
+	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 pbimg_write_obj(rfd, &rfe,
+			       OBJ_HDR__OBJ_TYPE__OBJ_REGFILE,
+			       reg_file_entry__get_packed_size,
+			       reg_file_entry__pack);
 	return 0;
 }
 
@@ -344,6 +355,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 +376,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 +405,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 +433,28 @@ 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 = pbimg_read_obj_eof(fd, &rfe,
+					 OBJ_HDR__OBJ_TYPE__OBJ_REGFILE,
+					 reg_file_entry__unpack);
 		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;
-- 
1.7.7.6



More information about the CRIU mailing list