[CRIU] [PATCH v2 05/30] ns: Add top_net_ns global variable

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 7 14:25:01 MSK 2017


It will be need for fast obtaining root_item's net_ns,
and to fixup old dumps.

v2: Add a comment to top_xxx_ns. Extend MARK_ROOT_NS().

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/namespaces.h |    1 +
 criu/namespaces.c         |   22 +++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 631d6228a..4e06ebc0f 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -163,6 +163,7 @@ struct ns_id {
 extern struct ns_id *ns_ids;
 extern struct ns_id *top_pid_ns;
 extern struct ns_id *root_user_ns;
+extern struct ns_id *top_net_ns;
 
 #define NS_DESC_ENTRY(_cflag, _str, _alt_str)		\
 	{						\
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 4d4edb56b..5ab64ccc6 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -893,8 +893,15 @@ static int set_ns_hookups(struct ns_id *ns)
 	return ret;
 }
 
+/*
+ * top_xxx_ns -- top namespaces of the dumped/restored tasks.
+ * For not-hierarchical types this means namespace of root_item.
+ * For hierarchical types this means the grand parent namespace,
+ * which is ancestor of all others.
+ */
 struct ns_id *top_pid_ns = NULL;
 struct ns_id *root_user_ns = NULL;
+struct ns_id *top_net_ns = NULL;
 /* Mapping NS_ROOT to NS_CRIU */
 UsernsEntry *userns_entry;
 
@@ -2135,7 +2142,7 @@ int read_ns_with_hookups(void)
 	return ret;
 }
 
-static int mark_root_ns(uint32_t id, struct ns_desc *desc)
+static int mark_root_ns(uint32_t id, struct ns_desc *desc, struct ns_id **ns_ret)
 {
 	struct ns_id *ns;
 
@@ -2145,18 +2152,23 @@ static int mark_root_ns(uint32_t id, struct ns_desc *desc)
 		return -1;
 	}
 	ns->type = NS_ROOT;
+
+	if (ns_ret)
+		*ns_ret = ns;
+
 	return 0;
 }
 
-#define MARK_ROOT_NS(ids, name)	\
-	(ids->has_##name##_ns_id && mark_root_ns(ids->name##_ns_id, &name##_ns_desc) < 0)
+#define MARK_ROOT_NS(ids, name, ns)	\
+	(ids->has_##name##_ns_id && mark_root_ns(ids->name##_ns_id, &name##_ns_desc, ns) < 0)
 
 int set_ns_roots(void)
 {
 	TaskKobjIdsEntry *ids = root_item->ids;
 	/* Set root for all namespaces except user and pid, which are set in read_ns_with_hookups() */
-	if (MARK_ROOT_NS(ids, net) || MARK_ROOT_NS(ids, ipc) || MARK_ROOT_NS(ids, uts) ||
-	    MARK_ROOT_NS(ids, mnt) || MARK_ROOT_NS(ids, cgroup))
+	if (MARK_ROOT_NS(ids, net, &top_net_ns) || MARK_ROOT_NS(ids, ipc, NULL) ||
+	    MARK_ROOT_NS(ids, uts, NULL) || MARK_ROOT_NS(ids, mnt, NULL) ||
+	    MARK_ROOT_NS(ids, cgroup, NULL))
 		return -1;
 	return 0;
 }



More information about the CRIU mailing list