Skip to content

Commit 0bb80f2

Browse files
dhowellsAl Viro
authored and
Al Viro
committed
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 <[email protected]> cc: [email protected] cc: Serge E. Hallyn <[email protected]> cc: Eric W. Biederman <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent c3bef7b commit 0bb80f2

15 files changed

+109
-92
lines changed

fs/namespace.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <linux/fs_struct.h> /* get_fs_root et.al. */
2222
#include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
2323
#include <linux/uaccess.h>
24-
#include <linux/proc_fs.h>
24+
#include <linux/proc_ns.h>
2525
#include "pnode.h"
2626
#include "internal.h"
2727

@@ -1350,13 +1350,13 @@ static bool mnt_ns_loop(struct path *path)
13501350
* mount namespace loop?
13511351
*/
13521352
struct inode *inode = path->dentry->d_inode;
1353-
struct proc_inode *ei;
1353+
struct proc_ns *ei;
13541354
struct mnt_namespace *mnt_ns;
13551355

13561356
if (!proc_ns_inode(inode))
13571357
return false;
13581358

1359-
ei = PROC_I(inode);
1359+
ei = get_proc_ns(inode);
13601360
if (ei->ns_ops != &mntns_operations)
13611361
return false;
13621362

fs/proc/inode.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static void proc_evict_inode(struct inode *inode)
5151
sysctl_head_put(head);
5252
}
5353
/* 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;
5656
if (ns_ops && ns)
5757
ns_ops->put(ns);
5858
}
@@ -73,8 +73,8 @@ static struct inode *proc_alloc_inode(struct super_block *sb)
7373
ei->pde = NULL;
7474
ei->sysctl = NULL;
7575
ei->sysctl_entry = NULL;
76-
ei->ns = NULL;
77-
ei->ns_ops = NULL;
76+
ei->ns.ns = NULL;
77+
ei->ns.ns_ops = NULL;
7878
inode = &ei->vfs_inode;
7979
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
8080
return inode;

fs/proc/namespaces.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int ns_delete_dentry(const struct dentry *dentry)
5151
static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
5252
{
5353
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;
5555

5656
return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]",
5757
ns_ops->name, inode->i_ino);
@@ -95,8 +95,8 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
9595
inode->i_op = &ns_inode_operations;
9696
inode->i_mode = S_IFREG | S_IRUGO;
9797
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;
100100
unlock_new_inode(inode);
101101
} else {
102102
ns_ops->put(ns);
@@ -128,7 +128,7 @@ static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd)
128128
if (!ptrace_may_access(task, PTRACE_MODE_READ))
129129
goto out_put_task;
130130

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);
132132
if (IS_ERR(ns_path.dentry)) {
133133
error = ERR_CAST(ns_path.dentry);
134134
goto out_put_task;
@@ -148,7 +148,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
148148
{
149149
struct inode *inode = dentry->d_inode;
150150
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;
152152
struct task_struct *task;
153153
void *ns;
154154
char name[50];
@@ -202,7 +202,7 @@ static struct dentry *proc_ns_instantiate(struct inode *dir,
202202
ei = PROC_I(inode);
203203
inode->i_mode = S_IFLNK|S_IRWXUGO;
204204
inode->i_op = &proc_ns_link_inode_operations;
205-
ei->ns_ops = ns_ops;
205+
ei->ns.ns_ops = ns_ops;
206206

207207
d_set_d_op(dentry, &pid_dentry_operations);
208208
d_add(dentry, inode);
@@ -337,6 +337,11 @@ struct file *proc_ns_fget(int fd)
337337
return ERR_PTR(-EINVAL);
338338
}
339339

340+
struct proc_ns *get_proc_ns(struct inode *inode)
341+
{
342+
return &PROC_I(inode)->ns;
343+
}
344+
340345
bool proc_ns_inode(struct inode *inode)
341346
{
342347
return inode->i_fop == &ns_file_operations;

include/linux/proc_fs.h

+2-66
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/spinlock.h>
77
#include <linux/magic.h>
88
#include <linux/atomic.h>
9+
#include <linux/proc_ns.h>
910

1011
struct net;
1112
struct completion;
@@ -23,18 +24,6 @@ struct mm_struct;
2324
/* Worst case buffer size needed for holding an integer. */
2425
#define PROC_NUMBUF 13
2526

26-
/*
27-
* We always define these enumerators
28-
*/
29-
30-
enum {
31-
PROC_ROOT_INO = 1,
32-
PROC_IPC_INIT_INO = 0xEFFFFFFFU,
33-
PROC_UTS_INIT_INO = 0xEFFFFFFEU,
34-
PROC_USER_INIT_INO = 0xEFFFFFFDU,
35-
PROC_PID_INIT_INO = 0xEFFFFFFCU,
36-
};
37-
3827
/*
3928
* This is not completely implemented yet. The idea is to
4029
* create an in-memory tree (like the actual /proc filesystem
@@ -81,10 +70,6 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
8170
extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
8271
extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
8372

84-
struct pid_namespace;
85-
86-
extern int pid_ns_prepare_proc(struct pid_namespace *ns);
87-
extern void pid_ns_release_proc(struct pid_namespace *ns);
8873

8974
/*
9075
* proc_tty.c
@@ -132,12 +117,6 @@ extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
132117

133118
extern void proc_set_size(struct proc_dir_entry *, loff_t);
134119
extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
135-
136-
extern struct file *proc_ns_fget(int fd);
137-
extern bool proc_ns_inode(struct inode *inode);
138-
139-
extern int proc_alloc_inum(unsigned int *pino);
140-
extern void proc_free_inum(unsigned int inum);
141120
#else
142121

143122
static inline void proc_flush_task(struct task_struct *task)
@@ -168,50 +147,8 @@ struct tty_driver;
168147
static inline void proc_tty_register_driver(struct tty_driver *driver) {};
169148
static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
170149

171-
static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
172-
{
173-
return 0;
174-
}
175-
176-
static inline void pid_ns_release_proc(struct pid_namespace *ns)
177-
{
178-
}
179-
180-
static inline struct file *proc_ns_fget(int fd)
181-
{
182-
return ERR_PTR(-EINVAL);
183-
}
184-
185-
static inline bool proc_ns_inode(struct inode *inode)
186-
{
187-
return false;
188-
}
189-
190-
static inline int proc_alloc_inum(unsigned int *inum)
191-
{
192-
*inum = 1;
193-
return 0;
194-
}
195-
static inline void proc_free_inum(unsigned int inum)
196-
{
197-
}
198150
#endif /* CONFIG_PROC_FS */
199151

