[CRIU] [PATCH] mount: wait when mntns will be created to get its root (v2)

Andrey Vagin avagin at openvz.org
Sun Nov 15 03:08:30 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

v2: add comments and rename ns_created to ns_populated.

Reported-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 include/namespaces.h |  2 +-
 mount.c              | 17 +++++++++++++----
 namespaces.c         |  3 ++-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/include/namespaces.h b/include/namespaces.h
index 9b7dca3..c655890 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -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 {
diff --git a/mount.c b/mount.c
index c56cb9a..562d6ca 100644
--- a/mount.c
+++ b/mount.c
@@ -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);
 }
 
diff --git a/namespaces.c b/namespaces.c
index 1123492..a874fb1 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -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:
-- 
2.4.3



More information about the CRIU mailing list