[CRIU] [PATCH 06/15] restore: Prepare on-restorer tcp socks earlier

Pavel Emelyanov xemul at virtuozzo.com
Tue May 24 04:35:07 PDT 2016


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-restore.c      | 17 +++++++++--------
 criu/include/sk-inet.h |  5 ++---
 criu/sk-tcp.c          | 12 ++++++------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 313fefc..c95d049 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -538,6 +538,14 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
 	if (prepare_proc_misc(pid, core->tc))
 		return -1;
 
+	/*
+	 * Get all the tcp sockets fds into rst memory -- restorer
+	 * will turn repair off before going sigreturn
+	 */
+	if (prepare_tcp_socks(ta))
+		return -1;
+
+
 	return sigreturn_restore(pid, ta_cp, core);
 }
 
@@ -2725,13 +2733,6 @@ static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 	BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
 
 	/*
-	 * Get all the tcp sockets fds into rst memory -- restorer
-	 * will turn repair off before going sigreturn
-	 */
-	if (rst_tcp_socks_prep())
-		goto err_nv;
-
-	/*
 	 * Copy timerfd params for restorer args, we need to proceed
 	 * timer setting at the very late.
 	 */
@@ -2866,6 +2867,7 @@ static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 
 	task_args->vmas = rst_mem_remap_ptr((unsigned long)task_args->vmas, RM_PRIVATE);
 	task_args->rings = rst_mem_remap_ptr((unsigned long)task_args->rings, RM_PRIVATE);
+	task_args->tcp_socks = rst_mem_remap_ptr((unsigned long)task_args->tcp_socks, RM_PRIVATE);
 
 #define remap_array(name, nr, cpos)	do {				\
 		task_args->name##_n = nr;				\
@@ -2875,7 +2877,6 @@ static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 	remap_array(posix_timers, posix_timers_nr, posix_timers_cpos);
 	remap_array(timerfd,	  rst_timerfd_nr, rst_timerfd_cpos);
 	remap_array(siginfo,	  siginfo_nr, siginfo_cpos);
-	remap_array(tcp_socks,	  rst_tcp_socks_nr, rst_tcp_socks_cpos);
 	remap_array(rlims,	  rlims_nr, rlims_cpos);
 	remap_array(helpers,	  n_helpers, helpers_pos);
 	remap_array(zombies,	  n_zombies, zombies_pos);
diff --git a/criu/include/sk-inet.h b/criu/include/sk-inet.h
index 1b4925e..112d6c5 100644
--- a/criu/include/sk-inet.h
+++ b/criu/include/sk-inet.h
@@ -76,9 +76,8 @@ extern int restore_one_tcp(int sk, struct inet_sk_info *si);
 extern int check_tcp(void);
 extern mutex_t *inet_get_reuseaddr_lock(struct inet_sk_info *ii);
 
-int rst_tcp_socks_prep(void);
-extern unsigned long rst_tcp_socks_cpos;
-extern unsigned int rst_tcp_socks_nr;
+struct task_restore_args;
+int prepare_tcp_socks(struct task_restore_args *);
 
 struct rst_tcp_sock {
 	int	sk;
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index 590170a..bc10d72 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -22,6 +22,7 @@
 #include "xmalloc.h"
 #include "config.h"
 #include "kerndat.h"
+#include "restorer.h"
 #include "rst-malloc.h"
 
 #include "protobuf.h"
@@ -670,14 +671,13 @@ err:
 	return -1;
 }
 
-unsigned long rst_tcp_socks_cpos;
-unsigned int rst_tcp_socks_nr = 0;
-
-int rst_tcp_socks_prep(void)
+int prepare_tcp_socks(struct task_restore_args *ta)
 {
 	struct inet_sk_info *ii;
 
-	rst_tcp_socks_cpos = rst_mem_align_cpos(RM_PRIVATE);
+	ta->tcp_socks = (struct rst_tcp_sock *) rst_mem_align_cpos(RM_PRIVATE);
+	ta->tcp_socks_n = 0;
+
 	list_for_each_entry(ii, &rst_tcp_repair_sockets, rlist) {
 		struct rst_tcp_sock *rs;
 
@@ -694,7 +694,7 @@ int rst_tcp_socks_prep(void)
 
 		rs->sk = ii->sk_fd;
 		rs->reuseaddr = ii->ie->opts->reuseaddr;
-		rst_tcp_socks_nr++;
+		ta->tcp_socks_n++;
 	}
 
 	return 0;
-- 
2.5.0



More information about the CRIU mailing list