Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 84604
b: refs/heads/master
c: ae5e1b2
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Emelyanov authored and Linus Torvalds committed Feb 8, 2008
1 parent 0053797 commit 58f8ad6
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 113 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 58bfdd6deeec02b73691ea2c951a3c5d743bca63
refs/heads/master: ae5e1b22f17983da929a0d0178896269e19da186
52 changes: 0 additions & 52 deletions trunk/include/linux/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,58 +100,6 @@ struct kern_ipc_perm
void *security;
};

struct ipc_ids;
struct ipc_namespace {
struct kref kref;
struct ipc_ids *ids[3];

int sem_ctls[4];
int used_sems;

int msg_ctlmax;
int msg_ctlmnb;
int msg_ctlmni;
atomic_t msg_bytes;
atomic_t msg_hdrs;

size_t shm_ctlmax;
size_t shm_ctlall;
int shm_ctlmni;
int shm_tot;
};

extern struct ipc_namespace init_ipc_ns;

#ifdef CONFIG_SYSVIPC
#define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
extern void free_ipc_ns(struct kref *kref);
extern struct ipc_namespace *copy_ipcs(unsigned long flags,
struct ipc_namespace *ns);
#else
#define INIT_IPC_NS(ns)
static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
struct ipc_namespace *ns)
{
return ns;
}
#endif

static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
{
#ifdef CONFIG_SYSVIPC
if (ns)
kref_get(&ns->kref);
#endif
return ns;
}

static inline void put_ipc_ns(struct ipc_namespace *ns)
{
#ifdef CONFIG_SYSVIPC
kref_put(&ns->kref, free_ipc_ns);
#endif
}

#endif /* __KERNEL__ */

#endif /* _LINUX_IPC_H */
69 changes: 69 additions & 0 deletions trunk/include/linux/ipc_namespace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef __IPC_NAMESPACE_H__
#define __IPC_NAMESPACE_H__

#include <linux/err.h>

struct ipc_ids;
struct ipc_namespace {
struct kref kref;
struct ipc_ids *ids[3];

int sem_ctls[4];
int used_sems;

int msg_ctlmax;
int msg_ctlmnb;
int msg_ctlmni;
atomic_t msg_bytes;
atomic_t msg_hdrs;

size_t shm_ctlmax;
size_t shm_ctlall;
int shm_ctlmni;
int shm_tot;
};

extern struct ipc_namespace init_ipc_ns;

#ifdef CONFIG_SYSVIPC
#define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
#else
#define INIT_IPC_NS(ns)
#endif

#if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
extern void free_ipc_ns(struct kref *kref);
extern struct ipc_namespace *copy_ipcs(unsigned long flags,
struct ipc_namespace *ns);

static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
{
if (ns)
kref_get(&ns->kref);
return ns;
}

static inline void put_ipc_ns(struct ipc_namespace *ns)
{
kref_put(&ns->kref, free_ipc_ns);
}
#else
static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
struct ipc_namespace *ns)
{
if (flags & CLONE_NEWIPC)
return ERR_PTR(-EINVAL);

return ns;
}

static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
{
return ns;
}

static inline void put_ipc_ns(struct ipc_namespace *ns)
{
}
#endif
#endif
7 changes: 7 additions & 0 deletions trunk/init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ config UTS_NS
In this namespace tasks see different info provided with the
uname() system call

config IPC_NS
bool "IPC namespace"
depends on NAMESPACES && SYSVIPC
help
In this namespace tasks work with IPC ids which correspond to
different IPC objects in different namespaces

config BLK_DEV_INITRD
bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
depends on BROKEN || !FRV
Expand Down
1 change: 1 addition & 0 deletions trunk/ipc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o
obj-$(CONFIG_SYSVIPC_SYSCTL) += ipc_sysctl.o
obj_mq-$(CONFIG_COMPAT) += compat_mq.o
obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y)
obj-$(CONFIG_IPC_NS) += namespace.o

1 change: 1 addition & 0 deletions trunk/ipc/ipc_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/nsproxy.h>
#include <linux/sysctl.h>
#include <linux/uaccess.h>
#include <linux/ipc_namespace.h>

static void *get_ipc(ctl_table *table)
{
Expand Down
3 changes: 3 additions & 0 deletions trunk/ipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/seq_file.h>
#include <linux/rwsem.h>
#include <linux/nsproxy.h>
#include <linux/ipc_namespace.h>

#include <asm/current.h>
#include <asm/uaccess.h>
Expand Down Expand Up @@ -90,6 +91,7 @@ static void __msg_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
ipc_init_ids(ids);
}

#ifdef CONFIG_IPC_NS
int msg_init_ns(struct ipc_namespace *ns)
{
struct ipc_ids *ids;
Expand Down Expand Up @@ -128,6 +130,7 @@ void msg_exit_ns(struct ipc_namespace *ns)
kfree(ns->ids[IPC_MSG_IDS]);
ns->ids[IPC_MSG_IDS] = NULL;
}
#endif

