Unverified Commit 83a5624a by 2xsec Committed by Christian Brauner

tools: lxc-checkpoint: add default log priority & cleanups

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent eda2d856
...@@ -30,16 +30,24 @@ ...@@ -30,16 +30,24 @@
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
static char *checkpoint_dir = NULL; #define OPT_PREDUMP_DIR (OPT_USAGE + 1)
static bool stop = false;
static bool verbose = false;
static bool do_restore = false;
static bool daemonize_set = false;
static bool pre_dump = false;
static char *predump_dir = NULL;
static char *actionscript_path = NULL;
#define OPT_PREDUMP_DIR OPT_USAGE + 1 lxc_log_define(lxc_checkpoint, lxc);
static int my_parser(struct lxc_arguments *args, int c, char *arg);
static int my_checker(const struct lxc_arguments *args);
static bool checkpoint(struct lxc_container *c);
static bool restore_finalize(struct lxc_container *c);
static bool restore(struct lxc_container *c);
static char *checkpoint_dir;
static bool stop;
static bool verbose;
static bool do_restore;
static bool daemonize_set;
static bool pre_dump;
static char *predump_dir;
static char *actionscript_path;
static const struct option my_longopts[] = { static const struct option my_longopts[] = {
{"checkpoint-dir", required_argument, 0, 'D'}, {"checkpoint-dir", required_argument, 0, 'D'},
...@@ -54,31 +62,39 @@ static const struct option my_longopts[] = { ...@@ -54,31 +62,39 @@ static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS LXC_COMMON_OPTIONS
}; };
lxc_log_define(lxc_checkpoint, lxc); static struct lxc_arguments my_args = {
.progname = "lxc-checkpoint",
static int my_checker(const struct lxc_arguments *args) .help = "\
{ --name=NAME\n\
if (do_restore && stop) { \n\
ERROR("-s not compatible with -r"); lxc-checkpoint checkpoints and restores a container\n\
return -1; Serializes a container's running state to disk to allow restoring it in\n\
its running state at a later time.\n\
} else if (!do_restore && daemonize_set) { \n\
ERROR("-d/-F not compatible with -r"); Options :\n\
return -1; -n, --name=NAME NAME of the container\n\
} -r, --restore Restore container\n\
-D, --checkpoint-dir=DIR directory to save the checkpoint in\n\
if (!checkpoint_dir) { -v, --verbose Enable verbose criu logs\n\
ERROR("-D is required"); -A, --action-script=PATH Path to criu action script\n\
return -1; Checkpoint options:\n\
} -s, --stop Stop the container after checkpointing.\n\
-p, --pre-dump Only pre-dump the memory of the container.\n\
if (pre_dump && do_restore) { Container keeps on running and following\n\
ERROR("-p not compatible with -r"); checkpoints will only dump the changes.\n\
return -1; --predump-dir=DIR path to images from previous dump (relative to -D)\n\
} Restore options:\n\
-d, --daemon Daemonize the container (default)\n\
return 0; -F, --foreground Start with the current tty attached to /dev/console\n\
} --rcfile=FILE Load configuration file FILE\n\
",
.options = my_longopts,
.parser = my_parser,
.daemonize = 1,
.checker = my_checker,
.log_priority = "ERROR",
.log_file = "none",
};
static int my_parser(struct lxc_arguments *args, int c, char *arg) static int my_parser(struct lxc_arguments *args, int c, char *arg)
{ {
...@@ -123,37 +139,29 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg) ...@@ -123,37 +139,29 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
return 0; return 0;
} }
static struct lxc_arguments my_args = { static int my_checker(const struct lxc_arguments *args)
.progname = "lxc-checkpoint", {
.help = "\ if (do_restore && stop) {
--name=NAME\n\ ERROR("-s not compatible with -r");
\n\ return -1;
lxc-checkpoint checkpoints and restores a container\n\
Serializes a container's running state to disk to allow restoring it in\n\ } else if (!do_restore && daemonize_set) {
its running state at a later time.\n\ ERROR("-d/-F not compatible with -r");
\n\ return -1;
Options :\n\ }
-n, --name=NAME NAME of the container\n\
-r, --restore Restore container\n\ if (!checkpoint_dir) {
-D, --checkpoint-dir=DIR directory to save the checkpoint in\n\ ERROR("-D is required");
-v, --verbose Enable verbose criu logs\n\ return -1;
-A, --action-script=PATH Path to criu action script\n\ }
Checkpoint options:\n\
-s, --stop Stop the container after checkpointing.\n\ if (pre_dump && do_restore) {
-p, --pre-dump Only pre-dump the memory of the container.\n\ ERROR("-p not compatible with -r");
Container keeps on running and following\n\ return -1;
checkpoints will only dump the changes.\n\ }
--predump-dir=DIR path to images from previous dump (relative to -D)\n\
Restore options:\n\ return 0;
-d, --daemon Daemonize the container (default)\n\ }
-F, --foreground Start with the current tty attached to /dev/console\n\
--rcfile=FILE Load configuration file FILE\n\
",
.options = my_longopts,
.parser = my_parser,
.daemonize = 1,
.checker = my_checker,
};
static bool checkpoint(struct lxc_container *c) static bool checkpoint(struct lxc_container *c)
{ {
...@@ -262,8 +270,6 @@ int main(int argc, char *argv[]) ...@@ -262,8 +270,6 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv)) if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name; log.name = my_args.name;
log.file = my_args.log_file; log.file = my_args.log_file;
log.level = my_args.log_priority; log.level = my_args.log_priority;
...@@ -273,7 +279,6 @@ int main(int argc, char *argv[]) ...@@ -273,7 +279,6 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log)) if (lxc_log_init(&log))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]); c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) { if (!c) {
......
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