[CRIU] [PATCH 02/12] dump: new structure for migrating of regular files introduced

Kinsbursky Stanislav skinsbursky at openvz.org
Fri Mar 23 12:23:17 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

This structure will be used for migrating of regular files images.
Today this info is migrated as a part of fdinfo structure.

Moreover, this file_entry structure is now used instead of local fd_parms
structure.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-dump.c       |   81 +++++++++++++++++++++++--------------------------------
 include/image.h |    9 ++++++
 2 files changed, 43 insertions(+), 47 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 42d0c97..35c2887 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -87,17 +87,8 @@ err:
 	return ret;
 }
 
-struct fd_parms {
-	unsigned long	fd_name;
-	unsigned long	pos;
-	unsigned int	flags;
-	unsigned int	type;
-
-	u64		id;
-	pid_t		pid;
-};
-
-static int dump_one_reg_file(const struct fd_parms *p, int lfd,
+static int dump_one_reg_file(const struct file_entry *p, pid_t pid,
+			     int lfd, unsigned long target_fd,
 			     const struct cr_fdset *cr_fdset,
 			     bool do_close_lfd)
 {
@@ -115,7 +106,7 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
 
 	big_buffer[len] = '\0';
 	pr_info("Dumping path for %lx fd via self %d [%s]\n",
-		p->fd_name, lfd, big_buffer);
+		target_fd, lfd, big_buffer);
 
 	if (do_close_lfd)
 		close(lfd);
@@ -123,10 +114,10 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
 	e.len	= len;
 	e.flags = p->flags;
 	e.pos	= p->pos;
-	e.addr	= p->fd_name;
+	e.addr	= target_fd;
 
 	e.fde.type	= p->type;
-	e.fde.fd	= (u32)p->fd_name;
+	e.fde.fd	= (u32)target_fd;
 	e.fde.id	= FD_ID_INVALID;
 
 	if (likely(!fd_is_special(&e.fde))) {
@@ -138,7 +129,7 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
 		 */
 		BUILD_BUG_ON(sizeof(entry->u.key) != sizeof(e.fde.id));
 
-		entry = fd_id_entry_collect((u32)p->id, p->pid, p->fd_name);
+		entry = fd_id_entry_collect((u32)p->id, pid, target_fd);
 		if (!entry)
 			goto err;
 
@@ -147,7 +138,7 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
 	}
 
 	pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
-		p->type, len, p->flags, p->pos, p->fd_name);
+		p->type, len, p->flags, p->pos, target_fd);
 
 	if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e))
 		goto err;
