Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1651e14e authored by Serge E. Hallyn's avatar Serge E. Hallyn Committed by Linus Torvalds
Browse files

[PATCH] namespaces: incorporate fs namespace into nsproxy



This moves the mount namespace into the nsproxy.  The mount namespace count
now refers to the number of nsproxies point to it, rather than the number of
tasks.  As a result, the unshare_namespace() function in kernel/fork.c no
longer checks whether it is being shared.

Signed-off-by: default avatarSerge Hallyn <serue@us.ibm.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Andrey Savochkin <saw@sw.ru>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0437eb59
Loading
Loading
Loading
Loading
+8 −14
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)

static inline int check_mnt(struct vfsmount *mnt)
{
	return mnt->mnt_namespace == current->namespace;
	return mnt->mnt_namespace == current->nsproxy->namespace;
}

static void touch_namespace(struct namespace *ns)
@@ -830,7 +830,7 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
	if (parent_nd) {
		detach_mnt(source_mnt, parent_nd);
		attach_mnt(source_mnt, nd);
		touch_namespace(current->namespace);
		touch_namespace(current->nsproxy->namespace);
	} else {
		mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
		commit_tree(source_mnt);
@@ -1441,7 +1441,7 @@ dput_out:
 */
struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
{
	struct namespace *namespace = tsk->namespace;
	struct namespace *namespace = tsk->nsproxy->namespace;
	struct namespace *new_ns;
	struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
	struct vfsmount *p, *q;
@@ -1508,7 +1508,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)

int copy_namespace(int flags, struct task_struct *tsk)
{
	struct namespace *namespace = tsk->namespace;
	struct namespace *namespace = tsk->nsproxy->namespace;
	struct namespace *new_ns;
	int err = 0;

@@ -1531,7 +1531,7 @@ int copy_namespace(int flags, struct task_struct *tsk)
		goto out;
	}

	tsk->namespace = new_ns;
	tsk->nsproxy->namespace = new_ns;

out:
	put_namespace(namespace);
@@ -1754,7 +1754,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
	detach_mnt(user_nd.mnt, &root_parent);
	attach_mnt(user_nd.mnt, &old_nd);     /* mount old root on put_old */
	attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
	touch_namespace(current->namespace);
	touch_namespace(current->nsproxy->namespace);
	spin_unlock(&vfsmount_lock);
	chroot_fs_refs(&user_nd, &new_nd);
	security_sb_post_pivotroot(&user_nd, &new_nd);
@@ -1780,7 +1780,6 @@ static void __init init_mount_tree(void)
{
	struct vfsmount *mnt;
	struct namespace *namespace;
	struct task_struct *g, *p;

	mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
	if (IS_ERR(mnt))
@@ -1796,13 +1795,8 @@ static void __init init_mount_tree(void)
	namespace->root = mnt;
	mnt->mnt_namespace = namespace;

	init_task.namespace = namespace;
	read_lock(&tasklist_lock);
	do_each_thread(g, p) {
	init_task.nsproxy->namespace = namespace;
	get_namespace(namespace);
		p->namespace = namespace;
	} while_each_thread(g, p);
	read_unlock(&tasklist_lock);

	set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root);
	set_fs_root(current->fs, namespace->root, namespace->root->mnt_root);
+3 −2
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@
#include <linux/cpuset.h>
#include <linux/audit.h>
#include <linux/poll.h>
#include <linux/nsproxy.h>
#include "internal.h"

/* NOTE:
@@ -473,7 +474,7 @@ static int mounts_open(struct inode *inode, struct file *file)

	if (task) {
		task_lock(task);
		namespace = task->namespace;
		namespace = task->nsproxy->namespace;
		if (namespace)
			get_namespace(namespace);
		task_unlock(task);
@@ -544,7 +545,7 @@ static int mountstats_open(struct inode *inode, struct file *file)

		if (task) {
			task_lock(task);
			namespace = task->namespace;
			namespace = task->nsproxy->namespace;
			if (namespace)
				get_namespace(namespace);
			task_unlock(task);
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ extern struct nsproxy init_nsproxy;
#define INIT_NSPROXY(nsproxy) {						\
	.count		= ATOMIC_INIT(1),				\
	.nslock		= SPIN_LOCK_UNLOCKED,				\
	.namespace	= NULL,						\
}

#define INIT_SIGHAND(sighand) {						\
+2 −4
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

#include <linux/mount.h>
#include <linux/sched.h>
#include <linux/nsproxy.h>

struct namespace {
	atomic_t		count;
@@ -26,11 +27,8 @@ static inline void put_namespace(struct namespace *namespace)

static inline void exit_namespace(struct task_struct *p)
{
	struct namespace *namespace = p->namespace;
	struct namespace *namespace = p->nsproxy->namespace;
	if (namespace) {
		task_lock(p);
		p->namespace = NULL;
		task_unlock(p);
		put_namespace(namespace);
	}
}
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
#include <linux/spinlock.h>
#include <linux/sched.h>

struct namespace;

/*
 * A structure to contain pointers to all per-process
 * namespaces - fs (mount), uts, network, sysvipc, etc.
@@ -19,6 +21,7 @@
struct nsproxy {
	atomic_t count;
	spinlock_t nslock;
	struct namespace *namespace;
};
extern struct nsproxy init_nsproxy;

Loading