From: Sukadev Bhattiprolu <[email protected]>
Date: Wed, 10 Mar 2010 22:24:17 -0800
Subject: [PATCH 3/6][v3][lxc] lxc_checkpoint: Add --statefile option

The existing --directory option to lxc_checkpoint expects to save the
checkpoint state in 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.

Users should specify either --statefile or --directory option (but not both)
to select the file/directory where the application state will be stored.

Signed-off-by: Sukadev Bhattiprolu <[email protected]>
---
 src/lxc/lxc_checkpoint.c |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/lxc/lxc_checkpoint.c b/src/lxc/lxc_checkpoint.c
index a8c74a9..b0cd634 100644
--- a/src/lxc/lxc_checkpoint.c
+++ b/src/lxc/lxc_checkpoint.c
@@ -37,10 +37,19 @@
 
 lxc_log_define(lxc_checkpoint_ui, lxc_checkpoint);
 
+static char *statedir;
+
 static int my_checker(const struct lxc_arguments* args)
 {
-       if (!args->statefile) {
-               lxc_error(args, "no statefile specified");
+       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;
        }
 
@@ -52,7 +61,8 @@ static int my_parser(struct lxc_arguments* args, int c, char* 
arg)
        switch (c) {
        case 'k': args->flags = LXC_FLAG_HALT; break;
        case 'p': args->flags = LXC_FLAG_PAUSE; break;
-       case 'd': args->statefile = arg; break;
+       case 'd': statedir = arg; break;
+       case 'S': args->statefile = arg; break;
        }
        return 0;
 }
@@ -61,13 +71,15 @@ static const struct option my_longopts[] = {
        {"kill", no_argument, 0, 'k'},
        {"pause", no_argument, 0, 'p'},
        {"directory", required_argument, 0, 'd'},
+       {"statefile", required_argument, 0, 'S'},
        LXC_COMMON_OPTIONS
 };
 
 static struct lxc_arguments my_args = {
        .progname = "lxc-checkpoint",
        .help     = "\
---name=NAME --directory STATEFILE\n\
+--name=NAME --directory STATEFILE (deprecated)\n\
+\tlxc_checkpoint --name=NAME --statefile=STATEFILE\n\
 \n\
 lxc-checkpoint checkpoints in STATEFILE the NAME container\n\
 \n\
@@ -75,7 +87,8 @@ Options :\n\
   -n, --name=NAME      NAME for name of the container\n\
   -k, --kill           stop the container after checkpoint\n\
   -p, --pause          don't unfreeze the container after the checkpoint\n\
-  -d, --directory=STATEFILE where to store the statefile\n",
+  -d, --directory=STATEFILE where to store the statefile (deprecated)\n\
+  -i, --statefile=STATEFILE where to store the checkpoint-image (LIBCR 
mode)\n",
 
        .options  = my_longopts,
        .parser   = my_parser,
@@ -97,6 +110,7 @@ static int create_statefile(const char *dir)
 int main(int argc, char *argv[])
 {
        int ret;
+       const char *statefile;
 
        ret = lxc_arguments_parse(&my_args, argc, argv);
        if (ret)
@@ -107,11 +121,15 @@ int main(int argc, char *argv[])
        if (ret)
                return ret;
 
-       ret = create_statefile(my_args.statefile);
-       if (ret)
-               return ret;
+       statefile = my_args.statefile;
+       if (statedir) {
+               statefile = statedir;
+               ret = create_statefile(statefile);
+               if (ret)
+                       return ret;
+       }
 
-       ret = lxc_checkpoint(my_args.name, my_args.statefile, my_args.flags);
+       ret = lxc_checkpoint(my_args.name, statefile, my_args.flags);
        if (ret)
                ERROR("failed to checkpoint '%s'", my_args.name);
        else
-- 
1.6.0.4

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel

Reply via email to