[CRIU] [PATCH 08/11] lazy-pages: merge ud_open into handle_socket_conn

Mike Rapoport rppt at linux.vnet.ibm.com
Sun Apr 10 23:19:51 PDT 2016


Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/uffd.c | 77 +++++++++++++++++++++++++------------------------------------
 1 file changed, 32 insertions(+), 45 deletions(-)

diff --git a/criu/uffd.c b/criu/uffd.c
index fece56e..7fadd06 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -154,47 +154,6 @@ out:
 
 static int pid;
 
-static int ud_open(int listen, struct sockaddr_un *saddr)
-{
-	int client;
-	int newfd;
-	int ret = -1;
-	socklen_t len;
-
-	/* accept new client request */
-	len = sizeof(struct sockaddr_un);
-	if ((client = accept(listen, saddr, &len)) < 0) {
-		pr_perror("server_accept error: %d", client);
-		close(listen);
-		return -1;
-	}
-
-	pr_debug("client fd %d\n", client);
-
-	/* The "transfer protocol" is first the pid as int and then
-	 * the FD for UFFD */
-	ret = recv(client, &pid, sizeof(pid), 0);
-	if (ret != sizeof(pid)) {
-		pr_perror("PID recv error:");
-		ret = -1;
-		goto out;
-	}
-	pr_debug("received PID: %d\n", pid);
-
-	newfd = recv_fd(client);
-	if (newfd < 0) {
-		pr_perror("recv_fd error:");
-		goto out;
-	}
-	pr_debug("newfd %d\n", newfd);
-	close(client);
-
-	return newfd;
-out:
-	close(client);
-	return ret;
-}
-
 static int get_page(unsigned long addr, void *dest)
 {
 	struct iovec iov;
@@ -550,14 +509,38 @@ static int handle_socket_conn(int listen, struct sockaddr_un *saddr,
 {
 	int uffd;
 	int uffd_flags;
+	int client;
+	int ret;
+	socklen_t len;
 
-	uffd = ud_open(listen, saddr);
-	if (uffd < 0) {
-		pr_perror("uffd open error");
+	/* accept new client request */
+	len = sizeof(struct sockaddr_un);
+	if ((client = accept(listen, saddr, &len)) < 0) {
+		pr_perror("server_accept error: %d", client);
+		close(listen);
 		return -1;
 	}
 
-	pr_debug("uffd is 0x%d\n", uffd);
+	pr_debug("client fd %d\n", client);
+
+	/* The "transfer protocol" is first the pid as int and then
+	 * the FD for UFFD */
+	ret = recv(client, &pid, sizeof(pid), 0);
+	if (ret != sizeof(pid)) {
+		pr_perror("PID recv error:");
+		ret = -1;
+		goto out;
+	}
+	pr_debug("received PID: %d\n", pid);
+
+	uffd = recv_fd(client);
+	if (uffd < 0) {
+		pr_perror("recv_fd error:");
+		goto out;
+	}
+	pr_debug("uffd is %d\n", uffd);
+	close(client);
+
 	uffd_flags = fcntl(uffd, F_GETFD, NULL);
 	pr_debug("uffd_flags are 0x%x\n", uffd_flags);
 	if (fcntl(uffd, F_SETFD, uffd_flags | O_NONBLOCK))
@@ -571,6 +554,10 @@ static int handle_socket_conn(int listen, struct sockaddr_un *saddr,
 		return -1;
 
 	return uffd;
+
+out:
+	close(client);
+	return ret;
 }
 
 #define POLL_TIMEOUT 5000
-- 
1.9.1



More information about the CRIU mailing list