[CRIU] [PATCH 1/8] vzctl: save a pid of init in a state file

Kir Kolyshkin kir at openvz.org
Wed May 15 19:35:04 EDT 2013


On 05/15/2013 09:10 AM, Andrey Vagin wrote:
> CRIU requires a pid of the init.


I suggest storing it in next to veipdumpdir
(defined in paths.am as veipdumpdir = $(localstatedir)/lib/vzctl/veip)
Something like /var/lib/vzctl/pids should be fine.

Also, do not make it run-time configurable. Who can ever need it?
This should make the below patch 10 times shorter.

>
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>   etc/vz.conf.in        |  1 +
>   include/res.h         |  1 +
>   include/types.h       |  2 ++
>   include/util.h        |  1 +
>   include/vzctl_param.h |  1 +
>   src/lib/config.c      | 10 ++++++++++
>   src/lib/util.c        |  6 ++++++
>   7 files changed, 22 insertions(+)
>
> diff --git a/etc/vz.conf.in b/etc/vz.conf.in
> index 07da9c7..25ab7d7 100644
> --- a/etc/vz.conf.in
> +++ b/etc/vz.conf.in
> @@ -2,6 +2,7 @@
>   VIRTUOZZO=yes
>   LOCKDIR=@VZDIR@/lock
>   DUMPDIR=@VZDIR@/dump
> +STATEDIR=@VZDIR@/state
>   VE0CPUUNITS=1000
>   VE_STOP_MODE=suspend
>   
> diff --git a/include/res.h b/include/res.h
> index 7060aef..814aec3 100644
> --- a/include/res.h
> +++ b/include/res.h
> @@ -44,6 +44,7 @@ struct env_param {
>   	unsigned long long features_mask;
>   	unsigned long long features_known;
>   	char *osrelease;
> +	char *statedir;
>   };
>   typedef struct env_param env_param_t;
>   
> diff --git a/include/types.h b/include/types.h
> index a4bce73..79e22ca 100644
> --- a/include/types.h
> +++ b/include/types.h
> @@ -61,6 +61,8 @@ typedef unsigned envid_t;
>   #define DEF_DUMPDIR	VZDIR "/dump"
>   #define DEF_DUMPFILE	"Dump.%d"
>   
> +#define DEF_STATEDIR	VZDIR "/state"
> +
>   /* CT states */
>   enum {
>   	STATE_STARTING = 1,
> diff --git a/include/util.h b/include/util.h
> index 0f87e6e..7e12583 100644
> --- a/include/util.h
> +++ b/include/util.h
> @@ -57,6 +57,7 @@ int get_num_cpu(void);
>   int get_lowmem(unsigned long long *mem);
>   unsigned long max_ul(unsigned long val1, unsigned long val2);
>   int get_dump_file(unsigned veid, const char *dumpdir, char *buf, int size);
> +int get_state_file(unsigned veid, const char *statedir, char *buf, int size);
>   int set_not_blk(int fd);
>   void close_fds(int close_std, ...);
>   int move_config(int veid, int action);
> diff --git a/include/vzctl_param.h b/include/vzctl_param.h
> index 99eb655..49ca7fb 100644
> --- a/include/vzctl_param.h
> +++ b/include/vzctl_param.h
> @@ -117,6 +117,7 @@
>   #define PARAM_WAIT		346
>   #define PARAM_IPV6NET		347
>   #define PARAM_VETH_ADD		348
> +#define PARAM_STATEDIR		349
>   
>   #define PARAM_FEATURES		350
>   #define PARAM_NETIF_ADD		351
> diff --git a/src/lib/config.c b/src/lib/config.c
> index 617df6a..914f846 100644
> --- a/src/lib/config.c
> +++ b/src/lib/config.c
> @@ -58,6 +58,7 @@ static vps_config config[] = {
>   /*	Op	*/
>   {"LOCKDIR",	NULL, PARAM_LOCKDIR},
>   {"DUMPDIR",	NULL, PARAM_DUMPDIR},
> +{"STATEDIR",	NULL, PARAM_STATEDIR},
>   /*	Log	*/
>   {"LOGGING",	NULL, PARAM_LOGGING},
>   {"LOG_LEVEL",	NULL, PARAM_LOGLEVEL},
> @@ -1968,6 +1969,9 @@ static int parse(envid_t veid, vps_param *vps_p, char *val, int id)
>   	case PARAM_DUMPDIR:
>   		ret = conf_parse_str(&vps_p->res.cpt.dumpdir, val);
>   		break;
> +	case PARAM_STATEDIR:
> +		ret = conf_parse_str(&vps_p->res.env.statedir, val);
> +		break;
>   	case PARAM_LOGGING:
>   		ret = conf_parse_yesno(&vps_p->log.enable, val);
>   		break;
> @@ -2735,6 +2739,11 @@ static void free_cpt(cpt_param *cpt)
>   	FREE_P(cpt->dumpfile)
>   }
>   
> +static void free_env(env_param_t *env)
> +{
> +	FREE_P(env->statedir)
> +}
> +
>   static void free_name(name_param *name)
>   {
>   	FREE_P(name->name)
> @@ -2743,6 +2752,7 @@ static void free_name(name_param *name)
>   
>   static void free_vps_res(vps_res *res)
>   {
> +	free_env(&res->env);
>   	free_fs(&res->fs);
>   	free_tmpl(&res->tmpl);
>   	free_ub(&res->ub);
> diff --git a/src/lib/util.c b/src/lib/util.c
> index df410ff..90c4a9b 100644
> --- a/src/lib/util.c
> +++ b/src/lib/util.c
> @@ -589,6 +589,12 @@ int get_dump_file(unsigned veid, const char *dumpdir, char *buf, int size)
>   			dumpdir != NULL ? dumpdir : DEF_DUMPDIR, veid);
>   }
>   
> +int get_state_file(unsigned veid, const char *statedir, char *buf, int size)
> +{
> +	return snprintf(buf, size, "%s/%d.pid",
> +			statedir != NULL ? statedir : DEF_STATEDIR, veid);
> +}
> +
>   int set_not_blk(int fd)
>   {
>   	int oldfl, ret;



More information about the CRIU mailing list