From e42f5e032e0a518374f8e38aae6af198d2b66da8 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Wed, 9 Sep 2020 19:39:53 +0300 Subject: [PATCH] tcp: allow to specify --tcp-close on dump In this case, states of established tcp connections will not be dumped and they will not be blocked. This will be useful in case of snapshots, when we don't need to restore tcp connections. Signed-off-by: Andrei Vagin --- criu/image.c | 11 +++++++++++ criu/sk-inet.c | 3 ++- criu/sk-tcp.c | 7 +++++++ images/inventory.proto | 1 + test/zdtm/static/Makefile | 1 + test/zdtm/static/socket-dump-tcp-close.c | 1 + test/zdtm/static/socket-dump-tcp-close.desc | 1 + 7 files changed, 24 insertions(+), 1 deletion(-) create mode 120000 test/zdtm/static/socket-dump-tcp-close.c create mode 100644 test/zdtm/static/socket-dump-tcp-close.desc diff --git a/criu/image.c b/criu/image.c index 56c6f787c..d4ad7a79e 100644 --- a/criu/image.c +++ b/criu/image.c @@ -81,6 +81,11 @@ int check_img_inventory(void) goto out_err; } + if (he->tcp_close && !opts.tcp_close) { + pr_err("Need to set the --tcp-close option."); + goto out_err; + } + ret = 0; out_err: @@ -212,6 +217,12 @@ int prepare_inventory(InventoryEntry *he) he->root_ids = crt.i.ids; + /* tcp_close has to be set on restore if it has been set on dump. */ + if (opts.tcp_close) { + he->tcp_close = true; + he->has_tcp_close = true; + } + return 0; } diff --git a/criu/sk-inet.c b/criu/sk-inet.c index dc1ee8144..42bae9454 100644 --- a/criu/sk-inet.c +++ b/criu/sk-inet.c @@ -194,7 +194,7 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk) case TCP_LAST_ACK: case TCP_CLOSING: case TCP_SYN_SENT: - if (!opts.tcp_established_ok) { + if (!opts.tcp_established_ok && !opts.tcp_close) { pr_err("Connected TCP socket, consider using --%s option.\n", SK_EST_PARAM); return 0; @@ -787,6 +787,7 @@ int restore_ip_opts(int sk, int family, int proto, IpOptsEntry *ioe) ret |= restore_ip_raw_opts(sk, family, proto, ioe->raw); return ret; } + static int open_inet_sk(struct file_desc *d, int *new_fd) { struct fdinfo_list_entry *fle = file_master(d); diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c index 8c982e5a4..0409e22c3 100644 --- a/criu/sk-tcp.c +++ b/criu/sk-tcp.c @@ -241,6 +241,10 @@ int dump_one_tcp(int fd, struct inet_sk_desc *sk, SkOptsEntry *soe) if (sk->dst_port == 0) return 0; + if (opts.tcp_close) { + return 0; + } + pr_info("Dumping TCP connection\n"); if (tcp_repair_established(fd, sk)) @@ -461,6 +465,9 @@ void rst_unlock_tcp_connections(void) { struct inet_sk_info *ii; + if (opts.tcp_close) + return; + /* Network will be unlocked by network-unlock scripts */ if (root_ns_mask & CLONE_NEWNET) return; diff --git a/images/inventory.proto b/images/inventory.proto index d1438e8c8..d7d0622c4 100644 --- a/images/inventory.proto +++ b/images/inventory.proto @@ -17,4 +17,5 @@ message inventory_entry { optional lsmtype lsmtype = 6; optional uint64 dump_uptime = 8; optional uint32 pre_dump_mode = 9; + optional bool tcp_close = 10; } diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index ae23e78aa..ee9b57abe 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -102,6 +102,7 @@ TST_NOFILE := \ socket-tcp4v6-closed \ socket-tcp-close0 \ socket-tcp-close1 \ + socket-dump-tcp-close \ socket-tcp-unconn \ socket-tcp6-unconn \ socket-tcp-syn-sent \ diff --git a/test/zdtm/static/socket-dump-tcp-close.c b/test/zdtm/static/socket-dump-tcp-close.c new file mode 120000 index 000000000..5e3c85c91 --- /dev/null +++ b/test/zdtm/static/socket-dump-tcp-close.c @@ -0,0 +1 @@ +socket-tcp-close0.c \ No newline at end of file diff --git a/test/zdtm/static/socket-dump-tcp-close.desc b/test/zdtm/static/socket-dump-tcp-close.desc new file mode 100644 index 000000000..c53a1f315 --- /dev/null +++ b/test/zdtm/static/socket-dump-tcp-close.desc @@ -0,0 +1 @@ +{'opts': '--tcp-close', 'flags': 'reqrst '}