[CRIU] [PATCH v3 1/8] dump: hide pararms id set into read_fd_params()

Kinsbursky Stanislav skinsbursky at openvz.org
Mon Mar 5 13:00:43 EST 2012


This is a cleanup patch - let's do all params tasks in one place.

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

---
 cr-dump.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index c4d62fe..87c9f2e 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -287,7 +287,7 @@ err:
 	return ret;
 }
 
-static int read_fd_params(pid_t pid, char *fd, struct fd_parms *p)
+static int read_fd_params(pid_t pid, char *fd, struct stat *fd_stat, struct fd_parms *p)
 {
 	FILE *file;
 	int ret;
@@ -310,7 +310,15 @@ static int read_fd_params(pid_t pid, char *fd, struct fd_parms *p)
 
 	p->pid	= pid;
 	p->id	= FD_ID_INVALID;
-
+	p->type = 0;
+
+	switch (fd_stat->st_mode & S_IFMT) {
+	case S_IFREG:
+	case S_IFDIR:
+	case S_IFCHR:
+		p->id = MAKE_FD_GENID(fd_stat->st_dev, fd_stat->st_ino, p->pos);
+		p->type = FDINFO_FD;
+	}
 	return 0;
 }
 
@@ -322,16 +330,13 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
 	struct fd_parms p;
 	int lfd;
 
-	if (read_fd_params(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, atoi(d_name), 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/%s", pid_fd_dir, d_name);
 		return -1;
 	}
 
@@ -340,6 +345,9 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
 		goto out_close;
 	}
 
+	if (read_fd_params(pid, d_name, &fd_stat, &p))
+		return -1;
+
 	if (S_ISCHR(fd_stat.st_mode) &&
 	    (major(fd_stat.st_rdev) == TTY_MAJOR ||
 	     major(fd_stat.st_rdev) == UNIX98_PTY_SLAVE_MAJOR)) {
@@ -355,13 +363,8 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
 
 	if (S_ISREG(fd_stat.st_mode) ||
 	    S_ISDIR(fd_stat.st_mode) ||
-	    (S_ISCHR(fd_stat.st_mode) && major(fd_stat.st_rdev) == MEM_MAJOR)) {
-
-		p.id = MAKE_FD_GENID(fd_stat.st_dev, fd_stat.st_ino, p.pos);
-		p.type = FDINFO_FD;
-
+	    (S_ISCHR(fd_stat.st_mode) && major(fd_stat.st_rdev) == MEM_MAJOR))
 		return dump_one_reg_file(&p, lfd, cr_fdset, 1);
-	}
 
 	if (S_ISFIFO(fd_stat.st_mode))
 		return dump_one_pipe(&p, fd_stat.st_ino, lfd, cr_fdset);



More information about the CRIU mailing list