Commit 64964528 authored by Al Viro's avatar Al Viro

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: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 3c041184
...@@ -3149,7 +3149,7 @@ bool fs_fully_visible(struct file_system_type *type) ...@@ -3149,7 +3149,7 @@ bool fs_fully_visible(struct file_system_type *type)
return visible; return visible;
} }
static void *mntns_get(struct task_struct *task) static struct ns_common *mntns_get(struct task_struct *task)
{ {
struct ns_common *ns = NULL; struct ns_common *ns = NULL;
struct nsproxy *nsproxy; struct nsproxy *nsproxy;
...@@ -3165,12 +3165,12 @@ static void *mntns_get(struct task_struct *task) ...@@ -3165,12 +3165,12 @@ static void *mntns_get(struct task_struct *task)
return ns; return ns;
} }
static void mntns_put(void *ns) static void mntns_put(struct ns_common *ns)
{ {
put_mnt_ns(to_mnt_ns(ns)); put_mnt_ns(to_mnt_ns(ns));
} }
static int mntns_install(struct nsproxy *nsproxy, void *ns) static int mntns_install(struct nsproxy *nsproxy, struct ns_common *ns)
{ {
struct fs_struct *fs = current->fs; struct fs_struct *fs = current->fs;
struct mnt_namespace *mnt_ns = to_mnt_ns(ns); struct mnt_namespace *mnt_ns = to_mnt_ns(ns);
...@@ -3203,17 +3203,10 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns) ...@@ -3203,17 +3203,10 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
return 0; return 0;
} }
static unsigned int mntns_inum(void *ns)
{
struct ns_common *p = ns;
return p->inum;
}
const struct proc_ns_operations mntns_operations = { const struct proc_ns_operations mntns_operations = {
.name = "mnt", .name = "mnt",
.type = CLONE_NEWNS, .type = CLONE_NEWNS,
.get = mntns_get, .get = mntns_get,
.put = mntns_put, .put = mntns_put,
.install = mntns_install, .install = mntns_install,
.inum = mntns_inum,
}; };
...@@ -33,7 +33,7 @@ static void proc_evict_inode(struct inode *inode) ...@@ -33,7 +33,7 @@ static void proc_evict_inode(struct inode *inode)
struct proc_dir_entry *de; struct proc_dir_entry *de;
struct ctl_table_header *head; struct ctl_table_header *head;
const struct proc_ns_operations *ns_ops; const struct proc_ns_operations *ns_ops;
void *ns; struct ns_common *ns;
truncate_inode_pages_final(&inode->i_data); truncate_inode_pages_final(&inode->i_data);
clear_inode(inode); clear_inode(inode);
......
...@@ -64,7 +64,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb, ...@@ -64,7 +64,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
struct inode *inode; struct inode *inode;
struct proc_inode *ei; struct proc_inode *ei;
struct qstr qname = { .name = "", }; struct qstr qname = { .name = "", };
void *ns; struct ns_common *ns;
ns = ns_ops->get(task); ns = ns_ops->get(task);
if (!ns) if (!ns)
...@@ -76,7 +76,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb, ...@@ -76,7 +76,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
inode = iget_locked(sb, ns_ops->inum(ns)); inode = iget_locked(sb, ns->inum);
if (!inode) { if (!inode) {
dput(dentry); dput(dentry);
ns_ops->put(ns); ns_ops->put(ns);
...@@ -144,7 +144,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl ...@@ -144,7 +144,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
struct proc_inode *ei = PROC_I(inode); struct proc_inode *ei = PROC_I(inode);
const struct proc_ns_operations *ns_ops = ei->ns.ns_ops; const struct proc_ns_operations *ns_ops = ei->ns.ns_ops;
struct task_struct *task; struct task_struct *task;
void *ns; struct ns_common *ns;
char name[50]; char name[50];
int res = -EACCES; int res = -EACCES;
...@@ -160,7 +160,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl ...@@ -160,7 +160,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
if (!ns) if (!ns)
goto out_put_task; goto out_put_task;
snprintf(name, sizeof(name), "%s:[%u]", ns_ops->name, ns_ops->inum(ns)); snprintf(name, sizeof(name), "%s:[%u]", ns_ops->name, ns->inum);
res = readlink_copy(buffer, buflen, name); res = readlink_copy(buffer, buflen, name);
ns_ops->put(ns); ns_ops->put(ns);
out_put_task: out_put_task:
......
...@@ -6,18 +6,18 @@ ...@@ -6,18 +6,18 @@
struct pid_namespace; struct pid_namespace;
struct nsproxy; struct nsproxy;
struct ns_common;
struct proc_ns_operations { struct proc_ns_operations {
const char *name; const char *name;
int type; int type;
void *(*get)(struct task_struct *task); struct ns_common *(*get)(struct task_struct *task);
void (*put)(void *ns); void (*put)(struct ns_common *ns);
int (*install)(struct nsproxy *nsproxy, void *ns); int (*install)(struct nsproxy *nsproxy, struct ns_common *ns);
unsigned int (*inum)(void *ns);
}; };
struct proc_ns { struct proc_ns {
void *ns; struct ns_common *ns;
const struct proc_ns_operations *ns_ops; const struct proc_ns_operations *ns_ops;
}; };
......
...@@ -154,7 +154,7 @@ static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns) ...@@ -154,7 +154,7 @@ static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
return container_of(ns, struct ipc_namespace, ns); return container_of(ns, struct ipc_namespace, ns);
} }
static void *ipcns_get(struct task_struct *task) static struct ns_common *ipcns_get(struct task_struct *task)
{ {
struct ipc_namespace *ns = NULL; struct ipc_namespace *ns = NULL;
struct nsproxy *nsproxy; struct nsproxy *nsproxy;
...@@ -168,12 +168,12 @@ static void *ipcns_get(struct task_struct *task) ...@@ -168,12 +168,12 @@ static void *ipcns_get(struct task_struct *task)
return ns ? &ns->ns : NULL; return ns ? &ns->ns : NULL;
} }
static void ipcns_put(void *ns) static void ipcns_put(struct ns_common *ns)
{ {
return put_ipc_ns(to_ipc_ns(ns)); return put_ipc_ns(to_ipc_ns(ns));
} }
static int ipcns_install(struct nsproxy *nsproxy, void *new) static int ipcns_install(struct nsproxy *nsproxy, struct ns_common *new)
{ {
struct ipc_namespace *ns = to_ipc_ns(new); struct ipc_namespace *ns = to_ipc_ns(new);
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
...@@ -187,16 +187,10 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new) ...@@ -187,16 +187,10 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new)
return 0; return 0;
} }
static unsigned int ipcns_inum(void *vp)
{
return ((struct ns_common *)vp)->inum;
}
const struct proc_ns_operations ipcns_operations = { const struct proc_ns_operations ipcns_operations = {
.name = "ipc", .name = "ipc",
.type = CLONE_NEWIPC, .type = CLONE_NEWIPC,
.get = ipcns_get, .get = ipcns_get,
.put = ipcns_put, .put = ipcns_put,
.install = ipcns_install, .install = ipcns_install,
.inum = ipcns_inum,
}; };
...@@ -318,7 +318,7 @@ static inline struct pid_namespace *to_pid_ns(struct ns_common *ns) ...@@ -318,7 +318,7 @@ static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
return container_of(ns, struct pid_namespace, ns); return container_of(ns, struct pid_namespace, ns);
} }
static void *pidns_get(struct task_struct *task) static struct ns_common *pidns_get(struct task_struct *task)
{ {
struct pid_namespace *ns; struct pid_namespace *ns;
...@@ -331,12 +331,12 @@ static void *pidns_get(struct task_struct *task) ...@@ -331,12 +331,12 @@ static void *pidns_get(struct task_struct *task)
return ns ? &ns->ns : NULL; return ns ? &ns->ns : NULL;
} }
static void pidns_put(void *ns) static void pidns_put(struct ns_common *ns)
{ {
put_pid_ns(to_pid_ns(ns)); put_pid_ns(to_pid_ns(ns));
} }
static int pidns_install(struct nsproxy *nsproxy, void *ns) static int pidns_install(struct nsproxy *nsproxy, struct ns_common *ns)
{ {
struct pid_namespace *active = task_active_pid_ns(current); struct pid_namespace *active = task_active_pid_ns(current);
struct pid_namespace *ancestor, *new = to_pid_ns(ns); struct pid_namespace *ancestor, *new = to_pid_ns(ns);
...@@ -367,18 +367,12 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns) ...@@ -367,18 +367,12 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns)
return 0; return 0;
} }
static unsigned int pidns_inum(void *ns)
{
return ((struct ns_common *)ns)->inum;
}
const struct proc_ns_operations pidns_operations = { const struct proc_ns_operations pidns_operations = {
.name = "pid", .name = "pid",
.type = CLONE_NEWPID, .type = CLONE_NEWPID,
.get = pidns_get, .get = pidns_get,
.put = pidns_put, .put = pidns_put,
.install = pidns_install, .install = pidns_install,
.inum = pidns_inum,
}; };
static __init int pid_namespaces_init(void) static __init int pid_namespaces_init(void)
......
...@@ -846,7 +846,7 @@ static inline struct user_namespace *to_user_ns(struct ns_common *ns) ...@@ -846,7 +846,7 @@ static inline struct user_namespace *to_user_ns(struct ns_common *ns)
return container_of(ns, struct user_namespace, ns); return container_of(ns, struct user_namespace, ns);
} }
static void *userns_get(struct task_struct *task) static struct ns_common *userns_get(struct task_struct *task)
{ {
struct user_namespace *user_ns; struct user_namespace *user_ns;
...@@ -857,12 +857,12 @@ static void *userns_get(struct task_struct *task) ...@@ -857,12 +857,12 @@ static void *userns_get(struct task_struct *task)
return user_ns ? &user_ns->ns : NULL; return user_ns ? &user_ns->ns : NULL;
} }
static void userns_put(void *ns) static void userns_put(struct ns_common *ns)
{ {
put_user_ns(to_user_ns(ns)); put_user_ns(to_user_ns(ns));
} }
static int userns_install(struct nsproxy *nsproxy, void *ns) static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns)
{ {
struct user_namespace *user_ns = to_user_ns(ns); struct user_namespace *user_ns = to_user_ns(ns);
struct cred *cred; struct cred *cred;
...@@ -893,18 +893,12 @@ static int userns_install(struct nsproxy *nsproxy, void *ns) ...@@ -893,18 +893,12 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
return commit_creds(cred); return commit_creds(cred);
} }
static unsigned int userns_inum(void *ns)
{
return ((struct ns_common *)ns)->inum;
}
const struct proc_ns_operations userns_operations = { const struct proc_ns_operations userns_operations = {
.name = "user", .name = "user",
.type = CLONE_NEWUSER, .type = CLONE_NEWUSER,
.get = userns_get, .get = userns_get,
.put = userns_put, .put = userns_put,
.install = userns_install, .install = userns_install,
.inum = userns_inum,
}; };
static __init int user_namespaces_init(void) static __init int user_namespaces_init(void)
......
...@@ -93,7 +93,7 @@ static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) ...@@ -93,7 +93,7 @@ static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
return container_of(ns, struct uts_namespace, ns); return container_of(ns, struct uts_namespace, ns);
} }
static void *utsns_get(struct task_struct *task) static struct ns_common *utsns_get(struct task_struct *task)
{ {
struct uts_namespace *ns = NULL; struct uts_namespace *ns = NULL;
struct nsproxy *nsproxy; struct nsproxy *nsproxy;
...@@ -109,12 +109,12 @@ static void *utsns_get(struct task_struct *task) ...@@ -109,12 +109,12 @@ static void *utsns_get(struct task_struct *task)
return ns ? &ns->ns : NULL; return ns ? &ns->ns : NULL;
} }
static void utsns_put(void *ns) static void utsns_put(struct ns_common *ns)
{ {
put_uts_ns(to_uts_ns(ns)); put_uts_ns(to_uts_ns(ns));
} }
static int utsns_install(struct nsproxy *nsproxy, void *new) static int utsns_install(struct nsproxy *nsproxy, struct ns_common *new)
{ {
struct uts_namespace *ns = to_uts_ns(new); struct uts_namespace *ns = to_uts_ns(new);
...@@ -128,16 +128,10 @@ static int utsns_install(struct nsproxy *nsproxy, void *new) ...@@ -128,16 +128,10 @@ static int utsns_install(struct nsproxy *nsproxy, void *new)
return 0; return 0;
} }
static unsigned int utsns_inum(void *vp)
{
return ((struct ns_common *)vp)->inum;
}
const struct proc_ns_operations utsns_operations = { const struct proc_ns_operations utsns_operations = {
.name = "uts", .name = "uts",
.type = CLONE_NEWUTS, .type = CLONE_NEWUTS,
.get = utsns_get, .get = utsns_get,
.put = utsns_put, .put = utsns_put,
.install = utsns_install, .install = utsns_install,
.inum = utsns_inum,
}; };
...@@ -629,7 +629,7 @@ void unregister_pernet_device(struct pernet_operations *ops) ...@@ -629,7 +629,7 @@ void unregister_pernet_device(struct pernet_operations *ops)
EXPORT_SYMBOL_GPL(unregister_pernet_device); EXPORT_SYMBOL_GPL(unregister_pernet_device);
#ifdef CONFIG_NET_NS #ifdef CONFIG_NET_NS
static void *netns_get(struct task_struct *task) static struct ns_common *netns_get(struct task_struct *task)
{ {
struct net *net = NULL; struct net *net = NULL;
struct nsproxy *nsproxy; struct nsproxy *nsproxy;
...@@ -648,12 +648,12 @@ static inline struct net *to_net_ns(struct ns_common *ns) ...@@ -648,12 +648,12 @@ static inline struct net *to_net_ns(struct ns_common *ns)
return container_of(ns, struct net, ns); return container_of(ns, struct net, ns);
} }
static void netns_put(void *ns) static void netns_put(struct ns_common *ns)
{ {
put_net(to_net_ns(ns)); put_net(to_net_ns(ns));
} }
static int netns_install(struct nsproxy *nsproxy, void *ns) static int netns_install(struct nsproxy *nsproxy, struct ns_common *ns)
{ {
struct net *net = to_net_ns(ns); struct net *net = to_net_ns(ns);
...@@ -666,17 +666,11 @@ static int netns_install(struct nsproxy *nsproxy, void *ns) ...@@ -666,17 +666,11 @@ static int netns_install(struct nsproxy *nsproxy, void *ns)
return 0; return 0;
} }
static unsigned int netns_inum(void *ns)
{
return ((struct ns_common *)ns)->inum;
}
const struct proc_ns_operations netns_operations = { const struct proc_ns_operations netns_operations = {
.name = "net", .name = "net",
.type = CLONE_NEWNET, .type = CLONE_NEWNET,
.get = netns_get, .get = netns_get,
.put = netns_put, .put = netns_put,
.install = netns_install, .install = netns_install,
.inum = netns_inum,
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment