]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
change C/R api
authorMichel Normand <normand@fr.ibm.com>
Thu, 19 Nov 2009 14:06:02 +0000 (15:06 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 19 Nov 2009 14:06:02 +0000 (15:06 +0100)
Change Checkpoint / Restart API

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

index d38de89ec1e67b0b0d99612b85212721ebc52b5e..71ca6693889dda7ca9bfdcd215497ef67d3d2fd3 100644 (file)
@@ -47,8 +47,7 @@ struct lxc_arguments {
        const char *statefile;
 
        /* for lxc-checkpoint */
-       int kill;
-       int pause;
+       int flags;
 
        /* for lxc-console */
        int ttynum;
index 8acac310f80d185b7c289a936a59285b22313b32..7e8a93e41ac6759b3e3702824b25e053661b5fbd 100644 (file)
@@ -25,7 +25,7 @@
 
 lxc_log_define(lxc_checkpoint, lxc);
 
-int lxc_checkpoint(const char *name, int fd, unsigned long flags)
+int lxc_checkpoint(const char *name, const char *statefile, int flags)
 {
        return 0;
 }
index a78fb65d7861b3a9826711bb625a1eb08429d83a..66cb3b8c24b5c739a9d447f5feaab454d94740bd 100644 (file)
 extern "C" {
 #endif
 
+#include <stddef.h>
+#include <lxc/state.h>
+
+struct lxc_msg;
+
 /**
  Following code is for liblxc.
 
  lxc/lxc.h will contain exports of liblxc
  **/
 
-#include <stddef.h>
-#include <lxc/state.h>
-
-struct lxc_msg;
-
 /*
  * Start the specified command inside a container
  * @name     : the name of the container
@@ -139,22 +139,25 @@ extern int lxc_cgroup_get(const char *name, const char *subsystem,
 extern const char *lxc_strerror(int error);
 
 /*
- * Checkpoint a container previously frozen
+ * Checkpoint a container
  * @name : the name of the container being checkpointed
- * @fd : file descriptor on which the container is checkpointed
- * @flags : checkpoint flags
+ * @statefile: string object 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, int fd, unsigned long flags);
+extern int lxc_checkpoint(const char *name, const char *statefile, int flags);
+#define LXC_FLAG_PAUSE 1
+#define LXC_FLAG_HALT  2
 
 /*
- * Restart a container previously frozen
+ * Restart a container
  * @name : the name of the container being restarted
- * @fd : file descriptor from which the container is restarted
- * @flags : restart flags
+ * @statefile: string object from which the container is restarted
+ * @rcfile: container configuration file.
+ * @flags : restart flags (an ORed value)
  * Returns 0 on success, < 0 otherwise
  */
-extern int lxc_restart(const char *name, int fd, unsigned long flags);
+extern int lxc_restart(const char *, const char *, const char *, int);
 
 /*
  * Returns the version number of the library
index ff59048e6cc5f6d86a497fe9bf84143667b48595..018068e970a16b0175c87a9fed4a05956d26a9d3 100644 (file)
@@ -23,8 +23,9 @@
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
-#include <libgen.h>
 #include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 
 #include <lxc/lxc.h>
@@ -49,8 +50,8 @@ static int my_checker(const struct lxc_arguments* args)
 static int my_parser(struct lxc_arguments* args, int c, char* arg)
 {
        switch (c) {
-       case 'k': args->kill = 1; break;
-       case 'p': args->pause = 1; break;
+       case 'k': args->flags = LXC_FLAG_HALT; break;
+       case 'p': args->flags = LXC_FLAG_PAUSE; break;
        case 'd': args->statefile = arg; break;
        }
        return 0;
@@ -83,40 +84,19 @@ Options :\n\
        .rcfile   = NULL,
 };
 
-static int save_config_file(const char *name, const char *dir)
+static int create_statefile(const char *dir)
 {
-       char *src, *dst;
-       int ret;
-
-       if (!asprintf(&src, LXCPATH "/%s/config", name)) {
-               ERROR("failed to allocate memory");
-               return -1;
-       }
-
-       if (access(src, F_OK)) {
-               free(src);
-               return 0;
-       }
-
-       if (!asprintf(&dst, "%s/config", dir)) {
-               ERROR("failed to allocate memory");
-               free(src);
+       if (mkdir(dir, 0700) == -1 && errno != EEXIST) {
+               ERROR("'%s' creation error : %m", dir);
                return -1;
        }
 
-       ret = lxc_copy_file(src, dst);
-       if (ret)
-               ERROR("failed to copy '%s' to '%s'", src, dst);
-
-       free(src);
-       free(dst);
-
-       return ret;
+       return 0;
 }
 
 int main(int argc, char *argv[])
 {
-       int ret = -1;
+       int ret;
 
        ret = lxc_arguments_parse(&my_args, argc, argv);
        if (ret)
@@ -127,13 +107,11 @@ int main(int argc, char *argv[])
        if (ret)
                return ret;
 
-       ret = save_config_file(my_args.name, my_args.statefile);
-       if (ret) {
-               ERROR("failed to save the configuration");
+       ret = create_statefile(my_args.statefile);
+       if (ret)
                return ret;
-       }
 
-       ret = lxc_checkpoint(my_args.name, -1, 0);
+       ret = lxc_checkpoint(my_args.name, my_args.statefile, my_args.flags);
        if (ret) {
                ERROR("failed to checkpoint '%s'", my_args.name);
                return ret;
index 77895a08449743f538d4a4018e802320e28f44b9..17cee0b7013da392839a73eaa865a4d57452af1b 100644 (file)
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
+#define _GNU_SOURCE
 #include <stdio.h>
-#include <libgen.h>
+#undef _GNU_SOURCE
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
 
@@ -30,6 +32,8 @@
 
 #include "arguments.h"
 
+lxc_log_define(lxc_restart, lxc);
+
 static int my_checker(const struct lxc_arguments* args)
 {
        if (!args->statefile) {
@@ -43,9 +47,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': args->statefile = arg; break;
+       case 'f': args->rcfile = arg; break;
+       case 'p': args->flags = LXC_FLAG_PAUSE; break;
        }
 
        return 0;
@@ -53,6 +57,8 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 
 static const struct option my_longopts[] = {
        {"directory", required_argument, 0, 'd'},
+       {"rcfile", required_argument, 0, 'f'},
+       {"pause", no_argument, 0, 'p'},
        LXC_COMMON_OPTIONS
 };
 
@@ -64,8 +70,10 @@ static struct lxc_arguments my_args = {
 lxc-restart restarts from STATEFILE the NAME container\n\
 \n\
 Options :\n\
-  -n, --name=NAME           NAME for name of the container\n\
-  -d, --directory=STATEFILE for name of statefile\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\
+  -f, --rcfile=FILE Load configuration file FILE\n",
        .options  = my_longopts,
        .parser   = my_parser,
        .checker  = my_checker,
@@ -80,8 +88,6 @@ int main(int argc, char *argv[])
                         my_args.progname, my_args.quiet))
                return -1;
 
-       if (lxc_restart(my_args.name, -1, 0))
-               return -1;
-
-       return 0;
+       return lxc_restart(my_args.name, my_args.statefile, my_args.rcfile,
+                          my_args.flags);
 }
index 1f42b40e9dfae71c7337e111e95fd90b3dd6e2aa..42576c1481640f9563c249531cc10c6c80a75361 100644 (file)
@@ -25,7 +25,8 @@
 
 lxc_log_define(lxc_restart, lxc);
 
-int lxc_restart(const char *name, int fd, unsigned long flags)
+int lxc_restart(const char *name, const char *statefile, const char *rcfile,
+               int flags)
 {
        return 0;
 }