Commit f77c80142e1afe6d5c16975ca5d7d1fc324b16f9
1 parent
33c429405a
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
bury struct proc_ns in fs/proc
a) make get_proc_ns() return a pointer to struct ns_common b) mirror ns_ops in dentry->d_fsdata of ns dentries, so that is_mnt_ns_file() could get away with fewer dereferences. That way struct proc_ns becomes invisible outside of fs/proc/*.c Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 6 changed files with 15 additions and 27 deletions Side-by-side Diff
fs/namespace.c
... | ... | @@ -1570,16 +1570,7 @@ |
1570 | 1570 | { |
1571 | 1571 | /* Is this a proxy for a mount namespace? */ |
1572 | 1572 | struct inode *inode = dentry->d_inode; |
1573 | - struct proc_ns *ei; | |
1574 | - | |
1575 | - if (!proc_ns_inode(inode)) | |
1576 | - return false; | |
1577 | - | |
1578 | - ei = get_proc_ns(inode); | |
1579 | - if (ei->ns_ops != &mntns_operations) | |
1580 | - return false; | |
1581 | - | |
1582 | - return true; | |
1573 | + return proc_ns_inode(inode) && dentry->d_fsdata == &mntns_operations; | |
1583 | 1574 | } |
1584 | 1575 | |
1585 | 1576 | struct mnt_namespace *to_mnt_ns(struct ns_common *ns) |
... | ... | @@ -1596,7 +1587,7 @@ |
1596 | 1587 | if (!is_mnt_ns_file(dentry)) |
1597 | 1588 | return false; |
1598 | 1589 | |
1599 | - mnt_ns = to_mnt_ns(get_proc_ns(dentry->d_inode)->ns); | |
1590 | + mnt_ns = to_mnt_ns(get_proc_ns(dentry->d_inode)); | |
1600 | 1591 | return current->nsproxy->mnt_ns->seq >= mnt_ns->seq; |
1601 | 1592 | } |
1602 | 1593 |
fs/proc/internal.h
fs/proc/namespaces.c
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | static char *ns_dname(struct dentry *dentry, char *buffer, int buflen) |
46 | 46 | { |
47 | 47 | struct inode *inode = dentry->d_inode; |
48 | - const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns.ns_ops; | |
48 | + const struct proc_ns_operations *ns_ops = dentry->d_fsdata; | |
49 | 49 | |
50 | 50 | return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]", |
51 | 51 | ns_ops->name, inode->i_ino); |
... | ... | @@ -75,6 +75,7 @@ |
75 | 75 | ns_ops->put(ns); |
76 | 76 | return ERR_PTR(-ENOMEM); |
77 | 77 | } |
78 | + dentry->d_fsdata = (void *)ns_ops; | |
78 | 79 | |
79 | 80 | inode = iget_locked(sb, ns->inum); |
80 | 81 | if (!inode) { |
81 | 82 | |
... | ... | @@ -286,9 +287,9 @@ |
286 | 287 | return ERR_PTR(-EINVAL); |
287 | 288 | } |
288 | 289 | |
289 | -struct proc_ns *get_proc_ns(struct inode *inode) | |
290 | +struct ns_common *get_proc_ns(struct inode *inode) | |
290 | 291 | { |
291 | - return &PROC_I(inode)->ns; | |
292 | + return PROC_I(inode)->ns.ns; | |
292 | 293 | } |
293 | 294 | |
294 | 295 | bool proc_ns_inode(struct inode *inode) |
include/linux/proc_ns.h
... | ... | @@ -16,11 +16,6 @@ |
16 | 16 | int (*install)(struct nsproxy *nsproxy, struct ns_common *ns); |
17 | 17 | }; |
18 | 18 | |
19 | -struct proc_ns { | |
20 | - struct ns_common *ns; | |
21 | - const struct proc_ns_operations *ns_ops; | |
22 | -}; | |
23 | - | |
24 | 19 | extern const struct proc_ns_operations netns_operations; |
25 | 20 | extern const struct proc_ns_operations utsns_operations; |
26 | 21 | extern const struct proc_ns_operations ipcns_operations; |
... | ... | @@ -44,7 +39,7 @@ |
44 | 39 | extern int pid_ns_prepare_proc(struct pid_namespace *ns); |
45 | 40 | extern void pid_ns_release_proc(struct pid_namespace *ns); |
46 | 41 | extern struct file *proc_ns_fget(int fd); |
47 | -extern struct proc_ns *get_proc_ns(struct inode *); | |
42 | +extern struct ns_common *get_proc_ns(struct inode *); | |
48 | 43 | extern int proc_alloc_inum(unsigned int *pino); |
49 | 44 | extern void proc_free_inum(unsigned int inum); |
50 | 45 | extern bool proc_ns_inode(struct inode *inode); |
... | ... | @@ -59,7 +54,7 @@ |
59 | 54 | return ERR_PTR(-EINVAL); |
60 | 55 | } |
61 | 56 | |
62 | -static inline struct proc_ns *get_proc_ns(struct inode *inode) { return NULL; } | |
57 | +static inline struct ns_common *get_proc_ns(struct inode *inode) { return NULL; } | |
63 | 58 | |
64 | 59 | static inline int proc_alloc_inum(unsigned int *inum) |
65 | 60 | { |
kernel/nsproxy.c
... | ... | @@ -222,7 +222,6 @@ |
222 | 222 | { |
223 | 223 | struct task_struct *tsk = current; |
224 | 224 | struct nsproxy *new_nsproxy; |
225 | - struct proc_ns *ei; | |
226 | 225 | struct file *file; |
227 | 226 | struct ns_common *ns; |
228 | 227 | int err; |
... | ... | @@ -232,8 +231,7 @@ |
232 | 231 | return PTR_ERR(file); |
233 | 232 | |
234 | 233 | err = -EINVAL; |
235 | - ei = get_proc_ns(file_inode(file)); | |
236 | - ns = ei->ns; | |
234 | + ns = get_proc_ns(file_inode(file)); | |
237 | 235 | if (nstype && (ns->ops->type != nstype)) |
238 | 236 | goto out; |
239 | 237 |
net/core/net_namespace.c
... | ... | @@ -337,7 +337,6 @@ |
337 | 337 | |
338 | 338 | struct net *get_net_ns_by_fd(int fd) |
339 | 339 | { |
340 | - struct proc_ns *ei; | |
341 | 340 | struct file *file; |
342 | 341 | struct ns_common *ns; |
343 | 342 | struct net *net; |
... | ... | @@ -346,8 +345,7 @@ |
346 | 345 | if (IS_ERR(file)) |
347 | 346 | return ERR_CAST(file); |
348 | 347 | |
349 | - ei = get_proc_ns(file_inode(file)); | |
350 | - ns = ei->ns; | |
348 | + ns = get_proc_ns(file_inode(file)); | |
351 | 349 | if (ns->ops == &netns_operations) |
352 | 350 | net = get_net(container_of(ns, struct net, ns)); |
353 | 351 | else |