@@ -161,34 +152,32 @@ err:
 
 static int dump_task_special_files(pid_t pid, const struct cr_fdset *cr_fdset)
 {
-	struct fd_parms params;
+	struct file_entry fe;
 	int fd, ret;
 
 	/* Dump /proc/pid/cwd */
-	params = (struct fd_parms) {
+	fe = (struct file_entry) {
 		.id		= FD_ID_INVALID,
-		.pid		= FD_PID_INVALID,
 		.type		= FDINFO_CWD,
 	};
 
 	fd = open_proc(pid, "cwd");
 	if (fd < 0)
 		return -1;
-	ret = dump_one_reg_file(&params, fd, cr_fdset, 1);
+	ret = dump_one_reg_file(&fe, FD_PID_INVALID, fd, 0, cr_fdset, 1);
 	if (ret)
 		return ret;
 
 	/* Dump /proc/pid/exe */
-	params = (struct fd_parms) {
+	fe = (struct file_entry) {
 		.id		= FD_ID_INVALID,
-		.pid		= FD_PID_INVALID,
 		.type		= FDINFO_EXE,
 	};
 
 	fd = open_proc(pid, "exe");
 	if (fd < 0)
 		return -1;
-	ret = dump_one_reg_file(&params, fd, cr_fdset, 1);
+	ret = dump_one_reg_file(&fe, FD_PID_INVALID, fd, 0, cr_fdset, 1);
 
 	return ret;
 }
@@ -248,7 +237,8 @@ err:
 	return ret;
 }
 
-static int dump_one_pipe(const struct fd_parms *p, unsigned int id, int lfd,
+static int dump_one_pipe(const struct file_entry *p, unsigned int id,
+			 int lfd, int target_fd,
 			 const struct cr_fdset *cr_fdset)
 {
 	struct pipe_entry e;
@@ -256,18 +246,18 @@ static int dump_one_pipe(const struct fd_parms *p, unsigned int id, int lfd,
 	struct statfs stfs_buf;
 
 	if (fstatfs(lfd, &stfs_buf) < 0) {
-		pr_perror("Can't fstatfs on %ld", p->fd_name);
+		pr_perror("Can't fstatfs on %d", lfd);
 		return -1;
 	}
 
 	if (stfs_buf.f_type != PIPEFS_MAGIC) {
-		pr_err("Dumping of FIFO's is not supported: %ld\n", p->fd_name);
+		pr_err("Dumping of FIFO's is not supported: %d\n", lfd);
 		return -1;
 	}
 
-	pr_info("Dumping pipe %ld/%x flags %x\n", p->fd_name, id, p->flags);
+	pr_info("Dumping pipe %d/%x flags %x\n", target_fd, id, p->flags);
 
-	e.fd		= p->fd_name;
+	e.fd		= target_fd;
 	e.pipeid	= id;
 	e.flags		= p->flags;
 
@@ -282,12 +272,12 @@ err:
 		pr_info("Dumped pipe: fd: %8x pipeid: %8x flags: %8x bytes: %8x\n",
 			e.fd, e.pipeid, e.flags, e.bytes);
 	else
-		pr_err("Dumping pipe %ld/%x flags %x\n", p->fd_name, id, p->flags);
+		pr_err("Dumping pipe %d/%x flags %x\n", target_fd, id, p->flags);
 
 	return ret;
 }
 
-static int read_fd_params(pid_t pid, const char *fd, struct fd_parms *p)
+static int fill_file_entry(pid_t pid, const char *fd, struct file_entry *p)
 {
 	FILE *file;
 	int ret;
@@ -296,7 +286,6 @@ static int read_fd_params(pid_t pid, const char *fd, struct fd_parms *p)
 	if (!file)
 		return -1;
 
-	p->fd_name = atoi(fd);
 	ret = fscanf(file, "pos:\t%li\nflags:\t%o\n", &p->pos, &p->flags);
 	fclose(file);
 
@@ -308,7 +297,6 @@ static int read_fd_params(pid_t pid, const char *fd, struct fd_parms *p)
 	pr_info("%d fdinfo %s: pos: %16lx flags: %16o\n",
 		pid, fd, p->pos, p->flags);
 
-	p->pid	= pid;
 	p->id	= FD_ID_INVALID;
 
 	return 0;
@@ -320,24 +308,25 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, const char *d_name,
 {
 	struct stat fd_stat;
 	int err = -1;
-	struct fd_parms p;
+	struct file_entry p;
 	int lfd;
+	int target_fd = atoi(d_name);
 
-	if (read_fd_params(pid, d_name, &p))
+	if (fill_file_entry(pid, d_name, &p))
 		return -1;
 
 	lfd = openat(pid_fd_dir, d_name, O_RDONLY);
 	if (lfd < 0) {
-		err = try_dump_socket(pid, p.fd_name, cr_fdset, sk_queue);
+		err = try_dump_socket(pid, target_fd, cr_fdset, sk_queue);
 		if (err != 1)
 			return err;
 
-		pr_perror("Failed to open %d/%ld", pid_fd_dir, p.fd_name);
+		pr_perror("Failed to open %d/%d", pid_fd_dir, target_fd);
 		return -1;
 	}
 
 	if (fstat(lfd, &fd_stat) < 0) {
-		pr_perror("Can't get stat on %ld", p.fd_name);
+		pr_perror("Can't get stat on %d", target_fd);
 		goto out_close;
 	}
 
@@ -345,10 +334,10 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, const char *d_name,
 	    (major(fd_stat.st_rdev) == TTY_MAJOR ||
 	     major(fd_stat.st_rdev) == UNIX98_PTY_SLAVE_MAJOR)) {
 		/* skip only standard destriptors */
-		if (p.fd_name < 3) {
+		if (target_fd < 3) {
 			err = 0;
-			pr_info("... Skipping tty ... %d/%ld\n",
-				pid_fd_dir, p.fd_name);
+			pr_info("... Skipping tty ... %d/%d\n",
+				pid_fd_dir, target_fd);
 			goto out_close;
 		}
 		goto err;
@@ -361,14 +350,14 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, const char *d_name,
 		p.id = MAKE_FD_GENID(fd_stat.st_dev, fd_stat.st_ino, p.pos);
 		p.type = FDINFO_REG;
 
-		return dump_one_reg_file(&p, lfd, cr_fdset, 1);
+		return dump_one_reg_file(&p, pid, lfd, target_fd, cr_fdset, 1);
 	}
 
 	if (S_ISFIFO(fd_stat.st_mode))
-		return dump_one_pipe(&p, fd_stat.st_ino, lfd, cr_fdset);
+		return dump_one_pipe(&p, fd_stat.st_ino, lfd, target_fd, cr_fdset);
 
 err:
-	pr_err("Can't dump file %ld of that type [%x]\n", p.fd_name, fd_stat.st_mode);
+	pr_err("Can't dump file %d of that type [%x]\n", target_fd, fd_stat.st_mode);
 
 out_close:
 	close_safe(&lfd);
@@ -473,10 +462,8 @@ static int add_shmem_area(pid_t pid, struct vma_entry *vma)
 static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
 		const struct cr_fdset *fdset)
 {
-	struct fd_parms p = {
-		.fd_name	= vma->start,
+	struct file_entry p = {
 		.id		= FD_ID_INVALID,
-		.pid		= pid,
 		.type		= FDINFO_MAP,
 	};
 
@@ -485,7 +472,7 @@ static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
 	else
 		p.flags = O_RDONLY;
 
-	return dump_one_reg_file(&p, file_fd, fdset, 0);
+	return dump_one_reg_file(&p, pid, file_fd, vma->start, fdset, 0);
 }
 
 static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
diff --git a/include/image.h b/include/image.h
index 6ff984a..bf77d77 100644
--- a/include/image.h
+++ b/include/image.h
@@ -46,6 +46,15 @@ struct fd_entry {
 	u8	type;
 } __packed;
 
+struct file_entry {
+	u64	id;
+	u64	pos;
+	u32	flags;
+	u8	type;
+	u8	len;
+	u8	name[0];
+} __packed;
+
 struct fdinfo_entry {
 	struct fd_entry fde;
 	u8	len;


More information about the CRIU mailing list