Commit ad3ac5e0 by Michel Normand Committed by Daniel Lezcano

change C/R api

Change Checkpoint / Restart API Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 55237dfa
......@@ -47,8 +47,7 @@ struct lxc_arguments {
const char *statefile;
/* for lxc-checkpoint */
int kill;
int pause;
int flags;
/* for lxc-console */
int ttynum;
......
......@@ -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;
}
......@@ -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
......
......@@ -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;
......
......@@ -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);
}
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment