]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/criu.c
2 * lxc: linux Container library
4 * Copyright © 2014-2015 Canonical Ltd.
7 * Tycho Andersen <tycho.andersen@canonical.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <linux/limits.h>
31 #include <sys/mount.h>
32 #include <sys/types.h>
49 #define CRIU_VERSION "2.0"
51 #define CRIU_GITID_VERSION "2.0"
52 #define CRIU_GITID_PATCHLEVEL 0
54 #define CRIU_IN_FLIGHT_SUPPORT "2.4"
56 lxc_log_define(lxc_criu
, lxc
);
59 /* The type of criu invocation, one of "dump" or "restore" */
62 /* the user-provided migrate options relevant to this action */
63 struct migrate_opts
*user
;
65 /* The container to dump */
66 struct lxc_container
*c
;
68 /* dump: stop the container or not after dumping? */
69 char tty_id
[32]; /* the criu tty id for /dev/console, i.e. "tty[${rdev}:${dev}]" */
71 /* restore: the file to write the init process' pid into */
72 struct lxc_handler
*handler
;
74 /* The path that is bind mounted from /dev/console, if any. We don't
75 * want to use `--ext-mount-map auto`'s result here because the pts
76 * device may have a different path (e.g. if the pty number is
77 * different) on the target host. NULL if lxc.console = "none".
81 /* The detected version of criu */
85 static int load_tty_major_minor(char *directory
, char *output
, int len
)
91 ret
= snprintf(path
, sizeof(path
), "%s/tty.info", directory
);
92 if (ret
< 0 || ret
>= sizeof(path
)) {
93 ERROR("snprintf'd too many chacters: %d", ret
);
99 /* This means we're coming from a liblxc which didn't export
100 * the tty info. In this case they had to have lxc.console =
101 * none, so there's no problem restoring.
106 SYSERROR("couldn't open %s", path
);
110 if (!fgets(output
, len
, f
)) {
112 SYSERROR("couldn't read %s", path
);
120 static void exec_criu(struct criu_opts
*opts
)
122 char **argv
, log
[PATH_MAX
];
123 int static_args
= 23, argc
= 0, i
, ret
;
127 char buf
[4096], tty_info
[32];
129 /* If we are currently in a cgroup /foo/bar, and the container is in a
130 * cgroup /lxc/foo, lxcfs will give us an ENOENT if some task in the
131 * container has an open fd that points to one of the cgroup files
132 * (systemd always opens its "root" cgroup). So, let's escape to the
133 * /actual/ root cgroup so that lxcfs thinks criu has enough rights to
136 if (!cgroup_escape()) {
137 ERROR("failed to escape cgroups");
141 /* The command line always looks like:
142 * criu $(action) --tcp-established --file-locks --link-remap \
143 * --manage-cgroups=full --action-script foo.sh -D $(directory) \
144 * -o $(directory)/$(action).log --ext-mount-map auto
145 * --enable-external-sharing --enable-external-masters
146 * --enable-fs hugetlbfs --enable-fs tracefs --ext-mount-map console:/dev/pts/n
147 * +1 for final NULL */
149 if (strcmp(opts
->action
, "dump") == 0 || strcmp(opts
->action
, "pre-dump") == 0) {
150 /* -t pid --freeze-cgroup /lxc/ct */
153 /* --prev-images-dir <path-to-directory-A-relative-to-B> */
154 if (opts
->user
->predump_dir
)
157 /* --page-server --address <address> --port <port> */
158 if (opts
->user
->pageserver_address
&& opts
->user
->pageserver_port
)
161 /* --leave-running (only for final dump) */
162 if (strcmp(opts
->action
, "dump") == 0 && !opts
->user
->stop
)
165 /* --external tty[88,4] */
170 if (!opts
->user
->preserves_inodes
)
173 /* --ghost-limit 1024 */
174 if (opts
->user
->ghost_limit
)
176 } else if (strcmp(opts
->action
, "restore") == 0) {
177 /* --root $(lxc_mount_point) --restore-detached
179 * --lsm-profile apparmor:whatever
184 if (load_tty_major_minor(opts
->user
->directory
, tty_info
, sizeof(tty_info
)))
187 /* --inherit-fd fd[%d]:tty[%s] */
194 if (cgroup_num_hierarchies() > 0)
195 static_args
+= 2 * cgroup_num_hierarchies();
197 if (opts
->user
->verbose
)
200 if (opts
->user
->action_script
)
203 ret
= snprintf(log
, PATH_MAX
, "%s/%s.log", opts
->user
->directory
, opts
->action
);
204 if (ret
< 0 || ret
>= PATH_MAX
) {
205 ERROR("logfile name too long\n");
209 argv
= malloc(static_args
* sizeof(*argv
));
213 memset(argv
, 0, static_args
* sizeof(*argv
));
215 #define DECLARE_ARG(arg) \
218 ERROR("Got NULL argument for criu"); \
221 argv[argc++] = strdup(arg); \
226 argv
[argc
++] = on_path("criu", NULL
);
228 ERROR("Couldn't find criu binary\n");
232 DECLARE_ARG(opts
->action
);
233 DECLARE_ARG("--tcp-established");
234 DECLARE_ARG("--file-locks");
235 DECLARE_ARG("--link-remap");
236 DECLARE_ARG("--manage-cgroups=full");
237 DECLARE_ARG("--ext-mount-map");
239 DECLARE_ARG("--enable-external-sharing");
240 DECLARE_ARG("--enable-external-masters");
241 DECLARE_ARG("--enable-fs");
242 DECLARE_ARG("hugetlbfs");
243 DECLARE_ARG("--enable-fs");
244 DECLARE_ARG("tracefs");
246 DECLARE_ARG(opts
->user
->directory
);
250 for (i
= 0; i
< cgroup_num_hierarchies(); i
++) {
251 char **controllers
= NULL
, *fullname
;
254 if (!cgroup_get_hierarchies(i
, &controllers
)) {
255 ERROR("failed to get hierarchy %d", i
);
259 /* if we are in a dump, we have to ask the monitor process what
260 * the right cgroup is. if this is a restore, we can just use
261 * the handler the restore task created.
263 if (!strcmp(opts
->action
, "dump") || !strcmp(opts
->action
, "pre-dump")) {
264 path
= lxc_cmd_get_cgroup_path(opts
->c
->name
, opts
->c
->config_path
, controllers
[0]);
266 ERROR("failed to get cgroup path for %s", controllers
[0]);
272 p
= cgroup_get_cgroup(opts
->handler
, controllers
[0]);
274 ERROR("failed to get cgroup path for %s", controllers
[0]);
280 ERROR("strdup failed");
285 if (!lxc_deslashify(&path
)) {
286 ERROR("failed to deslashify %s", path
);
291 fullname
= lxc_string_join(",", (const char **) controllers
, false);
293 ERROR("failed to join controllers");
298 ret
= sprintf(buf
, "%s:%s", fullname
, path
);
301 if (ret
< 0 || ret
>= sizeof(buf
)) {
302 ERROR("sprintf of cgroup root arg failed");
306 DECLARE_ARG("--cgroup-root");
310 if (opts
->user
->verbose
)
311 DECLARE_ARG("-vvvvvv");
313 if (opts
->user
->action_script
) {
314 DECLARE_ARG("--action-script");
315 DECLARE_ARG(opts
->user
->action_script
);
318 if (strcmp(opts
->action
, "dump") == 0 || strcmp(opts
->action
, "pre-dump") == 0) {
319 char pid
[32], *freezer_relative
;
321 if (sprintf(pid
, "%d", opts
->c
->init_pid(opts
->c
)) < 0)
327 freezer_relative
= lxc_cmd_get_cgroup_path(opts
->c
->name
,
328 opts
->c
->config_path
,
330 if (!freezer_relative
) {
331 ERROR("failed getting freezer path");
335 ret
= snprintf(log
, sizeof(log
), "/sys/fs/cgroup/freezer/%s", freezer_relative
);
336 if (ret
< 0 || ret
>= sizeof(log
))
339 if (!opts
->user
->disable_skip_in_flight
&&
340 strcmp(opts
->criu_version
, CRIU_IN_FLIGHT_SUPPORT
) >= 0)
341 DECLARE_ARG("--skip-in-flight");
343 DECLARE_ARG("--freeze-cgroup");
346 if (opts
->tty_id
[0]) {
347 DECLARE_ARG("--ext-mount-map");
348 DECLARE_ARG("/dev/console:console");
350 DECLARE_ARG("--external");
351 DECLARE_ARG(opts
->tty_id
);
354 if (opts
->user
->predump_dir
) {
355 DECLARE_ARG("--prev-images-dir");
356 DECLARE_ARG(opts
->user
->predump_dir
);
359 if (opts
->user
->pageserver_address
&& opts
->user
->pageserver_port
) {
360 DECLARE_ARG("--page-server");
361 DECLARE_ARG("--address");
362 DECLARE_ARG(opts
->user
->pageserver_address
);
363 DECLARE_ARG("--port");
364 DECLARE_ARG(opts
->user
->pageserver_port
);
367 if (!opts
->user
->preserves_inodes
)
368 DECLARE_ARG("--force-irmap");
370 if (opts
->user
->ghost_limit
) {
371 char ghost_limit
[32];
373 ret
= sprintf(ghost_limit
, "%"PRIu64
, opts
->user
->ghost_limit
);
374 if (ret
< 0 || ret
>= sizeof(ghost_limit
)) {
375 ERROR("failed to print ghost limit %"PRIu64
, opts
->user
->ghost_limit
);
379 DECLARE_ARG("--ghost-limit");
380 DECLARE_ARG(ghost_limit
);
383 /* only for final dump */
384 if (strcmp(opts
->action
, "dump") == 0 && !opts
->user
->stop
)
385 DECLARE_ARG("--leave-running");
386 } else if (strcmp(opts
->action
, "restore") == 0) {
389 struct lxc_conf
*lxc_conf
= opts
->c
->lxc_conf
;
391 DECLARE_ARG("--root");
392 DECLARE_ARG(opts
->c
->lxc_conf
->rootfs
.mount
);
393 DECLARE_ARG("--restore-detached");
394 DECLARE_ARG("--restore-sibling");
397 if (opts
->console_fd
< 0) {
398 ERROR("lxc.console configured on source host but not target");
402 ret
= snprintf(buf
, sizeof(buf
), "fd[%d]:%s", opts
->console_fd
, tty_info
);
403 if (ret
< 0 || ret
>= sizeof(buf
))
406 DECLARE_ARG("--inherit-fd");
409 if (opts
->console_name
) {
410 if (snprintf(buf
, sizeof(buf
), "console:%s", opts
->console_name
) < 0) {
411 SYSERROR("sprintf'd too many bytes");
413 DECLARE_ARG("--ext-mount-map");
417 if (lxc_conf
->lsm_aa_profile
|| lxc_conf
->lsm_se_context
) {
419 if (lxc_conf
->lsm_aa_profile
)
420 ret
= snprintf(buf
, sizeof(buf
), "apparmor:%s", lxc_conf
->lsm_aa_profile
);
422 ret
= snprintf(buf
, sizeof(buf
), "selinux:%s", lxc_conf
->lsm_se_context
);
424 if (ret
< 0 || ret
>= sizeof(buf
))
427 DECLARE_ARG("--lsm-profile");
431 additional
= lxc_list_len(&opts
->c
->lxc_conf
->network
) * 2;
433 m
= realloc(argv
, (argc
+ additional
+ 1) * sizeof(*argv
));
438 lxc_list_for_each(it
, &opts
->c
->lxc_conf
->network
) {
439 char eth
[128], *veth
;
440 struct lxc_netdev
*n
= it
->elem
;
442 if (n
->type
!= LXC_NET_VETH
)
446 if (strlen(n
->name
) >= sizeof(eth
))
448 strncpy(eth
, n
->name
, sizeof(eth
));
450 sprintf(eth
, "eth%d", netnr
);
452 veth
= n
->priv
.veth_attr
.pair
;
455 ret
= snprintf(buf
, sizeof(buf
), "%s=%s@%s", eth
, veth
, n
->link
);
457 ret
= snprintf(buf
, sizeof(buf
), "%s=%s", eth
, veth
);
458 if (ret
< 0 || ret
>= sizeof(buf
))
461 DECLARE_ARG("--veth-pair");
472 for (i
= 0; argv
[i
]; i
++) {
473 ret
= snprintf(buf
+ pos
, sizeof(buf
) - pos
, "%s ", argv
[i
]);
474 if (ret
< 0 || ret
>= sizeof(buf
) - pos
)
480 INFO("execing: %s", buf
);
483 execv(argv
[0], argv
);
485 for (i
= 0; argv
[i
]; i
++)
491 * Check to see if the criu version is recent enough for all the features we
492 * use. This version allows either CRIU_VERSION or (CRIU_GITID_VERSION and
493 * CRIU_GITID_PATCHLEVEL) to work, enabling users building from git to c/r
494 * things potentially before a version is released with a particular feature.
496 * The intent is that when criu development slows down, we can drop this, but
497 * for now we shouldn't attempt to c/r with versions that we know won't work.
499 * Note: If version != NULL criu_version() stores the detected criu version in
500 * version. Allocates memory for version which must be freed by caller.
502 static bool criu_version_ok(char **version
)
507 if (pipe(pipes
) < 0) {
508 SYSERROR("pipe() failed");
514 SYSERROR("fork() failed");
519 char *args
[] = { "criu", "--version", NULL
};
523 close(STDERR_FILENO
);
524 if (dup2(pipes
[1], STDOUT_FILENO
) < 0)
527 path
= on_path("criu", NULL
);
539 if (wait_for_pid(pid
) < 0) {
541 SYSERROR("execing criu failed, is it installed?");
545 f
= fdopen(pipes
[0], "r");
557 if (fscanf(f
, "Version: %1023[^\n]s", tmp
) != 1)
560 if (fgetc(f
) != '\n')
563 if (strcmp(tmp
, CRIU_VERSION
) >= 0)
566 if (fscanf(f
, "GitID: v%1023[^-]s", tmp
) != 1)
572 if (fscanf(f
, "%d", &patch
) != 1)
575 if (strcmp(tmp
, CRIU_GITID_VERSION
) < 0)
578 if (patch
< CRIU_GITID_PATCHLEVEL
)
592 ERROR("must have criu " CRIU_VERSION
" or greater to checkpoint/restore\n");
597 /* Check and make sure the container has a configuration that we know CRIU can
599 static bool criu_ok(struct lxc_container
*c
, char **criu_version
)
603 if (!criu_version_ok(criu_version
))
607 ERROR("Must be root to checkpoint\n");
611 /* We only know how to restore containers with veth networks. */
612 lxc_list_for_each(it
, &c
->lxc_conf
->network
) {
613 struct lxc_netdev
*n
= it
->elem
;
620 ERROR("Found network that is not VETH or NONE\n");
628 static bool restore_net_info(struct lxc_container
*c
)
631 bool has_error
= true;
633 if (container_mem_lock(c
))
636 lxc_list_for_each(it
, &c
->lxc_conf
->network
) {
637 struct lxc_netdev
*netdev
= it
->elem
;
638 char template[IFNAMSIZ
];
640 if (netdev
->type
!= LXC_NET_VETH
)
643 snprintf(template, sizeof(template), "vethXXXXXX");
645 if (!netdev
->priv
.veth_attr
.pair
)
646 netdev
->priv
.veth_attr
.pair
= lxc_mkifname(template);
648 if (!netdev
->priv
.veth_attr
.pair
)
655 container_mem_unlock(c
);
659 // do_restore never returns, the calling process is used as the
660 // monitor process. do_restore calls exit() if it fails.
661 static void do_restore(struct lxc_container
*c
, int status_pipe
, struct migrate_opts
*opts
, char *criu_version
)
664 struct lxc_handler
*handler
;
666 int pipes
[2] = {-1, -1};
668 /* Try to detach from the current controlling tty if it exists.
669 * Othwerise, lxc_init (via lxc_console) will attach the container's
670 * console output to the current tty, which is probably not what any
671 * library user wants, and if they do, they can just manually configure
674 fd
= open("/dev/tty", O_RDWR
);
676 if (ioctl(fd
, TIOCNOTTY
, NULL
) < 0)
677 SYSERROR("couldn't detach from tty");
681 handler
= lxc_init(c
->name
, c
->lxc_conf
, c
->config_path
);
685 if (!cgroup_init(handler
)) {
686 ERROR("failed initing cgroups");
687 goto out_fini_handler
;
690 if (!cgroup_create(handler
)) {
691 ERROR("failed creating groups");
692 goto out_fini_handler
;
695 if (!restore_net_info(c
)) {
696 ERROR("failed restoring network info");
697 goto out_fini_handler
;
700 resolve_clone_flags(handler
);
702 if (pipe(pipes
) < 0) {
703 SYSERROR("pipe() failed");
704 goto out_fini_handler
;
709 goto out_fini_handler
;
713 struct lxc_rootfs
*rootfs
;
721 if (dup2(pipes
[1], STDERR_FILENO
) < 0) {
722 SYSERROR("dup2 failed");
723 goto out_fini_handler
;
726 if (dup2(pipes
[1], STDOUT_FILENO
) < 0) {
727 SYSERROR("dup2 failed");
728 goto out_fini_handler
;
731 if (unshare(CLONE_NEWNS
))
732 goto out_fini_handler
;
734 /* CRIU needs the lxc root bind mounted so that it is the root of some
736 rootfs
= &c
->lxc_conf
->rootfs
;
738 if (rootfs_is_blockdev(c
->lxc_conf
)) {
739 if (do_rootfs_setup(c
->lxc_conf
, c
->name
, c
->config_path
) < 0)
740 goto out_fini_handler
;
742 if (mkdir(rootfs
->mount
, 0755) < 0 && errno
!= EEXIST
)
743 goto out_fini_handler
;
745 if (mount(NULL
, "/", NULL
, MS_SLAVE
| MS_REC
, NULL
) < 0) {
746 SYSERROR("remount / to private failed");
747 goto out_fini_handler
;
750 if (mount(rootfs
->path
, rootfs
->mount
, NULL
, MS_BIND
, NULL
) < 0) {
751 rmdir(rootfs
->mount
);
752 goto out_fini_handler
;
756 os
.action
= "restore";
759 os
.console_fd
= c
->lxc_conf
->console
.slave
;
760 os
.criu_version
= criu_version
;
761 os
.handler
= handler
;
763 if (os
.console_fd
>= 0) {
764 /* Twiddle the FD_CLOEXEC bit. We want to pass this FD to criu
765 * via --inherit-fd, so we don't want it to close.
767 flags
= fcntl(os
.console_fd
, F_GETFD
);
769 SYSERROR("F_GETFD failed: %d", os
.console_fd
);
770 goto out_fini_handler
;
773 flags
&= ~FD_CLOEXEC
;
775 if (fcntl(os
.console_fd
, F_SETFD
, flags
) < 0) {
776 SYSERROR("F_SETFD failed");
777 goto out_fini_handler
;
780 os
.console_name
= c
->lxc_conf
->console
.name
;
782 /* exec_criu() returning is an error */
784 umount(rootfs
->mount
);
785 rmdir(rootfs
->mount
);
786 goto out_fini_handler
;
794 pid_t w
= waitpid(pid
, &status
, 0);
797 goto out_fini_handler
;
800 if (WIFEXITED(status
)) {
803 if (WEXITSTATUS(status
)) {
806 n
= read(pipes
[0], buf
, sizeof(buf
));
808 SYSERROR("failed reading from criu stderr");
809 goto out_fini_handler
;
814 ERROR("criu process exited %d, output:\n%s\n", WEXITSTATUS(status
), buf
);
815 goto out_fini_handler
;
817 ret
= snprintf(buf
, sizeof(buf
), "/proc/self/task/%lu/children", (unsigned long)syscall(__NR_gettid
));
818 if (ret
< 0 || ret
>= sizeof(buf
)) {
819 ERROR("snprintf'd too many characters: %d", ret
);
820 goto out_fini_handler
;
823 FILE *f
= fopen(buf
, "r");
825 SYSERROR("couldn't read restore's children file %s\n", buf
);
826 goto out_fini_handler
;
829 ret
= fscanf(f
, "%d", (int*) &handler
->pid
);
832 ERROR("reading restore pid failed");
833 goto out_fini_handler
;
836 if (lxc_set_state(c
->name
, handler
, RUNNING
)) {
837 ERROR("error setting running state after restore");
838 goto out_fini_handler
;
842 ERROR("CRIU was killed with signal %d\n", WTERMSIG(status
));
843 goto out_fini_handler
;
848 ret
= write(status_pipe
, &status
, sizeof(status
));
852 if (sizeof(status
) != ret
) {
853 SYSERROR("failed to write all of status");
854 goto out_fini_handler
;
858 * See comment in lxcapi_start; we don't care if these
859 * fail because it's just a beauty thing. We just
860 * assign the return here to silence potential.
862 ret
= snprintf(title
, sizeof(title
), "[lxc monitor] %s %s", c
->config_path
, c
->name
);
863 ret
= setproctitle(title
);
865 ret
= lxc_poll(c
->name
, handler
);
867 lxc_abort(c
->name
, handler
);
868 lxc_fini(c
->name
, handler
);
878 lxc_fini(c
->name
, handler
);
881 if (status_pipe
>= 0) {
882 /* ensure getting here was a failure, e.g. if we failed to
883 * parse the child pid or something, even after a successful
888 if (write(status_pipe
, &status
, sizeof(status
)) != sizeof(status
)) {
889 SYSERROR("writing status failed");
897 static int save_tty_major_minor(char *directory
, struct lxc_container
*c
, char *tty_id
, int len
)
904 if (c
->lxc_conf
->console
.path
&& !strcmp(c
->lxc_conf
->console
.path
, "none")) {
909 ret
= snprintf(path
, sizeof(path
), "/proc/%d/root/dev/console", c
->init_pid(c
));
910 if (ret
< 0 || ret
>= sizeof(path
)) {
911 ERROR("snprintf'd too many chacters: %d", ret
);
915 ret
= stat(path
, &sb
);
917 SYSERROR("stat of %s failed", path
);
921 ret
= snprintf(path
, sizeof(path
), "%s/tty.info", directory
);
922 if (ret
< 0 || ret
>= sizeof(path
)) {
923 ERROR("snprintf'd too many characters: %d", ret
);
927 ret
= snprintf(tty_id
, len
, "tty[%llx:%llx]",
928 (long long unsigned) sb
.st_rdev
,
929 (long long unsigned) sb
.st_dev
);
930 if (ret
< 0 || ret
>= sizeof(path
)) {
931 ERROR("snprintf'd too many characters: %d", ret
);
935 f
= fopen(path
, "w");
937 SYSERROR("failed to open %s", path
);
941 ret
= fprintf(f
, "%s", tty_id
);
944 SYSERROR("failed to write to %s", path
);
948 /* do one of either predump or a regular dump */
949 static bool do_dump(struct lxc_container
*c
, char *mode
, struct migrate_opts
*opts
)
952 char *criu_version
= NULL
;
954 if (!criu_ok(c
, &criu_version
))
957 if (mkdir_p(opts
->directory
, 0700) < 0)
962 SYSERROR("fork failed");
968 struct lxc_handler h
;
971 if (!cgroup_init(&h
)) {
972 ERROR("failed to cgroup_init()");
979 os
.console_name
= c
->lxc_conf
->console
.path
;
980 os
.criu_version
= criu_version
;
982 if (save_tty_major_minor(opts
->directory
, c
, os
.tty_id
, sizeof(os
.tty_id
)) < 0)
985 /* exec_criu() returning is an error */
990 pid_t w
= waitpid(pid
, &status
, 0);
996 if (WIFEXITED(status
)) {
997 if (WEXITSTATUS(status
)) {
998 ERROR("dump failed with %d\n", WEXITSTATUS(status
));
1003 } else if (WIFSIGNALED(status
)) {
1004 ERROR("dump signaled with %d\n", WTERMSIG(status
));
1007 ERROR("unknown dump exit %d\n", status
);
1013 bool __criu_pre_dump(struct lxc_container
*c
, struct migrate_opts
*opts
)
1015 return do_dump(c
, "pre-dump", opts
);
1018 bool __criu_dump(struct lxc_container
*c
, struct migrate_opts
*opts
)
1020 char path
[PATH_MAX
];
1023 ret
= snprintf(path
, sizeof(path
), "%s/inventory.img", opts
->directory
);
1024 if (ret
< 0 || ret
>= sizeof(path
))
1027 if (access(path
, F_OK
) == 0) {
1028 ERROR("please use a fresh directory for the dump directory\n");
1032 return do_dump(c
, "dump", opts
);
1035 bool __criu_restore(struct lxc_container
*c
, struct migrate_opts
*opts
)
1040 char *criu_version
= NULL
;
1042 if (!criu_ok(c
, &criu_version
))
1046 ERROR("Must be root to restore\n");
1051 ERROR("failed to create pipe");
1064 // this never returns
1065 do_restore(c
, pipefd
[1], opts
, criu_version
);
1070 nread
= read(pipefd
[0], &status
, sizeof(status
));
1072 if (sizeof(status
) != nread
) {
1073 ERROR("reading status from pipe failed");
1077 // If the criu process was killed or exited nonzero, wait() for the
1078 // handler, since the restore process died. Otherwise, we don't need to
1079 // wait, since the child becomes the monitor process.
1080 if (!WIFEXITED(status
) || WEXITSTATUS(status
))
1085 if (wait_for_pid(pid
))
1086 ERROR("restore process died");