[CRIU] [PATCH 09/78] infect: Introduce infect_ctx

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:35:54 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

This structure will become the part of compel A[PB]I and
will be used by compel clients as configuration structure.

For now put there the pointer on a socket living in victim's
netns. If empty (-1), compel will create this socket its own,
but CRIU already creates such in an effective manner.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/include/parasite-syscall.h |  6 ++++++
 criu/parasite-syscall.c         | 19 +++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/criu/include/parasite-syscall.h b/criu/include/parasite-syscall.h
index 95296c55838d..b161a47ab48d 100644
--- a/criu/include/parasite-syscall.h
+++ b/criu/include/parasite-syscall.h
@@ -26,6 +26,10 @@ struct thread_ctx {
 	user_regs_struct_t	regs;
 };
 
+struct infect_ctx {
+	int	*p_sock;
+};
+
 /* parasite control block */
 struct parasite_ctl {
 	int			rpid;					/* Real pid of the victim */
@@ -34,6 +38,8 @@ struct parasite_ctl {
 	void			*sigreturn_addr;			/* A place for the breakpoint */
 	unsigned long		map_length;
 
+	struct infect_ctx	ictx;
+
 	/* thread leader data */
 	bool			daemonized;
 
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 81ddff712e89..137517c9cca5 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -446,7 +446,7 @@ static int restore_child_handler()
 }
 
 static int prepare_tsock(struct parasite_ctl *ctl, pid_t pid,
-		struct parasite_init_args *args, struct ns_id *net)
+		struct parasite_init_args *args)
 {
 	static int ssock = -1;
 
@@ -454,8 +454,13 @@ static int prepare_tsock(struct parasite_ctl *ctl, pid_t pid,
 	args->h_addr_len = gen_parasite_saddr(&args->h_addr, getpid());
 
 	if (ssock == -1) {
-		ssock = net->net.seqsk;
-		net->net.seqsk = -1;
+		ssock = *ctl->ictx.p_sock;
+		if (ssock == -1) {
+			pr_err("No socket in ictx\n");
+			goto err;
+		}
+
+		*ctl->ictx.p_sock = -1;
 
 		if (bind(ssock, (struct sockaddr *)&args->h_addr, args->h_addr_len) < 0) {
 			pr_perror("Can't bind socket");
@@ -499,7 +504,7 @@ static int accept_tsock(struct parasite_ctl *ctl)
 	return 0;
 }
 
-static int parasite_init_daemon(struct parasite_ctl *ctl, struct ns_id *net)
+static int parasite_init_daemon(struct parasite_ctl *ctl)
 {
 	struct parasite_init_args *args;
 	pid_t pid = ctl->rpid;
@@ -515,7 +520,7 @@ static int parasite_init_daemon(struct parasite_ctl *ctl, struct ns_id *net)
 
 	futex_set(&args->daemon_connected, 0);
 
-	if (prepare_tsock(ctl, pid, args, net))
+	if (prepare_tsock(ctl, pid, args))
 		goto err;
 
 	/* after this we can catch parasite errors in chld handler */
@@ -1435,7 +1440,7 @@ static int parasite_start_daemon(struct parasite_ctl *ctl, struct pstree_item *i
 	if (construct_sigframe(ctl->sigframe, ctl->rsigframe, &ctl->orig.sigmask, item->core[0]))
 		return -1;
 
-	if (parasite_init_daemon(ctl, dmpi(item)->netns))
+	if (parasite_init_daemon(ctl))
 		return -1;
 
 	return 0;
@@ -1475,6 +1480,8 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 	if (!ctl)
 		return NULL;
 
+	ctl->ictx.p_sock = &dmpi(item)->netns->net.seqsk;
+
 	parasite_ensure_args_size(dump_pages_args_size(vma_area_list));
 	parasite_ensure_args_size(aio_rings_args_size(vma_area_list));
 
-- 
2.7.4



More information about the CRIU mailing list