[CRIU] [PATCH 27/28] dump: remove redundant fd_entry structure

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Mar 22 14:00:33 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Now it's equash to fdinfo_entry structure.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-dump.c       |    9 ++++-----
 cr-restore.c    |    6 +++---
 cr-show.c       |    2 +-
 files.c         |   34 +++++++++++++++++-----------------
 include/image.h |   10 +++-------
 5 files changed, 28 insertions(+), 33 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 31f676f..71c3c02 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -144,7 +144,6 @@ static int dump_one_fdinfo(struct file_entry *p,
 	struct fdinfo_entry e = { };
 	int len;
 	long id;
-	struct fd_entry *fde = &e.fde;
 	u8 new;
 
 	id = dump_one_reg_file(p, pid, lfd, target_fd,
@@ -153,12 +152,12 @@ static int dump_one_fdinfo(struct file_entry *p,
 		return id;
 
 	/* Now it might have completely new ID here */
-	fde->id		= id;
-	fde->type	= p->type;
-	fde->fd		= target_fd;
+	e.id		= id;
+	e.type	= p->type;
+	e.fd		= target_fd;
 
 	pr_info("Dumping fdinfo: fd: %10d type: %2d id: %20ld\n",
-		e.fde.fd, e.fde.type, e.fde.id);
+		e.fd, e.type, e.id);
 
 	return write_img(cr_fdset->fds[CR_FD_FDINFO], &e);
 }
diff --git a/cr-restore.c b/cr-restore.c
index 1d16e57..795c167 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1532,13 +1532,13 @@ static char *restorer_get_exe_path(int pid)
 			pr_perror("%d: Bad fdinfo entry", pid);
 			goto err;
 		}
-		if (fe.fde.type == FDINFO_EXE)
+		if (fe.type == FDINFO_EXE)
 			break;
 	}
 
-	sfi = file_search(FDINFO_EXE, fe.fde.id);
+	sfi = file_search(FDINFO_EXE, fe.id);
 	if (sfi == NULL) {
-		pr_err("Failed to find exe with id %ld\n", fe.fde.id);
+		pr_err("Failed to find exe with id %ld\n", fe.id);
 		goto err;
 	}
 
diff --git a/cr-show.c b/cr-show.c
index 346bf2c..1d6421c 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -68,7 +68,7 @@ static void show_files(int fd_files)
 			goto out;
 
 		pr_msg("type: %02d id: %20ld fd: %d\n",
-		       e.fde.type, e.fde.id, e.fde.fd);
+		       e.type, e.id, e.fd);
 	}
 
 out:
diff --git a/files.c b/files.c
index 1f21b30..2d882cf 100644
--- a/files.c
+++ b/files.c
@@ -30,7 +30,7 @@ struct file_recipient {
 	u32			ready;
 };
 
-static int collect_fd_pid(int pid, struct fd_entry *fde)
+static int collect_fd_pid(int pid, const struct fdinfo_entry *fde)
 {
 	struct file_info *fi;
 	struct file_recipient *recipient;
@@ -40,7 +40,8 @@ static int collect_fd_pid(int pid, struct fd_entry *fde)
 
 	fi = file_search(fde->type, fde->id);
 	if (fi == NULL) {
-		pr_err("Failed to find shared file: type %d, id %ld\n\n", fde->type, fde->id);
+		pr_err("Failed to find shared file: type %d, id %ld\n\n",
+			fde->type, fde->id);
 		return -1;
 	}
 
@@ -141,17 +142,16 @@ int prepare_fd_pid(int pid)
 	}
 
 	while (1) {
-		struct fdinfo_entry e;
-		struct fd_entry *fde = &e.fde;
+		struct fdinfo_entry fde;
 
-		ret = read_img_eof(fdinfo_fd, &e);
+		ret = read_img_eof(fdinfo_fd, &fde);
 		if (ret <= 0)
 			break;
 
-		if (fd_is_special(fde))
+		if (fd_is_special(&fde))
 			continue;
 
-		ret = collect_fd_pid(pid, fde);
+		ret = collect_fd_pid(pid, &fde);
 		if (ret < 0)
 			break;
 	}
