Virtualization patches for IPC/UTS. 2nd step
Subsystems (4)
I propose to consider these patches for utsname and sysv IPC virtualization once more.
The main change from the previous version is an introduction of separate namespaces for each subsytem as suggested by Eric Biederman. People who work on containers don't care actually, so I splitted a container into namespaces.
The naming conventions used in these patches are (as example for IPC):
CONFIG_IPC_NS - per namespace config option
struct ipc_namespace - structure describing namepsaceipc_ns - names of var pointers, in task_struct etc.init_ipc_ns - default host namespace
interfaces:get_ipc_ns - refcountig interfaceput_ipc_ns - refcountig interfacecreate_ipc_ns - create _empty_ namespaceclone_ipc_ns - clone current namespace, if applicablefree_ipc_ns - destroy namespace when refs are 0
Please, note, these patches do not introduce CONFIG_XXX_NS option in any of Kconfigs, as it is questionable whether to have them scattered all around or place in some menu "Virtual namespaces". But patches compile and work fine both w/o and with it.
Also, please, note, that these patches do not virtualize corresponding sysctls or proc parts of uts/ipc. I suppose this must be postponed as we have no any consensus on /proc.
Some other minor differences from Eric/Dave patches:
- these patches heavily use current namespace context instead of bypassing additional argument to all functions where required.
- these patches compile to the old good kernel when namespaces are off.
Both patches are also available in GIT repo at:
http://git.openvz.org/pub/linux-2.6-openvz-ms/
Thanks,
Kirill
RFC PATCH 1/2 Virtualization of UTS
This patch introduces utsname namespace in system, which allows to have different utsnames on the host. Introduces config option CONFIG_UTS_NS and uts_namespace structure for this.
http://git.openvz.org/?p=linux-2.6-openvz-ms;a=commitdiff;h=216bb5e42c7eef7f1ed361244a60b1496e8bdf63
Kirill
include/linux/init_task.h +8 -0
@@ -3,6 +3,7 @@#include <linux/file.h> #include <linux/rcupdate.h> +#include <linux/utsname.h> #define INIT_FDTABLE \ { \
@@ -72,6 +73,12 @@extern struct group_info init_groups; +#ifdef CONFIG_UTS_NS +#define INIT_UTS_NS .uts_ns = &init_uts_ns, +#else +#define INIT_UTS_NS +#endif +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -121,6 +128,7 @@ extern struct group_info init_groups; .journal_info = NULL, \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl = ATOMIC_INIT(0), \ + INIT_UTS_NS \ }
include/linux/sched.h +4 -0
@@ -688,6 +688,7 @@ static inline void prefetch_stack(structstruct audit_context ;/* See audit.c */ struct mempolicy ; +struct uts_namespace ;struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */
@@ -802,6 +803,9 @@ struct task_struct {struct files_struct *files;/* namespace */ struct namespace *namespace; +#ifdef CONFIG_UTS_NS +struct uts_namespace *uts_ns; +#endif /* signal handlers */ struct signal_struct *signal;struct sighand_struct *sighand;
include/linux/utsname.h +29 -0
@@ -30,7 +30,36 @@ struct new_utsname {char domainname[65 ]; }; +#ifdef CONFIG_UTS_NS +#include <asm/atomic.h> + +struct uts_namespace { +atomic_t cnt; +struct new_utsname name; +}; + +extern struct uts_namespace *create_uts_ns (void ); +extern struct uts_namespace *clone_uts_ns (void ); +extern void free_uts_ns (struct uts_namespace *ns); + +static inline void get_uts_ns (struct uts_namespace *ns) +{ +atomic_inc (&ns->cnt); +} + +static inline void put_uts_ns (struct uts_namespace *ns) +{ +if (atomic_dec_and_test (&ns->cnt)) +free_uts_ns (ns); +} + +#define system_utsname (current->uts_ns->name) +extern struct uts_namespace init_uts_ns; +#else +#define get_uts_ns (ns) do { } while (0) +#define put_uts_ns (ns) do { } while (0)extern struct new_utsname system_utsname; +#endif extern struct rw_semaphore uts_sem;#endif
init/version.c +46 -0
58 lines not on this page · raw message
kernel/exit.c +1 -0
@@ -107,6 +107,7 @@ repeat:spin_unlock (&p->proc_lock);proc_pid_flush (proc_dentry);release_thread (p); +put_uts_ns (p->uts_ns);put_task_struct (p); p = leader;
kernel/fork.c +1 -0
@@ -1192,6 +1192,7 @@ static task_t *copy_process(unsigned lon }attach_pid (p,PIDTYPE_TGID , p->tgid);attach_pid (p,PIDTYPE_PID , p->pid); +get_uts_ns (p->uts_ns); nr_threads++; total_forks++;
kernel/sysctl.c +16 -10
@@ -229,12 +229,18 @@ static ctl_table root_table[] = { { .ctl_name = 0 } }; +#ifdef CONFIG_UTS_NS +#define sysctl_system_utsname (init_uts_ns.name) +#else +#define sysctl_system_utsname (system_utsname) +#endif +static ctl_table kern_table[] = { { .ctl_name =KERN_OSTYPE , .procname ="ostype" , - .data = system_utsname.sysname, - .maxlen =sizeof (system_utsname.sysname), + .data = sysctl_system_utsname.sysname, + .maxlen =sizeof (sysctl_system_utsname.sysname), .mode =0444 , .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,
@@ -242,8 +248,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_OSRELEASE, .procname = "osrelease", - .data = system_utsname.release, - .maxlen = sizeof(system_utsname.release), + .data = sysctl_system_utsname.release, + .maxlen = sizeof(sysctl_system_utsname.release), .mode = 0444, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,
@@ -251,8 +257,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_VERSION, .procname = "version", - .data = system_utsname.version, - .maxlen = sizeof(system_utsname.version), + .data = sysctl_system_utsname.version, + .maxlen = sizeof(sysctl_system_utsname.version), .mode = 0444, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,
@@ -260,8 +266,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_NODENAME, .procname = "hostname", - .data = system_utsname.nodename, - .maxlen = sizeof(system_utsname.nodename), + .data = sysctl_system_utsname.nodename, + .maxlen = sizeof(sysctl_system_utsname.nodename), .mode = 0644, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,
@@ -269,8 +275,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_DOMAINNAME, .procname = "domainname", - .data = system_utsname.domainname, - .maxlen = sizeof(system_utsname.domainname), + .data = sysctl_system_utsname.domainname, + .maxlen = sizeof(sysctl_system_utsname.domainname), .mode = 0644, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,
RFC PATCH 2/2 Virtualization of IPC
In reply to Kirill KorotaevThis patch introduces IPC namespaces, which allow to create isolated IPC users or containers.
Introduces CONFIG_IPC_NS and ipc_namespace structure.
It also uses current->ipc_ns as a pointer to current namespace, which reduces places where additional argument to functions should be added.
From: Pavel Emelianov <[email protected]>
Date: Wed, 22 Mar 2006 13:15:23 +0000 (-0500)
Subject: Move ipc objects into separate namespace.
X-Git-Url: http://git.openvz.org/?p=linux-2.6-openvz-ms;a=commitdiff;h=84a441429e7af425d27a8cda5beb70de5521a0be
Move ipc objects into separate namespace.
---
include/linux/init_task.h +8 -0
@@ -4,6 +4,7 @@#include <linux/file.h> #include <linux/rcupdate.h> #include <linux/utsname.h> +#include <linux/ipc.h> #define INIT_FDTABLE \ { \
@@ -79,6 +80,12 @@ extern struct group_info init_groups;#define INIT_UTS_NS #endif +#ifdef CONFIG_IPC_NS +#define INIT_IPC_NS .ipc_ns = &init_ipc_ns, +#else +#define INIT_IPC_NS +#endif +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -129,6 +136,7 @@ extern struct group_info init_groups; .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl =ATOMIC_INIT (0 ), \INIT_UTS_NS \ + INIT_IPC_NS \ }
include/linux/ipc.h +44 -0
50 lines not on this page · raw message
include/linux/sched.h +4 -0
@@ -689,6 +689,7 @@ static inline void prefetch_stack(structstruct audit_context ;/* See audit.c */ struct mempolicy ;struct uts_namespace ; +struct ipc_namespace ;struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */
@@ -806,6 +807,9 @@ struct task_struct {#ifdef CONFIG_UTS_NS struct uts_namespace *uts_ns;#endif +#ifdef CONFIG_IPC_NS +struct ipc_namespace *ipc_ns; +#endif /* signal handlers */ struct signal_struct *signal;struct sighand_struct *sighand;
ipc/msg.c +42 -7
75 lines not on this page · raw message
ipc/sem.c +41 -3
71 lines not on this page · raw message
ipc/shm.c +76 -8
150 lines not on this page · raw message
ipc/util.c +48 -3
75 lines not on this page · raw message
ipc/util.h +19 -1
@@ -8,6 +8,8 @@#ifndef _IPC_UTIL_H#define _IPC_UTIL_H +#include <linux/config.h> +#define USHRT_MAX 0xffff#define SEQ_MULTIPLIER (IPCMNI)
@@ -20,6 +22,7 @@ struct ipc_id_ary {struct kern_ipc_perm *p[0 ]; }; +struct ipc_namespace ;struct ipc_ids {int in_use;int max_id;
@@ -28,10 +31,25 @@ struct ipc_ids {struct semaphore sem;struct ipc_id_ary nullentry;struct ipc_id_ary * entries; +#ifdef CONFIG_IPC_NS +struct ipc_namespace *ns; +#endif }; +#ifdef CONFIG_IPC_NS +int init_sem_ns (struct ipc_namespace *ns); +int init_msg_ns (struct ipc_namespace *ns); +int init_shm_ns (struct ipc_namespace *ns); +void fini_sem_ns (struct ipc_namespace *ns); +void fini_msg_ns (struct ipc_namespace *ns); +void fini_shm_ns (struct ipc_namespace *ns); +#define __ipc_init +#else +#define __ipc_init __init +#endif +struct seq_file ; -void __init ipc_init_ids (struct ipc_ids * ids,int size); +void __ipc_init ipc_init_ids(struct ipc_ids* ids, int size);#ifdef CONFIG_PROC_FS void __init ipc_init_proc_interface(const char *path, const char *header, struct ipc_ids *ids,
kernel/exit.c +1 -0
@@ -108,6 +108,7 @@ repeat:proc_pid_flush (proc_dentry);release_thread (p);put_uts_ns (p->uts_ns); +put_ipc_ns (p->ipc_ns);put_task_struct (p); p = leader;
kernel/fork.c +1 -0
@@ -1193,6 +1193,7 @@ static task_t *copy_process(unsigned lonattach_pid (p,PIDTYPE_TGID , p->tgid);attach_pid (p,PIDTYPE_PID , p->pid);get_uts_ns (p->uts_ns); +get_ipc_ns (p->ipc_ns); nr_threads++; total_forks++;
kernel/sysctl.c +11 -0
@@ -93,6 +93,7 @@ extern char modprobe_path[];extern int sg_big_buff;#endif #ifdef CONFIG_SYSVIPC +#ifndef CONFIG_IPC_NS extern size_t shm_ctlmax;extern size_t shm_ctlall;extern int shm_ctlmni;
@@ -100,6 +101,16 @@ extern int msg_ctlmax;extern int msg_ctlmnb;extern int msg_ctlmni;extern int sem_ctls[]; +#else +#include <linux/ipc.h> +#define shm_ctlmax (init_ipc_ns.shm_ctlmax) +#define shm_ctlall (init_ipc_ns.shm_ctlall) +#define shm_ctlmni (init_ipc_ns.shm_ctlmni) +#define msg_ctlmax (init_ipc_ns.msg_ctlmax) +#define msg_ctlmnb (init_ipc_ns.msg_ctlmnb) +#define msg_ctlmni (init_ipc_ns.msg_ctlmni) +#define sem_ctls (init_ipc_ns.sem_ctls) +#endif #endif #ifdef __sparc__
Re: [RFC][PATCH 2/2] Virtualization of IPC
Quoted 5 lines · Kirill Korotaev
This patch introduces IPC namespaces, which allow to create isolated IPC users or containers.
IntroducesCONFIG_IPC_NSandipc_namespacestructure.
It also usescurrent->ipc_nsas a pointer to current namespace, which reduces places where additional argument to functions should be added.
In three words, I think this has "too many #ifdefs".
The non-containerized or namespaced case should probably just be one, static namespace variable that gets wrapped up in some nice #ifdefed hlper functions.
For instance, instead of this:
+#ifdef CONFIG_IPC_NS
+#define msg_ids (*(current->ipc_ns->msg_ids))
+#endif
Have
#ifdef CONFIG_IPC_NS
static inline struct ipc_namespace *current_ipc_ns(void)
{
return current->ipc_ns;
}
#else
static inline struct ipc_namespace *current_ipc_ns(void)
{
return &static_ipc_ns;
}#endif
And use current_ipc_ns()->msg_ids. I can't imagine that gcc can't figure that out and turn it back into effectively the same thing.
I really dislike the idea of replacing nice variables with macros that add indirection. They really might fool people. Putting a function there is much nicer.
Why avoid to passing these things around as function arguments? Doesn't that make it more explicit what is going on, and where the indirection is occurring? Does it also make refcounting and lifetime issues easier to manage?
BTW, Did you see my version of this?
-- Dave
Re: [RFC][PATCH 1/2] Virtualization of UTS
In reply to Kirill KorotaevQuoted 3 lines · Kirill Korotaev
This patch introduces utsname namespace in system, which allows to have different utsnames on the host.
Introduces config optionCONFIG_UTS_NSanduts_namespacestructure for this.
Ok. It looks like we need to resolve the sysctl issues before we merge either patch, into the stable kernel.
We also need to discuss the system call interface, as without one the functionality is unusable :)
Quoted 117 lines
http://git.openvz.org/?p=linux-2.6-openvz-ms;a=commitdiff;h=216bb5e42c7eef7f1ed361244a60b1496e8bdf63
Signed-off-by Pavel Emelianov <[email protected]>Signed-off-by Kirill Korotaev <[email protected]>Kirill
include/linux/init_task.h +8
-0@@ -3,6 +3,7 @@#include <linux/file.h> #include <linux/rcupdate.h> +#include <linux/utsname.h> #define INIT_FDTABLE \ { \@@ -72,6 +73,12 @@extern struct group_info init_groups; +#ifdef CONFIG_UTS_NS +#define INIT_UTS_NS .uts_ns = &init_uts_ns, +#else +#define INIT_UTS_NS +#endif +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB) @@ -121,6 +128,7 @@ extern struct group_info init_groups; .journal_info = NULL, \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl = ATOMIC_INIT(0), \ + INIT_UTS_NS \ }include/linux/sched.h +4
-0@@ -688,6 +688,7 @@ static inline void prefetch_stack(structstruct audit_context ;/* See audit.c */ struct mempolicy ; +struct uts_namespace ;struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */ @@ -802,6 +803,9 @@ struct task_struct {struct files_struct *files;/* namespace */ struct namespace *namespace; +#ifdef CONFIG_UTS_NS +struct uts_namespace *uts_ns; +#endif /* signal handlers */ struct signal_struct *signal;struct sighand_struct *sighand;include/linux/utsname.h +29
-0@@ -30,7 +30,36 @@ struct new_utsname {char domainname[65 ]; }; +#ifdef CONFIG_UTS_NS +#include <asm/atomic.h> + +struct uts_namespace { +atomic_t cnt; +struct new_utsname name; +}; + +extern struct uts_namespace *create_uts_ns (void ); +extern struct uts_namespace *clone_uts_ns (void ); +extern void free_uts_ns (struct uts_namespace *ns); + +static inline void get_uts_ns (struct uts_namespace *ns) +{ +atomic_inc (&ns->cnt); +} + +static inline void put_uts_ns (struct uts_namespace *ns) +{ +if (atomic_dec_and_test (&ns->cnt)) +free_uts_ns (ns); +} + +#define system_utsname (current->uts_ns->name) +extern struct uts_namespace init_uts_ns; +#else +#define get_uts_ns (ns) do { } while (0) +#define put_uts_ns (ns) do { } while (0)extern struct new_utsname system_utsname; +#endif extern struct rw_semaphore uts_sem;#endif init/version.c +14
-0@@ -17,6 +17,51 @@int version_string (LINUX_VERSION_CODE ); +#ifdef CONFIG_UTS_NS +struct uts_namespace init_uts_ns = { + .cnt =ATOMIC_INIT (1 ), + .name = { + .sysname =UTS_SYSNAME , + .nodename =UTS_NODENAME , + .release =UTS_RELEASE , + .version =UTS_VERSION , + .machine =UTS_MACHINE , + .domainname =UTS_DOMAINNAME , + }, +}; +struct uts_namespace *create_uts_ns (void ) +{
init/version.c line 44
Quoted 10 lines
init/version.c +10
-0+struct uts_namespace *ns; + + ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); +if (ns ==NULL ) +return NULL ; + +memset (&ns->name,0 ,sizeof (ns->name)); +atomic_set (&ns->cnt,1 ); +return ns; +}
Setting name to 0. Seems very wrong.
init/version.c line 58
Quoted 13 lines
init/version.c +13
-0+struct uts_namespace *clone_uts_ns (void ) +{ +struct uts_namespace *ns, *cur; + + ns =kmalloc (sizeof (struct uts_namespace ),GFP_KERNEL ); +if (ns ==NULL ) +return NULL ; + + cur = current->uts_ns; +memcpy (&ns->name, &cur->name,sizeof (cur->name)); +atomic_set (&ns->cnt,1 ); +return ns; +}
Having both create_uts_ns and clone_uts_ns is redundant.
There is a reasonable argument for copying resetting nodename and domainname to UTS_NODENAME, and UTS_DOMAINNAME, when we create a new instance. As we almost certainly do not want to continue to use the old ones and we need some value in there. Plus some user space tools special case the default UTS_NODENAME for setting the name from DHCP.
We can also do this from user space so it is not a huge deal either way. We certainly need to copy the other fields and not initialize them from the defaults because there is kernel initialization code that modifies the defaults.
init/version.c struct new_utsname system_utsname = { · line 75
Quoted 13 lines
init/version.c +6
-0+void free_uts_ns (struct uts_namespace *ns) +{ +kfree (ns); +} +#else struct new_utsname system_utsname = { .sysname =UTS_SYSNAME , .nodename = UTS_NODENAME,@@ -27,6 +72,7 @@ struct new_utsname system_utsname = { };EXPORT_SYMBOL (system_utsname); +#endif
I am a little concerned about the maintenance issues with placing having two identical initializers from system_utsname.
Quoted 15 lines
init/version.c +0
-0const char linux_banner[] ="Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@" kernel/exit.c +1
-0@@ -107,6 +107,7 @@ repeat:spin_unlock (&p->proc_lock);proc_pid_flush (proc_dentry);release_thread (p); +put_uts_ns (p->uts_ns);put_task_struct (p); p = leader;
kernel/fork.c static task_t *copy_process(unsigned lon · line 1198
Quoted 7 lines
kernel/fork.c +1
-0@@ -1192,6 +1192,7 @@ static task_t *copy_process(unsigned lon }attach_pid (p,PIDTYPE_TGID , p->tgid);attach_pid (p,PIDTYPE_PID , p->pid); +get_uts_ns (p->uts_ns); nr_threads++; total_forks++;
We don't need the tasklist_lock around get_uts_ns. Please move it earlier.
kernel/sysctl.c static ctl_table root_table[] = { · line 230
Quoted 5 lines
kernel/sysctl.c +0
-0@@ -229,12 +229,18 @@ static ctl_table root_table[] = { { .ctl_name = 0 } };
Since we can disable CONFIG_SYSCTL we probably want to leave this part for another patch. Although incremental progress is probably ok.
Quoted 61 lines
kernel/sysctl.c +16
-10+#ifdef CONFIG_UTS_NS +#define sysctl_system_utsname (init_uts_ns.name) +#else +#define sysctl_system_utsname (system_utsname) +#endif +static ctl_table kern_table[] = { { .ctl_name =KERN_OSTYPE , .procname ="ostype" , - .data = system_utsname.sysname, - .maxlen =sizeof (system_utsname.sysname), + .data = sysctl_system_utsname.sysname, + .maxlen =sizeof (sysctl_system_utsname.sysname), .mode =0444 , .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,@@ -242,8 +248,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_OSRELEASE, .procname = "osrelease", - .data = system_utsname.release, - .maxlen = sizeof(system_utsname.release), + .data = sysctl_system_utsname.release, + .maxlen = sizeof(sysctl_system_utsname.release), .mode = 0444, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,@@ -251,8 +257,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_VERSION, .procname = "version", - .data = system_utsname.version, - .maxlen = sizeof(system_utsname.version), + .data = sysctl_system_utsname.version, + .maxlen = sizeof(sysctl_system_utsname.version), .mode = 0444, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,@@ -260,8 +266,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_NODENAME, .procname = "hostname", - .data = system_utsname.nodename, - .maxlen = sizeof(system_utsname.nodename), + .data = sysctl_system_utsname.nodename, + .maxlen = sizeof(sysctl_system_utsname.nodename), .mode = 0644, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,@@ -269,8 +275,8 @@ static ctl_table kern_table[] = { { .ctl_name = KERN_DOMAINNAME, .procname = "domainname", - .data = system_utsname.domainname, - .maxlen = sizeof(system_utsname.domainname), + .data = sysctl_system_utsname.domainname, + .maxlen = sizeof(sysctl_system_utsname.domainname), .mode = 0644, .proc_handler = &proc_doutsstring, .strategy = &sysctl_string,
Re: [RFC][PATCH 1/2] Virtualization of UTS
Quoted 6 lines
Quoted 3 lines
This patch introduces utsname namespace in system, which allows to have different utsnames on the host.
Introduces config optionCONFIG_UTS_NSanduts_namespacestructure for this.Ok. It looks like we need to resolve the sysctl issues before we merge either patch, into the stable kernel.
I disagree with you. Right now we can have sysctl and proc for init namespaces only.
And when sysctl and proc are virtualized somehow, we can fix all these.
I simply don't expect /proc and sysctl to be done quickly. As we have very different approaches. And there is no any consensus. Why not to commit working/agreed parts then?
Quoted 2 lines
We also need to discuss the system call interface, as without one the functionality is unusable :)
I also don't see why it can be separated. There is an API in namespaces, and how it is mapped into syscalls is another question. At least it doesn't prevent us from commiting virtualization itself, agree?
Thanks,
Kirill
Re: [RFC][PATCH 1/2] Virtualization of UTS
Quoted 11 lines · Kirill Korotaev
Quoted 5 lines
Quoted 3 lines
This patch introduces utsname namespace in system, which allows to have different utsnames on the host.
Introduces config optionCONFIG_UTS_NSanduts_namespacestructure for this.Ok. It looks like we need to resolve the sysctl issues before we merge either patch, into the stable kernel.
I disagree with you. Right now we can have sysctl and proc for init namespaces only.
And when sysctl and proc are virtualized somehow, we can fix all these. I simply don't expect /proc and sysctl to be done quickly. As we have very different approaches. And there is no any consensus. Why not to commit working/agreed parts then?
So getting this code into Andrews development tree (as long as he is willing to accept it) looks very reasonable. We can't change the interface once we get into the stable kernel because that becomes part of the ABI.
So all I am saying is that this code is clearly not yet ready for the stable branch, because we plan to change the sysctl interface.
Quoted 5 lines
Quoted 2 lines
We also need to discuss the system call interface, as without one the functionality is unusable :)
I also don't see why it can be separated. There is an API in namespaces, and how it is mapped into syscalls is another question. At least it doesn't prevent us from commiting virtualization itself, agree?
Separating the patches makes a lot of sense. Putting something into the kernel without any in tree users is a problem.
Eric
Re: [RFC][PATCH 2/2] Virtualization of IPC
In reply to Kirill KorotaevQuoted 5 lines · Kirill Korotaev
This patch introduces IPC namespaces, which allow to create isolated IPC users or containers.
IntroducesCONFIG_IPC_NSandipc_namespacestructure.
It also usescurrent->ipc_nsas a pointer to current namespace, which reduces places where additional argument to functions should be added.
I don't see where we are freeing the shared memory segments, the message queues and the semaphores when the last user of the namespace goes away. Am I missing something?
Quoted 20 lines
include/linux/ipc.h +14
-0@@ -70,6 +70,50 @@ struct kern_ipc_perm#endif /* __KERNEL__ */ +#include <linux/config.h> + +#ifdef CONFIG_IPC_NS +#include <asm/atomic.h> + +struct ipc_ids; +struct ipc_namespace { + atomic_t cnt; + + struct ipc_ids *sem_ids; + int sem_ctls[4]; + int used_sems; + + struct ipc_ids *msg_ids;
include/linux/ipc.h struct kern_ipc_perm · line 96
Quoted 10 lines
include/linux/ipc.h +10
-0+int msg_ctlmax; +int msg_ctlmnb; +int msg_ctlmni; + +struct ipc_ids *shm_ids; +size_t shm_ctlmax; +size_t shm_ctlall; +int shm_ctlmni; +int shm_total; +};
I believe there is a small problem with this implementation. per namespace counts and limits are fine. But I think we want
to maintain true global limits as well. I know
concerns of that nature have been expressed in regards to Daves patch.
kernel/fork.c static task_t *copy_process(unsigned lon · line 1199
Quoted 10 lines
kernel/fork.c +1
-0@@ -1193,6 +1193,7 @@ static task_t *copy_process(unsigned lonattach_pid (p,PIDTYPE_TGID , p->tgid);attach_pid (p,PIDTYPE_PID , p->pid);get_uts_ns (p->uts_ns); +get_ipc_ns (p->ipc_ns); nr_threads++; total_forks++;
Again please move the get outside of the tasklist_lock.
Eric
Re: [RFC][PATCH 1/2] Virtualization of UTS
In reply to Kirill KorotaevQuoted 4 lines · Kirill Korotaev
This patch introduces utsname namespace in system, which allows to have different utsnames on the host.
Introduces config optionCONFIG_UTS_NSanduts_namespacestructure for this.
Please include patches inline, so they can be quoted inline.
+#define system_utsname (current->uts_ns->name)
This should be a static inline.
+struct uts_namespace *create_uts_ns(void)
+{
+ struct uts_namespace *ns;
+
+ ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
+ if (ns == NULL)
+ return NULL;
+
+ memset(&ns->name, 0, sizeof(ns->name));
+ atomic_set(&ns->cnt, 1);
+ return ns;
+}
IMHO, it's better to do something like:
{
foo = kmalloc();
if (foo) {
stuff;
etc;
}
return foo;
}I suggest you use kzalloc(), too.
Also, I think the API approach needs to be determined before the patches go into -mm, in case it impacts on the code.
Re: [RFC][PATCH 2/2] Virtualization of IPC
In reply to Dave HansenQuoted 31 lines · Dave Hansen
Quoted 5 lines · Kirill Korotaev
This patch introduces IPC namespaces, which allow to create isolated IPC users or containers.
IntroducesCONFIG_IPC_NSandipc_namespacestructure.
It also usescurrent->ipc_nsas a pointer to current namespace, which reduces places where additional argument to functions should be added.In three words, I think this has "too many #ifdefs".
The non-containerized or namespaced case should probably just be one, static namespace variable that gets wrapped up in some nice #ifdefed hlper functions.
For instance, instead of this:
ipc/msg.c +3
-0+#ifdef CONFIG_IPC_NS +#define msg_ids (*(current->ipc_ns->msg_ids)) +#endif Have
#ifdef
CONFIG_IPC_NS
static inline structipc_namespace*current_ipc_ns(void){ return current->ipc_ns; } #else static inline struct ipc_namespace *current_ipc_ns(void) { return &static_ipc_ns; }
Quoted 4 lines
#endif
And use current_ipc_ns()->msg_ids. I can't imagine that gcc can't figure that out and turn it back into effectively the same thing.
one issue here, not always 'current' is the right context, often you handle stuff on behalf of a task, which would then point to the 'proper' context ...
i.e. something like task_msg_ids(current) is probably better and more flexible, also I'm still not convinced that 'per process' is the proper context for those things, 'per container' or 'per space' would be more appropriate IMHO ...
more comments to follow, when I got to the patches ...
Quoted 10 lines
I really dislike the idea of replacing nice variables with macros that add indirection. They really might fool people. Putting a function there is much nicer.
Why avoid to passing these things around as function arguments? Doesn't that make it more explicit what is going on, and where the indirection is occurring? Does it also make refcounting and lifetime issues easier to manage?
BTW, Did you see my version of this?
no, where is it?
maybe we should put all that stuff on a wiki too?
best,
Herbert
Quoted 2 lines
-- Dave
Re: [RFC][PATCH 2/2] Virtualization of IPC
In reply to Kirill KorotaevQuoting Kirill Korotaev ([email protected]):
Thanks for sending the patches.
ipc/msg.c static int newque (key_t key, int msgflg · line 106
Quoted 3 lines
ipc/msg.c +3
-0+#define msg_ctlmax (current->ipc_ns->msg_ctlmax) +#define msg_ctlmnb (current->ipc_ns->msg_ctlmnb) +#define msg_ctlmni (current->ipc_ns->msg_ctlmni)
Oh my - woe to the person trying to figure out why
current->ipc_ns->msg_ctlmax = 20;
isn't compiling.
-serge
Re: [RFC][PATCH 1/2] Virtualization of UTS
In reply to Kirill Korotaevinclude/linux/utsname.h struct new_utsname { · line 54
Quoted 10 lines · Kirill Korotaev
include/linux/utsname.h +10
-0+static inline void get_uts_ns (struct uts_namespace *ns) +{ +atomic_inc (&ns->cnt); +} + +static inline void put_uts_ns (struct uts_namespace *ns) +{ +if (atomic_dec_and_test (&ns->cnt)) +free_uts_ns (ns); +}
I think somebody already said this, but this is probably better using kobject as I was asked to for the vx_info. (Documentation/kobject.txt)
Also I think it might be useful to have a count of tasks that refer to the structure, in addition to the count of actual references. In this way you can know whether the resource is "free" before its kobject destructor is called (as the vserver vx_info does).
Perhaps that abstraction is best to put in when it becomes "useful", like you have a situation where you want to do something when the last process with a utsname exits, but before the last kthread referencing the structure stops (eg, a sleeping process reading /proc somewhere).
Otherwise, nice and simple; I could quite easily at this point plug this into the syscall infrastructure I posted earlier (once it is reworked based on people's comments), and provide tests for this.
Sam.
Re: [RFC][PATCH 2/2] Virtualization of IPC
In reply to Herbert PoetzlQuoted 1 line · Herbert Poetzl
maybe we should put all that stuff on a wiki too?
Good heavens, for the love of life and everything pure and good in the world, no!
Perhaps we can get a kernel.org git tree? Each submission can be put in as seperate branches.
For instance I have already been doing this for several submissions, see
http://vserver.utsl.gen.nz/gitweb/?p=vserver;a=heads
This doesn't include Dave's or Kirill's patches yet (as of -0328T15:53 +12).
OK, now it does (as of -0328T17:23+12).
I am more than happy to continue to track people's submissions in this way, but they probably belong on kernel.org
Sam.
Re: [RFC][PATCH 1/2] Virtualization of UTS
In reply to Kirill KorotaevQuoted 11 lines · Kirill Korotaev
Quoted 5 lines
Quoted 3 lines
This patch introduces utsname namespace in system, which allows to have different utsnames on the host.
Introduces config optionCONFIG_UTS_NSanduts_namespacestructure for this.Ok. It looks like we need to resolve the sysctl issues before we merge either patch, into the stable kernel.
I disagree with you. Right now we can have sysctl and proc for init namespaces only.
And when sysctl and proc are virtualized somehow, we can fix all these. I simply don't expect /proc and sysctl to be done quickly. As we have very different approaches. And there is no any consensus. Why not to commit working/agreed parts then?
So for planning purposes. I don't think we can even if we ignore sysctl and proc have an implementation that we all agree is stable and safe before 2.6.17 merge window closes. I do think if we get our act together something that works and is tested when the 2.6.18 window opens is very reasonable. (Limited to UTS and sysvipc with other work waiting until later).
Does that sound like a reasonable and achievable goal?
Eric