mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-22 01:31:34 +00:00
restore: rework logic about temporary proc
We need proc for restoring processes. The existent /proc may be not suitable. E.g. If processes are in pidns. crtools mounts procfs in a temporary directory, but it should be umounted at the end. Before this patch crtools did that, but it doesn't work if processes in a mount namespace. Actually this logic can be simplified and this patch does that. * create a tmp dir * mount procfs * open this directory and save a file descriptor. * detach procfs * remove the tmp dir * access to proc via openat, statat and so on. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
2f272fa187
commit
2e9ddccdb9
1 changed files with 23 additions and 36 deletions
59
cr-restore.c
59
cr-restore.c
|
|
@ -632,40 +632,33 @@ static void restore_pgid(void)
|
|||
}
|
||||
}
|
||||
|
||||
static char proc_mountpoint[PATH_MAX] = "/proc";
|
||||
|
||||
static int prepare_proc(void)
|
||||
{
|
||||
snprintf(proc_mountpoint, sizeof(proc_mountpoint), "/tmp/crtools-proc.XXXXXX");
|
||||
if (mkdtemp(proc_mountpoint) == NULL) {
|
||||
pr_err("mkdtemp failed %m");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void umount_proc(void)
|
||||
{
|
||||
int err;
|
||||
err = umount(proc_mountpoint);
|
||||
if (err == -1)
|
||||
pr_err("Can't umount %s\n", proc_mountpoint);
|
||||
err = rmdir(proc_mountpoint);
|
||||
if (err == -1)
|
||||
pr_err("Can't delete %s\n", proc_mountpoint);
|
||||
}
|
||||
|
||||
static void mount_proc(void)
|
||||
{
|
||||
int ret;
|
||||
char proc_mountpoint[PATH_MAX];
|
||||
|
||||
mkdir("/tmp/", 0777);
|
||||
snprintf(proc_mountpoint, sizeof(proc_mountpoint), "crtools-proc.XXXXXX");
|
||||
if (mkdtemp(proc_mountpoint) == NULL) {
|
||||
pr_err("mkdtemp failed %m");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pr_info("Mount procfs in %s\n", proc_mountpoint);
|
||||
ret = mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL);
|
||||
if (ret == -1) {
|
||||
pr_err("mount failed");
|
||||
exit(1);
|
||||
}
|
||||
set_proc_mountpoint(proc_mountpoint);
|
||||
if (umount2(proc_mountpoint, MNT_DETACH) == -1) {
|
||||
pr_err("Can't umount %s\n", proc_mountpoint);
|
||||
exit(1);
|
||||
}
|
||||
if (rmdir(proc_mountpoint) == -1) {
|
||||
pr_err("Can't remove %s\n", proc_mountpoint);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static int restore_task_with_children(void *_arg)
|
||||
|
|
@ -699,6 +692,12 @@ static int restore_task_with_children(void *_arg)
|
|||
if (ret)
|
||||
exit(-1);
|
||||
|
||||
/*
|
||||
* We need non /proc proc mount for restoring pid and mount
|
||||
* namespaces and do not care for the rest of the cases.
|
||||
* Thus -- mount proc at custom location for any new namespace
|
||||
*/
|
||||
|
||||
mount_proc();
|
||||
}
|
||||
|
||||
|
|
@ -777,15 +776,6 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need non /proc proc mount for restoring pid and mount namespaces
|
||||
* and do not care for the rest of the cases. Thus -- mount proc at
|
||||
* custom location for any new namespace
|
||||
*/
|
||||
|
||||
if (opts->namespaces_flags && prepare_proc())
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* FIXME -- currently we assume that all the tasks live
|
||||
* in the same set of namespaces. This is done to debug
|
||||
|
|
@ -832,9 +822,6 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
|
|||
ret = (int)futex_get(&task_entries->nr_in_progress);
|
||||
|
||||
out:
|
||||
if (opts->namespaces_flags)
|
||||
umount_proc();
|
||||
|
||||
if (ret < 0) {
|
||||
struct pstree_item *pi;
|
||||
pr_err("Someone can't be restored\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue