Skip to content

Commit

Permalink
Merge pull request #1299 from adrianreber/master
Browse files Browse the repository at this point in the history
lxc-checkpoint: enable dirty memory tracking in criu
  • Loading branch information
stgraber committed Nov 15, 2016
2 parents 748c52b + 9f99a33 commit a8bae55
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lxc/criu.c
Expand Up @@ -398,6 +398,7 @@ static void exec_criu(struct criu_opts *opts)
if (opts->user->predump_dir) {
DECLARE_ARG("--prev-images-dir");
DECLARE_ARG(opts->user->predump_dir);
DECLARE_ARG("--track-mem");
}

if (opts->user->pageserver_address && opts->user->pageserver_port) {
Expand Down
43 changes: 41 additions & 2 deletions src/lxc/tools/lxc_checkpoint.c
Expand Up @@ -36,6 +36,10 @@ 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;

#define OPT_PREDUMP_DIR OPT_USAGE+1

static const struct option my_longopts[] = {
{"checkpoint-dir", required_argument, 0, 'D'},
Expand All @@ -44,6 +48,8 @@ static const struct option my_longopts[] = {
{"restore", no_argument, 0, 'r'},
{"daemon", no_argument, 0, 'd'},
{"foreground", no_argument, 0, 'F'},
{"pre-dump", no_argument, 0, 'p'},
{"predump-dir", required_argument, 0, OPT_PREDUMP_DIR},
LXC_COMMON_OPTIONS
};

Expand All @@ -63,6 +69,11 @@ static int my_checker(const struct lxc_arguments *args)
return -1;
}

if (pre_dump && do_restore) {
lxc_error(args, "-p not compatible with -r.");
return -1;
}

return 0;
}

Expand Down Expand Up @@ -91,6 +102,14 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
args->daemonize = 0;
daemonize_set = true;
break;
case 'p':
pre_dump = true;
break;
case OPT_PREDUMP_DIR:
predump_dir = strdup(arg);
if (!predump_dir)
return -1;
break;
}
return 0;
}
Expand All @@ -111,6 +130,10 @@ Options :\n\
-v, --verbose Enable verbose criu logs\n\
Checkpoint options:\n\
-s, --stop Stop the container after checkpointing.\n\
-p, --pre-dump Only pre-dump the memory of the container.\n\
Container keeps on running and following\n\
checkpoints will only dump the changes.\n\
--predump-dir=DIR path to images from previous dump (relative to -D)\n\
Restore options:\n\
-d, --daemon Daemonize the container (default)\n\
-F, --foreground Start with the current tty attached to /dev/console\n\
Expand All @@ -124,18 +147,34 @@ Options :\n\

static bool checkpoint(struct lxc_container *c)
{
struct migrate_opts opts;
bool ret;
int mode;

if (!c->is_running(c)) {
fprintf(stderr, "%s not running, not checkpointing.\n", my_args.name);
lxc_container_put(c);
return false;
}

ret = c->checkpoint(c, checkpoint_dir, stop, verbose);
memset(&opts, 0, sizeof(opts));

opts.directory = checkpoint_dir;
opts.stop = stop;
opts.verbose = verbose;
opts.predump_dir = predump_dir;

if (pre_dump)
mode = MIGRATE_PRE_DUMP;
else
mode = MIGRATE_DUMP;

ret = c->migrate(c, mode, &opts, sizeof(opts));
lxc_container_put(c);

if (!ret) {
/* the migrate() API does not negate the return code like
* checkpoint() and restore() does. */
if (ret) {
fprintf(stderr, "Checkpointing %s failed.\n", my_args.name);
return false;
}
Expand Down

0 comments on commit a8bae55

Please sign in to comment.