[CRIU] [PATCH 15/16] dump: cleanup sockets dump

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Mar 1 12:57:58 EST 2012



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

---
 cr-dump.c         |   20 +++-----------------
 include/files.h   |   11 +++++++++++
 include/sockets.h |    3 ++-
 sockets.c         |   29 ++++++-----------------------
 4 files changed, 22 insertions(+), 41 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 299df6f..dc2fc14 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -32,6 +32,7 @@
 #include "image.h"
 #include "proc_parse.h"
 #include "parasite-syscall.h"
+#include "files.h"
 
 #ifndef CONFIG_X86_64
 # error No x86-32 support yet
@@ -86,17 +87,6 @@ err:
 	return ret;
 }
 
-struct fd_parms {
-	unsigned long	fd_name;
-	unsigned long	pos;
-	unsigned int	flags;
-	unsigned int	type;
-	ino_t		ino;
-
-	u64		id;
-	pid_t		pid;
-};
-
 static int dump_one_reg_file_fd(struct fd_parms *p, int lfd,
 				struct cr_fdset *cr_fdset)
 {
@@ -382,12 +372,8 @@ static int dump_one_fd(pid_t pid, char *d_name, struct cr_fdset *cr_fdset,
 		err = dump_one_pipe(&p, 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 '%s'", file_path);
-		return -1;
+		err = dump_one_socket(&p, cr_fdset, sk_queue);
+		break;
 	case S_IFDIR:
 	case S_IFLNK:
 	case S_IFBLK:
diff --git a/include/files.h b/include/files.h
index eb6a219..cdc6ba2 100644
--- a/include/files.h
+++ b/include/files.h
@@ -37,6 +37,17 @@ struct fdinfo_list_entry {
 	u32			real_pid;
 };
 
+struct fd_parms {
+	unsigned long	fd_name;
+	unsigned long	pos;
+	unsigned int	flags;
+	unsigned int	type;
+	ino_t		ino;
+
+	u64		id;
+	pid_t		pid;
+};
+
 extern int prepare_fds(int pid);
 extern int prepare_fd_pid(int pid);
 extern int prepare_shared_fdinfo(void);
diff --git a/include/sockets.h b/include/sockets.h
index 960b918..97c9da5 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -22,7 +22,8 @@ struct sk_queue {
 };
 
 struct cr_fdset;
-extern int try_dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
+struct fd_parms;
+extern int dump_one_socket(struct fd_parms *p, const struct cr_fdset *cr_fdset,
 			   struct sk_queue *queue);
 
 extern int collect_sockets(void);
diff --git a/sockets.c b/sockets.c
index a4eaf59..131cb4f 100644
--- a/sockets.c
+++ b/sockets.c
@@ -22,6 +22,7 @@
 #include "crtools.h"
 #include "util.h"
 #include "inet_diag.h"
+#include "files.h"
 
 static char buf[4096];
 
@@ -362,7 +363,7 @@ err:
 	return -1;
 }
 
-int try_dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
+int dump_one_socket(struct fd_parms *p, const struct cr_fdset *cr_fdset,
 		    struct sk_queue *queue)
 {
 	const struct socket_desc *sk;
@@ -370,35 +371,17 @@ int try_dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
 	struct stat st;
 	char path[64];
 
-	/*
-	 * Sockets are tricky, we can't open it but can
-	 * do stats over and check for sokets magic.
-	 */
-	snprintf(buf, sizeof(buf), "/proc/%d/fd/%d", pid, fd);
-	if (statfs(buf, &fst)) {
-		pr_perror("Can't statfs %s", buf);
-		return -1;
-	}
-
-	if (stat(buf, &st)) {
-		pr_perror("Can't stat %s", buf);
-		return -1;
-	}
-
-	if (fst.f_type != SOCKFS_MAGIC)
-		return 1; /* not a socket, proceed with caller error */
-
-	sk = lookup_socket(st.st_ino);
+	sk = lookup_socket(p->ino);
 	if (!sk) {
-		pr_err("Uncollected socket %ld\n", st.st_ino);
+		pr_err("Uncollected socket %ld\n", p->ino);
 		return -1;
 	}
 
 	switch (sk->family) {
 	case AF_UNIX:
-		return dump_one_unix(sk, fd, cr_fdset, queue);
+		return dump_one_unix(sk, p->fd_name, cr_fdset, queue);
 	case AF_INET:
-		return dump_one_inet(sk, fd, cr_fdset, queue);
+		return dump_one_inet(sk, p->fd_name, cr_fdset, queue);
 	default:
 		pr_err("BUG! Unknown socket collected\n");
 		break;



More information about the CRIU mailing list