[CRIU] [PATCH 14/39] namespaces: dump mount namespaces before tasks (v2)

Andrey Vagin avagin at openvz.org
Mon Apr 21 07:23:24 PDT 2014


because we want to check, that all files are reachable.
For that we need to collect all mounts from all namespaces.

v2: dump mntns separately
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c            |  3 +++
 include/namespaces.h |  1 +
 namespaces.c         | 29 ++++++++++++++++++++++++-----
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 7868161..26ea732 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1757,6 +1757,9 @@ int cr_dump_tasks(pid_t pid)
 	if (!glob_fdset)
 		goto err;
 
+	if (dump_mnt_namespaces() < 0)
+		goto err;
+
 	for_each_pstree_item(item) {
 		if (dump_one_task(item))
 			goto err;
diff --git a/include/namespaces.h b/include/namespaces.h
index 7ce7db3..fcbe17c 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -35,6 +35,7 @@ extern unsigned long root_ns_mask;
 extern const struct fdtype_ops nsfile_dump_ops;
 extern struct collect_image_info nsfile_cinfo;
 
+extern int dump_mnt_namespaces(void);
 extern int dump_namespaces(struct pstree_item *item, unsigned int ns_flags);
 extern int prepare_namespace(struct pstree_item *item, unsigned long clone_flags);
 extern int try_show_namespaces(int pid);
diff --git a/namespaces.c b/namespaces.c
index 8ee48a2..190628b 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -419,6 +419,7 @@ static int do_dump_namespaces(struct ns_id *ns)
 
 	switch (ns->nd->cflag) {
 	case CLONE_NEWPID:
+	case CLONE_NEWNS:
 		ret = 0;
 		break;
 	case CLONE_NEWUTS:
@@ -431,11 +432,6 @@ static int do_dump_namespaces(struct ns_id *ns)
 				ns->id, ns->pid);
 		ret = dump_ipc_ns(ns->pid, ns->id);
 		break;
-	case CLONE_NEWNS:
-		pr_info("Dump MNT namespace (mountpoints) %d via %d\n",
-				ns->id, ns->pid);
-		ret = dump_mnt_ns(ns->pid, ns->id);
-		break;
 	case CLONE_NEWNET:
 		pr_info("Dump NET namespace info %d via %d\n",
 				ns->id, ns->pid);
@@ -450,6 +446,29 @@ static int do_dump_namespaces(struct ns_id *ns)
 
 }
 
+int dump_mnt_namespaces(void)
+{
+	struct ns_id *ns;
+	int ret = 0;
+
+	for (ns = ns_ids; ns; ns = ns->next) {
+		/* Skip current namespaces, which are in the list too  */
+		if (ns->pid == getpid())
+			continue;
+
+		if (!(ns->nd->cflag & CLONE_NEWNS))
+			continue;
+
+		pr_info("Dump MNT namespace (mountpoints) %d via %d\n",
+				ns->id, ns->pid);
+		ret = dump_mnt_ns(ns->pid, ns->id);
+		if (ret)
+			break;
+	}
+
+	return ret;
+}
+
 int dump_namespaces(struct pstree_item *item, unsigned int ns_flags)
 {
 	struct pid *ns_pid = &item->pid;
-- 
1.8.5.3



More information about the CRIU mailing list