200-
struct nsproxy;
201-
struct proc_ns_operations {
202-
const char *name;
203-
int type;
204-
void *(*get)(struct task_struct *task);
205-
void (*put)(void *ns);
206-
int (*install)(struct nsproxy *nsproxy, void *ns);
207-
unsigned int (*inum)(void *ns);
208-
};
209-
extern const struct proc_ns_operations netns_operations;
210-
extern const struct proc_ns_operations utsns_operations;
211-
extern const struct proc_ns_operations ipcns_operations;
212-
extern const struct proc_ns_operations pidns_operations;
213-
extern const struct proc_ns_operations userns_operations;
214-
extern const struct proc_ns_operations mntns_operations;
215152

216153
union proc_op {
217154
int (*proc_get_link)(struct dentry *, struct path *);
@@ -231,8 +168,7 @@ struct proc_inode {
231168
struct proc_dir_entry *pde;
232169
struct ctl_table_header *sysctl;
233170
struct ctl_table *sysctl_entry;
234-
void *ns;
235-
const struct proc_ns_operations *ns_ops;
171+
struct proc_ns ns;
236172
struct inode vfs_inode;
237173
};
238174

include/linux/proc_ns.h

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 */

init/version.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <linux/utsname.h>
1313
#include <generated/utsrelease.h>
1414
#include <linux/version.h>
15-
#include <linux/proc_fs.h>
15+
#include <linux/proc_ns.h>
1616

1717
#ifndef CONFIG_KALLSYMS
1818
#define version(a) Version_ ## a

ipc/msgutil.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/msg.h>
1717
#include <linux/ipc_namespace.h>
1818
#include <linux/utsname.h>
19-
#include <linux/proc_fs.h>
19+
#include <linux/proc_ns.h>
2020
#include <asm/uaccess.h>
2121

2222
#include "util.h"

ipc/namespace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <linux/fs.h>
1313
#include <linux/mount.h>
1414
#include <linux/user_namespace.h>
15-
#include <linux/proc_fs.h>
15+
#include <linux/proc_ns.h>
1616

1717
#include "util.h"
1818

kernel/nsproxy.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <linux/pid_namespace.h>
2323
#include <net/net_namespace.h>
2424
#include <linux/ipc_namespace.h>
25-
#include <linux/proc_fs.h>
25+
#include <linux/proc_ns.h>
2626
#include <linux/file.h>
2727
#include <linux/syscalls.h>
2828

@@ -241,7 +241,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
241241
const struct proc_ns_operations *ops;
242242
struct task_struct *tsk = current;
243243
struct nsproxy *new_nsproxy;
244-
struct proc_inode *ei;
244+
struct proc_ns *ei;
245245
struct file *file;
246246
int err;
247247

@@ -250,7 +250,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
250250
return PTR_ERR(file);
251251

252252
err = -EINVAL;
253-
ei = PROC_I(file_inode(file));
253+
ei = get_proc_ns(file_inode(file));
254254
ops = ei->ns_ops;
255255
if (nstype && (ops->type != nstype))
256256
goto out;

kernel/pid.c

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/pid_namespace.h>
3737
#include <linux/init_task.h>
3838
#include <linux/syscalls.h>
39+
#include <linux/proc_ns.h>
3940
#include <linux/proc_fs.h>
4041

4142
#define pid_hashfn(nr, ns) \

kernel/pid_namespace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/err.h>
1616
#include <linux/acct.h>
1717
#include <linux/slab.h>
18-
#include <linux/proc_fs.h>
18+
#include <linux/proc_ns.h>
1919
#include <linux/reboot.h>
2020
#include <linux/export.h>
2121

kernel/user.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/interrupt.h>
1717
#include <linux/export.h>
1818
#include <linux/user_namespace.h>
19-
#include <linux/proc_fs.h>
19+
#include <linux/proc_ns.h>
2020

2121
/*
2222
* userns count is 1 for root user, 1 for init_uts_ns,

kernel/user_namespace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/nsproxy.h>
1010
#include <linux/slab.h>
1111
#include <linux/user_namespace.h>
12-
#include <linux/proc_fs.h>
12+
#include <linux/proc_ns.h>
1313
#include <linux/highuid.h>
1414
#include <linux/cred.h>
1515
#include <linux/securebits.h>

kernel/utsname.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/err.h>
1616
#include <linux/slab.h>
1717
#include <linux/user_namespace.h>
18-
#include <linux/proc_fs.h>
18+
#include <linux/proc_ns.h>
1919

2020
static struct uts_namespace *create_uts_ns(void)
2121
{

0 commit comments

Comments
 (0)