[CRIU] [PATCH 2/3] p.haul: add criu version check

Nikita Spiridonov nspiridonov at virtuozzo.com
Thu Apr 14 04:18:10 PDT 2016


Check criu version to understand if the migration possible or not.
Assume we can migrate if version of criu on source machine less or
equal than version of criu on target machine.

Signed-off-by: Nikita Spiridonov <nspiridonov at virtuozzo.com>
---
 phaul/iters.py   |   11 +++++++++++
 phaul/service.py |   13 +++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/phaul/iters.py b/phaul/iters.py
index cbac565..93fa539 100644
--- a/phaul/iters.py
+++ b/phaul/iters.py
@@ -108,6 +108,16 @@ class phaul_iter_worker:
 		if not self.target_host.check_cpuinfo():
 			raise Exception("CPUs mismatch")
 
+	def __validate_criu_version(self):
+		if self.__force:
+			return
+		logging.info("Checking criu version")
+		version = criu_api.get_criu_version()
+		if not version:
+			raise Exception("Can't get criu version")
+		if not self.target_host.check_criu_version(version):
+			raise Exception("Incompatible criu versions")
+
 	def __check_support_mem_track(self):
 		req = criu_req.make_dirty_tracking_req(self.img)
 		resp = self.criu_connection.send_req(req)
@@ -159,6 +169,7 @@ class phaul_iter_worker:
 
 		self.fs.set_work_dir(self.img.work_dir())
 		self.__validate_cpu()
+		self.__validate_criu_version()
 		use_pre_dumps = self.__check_use_pre_dumps()
 		root_pid = self.htype.root_task_pid()
 
diff --git a/phaul/service.py b/phaul/service.py
index ecb0cc8..e9e4b9d 100644
--- a/phaul/service.py
+++ b/phaul/service.py
@@ -3,6 +3,7 @@
 #
 
 import logging
+import distutils.version
 import images
 import criu_api
 import criu_req
@@ -99,6 +100,18 @@ class phaul_service:
 		logging.info("\t`- %s", resp.success)
 		return resp.success
 
+	def rpc_check_criu_version(self, source_version):
+		logging.info("Checking criu version")
+		target_version = criu_api.get_criu_version()
+		if not target_version:
+			logging.info("\t`- Can't get criu version")
+			return False
+		result = (distutils.version.LooseVersion(source_version) <=
+			distutils.version.LooseVersion(target_version))
+		logging.info("\t`- %s -> %s", source_version, target_version)
+		logging.info("\t`- %s", result)
+		return result
+
 	def rpc_restore_from_images(self):
 		logging.info("Restoring from images")
 		self.htype.put_meta_images(self.img.image_dir())
-- 
1.7.1



More information about the CRIU mailing list