[CRIU] [PATCH 25/39] resotre: collect mounts of current mntns

Andrey Vagin avagin at openvz.org
Mon Apr 21 07:23:35 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 e54e4c0..521a388 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1243,6 +1243,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 867dd50..cb775f9 100644
--- a/mount.c
+++ b/mount.c
@@ -1433,6 +1433,30 @@ static int create_mnt_roots()
 	return 0;
 }
 
+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