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

Pavel Emelyanov xemul at parallels.com
Tue Sep 30 10:57:45 PDT 2014


On 09/30/2014 09:18 PM, Cyrill Gorcunov wrote:
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-service.c       | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  protobuf/rpc.proto |  3 +++
>  2 files changed, 62 insertions(+)
> 
> diff --git a/cr-service.c b/cr-service.c
> index 9b9f51e4a1c9..550a19dc0e81 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,64 @@ 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, ret;
> +
> +	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;
> +
> +	ret = send_criu_msg(sk, &resp);
> +
> +	if (success == false || ret || !msg->keep_open) {
> +		criu_req__free_unpacked(msg, NULL);
> +		msg->keep_open = false;
> +		ret = -1;

Why do we need this? If ret is not 0, then the ct_service_work
will just go ahead and terminate.

> +	}
> +
> +	return ret;
> +}
> +
>  int cr_service_work(int sk)
>  {
>  	int ret = -1;
> @@ -634,6 +689,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;
>  }
>  
>  /*
> 



More information about the CRIU mailing list