Commit fe974169 authored by Adrian Reber's avatar Adrian Reber Committed by Andrei Vagin

RPC: add version check interface

Instead of parsing the output of 'criu -V' this offers a RPC interface
to get CRIU's version. In a follow up patch a test script is included
to use the new interface:

 ./version.py
 Connecting to CRIU in swrk mode to check the version:
 RPC: Success
 CRIU major 2
 CRIU minor 12
 CRIU gitid v2.12-635-g6d3ae4d

This change exports the following version fields:
 * major
 * minor
 * gitid (optional)
 * sublevel (optional)
 * extra (optional)
 * name (optional)

The optional gitid field is not set when CRIU is not built from git.
Signed-off-by: 's avatarAdrian Reber <areber@redhat.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent bc169fef
......@@ -15,6 +15,7 @@
#include <arpa/inet.h>
#include <sched.h>
#include "version.h"
#include "crtools.h"
#include "cr_options.h"
#include "external.h"
......@@ -799,10 +800,45 @@ static int chk_keepopen_req(CriuReq *msg)
return 0;
else if (msg->type == CRIU_REQ_TYPE__FEATURE_CHECK)
return 0;
else if (msg->type == CRIU_REQ_TYPE__VERSION)
return 0;
return -1;
}
/*
* Return the version information, depending on the information
* available in version.h
*/
static int handle_version(int sk, CriuReq * msg)
{
CriuResp resp = CRIU_RESP__INIT;
CriuVersion version = CRIU_VERSION__INIT;
/* This assumes we will always have a major and minor version */
version.major = CRIU_VERSION_MAJOR;
version.minor = CRIU_VERSION_MINOR;
if (strcmp(CRIU_GITID, "0")) {
version.gitid = CRIU_GITID;
}
#ifdef CRIU_VERSION_SUBLEVEL
version.has_sublevel = 1;
version.sublevel = CRIU_VERSION_SUBLEVEL;
#endif
#ifdef CRIU_VERSION_EXTRA
version.has_extra = 1;
version.extra = CRIU_VERSION_EXTRA;
#endif
#ifdef CRIU_VERSION_NAME
/* This is not actually exported in version.h */
version.name = CRIU_VERSION_NAME;
#endif
resp.type = msg->type;
resp.success = true;
resp.version = &version;
return send_criu_msg(sk, &resp);
}
/*
* Generic function to handle CRIU_REQ_TYPE__FEATURE_CHECK.
*
......@@ -969,6 +1005,9 @@ more:
case CRIU_REQ_TYPE__FEATURE_CHECK:
ret = handle_feature_check(sk, msg);
break;
case CRIU_REQ_TYPE__VERSION:
ret = handle_version(sk, msg);
break;
default:
send_criu_err(sk, "Invalid req");
......
......@@ -139,6 +139,8 @@ enum criu_req_type {
CPUINFO_CHECK = 8;
FEATURE_CHECK = 9;
VERSION = 10;
}
/*
......@@ -191,4 +193,15 @@ message criu_resp {
optional int32 cr_errno = 7;
optional criu_features features = 8;
optional string cr_errmsg = 9;
optional criu_version version = 10;
}
/* Answer for criu_req_type.VERSION requests */
message criu_version {
required int32 major = 1;
required int32 minor = 2;
optional string gitid = 3;
optional int32 sublevel = 4;
optional int32 extra = 5;
optional string name = 6;
}
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