[2/3] lib/py: allow to execute page-server as a child process

Submitted by Andrei Vagin on April 24, 2017, 9:37 p.m.

Details

Message ID 20170424213751.31374-3-avagin@openvz.org
State New
Series "service: allow to run page-server as a child process"
Headers show

Commit Message

Andrei Vagin April 24, 2017, 9:37 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 lib/py/criu.py | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/py/criu.py b/lib/py/criu.py
index c4a09ea..f10dbc0 100644
--- a/lib/py/criu.py
+++ b/lib/py/criu.py
@@ -195,6 +195,7 @@  class criu:
 	def __init__(self):
 		self.use_binary('criu')
 		self.opts = rpc.criu_opts()
+		self.sk = None
 
 	def use_sk(self, sk_name):
 		"""
@@ -227,13 +228,20 @@  class criu:
 			daemon = True
 
 		try:
-			s = self._comm.connect(daemon)
+			if not self.sk:
+				s = self._comm.connect(daemon)
+			else:
+				s = self.sk
+
+			if req.keep_open:
+				self.sk = s
 
 			s.send(req.SerializeToString())
 
 			buf = s.recv(len(s.recv(1, socket.MSG_TRUNC | socket.MSG_PEEK)))
 
-			self._comm.disconnect()
+			if not req.keep_open:
+				self._comm.disconnect()
 
 			resp = rpc.criu_resp()
 			resp.ParseFromString(buf)
@@ -283,3 +291,28 @@  class criu:
 			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
 
 		return resp.restore
+
+	def page_server_chld(self):
+		req		= rpc.criu_req()
+		req.type	= rpc.PAGE_SERVER_CHLD
+		req.opts.MergeFrom(self.opts)
+		req.keep_open   = True
+
+		resp = self._send_req_and_recv_resp(req)
+
+		if not resp.success:
+			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
+
+		return resp.ps
+
+	def wait_pid(self, pid):
+		req		= rpc.criu_req()
+		req.type	= rpc.WAIT_PID
+		req.pid	 = pid
+
+		resp = self._send_req_and_recv_resp(req)
+
+		if not resp.success:
+			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
+
+		return resp.status