[CRIU] [PATCH cr 08/10] cr-restore: add ability to unlock connections from a controll process

Andrey Vagin avagin at openvz.org
Thu Sep 13 09:10:28 EDT 2012


For that crtools reads an image files and unlock connections one by one.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/sk-inet.h |    2 +-
 sk-inet.c         |   34 ++++++++++++++++++++++++++++++++++
 sk-tcp.c          |    8 --------
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/include/sk-inet.h b/include/sk-inet.h
index 18c8cdb..5657767 100644
--- a/include/sk-inet.h
+++ b/include/sk-inet.h
@@ -54,7 +54,7 @@ static inline void tcp_repair_off(int fd)
 
 void tcp_unlock_all(void);
 void tcp_locked_conn_add(struct inet_sk_info *);
-void tcp_unlock_connections(void);
+int tcp_unlock_connections(void);
 
 int dump_one_tcp(int sk, struct inet_sk_desc *sd);
 int restore_one_tcp(int sk, struct inet_sk_info *si);
diff --git a/sk-inet.c b/sk-inet.c
index 5543284..996362a 100644
--- a/sk-inet.c
+++ b/sk-inet.c
@@ -11,6 +11,7 @@
 
 #include "types.h"
 #include "libnetlink.h"
+#include "netfilter.h"
 #include "crtools.h"
 #include "inet_diag.h"
 #include "files.h"
@@ -586,3 +587,36 @@ void show_inetsk(int fd, struct cr_options *o)
 {
 	pb_show_plain_pretty(fd, PB_INETSK, "1:%#x 2:%#x 3:%d 4:%d 5:%d 6:%d 7:%d 8:%d 9:%2x 11:A 12:A");
 }
+
+int tcp_unlock_connections(void)
+{
+	InetSkEntry *ie;
+	int ifd, ret;
+
+	ifd = open_image_ro(CR_FD_INETSK);
+	if (ifd < 0)
+		return -1;
+
+	while (true) {
+		ret = pb_read_one_eof(ifd, &ie, PB_INETSK);
+		if (ret <= 0)
+			break;
+
+		if (!tcp_connection(ie)) {
+			inet_sk_entry__free_unpacked(ie, NULL);
+			continue;
+		}
+
+		ret = nf_connection_switch_raw(ie->src_addr, ie->src_port,
+						ie->dst_addr, ie->dst_port, 0);
+
+		inet_sk_entry__free_unpacked(ie, NULL);
+
+		if (ret < 0) {
+			pr_perror("Failed to unlock TCP connection");
+			break;
+		}
+	}
+
+	return ret;
+}
diff --git a/sk-tcp.c b/sk-tcp.c
index ec4582e..1f64f9e 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -560,14 +560,6 @@ void tcp_locked_conn_add(struct inet_sk_info *ii)
 	list_add_tail(&ii->rlist, &tcp_repair_sockets);
 }
 
-void tcp_unlock_connections(void)
-{
-	struct inet_sk_info *ii;
-
-	list_for_each_entry(ii, &tcp_repair_sockets, rlist)
-		nf_unlock_connection_info(ii);
-}
-
 void show_tcp_stream(int fd, struct cr_options *opt)
 {
 	TcpStreamEntry *tse;
-- 
1.7.1



More information about the CRIU mailing list