[CRIU] [PATCH 05/14] resotre: collect mounts of current mntns

Andrey Vagin avagin at openvz.org
Thu Apr 17 12:23:59 PDT 2014


It's required for restoring in the current mntns.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c    |  4 ++++
 include/mount.h |  2 ++
 mount.c         | 24 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+)

diff --git a/cr-restore.c b/cr-restore.c
index d66661c..2cdcb08 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1252,6 +1252,10 @@ static int restore_task_with_children(void *_arg)
 		if (prepare_namespace(current, ca->clone_flags))
 			exit(1);
 
+		if (!(root_ns_mask & CLONE_NEWNS))
+			if (rst_collect_local_mntns())
+				exit(1);
+
 		/*
 		 * We need non /proc proc mount for restoring pid and mount
 		 * namespaces and do not care for the rest of the cases.
diff --git a/include/mount.h b/include/mount.h
index 1361c61..8dc7a2e 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -29,4 +29,6 @@ extern bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev, const char *path);
 extern int restore_task_mnt_ns(struct ns_id *nsid, pid_t pid);
 extern int fini_mnt_ns(void);
 
+int rst_collect_local_mntns();
+
 #endif /* __CR_MOUNT_H__ */
diff --git a/mount.c b/mount.c
index ef65618..dce69dc 100644
--- a/mount.c
+++ b/mount.c
@@ -1416,6 +1416,30 @@ static char *get_mnt_roots(bool create)
 
 }
 
+int rst_collect_local_mntns()
+{
+	struct ns_id *nsid;
+
+	nsid = shmalloc(sizeof(struct ns_id));
+	if (nsid == NULL)
+		return -1;
+
+	nsid->nd = &mnt_ns_desc;
+	nsid->id = 0;
+	nsid->pid = getpid();
+	futex_set(&nsid->created, 1);
+
+	if (collect_mntinfo(nsid) == NULL)
+		return -1;
+
+	nsid->next = ns_ids;
+	ns_ids = nsid;
+
+	pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid);
+
+	return 0;
+}
+
 static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 {
 	MntEntry *me = NULL;
-- 
1.8.5.3



More information about the CRIU mailing list