[CRIU] [PATCH 1/2] sk-inet: Add support for shutdown'ed UDP/UDPlite sockets

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 3 07:39:15 PST 2017


Supporting shutdown for dgram sockets (udp and udplite)
is simple -- just fetch the state from diag module and
record it in the image, then upon socket creation restore
this state.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/sk-inet.c       | 20 ++++++++++++++------
 images/sk-inet.proto |  1 +
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index ee6ce60e2b12..e1c5b871bbcf 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -123,12 +123,6 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk)
 	BUG_ON((sk->sd.family != AF_INET) && (sk->sd.family != AF_INET6));
 
 	if (sk->type == SOCK_DGRAM) {
-		if (sk->shutdown) {
-			pr_err("Can't dump shutdown inet socket %x\n",
-					sk->sd.ino);
-			return 0;
-		}
-
 		if (sk->wqlen != 0) {
 			pr_err("Can't dump corked dgram socket %x\n",
 					sk->sd.ino);
@@ -426,6 +420,10 @@ static int do_dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p, int fa
 	case IPPROTO_TCP:
 		err = dump_one_tcp(lfd, sk);
 		break;
+	case IPPROTO_UDP:
+	case IPPROTO_UDPLITE:
+		sk_encode_shutdown(&ie, sk->shutdown);
+		/* Fallthrough! */
 	default:
 		err = 0;
 		break;
@@ -719,6 +717,16 @@ done:
 	if (restore_socket_opts(sk, ie->opts))
 		goto err;
 
+	if (ie->has_shutdown &&
+	    (ie->proto == IPPROTO_UDP ||
+	     ie->proto == IPPROTO_UDPLITE)) {
+		if (shutdown(sk, sk_decode_shutdown(ie->shutdown))) {
+			pr_perror("Can't shutdown socket into %d",
+				  sk_decode_shutdown(ie->shutdown));
+			goto err;
+		}
+	}
+
 	*new_fd = sk;
 	return 1;
 err:
diff --git a/images/sk-inet.proto b/images/sk-inet.proto
index 09c5a47d2464..b4e14fcc7058 100644
--- a/images/sk-inet.proto
+++ b/images/sk-inet.proto
@@ -40,4 +40,5 @@ message inet_sk_entry {
 	 * here and convert it on restore */
 	optional string			ifname		= 17;
 	optional uint32			ns_id		= 18;
+	optional sk_shutdown		shutdown	= 19;
 }
-- 
2.7.4



More information about the CRIU mailing list