Skip to content

Commit

Permalink
proc: Split the namespace stuff out into linux/proc_ns.h
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dhowells authored and Al Viro committed May 1, 2013
1 parent c3bef7b commit 0bb80f2
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 92 deletions.
6 changes: 3 additions & 3 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions fs/proc/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions fs/proc/namespaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -337,6 +337,11 @@ struct file *proc_ns_fget(int fd)
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;
Expand Down
68 changes: 2 additions & 66 deletions include/linux/proc_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 *);
Expand All @@ -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;
};

Expand Down
74 changes: 74 additions & 0 deletions include/linux/proc_ns.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 1 addition & 1 deletion init/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ipc/msgutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ipc/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions kernel/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion kernel/pid_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion kernel/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion kernel/user_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion kernel/utsname.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit 0bb80f2

Please sign in to comment.