[CRIU] [PATCH] migration feature: 1) add option --migrate | -m 2) add member variable in opts structure in cr_options.h 3) change socket ip in restore_sockaddr function in sk-inet.c

Ya Sun sunya888888 at 163.com
Sun Jul 13 06:00:23 PDT 2014


Signed-off-by: Ya Sun <sunya888888 at 163.com>
---
 crtools.c            | 18 +++++++++++++++++-
 include/cr_options.h |  2 ++
 sk-inet.c            |  8 +++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/crtools.c b/crtools.c
index b662fff..8a3baf1 100644
--- a/crtools.c
+++ b/crtools.c
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
 	int log_level = LOG_UNSET;
 	char *imgs_dir = ".";
 	char *work_dir = NULL;
-	static const char short_opts[] = "dsRf:F:t:p:hcD:o:n:v::xVr:jlW:L:M:";
+	static const char short_opts[] = "dsRf:F:t:p:hcD:o:n:v::xVr:jlW:L:M:m:";
 	static struct option long_opts[] = {
 		{ "tree", required_argument, 0, 't' },
 		{ "pid", required_argument, 0, 'p' },
@@ -167,6 +167,7 @@ int main(int argc, char *argv[])
 		{ "force-irmap", no_argument, 0, 58},
 		{ "ext-mount-map", required_argument, 0, 'M'},
 		{ "exec-cmd", no_argument, 0, 59},
+		{ "migrate", required_argument, 0, 'm'},
 		{ },
 	};
 
@@ -365,6 +366,13 @@ int main(int argc, char *argv[])
 					return 1;
 			}
 			break;
+		case 'm':{
+				if((opts.migrate_ip = inet_addr(optarg)) == INADDR_NONE){  
+					pr_msg("Error: ip for migration  is invalid\n");
+					return 1;
+				}
+			}
+			break;
 		case 'V':
 			pr_msg("Version: %s\n", CRIU_VERSION);
 			if (strcmp(CRIU_GITID, "0"))
@@ -407,6 +415,11 @@ int main(int argc, char *argv[])
 		opts.exec_cmd[argc - optind - 1] = NULL;
 	}
 
+
+	if(strcmp(argv[optind],"restore") && opts.migrate_ip != MIGRATE_IP_DEFAULT_NO){
+		pr_msg("Error:--migrate without criu restore in live-migrate is forbidden \n");
+		goto usage;
+	}
 	/* We must not open imgs dir, if service is called */
 	if (strcmp(argv[optind], "service")) {
 		ret = open_image_dir(imgs_dir);
@@ -564,6 +577,9 @@ usage:
 "  --port PORT           port of page server\n"
 "  -d|--daemon           run in the background after creating socket\n"
 "\n"
+"migrate form vm1 to vm2 with TCP/IP connection:\n"
+"  -m|--migrate VM2_IP   migrated from vm1 to vm2 with TCP/IP connection,which will be disconnected after migration\n"
+"\n"
 "Show options:\n"
 "  -f|--file FILE        show contents of a checkpoint file\n"
 "  -F|--fields FIELDS    show specified fields (comma separated)\n"
diff --git a/include/cr_options.h b/include/cr_options.h
index 55ca70b..707c949 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -18,6 +18,7 @@ struct script {
  */
 #define CPU_CAP_FPU		(1u)
 #define CPU_CAP_ALL		(-1u)
+#define MIGRATE_IP_DEFAULT_NO (-1u)
 
 struct cr_options {
 	int			final_state;
@@ -51,6 +52,7 @@ struct cr_options {
 	unsigned int		cpu_cap;
 	bool			force_irmap;
 	char			**exec_cmd;
+	unsigned int    migrate_ip;
 };
 
 extern struct cr_options opts;
diff --git a/sk-inet.c b/sk-inet.c
index a94cd41..c4f6fc9 100644
--- a/sk-inet.c
+++ b/sk-inet.c
@@ -578,7 +578,13 @@ static int restore_sockaddr(union sockaddr_inet *sa,
 	if (family == AF_INET) {
 		sa->v4.sin_family = AF_INET;
 		sa->v4.sin_port = htons(pb_port);
-		memcpy(&sa->v4.sin_addr.s_addr, pb_addr, sizeof(sa->v4.sin_addr.s_addr));
+		if(opts.migrate_ip == MIGRATE_IP_DEFAULT_NO){
+			memcpy(&sa->v4.sin_addr.s_addr, pb_addr, sizeof(sa->v4.sin_addr.s_addr));
+		}
+		else{
+			memcpy(&sa->v4.sin_addr.s_addr,&(opts.migrate_ip),sizeof(sa->v4.sin_addr.s_addr));//restore TCP connection     for migration
+			pr_msg("migrate_ip:%s\n",inet_ntoa(sa->v4.sin_addr));
+		}
 		return sizeof(sa->v4);
 	}
 
-- 
1.9.1




More information about the CRIU mailing list