]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
proc: Split the namespace stuff out into linux/proc_ns.h
authorDavid Howells <dhowells@redhat.com>
Fri, 12 Apr 2013 00:50:06 +0000 (01:50 +0100)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 1 May 2013 21:29:39 +0000 (17:29 -0400)
Split the proc namespace stuff out into linux/proc_ns.h.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: netdev@vger.kernel.org
cc: Serge E. Hallyn <serge.hallyn@ubuntu.com>
cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
15 files changed:
fs/namespace.c
fs/proc/inode.c
fs/proc/namespaces.c
include/linux/proc_fs.h
include/linux/proc_ns.h [new file with mode: 0644]
init/version.c
ipc/msgutil.c
ipc/namespace.c
kernel/nsproxy.c
kernel/pid.c
kernel/pid_namespace.c
kernel/user.c
kernel/user_namespace.c
kernel/utsname.c
net/core/net_namespace.c

index ed0708f2415f74bddf63d19680c4ec887f62f9a8..0f0cf9379c9eed3d3d636fed3df56350a435c897 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/fs_struct.h>   /* get_fs_root et.al. */
 #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
 #include <linux/uaccess.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 #include "pnode.h"
 #include "internal.h"
 
@@ -1350,13 +1350,13 @@ static bool mnt_ns_loop(struct path *path)
         * mount namespace loop?
         */
        struct inode *inode = path->dentry->d_inode;
-       struct proc_inode *ei;
+       struct proc_ns *ei;
        struct mnt_namespace *mnt_ns;
 
        if (!proc_ns_inode(inode))
                return false;
 
-       ei = PROC_I(inode);
+       ei = get_proc_ns(inode);
        if (ei->ns_ops != &mntns_operations)
                return false;
 
index bd2f76427fecbf8d28735ad625efca036cd6c395..073aea60cf8f0ed1ccce604ab0accd8b07dd96ba 100644 (file)
@@ -51,8 +51,8 @@ static void proc_evict_inode(struct inode *inode)
                sysctl_head_put(head);
        }
        /* Release any associated namespace */
-       ns_ops = PROC_I(inode)->ns_ops;
-       ns = PROC_I(inode)->ns;
+       ns_ops = PROC_I(inode)->ns.ns_ops;
+       ns = PROC_I(inode)->ns.ns;
        if (ns_ops && ns)
                ns_ops->put(ns);
 }
@@ -73,8 +73,8 @@ static struct inode *proc_alloc_inode(struct super_block *sb)
        ei->pde = NULL;
        ei->sysctl = NULL;
        ei->sysctl_entry = NULL;
-       ei->ns = NULL;
-       ei->ns_ops = NULL;
+       ei->ns.ns = NULL;
+       ei->ns.ns_ops = NULL;
        inode = &ei->vfs_inode;
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
        return inode;
index 66b51c0383da790c1219aa9716d484681f61cde8..54bdc6701e9fd785ddc14c277a48ff455683d773 100644 (file)
@@ -51,7 +51,7 @@ static int ns_delete_dentry(const struct dentry *dentry)
 static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
 {
        struct inode *inode = dentry->d_inode;
-       const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
+       const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns.ns_ops;
 
        return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]",
                ns_ops->name, inode->i_ino);
@@ -95,8 +95,8 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
                inode->i_op = &ns_inode_operations;
                inode->i_mode = S_IFREG | S_IRUGO;
                inode->i_fop = &ns_file_operations;
-               ei->ns_ops = ns_ops;
-               ei->ns = ns;
+               ei->ns.ns_ops = ns_ops;
+               ei->ns.ns = ns;
                unlock_new_inode(inode);
        } else {
                ns_ops->put(ns);
@@ -128,7 +128,7 @@ static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd)
        if (!ptrace_may_access(task, PTRACE_MODE_READ))
                goto out_put_task;
 
