[CRIU] [PATCH 26/28] dump: split dump of fd entry and file

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


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Vma file doesn't have fd entry.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-dump.c |   62 ++++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 33 insertions(+), 29 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 96cfe60..31f676f 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -87,16 +87,12 @@ err:
 	return ret;
 }
 
-static int dump_one_reg_file(struct file_entry *p, pid_t pid,
-			     int lfd, unsigned long target_fd,
-			     const struct cr_fdset *cr_fdset,
-			     bool do_close_lfd)
+static long dump_one_reg_file(struct file_entry *p, pid_t pid,
+			     int lfd, int target_fd,
+			     int reg_files_fd, bool do_close_lfd)
 {
-	struct fdinfo_entry e = { };
 	char fd_str[128];
 	int len;
-	int ret = -1;
-	struct fd_entry *fde = &e.fde;
 	struct stat fd_stat;
 	u8 new;
 	long id;
@@ -114,25 +110,16 @@ static int dump_one_reg_file(struct file_entry *p, pid_t pid,
 	}
 
 	big_buffer[len] = '\0';
-	pr_info("Dumping path for %lx fd via self %d [%s]\n",
-		target_fd, lfd, big_buffer);
 
 	if (do_close_lfd)
 		close(lfd);
 
-	fde->type	= p->type;
-	fde->fd		= (u32)target_fd;
-	fde->id		= FD_ID_INVALID;
-
 	p->id = MAKE_FD_GENID(fd_stat.st_dev, fd_stat.st_ino, p->pos);
 	id = file_collect(pid, target_fd, p, &new);
 	if (id < 0)
 		return id;
-
-	/* Now it might have completely new ID here */
-	fde->id = id;
-
 	if (new) {
+		p->id = id;
 		p->len = len;
 
 		pr_info("Dumping regular file: id %ld, pos %ld, "
@@ -142,21 +129,38 @@ static int dump_one_reg_file(struct file_entry *p, pid_t pid,
 			pr_info(" --> %s", big_buffer);
 		pr_info("\n");
 
-		if (write_img(cr_fdset->fds[CR_FD_REG_FILES], p))
+		if (write_img(reg_files_fd, p))
 			return -1;
-		if (write_img_buf(cr_fdset->fds[CR_FD_REG_FILES], big_buffer, len))
+		if (write_img_buf(reg_files_fd, big_buffer, p->len))
 			return -1;
 	}
+	return id;
+}
+
+static int dump_one_fdinfo(struct file_entry *p,
+			   pid_t pid, int lfd, int target_fd,
+			   const struct cr_fdset *cr_fdset)
+{
+	struct fdinfo_entry e = { };
+	int len;
+	long id;
+	struct fd_entry *fde = &e.fde;
+	u8 new;
 
-	if (fd_is_special(fde))
+	id = dump_one_reg_file(p, pid, lfd, target_fd,
+			       cr_fdset->fds[CR_FD_REG_FILES], 1);
+	if (id < 0)
 		return id;
 
-	pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
-		p->type, len, p->flags, p->pos, target_fd);
+	/* Now it might have completely new ID here */
+	fde->id		= id;
+	fde->type	= p->type;
+	fde->fd		= target_fd;
 
-	if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e))
-		return -1;
-	return 0;
+	pr_info("Dumping fdinfo: fd: %10d type: %2d id: %20ld\n",
+		e.fde.fd, e.fde.type, e.fde.id);
+
+	return write_img(cr_fdset->fds[CR_FD_FDINFO], &e);
 }
 
 static int dump_task_special_files(pid_t pid, const struct cr_fdset *cr_fdset)
@@ -173,7 +177,7 @@ static int dump_task_special_files(pid_t pid, const struct cr_fdset *cr_fdset)
 	fd = open_proc(pid, "cwd");
 	if (fd < 0)
 		return -1;
-	ret = dump_one_reg_file(&fe, pid, fd, 0, cr_fdset, 1);
+	ret = dump_one_fdinfo(&fe, pid, fd, 0, cr_fdset);
 	if (ret)
 		return ret;
 
@@ -186,7 +190,7 @@ static int dump_task_special_files(pid_t pid, const struct cr_fdset *cr_fdset)
 	fd = open_proc(pid, "exe");
 	if (fd < 0)
 		return -1;
-	return dump_one_reg_file(&fe, pid, fd, 0, cr_fdset, 1);
+	return dump_one_fdinfo(&fe, pid, fd, 0, cr_fdset);
 }
 
 static int dump_pipe_and_data(int lfd, struct pipe_entry *e,
@@ -352,7 +356,7 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, const char *d_name,
 
 		p.type = FDINFO_REG;
 
-		return dump_one_reg_file(&p, pid, lfd, target_fd, cr_fdset, 1);
+		return dump_one_fdinfo(&p, pid, lfd, target_fd, cr_fdset);
 	}
 
 	if (S_ISFIFO(fd_stat.st_mode))
@@ -475,7 +479,7 @@ static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
 	else
 		p.flags = O_RDONLY;
 
-	id = dump_one_reg_file(&p, pid, file_fd, vma->start, fdset, 0);
+	id = dump_one_reg_file(&p, pid, file_fd, vma->start, fdset->fds[CR_FD_REG_FILES], 0);
 	if (id < 0)
 		return -1;
 	vma->shmid = id;


More information about the CRIU mailing list