New pseudo-filesystem: nsfs. Targets of /proc/*/ns/* live there now. It's not mountable (not even registered, so it's not in /proc/filesystems, etc.). Files on it *are* bindable - we explicitly permit that in do_loopback(). This stuff lives in fs/nsfs.c now; proc_ns_fget() moved there as well. get_proc_ns() is a macro now (it's simply returning ->i_private; would have been an inline, if not for header ordering headache). proc_ns_inode() is an ex-parrot. The interface used in procfs is ns_get_path(path, task, ops) and ns_get_name(buf, size, task, ops). Dentries and inodes are never hashed; a non-counting reference to dentry is stashed in ns_common (removed by ->d_prune()) and reused by ns_get_path() if present. See ns_get_path()/ns_prune_dentry/nsfs_evict() for details of that mechanism. As the result, proc_ns_follow_link() has stopped poking in nd->path.mnt; it does nd_jump_link() on a consistent <vfsmount,dentry> pair it gets from ns_get_path().
Showing the changes to include (3 of 10 files). Show all
Unified · Split
| @@ -4,6 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | struct proc_ns_operations; |
| 5 | 5 | |
| 6 | 6 | struct ns_common { |
| 7 | + atomic_long_t stashed; | |
| 7 | 8 | const struct proc_ns_operations *ops; |
| 8 | 9 | unsigned int inum; |
| 9 | 10 | }; |
| @@ -4,9 +4,11 @@ · 3 unmodified lines | ||
| 4 | 4 | #ifndef _LINUX_PROC_NS_H |
| 5 | 5 | #define _LINUX_PROC_NS_H |
| 6 | 6 | |
| 7 | +#include <linux/ns_common.h> | |
| 8 | + | |
| 7 | 9 | struct pid_namespace; |
| 8 | 10 | struct nsproxy; |
| 9 | −struct ns_common; | |
| 11 | +struct path; | |
| 10 | 12 | |
| 11 | 13 | struct proc_ns_operations { |
| 12 | 14 | const char *name; |
| @@ -38,35 +40,38 @@ enum { · 25 unmodified lines | ||
| 38 | 40 | |
| 39 | 41 | extern int pid_ns_prepare_proc(struct pid_namespace *ns); |
| 40 | 42 | extern void pid_ns_release_proc(struct pid_namespace *ns); |
| 41 | −extern struct file *proc_ns_fget(int fd); | |
| 42 | −extern struct ns_common *get_proc_ns(struct inode *); | |
| 43 | 43 | extern int proc_alloc_inum(unsigned int *pino); |
| 44 | 44 | extern void proc_free_inum(unsigned int inum); |
| 45 | −extern bool proc_ns_inode(struct inode *inode); | |
| 46 | 45 | |
| 47 | 46 | #else /* CONFIG_PROC_FS */ |
| 48 | 47 | |
| 49 | 48 | static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; } |
| 50 | 49 | static inline void pid_ns_release_proc(struct pid_namespace *ns) {} |
| 51 | 50 | |
| 52 | −static inline struct file *proc_ns_fget(int fd) | |
| 53 | −{ | |
| 54 | − return ERR_PTR(-EINVAL); | |
| 55 | −} | |
| 56 | − | |
| 57 | −static inline struct ns_common *get_proc_ns(struct inode *inode) { return NULL; } | |
| 58 | − | |
| 59 | 51 | static inline int proc_alloc_inum(unsigned int *inum) |
| 60 | 52 | { |
| 61 | 53 | *inum = 1; |
| 62 | 54 | return 0; |
| 63 | 55 | } |
| 64 | 56 | static inline void proc_free_inum(unsigned int inum) {} |
| 65 | −static inline bool proc_ns_inode(struct inode *inode) { return false; } | |
| 66 | 57 | |
| 67 | 58 | #endif /* CONFIG_PROC_FS */ |
| 68 | 59 | |
| 69 | −#define ns_alloc_inum(ns) proc_alloc_inum(&(ns)->inum) | |
| 60 | +static inline int ns_alloc_inum(struct ns_common *ns) | |
| 61 | +{ | |
| 62 | + atomic_long_set(&ns->stashed, 0); | |
| 63 | + return proc_alloc_inum(&ns->inum); | |
| 64 | +} | |
| 65 | + | |
| 70 | 66 | #define ns_free_inum(ns) proc_free_inum((ns)->inum) |
| 71 | 67 | |
| 68 | +extern struct file *proc_ns_fget(int fd); | |
| 69 | +#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) | |
| 70 | +extern void *ns_get_path(struct path *path, struct task_struct *task, | |
| 71 | + const struct proc_ns_operations *ns_ops); | |
| 72 | + | |
| 73 | +extern int ns_get_name(char *buf, size_t size, struct task_struct *task, | |
| 74 | + const struct proc_ns_operations *ns_ops); | |
| 75 | +extern void nsfs_init(void); | |
| 76 | + | |
| 72 | 77 | #endif /* _LINUX_PROC_NS_H */ |
| @@ -72,5 +72,6 @@ · 71 unmodified lines | ||
| 72 | 72 | #define MTD_INODE_FS_MAGIC 0x11307854 |
| 73 | 73 | #define ANON_INODE_FS_MAGIC 0x09041934 |
| 74 | 74 | #define BTRFS_TEST_MAGIC 0x73727279 |
| 75 | +#define NSFS_MAGIC 0x6e736673 | |
| 75 | 76 | |
| 76 | 77 | #endif /* __LINUX_MAGIC_H__ */ |