[CRIU] [PATCH 03/10] net: Do walk net namespaces to collect

Pavel Emelyanov xemul at parallels.com
Mon Sep 29 11:04:11 PDT 2014


Right now we don't support multiple net namespaces,
but some day we will. Other than this we have a logic
to distinguish cases with no namespaces vs one namespace,
so this walking already makes sence.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 net.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/net.c b/net.c
index 060b3f5..7cf3d2c 100644
--- a/net.c
+++ b/net.c
@@ -628,9 +628,35 @@ int veth_pair_add(char *in, char *out)
 	return 0;
 }
 
+static int collect_net_ns(struct ns_id *ns)
+{
+	pr_info("Collecting netns %d/%d\n", ns->id, ns->pid);
+	return collect_sockets(ns->pid);
+}
+
 int collect_net_namespaces(void)
 {
-	return collect_sockets(root_item->pid.real);
+	int ret = 0;
+	struct ns_id *ns;
+
+	for (ns = ns_ids; ns; ns = ns->next) {
+		if (!(ns->nd->cflag & CLONE_NEWNET))
+			continue;
+
+		if (ns->pid == getpid()) {
+			if ((root_ns_mask & CLONE_NEWNET))
+				continue;
+
+			ret = collect_net_ns(ns);
+			break;
+		}
+
+		ret = collect_net_ns(ns);
+		if (ret)
+			break;
+	}
+
+	return ret;
 }
 
 struct ns_desc net_ns_desc = NS_DESC_ENTRY(CLONE_NEWNET, "net");
-- 
1.8.4.2




More information about the CRIU mailing list