[CRIU] [PATCH 3/12] sockets: Delay dgram connection

Pavel Emelyanov xemul at parallels.com
Tue Feb 7 06:51:08 EST 2012


By the time we try to resolve datagram socket connection name the other
end may not yet be on the hash. Move the address resolution into the
conn job.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---
-------------- next part --------------
From d4c2dc135a21dcddbb761c90b37411bac9cc2c32 Mon Sep 17 00:00:00 2001
From: root <root at dhcp-10-30-23-222.sw.ru>
Date: Tue, 7 Feb 2012 14:12:25 +0300
Subject: [PATCH 03/12] move dgram connect higher

---
 sockets.c |   67 +++++++++++++++++++++++++++++++------------------------------
 1 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/sockets.c b/sockets.c
index b0d7206..de0d03d 100644
--- a/sockets.c
+++ b/sockets.c
@@ -651,10 +651,20 @@ out:
 	return err;
 }
 
+static void prep_conn_addr(int id, struct sockaddr_un *addr, int *addrlen)
+{
+	addr->sun_family = AF_UNIX;
+	addr->sun_path[0] = '\0';
+
+	snprintf(addr->sun_path + 1, UNIX_PATH_MAX - 1, "crtools-sk-%10d", id);
+
+	*addrlen = sizeof(addr->sun_family) + sizeof("crtools-sk-") - 1 + 10;
+}
+
 struct unix_conn_job {
-	struct sockaddr_un	addr;
-	int			addrlen;
 	int			fd;
+	unsigned int		peer;
+	int			flags;
 	struct unix_conn_job	*next;
 };
 
@@ -673,10 +683,29 @@ static int run_connect_jobs(void)
 	cj = conn_jobs;
 	while (cj) {
 		int attempts = 8;
+		struct sockaddr_un addr;
+		int addrlen;
+
+		/*
+		 * Might need to resolve in-flight connection name.
+		 */
+		if (cj->flags & USK_INFLIGHT) {
+			struct unix_sk_listen *e;
+
+			e = lookup_unix_listen(cj->peer);
+			if (!e) {
+				pr_err("Bad in-flight socket peer %d\n", cj->peer);
+				return -1;
+			}
+
+			memcpy(&addr, &e->addr, sizeof(addr));
+			addrlen = e->addrlen;
+		} else
+			prep_conn_addr(cj->peer, &addr, &addrlen);
 
 		unix_show_job("Run conn", cj->fd, -1);
 try_again:
-		if (connect(cj->fd, (struct sockaddr *)&cj->addr, cj->addrlen) < 0) {
+		if (connect(cj->fd, (struct sockaddr *)&addr, addrlen) < 0) {
 			if (attempts) {
 				usleep(1000);
 				attempts--;
@@ -743,16 +772,6 @@ static int run_accept_jobs(void)
 	return 0;
 }
 
-static void prep_conn_addr(int id, struct sockaddr_un *addr, int *addrlen)
-{
-	addr->sun_family = AF_UNIX;
-	addr->sun_path[0] = '\0';
-
-	snprintf(addr->sun_path + 1, UNIX_PATH_MAX - 1, "crtools-sk-%10d", id);
-
-	*addrlen = sizeof(addr->sun_family) + sizeof("crtools-sk-") - 1 + 10;
-}
-
 struct unix_dgram_bound {
 	struct unix_dgram_bound	*next;
 	struct sockaddr_un	addr;
@@ -992,27 +1011,9 @@ static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int img_fd)
 			if (!cj)
 				goto err;
 
-			/*
-			 * Might need to resolve in-flight connection name.
-			 */
-			if (ue->flags & USK_INFLIGHT) {
-				struct unix_sk_listen *e;
-
-				/*
-				 * Find out listening sockets name.
-				 */
-				e = lookup_unix_listen(ue->peer);
-				if (!e) {
-					pr_err("Bad in-flight socket peer %d\n",
-						ue->peer);
-					goto err;
-				}
-
-				memcpy(&cj->addr, &e->addr, sizeof(cj->addr));
-				cj->addrlen = e->addrlen;
-			} else
-				prep_conn_addr(ue->peer, &cj->addr, &cj->addrlen);
 
+			cj->peer = ue->peer;
+			cj->flags = ue->flags;
 			cj->fd = ue->fd;
 			cj->next = conn_jobs;
 			conn_jobs = cj;
-- 
1.6.5.2


More information about the CRIU mailing list