]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc: add --statefile opt to lxc-checkpoint/restart
authorMichel Normand <normand@fr.ibm.com>
Fri, 2 Apr 2010 16:45:47 +0000 (18:45 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Fri, 2 Apr 2010 16:49:11 +0000 (18:49 +0200)
based on patch from: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>

but also:
* remove the deprecated --directory one.
* change liblxc api of checkpoint/restart to use fd and not string.
* explicitely report error messages for the checkpoint/restart stub functions.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/checkpoint.c
src/lxc/lxc.h
src/lxc/lxc_checkpoint.c
src/lxc/lxc_restart.c
src/lxc/restart.c

index 7e8a93e41ac6759b3e3702824b25e053661b5fbd..a2d0d8a0764e5869bb4bdea8ef0222cd8998fd4b 100644 (file)
@@ -25,7 +25,8 @@
 
 lxc_log_define(lxc_checkpoint, lxc);
 
-int lxc_checkpoint(const char *name, const char *statefile, int flags)
+int lxc_checkpoint(const char *name, int sfd, int flags)
 {
-       return 0;
+       ERROR("'checkpoint' function not implemented");
+       return -1;
 }
index b0b9f4e61f578f4e0a50d1a7442f8a7cbc9edc0d..d89102fe31bb0846d1e0fa9cebcdf4da4a531c3d 100644 (file)
@@ -142,23 +142,23 @@ extern const char *lxc_strerror(int error);
 /*
  * Checkpoint a container
  * @name : the name of the container being checkpointed
- * @statefile: string object on which the container is checkpointed
+ * @sfd: fd on which the container is checkpointed
  * @flags : checkpoint flags (an ORed value)
  * Returns 0 on success, < 0 otherwise
  */
-extern int lxc_checkpoint(const char *name, const char *statefile, int flags);
+extern int lxc_checkpoint(const char *name, int sfd, int flags);
 #define LXC_FLAG_PAUSE 1
 #define LXC_FLAG_HALT  2
 
 /*
  * Restart a container
  * @name : the name of the container being restarted
- * @statefile: string object from which the container is restarted
+ * @sfd: fd from which the container is restarted
  * @conf: lxc_conf structure.
  * @flags : restart flags (an ORed value)
  * Returns 0 on success, < 0 otherwise
  */
-extern int lxc_restart(const char *, const char *, struct lxc_conf *, int);
+extern int lxc_restart(const char *, int, struct lxc_conf *, int);
 
 /*
  * Returns the version number of the library
index a8c74a9a3d95a0196be2d3ef3cddd12d61fd35cd..b67a53d070efb4b1395627bec136ed158ac8eb7e 100644 (file)
@@ -27,6 +27,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <fcntl.h>
 
 #include <lxc/lxc.h>
 #include <lxc/log.h>
@@ -52,7 +53,7 @@ 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 'S': args->statefile = arg; break;
        }
        return 0;
 }
@@ -60,14 +61,14 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 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 --statefile STATEFILE\n\
 \n\
 lxc-checkpoint checkpoints in STATEFILE the NAME container\n\
 \n\
@@ -75,7 +76,7 @@ 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",
+  -S, --statefile=STATEFILE file in which to store the statefile\n",
 
        .options  = my_longopts,
        .parser   = my_parser,
@@ -84,19 +85,10 @@ Options :\n\
        .rcfile   = NULL,
 };
 
-static int create_statefile(const char *dir)
-{
-       if (mkdir(dir, 0700) == -1 && errno != EEXIST) {
-               ERROR("'%s' creation error : %m", dir);
-               return -1;
-       }
-
-       return 0;
-}
-
 int main(int argc, char *argv[])
 {
        int ret;
+       int sfd = -1;
 
        ret = lxc_arguments_parse(&my_args, argc, argv);
        if (ret)
@@ -107,11 +99,14 @@ int main(int argc, char *argv[])
        if (ret)
                return ret;
 
-       ret = create_statefile(my_args.statefile);
-       if (ret)
-               return ret;
+#define OPEN_WRITE_MODE O_CREAT | O_RDWR | O_EXCL | O_CLOEXEC | O_LARGEFILE
+       sfd = open(my_args.statefile, OPEN_WRITE_MODE, 0600);
+       if (sfd < 0) {
+               ERROR("'%s' open failure : %m", my_args.statefile);
+               return sfd;
+       }
 
-       ret = lxc_checkpoint(my_args.name, my_args.statefile, my_args.flags);
+       ret = lxc_checkpoint(my_args.name, sfd, my_args.flags);
        if (ret)
                ERROR("failed to checkpoint '%s'", my_args.name);
        else
index 7db1d85da61e45d16ce7bf7ac10e77753f3857e2..6ce5cafd586a7a4b84652e77bccd16e3d5680c28 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <fcntl.h>
 
 #include "log.h"
 #include "lxc.h"
@@ -52,7 +53,7 @@ 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 'S': args->statefile = arg; break;
        case 'f': args->rcfile = arg; break;
        case 'p': args->flags = LXC_FLAG_PAUSE; break;
        case 's': return lxc_config_define_add(&defines, arg);
@@ -62,7 +63,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 }
 
 static const struct option my_longopts[] = {
-       {"directory", required_argument, 0, 'd'},
+       {"statefile", required_argument, 0, 'S'},
        {"rcfile", required_argument, 0, 'f'},
        {"pause", no_argument, 0, 'p'},
        {"define", required_argument, 0, 's'},
@@ -72,14 +73,14 @@ static const struct option my_longopts[] = {
 static struct lxc_arguments my_args = {
        .progname = "lxc-restart",
        .help     = "\
---name=NAME --directory STATEFILE\n\
+--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\
+  -S, --statefile=STATEFILE file from which to read data\n\
   -f, --rcfile=FILE Load configuration file FILE\n\
   -s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
        .options  = my_longopts,
@@ -89,6 +90,7 @@ Options :\n\
 
 int main(int argc, char *argv[])
 {
+       int sfd = -1;
        char *rcfile = NULL;
        struct lxc_conf *conf;
 
@@ -131,6 +133,12 @@ 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);
+#define OPEN_READ_MODE O_RDONLY | O_CLOEXEC | O_LARGEFILE
+       sfd = open(my_args.statefile, OPEN_READ_MODE, 0);
+       if (sfd < 0) {
+               ERROR("'%s' open failure : %m", my_args.statefile);
+               return sfd;
+       }
+
+       return lxc_restart(my_args.name, sfd, conf, my_args.flags);
 }
index 467489ebc29c014690518bb542b3040d3e09c3c2..2fbdabf3086733ca640bca2007a31cd4efe3fbc2 100644 (file)
@@ -25,8 +25,8 @@
 
 lxc_log_define(lxc_restart, lxc);
 
-int lxc_restart(const char *name, const char *statefile, struct lxc_conf *conf,
-               int flags)
+int lxc_restart(const char *name, int sfd, struct lxc_conf *conf, int flags)
 {
-       return 0;
+       ERROR("'restart' function not implemented");
+       return -1;
 }