-       ns_path.dentry = proc_ns_get_dentry(sb, task, ei->ns_ops);
+       ns_path.dentry = proc_ns_get_dentry(sb, task, ei->ns.ns_ops);
        if (IS_ERR(ns_path.dentry)) {
                error = ERR_CAST(ns_path.dentry);
                goto out_put_task;
@@ -148,7 +148,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
 {
        struct inode *inode = dentry->d_inode;
        struct proc_inode *ei = PROC_I(inode);
-       const struct proc_ns_operations *ns_ops = ei->ns_ops;
+       const struct proc_ns_operations *ns_ops = ei->ns.ns_ops;
        struct task_struct *task;
        void *ns;
        char name[50];
@@ -202,7 +202,7 @@ static struct dentry *proc_ns_instantiate(struct inode *dir,
        ei = PROC_I(inode);
        inode->i_mode = S_IFLNK|S_IRWXUGO;
        inode->i_op = &proc_ns_link_inode_operations;
-       ei->ns_ops = ns_ops;
+       ei->ns.ns_ops = ns_ops;
 
        d_set_d_op(dentry, &pid_dentry_operations);
        d_add(dentry, inode);
@@ -337,6 +337,11 @@ out_invalid:
        return ERR_PTR(-EINVAL);
 }
 
+struct proc_ns *get_proc_ns(struct inode *inode)
+{
+       return &PROC_I(inode)->ns;
+}
+
 bool proc_ns_inode(struct inode *inode)
 {
        return inode->i_fop == &ns_file_operations;
index 28a4d7e78803b602671b8624ffb914070de95593..8f7d8f24141abc1a56c3ad23a6f77b9765266cb8 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/spinlock.h>
 #include <linux/magic.h>
 #include <linux/atomic.h>
+#include <linux/proc_ns.h>
 
 struct net;
 struct completion;
@@ -23,18 +24,6 @@ struct mm_struct;
 /* Worst case buffer size needed for holding an integer. */
 #define PROC_NUMBUF 13
 
-/*
- * We always define these enumerators
- */
-
-enum {
-       PROC_ROOT_INO           = 1,
-       PROC_IPC_INIT_INO       = 0xEFFFFFFFU,
-       PROC_UTS_INIT_INO       = 0xEFFFFFFEU,
-       PROC_USER_INIT_INO      = 0xEFFFFFFDU,
-       PROC_PID_INIT_INO       = 0xEFFFFFFCU,
-};
-
 /*
  * This is not completely implemented yet. The idea is to
  * 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,
 extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
 extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
 
-struct pid_namespace;
-
-extern int pid_ns_prepare_proc(struct pid_namespace *ns);
-extern void pid_ns_release_proc(struct pid_namespace *ns);
 
 /*
  * proc_tty.c
@@ -132,12 +117,6 @@ extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
 
 extern void proc_set_size(struct proc_dir_entry *, loff_t);
 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
-
-extern struct file *proc_ns_fget(int fd);
-extern bool proc_ns_inode(struct inode *inode);
-
-extern int proc_alloc_inum(unsigned int *pino);
-extern void proc_free_inum(unsigned int inum);
 #else
 
 static inline void proc_flush_task(struct task_struct *task)
@@ -168,50 +147,8 @@ struct tty_driver;
 static inline void proc_tty_register_driver(struct tty_driver *driver) {};
 static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
 
-static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
-{
-       return 0;
-}
-
-static inline void pid_ns_release_proc(struct pid_namespace *ns)
-{
-}
-
-static inline struct file *proc_ns_fget(int fd)
-{
-       return ERR_PTR(-EINVAL);
-}
-
-static inline bool proc_ns_inode(struct inode *inode)
-{
-       return false;
-}
-
-static inline int proc_alloc_inum(unsigned int *inum)
-{
-       *inum = 1;
-       return 0;
-}
-static inline void proc_free_inum(unsigned int inum)
-{
-}
 #endif /* CONFIG_PROC_FS */
 
-struct nsproxy;
-struct proc_ns_operations {
-       const char *name;
-       int type;
-       void *(*get)(struct task_struct *task);
-       void (*put)(void *ns);
-       int (*install)(struct nsproxy *nsproxy, void *ns);
-       unsigned int (*inum)(void *ns);
-};
-extern const struct proc_ns_operations netns_operations;
-extern const struct proc_ns_operations utsns_operations;
-extern const struct proc_ns_operations ipcns_operations;
-extern const struct proc_ns_operations pidns_operations;
-extern const struct proc_ns_operations userns_operations;
-extern const struct proc_ns_operations mntns_operations;
 
 union proc_op {
        int (*proc_get_link)(struct dentry *, struct path *);
@@ -231,8 +168,7 @@ struct proc_inode {
        struct proc_dir_entry *pde;
        struct ctl_table_header *sysctl;
        struct ctl_table *sysctl_entry;
-       void *ns;
-       const struct proc_ns_operations *ns_ops;
+       struct proc_ns ns;
        struct inode vfs_inode;
 };
 
diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
new file mode 100644 (file)
index 0000000..34a1e10
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * procfs namespace bits
+ */
+#ifndef _LINUX_PROC_NS_H
+#define _LINUX_PROC_NS_H
+
+struct pid_namespace;
+struct nsproxy;
+
+struct proc_ns_operations {
+       const char *name;
+       int type;
+       void *(*get)(struct task_struct *task);
+       void (*put)(void *ns);
+       int (*install)(struct nsproxy *nsproxy, void *ns);
+       unsigned int (*inum)(void *ns);
+};
+
+struct proc_ns {
+       void *ns;
+       const struct proc_ns_operations *ns_ops;
+};
+
+extern const struct proc_ns_operations netns_operations;
+extern const struct proc_ns_operations utsns_operations;
+extern const struct proc_ns_operations ipcns_operations;
+extern const struct proc_ns_operations pidns_operations;
+extern const struct proc_ns_operations userns_operations;
+extern const struct proc_ns_operations mntns_operations;
+
+/*
+ * We always define these enumerators
+ */
+enum {
+       PROC_ROOT_INO           = 1,
+       PROC_IPC_INIT_INO       = 0xEFFFFFFFU,
+       PROC_UTS_INIT_INO       = 0xEFFFFFFEU,
+       PROC_USER_INIT_INO      = 0xEFFFFFFDU,
+       PROC_PID_INIT_INO       = 0xEFFFFFFCU,
+};
+
+#ifdef CONFIG_PROC_FS
+
+extern int pid_ns_prepare_proc(struct pid_namespace *ns);
+extern void pid_ns_release_proc(struct pid_namespace *ns);
+extern struct file *proc_ns_fget(int fd);
+extern struct proc_ns *get_proc_ns(struct inode *);
+extern int proc_alloc_inum(unsigned int *pino);
+extern void proc_free_inum(unsigned int inum);
+extern bool proc_ns_inode(struct inode *inode);
+
+#else /* CONFIG_PROC_FS */
+
+static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; }
+static inline void pid_ns_release_proc(struct pid_namespace *ns) {}
+
+static inline struct file *proc_ns_fget(int fd)
+{
+       return ERR_PTR(-EINVAL);
+}
+
+static inline struct proc_ns *get_proc_ns(struct inode *inode) { return NULL; }
+
+static inline int proc_alloc_inum(unsigned int *inum)
+{
+       *inum = 1;
+       return 0;
+}
+static inline void proc_free_inum(unsigned int inum) {}
+static inline bool proc_ns_inode(struct inode *inode) { return false; }
+
+#endif /* CONFIG_PROC_FS */
+
+#endif /* _LINUX_PROC_NS_H */
index 58170f18912d885e9fcd76b2892c4866beda577d..1a4718e500fe78238de84cc872eb559706dfbb5e 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/utsname.h>
 #include <generated/utsrelease.h>
 #include <linux/version.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 
 #ifndef CONFIG_KALLSYMS
 #define version(a) Version_ ## a
index 5df8e4bf1db00debfedc37a3487cfddc612126ad..8f0201735f16c6ceaf6b8eda9b4840c76b5e18bd 100644 (file)
@@ -16,7 +16,7 @@
 #include <linux/msg.h>
 #include <linux/ipc_namespace.h>
 #include <linux/utsname.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 #include <asm/uaccess.h>
 
 #include "util.h"
index 7c1fa451b0b0d75ae5265fea8fbe1193cb865223..7ee61bf449332bbb556f4742e72c8f54c8111d89 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/fs.h>
 #include <linux/mount.h>
 #include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 
 #include "util.h"
 
index afc0456f227abe76788ac666f7c1239759b5096e..364ceab15f0cc09816fdd1b36b78814b06227991 100644 (file)
@@ -22,7 +22,7 @@
 #include <linux/pid_namespace.h>
 #include <net/net_namespace.h>
 #include <linux/ipc_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 #include <linux/file.h>
 #include <linux/syscalls.h>
 
@@ -241,7 +241,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
        const struct proc_ns_operations *ops;
        struct task_struct *tsk = current;
        struct nsproxy *new_nsproxy;
-       struct proc_inode *ei;
+       struct proc_ns *ei;
        struct file *file;
        int err;
 
@@ -250,7 +250,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
                return PTR_ERR(file);
 
        err = -EINVAL;
-       ei = PROC_I(file_inode(file));
+       ei = get_proc_ns(file_inode(file));
        ops = ei->ns_ops;
        if (nstype && (ops->type != nstype))
                goto out;
index 047dc62646389fd5abdf5fc63cb8db963a1a5b60..686255e2c39e4874a13d78051afc8f54c7d4ae63 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/init_task.h>
 #include <linux/syscalls.h>
+#include <linux/proc_ns.h>
 #include <linux/proc_fs.h>
 
 #define pid_hashfn(nr, ns)     \
index c1c3dc1c60233f337a01ff13587f1a5a7f57f1cd..4af28a84906545765c1429461e166c4d362e765c 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/err.h>
 #include <linux/acct.h>
 #include <linux/slab.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 #include <linux/reboot.h>
 #include <linux/export.h>
 
index e81978e8c03b2b5f1a38d62248d8408fbfcd2d13..5bbb91988e69278f2cd012896db29688c9234476 100644 (file)
@@ -16,7 +16,7 @@
 #include <linux/interrupt.h>
 #include <linux/export.h>
 #include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 
 /*
  * userns count is 1 for root user, 1 for init_uts_ns,
index b14f4d3420439ca629be08494ef417e734513499..51855f5f6311211c785373d52e990f879ec959fe 100644 (file)
@@ -9,7 +9,7 @@
 #include <linux/nsproxy.h>
 #include <linux/slab.h>
 #include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 #include <linux/highuid.h>
 #include <linux/cred.h>
 #include <linux/securebits.h>
index a47fc5de31136a7832df8754f0342b8937ad5268..2fc8576efaa8e7a5201d9334f6fb8452cc14226a 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 
 static struct uts_namespace *create_uts_ns(void)
 {
index 80e271d9e64b36425d14eed4fdebed570f7a98f5..f976520367542a5fdfc9e609e16a5a696dd767ad 100644 (file)
@@ -10,7 +10,8 @@
 #include <linux/idr.h>
 #include <linux/rculist.h>
 #include <linux/nsproxy.h>
-#include <linux/proc_fs.h>
+#include <linux/fs.h>
+#include <linux/proc_ns.h>
 #include <linux/file.h>
 #include <linux/export.h>
 #include <linux/user_namespace.h>
@@ -336,7 +337,7 @@ EXPORT_SYMBOL_GPL(__put_net);
 
 struct net *get_net_ns_by_fd(int fd)
 {
-       struct proc_inode *ei;
+       struct proc_ns *ei;
        struct file *file;
        struct net *net;
 
@@ -344,7 +345,7 @@ struct net *get_net_ns_by_fd(int fd)
        if (IS_ERR(file))
                return ERR_CAST(file);
 
-       ei = PROC_I(file_inode(file));
+       ei = get_proc_ns(file_inode(file));
        if (ei->ns_ops == &netns_operations)
                net = get_net(ei->ns);
        else