[CRIU] [PATCH 5/6] tcp: allow to dump intermediate closing states

Andrey Vagin avagin at openvz.org
Tue Mar 4 21:04:59 PST 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 sk-inet.c | 17 ++++++++++++++---
 sk-tcp.c  |  7 ++++++-
 sockets.c | 15 ++++++++++++++-
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/sk-inet.c b/sk-inet.c
index 02c653f..ca10485 100644
--- a/sk-inet.c
+++ b/sk-inet.c
@@ -93,12 +93,12 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk, int proto)
 {
 	BUG_ON((sk->sd.family != AF_INET) && (sk->sd.family != AF_INET6));
 
-	if (sk->shutdown) {
+/*	if (sk->shutdown) {
 		pr_err("Can't dump shutdown inet socket %x\n",
 				sk->sd.ino);
 		return 0;
 	}
-
+*/
 	if (sk->type == SOCK_DGRAM) {
 		if (sk->wqlen != 0) {
 			pr_err("Can't dump corked dgram socket %x\n",
@@ -134,6 +134,11 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk, int proto)
 		}
 		break;
 	case TCP_ESTABLISHED:
+	case TCP_FIN_WAIT2:
+	case TCP_FIN_WAIT1:
+	case TCP_CLOSE_WAIT:
+	case TCP_LAST_ACK:
+	case TCP_CLOSING:
 		if (!opts.tcp_established_ok) {
 			pr_err("Connected TCP socket, consider using %s option.\n",
 					SK_EST_PARAM);
@@ -381,7 +386,13 @@ static struct file_desc_ops inet_desc_ops = {
 
 static inline int tcp_connection(InetSkEntry *ie)
 {
-	return (ie->proto == IPPROTO_TCP) && (ie->state == TCP_ESTABLISHED);
+	return ie->proto == IPPROTO_TCP &&
+			(ie->state == TCP_ESTABLISHED ||
+			 ie->state == TCP_FIN_WAIT1   ||
+			 ie->state == TCP_FIN_WAIT2   ||
+			 ie->state == TCP_CLOSE_WAIT  ||
+			 ie->state == TCP_LAST_ACK    ||
+			 ie->state == TCP_CLOSING);
 }
 
 static int collect_one_inetsk(void *o, ProtobufCMessage *base)
diff --git a/sk-tcp.c b/sk-tcp.c
index 78715f5..e15fbcb 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -80,6 +80,11 @@ static int refresh_inet_sk(struct inet_sk_desc *sk)
 
 	switch (info.tcpi_state) {
 	case TCP_ESTABLISHED:
+	case TCP_FIN_WAIT1:
+	case TCP_FIN_WAIT2:
+	case TCP_CLOSE_WAIT:
+	case TCP_LAST_ACK:
+	case TCP_CLOSING:
 	case TCP_CLOSE:
 		break;
 	default:
@@ -422,7 +427,7 @@ err_in:
 
 int dump_one_tcp(int fd, struct inet_sk_desc *sk)
 {
-	if (sk->state != TCP_ESTABLISHED)
+	if (sk->state == TCP_CLOSE || sk->state == TCP_LISTEN)
 		return 0;
 
 	pr_info("Dumping TCP connection\n");
diff --git a/sockets.c b/sockets.c
index 36b2378..43a5b74 100644
--- a/sockets.c
+++ b/sockets.c
@@ -557,7 +557,10 @@ int collect_sockets(int pid)
 	req.r.i.sdiag_protocol	= IPPROTO_TCP;
 	req.r.i.idiag_ext	= 0;
 	/* Only listening and established sockets supported yet */
-	req.r.i.idiag_states	= (1 << TCP_LISTEN) | (1 << TCP_ESTABLISHED);
+	req.r.i.idiag_states	= (1 << TCP_LISTEN) | (1 << TCP_ESTABLISHED) |
+					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
+					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
+					(1 << TCP_CLOSING);
 	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, &req.r.i);
 	if (tmp)
 		err = tmp;
@@ -693,6 +696,16 @@ char *skstate2s(u32 state)
 		return "closed";
 	else if (state == TCP_LISTEN)
 		return "listen";
+	else if (state == TCP_FIN_WAIT1)
+		return "fin-wait1";
+	else if (state == TCP_FIN_WAIT2)
+		return "fin-wait2";
+	else if (state == TCP_CLOSE_WAIT)
+		return "close-wait";
+	else if (state == TCP_LAST_ACK)
+		return "last-ack";
+	else if (state == TCP_LAST_ACK)
+		return "closing";
 	else
 		return unknown(state);
 }
-- 
1.8.5.3



More information about the CRIU mailing list