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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Apr 30 19:01:12 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.vz7.150.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.vz7.150.5
------>
commit 71e1ad692e8bd0720efceb5bbd13f485a688cdc4
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Thu Apr 30 19:01:11 2020 +0300

    proc: add a proc_show_path method to fix mountinfo
    
    Original ms patch: 75509fd88fbd
    
      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 4eef2b46b87e8..0fff949bcc135 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};


More information about the Devel mailing list