[CRIU] [PATCH 12/12] cpuinfo: rpc -- Add CPUINFO_DUMP/CPUINFO_CHECK commands, v2

Cyrill Gorcunov gorcunov at gmail.com
Tue Sep 30 14:08:34 PDT 2014


On Tue, Sep 30, 2014 at 09:18:55PM +0400, Cyrill Gorcunov wrote:
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>

Updated
-------------- next part --------------
>From fea15362291a525f4b00f7e070968c6890cc831e Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri, 19 Sep 2014 17:56:11 +0400
Subject: [PATCH 12/12] cpuinfo: rpc -- Add CPUINFO_DUMP/CPUINFO_CHECK commands

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-service.c       | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 protobuf/rpc.proto |  3 +++
 2 files changed, 54 insertions(+)

diff --git a/cr-service.c b/cr-service.c
index 9b9f51e4a1c9..f04e4d6fecf1 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -17,6 +17,7 @@
 #include "cr_options.h"
 #include "util.h"
 #include "log.h"
+#include "cpu.h"
 #include "pstree.h"
 #include "cr-service.h"
 #include "cr-service-const.h"
@@ -600,10 +601,56 @@ static int chk_keepopen_req(CriuReq *msg)
 	if (msg->type == CRIU_REQ_TYPE__PAGE_SERVER)
 		/* This just fork()-s so no leaks */
 		return 0;
+	else if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ||
+		 msg->type == CRIU_REQ_TYPE__CPUINFO_CHECK)
+		return 0;
 
 	return -1;
 }
 
+static int handle_cpuinfo(int sk, CriuReq *msg)
+{
+	CriuResp resp = CRIU_RESP__INIT;
+	bool success = false;
+	int pid, status;
+
+	pid = fork();
+	if (pid < 0) {
+		pr_perror("Can't fork");
+		goto out;
+	}
+
+	if (pid == 0) {
+		int ret = 1;
+
+		if (setup_opts_from_req(sk, msg->opts))
+			goto cout;
+
+		setproctitle("cpuinfo %s --rpc -D %s",
+			     msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ?
+			     "dump" : "check",
+			     images_dir);
+
+		if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP)
+			ret = cpuinfo_dump();
+		else
+			ret = cpuinfo_check();
+cout:
+		exit(ret);
+	}
+
+	wait(&status);
+	if (!WIFEXITED(status) || WEXITSTATUS(status))
+		goto out;
+
+	success = true;
+out:
+	resp.type = msg->type;
+	resp.success = success;
+
+	return send_criu_msg(sk, &resp);
+}
+
 int cr_service_work(int sk)
 {
 	int ret = -1;
@@ -634,6 +681,10 @@ more:
 	case CRIU_REQ_TYPE__PAGE_SERVER:
 		ret =  start_page_server_req(sk, msg->opts);
 		break;
+	case CRIU_REQ_TYPE__CPUINFO_DUMP:
+	case CRIU_REQ_TYPE__CPUINFO_CHECK:
+		ret = handle_cpuinfo(sk, msg);
+		break;
 
 	default:
 		send_criu_err(sk, "Invalid req");
diff --git a/protobuf/rpc.proto b/protobuf/rpc.proto
index 4617e7bc3ab1..d511512c5696 100644
--- a/protobuf/rpc.proto
+++ b/protobuf/rpc.proto
@@ -79,6 +79,9 @@ enum criu_req_type {
 	PAGE_SERVER	= 5;
 
 	NOTIFY		= 6;
+
+	CPUINFO_DUMP	= 7;
+	CPUINFO_CHECK	= 8;
 }
 
 /*
-- 
1.9.3



More information about the CRIU mailing list