[CRIU] [PATCH 16/16] dump: use fd_params->type for cwd and exe magic

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Mar 1 12:58:05 EST 2012



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

---
 cr-dump.c       |   17 ++++++++++-------
 files.c         |    7 ++++---
 include/image.h |   12 ++++++------
 restorer.c      |    2 +-
 4 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index dc2fc14..50f71ef 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -145,16 +145,21 @@ static int dump_one_reg_file(struct fd_parms *p, struct cr_fdset *cr_fdset)
 	int ret;
 	int lfd;
 
-	switch ((unsigned long)p->fd_name) {
+	switch (p->type) {
 		case FDINFO_CWD:
 			snprintf(fd_str, sizeof(fd_str), "/proc/%d/cwd", p->pid);
 			break;
 		case FDINFO_EXE:
 			snprintf(fd_str, sizeof(fd_str), "/proc/%d/exe", p->pid);
 			break;
-		default:
+		case FDINFO_REG:
 			snprintf(fd_str, sizeof(fd_str), "/proc/%d/fd/%ld", p->pid, p->fd_name);
 			break;
+		case FDINFO_MAP:
+			BUG_ON(1);
+		default:
+			pr_err("%s: unknown fd type: %d\n", __func__, p->type);
+			return -1;
 	}
 	lfd = open(fd_str, O_RDONLY);
 	if (lfd < 0) {
@@ -173,10 +178,9 @@ static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)
 
 	/* Dump /proc/pid/cwd */
 	params = (struct fd_parms) {
-		.fd_name	= FDINFO_CWD,
 		.id		= FD_ID_INVALID,
 		.pid		= pid,
-		.type		= FDINFO_FD,
+		.type		= FDINFO_CWD,
 	};
 
 	ret = dump_one_reg_file(&params, cr_fdset);
@@ -185,10 +189,9 @@ static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)
 
 	/* Dump /proc/pid/exe */
 	params = (struct fd_parms) {
-		.fd_name	= FDINFO_EXE,
 		.id		= FD_ID_INVALID,
 		.pid		= pid,
-		.type		= FDINFO_FD,
+		.type		= FDINFO_EXE,
 	};
 
 	ret = dump_one_reg_file(&params, cr_fdset);
@@ -325,7 +328,7 @@ static int read_fd_params(pid_t pid, char *fd, struct stat *fd_stat, struct fd_p
 	p->type = 0;
 	if (S_ISREG(fd_stat->st_mode) || S_ISCHR(fd_stat->st_mode)) {
 		p->id = MAKE_FD_GENID(fd_stat->st_dev, fd_stat->st_ino, p->pos);
-		p->type = FDINFO_FD;
+		p->type = FDINFO_REG;
 	}
 	return 0;
 }
diff --git a/files.c b/files.c
index 6c3d8b3..4409878 100644
--- a/files.c
+++ b/files.c
@@ -403,7 +403,7 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta
 	pr_info("\t%d: Got fd for %lx type %d namelen %d users %d\n", pid,
 			(unsigned long)fe->addr, fe->type, fe->len, fi->users);
 
-	BUG_ON(fe->type != FDINFO_FD);
+	BUG_ON(fe->type != FDINFO_REG);
 
 
 	switch (state) {
@@ -431,11 +431,12 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
 
 	if (fe->type == FDINFO_MAP)
 		return open_fmap(pid, fe, fdinfo_fd);
-	if (fe->addr == FDINFO_CWD)
+	if (fe->type == FDINFO_CWD)
 		return restore_cwd(fe, fdinfo_fd);
-	if (fe->addr == FDINFO_EXE)
+	if (fe->type == FDINFO_EXE)
 		return restore_exe_early(fe, fdinfo_fd);
 
+	pr_info("%d: fe->type: %d\n", pid,  fe->type);
 	BUG_ON(1);
 	return -1;
 }
diff --git a/include/image.h b/include/image.h
index db4015f..52c909c 100644
--- a/include/image.h
+++ b/include/image.h
@@ -29,12 +29,12 @@
 
 #define PIPEFS_MAGIC	0x50495045
 
-#define FDINFO_FD	1
+#define FDINFO_REG	1
 #define FDINFO_MAP	2
 
 /* Specials */
-#define FDINFO_CWD	(-1ULL)
-#define FDINFO_EXE	(-2ULL)
+#define FDINFO_CWD	3
+#define FDINFO_EXE	4
 
 #define PAGE_IMAGE_SIZE	4096
 #define PAGE_RSS	1
@@ -51,9 +51,9 @@ struct fdinfo_entry {
 } __packed;
 
 #define fd_is_special(fe)		\
-	(((fe)->type != FDINFO_FD)  ||	\
-	 ((fe)->addr == FDINFO_CWD) ||	\
-	 ((fe)->addr == FDINFO_EXE))
+	(((fe)->type == FDINFO_MAP) ||	\
+	 ((fe)->type == FDINFO_CWD) ||	\
+	 ((fe)->type == FDINFO_EXE))
 
 struct shmem_entry {
 	u64	start;
diff --git a/restorer.c b/restorer.c
index 552f741..8b11f35 100644
--- a/restorer.c
+++ b/restorer.c
@@ -248,7 +248,7 @@ static long restore_self_exe_late(struct task_restore_core_args *args)
 			goto err;
 		}
 
-		if (fe.type == FDINFO_FD && fe.addr == FDINFO_EXE)
+		if (fe.type == FDINFO_EXE)
 			break;
 
 		if (fe.len)



More information about the CRIU mailing list