Skip to content

Commit 6496452

Browse files
author
Al Viro
committed
make proc_ns_operations work with struct ns_common * instead of void *
We can do that now. And kill ->inum(), while we are at it - all instances are identical. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 3c04118 commit 6496452

9 files changed

Lines changed: 28 additions & 65 deletions

File tree

‎fs/namespace.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,7 +3149,7 @@ bool fs_fully_visible(struct file_system_type *type)
31493149
return visible;
31503150
}
31513151

3152-
static void *mntns_get(struct task_struct *task)
3152+
static struct ns_common *mntns_get(struct task_struct *task)
31533153
{
31543154
struct ns_common *ns = NULL;
31553155
struct nsproxy *nsproxy;
@@ -3165,12 +3165,12 @@ static void *mntns_get(struct task_struct *task)
31653165
return ns;
31663166
}
31673167

3168-
static void mntns_put(void *ns)
3168+
static void mntns_put(struct ns_common *ns)
31693169
{
31703170
put_mnt_ns(to_mnt_ns(ns));
31713171
}
31723172

3173-
static int mntns_install(struct nsproxy *nsproxy, void *ns)
3173+
static int mntns_install(struct nsproxy *nsproxy, struct ns_common *ns)
31743174
{
31753175
struct fs_struct *fs = current->fs;
31763176
struct mnt_namespace *mnt_ns = to_mnt_ns(ns);
@@ -3203,17 +3203,10 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
32033203
return 0;
32043204
}
32053205

3206-
static unsigned int mntns_inum(void *ns)
3207-
{
3208-
struct ns_common *p = ns;
3209-
return p->inum;
3210-
}
3211-
32123206
const struct proc_ns_operations mntns_operations = {
32133207
.name = "mnt",
32143208
.type = CLONE_NEWNS,
32153209
.get = mntns_get,
32163210
.put = mntns_put,
32173211
.install = mntns_install,
3218-
.inum = mntns_inum,
32193212
};

‎fs/proc/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void proc_evict_inode(struct inode *inode)
3333
struct proc_dir_entry *de;
3434
struct ctl_table_header *head;
3535
const struct proc_ns_operations *ns_ops;
36-
void *ns;
36+
struct ns_common *ns;
3737

3838
truncate_inode_pages_final(&inode->i_data);
3939
clear_inode(inode);

‎fs/proc/namespaces.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
6464
struct inode *inode;
6565
struct proc_inode *ei;
6666
struct qstr qname = { .name = "", };
67-
void *ns;
67+
struct ns_common *ns;
6868

6969
ns = ns_ops->get(task);
7070
if (!ns)
@@ -76,7 +76,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
7676
return ERR_PTR(-ENOMEM);
7777
}
7878

79-
inode = iget_locked(sb, ns_ops->inum(ns));
79+
inode = iget_locked(sb, ns->inum);
8080
if (!inode) {
8181
dput(dentry);
8282
ns_ops->put(ns);
@@ -144,7 +144,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
144144
struct proc_inode *ei = PROC_I(inode);
145145
const struct proc_ns_operations *ns_ops = ei->ns.ns_ops;
146146
struct task_struct *task;
147-
void *ns;
147+
struct ns_common *ns;
148148
char name[50];
149149
int res = -EACCES;
150150

@@ -160,7 +160,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
160160
if (!ns)
161161
goto out_put_task;
162162

163-
snprintf(name, sizeof(name), "%s:[%u]", ns_ops->name, ns_ops->inum(ns));
163+
snprintf(name, sizeof(name), "%s:[%u]", ns_ops->name, ns->inum);
164164
res = readlink_copy(buffer, buflen, name);
165165
ns_ops->put(ns);
166166
out_put_task:

‎include/linux/proc_ns.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
struct pid_namespace;
88
struct nsproxy;
9+
struct ns_common;
910

1011
struct proc_ns_operations {
1112
const char *name;
1213
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);
14+
struct ns_common *(*get)(struct task_struct *task);
15+
void (*put)(struct ns_common *ns);
16+
int (*install)(struct nsproxy *nsproxy, struct ns_common *ns);
1717
};
1818

