Commit 23573119 authored by Adrian Reber's avatar Adrian Reber Committed by Pavel Emelyanov

Introduce feature check via RPC

There are still systems which do not support dirty memory tracking.
This offers an interface to query the dirty memory tracking availability
via the new feature check RPC.

This is in preparation of a p.haul change which will use this RPC
interface to automatically detect if pre-dumps should be executed
or not.

This change introduces an additional optional field in the
criu_request and criu_response message (features) which is a
'criu_features' message.

Right now only the check for the memory tracking feature is supported
in the message 'criu_features':
	optional bool                   mem_track       = 1;

v2: Instead of checking for memory tracking only, provide a generic
    interface to check for arbitrary features.

v3: Do not use bitfields for feature encoding but protobuf optional
    message parameters.
Signed-off-by: 's avatarAdrian Reber <areber@redhat.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 29c08d86
......@@ -32,6 +32,7 @@
#include "security.h"
#include "sockets.h"
#include "irmap.h"
#include "kerndat.h"
#include "setproctitle.h"
......@@ -723,10 +724,87 @@ static int chk_keepopen_req(CriuReq *msg)
else if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ||
msg->type == CRIU_REQ_TYPE__CPUINFO_CHECK)
return 0;
else if (msg->type == CRIU_REQ_TYPE__FEATURE_CHECK)
return 0;
return -1;
}
/*
* Generic function to handle CRIU_REQ_TYPE__FEATURE_CHECK.
*
* The function will have resp.sucess = true for most cases
* and the actual result will be in resp.features.
*
* For each feature which has been requested in msg->features
* the corresponding parameter will be set in resp.features.
*/
static int handle_feature_check(int sk, CriuReq * msg)
{
CriuResp resp = CRIU_RESP__INIT;
CriuFeatures feat = CRIU_FEATURES__INIT;
bool success = false;
int pid, status;
/* enable setting of an optional message */
feat.has_mem_track = 1;
feat.mem_track = false;
/*
* Check if the requested feature check can be answered.
*
* This function is right now hard-coded to memory
* tracking detection and needs other/better logic to
* handle multiple feature checks.
*/
if (msg->features->has_mem_track != 1) {
pr_warn("Feature checking for unknown feature.\n");
goto out;
}
/*
* From this point on the function will always
* 'succeed'. If the requested features are supported
* can be seen if the requested optional parameters are
* set in the message 'criu_features'.
*/
success = true;
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("feature-check --rpc -D %s", images_dir);
kerndat_get_dirty_track();
if (kdat.has_dirty_track)
ret = 0;
cout:
exit(ret);
}
wait(&status);
if (!WIFEXITED(status) || WEXITSTATUS(status))
goto out;
feat.mem_track = true;
out:
resp.features = &feat;
resp.type = msg->type;
resp.success = success;
return send_criu_msg(sk, &resp);
}
static int handle_cpuinfo(int sk, CriuReq *msg)
{
CriuResp resp = CRIU_RESP__INIT;
......@@ -804,6 +882,9 @@ more:
case CRIU_REQ_TYPE__CPUINFO_CHECK:
ret = handle_cpuinfo(sk, msg);
break;
case CRIU_REQ_TYPE__FEATURE_CHECK:
ret = handle_feature_check(sk, msg);
break;
default:
send_criu_err(sk, "Invalid req");
......
......@@ -115,6 +115,16 @@ enum criu_req_type {
CPUINFO_DUMP = 7;
CPUINFO_CHECK = 8;
FEATURE_CHECK = 9;
}
/*
* List of features which can queried via
* CRIU_REQ_TYPE__FEATURE_CHECK
*/
message criu_features {
optional bool mem_track = 1;
}
/*
......@@ -134,6 +144,12 @@ message criu_req {
* for all request types.
*/
optional bool keep_open = 4;
/*
* 'features' can be used to query which features
* are supported by the installed criu/kernel
* via RPC.
*/
optional criu_features features = 5;
}
/*
......@@ -151,4 +167,5 @@ message criu_resp {
optional criu_page_server_info ps = 6;
optional int32 cr_errno = 7;
optional criu_features features = 8;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment