Commit b78af192 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

mount: wait when mntns will be created to get its root (v2)

v2: add comments and rename ns_created to ns_populated.
Reported-by: 's avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 322655fb
......@@ -31,7 +31,7 @@ struct ns_id {
* are mounted) and other tasks may do setns on it
* and proceed.
*/
futex_t ns_created;
futex_t ns_populated;
union {
struct {
......
......@@ -2356,7 +2356,7 @@ static int rst_collect_local_mntns(void)
if (!mntinfo)
return -1;
futex_set(&nsid->ns_created, 1);
futex_set(&nsid->ns_populated, 1);
return 0;
}
......@@ -2604,7 +2604,7 @@ static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *curren
close(fd);
if (nsid->ns_pid == current->pid.virt)
futex_set_and_wake(&nsid->ns_created, 1);
futex_set_and_wake(&nsid->ns_populated, 1);
return 0;
}
......@@ -2949,8 +2949,17 @@ set_root:
return ret;
}
int mntns_get_root_fd(struct ns_id *mntns)
{
int mntns_get_root_fd(struct ns_id *mntns) {
/*
* We need to find a task from the target namespace and open its root.
* For that we need to wait when one of tasks enters into required
* namespaces.
*
* The root task is born in the root mount namespace.
*/
if (mntns->type != NS_ROOT)
futex_wait_while_eq(&mntns->ns_populated, 0);
return __mntns_get_root_fd(mntns->ns_pid);
}
......
......@@ -144,7 +144,7 @@ static struct ns_id *__rst_new_ns_id(unsigned int id, pid_t pid,
if (nsid) {
nsid->type = type;
nsid_add(nsid, nd, id, pid);
futex_set(&nsid->ns_created, 0);
futex_set(&nsid->ns_populated, 0);
}
return nsid;
......@@ -268,6 +268,7 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
nsid->type = type;
nsid->kid = kid;
futex_set(&nsid->ns_populated, 1);
nsid_add(nsid, nd, ns_next_id++, pid);
found:
......
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