Skip to content

Commit f77c801

Browse files
author
Al Viro
committed
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>
1 parent 33c4294 commit f77c801

6 files changed

Lines changed: 15 additions & 27 deletions

File tree

fs/namespace.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,16 +1570,7 @@ static bool is_mnt_ns_file(struct dentry *dentry)
15701570
{
15711571
/* Is this a proxy for a mount namespace? */
15721572
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;
15831574
}
15841575

15851576
struct mnt_namespace *to_mnt_ns(struct ns_common *ns)
@@ -1596,7 +1587,7 @@ static bool mnt_ns_loop(struct dentry *dentry)
15961587
if (!is_mnt_ns_file(dentry))
15971588
return false;
15981589

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));
16001591
return current->nsproxy->mnt_ns->seq >= mnt_ns->seq;
16011592
}
16021593

fs/proc/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ union proc_op {
5757
struct task_struct *task);
5858
};
5959

60+
struct proc_ns {
61+
struct ns_common *ns;
62+
const struct proc_ns_operations *ns_ops;
63+
};
64+
6065
struct proc_inode {
6166
struct pid *pid;
6267
int fd;

fs/proc/namespaces.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static const struct inode_operations ns_inode_operations = {
4545
static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
4646
{
4747
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;
4949

5050
return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]",
5151
ns_ops->name, inode->i_ino);
@@ -75,6 +75,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
7575
ns_ops->put(ns);
7676
return ERR_PTR(-ENOMEM);
7777
}
78+
dentry->d_fsdata = (void *)ns_ops;
7879

7980
inode = iget_locked(sb, ns->inum);
8081
if (!inode) {
@@ -286,9 +287,9 @@ struct file *proc_ns_fget(int fd)
286287
return ERR_PTR(-EINVAL);
287288
}
288289

289-
struct proc_ns *get_proc_ns(struct inode *inode)
290+
struct ns_common *get_proc_ns(struct inode *inode)
290291
{
291-
return &PROC_I(inode)->ns;
292+
return PROC_I(inode)->ns.ns;
292293
}
293294

294295
bool proc_ns_inode(struct inode *inode)

include/linux/proc_ns.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ struct proc_ns_operations {
1616
int (*install)(struct nsproxy *nsproxy, struct ns_common *ns);
1717
};
1818

19-
struct proc_ns {
20-
struct ns_common *ns;
21-
const struct proc_ns_operations *ns_ops;
22-
};
23-
2419
extern const struct proc_ns_operations netns_operations;
2520
extern const struct proc_ns_operations utsns_operations;
2621
extern const struct proc_ns_operations ipcns_operations;
@@ -44,7 +39,7 @@ enum {
4439
extern int pid_ns_prepare_proc(struct pid_namespace *ns);
4540
extern void pid_ns_release_proc(struct pid_namespace *ns);
4641
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 *);
4843
extern int proc_alloc_inum(unsigned int *pino);
4944
extern void proc_free_inum(unsigned int inum);
5045
extern bool proc_ns_inode(struct inode *inode);
@@ -59,7 +54,7 @@ static inline struct file *proc_ns_fget(int fd)
5954
return ERR_PTR(-EINVAL);
6055
}
6156

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; }
6358

6459
static inline int proc_alloc_inum(unsigned int *inum)
6560
{

kernel/nsproxy.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
222222
{
223223
struct task_struct *tsk = current;
224224
struct nsproxy *new_nsproxy;
225-
struct proc_ns *ei;
226225
struct file *file;
227226
struct ns_common *ns;
228227
int err;
@@ -232,8 +231,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
232231
return PTR_ERR(file);
233232

234233
err = -EINVAL;
235-
ei = get_proc_ns(file_inode(file));
236-
ns = ei->ns;
234+
ns = get_proc_ns(file_inode(file));
237235
if (nstype && (ns->ops->type != nstype))
238236
goto out;
239237

net/core/net_namespace.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ EXPORT_SYMBOL_GPL(__put_net);
337337

338338
struct net *get_net_ns_by_fd(int fd)
339339
{
340-
struct proc_ns *ei;
341340
struct file *file;
342341
struct ns_common *ns;
343342
struct net *net;
@@ -346,8 +345,7 @@ struct net *get_net_ns_by_fd(int fd)
346345
if (IS_ERR(file))
347346
return ERR_CAST(file);
348347

349-
ei = get_proc_ns(file_inode(file));
350-
ns = ei->ns;
348+
ns = get_proc_ns(file_inode(file));
351349
if (ns->ops == &netns_operations)
352350
net = get_net(container_of(ns, struct net, ns));
353351
else

0 commit comments

Comments
 (0)