Skip to content

Commit b973373

Browse files
authored
Merge pull request #1758 from kolyshkin/pr-1747-followups
Fixup "criu: support mounts where dest is a symlink"
2 parents 735014f + b1133e9 commit b973373

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/libcrun/criu.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
418418
cleanup_wrapper struct libcriu_wrapper_s *wrapper = NULL;
419419
cleanup_free char *descriptors_path = NULL;
420420
cleanup_free char *freezer_path = NULL;
421-
cleanup_free char *rootfs = NULL;
421+
cleanup_free char *path = NULL;
422422
cleanup_close int image_fd = -1;
423423
cleanup_close int work_fd = -1;
424424
int cgroup_mode;
@@ -557,13 +557,13 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
557557
if (UNLIKELY (ret < 0))
558558
return crun_error_wrap (err, "error saving CRIU descriptors file");
559559

560-
ret = append_paths (&rootfs, err, status->bundle, status->rootfs, NULL);
560+
ret = append_paths (&path, err, status->bundle, status->rootfs, NULL);
561561
if (UNLIKELY (ret < 0))
562562
return ret;
563563

564-
ret = libcriu_wrapper->criu_set_root (rootfs);
564+
ret = libcriu_wrapper->criu_set_root (path);
565565
if (UNLIKELY (ret != 0))
566-
return crun_make_error (err, 0, "error setting CRIU root to `%s`", rootfs);
566+
return crun_make_error (err, 0, "error setting CRIU root to `%s`", path);
567567

568568
cgroup_mode = libcrun_get_cgroup_mode (err);
569569
if (UNLIKELY (cgroup_mode < 0))
@@ -586,10 +586,16 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
586586
char buf[PATH_MAX];
587587
const char *dest_in_root;
588588

589-
dest_in_root = chroot_realpath (rootfs, def->mounts[i]->destination, buf);
589+
dest_in_root = chroot_realpath (status->rootfs, def->mounts[i]->destination, buf);
590590
if (UNLIKELY (dest_in_root == NULL))
591-
return crun_make_error (err, errno, "unable to resolve external bind mount `%s` under rootfs", def->mounts[i]->destination);
592-
dest_in_root += strlen (rootfs);
591+
{
592+
if (errno != ENOENT)
593+
return crun_make_error (err, errno, "unable to resolve external bind mount `%s` under rootfs", def->mounts[i]->destination);
594+
else
595+
dest_in_root = def->mounts[i]->destination;
596+
}
597+
else
598+
dest_in_root += strlen (status->rootfs);
593599

594600
ret = libcriu_wrapper->criu_add_ext_mount (dest_in_root, dest_in_root);
595601
if (UNLIKELY (ret < 0))
@@ -793,7 +799,6 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
793799
cleanup_close int inherit_new_pid_fd = -1;
794800
cleanup_close int image_fd = -1;
795801
cleanup_free char *root = NULL;
796-
cleanup_free char *rootfs = NULL;
797802
cleanup_free char *bundle_cleanup = NULL;
798803
cleanup_close int work_fd = -1;
799804
int ret_out;
@@ -904,9 +909,6 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
904909
}
905910

906911
/* Tell CRIU about external bind mounts. */
907-
ret = append_paths (&rootfs, err, status->bundle, status->rootfs, NULL);
908-
if (UNLIKELY (ret < 0))
909-
return ret;
910912
for (i = 0; i < def->mounts_len; i++)
911913
{
912914
if (is_bind_mount (def->mounts[i], NULL))
@@ -915,10 +917,15 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
915917
char buf[PATH_MAX];
916918
const char *dest_in_root;
917919

918-
dest_in_root = chroot_realpath (rootfs, def->mounts[i]->destination, buf);
920+
dest_in_root = chroot_realpath (status->rootfs, def->mounts[i]->destination, buf);
919921
if (UNLIKELY (dest_in_root == NULL))
920-
return crun_make_error (err, errno, "unable to resolve external bind mount `%s` under rootfs", def->mounts[i]->destination);
921-
dest_in_root += strlen (rootfs);
922+
{
923+
if (errno != ENOENT)
924+
return crun_make_error (err, errno, "unable to resolve external bind mount destination `%s` under rootfs", def->mounts[i]->destination);
925+
dest_in_root = def->mounts[i]->destination;
926+
}
927+
else
928+
dest_in_root += strlen (status->rootfs);
922929

923930
ret = libcriu_wrapper->criu_add_ext_mount (dest_in_root, def->mounts[i]->source);
924931
if (UNLIKELY (ret < 0))

tests/tmt/podman/system-test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ rpm -q conmon containers-common crun podman podman-tests
1414
bats -t /usr/share/podman/test/system/030-run.bats
1515
bats -t /usr/share/podman/test/system/075-exec.bats
1616
bats -t /usr/share/podman/test/system/280-update.bats
17+
bats -t /usr/share/podman/test/system/520-checkpoint.bats

0 commit comments

Comments
 (0)