[Devel] [PATCH RH7] proc: add a proc_show_path method to fix mountinfo

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Apr 28 14:20:40 MSK 2020


Original ms patch:

nsfs: Add a show_path method to fix mountinfo

Today mountinfo displays a very unhelpful "/" for nsfs files.  Add a
show_path method returning the same string as ns_dname.  This results
in a bind mount of /proc/<pid>/ns/net showing up in /proc/<pid>/mountinfo as
"net:[1234...]" instead of "/".

Signed-off-by: "Eric W. Biederman" <ebiederm at xmission.com>

We don't have nsfs so we can add a method to procfs with special
handling of ns files.

We need it to support docker migration in CRIU so that criu can dump and
restore namespace file bind-mounts. In theory for non-detached ns we can
find match for "name:[id]" in /proc/*/ns/<name> files readlink, thus
finding the source for bind-mount.

https://jira.sw.ru/browse/PSBM-102357

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 fs/proc/inode.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 4eef2b46b87e..0fff949bcc13 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -23,6 +23,7 @@
 #include <linux/slab.h>
 #include <linux/mount.h>
 #include <linux/magic.h>
+#include <linux/proc_ns.h>
 
 #include <asm/uaccess.h>
 
@@ -124,6 +125,21 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root)
 	return 0;
 }
 
+static int proc_show_path(struct seq_file *seq, struct dentry *dentry)
+{
+	struct inode *inode = d_inode(dentry);
+	struct proc_ns *ei;
+
+	if (proc_ns_inode(inode)) {
+		ei = get_proc_ns(inode);
+		seq_printf(seq, "%s:[%lu]", ei->ns_ops->name, inode->i_ino);
+		return 0;
+	}
+
+	seq_dentry(seq, dentry, " \t\n\\");
+	return 0;
+}
+
 static const struct super_operations proc_sops = {
 	.alloc_inode	= proc_alloc_inode,
 	.destroy_inode	= proc_destroy_inode,
@@ -132,6 +148,7 @@ static const struct super_operations proc_sops = {
 	.statfs		= simple_statfs,
 	.remount_fs	= proc_remount,
 	.show_options	= proc_show_options,
+	.show_path	= proc_show_path,
 };
 
 enum {BIAS = -1U<<31};
-- 
2.24.1



More information about the Devel mailing list