1919
struct proc_ns {
20-
void *ns;
20+
struct ns_common *ns;
2121
const struct proc_ns_operations *ns_ops;
2222
};
2323

‎ipc/namespace.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
154154
return container_of(ns, struct ipc_namespace, ns);
155155
}
156156

157-
static void *ipcns_get(struct task_struct *task)
157+
static struct ns_common *ipcns_get(struct task_struct *task)
158158
{
159159
struct ipc_namespace *ns = NULL;
160160
struct nsproxy *nsproxy;
@@ -168,12 +168,12 @@ static void *ipcns_get(struct task_struct *task)
168168
return ns ? &ns->ns : NULL;
169169
}
170170

171-
static void ipcns_put(void *ns)
171+
static void ipcns_put(struct ns_common *ns)
172172
{
173173
return put_ipc_ns(to_ipc_ns(ns));
174174
}
175175

176-
static int ipcns_install(struct nsproxy *nsproxy, void *new)
176+
static int ipcns_install(struct nsproxy *nsproxy, struct ns_common *new)
177177
{
178178
struct ipc_namespace *ns = to_ipc_ns(new);
179179
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
@@ -187,16 +187,10 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new)
187187
return 0;
188188
}
189189

190-
static unsigned int ipcns_inum(void *vp)
191-
{
192-
return ((struct ns_common *)vp)->inum;
193-
}
194-
195190
const struct proc_ns_operations ipcns_operations = {
196191
.name = "ipc",
197192
.type = CLONE_NEWIPC,
198193
.get = ipcns_get,
199194
.put = ipcns_put,
200195
.install = ipcns_install,
201-
.inum = ipcns_inum,
202196
};

‎kernel/pid_namespace.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
318318
return container_of(ns, struct pid_namespace, ns);
319319
}
320320

321-
static void *pidns_get(struct task_struct *task)
321+
static struct ns_common *pidns_get(struct task_struct *task)
322322
{
323323
struct pid_namespace *ns;
324324

@@ -331,12 +331,12 @@ static void *pidns_get(struct task_struct *task)
331331
return ns ? &ns->ns : NULL;
332332
}
333333

334-
static void pidns_put(void *ns)
334+
static void pidns_put(struct ns_common *ns)
335335
{
336336
put_pid_ns(to_pid_ns(ns));
337337
}
338338

339-
static int pidns_install(struct nsproxy *nsproxy, void *ns)
339+
static int pidns_install(struct nsproxy *nsproxy, struct ns_common *ns)
340340
{
341341
struct pid_namespace *active = task_active_pid_ns(current);
342342
struct pid_namespace *ancestor, *new = to_pid_ns(ns);
@@ -367,18 +367,12 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns)
367367
return 0;
368368
}
369369

370-
static unsigned int pidns_inum(void *ns)
371-
{
372-
return ((struct ns_common *)ns)->inum;
373-
}
374-
375370
const struct proc_ns_operations pidns_operations = {
376371
.name = "pid",
377372
.type = CLONE_NEWPID,
378373
.get = pidns_get,
379374
.put = pidns_put,
380375
.install = pidns_install,
381-
.inum = pidns_inum,
382376
};
383377

384378
static __init int pid_namespaces_init(void)

‎kernel/user_namespace.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ static inline struct user_namespace *to_user_ns(struct ns_common *ns)
846846
return container_of(ns, struct user_namespace, ns);
847847
}
848848

849-
static void *userns_get(struct task_struct *task)
849+
static struct ns_common *userns_get(struct task_struct *task)
850850
{
851851
struct user_namespace *user_ns;
852852

@@ -857,12 +857,12 @@ static void *userns_get(struct task_struct *task)
857857
return user_ns ? &user_ns->ns : NULL;
858858
}
859859

860-
static void userns_put(void *ns)
860+
static void userns_put(struct ns_common *ns)
861861
{
862862
put_user_ns(to_user_ns(ns));
863863
}
864864

