[CRIU] [PATCH 7/8] restore: UNIX sockets queue support

Kinsbursky Stanislav skinsbursky at openvz.org
Tue Feb 28 05:31:53 EST 2012


Based on xemul@ patches.

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

---
 cr-restore.c      |    2 +-
 include/crtools.h |    2 ++
 sockets.c         |   44 +++++++++++++++++++++++++++++++++-----------
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 4443990..c19cc30 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -99,7 +99,7 @@ static struct shmems *shmems;
 static struct pipe_info *pipes;
 static int nr_pipes;
 
-static pid_t pstree_pid;
+pid_t pstree_pid;
 struct pstree_item *me;
 
 static int restore_task_with_children(void *);
diff --git a/include/crtools.h b/include/crtools.h
index 21738fd..8ac10f2 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -157,6 +157,8 @@ struct pstree_item {
 	u32			*children;	/* array of children */
 };
 
+extern pid_t pstree_pid;
+
 static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
 {
 	return addr >= (unsigned long)vma->vma.start &&
diff --git a/sockets.c b/sockets.c
index 1e02681..f428db5 100644
--- a/sockets.c
+++ b/sockets.c
@@ -790,7 +790,7 @@ enum {
 
 static void unix_show_job(const char *type, int fd, int id)
 {
-	pr_debug("%s job fd %d id %d\n", type, fd, id);
+	pr_info("%s job fd %d id %d\n", type, fd, id);
 }
 
 static struct unix_conn_job *conn_jobs;
@@ -816,7 +816,7 @@ static int schedule_conn_job(int type, const struct unix_sk_entry *ue)
 	return 0;
 }
 
-static int run_connect_jobs(void)
+static int run_connect_jobs(struct list_head *packets_list)
 {
 	struct unix_conn_job *cj, *next;
 	int i;
@@ -825,7 +825,7 @@ static int run_connect_jobs(void)
 	while (cj) {
 		int attempts = 8;
 		struct sockaddr_un addr;
-		int addrlen;
+		int addrlen, ret;
 
 		/*
 		 * Might need to resolve in-flight connection name.
@@ -850,7 +850,7 @@ static int run_connect_jobs(void)
 			addrlen = e->addrlen;
 		}
 
-		unix_show_job("Run conn", cj->fd, -1);
+		unix_show_job("Run conn", cj->fd, cj->peer);
 try_again:
 		if (connect(cj->fd, (struct sockaddr *)&addr, addrlen) < 0) {
 			if (attempts) {
@@ -862,7 +862,12 @@ try_again:
 			return -1;
 		}
 
-		unix_show_job("Fin conn", cj->fd, -1);
+		unix_show_job("Fin conn", cj->fd, cj->peer);
+
+		ret = restore_socket_queue(cj->fd, cj->peer, packets_list);
+		if (ret < 0)
+			return -1;
+
 		next = cj->next;
 		xfree(cj);
 		cj = next;
@@ -887,6 +892,7 @@ try_again:
 
 struct unix_accept_job {
 	int			fd;
+	int			peer;
 	struct unix_accept_job	*next;
 };
 
@@ -914,6 +920,7 @@ static int schedule_acc_job(int sk, const struct unix_sk_entry *ue)
 		goto err;
 
 	aj->fd = ue->fd;
+	aj->peer = ue->peer;
 	aj->next = accept_jobs;
 	accept_jobs = aj;
 	unix_show_job("Sched acc", ue->fd, ue->id);
@@ -922,13 +929,13 @@ err:
 	return -1;
 }
 
-static int run_accept_jobs(void)
+static int run_accept_jobs(struct list_head *packets_list)
 {
 	struct unix_accept_job *aj, *next;
 
 	aj = accept_jobs;
 	while (aj) {
-		int fd;
+		int fd, ret;
 
 		unix_show_job("Run acc", aj->fd, -1);
 		fd = accept(aj->fd, NULL, NULL);
@@ -940,6 +947,10 @@ static int run_accept_jobs(void)
 		if (reopen_fd_as_nocheck(aj->fd, fd))
 			return -1;
 
+		ret = restore_socket_queue(aj->fd, aj->peer, packets_list);
+		if (ret < 0)
+			return -1;
+
 		unix_show_job("Fin acc", aj->fd, -1);
 		next = aj->next;
 		xfree(aj);
@@ -1105,7 +1116,8 @@ err:
 
 static int prepare_unix_sockets(int pid)
 {
-	int usk_fd, ret = -1;
+	int usk_fd, ret = -1, pkt_fd;
+	LIST_HEAD(packets_list);
 
 	usk_fd = open_image_ro(CR_FD_UNIXSK, pid);
 	if (usk_fd < 0)
@@ -1125,10 +1137,20 @@ static int prepare_unix_sockets(int pid)
 err:
 	close(usk_fd);
 
+	if (ret)
+		return ret;
+
+	pkt_fd = open_image_ro(CR_FD_SK_QUEUES, pstree_pid);
+	if (pkt_fd < 0)
+		return -1;
+	ret = read_sockets_queues(pkt_fd, &packets_list);
+	close(pkt_fd);
+	if (ret < 0)
+		return ret;
+
+	ret = run_connect_jobs(&packets_list);
 	if (!ret)
-		ret = run_connect_jobs();
-	if (!ret)
-		ret = run_accept_jobs();
+		ret = run_accept_jobs(&packets_list);
 
 	return ret;
 }



More information about the CRIU mailing list