[CRIU] [PATCH 04/12] restore: add mount id-s in the ns_ids list

Andrey Vagin avagin at openvz.org
Fri Jan 10 05:49:58 PST 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/namespaces.h |  1 +
 namespaces.c         | 28 ++++++++++++++++++++++++++++
 pstree.c             |  5 +++++
 3 files changed, 34 insertions(+)

diff --git a/include/namespaces.h b/include/namespaces.h
index 40bc2d9..8059dbf 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -42,5 +42,6 @@ extern int switch_ns(int pid, struct ns_desc *nd, int *rst);
 extern int restore_ns(int rst, struct ns_desc *nd);
 
 extern int dump_task_ns_ids(struct pstree_item *);
+extern int add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
 
 #endif /* __CR_NS_H__ */
diff --git a/namespaces.c b/namespaces.c
index 970ddfa..d8b2690 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -117,6 +117,34 @@ struct ns_id *ns_ids = NULL;
 static unsigned int ns_next_id = 1;
 unsigned long current_ns_mask = 0;
 
+int add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
+{
+	struct ns_id *nsid;
+
+	for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
+		if (nsid->id == id) {
+			if (pid_rst_prio(pid, nsid->pid))
+				nsid->pid = pid;
+			return 0;
+		}
+	}
+
+	nsid = shmalloc(sizeof(struct ns_id));
+	if (nsid == NULL)
+		return -1;
+
+	nsid->nd = nd;
+	nsid->id = id;
+	nsid->pid = pid;
+
+	nsid->next = ns_ids;
+	ns_ids = nsid;
+
+	pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid);
+
+	return 0;
+}
+
 static unsigned int lookup_ns_id(unsigned int kid, struct ns_desc *nd)
 {
 	struct ns_id *nsid;
diff --git a/pstree.c b/pstree.c
index b83453f..1c5f240 100644
--- a/pstree.c
+++ b/pstree.c
@@ -9,6 +9,7 @@
 #include "namespaces.h"
 #include "files.h"
 #include "tty.h"
+#include "mount.h"
 #include "asm/dump.h"
 
 #include "protobuf.h"
@@ -384,6 +385,10 @@ static int read_pstree_image(void)
 		if (ret != 1)
 			goto err;
 
+		if (pi->ids->has_mnt_ns_id) {
+			if (add_ns_id(pi->ids->mnt_ns_id, pi->pid.virt, &mnt_ns_desc))
+				goto err;
+		}
 	}
 err:
 	close(ps_fd);
-- 
1.8.3.1



More information about the CRIU mailing list