diff options
author | Michel Normand <normand@fr.ibm.com> | 2009-11-19 15:06:02 +0100 |
---|---|---|
committer | Daniel Lezcano <dlezcano@fr.ibm.com> | 2009-11-19 15:06:02 +0100 |
commit | ad3ac5e0adef246d7ada5dd259537feccf3d6521 (patch) | |
tree | b7c911ff5ef9608c4ad6fd37218eb6f0190d622e | |
parent | remove unused cr_plugin_columbia.c (diff) | |
download | lxc-ad3ac5e0adef246d7ada5dd259537feccf3d6521.tar.gz lxc-ad3ac5e0adef246d7ada5dd259537feccf3d6521.tar.bz2 lxc-ad3ac5e0adef246d7ada5dd259537feccf3d6521.zip |
change C/R api
Change Checkpoint / Restart API
Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
-rw-r--r-- | src/lxc/arguments.h | 3 | ||||
-rw-r--r-- | src/lxc/checkpoint.c | 2 | ||||
-rw-r--r-- | src/lxc/lxc.h | 29 | ||||
-rw-r--r-- | src/lxc/lxc_checkpoint.c | 46 | ||||
-rw-r--r-- | src/lxc/lxc_restart.c | 26 | ||||
-rw-r--r-- | src/lxc/restart.c | 3 |
6 files changed, 48 insertions, 61 deletions
diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index d38de89..71ca669 100644 --- a/src/lxc/arguments.h +++ b/src/lxc/arguments.h @@ -47,8 +47,7 @@ struct lxc_arguments { const char *statefile; /* for lxc-checkpoint */ - int kill; - int pause; + int flags; /* for lxc-console */ int ttynum; diff --git a/src/lxc/checkpoint.c b/src/lxc/checkpoint.c index 8acac31..7e8a93e 100644 --- a/src/lxc/checkpoint.c +++ b/src/lxc/checkpoint.c @@ -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; } diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index a78fb65..66cb3b8 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -27,17 +27,17 @@ 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 diff --git a/src/lxc/lxc_checkpoint.c b/src/lxc/lxc_checkpoint.c index ff59048..018068e 100644 --- a/src/lxc/lxc_checkpoint.c +++ b/src/lxc/lxc_checkpoint.c @@ -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; diff --git a/src/lxc/lxc_restart.c b/src/lxc/lxc_restart.c index 77895a0..17cee0b 100644 --- a/src/lxc/lxc_restart.c +++ b/src/lxc/lxc_restart.c @@ -20,8 +20,10 @@ * 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); } diff --git a/src/lxc/restart.c b/src/lxc/restart.c index 1f42b40..42576c1 100644 --- a/src/lxc/restart.c +++ b/src/lxc/restart.c @@ -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; } |