Commit a201f598 authored by Pavel Emelyanov's avatar Pavel Emelyanov

rst: Create custom proc every time we restore a namespace

We need own proc for restoring mount namespace, since the proc should
be umounted and mounted back diring namespace restore and I don't want
to introduce a special kludge for this.

One more notice -- the temp proc is mounted _after_ namespaces recreation
for the same reason (it will be umounted by prepare_mnt_ns).
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent fe41f84b
...@@ -812,6 +812,40 @@ static void restore_pgid(void) ...@@ -812,6 +812,40 @@ static void restore_pgid(void)
static char proc_mountpoint[PATH_MAX] = "/proc"; 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;
ret = mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL);
if (ret == -1) {
pr_err("mount failed");
exit(1);
}
set_proc_mountpoint(proc_mountpoint);
}
static bool restore_before_setsid(struct pstree_item *child) static bool restore_before_setsid(struct pstree_item *child)
{ {
int csid = child->born_sid == -1 ? child->sid : child->born_sid; int csid = child->born_sid == -1 ? child->sid : child->born_sid;
...@@ -840,15 +874,6 @@ static int restore_task_with_children(void *_arg) ...@@ -840,15 +874,6 @@ static int restore_task_with_children(void *_arg)
exit(-1); exit(-1);
} }
if (pid == 1) { /* New pid namespace */
ret = mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL);
if (ret == -1) {
pr_err("mount failed");
exit(1);
}
set_proc_mountpoint(proc_mountpoint);
}
ret = log_init_by_pid(); ret = log_init_by_pid();
if (ret < 0) if (ret < 0)
exit(1); exit(1);
...@@ -857,6 +882,8 @@ static int restore_task_with_children(void *_arg) ...@@ -857,6 +882,8 @@ static int restore_task_with_children(void *_arg)
ret = prepare_namespace(me->pid.virt, ca->clone_flags); ret = prepare_namespace(me->pid.virt, ca->clone_flags);
if (ret) if (ret)
exit(-1); exit(-1);
mount_proc();
} }
/* /*
...@@ -927,6 +954,15 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts) ...@@ -927,6 +954,15 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
return -1; 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 * FIXME -- currently we assume that all the tasks live
* in the same set of namespaces. This is done to debug * in the same set of namespaces. This is done to debug
...@@ -940,13 +976,6 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts) ...@@ -940,13 +976,6 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
pr_err("crtools should be re-executed with --namespace pid\n"); pr_err("crtools should be re-executed with --namespace pid\n");
return -1; return -1;
} }
snprintf(proc_mountpoint, sizeof(proc_mountpoint), "/tmp/crtools-proc.XXXXXX");
if (mkdtemp(proc_mountpoint) == NULL) {
pr_err("mkdtemp failed %m");
return -1;
}
} else if (opts->namespaces_flags & CLONE_NEWPID) { } else if (opts->namespaces_flags & CLONE_NEWPID) {
pr_err("Can't restore pid namespace without the process init\n"); pr_err("Can't restore pid namespace without the process init\n");
return -1; return -1;
...@@ -971,15 +1000,8 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts) ...@@ -971,15 +1000,8 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
ret = (int)futex_get(&task_entries->nr_in_progress); ret = (int)futex_get(&task_entries->nr_in_progress);
out: out:
if (init->pid.virt == 1) { if (opts->namespaces_flags)
int err; umount_proc();
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);
}
if (ret < 0) { if (ret < 0) {
struct pstree_item *pi; struct pstree_item *pi;
......
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