[CRIU] [PATCH v2 05/11] dump: use switch for dumping fd

Kinsbursky Stanislav skinsbursky at openvz.org
Mon Mar 5 07:38:32 EST 2012


This is a cleanup patch - switch over fd_stat.st_mode instead of silly if-else.

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

---
 cr-dump.c |   63 +++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 3a441f6..39590b7 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -337,39 +337,48 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
 		return -1;
 
 	lfd = openat(pid_fd_dir, d_name, O_RDONLY);
-	if (lfd < 0) {
-		err = try_dump_socket(pid, atoi(d_name), cr_fdset, sk_queue);
+
+	switch (fd_stat.st_mode & S_IFMT) {
+	case S_IFCHR:
+		if (major(fd_stat.st_rdev) != MEM_MAJOR) {
+			if ((major(fd_stat.st_rdev) == TTY_MAJOR) ||
+			    (major(fd_stat.st_rdev) == UNIX98_PTY_SLAVE_MAJOR)) {
+				/* skip only standard destriptors */
+				if (atoi(d_name) < 3) {
+					err = 0;
+					pr_info("... Skipping tty ... %d/%ld\n",
+						pid_fd_dir, p.fd_name);
+				}
+			}
+			break;
+		}
+		/*
+		 * This is a TMPFS file.
+		 * Proceed to dump_one_reg_file().
+		 */
+	case S_IFREG:
+		err = dump_one_reg_file(&p, lfd, cr_fdset, 0);
+		break;
+	case S_IFIFO:
+		err = dump_one_pipe(&p, lfd, cr_fdset);
+		break;
+	case S_IFSOCK:
+		err = try_dump_socket(pid, p.fd_name, cr_fdset, sk_queue);
 		if (err != 1)
 			return err;
 
 		pr_perror("Failed to open %d/%ld", pid_fd_dir, p.fd_name);
 		return -1;
+	case S_IFDIR:
+	case S_IFLNK:
+	case S_IFBLK:
+		break;
+	default:
+		pr_err("%s: unknown file type: %o\n", __func__, fd_stat.st_mode & S_IFMT);
+		break;
 	}
-
-	if (S_ISCHR(fd_stat.st_mode) &&
-	    (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) {
-			err = 0;
-			pr_info("... Skipping tty ... %d/%ld\n",
-				pid_fd_dir, p.fd_name);
-			goto out_close;
-		}
-		goto err;
-	}
-
-	if (S_ISREG(fd_stat.st_mode) ||
-	    (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, lfd, cr_fdset);
-
-err:
-	pr_err("Can't dump file %ld of that type [%x]\n", p.fd_name, fd_stat.st_mode);
-
-out_close:
+	if (err)
+		pr_err("Can't dump file %ld of that type [%x]\n", p.fd_name, fd_stat.st_mode);
 	close_safe(&lfd);
 	return err;
 }



More information about the CRIU mailing list