[lxc-devel] [PATCH 1/4] Add lxc.ephemeral lxc.ephemeral indicates whether a container will be destroyed on shutdown Can be 0 for non-ephemeral and 1 for ephemeral.

Serge Hallyn serge.hallyn at ubuntu.com
Thu Sep 10 04:28:30 UTC 2015


Quoting Christian Brauner (christianvanbrauner at gmail.com):
> Signed-off-by: Christian Brauner <christianvanbrauner at gmail.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/conf.h    |  3 +++
>  src/lxc/confile.c | 20 ++++++++++++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/src/lxc/conf.h b/src/lxc/conf.h
> index dc5328a..5aebd91 100644
> --- a/src/lxc/conf.h
> +++ b/src/lxc/conf.h
> @@ -370,6 +370,9 @@ struct lxc_conf {
>  	 * should run under when using lxc-execute */
>  	uid_t init_uid;
>  	gid_t init_gid;
> +
> +	/* indicator if the container will be destroyed on shutdown */
> +	int ephemeral;
>  };
>  
>  #ifdef HAVE_TLS
> diff --git a/src/lxc/confile.c b/src/lxc/confile.c
> index ca3b8d8..5f8540e 100644
> --- a/src/lxc/confile.c
> +++ b/src/lxc/confile.c
> @@ -108,6 +108,7 @@ static int config_environment(const char *, const char *, struct lxc_conf *);
>  static int config_init_cmd(const char *, const char *, struct lxc_conf *);
>  static int config_init_uid(const char *, const char *, struct lxc_conf *);
>  static int config_init_gid(const char *, const char *, struct lxc_conf *);
> +static int config_ephemeral(const char *, const char *, struct lxc_conf *);
>  
>  static struct lxc_config_t config[] = {
>  
> @@ -176,6 +177,7 @@ static struct lxc_config_t config[] = {
>  	{ "lxc.init_cmd",             config_init_cmd             },
>  	{ "lxc.init_uid",             config_init_uid             },
>  	{ "lxc.init_gid",             config_init_gid             },
> +	{ "lxc.ephemeral",            config_ephemeral            },
>  };
>  
>  struct signame {
> @@ -2490,6 +2492,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
>  		return lxc_get_conf_int(c, retv, inlen, c->init_uid);
>  	else if (strcmp(key, "lxc.init_gid") == 0)
>  		return lxc_get_conf_int(c, retv, inlen, c->init_gid);
> +	else if (strcmp(key, "lxc.ephemeral") == 0)
> +		return lxc_get_conf_int(c, retv, inlen, c->ephemeral);
>  	else return -1;
>  
>  	if (!v)
> @@ -2759,3 +2763,19 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
>  	}
>  	return true;
>  }
> +
> +static int config_ephemeral(const char *key, const char *value,
> +			    struct lxc_conf *lxc_conf)
> +{
> +	int v = atoi(value);
> +
> +	if (v != 0 && v != 1) {
> +		ERROR("Wrong value for lxc.ephemeral. Can only be set to 0 or 1");
> +		return -1;
> +	} else {
> +		lxc_conf->ephemeral = v;
> +	}
> +
> +	return 0;
> +}
> +
> -- 
> 2.5.1
> 


More information about the lxc-devel mailing list