[CRIU] [crtools-bot] sockets: Delay dgram connection
Cyrill Gorcunov
gorcunov at openvz.org
Tue Feb 7 08:26:52 EST 2012
The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
--------------->
commit fe598403dfdc9a5d0ea2ea4c3da02138f43eb96e
Author: Pavel Emelyanov <xemul at parallels.com>
Date: Tue Feb 7 15:51:08 2012 +0400
sockets: Delay dgram connection
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>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
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;
More information about the CRIU
mailing list