Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

proc: Split the namespace stuff out into linux/proc_ns.h

Split the proc namespace stuff out into linux/proc_ns.h.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: netdev@vger.kernel.org
cc: Serge E. Hallyn <serge.hallyn@ubuntu.com>
cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

David Howells and committed by
Al Viro
0bb80f24 c3bef7bc

+109 -92
+3 -3
fs/namespace.c
··· 21 21 #include <linux/fs_struct.h> /* get_fs_root et.al. */ 22 22 #include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */ 23 23 #include <linux/uaccess.h> 24 - #include <linux/proc_fs.h> 24 + #include <linux/proc_ns.h> 25 25 #include "pnode.h" 26 26 #include "internal.h" 27 27 ··· 1350 1350 * mount namespace loop? 1351 1351 */ 1352 1352 struct inode *inode = path->dentry->d_inode; 1353 - struct proc_inode *ei; 1353 + struct proc_ns *ei; 1354 1354 struct mnt_namespace *mnt_ns; 1355 1355 1356 1356 if (!proc_ns_inode(inode)) 1357 1357 return false; 1358 1358 1359 - ei = PROC_I(inode); 1359 + ei = get_proc_ns(inode); 1360 1360 if (ei->ns_ops != &mntns_operations) 1361 1361 return false; 1362 1362
+4 -4
fs/proc/inode.c
··· 51 51 sysctl_head_put(head); 52 52 } 53 53 /* Release any associated namespace */ 54 - ns_ops = PROC_I(inode)->ns_ops; 55 - ns = PROC_I(inode)->ns; 54 + ns_ops = PROC_I(inode)->ns.ns_ops; 55 + ns = PROC_I(inode)->ns.ns; 56 56 if (ns_ops && ns) 57 57 ns_ops->put(ns); 58 58 } ··· 73 73 ei->pde = NULL; 74 74 ei->sysctl = NULL; 75 75 ei->sysctl_entry = NULL; 76 - ei->ns = NULL; 77 - ei->ns_ops = NULL; 76 + ei->ns.ns = NULL; 77 + ei->ns.ns_ops = NULL; 78 78 inode = &ei->vfs_inode; 79 79 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 80 80 return inode;
+11 -6
fs/proc/namespaces.c
··· 51 51 static char *ns_dname(struct dentry *dentry, char *buffer, int buflen) 52 52 { 53 53 struct inode *inode = dentry->d_inode; 54 - const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; 54 + const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns.ns_ops; 55 55 56 56 return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]", 57 57 ns_ops->name, inode->i_ino); ··· 95 95 inode->i_op = &ns_inode_operations; 96 96 inode->i_mode = S_IFREG | S_IRUGO; 97 97 inode->i_fop = &ns_file_operations; 98 - ei->ns_ops = ns_ops; 99 - ei->ns = ns; 98 + ei->ns.ns_ops = ns_ops; 99 + ei->ns.ns = ns; 100 100 unlock_new_inode(inode); 101 101 } else { 102 102 ns_ops->put(ns); ··· 128 128 if (!ptrace_may_access(task, PTRACE_MODE_READ)) 129 129 goto out_put_task; 130 130 131 - ns_path.dentry = proc_ns_get_dentry(sb, task, ei->ns_ops); 131 + ns_path.dentry = proc_ns_get_dentry(sb, task, ei->ns.ns_ops); 132 132 if (IS_ERR(ns_path.dentry)) { 133 133 error = ERR_CAST(ns_path.dentry); 134 134 goto out_put_task; ··· 148 148 { 149 149 struct inode *inode = dentry->d_inode; 150 150 struct proc_inode *ei = PROC_I(inode); 151 - const struct proc_ns_operations *ns_ops = ei->ns_ops; 151 + const struct proc_ns_operations *ns_ops = ei->ns.ns_ops; 152 152 struct task_struct *task; 153 153 void *ns; 154 154 char name[50]; ··· 202 202 ei = PROC_I(inode); 203 203 inode->i_mode = S_IFLNK|S_IRWXUGO; 204 204 inode->i_op = &proc_ns_link_inode_operations; 205 - ei->ns_ops = ns_ops; 205 + ei->ns.ns_ops = ns_ops; 206 206 207 207 d_set_d_op(dentry, &pid_dentry_operations); 208 208 d_add(dentry, inode); ··· 335 335 out_invalid: 336 336 fput(file); 337 337 return ERR_PTR(-EINVAL); 338 + } 339 + 340 + struct proc_ns *get_proc_ns(struct inode *inode) 341 + { 342 + return &PROC_I(inode)->ns; 338 343 } 339 344 340 345 bool proc_ns_inode(struct inode *inode)
+2 -66
include/linux/proc_fs.h
··· 6 6 #include <linux/spinlock.h> 7 7 #include <linux/magic.h> 8 8 #include <linux/atomic.h> 9 + #include <linux/proc_ns.h> 9 10 10 11 struct net; 11 12 struct completion; ··· 23 22 24 23 /* Worst case buffer size needed for holding an integer. */ 25 24 #define PROC_NUMBUF 13 26 - 27 - /* 28 - * We always define these enumerators 29 - */ 30 - 31 - enum { 32 - PROC_ROOT_INO = 1, 33 - PROC_IPC_INIT_INO = 0xEFFFFFFFU, 34 - PROC_UTS_INIT_INO = 0xEFFFFFFEU, 35 - PROC_USER_INIT_INO = 0xEFFFFFFDU, 36 - PROC_PID_INIT_INO = 0xEFFFFFFCU, 37 - }; 38 25 39 26 /* 40 27 * This is not completely implemented yet. The idea is to ··· 70 81 extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent); 71 82 extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent); 72 83 73 - struct pid_namespace; 74 - 75 - extern int pid_ns_prepare_proc(struct pid_namespace *ns); 76 - extern void pid_ns_release_proc(struct pid_namespace *ns); 77 84 78 85 /* 79 86 * proc_tty.c ··· 117 132 118 133 extern void proc_set_size(struct proc_dir_entry *, loff_t); 119 134 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); 120 - 121 - extern struct file *proc_ns_fget(int fd); 122 - extern bool proc_ns_inode(struct inode *inode); 123 - 124 - extern int proc_alloc_inum(unsigned int *pino); 125 - extern void proc_free_inum(unsigned int inum); 126 135 #else 127 136 128 137 static inline void proc_flush_task(struct task_struct *task) ··· 147 168 static inline void proc_tty_register_driver(struct tty_driver *driver) {}; 148 169 static inline void proc_tty_unregister_driver(struct tty_driver *driver) {}; 149 170 150 - static inline int pid_ns_prepare_proc(struct pid_namespace *ns) 151 - { 152 - return 0; 153 - } 154 - 155 - static inline void pid_ns_release_proc(struct pid_namespace *ns) 156 - { 157 - } 158 - 159 - static inline struct file *proc_ns_fget(int fd) 160 - { 161 - return ERR_PTR(-EINVAL); 162 - } 163 - 164 - static inline bool proc_ns_inode(struct inode *inode) 165 - { 166 - return false; 167 - } 168 - 169 - static inline int proc_alloc_inum(unsigned int *inum) 170 - { 171 - *inum = 1; 172 - return 0; 173 - } 174 - static inline void proc_free_inum(unsigned int inum) 175 - { 176 - } 177 171 #endif /* CONFIG_PROC_FS */ 178 172 179 - struct nsproxy; 180 - struct proc_ns_operations { 181 - const char *name; 182 - int type; 183 - void *(*get)(struct task_struct *task); 184 - void (*put)(void *ns); 185 - int (*install)(struct nsproxy *nsproxy, void *ns); 186 - unsigned int (*inum)(void *ns); 187 - }; 188 - extern const struct proc_ns_operations netns_operations; 189 - extern const struct proc_ns_operations utsns_operations; 190 - extern const struct proc_ns_operations ipcns_operations; 191 - extern const struct proc_ns_operations pidns_operations; 192 - extern const struct proc_ns_operations userns_operations; 193 - extern const struct proc_ns_operations mntns_operations; 194 173 195 174 union proc_op { 196 175 int (*proc_get_link)(struct dentry *, struct path *); ··· 168 231 struct proc_dir_entry *pde; 169 232 struct ctl_table_header *sysctl; 170 233 struct ctl_table *sysctl_entry; 171 - void *ns; 172 - const struct proc_ns_operations *ns_ops; 234 + struct proc_ns ns; 173 235 struct inode vfs_inode; 174 236 }; 175 237
+74
include/linux/proc_ns.h
··· 1 + /* 2 + * procfs namespace bits 3 + */ 4 + #ifndef _LINUX_PROC_NS_H 5 + #define _LINUX_PROC_NS_H 6 + 7 + struct pid_namespace; 8 + struct nsproxy; 9 + 10 + struct proc_ns_operations { 11 + const char *name; 12 + int type; 13 + void *(*get)(struct task_struct *task); 14 + void (*put)(void *ns); 15 + int (*install)(struct nsproxy *nsproxy, void *ns); 16 + unsigned int (*inum)(void *ns); 17 + }; 18 + 19 + struct proc_ns { 20 + void *ns; 21 + const struct proc_ns_operations *ns_ops; 22 + }; 23 + 24 + extern const struct proc_ns_operations netns_operations; 25 + extern const struct proc_ns_operations utsns_operations; 26 + extern const struct proc_ns_operations ipcns_operations; 27 + extern const struct proc_ns_operations pidns_operations; 28 + extern const struct proc_ns_operations userns_operations; 29 + extern const struct proc_ns_operations mntns_operations; 30 + 31 + /* 32 + * We always define these enumerators 33 + */ 34 + enum { 35 + PROC_ROOT_INO = 1, 36 + PROC_IPC_INIT_INO = 0xEFFFFFFFU, 37 + PROC_UTS_INIT_INO = 0xEFFFFFFEU, 38 + PROC_USER_INIT_INO = 0xEFFFFFFDU, 39 + PROC_PID_INIT_INO = 0xEFFFFFFCU, 40 + }; 41 + 42 + #ifdef CONFIG_PROC_FS 43 + 44 + extern int pid_ns_prepare_proc(struct pid_namespace *ns); 45 + extern void pid_ns_release_proc(struct pid_namespace *ns); 46 + extern struct file *proc_ns_fget(int fd); 47 + extern struct proc_ns *get_proc_ns(struct inode *); 48 + extern int proc_alloc_inum(unsigned int *pino); 49 + extern void proc_free_inum(unsigned int inum); 50 + extern bool proc_ns_inode(struct inode *inode); 51 + 52 + #else /* CONFIG_PROC_FS */ 53 + 54 + static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; } 55 + static inline void pid_ns_release_proc(struct pid_namespace *ns) {} 56 + 57 + static inline struct file *proc_ns_fget(int fd) 58 + { 59 + return ERR_PTR(-EINVAL); 60 + } 61 + 62 + static inline struct proc_ns *get_proc_ns(struct inode *inode) { return NULL; } 63 + 64 + static inline int proc_alloc_inum(unsigned int *inum) 65 + { 66 + *inum = 1; 67 + return 0; 68 + } 69 + static inline void proc_free_inum(unsigned int inum) {} 70 + static inline bool proc_ns_inode(struct inode *inode) { return false; } 71 + 72 + #endif /* CONFIG_PROC_FS */ 73 + 74 + #endif /* _LINUX_PROC_NS_H */
+1 -1
init/version.c
··· 12 12 #include <linux/utsname.h> 13 13 #include <generated/utsrelease.h> 14 14 #include <linux/version.h> 15 - #include <linux/proc_fs.h> 15 + #include <linux/proc_ns.h> 16 16 17 17 #ifndef CONFIG_KALLSYMS 18 18 #define version(a) Version_ ## a
+1 -1
ipc/msgutil.c
··· 16 16 #include <linux/msg.h> 17 17 #include <linux/ipc_namespace.h> 18 18 #include <linux/utsname.h> 19 - #include <linux/proc_fs.h> 19 + #include <linux/proc_ns.h> 20 20 #include <asm/uaccess.h> 21 21 22 22 #include "util.h"
+1 -1
ipc/namespace.c
··· 12 12 #include <linux/fs.h> 13 13 #include <linux/mount.h> 14 14 #include <linux/user_namespace.h> 15 - #include <linux/proc_fs.h> 15 + #include <linux/proc_ns.h> 16 16 17 17 #include "util.h" 18 18
+3 -3
kernel/nsproxy.c
··· 22 22 #include <linux/pid_namespace.h> 23 23 #include <net/net_namespace.h> 24 24 #include <linux/ipc_namespace.h> 25 - #include <linux/proc_fs.h> 25 + #include <linux/proc_ns.h> 26 26 #include <linux/file.h> 27 27 #include <linux/syscalls.h> 28 28 ··· 241 241 const struct proc_ns_operations *ops; 242 242 struct task_struct *tsk = current; 243 243 struct nsproxy *new_nsproxy; 244 - struct proc_inode *ei; 244 + struct proc_ns *ei; 245 245 struct file *file; 246 246 int err; 247 247 ··· 250 250 return PTR_ERR(file); 251 251 252 252 err = -EINVAL; 253 - ei = PROC_I(file_inode(file)); 253 + ei = get_proc_ns(file_inode(file)); 254 254 ops = ei->ns_ops; 255 255 if (nstype && (ops->type != nstype)) 256 256 goto out;
+1
kernel/pid.c
··· 36 36 #include <linux/pid_namespace.h> 37 37 #include <linux/init_task.h> 38 38 #include <linux/syscalls.h> 39 + #include <linux/proc_ns.h> 39 40 #include <linux/proc_fs.h> 40 41 41 42 #define pid_hashfn(nr, ns) \
+1 -1
kernel/pid_namespace.c
··· 15 15 #include <linux/err.h> 16 16 #include <linux/acct.h> 17 17 #include <linux/slab.h> 18 - #include <linux/proc_fs.h> 18 + #include <linux/proc_ns.h> 19 19 #include <linux/reboot.h> 20 20 #include <linux/export.h> 21 21
+1 -1
kernel/user.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/export.h> 18 18 #include <linux/user_namespace.h> 19 - #include <linux/proc_fs.h> 19 + #include <linux/proc_ns.h> 20 20 21 21 /* 22 22 * userns count is 1 for root user, 1 for init_uts_ns,
+1 -1
kernel/user_namespace.c
··· 9 9 #include <linux/nsproxy.h> 10 10 #include <linux/slab.h> 11 11 #include <linux/user_namespace.h> 12 - #include <linux/proc_fs.h> 12 + #include <linux/proc_ns.h> 13 13 #include <linux/highuid.h> 14 14 #include <linux/cred.h> 15 15 #include <linux/securebits.h>
+1 -1
kernel/utsname.c
··· 15 15 #include <linux/err.h> 16 16 #include <linux/slab.h> 17 17 #include <linux/user_namespace.h> 18 - #include <linux/proc_fs.h> 18 + #include <linux/proc_ns.h> 19 19 20 20 static struct uts_namespace *create_uts_ns(void) 21 21 {
+4 -3
net/core/net_namespace.c
··· 10 10 #include <linux/idr.h> 11 11 #include <linux/rculist.h> 12 12 #include <linux/nsproxy.h> 13 - #include <linux/proc_fs.h> 13 + #include <linux/fs.h> 14 + #include <linux/proc_ns.h> 14 15 #include <linux/file.h> 15 16 #include <linux/export.h> 16 17 #include <linux/user_namespace.h> ··· 337 336 338 337 struct net *get_net_ns_by_fd(int fd) 339 338 { 340 - struct proc_inode *ei; 339 + struct proc_ns *ei; 341 340 struct file *file; 342 341 struct net *net; 343 342 ··· 345 344 if (IS_ERR(file)) 346 345 return ERR_CAST(file); 347 346 348 - ei = PROC_I(file_inode(file)); 347 + ei = get_proc_ns(file_inode(file)); 349 348 if (ei->ns_ops == &netns_operations) 350 349 net = get_net(ei->ns); 351 350 else