@@ -183,7 +183,7 @@ static int restore_cwd(int id)
 	return 0;
 }
 
-static int receive_shared_fd(int pid, struct file_info *fi, struct fd_entry *fde)
+static int receive_shared_fd(int pid, struct file_info *fi, struct fdinfo_entry *fde)
 {
 	int real_fd;
 
@@ -280,7 +280,7 @@ static int send_fd_to_recipients(struct file_info *fi)
 	return 0;
 }
 
-static int open_reg_file(struct file_info *fi, struct fd_entry *fde)
+static int open_reg_file(struct file_info *fi, struct fdinfo_entry *fde)
 {
 	const struct file_entry *rfe = fi->rfe;
 
@@ -307,7 +307,7 @@ static int open_reg_file(struct file_info *fi, struct fd_entry *fde)
 	return send_fd_to_recipients(fi);
 }
 
-static int open_fd_and_send(int pid, struct file_info *fi, struct fd_entry *fde)
+static int open_fd_and_send(int pid, struct file_info *fi, struct fdinfo_entry *fde)
 {
 	if (fi->pid != pid)
 		return 0;
@@ -321,7 +321,7 @@ static int open_fd_and_send(int pid, struct file_info *fi, struct fd_entry *fde)
 	return -1;
 }
 
-static int open_fd_transport(int pid, struct file_info *fi, struct fd_entry *fde)
+static int open_fd_transport(int pid, struct file_info *fi, struct fdinfo_entry *fde)
 {
 	if (fi->pid == pid)
 		return 0;
@@ -332,7 +332,7 @@ static int open_fd_transport(int pid, struct file_info *fi, struct fd_entry *fde
 	return open_transport(pid, fde->fd, fi);
 }
 
-static int open_fdinfo(int pid, struct fd_entry *fde, int *fdinfo_fd, int state)
+static int open_fdinfo(int pid, struct fdinfo_entry *fde, int *fdinfo_fd, int state)
 {
 	int ret;
 	struct file_info *fi;
@@ -396,23 +396,23 @@ int prepare_fds(int pid)
 				goto err;
 			}
 
-			if (fe.fde.type == FDINFO_CWD) {
-				cwd_id = fe.fde.id;
+			if (fe.type == FDINFO_CWD) {
+				cwd_id = fe.id;
 				continue;
 			}
-			if (fe.fde.type == FDINFO_EXE)
+			if (fe.type == FDINFO_EXE)
 				/*
 				 * We restore the EXE symlink at very late stage
 				 * because of restrictions applied from kernel side,
 				 * so simply skip it for a while.
 				 */
 				continue;
-			if (fe.fde.type == FDINFO_MAP)
+			if (fe.type == FDINFO_MAP)
 				continue;
 
 			offset = lseek(fdinfo_fd, 0, SEEK_CUR);
 
-			if (open_fdinfo(pid, &fe.fde, &fdinfo_fd, state))
+			if (open_fdinfo(pid, &fe, &fdinfo_fd, state))
 				goto err;
 		}
 	}
diff --git a/include/image.h b/include/image.h
index 62c6bac..5afbc1f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -45,12 +45,6 @@ enum fd_types {
 #define PAGE_RSS	1
 #define PAGE_ANON	2
 
-struct fd_entry {
-	u64	id;
-	u32	fd;
-	u8	type;
-} __packed;
-
 struct file_entry {
 	u64	id;
 	u64	pos;
@@ -61,7 +55,9 @@ struct file_entry {
 } __packed;
 
 struct fdinfo_entry {
-	struct fd_entry fde;
+	u64	id;
+	u32	fd;
+	u8	type;
 } __packed;
 
 #define fd_is_special(fde)	((fde)->type == FDINFO_MAP)


More information about the CRIU mailing list