[CRIU] [PATCH v2 10/11] dump: cleanup sockets dump

Kinsbursky Stanislav skinsbursky at openvz.org
Mon Mar 5 07:39:06 EST 2012


Now we don't need to check fd for socket. And thus can greatly simplify this
code.

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

---
 cr-dump.c         |   21 +++------------------
 include/files.h   |   12 ++++++++++++
 include/sockets.h |    3 ++-
 sockets.c         |   29 ++++++-----------------------
 4 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index a1f7d3b..0145f57 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
@@ -87,18 +88,6 @@ err:
 	return ret;
 }
 
-struct fd_parms {
-	unsigned long	fd_name;
-	unsigned long	pos;
-	unsigned int	flags;
-	unsigned int	type;
-	ino_t		ino;
-	int		pid_fd_dir;
-
-	u64		id;
-	pid_t		pid;
-};
-
 static int dump_one_reg_file_fd(struct fd_parms *p, int lfd,
 				struct cr_fdset *cr_fdset)
 {
@@ -383,12 +372,8 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct 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 %d/%ld", p.pid_fd_dir, p.fd_name);
-		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..c3745da 100644
--- a/include/files.h
+++ b/include/files.h
@@ -37,6 +37,18 @@ 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;
+	int             pid_fd_dir;
+
+	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 f1896fa..0ce2d12 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];
 
@@ -369,7 +370,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;
@@ -377,35 +378,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