void __init msg_init(void)
{
Expand Down
73 changes: 73 additions & 0 deletions trunk/ipc/namespace.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* linux/ipc/namespace.c
* Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
*/

#include <linux/ipc.h>
#include <linux/msg.h>
#include <linux/ipc_namespace.h>
#include <linux/rcupdate.h>
#include <linux/nsproxy.h>
#include <linux/slab.h>

#include "util.h"

static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
{
int err;
struct ipc_namespace *ns;

err = -ENOMEM;
ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
if (ns == NULL)
goto err_mem;

err = sem_init_ns(ns);
if (err)
goto err_sem;
err = msg_init_ns(ns);
if (err)
goto err_msg;
err = shm_init_ns(ns);
if (err)
goto err_shm;

kref_init(&ns->kref);
return ns;

err_shm:
msg_exit_ns(ns);
err_msg:
sem_exit_ns(ns);
err_sem:
kfree(ns);
err_mem:
return ERR_PTR(err);
}

struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
{
struct ipc_namespace *new_ns;

BUG_ON(!ns);
get_ipc_ns(ns);

if (!(flags & CLONE_NEWIPC))
return ns;

new_ns = clone_ipc_ns(ns);

put_ipc_ns(ns);
return new_ns;
}

void free_ipc_ns(struct kref *kref)
{
struct ipc_namespace *ns;

ns = container_of(kref, struct ipc_namespace, kref);
sem_exit_ns(ns);
msg_exit_ns(ns);
shm_exit_ns(ns);
kfree(ns);
}
3 changes: 3 additions & 0 deletions trunk/ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include <linux/seq_file.h>
#include <linux/rwsem.h>
#include <linux/nsproxy.h>
#include <linux/ipc_namespace.h>

#include <asm/uaccess.h>
#include "util.h"
Expand Down Expand Up @@ -128,6 +129,7 @@ static void __sem_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
ipc_init_ids(ids);
}

#ifdef CONFIG_IPC_NS
int sem_init_ns(struct ipc_namespace *ns)
{
struct ipc_ids *ids;
Expand Down Expand Up @@ -165,6 +167,7 @@ void sem_exit_ns(struct ipc_namespace *ns)
kfree(ns->ids[IPC_SEM_IDS]);
ns->ids[IPC_SEM_IDS] = NULL;
}
#endif

void __init sem_init (void)
{
Expand Down
3 changes: 3 additions & 0 deletions trunk/ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <linux/rwsem.h>
#include <linux/nsproxy.h>
#include <linux/mount.h>
#include <linux/ipc_namespace.h>

#include <asm/uaccess.h>

Expand Down Expand Up @@ -96,6 +97,7 @@ static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
shm_destroy(ns, shp);
}

#ifdef CONFIG_IPC_NS
int shm_init_ns(struct ipc_namespace *ns)
{
struct ipc_ids *ids;
Expand Down Expand Up @@ -133,6 +135,7 @@ void shm_exit_ns(struct ipc_namespace *ns)
kfree(ns->ids[IPC_SHM_IDS]);
ns->ids[IPC_SHM_IDS] = NULL;
}
#endif

void __init shm_init (void)
{
Expand Down
61 changes: 1 addition & 60 deletions trunk/ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/audit.h>
#include <linux/nsproxy.h>
#include <linux/rwsem.h>
#include <linux/ipc_namespace.h>

#include <asm/unistd.h>

Expand All @@ -51,66 +52,6 @@ struct ipc_namespace init_ipc_ns = {
},
};

static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
{
int err;
struct ipc_namespace *ns;

err = -ENOMEM;
ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
if (ns == NULL)
goto err_mem;

err = sem_init_ns(ns);
if (err)
goto err_sem;
err = msg_init_ns(ns);
if (err)
goto err_msg;
err = shm_init_ns(ns);
if (err)
goto err_shm;

kref_init(&ns->kref);
return ns;

err_shm:
msg_exit_ns(ns);
err_msg:
sem_exit_ns(ns);
err_sem:
kfree(ns);
err_mem:
return ERR_PTR(err);
}

struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
{
struct ipc_namespace *new_ns;

BUG_ON(!ns);
get_ipc_ns(ns);

if (!(flags & CLONE_NEWIPC))
return ns;

new_ns = clone_ipc_ns(ns);

put_ipc_ns(ns);
return new_ns;
}

void free_ipc_ns(struct kref *kref)
{
struct ipc_namespace *ns;

ns = container_of(kref, struct ipc_namespace, kref);
sem_exit_ns(ns);
msg_exit_ns(ns);
shm_exit_ns(ns);
kfree(ns);
}

/**
* ipc_init - initialise IPC subsystem
*
Expand Down
2 changes: 2 additions & 0 deletions trunk/ipc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void sem_init (void);
void msg_init (void);
void shm_init (void);

struct ipc_namespace;

int sem_init_ns(struct ipc_namespace *ns);
int msg_init_ns(struct ipc_namespace *ns);
int shm_init_ns(struct ipc_namespace *ns);
Expand Down
1 change: 1 addition & 0 deletions trunk/kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/utsname.h>
#include <linux/pid_namespace.h>
#include <net/net_namespace.h>
#include <linux/ipc_namespace.h>

static struct kmem_cache *nsproxy_cachep;

Expand Down

0 comments on commit 58f8ad6

Please sign in to comment.