diff --git a/fs/nsfs.c b/fs/nsfs.c index 8f20d60..bfd5bde 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -8,8 +8,20 @@ static struct vfsmount *nsfs_mnt; +static void show_fdinfo(struct seq_file *m, struct file *f) +{ + struct dentry *dentry = f->f_path.dentry; + struct inode *inode = d_inode(dentry); + const struct proc_ns_operations *ns_ops = dentry->d_fsdata; + struct ns_common *ns = inode->i_private; + + if (ns_ops->show_fdinfo) + ns_ops->show_fdinfo(m, ns); +} + static const struct file_operations ns_file_operations = { .llseek = no_llseek, + .show_fdinfo = show_fdinfo, }; static char *ns_dname(struct dentry *dentry, char *buffer, int buflen) diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index de0e771..fed276b 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -18,6 +18,7 @@ struct proc_ns_operations { struct ns_common *(*get)(struct task_struct *task); void (*put)(struct ns_common *ns); int (*install)(struct nsproxy *nsproxy, struct ns_common *ns); + void (*show_fdinfo)(struct seq_file *m, struct ns_common *ns); }; extern const struct proc_ns_operations netns_operations; diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index a65ba13..910b388 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -388,12 +388,20 @@ static int pidns_install(struct nsproxy *nsproxy, struct ns_common *ns) return 0; } +static void pidns_fdinfo(struct seq_file *m, struct ns_common *ns) +{ + struct pid_namespace *pidns = to_pid_ns(ns); + + seq_printf(m, "userns: %u\n", pidns->user_ns->ns.inum); +} + const struct proc_ns_operations pidns_operations = { .name = "pid", .type = CLONE_NEWPID, .get = pidns_get, .put = pidns_put, .install = pidns_install, + .show_fdinfo = pidns_fdinfo, }; static __init int pid_namespaces_init(void)