Commit 2c370428 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Andrei Vagin

tcp: Add tcp-close option to restore connected TCP sockets in closed state

New restore option 'tcp-close' was introduced. It restores all connected
TCP sockets in TCP_CLOSE state. Here we consider tcp sockets in
TCP_ESTABLISHED, TCP_FIN_WAIT2, TCP_FIN_WAIT1, TCP_CLOSE_WAIT,
TCP_LAST_ACK, TCP_CLOSING, TCP_SYN_SENT states as connected sockets.
This is consistent with current CRIU usage of these states. Thus this
option doesn't affect sockets with original states of TCP_LISTEN and
TCP_CLOSE.
Signed-off-by: 's avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: 's avatarEugene Batalov <eabatalov89@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 4c332970
...@@ -264,6 +264,9 @@ For example, the command line for the above example should look like this: ...@@ -264,6 +264,9 @@ For example, the command line for the above example should look like this:
The TCP stack on the client side is expected to handle the The TCP stack on the client side is expected to handle the
re-connect gracefully. re-connect gracefully.
*--tcp-close*::
Restore connected TCP sockets in closed state.
*--evasive-devices*:: *--evasive-devices*::
Use any path to a device file if the original one is inaccessible. Use any path to a device file if the original one is inaccessible.
......
...@@ -290,6 +290,7 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -290,6 +290,7 @@ int main(int argc, char *argv[], char *envp[])
BOOL_OPT("display-stats", &opts.display_stats), BOOL_OPT("display-stats", &opts.display_stats),
BOOL_OPT("weak-sysctls", &opts.weak_sysctls), BOOL_OPT("weak-sysctls", &opts.weak_sysctls),
{ "status-fd", required_argument, 0, 1088 }, { "status-fd", required_argument, 0, 1088 },
{ SK_CLOSE_PARAM, no_argument, 0, 1089 },
{ }, { },
}; };
...@@ -568,6 +569,9 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -568,6 +569,9 @@ int main(int argc, char *argv[], char *envp[])
return 1; return 1;
} }
break; break;
case 1089:
opts.tcp_close = true;
break;
case 'V': case 'V':
pr_msg("Version: %s\n", CRIU_VERSION); pr_msg("Version: %s\n", CRIU_VERSION);
if (strcmp(CRIU_GITID, "0")) if (strcmp(CRIU_GITID, "0"))
...@@ -826,6 +830,7 @@ usage: ...@@ -826,6 +830,7 @@ usage:
"* Special resources support:\n" "* Special resources support:\n"
" --" SK_EST_PARAM " checkpoint/restore established TCP connections\n" " --" SK_EST_PARAM " checkpoint/restore established TCP connections\n"
" --" SK_INFLIGHT_PARAM " skip (ignore) in-flight TCP connections\n" " --" SK_INFLIGHT_PARAM " skip (ignore) in-flight TCP connections\n"
" --" SK_CLOSE_PARAM " restore connected TCP sockets in closed state\n"
" -r|--root PATH change the root filesystem (when run in mount namespace)\n" " -r|--root PATH change the root filesystem (when run in mount namespace)\n"
" --evasive-devices use any path to a device file if the original one\n" " --evasive-devices use any path to a device file if the original one\n"
" is inaccessible\n" " is inaccessible\n"
......
...@@ -63,6 +63,7 @@ struct cr_options { ...@@ -63,6 +63,7 @@ struct cr_options {
int shell_job; int shell_job;
int handle_file_locks; int handle_file_locks;
int tcp_established_ok; int tcp_established_ok;
bool tcp_close;
int evasive_devices; int evasive_devices;
int link_remap_ok; int link_remap_ok;
int log_file_per_pid; int log_file_per_pid;
......
...@@ -75,6 +75,7 @@ extern int restore_one_tcp(int sk, struct inet_sk_info *si); ...@@ -75,6 +75,7 @@ extern int restore_one_tcp(int sk, struct inet_sk_info *si);
#define SK_EST_PARAM "tcp-established" #define SK_EST_PARAM "tcp-established"
#define SK_INFLIGHT_PARAM "skip-in-flight" #define SK_INFLIGHT_PARAM "skip-in-flight"
#define SK_CLOSE_PARAM "tcp-close"
struct task_restore_args; struct task_restore_args;
int prepare_tcp_socks(struct task_restore_args *); int prepare_tcp_socks(struct task_restore_args *);
......
...@@ -648,7 +648,7 @@ static int open_inet_sk(struct file_desc *d, int *new_fd) ...@@ -648,7 +648,7 @@ static int open_inet_sk(struct file_desc *d, int *new_fd)
goto err; goto err;
if (tcp_connection(ie)) { if (tcp_connection(ie)) {
if (!opts.tcp_established_ok) { if (!opts.tcp_established_ok && !opts.tcp_close) {
pr_err("Connected TCP socket in image\n"); pr_err("Connected TCP socket in image\n");
goto err; goto err;
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "../soccr/soccr.h" #include "../soccr/soccr.h"
#include "cr_options.h"
#include "util.h" #include "util.h"
#include "common/list.h" #include "common/list.h"
#include "log.h" #include "log.h"
...@@ -407,6 +408,11 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii) ...@@ -407,6 +408,11 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii)
pr_info("Restoring TCP connection\n"); pr_info("Restoring TCP connection\n");
if (opts.tcp_close &&
ii->ie->state != TCP_LISTEN && ii->ie->state != TCP_CLOSE) {
return 0;
}
sk = libsoccr_pause(fd); sk = libsoccr_pause(fd);
if (!sk) if (!sk)
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment