[CRIU] [PATCH 3/3] zdtm: run page-server via rpc

Andrei Vagin avagin at openvz.org
Tue May 16 22:07:13 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

v2: typo fix
v3: run criu pre-dump via rpc
v4: don't use status-fd for rpc

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 lib/py/criu.py              | 15 ++++++++++++++
 scripts/travis/travis-tests |  1 +
 test/zdtm.py                | 49 +++++++++++++++++++++++++++++++++++++++------
 3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/lib/py/criu.py b/lib/py/criu.py
index f10dbc0..cafaea8 100644
--- a/lib/py/criu.py
+++ b/lib/py/criu.py
@@ -277,6 +277,21 @@ class criu:
 
 		return resp.dump
 
+	def pre_dump(self):
+		"""
+		Checkpoint a process/tree identified by opts.pid.
+		"""
+		req 		= rpc.criu_req()
+		req.type	= rpc.PRE_DUMP
+		req.opts.MergeFrom(self.opts)
+
+		resp = self._send_req_and_recv_resp(req)
+
+		if not resp.success:
+			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
+
+		return resp.dump
+
 	def restore(self):
 		"""
 		Restore a process/tree.
diff --git a/scripts/travis/travis-tests b/scripts/travis/travis-tests
index d8a3e19..5f74d30 100755
--- a/scripts/travis/travis-tests
+++ b/scripts/travis/travis-tests
@@ -87,6 +87,7 @@ ip net add test
 
 # RPC testing
 ./test/zdtm.py run -t zdtm/static/env00 --rpc		# Basic
+./test/zdtm.py run -t zdtm/static/env00 --rpc --pre 2 --page-server
 ./test/zdtm.py run -t zdtm/static/ptrace_sig -f h --rpc # Error handling (crfail test)
 
 ./test/zdtm.py run --empty-ns -T zdtm/static/socket-tcp*-local --iter 2
diff --git a/test/zdtm.py b/test/zdtm.py
index 26b8939..5fcc3e1 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -695,6 +695,14 @@ class criu_cli:
 		return cr.wait()
 
 
+class criu_rpc_process:
+	def wait(self):
+		return self.criu.wait_pid(self.pid)
+
+	def terminate(self):
+		os.kill(self.pid, signal.SIGTERM)
+
+
 class criu_rpc:
 	@staticmethod
 	def __set_opts(criu, args, ctx):
@@ -729,6 +737,25 @@ class criu_rpc:
 			if arg == '--external':
 				criu.opts.external.append(args.pop(0))
 				continue
+			if arg == '--status-fd':
+				fd = int(args.pop(0))
+				os.write(fd, "\0")
+				fcntl.fcntl(fd, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
+				continue
+			if arg == '--port':
+				criu.opts.ps.port = int(args.pop(0))
+				continue
+			if arg == '--address':
+				criu.opts.ps.address = args.pop(0)
+				continue
+			if arg == '--page-server':
+				continue
+			if arg == '--prev-images-dir':
+				criu.opts.parent_img = args.pop(0)
+				continue
+			if arg == '--track-mem':
+				criu.opts.track_mem = True
+				continue
 
 			raise test_fail_exc('RPC for %s required' % arg)
 
@@ -740,17 +767,18 @@ class criu_rpc:
 			raise test_fail_exc('RPC and SAT not supported')
 		if preexec:
 			raise test_fail_exc('RPC and PREEXEC not supported')
-		if nowait:
-			raise test_fail_exc("RPC and status-fd not supported")
 
 		ctx = {}  # Object used to keep info untill action is done
 		criu = crpc.criu()
 		criu.use_binary(criu_bin)
 		criu_rpc.__set_opts(criu, args, ctx)
+		p = None
 
 		try:
 			if action == 'dump':
 				criu.dump()
+			elif action == 'pre-dump':
+				criu.pre_dump()
 			elif action == 'restore':
 				if 'rd' not in ctx:
 					raise test_fail_exc('RPC Non-detached restore is impossible')
@@ -759,10 +787,15 @@ class criu_rpc:
 				pidf = ctx.get('pidf')
 				if pidf:
 					open(pidf, 'w').write('%d\n' % res.pid)
+			elif action == "page-server":
+				res = criu.page_server_chld()
+				p = criu_rpc_process()
+				p.pid = res.pid
+				p.criu = criu
 			else:
 				raise test_fail_exc('RPC for %s required' % action)
-		except crpc.CRIUExceptionExternal:
-			print "Fail"
+		except crpc.CRIUExceptionExternal, e:
+			print "Fail", e
 			ret = -1
 		else:
 			ret = 0
@@ -770,6 +803,10 @@ class criu_rpc:
 		imgd = ctx.get('imgd')
 		if imgd:
 			os.close(imgd)
+
+		if nowait and ret == 0:
+			return p
+
 		return ret
 
 
@@ -1041,11 +1078,11 @@ class criu:
 	def kill(self):
 		if self.__lazy_pages_p:
 			self.__lazy_pages_p.terminate()
-			print "criu lazy-pages exited with %s" & self.wait()
+			print "criu lazy-pages exited with %s" % self.__lazy_pages_p.wait()
 			self.__lazy_pages_p = None
 		if self.__page_server_p:
 			self.__page_server_p.terminate()
-			print "criu page-server exited with %s" & self.wait()
+			print "criu page-server exited with %s" % self.__page_server_p.wait()
 			self.__page_server_p = None
 
 
-- 
2.9.3



More information about the CRIU mailing list