[PATCH 2/6][lxc][v3] lxc_restart: Add --statefile option

Michel Normand normand at fr.ibm.com
Wed Mar 31 01:10:06 PDT 2010


unable to apply without manual changes
you have blank character on one line

---
Michel


Le mercredi 31 mars 2010 à 00:07 -0700, Sukadev Bhattiprolu a écrit :
> From: Sukadev Bhattiprolu <sukadev at linux.vnet.ibm.com>
> Date: Sat, 27 Mar 2010 00:08:17 -0700
> Subject: [PATCH 2/6][lxc][v3] lxc_restart: Add --statefile option
> 
> The existing --directory option to lxc_restart expects the checkpoint state
> to be a directory. USERCR however uses a single regular file to store the
> checkpoint image. So add a --statefile option to enable checkpointing and
> restarting applications using USERCR.
> 
> Depending on how the application was checkpointed, users should specify
> either --statefile=STATEFILE or the --directory=STATEFILE option (but not
> both).
> 
> Signed-off-by: Sukadev Bhattiprolu <sukadev at linux.vnet.ibm.com>
> ---
>  src/lxc/lxc_restart.c |   34 +++++++++++++++++++++++++---------
>  1 files changed, 25 insertions(+), 9 deletions(-)
> 
> diff --git a/src/lxc/lxc_restart.c b/src/lxc/lxc_restart.c
> index 7db1d85..de4b421 100644
> --- a/src/lxc/lxc_restart.c
> +++ b/src/lxc/lxc_restart.c
> @@ -38,13 +38,21 @@
>  lxc_log_define(lxc_restart_ui, lxc_restart);
>  
>  static struct lxc_list defines;
> +static char *statedir;
>  
>  static int my_checker(const struct lxc_arguments* args)
>  {
> -	if (!args->statefile) {
> -		lxc_error(args, "no statefile specified");
> -		return -1;
> -	}
> +	int d, f;
> +	
> +	/* make them boolean */
> +	d = !!(statedir);
> +	f = !!(args->statefile);
> +
> +        if (!(d ^ f)) {
> +                lxc_error(args, "Must specify exactly one of --directory "
> +                                "and --statefile options");
> +                return -1;
> +        }
>  
>  	return 0;
>  }
> @@ -52,8 +60,9 @@ static int my_checker(const struct lxc_arguments* args)
>  static int my_parser(struct lxc_arguments* args, int c, char* arg)
>  {
>  	switch (c) {
> -	case 'd': args->statefile = arg; break;
> +	case 'd': statedir = arg; break;
>  	case 'f': args->rcfile = arg; break;
> +	case 'S': args->statefile = arg; break;
>  	case 'p': args->flags = LXC_FLAG_PAUSE; break;
>  	case 's': return lxc_config_define_add(&defines, arg);
>  	}
> @@ -66,21 +75,24 @@ static const struct option my_longopts[] = {
>  	{"rcfile", required_argument, 0, 'f'},
>  	{"pause", no_argument, 0, 'p'},
>  	{"define", required_argument, 0, 's'},
> +	{"statefile", required_argument, 0, 'S'},
>  	LXC_COMMON_OPTIONS
>  };
>  
>  static struct lxc_arguments my_args = {
>  	.progname = "lxc-restart",
>  	.help     = "\
> ---name=NAME --directory STATEFILE\n\
> +--name=NAME --directory STATEFILE (deprecated)\n\
> +\tlxc_restart --name=NAME --statefile=STATEFILE\n\
>  \n\
>  lxc-restart restarts from STATEFILE the NAME container\n\
>  \n\
>  Options :\n\
>    -n, --name=NAME      NAME for name of the container\n\
>    -p, --pause          do not release the container after the restart\n\
> -  -d, --directory=STATEFILE for name of statefile\n\
> +  -d, --directory=STATEFILE for name of statefile (legacy mode, deprecated)\n\
>    -f, --rcfile=FILE Load configuration file FILE\n\
> +  -i, --statefile=STATEFILE Load the application state from STATEFILE (libcr mode)\n\
>    -s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
>  	.options  = my_longopts,
>  	.parser   = my_parser,
> @@ -90,6 +102,7 @@ Options :\n\
>  int main(int argc, char *argv[])
>  {
>  	char *rcfile = NULL;
> +	const char *statefile;
>  	struct lxc_conf *conf;
>  
>  	lxc_list_init(&defines);
> @@ -131,6 +144,9 @@ int main(int argc, char *argv[])
>  	if (lxc_config_define_load(&defines, conf))
>  		return -1;
>  
> -	return lxc_restart(my_args.name, my_args.statefile, conf,
> -			   my_args.flags);
> +	statefile = my_args.statefile;
> +	if (statedir)
> +		statefile = statedir;
> +
> +	return lxc_restart(my_args.name, statefile, conf, my_args.flags);
>  }




More information about the Containers mailing list