[CRIU] [PATCH 07/11] p.haul: introduce migration mode conception

Nikita Spiridonov nspiridonov at virtuozzo.com
Mon Mar 21 09:35:22 PDT 2016


Introduce migration mode conception so p.haul can work in different
modes now.

Old mode of work referred to as "live" mode. Live mode migrate
memory and fs to target host iteratively while possible, checkpoint
process tree on source host and restore it on target host.

Add stubs for new mode of work reffered to as "restart". Restart mode
migrate fs to target host iteratively while possible, stop process
tree on source host and start it on target host. This mode needed
mainly for containers migration without c/r.

Signed-off-by: Nikita Spiridonov <nspiridonov at virtuozzo.com>
---
 p.haul               |    2 +-
 phaul/args_parser.py |    2 ++
 phaul/iters.py       |   37 ++++++++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/p.haul b/p.haul
index b6fb234..cd9d6a7 100755
--- a/p.haul
+++ b/p.haul
@@ -42,7 +42,7 @@ connection = phaul.connection.establish(args.fdrpc, args.fdmem, args.fdfs)
 
 # Start the migration
 ph_type = args.type, args.id
-worker = phaul.iters.phaul_iter_worker(ph_type, connection)
+worker = phaul.iters.phaul_iter_worker(ph_type, args.mode, connection)
 worker.set_options(vars(args))
 worker.start_migration()
 
diff --git a/phaul/args_parser.py b/phaul/args_parser.py
index a98b64f..165ef60 100644
--- a/phaul/args_parser.py
+++ b/phaul/args_parser.py
@@ -23,6 +23,8 @@ def parse_client_args():
 	parser.add_argument("--fdrpc", type=int, required=True, help="File descriptor of rpc socket")
 	parser.add_argument("--fdmem", type=int, required=True, help="File descriptor of memory socket")
 	parser.add_argument("--fdfs", help="Module specific definition of fs channel")
+	parser.add_argument("--mode", choices=iters.MIGRATION_MODES,
+		default=iters.MIGRATION_MODE_LIVE, help="Mode of migration")
 	parser.add_argument("-v", default=criu_api.def_verb, type=int, dest="verbose", help="Verbosity level")
 	parser.add_argument("--keep-images", default=False, action='store_true', help="Keep images after migration")
 	parser.add_argument("--dst-rpid", default=None, help="Write pidfile on restore")
diff --git a/phaul/iters.py b/phaul/iters.py
index b2bd183..8cd7b94 100644
--- a/phaul/iters.py
+++ b/phaul/iters.py
@@ -12,6 +12,11 @@ import criu_req
 import htype
 import errno
 
+
+MIGRATION_MODE_LIVE = "live"
+MIGRATION_MODE_RESTART = "restart"
+MIGRATION_MODES = (MIGRATION_MODE_LIVE, MIGRATION_MODE_RESTART)
+
 PRE_DUMP_AUTO_DETECT = None
 PRE_DUMP_DISABLE = False
 PRE_DUMP_ENABLE = True
@@ -29,7 +34,8 @@ phaul_iter_grow_max = 10
 
 
 class phaul_iter_worker:
-	def __init__(self, p_type, connection):
+	def __init__(self, p_type, mode, connection):
+		self.__mode = mode
 		self.connection = connection
 		self.target_host = xem_rpc_client.rpc_proxy(self.connection.rpc_sk)
 
@@ -115,6 +121,21 @@ class phaul_iter_worker:
 		return use_pre_dumps
 
 	def start_migration(self):
+		logging.info("Start migration in %s mode", self.__mode)
+		if self.__mode == MIGRATION_MODE_LIVE:
+			self.__start_live_migration()
+		elif self.__mode == MIGRATION_MODE_RESTART:
+			self.__start_restart_migration()
+		else:
+			raise Exception("Unknown migration mode")
+
+	def __start_live_migration(self):
+		"""
+		Start migration in live mode
+
+		Migrate memory and fs to target host iteratively while possible,
+		checkpoint process tree on source host and restore it on target host.
+		"""
 
 		self.fs.set_work_dir(self.img.work_dir())
 		self.__validate_cpu()
@@ -148,7 +169,7 @@ class phaul_iter_worker:
 			migration_stats.handle_iteration(dstats, fsstats)
 
 			# Decide whether we continue iteration or stop and do final dump
-			if not self.__check_iter_progress(iter_index, dstats, prev_dstats):
+			if not self.__check_live_iter_progress(iter_index, dstats, prev_dstats):
 				break
 
 			iter_index += 1
@@ -185,7 +206,17 @@ class phaul_iter_worker:
 		self.img.close()
 		self.criu_connection.close()
 
-	def __check_iter_progress(self, index, dstats, prev_dstats):
+	def __start_restart_migration(self):
+		"""
+		Start migration in restart mode
+
+		Migrate fs to target host iteratively while possible, stop process
+		tree on source host and start it on target host.
+		"""
+
+		raise Exception("Not implemented")
+
+	def __check_live_iter_progress(self, index, dstats, prev_dstats):
 
 		logging.info("Checking iteration progress:")
 
-- 
1.7.1



More information about the CRIU mailing list