[v2,1/2] RPC: add version check interface

Submitted by Adrian Reber on April 6, 2017, 3:03 p.m.

Details

Message ID 20170406150330.3818-1-adrian@lisas.de
State New
Series "Series without cover letter"
Headers show

Commit Message

Adrian Reber April 6, 2017, 3:03 p.m.
From: Adrian Reber <areber@redhat.com>

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: Adrian Reber <areber@redhat.com>
---
 criu/cr-service.c | 39 +++++++++++++++++++++++++++++++++++++++
 images/rpc.proto  | 13 +++++++++++++
 2 files changed, 52 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/cr-service.c b/criu/cr-service.c
index 78142b0..d59ab8b 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -15,6 +15,7 @@ 
 #include <arpa/inet.h>
 #include <sched.h>
 
+#include "version.h"
 #include "crtools.h"
 #include "cr_options.h"
 #include "external.h"
@@ -806,11 +807,46 @@  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.
  *
  * The function will have resp.success = true for most cases
@@ -1004,6 +1040,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");
diff --git a/images/rpc.proto b/images/rpc.proto
index f894ae1..48e42e2 100644
--- a/images/rpc.proto
+++ b/images/rpc.proto
@@ -140,6 +140,8 @@  enum criu_req_type {
 	CPUINFO_CHECK	= 8;
 
 	FEATURE_CHECK	= 9;
+
+	VERSION		= 10;
 }
 
 /*
@@ -193,4 +195,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;
 }

Comments

Andrei Vagin April 7, 2017, 10:39 p.m.
Applied, thanks!

On Thu, Apr 06, 2017 at 05:03:29PM +0200, Adrian Reber wrote:
> From: Adrian Reber <areber@redhat.com>
> 
> 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: Adrian Reber <areber@redhat.com>
> ---
>  criu/cr-service.c | 39 +++++++++++++++++++++++++++++++++++++++
>  images/rpc.proto  | 13 +++++++++++++
>  2 files changed, 52 insertions(+)
> 
> diff --git a/criu/cr-service.c b/criu/cr-service.c
> index 78142b0..d59ab8b 100644
> --- a/criu/cr-service.c
> +++ b/criu/cr-service.c
> @@ -15,6 +15,7 @@
>  #include <arpa/inet.h>
>  #include <sched.h>
>  
> +#include "version.h"
>  #include "crtools.h"
>  #include "cr_options.h"
>  #include "external.h"
> @@ -806,11 +807,46 @@ 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.
>   *
>   * The function will have resp.success = true for most cases
> @@ -1004,6 +1040,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");
> diff --git a/images/rpc.proto b/images/rpc.proto
> index f894ae1..48e42e2 100644
> --- a/images/rpc.proto
> +++ b/images/rpc.proto
> @@ -140,6 +140,8 @@ enum criu_req_type {
>  	CPUINFO_CHECK	= 8;
>  
>  	FEATURE_CHECK	= 9;
> +
> +	VERSION		= 10;
>  }
>  
>  /*
> @@ -193,4 +195,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;
>  }
> -- 
> 2.9.3
>