865-
static int userns_install(struct nsproxy *nsproxy, void *ns)
865+
static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns)
866866
{
867867
struct user_namespace *user_ns = to_user_ns(ns);
868868
struct cred *cred;
@@ -893,18 +893,12 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
893893
return commit_creds(cred);
894894
}
895895

896-
static unsigned int userns_inum(void *ns)
897-
{
898-
return ((struct ns_common *)ns)->inum;
899-
}
900-
901896
const struct proc_ns_operations userns_operations = {
902897
.name = "user",
903898
.type = CLONE_NEWUSER,
904899
.get = userns_get,
905900
.put = userns_put,
906901
.install = userns_install,
907-
.inum = userns_inum,
908902
};
909903

910904
static __init int user_namespaces_init(void)

‎kernel/utsname.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
9393
return container_of(ns, struct uts_namespace, ns);
9494
}
9595

96-
static void *utsns_get(struct task_struct *task)
96+
static struct ns_common *utsns_get(struct task_struct *task)
9797
{
9898
struct uts_namespace *ns = NULL;
9999
struct nsproxy *nsproxy;
@@ -109,12 +109,12 @@ static void *utsns_get(struct task_struct *task)
109109
return ns ? &ns->ns : NULL;
110110
}
111111

112-
static void utsns_put(void *ns)
112+
static void utsns_put(struct ns_common *ns)
113113
{
114114
put_uts_ns(to_uts_ns(ns));
115115
}
116116

117-
static int utsns_install(struct nsproxy *nsproxy, void *new)
117+
static int utsns_install(struct nsproxy *nsproxy, struct ns_common *new)
118118
{
119119
struct uts_namespace *ns = to_uts_ns(new);
120120

@@ -128,16 +128,10 @@ static int utsns_install(struct nsproxy *nsproxy, void *new)
128128
return 0;
129129
}
130130

131-
static unsigned int utsns_inum(void *vp)
132-
{
133-
return ((struct ns_common *)vp)->inum;
134-
}
135-
136131
const struct proc_ns_operations utsns_operations = {
137132
.name = "uts",
138133
.type = CLONE_NEWUTS,
139134
.get = utsns_get,
140135
.put = utsns_put,
141136
.install = utsns_install,
142-
.inum = utsns_inum,
143137
};

‎net/core/net_namespace.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ void unregister_pernet_device(struct pernet_operations *ops)
629629
EXPORT_SYMBOL_GPL(unregister_pernet_device);
630630

631631
#ifdef CONFIG_NET_NS
632-
static void *netns_get(struct task_struct *task)
632+
static struct ns_common *netns_get(struct task_struct *task)
633633
{
634634
struct net *net = NULL;
635635
struct nsproxy *nsproxy;
@@ -648,12 +648,12 @@ static inline struct net *to_net_ns(struct ns_common *ns)
648648
return container_of(ns, struct net, ns);
649649
}
650650

651-
static void netns_put(void *ns)
651+
static void netns_put(struct ns_common *ns)
652652
{
653653
put_net(to_net_ns(ns));
654654
}
655655

656-
static int netns_install(struct nsproxy *nsproxy, void *ns)
656+
static int netns_install(struct nsproxy *nsproxy, struct ns_common *ns)
657657
{
658658
struct net *net = to_net_ns(ns);
659659

@@ -666,17 +666,11 @@ static int netns_install(struct nsproxy *nsproxy, void *ns)
666666
return 0;
667667
}
668668

669-
static unsigned int netns_inum(void *ns)
670-
{
671-
return ((struct ns_common *)ns)->inum;
672-
}
673-
674669
const struct proc_ns_operations netns_operations = {
675670
.name = "net",
676671
.type = CLONE_NEWNET,
677672
.get = netns_get,
678673
.put = netns_put,
679674
.install = netns_install,
680-
.inum = netns_inum,
681675
};
682676
#endif

0 commit comments

Comments
 (0)