[CRIU] [PATCH 2/3] service: Allow to server more requests after page-server start

Pavel Emelyanov xemul at parallels.com
Thu Sep 4 09:40:25 PDT 2014


The problem with several requests is that criu leaks resources after
doing dump/restore. It's OK since process exits anyway, but for
multy requests per connection it's better to audit this thing.

For now -- allow to do requests after the page-server-start one only.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-service.c       | 32 ++++++++++++++++++++++++++++++++
 protobuf/rpc.proto |  7 +++++++
 2 files changed, 39 insertions(+)

diff --git a/cr-service.c b/cr-service.c
index d48c2ec..06b531c 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -531,16 +531,41 @@ out:
 	return send_criu_msg(sk, &resp);
 }
 
+static int chk_keepopen_req(CriuReq *msg)
+{
+	if (!msg->keep_open)
+		return 0;
+
+	/*
+	 * Service may (well, it will) leave some
+	 * resources leaked after processing e.g.
+	 * dump or restore requests. Before we audit
+	 * the code for this, let's first enable
+	 * mreq RPCs for those requests we know do
+	 * good work
+	 */
+
+	if (msg->type == CRIU_REQ_TYPE__PAGE_SERVER)
+		/* This just fork()-s so no leaks */
+		return 0;
+
+	return -1;
+}
+
 int cr_service_work(int sk)
 {
 	int ret = -1;
 	CriuReq *msg = 0;
 
+more:
 	if (recv_criu_msg(sk, &msg) == -1) {
 		pr_perror("Can't recv request");
 		goto err;
 	}
 
+	if (chk_keepopen_req(msg))
+		goto err;
+
 	switch (msg->type) {
 	case CRIU_REQ_TYPE__DUMP:
 		ret = dump_using_req(sk, msg->opts);
@@ -562,6 +587,13 @@ int cr_service_work(int sk)
 		send_criu_err(sk, "Invalid req");
 		break;
 	}
+
+	if (!ret && msg->keep_open) {
+		criu_req__free_unpacked(msg, NULL);
+		ret = -1;
+		goto more;
+	}
+
 err:
 	return ret;
 }
diff --git a/protobuf/rpc.proto b/protobuf/rpc.proto
index e9a74b4..8ace89c 100644
--- a/protobuf/rpc.proto
+++ b/protobuf/rpc.proto
@@ -89,6 +89,13 @@ message criu_req {
 
 	optional criu_opts		opts		= 2;
 	optional bool			notify_success	= 3;
+
+	/*
+	 * When set service won't close the connection but
+	 * will wait for more req-s to appear. Works not
+	 * for all request types.
+	 */
+	optional bool			keep_open	= 4;
 }
 
 /*
-- 
1.8.4.2




More information about the CRIU mailing list