[CRIU] [PATCH] rpc: add constants for cgroups modes

Pavel Emelyanov xemul at parallels.com
Thu Aug 6 05:52:47 PDT 2015


On 08/06/2015 03:39 PM, Ruslan Kuprieiev wrote:
> Signed-off-by: Ruslan Kuprieiev <rkuprieiev at cloudlinux.com>
> ---
>  cr-service.c       | 33 +++++++++++++++++++++++++++++++--
>  lib/criu.c         |  6 +++---
>  lib/criu.h         | 14 ++++++++++++--
>  protobuf/rpc.proto | 12 +++++++++++-
>  4 files changed, 57 insertions(+), 8 deletions(-)
> 
> diff --git a/cr-service.c b/cr-service.c
> index 334681b..d892b18 100644
> --- a/cr-service.c
> +++ b/cr-service.c
> @@ -401,8 +401,37 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  		opts.manage_cgroups = req->manage_cgroups ? CG_MODE_SOFT : CG_MODE_IGNORE;
>  
>  	/* Override the manage_cgroup if mode is set explicitly */
> -	if (req->has_manage_cgroups_mode)
> -		opts.manage_cgroups = req->manage_cgroups_mode;
> +	if (req->has_manage_cgroups_mode) {
> +		unsigned int mode;
> +
> +		switch (req->manage_cgroups_mode) {
> +		case CRIU_CG_MODE__IGNORE:
> +			mode = CG_MODE_IGNORE;
> +			break;
> +		case CRIU_CG_MODE__NONE:
> +			mode = CG_MODE_NONE;
> +			break;
> +		case CRIU_CG_MODE__PROPS:
> +			mode = CG_MODE_PROPS;
> +			break;
> +		case CRIU_CG_MODE__SOFT:
> +			mode = CG_MODE_SOFT;
> +			break;
> +		case CRIU_CG_MODE__FULL:
> +			mode = CG_MODE_FULL;
> +			break;
> +		case CRIU_CG_MODE__STRICT:
> +			mode = CG_MODE_STRICT;
> +			break;
> +		case CRIU_CG_MODE__DEFAULT:
> +			mode = CG_MODE_DEFAULT;
> +			break;
> +		default:
> +			goto err;
> +		}

Can we do it like

if (req->manage_cgroups_mode < MAX_MODE)
	mode = (int)req->manage_cgroups_mode;

and put necessary amount of BUILD_BUG_ON()-s nearby?

> +
> +		opts.manage_cgroups = mode;
> +	}
>  
>  	if (req->has_auto_ext_mnt)
>  		opts.autodetect_ext_mounts = req->auto_ext_mnt;
> diff --git a/lib/criu.c b/lib/criu.c
> index 90f909f..3fac24e 100644
> --- a/lib/criu.c
> +++ b/lib/criu.c
> @@ -375,13 +375,13 @@ void criu_set_manage_cgroups(bool manage)
>  	criu_local_set_manage_cgroups(global_opts, manage);
>  }
>  
> -void criu_local_set_manage_cgroups_mode(criu_opts *opts, unsigned int mode)
> +void criu_local_set_manage_cgroups_mode(criu_opts *opts, enum criu_cg_mode mode)
>  {
>  	opts->rpc->has_manage_cgroups_mode = true;
> -	opts->rpc->manage_cgroups_mode = mode;
> +	opts->rpc->manage_cgroups_mode = (CriuCgMode)mode;
>  }
>  
> -void criu_set_manage_cgroups_mode(unsigned int mode)
> +void criu_set_manage_cgroups_mode(enum criu_cg_mode mode)
>  {
>  	criu_local_set_manage_cgroups_mode(global_opts, mode);
>  }
> diff --git a/lib/criu.h b/lib/criu.h
> index 169b9e3..c22bad3 100644
> --- a/lib/criu.h
> +++ b/lib/criu.h
> @@ -31,6 +31,16 @@ enum criu_service_comm {
>  	CRIU_COMM_BIN
>  };
>  
> +enum criu_cg_mode {
> +	CRIU_CG_MODE_IGNORE	= 0,
> +	CRIU_CG_MODE_NONE	= 1,
> +	CRIU_CG_MODE_PROPS	= 2,
> +	CRIU_CG_MODE_SOFT	= 3,
> +	CRIU_CG_MODE_FULL	= 4,
> +	CRIU_CG_MODE_STRICT	= 5,
> +	CRIU_CG_MODE_DEFAULT	= 6
> +};
> +
>  void criu_set_service_address(char *path);
>  void criu_set_service_fd(int fd);
>  void criu_set_service_binary(char *path);
> @@ -67,7 +77,7 @@ void criu_set_log_file(char *log_file);
>  void criu_set_cpu_cap(unsigned int cap);
>  void criu_set_root(char *root);
>  void criu_set_manage_cgroups(bool manage);
> -void criu_set_manage_cgroups_mode(unsigned int mode);
> +void criu_set_manage_cgroups_mode(enum criu_cg_mode mode);
>  void criu_set_auto_ext_mnt(bool val);
>  void criu_set_ext_sharing(bool val);
>  void criu_set_ext_masters(bool val);
> @@ -167,7 +177,7 @@ void criu_local_set_log_file(criu_opts *opts, char *log_file);
>  void criu_local_set_cpu_cap(criu_opts *opts, unsigned int cap);
>  void criu_local_set_root(criu_opts *opts, char *root);
>  void criu_local_set_manage_cgroups(criu_opts *opts, bool manage);
> -void criu_local_set_manage_cgroups_mode(criu_opts *opts, unsigned int mode);
> +void criu_local_set_manage_cgroups_mode(criu_opts *opts, enum criu_cg_mode mode);
>  void criu_local_set_auto_ext_mnt(criu_opts *opts, bool val);
>  void criu_local_set_ext_sharing(criu_opts *opts, bool val);
>  void criu_local_set_ext_masters(criu_opts *opts, bool val);
> diff --git a/protobuf/rpc.proto b/protobuf/rpc.proto
> index f49325e..04dbfef 100644
> --- a/protobuf/rpc.proto
> +++ b/protobuf/rpc.proto
> @@ -29,6 +29,16 @@ message unix_sk {
>  	required uint32		inode 	= 1;
>  };
>  
> +enum criu_cg_mode {
> +	IGNORE	= 0;
> +	NONE	= 1;
> +	PROPS	= 2;
> +	SOFT	= 3;
> +	FULL	= 4;
> +	STRICT	= 5;
> +	DEFAULT = 6;
> +};
> +
>  message criu_opts {
>  	required int32			images_dir_fd	= 1;
>  	optional int32			pid		= 2; /* if not set on dump, will dump requesting process */
> @@ -75,7 +85,7 @@ message criu_opts {
>  
>  	repeated unix_sk                unix_sk_ino     = 33;
>  
> -	optional uint32                 manage_cgroups_mode = 34;
> +	optional criu_cg_mode		manage_cgroups_mode = 34;
>  }
>  
>  message criu_dump_resp {
> 



More information about the CRIU mailing list