[CRIU] [PATCH 30/37] mount: prepare to work without mnt_id

Andrey Vagin avagin at openvz.org
Fri Apr 18 07:43:08 PDT 2014


Kernels before 3.15 doesn't show mnt_id and mnt_id isn't saved in
images, if mntns isn't dumped.

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

diff --git a/include/mount.h b/include/mount.h
index 25df359..729a638 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -4,6 +4,7 @@
 extern struct mount_info *mntinfo;
 
 extern int mntns_collect_root(pid_t pid);
+extern struct ns_id *lookup_nsid_by_mnt_id(int mnt_id);
 
 struct proc_mountinfo;
 
diff --git a/mount.c b/mount.c
index 78364f7..9ed5cdc 100644
--- a/mount.c
+++ b/mount.c
@@ -1572,6 +1572,9 @@ char *rst_get_mnt_root(int mnt_id)
 	if (!(root_ns_mask & CLONE_NEWNS))
 		return path;
 
+	if (mnt_id  == -1)
+		return path;
+
 	m = lookup_mnt_id(mnt_id);
 	if (m == NULL)
 		return NULL;
@@ -1837,6 +1840,27 @@ set_root:
 	return ret;
 }
 
+struct ns_id *lookup_nsid_by_mnt_id(int mnt_id)
+{
+	struct mount_info *mi;
+
+	/*
+	 * Kernel before 3.15 doesn't show mnt_id for file descriptors.
+	 * mnt_id isn't saved for files, if mntns isn't dumped.
+	 * In both these cases we have only one root, so here
+	 * is not matter which mount will be restured.
+	 */
+	if (mnt_id == -1)
+		mi = mntinfo;
+	else
+		mi = lookup_mnt_id(mnt_id);
+
+	if (mi == NULL)
+		return NULL;
+
+	return mi->nsid;
+}
+
 int collect_mnt_namespaces(void)
 {
 	struct mount_info *pm;
-- 
1.8.5.3



More information about the CRIU mailing list